#define BUTTON PORTB,0
ORG 0x00 ;reset vector
goto main ;
ORG 0x04 ;Interrupt vector
movwf W_temp ;save W
swapf STATUS,W ;save status reg
movwf STATUS_temp ;
clrf STATUS ;make sure we are in bank 0, although we do not switch banks here
bcf PIR1, T1IF ;clear interrupt flag
bcf INTCON,T1ON ;stop the timer
movlw high (.65536-.1000) ;reload timer; the value may need to be adjusted slightly, to get exactly 1ms
movwf TMR1H ;
movlw low (.65536-.1000) ;
movwf TMR1L ;
incfsz Counter,F ;increment the 16 bit ms counter
incf Counter+1,F ;
swapf STATUS_temp,W ;restore registers
movwf STATUS ;
swapf W_temp,F ;
swapf W_temp,W ;
retfie ;return
main: ;main code
;put all your initializations here
clrf Counter ;clear the 16-bit counter
clrf Counter+1 ;
movlw B'10000000' ;enable interrupts in general
movwf INTCON ;
Wait_h: btfss BUTTON ;wait here until button pressed
goto Wait_h ;
movlw high (.65536-.1000) ;preload timer; value can be changed, so the first interrupt occurs exactly after 1ms
movwf TMR1H ;
movlw low (.65536-.1000) ;
movwf TMR1L ;
bsf T1CON,TMR1ON ;turn on TMR1
bcf PIR1,T1IF ;clear TMR1 interrupt flag, just in case
bsf INTCON,PIEI ;enable peripherals interrupts (TMR1 is a peripheral)
Wait_l: btfsc BUTTON ;wait for button to be released
goto Wait_l ;
Wait_r: btfss BUTTON ;wait for the rising edge here
goto Wait_r ;
bcf T1CON ;stop TMR1
bcf INTCON,PIEI ;disable peripheral interrupts
call DISPLAY ;call the routine that displays the time on the LCD
clrf Counter ;clear the 16-bit counter
clrf Counter+1 ;
Wait_f: btfsc BUTTON ;now wait here for a falling edge
goto Wait_f ;
goto Wait_h ;re-start the cycle
IamnotJunk said:PICbasic probably is a lot harder to be achieved than assembly language.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?