View previous topic :: View next topic |
Author |
Message |
padron70
Joined: 08 Dec 2005 Posts: 7
|
Problem with Pcf8583-> month incorrect |
Posted: Wed Feb 22, 2006 2:01 pm |
|
|
I have a problem with the lecture of the month in the pcf8583:
Code: |
dat2=read_pcf(0x03);
dat3=read_pcf(0x04);
dat4=read_pcf(0x05);
dat5=read_pcf(0x06);//month
|
i don't know how show the month correctly, with a change of day, for example -> 28 /2 the following month is 1/13...
do you know As I must take the data from the month (dat5)?
Projects Pic: http://mrpelectronica.webcindario.com/index.htm |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 22, 2006 2:12 pm |
|
|
That register also contains the Weekdays. There is also a Mask bit
in the Control/Status register, that can configure the read operation
to mask off the Weekdays when you just want to read the Months.
Also, there may be a problem with your method of converting BCD
to binary, or in your printf statement.
You need to post the code that shows how you do the BCD to binary
conversion and also your printf code. |
|
|
padron70
Joined: 08 Dec 2005 Posts: 7
|
|
Posted: Wed Feb 22, 2006 2:20 pm |
|
|
This is the code:
Code: |
if (hora==1)//mostra a hora
{
dat1=read_pcf(0x02);
dat2=read_pcf(0x03);
dat3=read_pcf(0x04);
dat4=read_pcf(0x05);
dat5=read_pcf(0x06);
lcd_ponc("\f");
lcd_vaixy(1,1);
printf(lcd_ponc,"%u:%u:%u ",
bcd2bin(dat3),bcd2bin(dat2),bcd2bin(dat1));
lcd_vaixy(1,2);
printf(lcd_ponc,"Fecha= %u del %u ",
bcd2bin(dat4),bcd2bin(dat5));
}
|
The bcd2bin function is:
Code: |
#define bcd2bin(val) ((val)&15)+((val)>>4)*10
|
this function I believe that I have taken it of this forum. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 22, 2006 2:47 pm |
|
|
But what about the Mask bit of the Control/Status register ?
The data sheet says:
Quote: |
Mask flag:
0: Read locations 05 to 06 unmasked
1: Read date and month count |
The power-up state for that register is all 0's.
This means you will read the Weekday along with the month,
unless you set the Mask bit = 1.
Quote: | reset state: 0000 0000 |
What value are you writing to the Control/Status register,
to initialize it ? |
|
|
padron70
Joined: 08 Dec 2005 Posts: 7
|
|
Posted: Wed Feb 22, 2006 2:56 pm |
|
|
This is the initial configuration:
Code: |
// configura calendario
write_pcf(0x00,0x00);//control status
write_pcf(0x02,bin2bcd(0x00));//segundos inicial
write_pcf(0x03,bin2bcd(59));//minuto inicial
write_pcf(0x04,bin2bcd(23));//hora inicial
write_pcf(0x05,bin2bcd(2));//dia incial
write_pcf(0x06,bin2bcd(2));//mes inicial
// fin conf. calendario
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 22, 2006 3:01 pm |
|
|
Quote: | write_pcf(0x00,0x00);//control status |
You need to set the Mask bit in the Control/Status register = 1.
Download the PCF8583 data sheet and look at page 6.
What value should you write to the Control/Status register,
instead of 0x00, so that the Mask bit is set = 1 ?
http://www.semiconductors.philips.com/acrobat/datasheets/PCF8583_5.pdf
Determine the value, and then edit your write_pcf() statement above
to write the correct value. |
|
|
padron70
Joined: 08 Dec 2005 Posts: 7
|
|
Posted: Wed Feb 22, 2006 3:06 pm |
|
|
Thank you, PCM .
I working...mask flag:1 (read date and month count directly) |
|
|
|