I2C PROTOCAL
I2C PROTOCAL
Code for I2C to EEPROM
TASK TO WRITE VALUES IN EEPROM AND READ FROM EEPROM ?
//I2C
#include <LPC21xx.h>
#include "delayheader.h"
#include "lcdheader.h"
#include "i2c_header.h"
#include <LPC21xx.h>
#include "delayheader.h"
#include "lcdheader.h"
#include "i2c_header.h"
int main()
{
char c;
PINSEL0 |=(1<<4)|(1<<6); //pin configure
PINSEL0 &=~(1<<5)|(1<<7);
lcdinit(); //lcd initialization
lcdstring("I2C PROGRAM");
lcdcmd(0xc0);
PINSEL0 &=~(1<<5)|(1<<7);
lcdinit(); //lcd initialization
lcdstring("I2C PROGRAM");
lcdcmd(0xc0);
I2CONSET= (1<<6); //this register 6th bit is ENABLE the I2C Block
I2SCLH=75; //refer notes given clcok
I2SCLL=75;
I2C_START(); //FOR I2C start funtion
I2SCLH=75; //refer notes given clcok
I2SCLL=75;
I2C_START(); //FOR I2C start funtion
I2C_DATA(0xA0); // device addres (memory addres)
I2C_DATA(0x00);
I2C_DATA(0x01);
I2C_DATA(0x00);
I2C_DATA(0x01);
I2C_DATA('A'); // data writing
I2C_DATA('B');
I2C_DATA('C');
I2C_DATA('B');
I2C_DATA('C');
I2C_STOP(); //for I2C stop
delay(500); // delay
delay(500); // delay
// "read data from EEPROM we need to write dummy"
I2C_START();
I2C_DATA(0xA0); //write mode
I2C_DATA(0x00);
I2C_DATA(0x01);
I2C_START();
I2C_DATA(0xA0); //write mode
I2C_DATA(0x00);
I2C_DATA(0x01);
I2C_START(); // repetative start we need to give
I2C_DATA(0xA1); // A1 is the read mode
I2C_DATA(0xA1); // A1 is the read mode
I2CONSET =(1 << 2); // to generate ack on reception
c=I2C_RCV(); //for a
lcddata(c);
c=I2C_RCV(); //for b
lcddata(c);
c=I2C_RCV(); // for b
lcddata(c);
c=I2C_RCV(); //for a
lcddata(c);
c=I2C_RCV(); //for b
lcddata(c);
c=I2C_RCV(); // for b
lcddata(c);
I2C_STOP();
}
i2c_header file.h
void I2C_STOP(void);
unsigned char I2C_RCV(void);
void I2C_DATA(unsigned char);
void I2C_START(void);
unsigned char I2C_RCV(void);
void I2C_DATA(unsigned char);
void I2C_START(void);
lcdheader file.h
#define RS (1<<10)
#define RW (1<<12)
#define EN (1<<13)
#define DATA_PINS (0xff<<15)
#define RW (1<<12)
#define EN (1<<13)
#define DATA_PINS (0xff<<15)
void delay(int count);
void lcdcmd (int cmd);
void lcddata (int data);
void lcdstring(char *string);
void lcdstringmul(char *str);
void lcd_num(int num);
void lcdinit(void);
void lcdcmd (int cmd);
void lcddata (int data);
void lcdstring(char *string);
void lcdstringmul(char *str);
void lcd_num(int num);
void lcdinit(void);
Comments
Post a Comment