You are on page 1of 2

COUNT1 equ 20h ; First counter for our delay loops

COUNT2 equ 21h ; Second counter for our delay loops


INCvar equ 22h
goto start
;***************INTERRUPT ROUTINE***************
org 0x04 ;This is where PC points on an interrupt
incf INCvar,f
bcf INTCON, T0IF;We need to clear this flag to enable more interrupt
s
retfie ;Come out of the interrupt routine
start:
; Setting up the ports
clrf TMR0 ; Clear Timer0 register
clrf INTCON ; Disable interrupts and clear T0IF
bsf STATUS, RP0 ; Bank 1
movlw 0x02 ; PortB pull-ups are disabled,
movwf OPTION_REG ; Interrupt on rising edge of RB0/INT pin
; TMR0 Clock source increment from internal cloc
k
; Increment on rising edge of RA4/T0CKI pin
; TMR0 prescaler of 1:8
; (note 0x08, 1:1 faster but PSA is assigned to
WDT)
; (note 0x02, 1:8 slows down the TMR0 in Extreme
ly Fast
; but still our eyes can't see transition
in real time)
; (note 0x07, 1:256 slowest PS but still our eye
s can't see
; transition in real time)
bsf STATUS, 5
movlw h'06'
movwf ADCON1
movlw h'01'
movwf TRISA
movlw h'00'
movwf TRISE
movwf TRISB
movwf TRISC
movwf TRISD
bcf STATUS, 5
clrf PORTB
clrf PORTC
clrf PORTD
movwf ADCON1
bcf STATUS, RP0 ; Bank 0
clrf PORTB
; Start of the main program
main: clrf INCvar
movf INCvar,w
call table
movwf PORTB
btfss PORTA,0
goto X
goto T0_OVRFLW_wait
T0_OVRFLW_wait:
call CHECK
movf INCvar,w
call table
movwf PORTB
bsf INTCON, GIE ; Enable all Interrupts
bsf INTCON, T0IE ; Enable TMR0 Interrupt
bcf INTCON, T0IF ; T0IF - Clear FLag Bit Just In Case
; and dispalying that on PORTB
btfss INTCON, T0IF ; is there a TMR0 overflow?
goto T0_OVRFLW_wait ; if No, wait for the timer overflow
goto main ; never executed, interrupt happend
CHECK: btfss PORTA,0
goto main
movf INCvar,w
xorlw h'10'
btfsc STATUS,Z
clrf INCvar
return
X: clrf TMR0
goto main
table: addwf PCL,f
retlw 3fh
retlw 06h
retlw 5bh
retlw 4fh
retlw 66h
retlw 6dh
retlw 7dh
retlw 07h
retlw 7fh
retlw 6fh
retlw 77h
retlw 7ch
retlw 39h
retlw 5eh
retlw 79h
retlw 71h
return
delay: movlw D'5' ; use 5 in Extremely Fast and PS = 02
movwf COUNT1 ; use 255 in actual module
delay1: movwf COUNT2
delay2: decfsz COUNT2,1
goto delay2
decfsz COUNT1,f
goto delay1
return
; End of program block
end

You might also like