Datasheet

Library Example
The example demonstrates Software I˛C Library routines usage. The AVR MCU is
connected (SCL, SDA pins) to PCF8583 RTC (real-time clock). Program reads date
and time are read from the RTC and prints it on LCD.
char seconds, minutes, hours, day, month, year; // Global date/time
variables
// Software I2C connections
sbit Soft_I2C_Scl_Output at PORTC.B0;
sbit Soft_I2C_Sda_Output at PORTC.B1;
sbit Soft_I2C_Scl_Input at PINC.B0;
sbit Soft_I2C_Sda_Input at PINC.B1;
sbit Soft_I2C_Scl_Direction at DDRC.B0;
sbit Soft_I2C_Sda_Direction at DDRC.B1;
// End Software I2C connections
// LCD module connections
sbit LCD_RS at PORTD.B2;
sbit LCD_EN at PORTD.B3;
sbit LCD_D4 at PORTD.B4;
sbit LCD_D5 at PORTD.B5;
sbit LCD_D6 at PORTD.B6;
sbit LCD_D7 at PORTD.B7;
sbit LCD_RS_Direction at DDRD.B2;
sbit LCD_EN_Direction at DDRD.B3;
sbit LCD_D4_Direction at DDRD.B4;
sbit LCD_D5_Direction at DDRD.B5;
sbit LCD_D6_Direction at DDRD.B6;
sbit LCD_D7_Direction at DDRD.B7;
// End LCD module connections
//--------------------- Reads time and date information from RTC
(PCF8583)
void Read_Time() {
Soft_I2C_Start(); // Issue start signal
Soft_I2C_Write(0xA0); // Address PCF8583, see PCF8583 datasheet
Soft_I2C_Write(2); // Start from address 2
Soft_I2C_Start(); // Issue repeated start signal
Soft_I2C_Write(0xA1); // Address PCF8583 for reading R/W=1
seconds = Soft_I2C_Read(1); // Read seconds byte
minutes = Soft_I2C_Read(1); // Read minutes byte
hours = Soft_I2C_Read(1); // Read hours byte
day = Soft_I2C_Read(1); // Read year/day byte
month = Soft_I2C_Read(0); // Read weekday/month byte
Soft_I2C_Stop(); // Issue stop signal
407
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroC PRO for AVR
CHAPTER 6