Datasheet
Library Example
The example demonstrates Software I
2
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.
program RTC_Read;
var seconds, minutes, hours, day, month, year : byte; // Global
date/time variables
// Software I2C connections
var Soft_I2C_Scl_Output : sbit at PORTC.B0;
Soft_I2C_Sda_Output : sbit at PORTC.B1;
Soft_I2C_Scl_Input : sbit at PINC.B0;
Soft_I2C_Sda_Input : sbit at PINC.B1;
Soft_I2C_Scl_Direction : sbit at DDRC.B0:
Soft_I2C_Sda_Direction : sbit at DDRC.B1;
// End Software I2C connections
// Lcd module connections
var LCD_RS : sbit at PORTD.B2;
LCD_EN : sbit at PORTD.B3;
LCD_D4 : sbit at PORTD.B4;
LCD_D5 : sbit at PORTD.B5;
LCD_D6 : sbit at PORTD.B6;
LCD_D7 : sbit at PORTD.B7;
LCD_RS_Direction : sbit at DDRD.B2;
LCD_EN_Direction : sbit at DDRD.B3
LCD_D4_Direction : sbit at DDRD.B4;
LCD_D5_Direction : sbit at DDRD.B5;
LCD_D6_Direction : sbit at DDRD.B6;
LCD_D7_Direction : sbit at DDRD.B7;
// End Lcd module connections
//--------------------- Reads time and date information from RTC
(PCF8583)
procedure Read_Time();
begin
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
356
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6