#include "P18f4550.INC"
CONFIG WDT=OFF; disable watchdog timer CONFIG MCLRE = ON; MCLEAR Pin on CONFIG DEBUG = ON; Enable Debug Mode CONFIG LVP = OFF; Low-Voltage programming disabled (necessary for debugging) CONFIG FOSC = INTOSCIO_EC;Internal oscillator, port function on RA6
org 0; start code at 0
Delay1 res 2 ; variable Delay1 Delay2 res 2 ; variable Delay2 Delay3 res 2 ; variable Delay3
Start: CLRF PORTD ; Initialize with 0's output D. CLRF TRISD ; Make port D output CLRF Delay1; Clear delay variables CLRF Delay2
SETF TRISC ; Make port c an input
MOVLW H'40' ; Initialize delay3 to 0x40. This is the delay used to rotate the segments. MOVWF Delay3
BSF PORTD,RD0 ;Turn on bit 0 in RD0
MainLoop: RRNCF PORTD ; Rotate bits in D. This causes the segments in display to shift.
MOVF Delay3,0 ; Reload Delay2 eith the value of Delay3. Delay2 controls the rate the MOVWF Delay2 ; rotate takes place.
MOVLW H'F0' ; Test if Delay3 is at the maximum of 0xF0 or more. If that is the case, do not CPFSLT Delay3 ; read the left switch. goto noincrement MOVLW 4 ; Read the left switch. BTFSS PORTC,0 ; If the switch is 0 (gnd), then increase Delay3 by 4, otherwise skip the increment. ADDWF Delay3,1
noincrement:
MOVLW H'05' ; Test if Delay3 is at the minimum pf 0x5 or less. If that is the case do not CPFSGT Delay3 ; read the right switch. goto Delay
MOVLW 4 ; Read the right switch. BTFSS PORTC,1 ; If the switch is 0, then decrement Delay3 by 4, otherwise skip the decrement operation. SUBWF Delay3,1 Delay:
DECFSZ Delay1,1 ;Decrement Delay1 by 1, skip next instruction if Delay1 is 0 GOTO Delay DECFSZ Delay2,1 ;Decrement Delay1 by 1, skip next instruction if Delay1 is 0 GOTO Delay GOTO MainLoop
end
|