Code:
EEPROM 1,[1,2,3,4,5,6,7,8,9,10,101,102,103,104,105,106,107,108,109,110]
'Keep this command at the first line.
'this will run only one time during the programming.
'not each time you power your PIC.
'These are your initial default values.
Increase_OnTime_Push_Button VAR PORTD.2 '(pin 21) 2nd
Decrease_OnTime_Push_Button VAR PORTB.0 '(pin 33) 3rd
Increase_OffTime_Push_Button VAR PORTB.1 '(pin 34) 4th
Decrease_OffTime_Push_Button VAR PORTB.2 '(pin 20) 5th
Change_On_Off_Time_Push_Button VAR PORTD.1 '(pin 35) 6th
Led VAR PORTA.1 '(pin 3)
Buzzer VAR PORTC.2 '(pin 17)
IncrFlag VAR BIT
DecrFlag VAR BIT
OnTime VAR byte
OffTime VAR byte
Index VAR byte
Hour VAR byte
HOUR = 0
Is_Pressed CON 0
Is_Not_Pressed CON 1
IncrFlag = 0 '0 = button is NOT pressed. 1= button is pressed.
DecrFlag = 0
GOTO MainLoop
Change_On_Off_Time:
WHILE Change_On_Off_Time_Push_Button = Is_Pressed : GOSUB buzz : WEND
Loop:
IF Increase_OnTime_Push_Button = Is_Pressed THEN
WHILE Increase_OnTime_Push_Button = Is_Pressed : GOSUB buzz : WEND
IncrFlag = 1
OnTime = OnTime + 1
ENDIF
IF Decrease_OnTime_Push_Button = Is_Pressed THEN
WHILE Decrease_OnTime_Push_Button = Is_Pressed : GOSUB buzz : WEND
IncrFlag = 1
OnTime = OnTime - 1
ENDIF
IF Increase_OffTime_Push_Button = Is_Pressed THEN
WHILE Increase_OffTime_Push_Button = Is_Pressed : GOSUB buzz : WEND
DecrFlag = 1
OffTime = OffTime + 1
ENDIF
IF Decrease_OffTime_Push_Button = Is_Pressed THEN
WHILE decrease_OffTime_Push_Button = Is_Pressed : GOSUB buzz : WEND
DecrFlag = 1
OffTime = OffTime - 1
ENDIF
IF Change_On_Off_Time_Push_Button = Is_Pressed THEN
WHILE Change_On_Off_Time_Push_Button = Is_Pressed : GOSUB buzz : WEND
IF IncrFlag THEN WRITE 1, OnTime 'If zero, then it means OnTime never changed.
IF DecrFlag THEN WRITE 101,OffTime 'If zero, then it means OffTime never changed.
gosub buzz ''''
pause 100 'kind a confirmation sound.
gosub buzz ''''
GOTO MainLoop
ENDIF
LCDOUT $fe,1, "OnTime = ",dec Ontime
LCDOUT $fe, $c0,"OffTime = ",dec OffTime
PAUSE 10
GOTO Loop
MainLoop:
IF Change_On_Off_Time_Push_Button = Is_Pressed THEN goto Change_On_Off_Time
'Hour variable gets its value here......
IF Increase_OnTime_Push_Button = Is_Pressed THEN
WHILE Increase_OnTime_Push_Button = Is_Pressed : GOSUB buzz : WEND
Hour = Hour + 1
ENDIF
'Hour variable gets its value here......
IF Decrease_OnTime_Push_Button = Is_Pressed THEN
WHILE Decrease_OnTime_Push_Button = Is_Pressed : GOSUB buzz : WEND
Hour = Hour - 1
ENDIF
FOR Index = 1 to 10
READ Index , OnTime ' Read stored ON time.
READ Index +100, OffTime ' Read stored OFF time.
IF Hour = Ontime THEN Led = 1 ' If yes, turn ON the relay.
IF Hour = Offtime THEN Led = 0 ' If yes, turn OFF the relay.
NEXT Index
LCDOUT $fe,1, "Hr=",dec Hour," OnTime=",DEC Ontime
LCDOUT $fe, $c0,"OffTime = ",DEC OffTime
PAUSE 100
GOTO MainLoop
Buzz:
PWM Buzzer,250,1
RETURN
END
Bookmarks