Page 1 of 1

PCF8583 come posso settare le variabili ?

PostPosted: 29 Jun 2011, 07:45
by Atmega32
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

Re: PCF8583 SET TIME ?

PostPosted: 29 Jun 2011, 08:48
by tubincolo
Ti consiglio di non usare un ciclo infinito senza uscita.
Invece di più pulsanti, è sufficiente utilizzare un pulsante di incremento con un contatore per il ciclo delle rispettive variabili.
L'altro pulsante può essere un pulsante di configurazione per le diverse variabili (un conteggio per ogni ... mese, giorno, ora .....) e se l'ultimo conteggio è raggiunto si può ritornare al programma principale.
Il pulsante di configurazione può essere una subroutine di interrupt, in modo da non dover stare lì tutto il tempo.
Utilizza un antirimbalzo per la gestione dei pulsanti e un ritardo, in modo da non avere più di 50 conteggi in un secondo.
Ci sono molti modi per farlo. Se vuoi, potresti utilizzare più tasti e utilizzare un pulsante per ogni variabile.
Poi prima di tornare al programma principale basta scrivere i nuovi valori sull' RTC.

Buon lavoro...
Ciao