Libraries for I2C (MSSP1), RTC DS1307 and EEPROM AT24C32 (Pic Basic Compiler Oshonsoft).

DogFlu66

Member

I2C Library for PIC18F26K22 using MSSP1​

This library provides essential functions for managing I2C communication in master mode with the MSSP1 module of the PIC18F26K22. It includes initialization, reading, writing, and control of I2C transactions, such as START, STOP, and RESTART signals. It is designed for use with I2C slave devices like EEPROMs, sensors, or RTCs.

  • Init_I2C: Initializes the MSSP1 module in I2C master mode and configures the clock speed.
  • START_I2C: Sends a START condition to begin communication on the I2C bus.
  • STOP_I2C: Sends a STOP condition to end a transaction on the I2C bus.
  • ReStart_I2C: Sends a RESTART condition to continue a transaction without stopping it.
  • WRITE_I2C: Writes a byte to the I2C bus and checks for an acknowledgment (ACK) from the slave device.
  • READ_I2C: Reads a byte from the I2C bus and sends an ACK or NACK after reading.
  • WriteDevice_I2C: Sends the slave address and writes data to the slave device over I2C.
  • ReadDevice_I2C: Sends the slave address and reads a byte from the slave device over I2C.

DS1307 Library for PIC18 Basic (I2C)​

This library enables communication with the DS1307 Real-Time Clock (RTC) module, providing functions to read, write, and configure the clock. It includes support for handling 12-hour and 24-hour formats, AM/PM modes, and controlling square wave output.

  • DS1307_Init: Initializes the DS1307 by verifying and restarting the oscillator if necessary.
  • DS1307_Set_24h: Configures the DS1307 to operate in 24-hour mode.
  • DS1307_Set_12h: Configures the DS1307 to operate in 12-hour mode.
  • DS1307_Set_AM_PM: Sets the AM or PM mode in 12-hour format.
  • DS1307_Get_AM_PM_24h: Retrieves the current AM/PM/24-hour mode.
  • DS1307_Write: Sends a command and data to the DS1307 at the specified register.
  • DS1307_Read: Reads a byte of data from the specified register of the DS1307.
  • DS1307_Set_DateTime: Sets the date and time in the DS1307 module.
  • DS1307_Get_Date: Reads the current date from the DS1307.
  • DS1307_Get_Time: Reads the current time from the DS1307.
  • DS1307_Set_Hour: Sets the hour in the DS1307, ensuring compatibility with the current hour mode (12h/24h).
  • DS1307_Set_Minutes: Sets the minutes in the DS1307.
  • DS1307_Set_Seconds: Sets the seconds in the DS1307.
  • DS1307_Set_DayOfWeek: Sets the day of the week in the DS1307.
  • DS1307_Get_DayOfWeek: Reads the day of the week from the DS1307.
  • DS1307_SquareWave: Enables square wave output on the DS1307 and sets the frequency.
  • DS1307_Write_RAM: Writes a byte of data to the volatile RAM of the DS1307.
  • DS1307_Read_RAM: Reads a byte of data from the DS1307's RAM.

AT24C32 EEPROM Library for PIC18 Basic (I2C)​

This library provides essential functions for communication with the AT24C32 EEPROM via the I2C protocol. It includes methods for reading, writing, and managing the memory, supporting byte-level and page-level operations.

  • EEPROM_WriteByte: Writes a single byte of data to a specified 16-bit memory address in the EEPROM.
  • EEPROM_ReadByte: Reads a single byte of data from a specified 16-bit memory address in the EEPROM.
  • EEPROM_WritePage: Writes up to 32 bytes (one page) of data starting from a specified memory address.
  • EEPROM_ReadSequential: Reads multiple bytes of data sequentially from a specified memory address in the EEPROM.
I have used the following module which contains the RTC DS1307 and the E2PROM AT24C32:
 

Attachments

  • I2C RTC EEProm.jpg
    45.7 KB · Views: 7
  • Test RTC DS1307.bas
    3.7 KB · Views: 7
  • _I2CLibrary.bas
    6.6 KB · Views: 7
  • _DS1307Library.bas
    16 KB · Views: 7
  • Test AT24C32 I2C.bas
    3.5 KB · Views: 7
  • _AT24C32Library.bas
    5.9 KB · Views: 7
  • _Pic18F26K22Library.bas
    43.3 KB · Views: 8
Cookies are required to use this site. You must accept them to continue using the site. Learn more…