jsreis
Newbie level 3
- Joined
- Jun 29, 2013
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 41
Hello, I am new to pic microcontroller and need help.
I need to control a led AT GPIO,0 when a push button is pressed once the led will turn on and stay on for 90 minutes and then turn off waiting for the button be pressed again. but in between that time if I push the button for 2 sec will turn off led.
I try using delay rotine for 90 minutes and work fine but the problem is while the delay rotine was runing if I press the button for 2 sec nothing happen. so I have to use the TMR0 register and doing that I can't get long time delays.
please help me how I have to do.
here is some of my code.
Thanks,
SetUp
movwf OSCCAL ; update register with factory cal value
movlw b'10000111' ;10000111
;-0------, weak pullups ON
;--0-----, set TMR0
;---0----, set TOSE rising edge
;----0---, set PSA presacler as Timer0
;-----111, set presacale to 256
option ;increments at every 256us
movlw b'00001000' ;GPIO Register GPO,GP3
tris GPIO ;GP3 input, all others outputs
clrf GPIO ;make outputs LOW
Start
call Delay1 ;20mS debounce delay
btfsc GPIO,3 ;Is Sw LOW? - pushed
goto Start ;loop
call beep1 ;40mS beep
bsf GPIO,0 ;activate backlight
call Delay2
clrf cnt_65ms
Timer_90
clrf TMR0
; clrf cnt_65ms
w_tmr0
btfss GPIO,3
goto power_dw
movf TMR0,w
xorlw .255
btfss STATUS,Z
goto w_tmr0
incf cnt_65ms,f
movlw .955
xorwf cnt_65ms,w
btfss STATUS,Z
goto Timer_90
movlw .125
subwf cnt_65ms,w
btfss STATUS,C
call beep1
bcf GPIO,0
call beep1
; btfss GPIO,3
goto SetUp
power_dw ;look at sw if pushed more than 2sec turn off backlight
call Delay2 ;delay 1 second
btfsc GPIO,3 ;Is Sw LOW? - pushed
goto $-2
call Delay2 ;delay 1 second
; call Delay2 ;delay 1 second
btfsc GPIO,3 ;Is Sw LOW? - pushed
goto $-5
bcf GPIO,0 ;de-activate Backlight LED
call beep2 ;40mS beeps
call Delay2
call Delay2
nop
goto SetUp
;******************************************************************
; subroutines *
;******************************************************************
beep2 call beep1 ; 40mS beep
call Delay1 ; 20mS delay
beep1 movlw .40
movwf temp
goto $+1
decfsz DelA,1
goto $-2
movlw b'00000100' ;spkr pin
xorwf GPIO,F ;spkr bit will toggle
decfsz temp,1
goto $-6
retlw 00
Delay1 movlw .20 ; 20mS delay
movwf temp
goto $+1
decfsz DelA,1
goto $-2
decfsz temp,1
goto $-4
retlw 00
Delay2 movlw .50 ;1 Second delay
movwf DelB
call Delay1
decfsz DelB,1
goto $-2
retlw 00
END ; end of program
I need to control a led AT GPIO,0 when a push button is pressed once the led will turn on and stay on for 90 minutes and then turn off waiting for the button be pressed again. but in between that time if I push the button for 2 sec will turn off led.
I try using delay rotine for 90 minutes and work fine but the problem is while the delay rotine was runing if I press the button for 2 sec nothing happen. so I have to use the TMR0 register and doing that I can't get long time delays.
please help me how I have to do.
here is some of my code.
Thanks,
SetUp
movwf OSCCAL ; update register with factory cal value
movlw b'10000111' ;10000111
;-0------, weak pullups ON
;--0-----, set TMR0
;---0----, set TOSE rising edge
;----0---, set PSA presacler as Timer0
;-----111, set presacale to 256
option ;increments at every 256us
movlw b'00001000' ;GPIO Register GPO,GP3
tris GPIO ;GP3 input, all others outputs
clrf GPIO ;make outputs LOW
Start
call Delay1 ;20mS debounce delay
btfsc GPIO,3 ;Is Sw LOW? - pushed
goto Start ;loop
call beep1 ;40mS beep
bsf GPIO,0 ;activate backlight
call Delay2
clrf cnt_65ms
Timer_90
clrf TMR0
; clrf cnt_65ms
w_tmr0
btfss GPIO,3
goto power_dw
movf TMR0,w
xorlw .255
btfss STATUS,Z
goto w_tmr0
incf cnt_65ms,f
movlw .955
xorwf cnt_65ms,w
btfss STATUS,Z
goto Timer_90
movlw .125
subwf cnt_65ms,w
btfss STATUS,C
call beep1
bcf GPIO,0
call beep1
; btfss GPIO,3
goto SetUp
power_dw ;look at sw if pushed more than 2sec turn off backlight
call Delay2 ;delay 1 second
btfsc GPIO,3 ;Is Sw LOW? - pushed
goto $-2
call Delay2 ;delay 1 second
; call Delay2 ;delay 1 second
btfsc GPIO,3 ;Is Sw LOW? - pushed
goto $-5
bcf GPIO,0 ;de-activate Backlight LED
call beep2 ;40mS beeps
call Delay2
call Delay2
nop
goto SetUp
;******************************************************************
; subroutines *
;******************************************************************
beep2 call beep1 ; 40mS beep
call Delay1 ; 20mS delay
beep1 movlw .40
movwf temp
goto $+1
decfsz DelA,1
goto $-2
movlw b'00000100' ;spkr pin
xorwf GPIO,F ;spkr bit will toggle
decfsz temp,1
goto $-6
retlw 00
Delay1 movlw .20 ; 20mS delay
movwf temp
goto $+1
decfsz DelA,1
goto $-2
decfsz temp,1
goto $-4
retlw 00
Delay2 movlw .50 ;1 Second delay
movwf DelB
call Delay1
decfsz DelB,1
goto $-2
retlw 00
END ; end of program