I2C bus for 24LC16 For CSS Compiler

Summary of I2C bus for 24LC16 For CSS Compiler


This article presents a PIC16F877 project that writes a setpoint to a 24LCxx I2C EEPROM, initializes a 4-bit LCD, and continuously reads and displays the stored setpoint on the LCD. The code configures clocks, timers, I2C, ports, and disables analog/PSP functionality.

Parts used in the PIC16F877 EEPROM Read Project:

  • PIC16F877 microcontroller
  • 4-bit LCD module (HD44780-compatible)
  • 24LCxx I2C EEPROM
  • 4 MHz crystal oscillator
  • Pull-up resistors for I2C lines (SDA, SCL)
  • Power supply (VCC, GND)
  • Wiring/header connections
  • Development tools for PIC (compiler, programmer)

 

#include <16F877.h>
#device adc=8
#FUSES NOWDT ,XT                                        
#use delay(clock=4000000)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)

#INCLUDE "LCD_4BIT.C"
#include "I2C_24LCxx.c "
int8  value,setpoint=112; 

void main(){
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1); 
   set_tris_c(0B10000000);      // 1000 0000    PortC
   set_tris_d(0B00000000);      // 0000 0000    Portd is Output
   lcd_init();
   Write_eeprom_24LCxx(0x01,setpoint);  
   lcd_init();
   lcd_ROW_COL(1,0);  // defind  ddram address for put string
   lcd_putc(" KCHI_MICRO.PIC");
   lcd_ROW_COL(2,0);
   lcd_putc("READ EEPROM 24LC");
   DELAY_MS(1000);
   LCD_CLear();
   LCD_INIT();
 while (TRUE){ 
      Lcd_row_col(1,0);   
      Lcd_putc("setpoint="); 
      value=Read_eeprom_24LCxx(0x01);
      hex_bcd(VALUE);
      lcd_row_col(1,9);
      sent_Lcd();
      delay_ms(100);
   }
}

Quick Solutions to Questions related to the PIC16F877 EEPROM Read Project:

  • What does the project do?
    It writes a setpoint value to a 24LCxx EEPROM and continuously reads and displays that value on a 4-bit LCD.
  • Which microcontroller is used?
    The project uses the PIC16F877 microcontroller.
  • How is the EEPROM accessed?
    The EEPROM is accessed via I2C using the sda=PIN_C4 and scl=PIN_C3 configuration.
  • What initial setpoint is written to EEPROM?
    The code writes a setpoint value of 112 to EEPROM address 0x01.
  • How is the LCD initialized?
    The project initializes a 4-bit LCD using included LCD_4BIT.C functions and calls lcd_init and LCD_INIT.
  • Are analog inputs enabled?
    No, analog inputs are disabled using setup_adc_ports(NO_ANALOGS) and setup_adc(ADC_OFF).
  • Which port pins are configured as outputs?
    Port D is configured as all outputs with set_tris_d(0B00000000); Port C sets bit 7 as input with set_tris_c(0B10000000).
  • How often is the EEPROM value read and displayed?
    The code continuously reads the EEPROM and updates the LCD inside a while(TRUE) loop with a 100 ms delay each iteration.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter