#include <p18F1320.inc>
CONFIG WDT=OFF; disable watchdog timer
CONFIG MCLRE = OFF; MCLEAR Pin off
CONFIG DEBUG = OFF; Enable Debug Mode
CONFIG LVP = OFF; Low-Voltage programming disabled (necessary for debugging)
CONFIG OSC = INTIO2;Internal oscillator, port function on RA6
CONFIG PWRT = ON
org 0; start code at 0
cblock 0x20
Delay1
Delay2
count
var1
endc
Start:
clrf TRISA
clrf LATA
clrf LATB
clrf TRISB
movlw b'01100000'
movwf OSCCON
movlw b'01111111'
movwf ADCON1
movlw 0xFF
movwf TRISA
clrf count
clrf var1
Main:
WaitKeyPress:
btfsc PORTA,RA0
goto WaitKeyPress
call Delay
incf var1
movlw d'1'
cpfseq var1
goto WaitKeyPress
goto TurnLeftLED
movlw d'2'
cpfseq var1
goto WaitKeyPress
goto TurnRightLED
movlw d'3'
cpfseq var1
goto WaitKeyPress
goto TurnOnAllLED
TurnLeftLED:
movlw b'00000001'
movwf LATB
Loop1:
rrncf LATB
call Delay
btfsc PORTA,RA0
goto Loop1
goto WaitKeyPress
goto TurnLeftLED
TurnRightLED:
movlw b'10000000'
movwf LATB
Loop2:
rlncf LATB
call Delay
btfsc PORTA,RA0
goto Loop2
goto WaitKeyPress
goto TurnRightLED
TurnOnAllLED:
clrf LATB
Loop3:
movlw b'111111111'
btfsc PORTA,RA0
goto Loop3
goto WaitKeyPress
goto TurnOnAllLED
Delay:
; movwf Delay2
DelayLoop:
DECFSZ Delay1,f ;Decrement Delay1 by 1, skip next instruction if Delay1 is 0
GOTO Delay
DECFSZ Delay2,f
GOTO Delay
return
end