$regfile = "m16def.dat"
$crystal = 8000000
Config Lcd = 20 * 4
Config Lcdpin = Pin , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 , Rs = Portc.5 , E = Portc.4
Lcd "1nafar"
Locate 1 , 1
Wait 3
Cursor Off
Cls
Config Porta = Input
Config Portb = Output
Config Portd = Input
Dim T1 As Word
Dim T2 As Word
Dim Keyb As Byte
Dim Key As Byte
Dim Saniye As Byte
Dim Daghighe As Byte
Dim Saat As Byte
Dim Rooz As Word
Dim Mah As Word
Dim Sal As Word
Dim Kbs As Bit
Dim A As Byte
Dim B As Byte
Dim C As Byte
Dim D As Byte
Dim E As Byte
Dim F As Byte
Dim G As Byte
Dim H As Byte
Dim I As Word
Dim K As Byte
Dim L As Byte
Dim M As Byte
Dim N As Word
Dim O As Word
Dim P As Byte
Rooz = 21
Mah = 4
Sal = 92
D = 255
E = 1
T2 = 300
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@
Config Adc = Single , Prescaler = Auto ,
Start Adc
Config Timer2 = Timer , Async = On , Prescale = 128
Enable Interrupts
Enable Timer2
On Timer2 Newtime
Stop Timer2
Timer1 = D
Start Timer2
Main:
Do
T1 = Getadc(0) : T1 = T1
Locate 4 , 7 : Lcd "LDR:" ; T1 ; " "
Config Debounce = 10
Debounce Pind.0 , 1 , Set_time
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
If Saniye > 59 Then
Incr Daghighe
Incr E
Saniye = 0
If Daghighe > 59 Then
Incr Saat
Daghighe = 0
Saniye = 0
If Saat > 23 Then
Saat = 0
Saniye = 0
Daghighe = 0
Incr Rooz
Incr A
If Sal = 91 Or Sal = 95 Or Sal = 99 Or Sal = 03 Or Sal = 07 Or Sal = 11 Or Sal = 15 Then
Kbs = 1
Else
Kbs = 0
End If
If Mah > 6 Then
Jmp Aa
Else
jmp bb
End If
Aa:
If Mah = 12 And Kbs = 0 Then
If Rooz > 29 Then
Rooz = 1 : Incr Mah : End If
Else
If Rooz > 30 Then
Rooz = 1 : Incr Mah : End If
End If
jmp cc
Bb:
If Rooz > 31 Then
Rooz = 1 : Incr Mah
End If
Cc:
If Mah > 12 Then
Incr Sal : Mah = 1 : Rooz = 1
End If
If Sal > 99 Then
Sal = 00
End If
End If
End If
End If
T1 = T1
T2 = T2
If T1 => T2 Then Set Portb.6
If T1 <= T2 Then Reset Portb.6
If Pina.1 = 0 Then I = 0
If I = 0 And Portb.6 = 1 And Pind.3 = 1 Then Set Portb.0
If I = 0 And Portb.6 = 1 And Pind.3 = 0 Then Reset Portb.0
If I = 0 And Portb.6 = 0 And Pind.3 = 1 Then Reset Portb.0
If I = 0 And Portb.6 = 0 And Pind.3 = 0 Then Set Portb.0
If I => 360 Then Reset Portb.0
If Pina.1 = 0 Then O = 0
If O => 320 And Portb.0 = 1 Then Set Portb.4
If O =< 320 And Portb.0 = 1 Then Reset Portb.4
If Pina.2 = 0 Then K = 0
If K = 0 Then Set Portb.1
If K => 180 Then Reset Portb.1
If Pina.2 = 0 Then N = 0
If N = 0 Then Set Portb.2
If N => 400 Then Reset Portb.2
If Pina.3 = 0 Then M = 0
If M = 0 Then Set Portb.3
If M => 180 Then Reset Portb.3
Locate 2 , 7
If Saat < 10 Then
Lcd "0" ; Saat ; ":"
Else
Lcd Saat ; ":"
End If
If Daghighe < 10 Then
Lcd "0" ; Daghighe ; ":"
Else
Lcd Daghighe ; ":"
End If
If Saniye < 10 Then
Lcd "0" ; Saniye ; " "
Else
Lcd Saniye ; " "
End If
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Locate 3 , 7
If Sal < 10 Then
Lcd "0" ; Sal ; "/"
Else
Lcd Sal ; "/"
End If
If Mah < 10 Then
Lcd "0" ; Mah ; "/"
Else
Lcd Mah ; "/"
End If
If Rooz < 10 Then
Lcd "0" ; Rooz ; " "
Else
Lcd Rooz ; " "
End If
If Portb.6 = 1 Then
Locate 1 , 8
Lcd " DAY "
Elseif Portb.6 = 0 Then
Locate 1 , 8
Lcd "NIGHT"
End If
If Portb.6 = 1 And Pind.3 = 1 Then
Locate 1 , 16
Lcd " EN "
Elseif Portb.6 = 1 And Pind.3 = 0 Then
Locate 1 , 16
Lcd " DI "
End If
If Portb.6 = 0 And Pind.3 = 1 Then
Locate 1 , 16
Lcd " DI "
Elseif Portb.6 = 0 And Pind.3 = 0 Then
Locate 1 , 16
Lcd " EN "
End If
If Portb.2 = 1 Then
Locate 1 , 1
Lcd "FAN"
Elseif Portb.2 = 0 Then
Locate 1 , 1
Lcd " "
End If
If Pina.1 = 0 Then
Locate 2 , 1
Lcd "1"
Elseif Pina.1 = 1 Then
Locate 2 , 1
Lcd " "
End If
If Pina.2 = 0 Then
Locate 3 , 1
Lcd "2"
Elseif Pina.2 = 1 Then
Locate 3 , 1
Lcd " "
End If
If Pina.3 = 0 Then
Locate 4 , 1
Lcd "3"
Elseif Pina.3 = 1 Then
Locate 4 , 1
Lcd " "
End If
If Portb.0 = 1 Then
Locate 2 , 18
Lcd " ON"
Elseif Portb.0 = 0 Then
Locate 2 , 18
Lcd "OFF"
End If
If Portb.1 = 1 Then
Locate 3 , 18
Lcd " ON"
Elseif Portb.1 = 0 Then
Locate 3 , 18
Lcd "OFF"
End If
If Portb.3 = 1 Then
Locate 4 , 18
Lcd " ON"
Elseif Portb.3 = 0 Then
Locate 4 , 18
Lcd "OFF"
End If
Loop
End
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Newtime:
Timer1 = D
Incr Saniye
Incr I
If I => 365 Then I = 1
Incr K
If K => 254 Then K = 1
Incr L
If L => 254 Then L = 1
Incr M
If M => 254 Then M = 1
Incr N
If N => 410 Then N = 1
Incr O
If O = 325 Then O = 1
Incr P
If P = 254 Then P = 1
If Portb.7 = 0 Then
Portb.7 = 1
Else
Portb.7 = 0
End If
Return
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Set_time:
Locate 4 , 7
Lcd " MIN "
Debounce Pind.1 , 1 , Incr_daghighe
Debounce Pind.2 , 1 , Decr_daghighe
Debounce Pind.0 , 1 , Set_time_h
jmp Set_time
Incr_daghighe:
Incr Daghighe
If Daghighe > 59 Then Daghighe = 0
Locate 2 , 10
If Daghighe < 10 Then
Lcd "0" ; Daghighe
Else
Lcd Daghighe
End If
jmp Set_time
Decr_daghighe:
Decr Daghighe
If Daghighe = 255 Then Daghighe = 59
Locate 2 , 10
If Daghighe < 10 Then
Lcd "0" ; Daghighe
Else
Lcd Daghighe
End If
jmp Set_time
Return
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Set_time_h:
Locate 4 , 7
Lcd " HOUR "
Debounce Pind.1 , 1 , Incr_saat
Debounce Pind.2 , 1 , Decr_saat
Debounce Pind.0 , 1 , Set_date
jmp Set_time_h
Incr_saat:
Incr Saat
If Saat > 23 Then Saat = 0
Locate 2 , 7
If Saat < 10 Then
Lcd "0" ; Saat
Else
Lcd Saat
End If
jmp Set_time_h
Decr_saat:
Decr Saat
If Saat = 255 Then Saat = 23
Locate 2 , 7
If Saat < 10 Then
Lcd "0" ; Saat
Else
Lcd Saat
End If
jmp Set_time_h
Return
'#########################################
Set_date:
Locate 4 , 7
Lcd " DAY "
Debounce Pind.1 , 1 , Incr_rooz
Debounce Pind.2 , 1 , Decr_rooz
Debounce Pind.0 , 1 , Set_mah_m
jmp Set_date
Incr_rooz:
Incr Rooz
If Rooz > 30 Then Rooz = 01
Locate 3 , 13
If Rooz < 10 Then
Lcd "0" ; Rooz
Else
Lcd Rooz
End If
jmp Set_date
Decr_rooz:
Decr Rooz
If Rooz = 65535 Then Rooz = 30
Locate 3 , 13
If Rooz < 10 Then
Lcd "0" ; Rooz
Else
Lcd Rooz
End If
jmp Set_date
Return
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Set_mah_m:
Locate 4 , 7
Lcd " MON "
Debounce Pind.1 , 1 , Incr_mah
Debounce Pind.2 , 1 , Decr_mah
Debounce Pind.0 , 1 , Set_sal_s
jmp Set_mah_m
Incr_mah:
Incr Mah
If Mah > 12 Then Mah = 01
Locate 3 , 10
If Mah < 10 Then
Lcd "0" ; Mah
Else
Lcd Mah
End If
jmp Set_mah_m
Decr_mah:
Decr Mah
If Mah = 65535 Then Mah = 12
Locate 3 , 10
If Mah < 10 Then
Lcd "0" ; Mah
Else
Lcd Mah
End If
jmp Set_mah_m
Return
'#####################################
Set_sal_s:
Locate 4 , 7
Lcd " YEAR "
Debounce Pind.1 , 1 , Incr_sal
Debounce Pind.2 , 1 , Decr_sal
Debounce Pind.0 , 1 , Set_t2
jmp Set_sal_s
Incr_sal:
Incr Sal
If Sal > 99 Then Sal = 0
Locate 3 , 7
If Sal < 10 Then
Lcd "0" ; Sal
Else
Lcd Sal
End If
jmp Set_sal_s
Decr_sal:
Decr Sal
If Sal = 65535 Then Sal = 99
Locate 3 , 7
If Sal < 10 Then
Lcd "0" ; Sal
Else
Lcd Sal
End If
jmp Set_sal_s
Return
'##############################################
Set_t2:
Locate 2 , 5
Lcd " SET LDR "
Locate 3 , 5
Lcd " LDR: " ; T2 ; " "
Locate 4 , 7
Lcd " "
Waitms 20
Debounce Pind.1 , 1 , Incr_t2
Debounce Pind.2 , 1 , Decr_t2
Debounce Pind.0 , 1 , Main
jmp Set_T2
Return
Incr_t2:
Incr T2
If T2 > 975 Then T2 = 10
jmp Set_T2
Return
Decr_t2:
Decr T2
If T2 < 10 Then T2 = 975
jmp Set_T2
Return