Mikroelektronika MIKROE-724 データシート

ページ / 726
454
mikoBasic 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
dim seconds, minutes, hours, day, month_, year as byte    ‘ Global date/time variables
‘ Software I2C connections
dim Soft_I2C_Scl           as sbit at RF3_bit
    Soft_I2C_Sda           as sbit at RF2_bit
    Soft_I2C_Scl_Direction as sbit at TRISF3_bit
    Soft_I2C_Sda_Direction as sbit at TRISF2_bit
‘ End Software I2C connections
‘ LCD module connections
dim LCD_RS as sbit at LATD0_bit
dim LCD_EN as sbit at LATD1_bit
dim LCD_D4 as sbit at LATB0_bit
dim LCD_D5 as sbit at LATB1_bit
dim LCD_D6 as sbit at LATB2_bit
dim LCD_D7 as sbit at LATB3_bit
dim LCD_RS_Direction as sbit at TRISD0_bit
dim LCD_EN_Direction as sbit at TRISD1_bit
dim LCD_D4_Direction as sbit at TRISB0_bit
dim LCD_D5_Direction as sbit at TRISB1_bit
dim LCD_D6_Direction as sbit at TRISB2_bit
dim LCD_D7_Direction as sbit at TRISB3_bit
‘ 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
‘-------------------- Formats date and time
sub procedure Transform_Time()