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.
program RTC_Read
dim seconds, minutes, hours, _day, _month, year as byte ' Global
date/time variables
' Software I2C connections
dim Soft_I2C_Scl_Output as sbit at PORTC.B0
Soft_I2C_Sda_Output as sbit at PORTC.B1
Soft_I2C_Scl_Input as sbit at PINC.B0
Soft_I2C_Sda_Input as sbit at PINC.B1
Soft_I2C_Scl_Direction as sbit at DDRC.B0
Soft_I2C_Sda_Direction as sbit at DDRC.B1
' End Software I2C connections
' Lcd module connections
dim LCD_RS as sbit at PORTD.B2
LCD_EN as sbit at PORTD.B3
LCD_D4 as sbit at PORTD.B4
LCD_D5 as sbit at PORTD.B5
LCD_D6 as sbit at PORTD.B6
LCD_D7 as sbit at PORTD.B7
LCD_RS_Direction as sbit at DDRD.B2
LCD_EN_Direction as sbit at DDRD.B3
LCD_D4_Direction as sbit at DDRD.B4
LCD_D5_Direction as sbit at DDRD.B5
LCD_D6_Direction as sbit at DDRD.B6
LCD_D7_Direction as sbit at DDRD.B7
' End Lcd module connections
'--------------------- Reads time and date information from RTC
(PCF8583)
sub procedure 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}
end sub
343
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6