User manual
453
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
Library Example
The example demonstrates use of the Software I²C Library. The dsPIC30/33 or PIC24 MCU is connected (SCL, SDA
pins) to PCF8583 RTC (real-time clock). Program sends date/time to RTC.
Copy Code To Clipboard
program RTC_Read;
var seconds, minutes, hours, day, month, year : byte; // Global date/time variables
// Software I2C connections
var Soft_I2C_Scl : sbit at RF3_bit;
Soft_I2C_Sda : sbit at RF2_bit;
Soft_I2C_Scl_Direction : sbit at TRISF3_bit;
Soft_I2C_Sda_Direction : sbit at TRISF2_bit;
// End Software I2C connections
// LCD module connections
var LCD_RS : sbit at LATD0_bit;
var LCD_EN : sbit at LATD1_bit;
var LCD_D4 : sbit at LATB0_bit;
var LCD_D5 : sbit at LATB1_bit;
var LCD_D6 : sbit at LATB2_bit;
var LCD_D7 : sbit at LATB3_bit;
var LCD_RS_Direction : sbit at TRISD0_bit;
var LCD_EN_Direction : sbit at TRISD1_bit;
var LCD_D4_Direction : sbit at TRISB0_bit;
var LCD_D5_Direction : sbit at TRISB1_bit;
var LCD_D6_Direction : sbit at TRISB2_bit;
var LCD_D7_Direction : sbit at TRISB3_bit;
// 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
month := Soft_I2C_Read(0); // Read weekday/month byte}
Soft_I2C_Stop(); // Issue stop signal}
end;