Code:
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 9600
$lib "ds1307rtc.lib" ' modified lib
Declare Sub Gettemp()
Declare Sub Enterdatetime()
Declare Sub Getkey()
Declare Sub Getkey2()
Declare Sub Menu()
'Declare Sub Checklight()
'Config
Config Lcdpin = Pin , Db4 = Portb.5 , Db5 = Portb.4 , Db6 = Portb.3 , Db7 = Portb.2 , E = Portb.1 , Rs = Portd.7
Config Lcd = 20 * 4
Cursor Off
Config Sda = Portc.4
Config Scl = Portc.5
Config 1wire = Portb.0
Config Clock = User
Config Date = Dmy , Separator = -
Config Pinb.6 = Output 'lamp4
Config Pinb.7 = Output 'lamp3
Config Pind.6 = Output 'lamp1
Config Pind.5 = Output 'lamp2
Config Pinc.1 = Input 'enter button & enter the menu
Config Pinc.2 = Input 'down button
Config Pinc.3 = Input 'up button
Portc.3 = 1
Portc.2 = 1
Portc.1 = 1
Portd.6 = 0
Portd.5 = 0
Portb.7 = 0
Portb.6 = 0
Time$ = "21:08:40" ' to watch the day changing value
Date$ = "03-12-06"
'Dim Weekday As Byte
'Dim Ds1307w As Byte
'Dim Ds1307r As Byte
Dim Scrachpad(8) As Byte
Dim Tmp As Integer
Dim Wynik As Single
Dim Temp As String * 10
Dim Temp1 As String * 10
Dim Temp2 As String * 10
Dim Lightsonmin As Word 'light on time converted to minutes
Dim Lightsoffmin As Word 'light off time converted to minutes
Dim Currentmin As Word
Dim Eventhrs As Byte 'event hrs
Dim Eventmin As Byte 'event minutes
Dim Oldmin As Byte
'Dim Gp1 As Byte 'general purpose variable
'Dim Gp2 As Byte 'general purpose variable
'Dim Gp3 As Byte 'general purpose variable
'Dim Gp4 As Byte 'general purpose variable
Dim J1 As Byte 'used by date and time subs
Dim M1 As Byte
Dim D1 As Byte
Dim H1 As Byte 'used by date and time subs
Dim Min1 As Byte
Dim Aa As Byte 'sw var
Dim X1 As Byte 'klok var
Dim Z1 As Byte
Dim Z2 As Byte
'Constants for DS18b20
Const Skip_rom = &HCC
Const Convert = &H44
Const Read_sp = &HBE
Const Write_sp = &H4E
'Constands for DS1307
'address of ds1307
Const Ds1307w = &HD0 ' Addresses of Ds1307 clock
Const Ds1307r = &HD1
'---------------------------------
'Config Timer1 = Timer , Prescale = 256 'Konfiguriere Timer1
'Enable Timer1 'schalte den Timer1 ein
'On Timer1 Gettemp 'verzweige bei Timer1 überlauf zu Isr_von_Timer1
'Enable Interrupts
'Timer1 = 34285
Waitms 100
' assigning the time will call the SetTime routine
$eepromhex 'tell compiler to write in Intel hex format
$eeprom
Lights1on:
Data 21 , 09
Lights1off:
Data 21 , 10
Lights1_on:
Data 21 , 12
Lights1_off:
Data 21 , 14
Lights2on:
Data 21 , 10
Lights2off:
Data 21 , 15
Lights2_on:
Data 21 , 16
Lights2_off:
Data 21 , 17
Lights3on:
Data 21 , 10
Lights3off:
Data 21 , 15
Lights3_on:
Data 21 , 16
Lights3_off:
Data 21 , 17
Lights4on:
Data 21 , 09
Lights4off:
Data 21 , 10
Lights4_on:
Data 0 , 0
Lights4_off:
Data 0 , 0
$data
Cls
Start:
Do
Locate 1 , 1
Lcd "Datum: " ; Date$ ; " "
Locate 2 , 1
Lcd "Tijd: " ; Time$ ; " "
If _min <> Oldmin Then
Gettemp
Locate 3 , 1
Lcd "Temp: " ; Temp
End If
If _sec = 5 Then
Goto Checklights
End If
If Pinc.1 = 0 Then
Menu
End If
'Wait 1
Loop
End
'called from ds1307clock.lib
Getdatetime:
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' start address in 1307
I2cstart ' Generate start code
I2cwbyte Ds1307r ' send address
I2crbyte _sec , Ack
I2crbyte _min , Ack ' MINUTES
I2crbyte _hour , Ack ' Hours
'I2crbyte Weekday , Ack ' Day of Week
I2crbyte _day , Ack ' Day of Month
I2crbyte _month , Ack ' Month of Year
I2crbyte _year , Nack ' Year
I2cstop
_sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
_day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
Return
Setdate:
_day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 4 ' starting address in 1307
I2cwbyte _day ' Send Data to SECONDS
I2cwbyte _month ' MINUTES
I2cwbyte _year ' Hours
I2cstop
Return
Settime:
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' starting address in 1307
I2cwbyte _sec ' Send Data to SECONDS
I2cwbyte _min ' MINUTES
I2cwbyte _hour ' Hours
I2cstop
Return
' SUBS *******************************************************************
Sub Enterdatetime()
Cls
X1 = 05
Aa = 0
Do
If X1 > 99 Then X1 = 00
If X1 < 1 Then X1 = 99
Waitms 300
Locate 1 , 1
Lcd "Geef Het Jaar: " ; X1 ; " "
Getkey
J1 = X1
Loop Until Aa = 1
Cls
Aa = 0
X1 = 06
Do
If X1 > 12 Then X1 = 01
If X1 < 1 Then X1 = 12
Waitms 300
Locate 1 , 1
Lcd "Geef de maand: " ; X1 ; " "
Getkey
M1 = X1
Loop Until Aa = 1
Cls
Aa = 0
X1 = 15
Do
If X1 > 31 Then X1 = 01
If X1 < 1 Then X1 = 31
Waitms 300
Locate 1 , 1
Lcd "Geef de dag: " ; X1 ; " "
Getkey
D1 = X1
Loop Until Aa = 1
_year = J1
_month = M1
_day = D1
Gosub Setdate
Cls
Aa = 0
X1 = 12
Do
If X1 > 24 Then X1 = 01
If X1 < 1 Then X1 = 24
Waitms 300
Locate 1 , 1
Lcd "Geef het uur: " ; X1 ; " "
Getkey
H1 = X1
Loop Until Aa = 1
Cls
Aa = 0
X1 = 30
Do
If X1 > 59 Then X1 = 00
If X1 < 01 Then X1 = 59
Locate 1 , 1
Lcd "Geef minuten: " ; X1 ; " "
Getkey
Min1 = X1
Loop Until Aa = 1
_hour = H1
_min = Min1
_sec = 0
Gosub Settime
End Sub
Sub Getkey()
Waitms 300
If Pinc.3 = 0 Then Incr X1
If Pinc.2 = 0 Then Decr X1
If Pinc.1 = 0 Then
Aa = 1
Else
Aa = 0
End If
End Sub
Sub Getkey2()
Waitms 300
If Pinc.3 = 0 Then Incr Z1
If Pinc.2 = 0 Then Decr Z1
If Pinc.1 = 0 Then
Aa = 1
Else
Aa = 0
End If
End Sub
Sub Menu()
Aa = 0
X1 = 0
Cls
Locate 1 , 1
Lcd " Menu "
Locate 2 , 1
Lcd "up/down voor keuze"
Do
Getkey
If X1 = 1 Then
Locate 4 , 1
Lcd "klok instellen "
Elseif X1 = 2 Then
Locate 4 , 1
Lcd "SW1 programeren"
Elseif X1 = 3 Then
Locate 4 , 1
Lcd "SW1-2 programeren"
Elseif X1 = 4 Then
Locate 4 , 1
Lcd "SW2 programeren"
Elseif X1 = 5 Then
Locate 4 , 1
Lcd "SW2-2 programeren"
Elseif X1 = 6 Then
Locate 4 , 1
Lcd "SW3 programeren"
Elseif X1 = 7 Then
Locate 4 , 1
Lcd "SW3-2 programeren"
Elseif X1 = 8 Then
Locate 4 , 1
Lcd "SW4 programeren"
Elseif X1 = 9 Then
Locate 4 , 1
Lcd "SW4-2 programeren"
Elseif X1 = 10 Then
Locate 4 , 1
Lcd "menu verlaten "
Elseif X1 > 10 Then
X1 = 1
Elseif X1 < 1 Then
X1 = 10
End If
Loop Until Aa = 1
If X1 = 10 Then
Cls
Return
Elseif X1 = 9 Then
Gosub T4s
Elseif X1 = 8 Then
Gosub T4
Elseif X1 = 7 Then
Gosub T3s
Elseif X1 = 6 Then
Gosub T3
Elseif X1 = 5 Then
Gosub T2s
Elseif X1 = 4 Then
Gosub T2
Elseif X1 = 3 Then
Gosub T1s
Elseif X1 = 2 Then
'Temp1 = "Lights1on "
'Temp2 = "Lights1off"
Gosub T1
Elseif X1 = 1 Then
Enterdatetime
End If
End Sub
T1:
Cls
Locate 1 , 1
Lcd "SW1 aan progr 1"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights1on
Writeeeprom M1
Cls
Locate 1 , 1
Lcd "SW1 uit progr 1"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights1off
Writeeeprom M1
Return
T1s:
Cls
Locate 1 , 1
Lcd "SW1 aan progr 2"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights1_on
Writeeeprom M1
Cls
Locate 1 , 1
Lcd "SW1 uit progr 2"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights1_off
Writeeeprom M1
Return
T2:
Cls
Locate 1 , 1
Lcd "SW2 aan progr 1"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights2on
Writeeeprom M1
Cls
Locate 1 , 1
Lcd "SW2 uit progr 1"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights2off
Writeeeprom M1
Return
T2s:
Cls
Locate 1 , 1
Lcd "SW2 aan progr 2"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights2_on
Writeeeprom M1
Cls
Locate 1 , 1
Lcd "SW2 uit progr 2"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights2_off
Writeeeprom M1
Return
T3:
Cls
Locate 1 , 1
Lcd "SW3 aan progr 1"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights3on
Writeeeprom M1
Cls
Locate 1 , 1
Lcd "SW3 uit progr 1"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights3off
Writeeeprom M1
Return
T3s:
Cls
Locate 1 , 1
Lcd "SW3 aan progr 2"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights3_on
Writeeeprom M1
Cls
Locate 1 , 1
Lcd "SW3 uit progr 2"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights3_off
Writeeeprom M1
Return
T4:
Cls
Locate 1 , 1
Lcd "SW4 aan progr 1"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights4on
Writeeeprom M1
Cls
Locate 1 , 1
Lcd "SW4 uit progr 1"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights4off
Writeeeprom M1
Return
T4s:
Cls
Locate 1 , 1
Lcd "SW4 aan progr 2"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights4_on
Writeeeprom M1
Cls
Locate 1 , 1
Lcd "SW4 uit progr 2"
Aa = 0
Gosub Lamp
Writeeeprom H1 , Lights4_off
Writeeeprom M1
Return
Lamp:
Do
If Z1 > 24 Then Z1 = 01
If Z1 < 1 Then Z1 = 24
Waitms 300
Locate 2 , 1
Lcd "Geef het uur: " ; Z1 ; " "
Getkey2
H1 = Z1
Loop Until Aa = 1
Do
If Z1 > 59 Then Z1 = 00
If Z1 < 01 Then Z1 = 59
Waitms 300
Locate 2 , 1
Lcd "Geef de minuten: " ; Z1 ; " "
Getkey2
M1 = Z1
Loop Until Aa = 1
Return
Checklights:
Readeeprom Eventhrs , Lights1on
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portd.6 = 1
Locate 4 , 1
Lcd "sw1+" 'turn on light 1
End If
End If
Readeeprom Eventhrs , Lights1off
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portd.6 = 0
Locate 4 , 1
Lcd "sw1-" 'turn off light 1
End If
End If
Readeeprom Eventhrs , Lights1_on
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portd.6 = 1
Locate 4 , 1
Lcd "sw1s+" 'turn on light 1 second
End If
End If
Readeeprom Eventhrs , Lights1_off
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portd.6 = 0
Locate 4 , 1
Lcd "sw1s-" 'turn off light 1 second
End If
End If
Readeeprom Eventhrs , Lights2on
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portd.5 = 1
Locate 4 , 7
Lcd "sw2+" 'turn on light 2
End If
End If
Readeeprom Eventhrs , Lights2off
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portd.5 = 0
Locate 4 , 7
Lcd "sw2-" 'turn off light 2
End If
End If
Readeeprom Eventhrs , Lights2_on
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portd.5 = 1
Locate 4 , 7
Lcd "sw2s+" 'turn on light 2 second
End If
End If
Readeeprom Eventhrs , Lights2_off
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portd.5 = 0
Locate 4 , 7
Lcd "sw2s-" 'turn off light 2 second
End If
End If
Readeeprom Eventhrs , Lights3on
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portb.7 = 1
Locate 4 , 13
Lcd "sw3+" 'turn on light 3
End If
End If
Readeeprom Eventhrs , Lights3off
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portb.7 = 0
Locate 4 , 13
Lcd "sw3-" 'turn off light 3
End If
End If
Readeeprom Eventhrs , Lights3_on
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portb.7 = 1
Locate 4 , 13
Lcd "sw3s+" 'turn on light 3 second
End If
End If
Readeeprom Eventhrs , Lights3_off
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portb.7 = 0
Locate 4 , 13
Lcd "sw3s-" 'turn off light 3 second
End If
End If
Readeeprom Eventhrs , Lights4on
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portb.6 = 1
Locate 3 , 13
Lcd "sw4+" 'turn on light 4
End If
End If
Readeeprom Eventhrs , Lights4off
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portb.6 = 0
Locate 3 , 13
Lcd "sw4-" 'turn off light 4
End If
End If
Readeeprom Eventhrs , Lights4_on
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portb.6 = 1
Locate 3 , 13
Lcd "sw4s+" 'turn on light 4 second
End If
End If
Readeeprom Eventhrs , Lights4_off
Readeeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Portb.6 = 0
Locate 3 , 13
Lcd "sw4s-" 'turn off light 4 second
End If
End If
Goto Start
Sub Gettemp()
1wreset
1wwrite Skip_rom
1wwrite Write_sp
1wwrite 0
1wwrite 0
1wwrite &H7F
1wreset
1wwrite Skip_rom
1wwrite Convert
Waitms 800
1wreset
1wwrite Skip_rom
1wwrite Read_sp
Scrachpad(1) = 1wread()
Scrachpad(2) = 1wread()
Tmp = Scrachpad(2) * 256
Tmp = Tmp + Scrachpad(1)
Wynik = Tmp
Wynik = Wynik / 16
Temp = Fusing(wynik , "#.##")
Oldmin = _min
End Sub
End
mein iedee ist um ein schaltuhr su machen der 4 220 volt contacte seperat schalted und am liebsten mit 2 oder mehr versiedene seiten die man programieren kan.naturlich die uhr ist aug su programieren.
Lesezeichen