Specifications
mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix B: Examples
digbyte Dval
movf Dig0, w
call Bcdto7seg ; Place LO mask on the PORTD
movwf PORTD
bsf PORTA, 0
goto ISR_end
; End of interrupt routine...
ISR_end
movf pclath_temp,w ; PCLATH register is given its original
movwf PCLATH ; state
movf status_temp,w ; STATUS register is given its original
movwf STATUS ; state
swapf w_temp,f ; W register is given its original
; state
swapf w_temp,w
retfie ; Return from interrupt routine
main
banksel ANSEL ; Selects bank containing ANSEL
clrf ANSEL ; All pins are digital
clrf ANSELH
BANKSEL TRISA
movlw b'11111100' ; RA0 and RA1 are configured as outputs and
; used for 7-segment display multiplexing
; RA2 is input push-button for initializa
; tion
movwf TRISA
clrf TRISD
BANKSEL OPTION_REG
movlw b'10000110' ; TMR0 is incremented each 32us (Fclk=8MHz)
movwf OPTION_REG
BANKSEL PORTA
movlw poc_vr
movwf Dval ; Dval contains counter value
movlw b'00000001' ; Initializes variable specifying display
movwf One ; to switch on
movwf PORTA
movlw .100
movwf TMR0 ; TMR0 interrupt appr.every 10ms
bsf INTCON, GIE ; Global interrupt enabled
bsf INTCON, T0IE ; Timer TMR0 interrupt enabled
bcf INTCON, T0IF
Loop
btfss One, 3 ; Falling edge encountered?
goto Dec ; Yes! Go to Dec
btfss PORTA, 2 ; Counter reset button pressed?
goto Reset ; Yes! Go to Reset
goto Loop
; Decrement Dval counter by 1
Dec
btfss One, 3
goto Dec
movf Dval, f
btfsc STATUS, Z ; Is Dval equal to 0?
goto Loop ; If it is, go to loop and wait for T2
decf Dval, f ; If Dval not equal to 0, decrement it by 1
goto Loop
Reset
btfss PORTA, 2 ; Wait for rising edge
goto Reset
movlw poc_vr
movwf Dval ; Write initial value to counter
goto Loop
;****************************************************************************
ORG 0x0300 ; Lookup table is at the top of third page, but
; can be placed at some other place, it is impor
http://www.mikroe.com/en/books/picmcubook/appb/ (43 of 54)5/3/2009 11:36:02 AM