Hallo habe jezt dem uhr laufen auf nem lcd.
aber wie schreibe ich ein routiner sum einstellen fon dieser uhr.
also datum und seit, mit 2 oder 4 taster.
Code:
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 9600
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2
Config Lcd = 20 * 4
Config Sda = Portc.4
Config Scl = Portc.5
Cls
$lib "mcsbyte.lbx" ' for smaller code
$lib "ds1307rtc.lib" ' modified lib
'address of ds1307
Const Ds1307w = &HD0 ' Addresses of Ds1307 clock
Const Ds1307r = &HD1
Config Clock = User ' this will dim the bytes automatic
'dim other needed variables
Dim Weekday As Byte
Locate 1 , 1
Lcd "DS1307"
Waitms 100
' assigning the time will call the SetTime routine
Time$ = "23:58:59" ' to watch the day changing value
Date$ = "11-13-02" ' 13 november 2002
Do
Cls
Locate 1 , 1
Lcd "Datum: " ; Date$ ;
Locate 2 , 1
Lcd "Tijd: " ; Time$
Waitms 500
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
Lesezeichen