Hi I’m doing a small project using PIC16F628A.It’s a one hour timer.
It’s having two digits & it’s having only two buttons,
RA2 - count up button
RA3 – set button
RB7 – output LED
I wrote a program listed below. The counting part works very well. Every time when I press the count up button it counts to 0 to 59 at each press. It works well.
Now I want to use the other button (set button).If you count up 5 & press the set button it must give a 5 minutes delay. If you count up 10 & press the set button it must give 10 minutes delay etc…
Calculating delays of course ok. But I don’t know how to detect the value at present.
What’s the coding do I have to write? Where is the best place to keep the set button coding?
But I tried something like this to detect the value at present. I don’t know whether its right please helps me.
Thanks
It’s having two digits & it’s having only two buttons,
RA2 - count up button
RA3 – set button
RB7 – output LED
I wrote a program listed below. The counting part works very well. Every time when I press the count up button it counts to 0 to 59 at each press. It works well.
Code:
LIST p=16F628A
include "P16F628A.inc"
cblock 0x20
DIGIT1
DIGIT2
d1
d2
d3
d4
Flag
endc
PC EQU 02H
STATUS EQU 03H
PORTA EQU 05H
PORTB EQU 06H
TRISA EQU 85H
TRISB EQU 86H
CMCON EQU 1FH
org 0x00
movlw 0x07
movwf CMCON ;turn comparators off
bsf STATUS,5
movlw b'01100' ;RA2,RA3 inputs
movwf TRISA
movlw b'00000000' ;portB all outputs
movwf TRISB
bcf STATUS,5
clrf Flag
goto START
TABLE addwf PC,1
retlw b'00111111' ;0
retlw b'00000110' ;1
retlw b'01011011' ;2
retlw b'01001111' ;3
retlw b'01100110' ;4
retlw b'01101101' ;5
retlw b'01111101' ;6
retlw b'00000111' ;7
retlw b'01111111' ;8
retlw b'01101111' ;9
START clrf DIGIT1
clrf DIGIT2
;***********display the digit1***************
STAY bcf Flag,0 ;clear the button press flag
LOOP bcf PORTA,0 ;disable digit2
movf DIGIT1,0
call TABLE
movwf PORTB
bsf PORTA,1 ;enable digit1
call Delay
;***********display the digit2***************
bcf PORTA,1 ;disable digit1
movf DIGIT2,0
call TABLE
movwf PORTB
bsf PORTA,0 ;enable digit2
call Delay
;**********check the button is pressed*******
MAIN btfsc PORTA,2 ;test the button on portA
goto STAY
call DELAY1 ;debounce delay
btfsc PORTA,2
goto STAY
btfsc Flag,0 ;button pressed first time(calling a flag)
goto LOOP
goto COUNTUP
;**********update digit1 & digit2************
COUNTUP incf DIGIT1,1 ;increase digit1
movlw 0AH ;load with ten
xorwf DIGIT1,0 ;compare
btfss STATUS,2
goto LOOP1
clrf DIGIT1
incf DIGIT2,1 ;increase digit2
movlw 06H ;load with six
xorwf DIGIT2,0 ;compare
btfsc STATUS,2
clrf DIGIT2
LOOP1 bsf Flag,0 ;set button press flag
goto LOOP
;-------------display delay 10ms------------------------
Delay movlw 0xcF ;10ms
movwf d3
movlw 0x08
movwf d4
Delay_1
decfsz d3, f
goto $+2
decfsz d4, f
goto Delay_1
goto $+1
RETURN
;--------button debounce delay 0.0009S------------------
DELAY1 movlw 0xB3
movwf d1
movlw 0x01
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
goto $+1
RETURN
end
Calculating delays of course ok. But I don’t know how to detect the value at present.
What’s the coding do I have to write? Where is the best place to keep the set button coding?
But I tried something like this to detect the value at present. I don’t know whether its right please helps me.
Code:
btfsc PORTA,3 ;test the SET button RA3
goto
call DELAY1 ;debounce delay
btfsc PORTA,3
goto
btfsc Flag,0
goto
goto Detect1
Detect1 movlw 01H ;Detects number 1
xorwf DIGIT1,0
btfss STATUS,2
goto Detect2 ;its not 1 then goto next
goto Delay1min ;call 1minute delay
Detect2 movlw 02H ;Detects number 2
xorwf DIGIT1,0
btfss STATUS,2
goto Detect3 ;its not 2 then goto next
goto Delay2min ;call 2minutes delay
Detect3 ----
----
Thanks