Académique Documents
Professionnel Documents
Culture Documents
Page 1 of 4
Loginway
//--------Pin definition--------//
#define PCF8583_SDA PIN_C4
#define PCF8583_SCL PIN_C3
http://loginway.net/pcf8583-real-time-clock-pic16f877a-project-on-the-pic-01-developmen... 9/21/2010
Loginway » The PCF8583 Real Time Clock & PIC16F877A project on the PIC-01 Devel... Page 2 of 4
#ifndef PCF8583_WRITE_ADDRESS
#define PCF8583_WRITE_ADDRESS 0xA0 //Pin A0 Low
#define PCF8583_READ_ADDRESS 0xA1
#endif
void init_PCF8583() {
output_float(PCF8583_SCL);
output_float(PCF8583_SDA);
}
BOOLEAN PCF8583_ready() {
int1 ack;
i2c_start();
ack = i2c_write(PCF8583_WRITE_ADDRESS);
i2c_stop();
return !ack;
}
while(!PCF8583_ready());
i2c_start();
i2c_write(PCF8583_WRITE_ADDRESS);
i2c_write(address);
i2c_start();
i2c_write(PCF8583_READ_ADDRESS);
data=i2c_read(0);
i2c_stop();
return(data);
}
The rtc.c listing shows has to read date and time from the
PCF8583.
//-------------------------------
// rtc.c
// pcf8583p RTC
#include<16f877a.h> //Device
#use delay (clock=4000000) //4.00 MHz
http://loginway.net/pcf8583-real-time-clock-pic16f877a-project-on-the-pic-01-developmen... 9/21/2010
Loginway » The PCF8583 Real Time Clock & PIC16F877A project on the PIC-01 Devel... Page 3 of 4
#include<pcf8583.h>
void main(void)
{
lcd_init(); //lcd start
lcd_init_custom_chars();
init_PCF8583();while(TRUE)
{
delay_ms(100);
lcd_gotoxy(1,1);
weekday=read_PCF8583(0x06);
weekday>>=5;
printf(lcd_putc,"%s",weekday_names[weekday]);
day=read_PCF8583(0x05);
printf(lcd_putc," %x/",day&0x3f);
month=read_PCF8583(0x06);
printf(lcd_putc,"%x/",month&0x1f);
year=read_PCF8583(0x05);
printf(lcd_putc,"20%x",year&0xc0);
hour=read_PCF8583(0x04);
printf(lcd_putc,"\n%x:",hour);
min=read_PCF8583(0x03);
printf(lcd_putc,"%x:",min);
sec=read_PCF8583(0x02);
printf(lcd_putc,"%x",sec);
}
For further development, it would be sensible to include set_time() and set_date() functions
and using interrupts.
http://loginway.net/pcf8583-real-time-clock-pic16f877a-project-on-the-pic-01-developmen... 9/21/2010
Loginway » The PCF8583 Real Time Clock & PIC16F877A project on the PIC-01 Devel... Page 4 of 4
rtc.hex (.zip)
PCF8583.h (.zip)
© 2010 Loginway
Subscribe to feed
Powered by WordPress | Theme design by Andreas Viklund
Bad Behavior has blocked 61 access attempts in the last 7 days.
http://loginway.net/pcf8583-real-time-clock-pic16f877a-project-on-the-pic-01-developmen... 9/21/2010