/************************************************************************************************
File Name : EEPROM interfacing
Controller : P89v51RD2
Description : Code to interface EEPROM and particulur page read and display on uart
Author : Nagaraj Navalagund
Company : Elegance Technologies
*************************************************************************************************/
/*************************************************************************************************
Header Files
*************************************************************************************************/
#include<e.h>
//Include header file lcd that contains lcd command and data function defenitions.
/*************************************************************************************************
Function Name : Main
Return Type : void
Description : Function to initialise the EEPROM and particulur page read and display on uart
*******************************************************************************************/
void main(void)
{
unsigned char Edata[19];
unsigned char st[20]="elegancetechnologes";// given string
UART();//uart unilization
EEPROM_WriteString(0xF1,st);//eepron writeing
delay(1);
EEPROM_ReadString(0xF1,Edata);//eeprom reading
Edata[19]=0x00;
UART_TxString(Edata);//uart trasmitting
// while(1);
}
/************************************************************************************************
Function Name : i2c clock
Return Type : void
Description : Function to initialise the clock
*******************************************************************************************/
unsigned int z;
void I2C_Clock()
{
delay(1);
SCL = 1;
delay(1);
SCL = 0;
}
/************************************************************************************************
Function Name : i2c start
Return Type : void
Description : Function to initialise the scl and sdl lines
*******************************************************************************************/
void I2C_Start()
{
SCL = 0;
SDA = 1; //setting the pin
delay(1);
SCL = 1;
delay(1);
SDA = 0; //disable pin
delay(1);
SCL = 0;
}
/************************************************************************************************
Function Name : i2c stop
Return Type : void
Description : Function to initialise the scl and sdl lines
*******************************************************************************************/
void I2C_Stop()
{
SCL = 0;
delay(1);
SDA = 0;
delay(1);
SCL = 1; //setting pin
delay(1);
SDA = 1; //setting the pin
}
/************************************************************************************************
Function Name : i2c write
Return Type : void
Description : Function to initialise the write a word on i2c
*******************************************************************************************/
void I2C_Write(unsigned char dat)
{
unsigned char i;
for(i=0;i<8;i++)
{
SDA = dat & 0x80; //we are settinh up 9- carry
I2C_Clock(); //i2c clock
dat = dat<<1;//data sending 1 and set a byte (8-bits)
delay(1);
}
SDA = 1;
}
/************************************************************************************************
Function Name : i2c read
Return Type : void
Description : Function to initialise the to i2c
*******************************************************************************************/
unsigned char I2C_Read(void)
{
unsigned char i, dat=0x00;
SDA=1; //I/P
for(i=0;i<8;i++) // data
{
delay(1);
SCL = 1;
delay(1);
dat = dat<<1; //dat is Shifted each time and
dat = dat | SDA; //ORed with the received bit to pack into byte
SCL = 0;
}
return dat;
}
/************************************************************************************************
Function Name : i2c acknolgment
Return Type : void
Description : Function to initialise the acknolgement
*******************************************************************************************/
void I2C_Ack()
{
SDA = 0;
I2C_Clock();
SDA = 1;
//printf("ack \n");
}
/************************************************************************************************
Function Name : i2c no acknoledgment
Return Type : void
Description : Function to initialise the no ack
*******************************************************************************************/
void I2C_NoAck()
{
SDA = 1;
I2C_Clock();
SCL = 1;
// printf("ack no\n");
}
/************************************************************************************************
Function Name : delay
Return Type : void
Description : Function to initialise the delay
*******************************************************************************************/
void delay(unsigned int z)
{
int j,i;
for(i=0;i<z;i++)
for(j=0;j<1275;j++);//1i sec dealy
}
/************************************************************************************************
Function Name : uart transmetting
Return Type : void
Description : Function to initialise the tranmiting char
*******************************************************************************************/
void UART_TxChar(char ch)
{
SBUF=ch; //setting buf
while(TI==0); //until it recevie
TI=0; //stop transmetting
}
/************************************************************************************************
Function Name : uart
Return Type : void
Description : Function to initialise the uart
*******************************************************************************************/
void UART()
{
TMOD |=0x20;//timer 0 and mode 2(8-bit)
TH1=-3; //9600 board rate
SCON=0x50; //setting serial buff for uart
TR1=1; //
}
/************************************************************************************************
Function Name : transmeting string
Return Type : void
Description : Function to initialise the transmeting string
*******************************************************************************************/
void UART_TxString(char *string_ptr)
{
while(*string_ptr)//string address
UART_TxChar(*string_ptr++); //trtasmetting char with inc address
}
/************************************************************************************************
Function Name : EEPOROM
Return Type : void
Description : Function to initialise the eeprom write
*******************************************************************************************/
void EWrite(unsigned char eeprom_Address, unsigned char eeprom_Data)
{
I2C_Start();
I2C_Write(EEPROM_ID); //device address
I2C_Ack();//i2c acknoledment
I2C_Write(eeprom_Address);//Select the Specified EEPROM address of AT2408
I2C_Ack();
I2C_Write(eeprom_Data); // Write the data at specified address
I2C_Ack();
I2C_Stop();
delay(1);
}
/************************************************************************************************
Function Name : Main
Return Type : void
Description : Function to initialise the LCD and display the string and charecters on LCD
*******************************************************************************************/
unsigned char ERead(unsigned char eeprom_Address)
{
unsigned char eData;
I2C_Start();
I2C_Write(EEPROM_ID); //Select the Specified EEPROM address of AT2408
I2C_Ack();
I2C_Write(eeprom_Address); // Write the data at specified address
I2C_Ack();
I2C_Start();
I2C_Write(0xA7); // connect I2c Bus
I2C_Ack();
EEPROM.rar_I AM
版权申诉
92 浏览量
2022-09-14
22:27:34
上传
评论
收藏 103KB RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/6a7aa99d23544fe38965063dcf203f49_weixin_42664597.jpg!1)
小贝德罗
- 粉丝: 71
- 资源: 1万+
最新资源
- MyBatisCodeHelperPro 3.3.2-2322 2023.2-2024.1
- 基于Python的简单的学生成绩管理程序设计(课程设计)
- jdk-8u20-windows-x64安装版本-jdk-8u301-linux-x64解压版
- 植物大战僵尸杂交版 修改阳光和冷却
- html css js网页设计ntion-model-for-开发笔记
- 数据库课程设计-processing开发笔记
- matlab画图sic-开发demo
- 数据库原理课程设计-图书馆数据库管理系统
- IEC101Sim IEC870-5-101协议仿真主站、子站 (含源码 C++Builder)
- 2212503007陈熙炜跨境2202作业2.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)