Ciao a tutti spero in un aiuto!
Ho un problema con il PCF8583. Il display LCD funziona (HH: MM: SS) ed è molto bello, ma non so come impostare il tempo.
Il mio codice originale è da qui:
$regfile = "m32def.dat"
$crystal = 16000000
$baud = 9600
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.3 , Rs = Portc.2
'*********************
'********************
Config Sda = Portc.1
Config Scl = Portc.0
Config Pinb.0 = Input
Config Pinb.1 = Input
Config Pind.6 = Output
Portd.6 = 0
Portb.0 = 1
Portb.1 = 1
Config Timer0 = Timer , Prescale = 1024
Dim Ss As Byte , Mm As Byte , Hh As Byte , Day As Byte , Month As Byte
Dim Wm As Byte , Yd As Byte
Dim Sdatumzeit As String * 16
Dim Sstatus As String * 16
Const Rtc_w = &HA2
'RTC-Schreibadresse
Const Rtc_r = &HA3
'RTC-Leseadresse
Declare Sub Settime(ss As Byte , Mm As Byte , Hh As Byte , Day As Byte , Month As Byte)
Declare Sub Gettime
Month = 1
Day = 1
Hh = 23
Mm = 30
Ss = 20
Call Settime(ss , Mm , Hh , Day , Month)
On Timer0 Timer0_isr
Enable Interrupts
Enable Timer0
Cls
Do
Loop
End
Sub Gettime
I2cstart ' Start
I2cwbyte Rtc_w '
'Write-addresse PCF8583
I2cwbyte 2 ' select
'second register
I2cstart ' generate
'repeated start
I2cwbyte Rtc_r ' write
'address for reading
I2crbyte Ss , Ack ' read
'seconds
I2crbyte Mm , Ack ' read
'minuts
I2crbyte Hh , Ack ' read
'hours
I2crbyte Yd , Ack ' read
'year and days
I2crbyte Wm , Nack ' read
'weekday and month
I2crbyte Day , Ack ' read
'year and days
I2crbyte Month , Nack ' read
'weekday and month
I2cstop ' generate
'stop
End Sub
Sub Settime(ss As Byte , Mm As Byte , Hh As Byte , Day As Byte , Month As Byte)
Ss = Makebcd(ss) ' seconds
Mm = Makebcd(mm) ' minuts
Hh = Makebcd(hh) ' hours
Day = Makebcd(day) ' days
Month = Makebcd(month) ' months
I2cstart ' generate
'start
I2cwbyte Rtc_w ' write
'address
I2cwbyte 0 ' select
'control register
I2cwbyte 8 ' set year
'and day bit for masking
I2cstop ' generate
'stop
I2cstart ' generate
'start
I2cwbyte Rtc_w ' write
'mode
I2cwbyte 2 ' select
'seconds Register
I2cwbyte Ss ' write
'seconds
I2cwbyte Mm ' write
'minuts
I2cwbyte Hh
I2cwbyte Day ' write
'days
I2cwbyte Month
I2cstop
End Sub
Timer0_isr:
Call Gettime
Portb = Ss
Toggle Portb.7
Sdatumzeit = Bcd(hh) + ":" + Bcd(mm) + ":" + Bcd(ss)
Locate 1 , 1
Lcd Sdatumzeit
Locate 1 , 1
Return