吸取网上的写法加上鸿哥的框架,整合成自己的一套思路,程序含指针,数组,搞了两天,以此纪念,请看:
/*
函数实现功能:利用AT24C02进行掉电后的数据保存。一共有4个窗口。每个窗口显示一个参数,
4个被更改后的参数断电后不丢失,数据可以保存,断电再上电后还是上一次最新被修改的数据。
*/
#include <reg52.h>
#include <intrins.h>
#define const_key_time 12
#define const_voice_short 20
#define I2CDelay() {_nop_();_nop_();_nop_();_nop_();}
/*I2C所有的底层操作函数,包括起始,停止,字节写,字节读+非应答,字节读+应答*/
void I2CStart();//产生总线起始信号
bit I2CWrite(unsigned char dat);//I2C总线写操作,根据时序写一个字节,返回从机应答值
unsigned char I2CReadNACK();//I2C总线读操作,根据时序读一个字节,不给从机应答值
unsigned char I2CReadACK();
void I2CStop();//产生总线停止信号
//读取函数,从EEPROM中读到数组中去
void E2Read2Byte(unsigned char *buf,unsigned char addr,unsigned char len);
//写函数,把数组元素写到EEPROM中去。
void E2Write2Byte(unsigned char *buf,unsigned char addr,unsigned char len);
void initial_myself();
void delay_long(unsigned int uiDelayLong);
void initial_peripheral();
void key_scan();
void key_service();
void dig_show();
void dig_hc595_drive(unsigned char ucDigStatusTemp16_09,unsigned char ucDigStatusTemp08_01);
void dig_service();
void T0_time();
sbit I2C_SCL = P3^7;
sbit I2C_SDA = P3^6;
sbit key_sr1 = P0^0;
sbit key_sr2 = P0^1;
sbit key_sr3 = P0^2;
sbit key_gnd_dr = P0^4;
sbit dig_hc595_sh_dr = P2^0;
sbit dig_hc595_st_dr = P2^1;
sbit dig_hc595_ds_dr = P2^2;
sbit beep_dr = P2^7;
bit KeyLock1 = 0;
bit KeyLock2 = 0;
bit KeyLock3 = 0;
bit DigDot1 = 0;
bit DigDot2 = 0;
bit DigDot3 = 0;
bit DigDot4 = 0;
bit DigDot5 = 0;
bit DigDot6 = 0;
bit DigDot7 = 0;
bit DigDot8 = 0;
unsigned char buf[8];
unsigned char ucDigStep = 1;
unsigned char ucWd = 1;
unsigned int uiWd1Part = 0;
unsigned int uiWd2Part = 0;
unsigned int uiWd3Part = 0;
unsigned int uiWd4Part = 0;
unsigned char ucDigStatus16_09 = 0;
unsigned char ucDigStatus08_01 = 0;
unsigned int uiBeepTimeCnt = 0;
unsigned char ucKeySec = 0;
unsigned int uiKeyTimeCnt1 = 0;
unsigned int uiKeyTimeCnt2 = 0;
unsigned int uiKeyTimeCnt3 = 0;
unsigned char code ucdig_table[]=
{
0x3f, //0 序号0
0x06, //1 序号1
0x5b, //2 序号2
0x4f, //3 序号3
0x66, //4 序号4
0x6d, //5 序号5
0x7d, //6 序号6
0x07, //7 序号7
0x7f, //8 序号8
0x6f, //9 序号9
0x00, //无 序号10
0x40, //- 序号11
0x73 //P 序号12
};
unsigned char ucLedBuff[8]=
{
0x3f,0x3f,0x3f,0x3f,0x00,0x06,0x40,0x73
};
void main()
{
initial_myself();
delay_long(100);
initial_peripheral();
while(1)
{
key_service();
dig_service();
}
}
//请看I2C1文件的解释
void I2CStart()
{
I2C_SCL = 1;
I2C_SDA = 1;
I2CDelay();
I2C_SDA = 0;
I2CDelay();
I2C_SCL = 0;
}
//请看I2C1文件的解释
void I2CStop()
{
I2C_SCL = 0;
I2C_SDA = 0;
I2CDelay();
I2C_SCL = 1;
I2CDelay()
I2C_SDA = 1;
I2CDelay();
}
/*
I2C总线写操作,字节写,字节里面的每一位是怎么发送的,根据时序写(发送)一个字节,
返回从机应答值ACK, dat--待发送的字节,具体解释看 I2C1文件
*/
bit I2CWrite(unsigned char dat)
{
bit ACK;
unsigned char mask;//用于探测字节内某一位的掩码变量
for(mask = 0x80;mask!=0;mask>>=1)
{
if((mask&dat)==0)
{
I2C_SDA = 0;
}
else
{
I2C_SDA = 1;
}
I2CDelay();
I2C_SCL=1;
I2CDelay();
I2C_SCL=0;
}
I2C_SDA = 1;
I2CDelay();
I2C_SCL = 1;
ACK = I2C_SDA;
I2CDelay();
I2C_SCL = 0;
return (~ACK);//应答值取反以符合通常的逻辑
}
/*
I2C总线读操作,根据时序读一个字节,不给从机应答值.返回值--读到的字节
*/
unsigned char I2CReadNACK()
{
unsigned char mask;
unsigned char dat = 0;//用来保存读到的值
I2C_SDA = 1;//确保总线是释放状态
for(mask = 0x80;mask!=0;mask>>=1)//从高到底位依次进行
{
I2CDelay();
I2C_SCL = 1;//拉高SCL,为高的时候,接收方来读取当前SDA的电平信号
if(I2C_SDA==0)//读取SDA的值
{
dat&=~mask;//为0时,dat中对应位清零
}
else
{
dat|=mask;//为1时,dat中对应位置1
}
I2CDelay();
I2C_SCL = 0;//再拉低SCL,以使从机发出下一位
}
I2C_SDA=1;//八位数据发送完毕,不给从机应答值,间接告诉EEPROM不需要再读数据啦
I2CDelay();
I2C_SCL = 1;
I2CDelay();
I2C_SCL = 0;//再拉低SCL,完成非应答位
return dat;
}
/*
I2C总线读操作,根据时序读一个字节,要给从机应答值.返回值--读到的字节
*/
unsigned char I2CReadACK()
{
unsigned char mask;
unsigned char dat = 0;
I2C_SDA = 1;
for(mask = 0x80;mask!=0;mask>>=1)
{
I2CDelay();
I2C_SCL = 1;
if(I2C_SDA==0)
{
dat&=~mask;
}
else
{
dat|=mask;
}
I2CDelay();
I2C_SCL = 0;
}
I2C_SDA=0;////8位数据发送完毕,给从机应答值,告诉EEPROM需要再读数据
I2CDelay();
I2C_SCL = 1;
I2CDelay();
I2C_SCL = 0;
return dat;
}
/*
unsigned char *buf定义了一个可以指向字符型数据的指针变量,buf用来保存数组buf[]的地址了,
addr--AT24C02的起始地址,len--读取长度
函数实现把EEPROM里面起始地址为addr开始的,len个长度的数据读出来,存储在数组buf[]里面,
本例中len=2,所以读出来的数据分别存储在buf[0],buf[1]中
一句话概括:读,从EEPROM中读到数组中去。
*/
void E2Read2Byte(unsigned char *buf,unsigned char addr,unsigned char len)
{
do{
I2CStart();//发送起始信号
if(I2CWrite(0xA0))//发送器件的地址,但是读写方向要改为“写”即“0”
{
break;
}
I2CStop();
}while(1);
I2CWrite(addr);//发送起始地址,要读取的数据所在EEPROM里面的地址
I2CStart();//重新发送起始信号
I2CWrite(0xA1);//重新发送器件的地址1010 000,但是读写方向要改为“读”即“1”,则1010 0001
while(len>1)//本例中len=2
{
*buf++ = I2CReadACK();/*
*buf++等价于*(buf++),先*buf,再buf++。*buf=buf[0],指针变量buf指向了下一个元素,len=2时,
把起始地址addr里面的数据读出并且存储在buf[0],主机回应一个应答位ACK,表示表示还要继续读一个字节
*/
len--;//len=1
}
*buf = I2CReadNACK();/*
buf已经指向了下一个元素,指针变量buf存储的是下一个元素的地址,*buf解引用就是访问指针变量buf指向的那个元素,
也就是,把读到的数据存储在buf[1].I2CReadNACK()主机不回应,表示不想继续读
*/
I2CStop();
}
/*
unsigned char *buf定义了一个可以指向字符型数据的指针变量,buf用来保存数组buf[]的地址了,
addr--AT24C02的起始地址,len--写入长度
函数实现把buf[8]数组元素发送给EEPROM,EEPROM从起始地址addr开始存储主机发给它的数据,打算发送多少由len决定.
(从地址addr开始写buf[]元素。)
一句话概括:写,数组元素写到EEPROM中去。
*/
void E2Write2Byte(unsigned char *buf,unsigned char addr,unsigned char len)
{
while(len--)//本例中len=2
{
do{
I2CStart();//发送起始位
if(I2CWrite(0xA0))//发送器件的地址,但是读写方向要改为“写”即“0”
{
break;
}
I2CStop();
}while(1);
I2CWrite(addr++);//数据要存储的地址,数据要存在EEPROM中的 哪个地址上面
I2CWrite(*buf++);/*发送buf[8]数组里面的成员,I2CWrite(*buf++)是先I2CWrite(*buf),
而*buf解引用是buf[]数组的元素,后buf++,这句实现,把数组元素发送出去给EEPROM*/
I2CStop();
}
}
void dig_service()
{
switch(ucWd)
{
case 1:
ucLedBuff[5]=ucdig_table[1];
if(uiWd1Part<10)
{
ucLedBuff[0]=ucdig_table[uiWd1Part%10];
ucLedBuff[1]=ucdig_table[10];
ucLedBuff[2]=ucdig_table[10];
ucLedBuff[3]=ucdig_table[10];
}
else if(uiWd1Part<100)
{
ucLedBuff[0]=ucdig_table[uiWd1Part%10];
ucLedBuff[1]=ucdig_table[uiWd1Part/10%10];
ucLedBuff[2]=ucdig_table[10];
ucLedBuff[3]=ucdig_table[10];
}
else if(uiWd1Part<1000)
{
ucLedBuff[0]=ucdig_table[uiWd1Part%10];
ucLedBuff[1]=ucdig_table[uiWd1Part/10%10];
ucLedBuff[2]=ucdig_table[uiWd1Part/100%10];
ucLedBuff[3]=ucdig_table[10];
}
else
{
ucLedBuff[0]=ucdig_table[uiWd1Part%10];
ucLedBuff[1]=ucdig_table[uiWd1Part/10%10];
ucLedBuff[2]=ucdig_table[uiWd1Part/100%10];
ucLedBuff[3]=ucdig_table[uiWd1Part/1000%10];
}
/*最开始把 buf[1]=uiWd1Part;
buf[0]=uiWd1Part>>8;
E2Write2Byte(buf,0x00,2);写在这里,每次循环都要往EEPROM里面搽写,
而EEPROM寿命只有30万到100万,如此AT24C02用不了多久就会坏掉的。
*/
break;
case 2:
ucLedBuff[5]=ucdig_table[2];
if(uiWd2Part<10)
{
ucLedBuff[0]=ucdig_table[uiWd2Part%10];
ucLedBuff[1]=ucdig_table[10];
ucLedBuff[2]=ucdig_table[10];
ucLedBuff[3]=ucdig_table[10];
}
else if(uiWd2Part<100)
{
ucLedBuff[0]=ucdig_table[uiWd2Part%10];
ucLedBuff[1]=ucdig_table[uiWd2Part/10%10];
ucLedBuff[2]=ucdig_table[10];
ucLedBuff[3]=ucdig_table[10];
}
else if(uiWd2Part<1000)
{
ucLedBuff[0]=ucdig_table[uiWd2Part%10];
ucLedBuff[1]=ucdig_table[uiWd2Part/10%10];
ucLedBuff[2]=ucdig_table[uiWd2Part/100%10];
ucLedBuff[3]=ucdig_table[10];
}
else
{
ucLedBuff[0]=ucdig_table[uiWd2Part%10];
ucLedBuff[1]=ucdig_table[uiWd2Part/10%10];
ucLedBuff[2]=ucdig_table[uiWd2Part/100%10];
ucLedBuff[3]=ucdig_table[uiWd2Part/1000%10];
}
/*最开始把 buf[3]=uiWd1Part;
buf[2]=uiWd1Part>>8;
E2Write2Byte(buf+2,0x02,2);写在这里,每次循环都要往EEPROM里面搽写,
而EEPROM寿命只有30万到100万,如此AT24C02用不了多久就会坏掉的。
*/
break;
case 3:
ucLedBuff[5]=ucdig_table[3];
if(uiWd3Part<10)
{
ucLedBuff[0]=ucdig_table[uiWd3Part%10];
ucLedBuff[1]=ucdig_table[10];
ucLedBuff[2]=ucdig_table[10];
ucLedBuff[3]=ucdig_table[10];
}
else if(uiWd3Part<100)
{
ucLedBuff[0]=ucdig_table[uiWd3Part%10];
ucLedBuff[1]=ucdig_table[uiWd3Part/10%10];
ucLedBuff[2]=ucdig_table[10];
ucLedBuff[3]=ucdig_table[10];
}
else if(uiWd3Part<1000)
{
ucLedBuff[0]=ucdig_table[uiWd3Part%10];
ucLedBuff[1]=ucdig_table[uiWd3Part/10%10];
ucLedBuff[2]=ucdig_table[uiWd3Part/100%10];
ucLedBuff[3]=ucdig_table[10];
}
else
{
ucLedBuff[0]=ucdig_table[uiWd3Part%10];
ucLedBuff[1]=ucdig_table[uiWd3Part/10%10];
ucLedBuff[2]=ucdig_table[uiWd3Part/100%10];
ucLedBuff[3]=ucdig_table[uiWd3Part/1000%10];
}
break;
case 4:
ucLedBuff[5]=ucdig_table[4];
if(uiWd4Part<10)
{
ucLedBuff[0]=ucdig_table[uiWd4Part%10];
ucLedBuff[1]=ucdig_table[10];
ucLedBuff[2]=ucdig_table[10];
ucLedBuff[3]=ucdig_table[10];
}
else if(uiWd4Part<100)
{
ucLedBuff[0]=ucdig_table[uiWd4Part%10];
ucLedBuff[1]=ucdig_table[uiWd4Part/10%10];
ucLedBuff[2]=ucdig_table[10];
ucLedBuff[3]=ucdig_table[10];
}
else if(uiWd4Part<1000)
{
ucLedBuff[0]=ucdig_table[uiWd4Part%10];
ucLedBuff[1]=ucdig_table[uiWd4Part/10%10];
ucLedBuff[2]=ucdig_table[uiWd4Part/100%10];
ucLedBuff[3]=ucdig_table[10];
}
else
{
ucLedBuff[0]=ucdig_table[uiWd4Part%10];
ucLedBuff[1]=ucdig_table[uiWd4Part/10%10];
ucLedBuff[2]=ucdig_table[uiWd4Part/100%10];
ucLedBuff[3]=ucdig_table[uiWd4Part/1000%10];
}
break;
default:
break;
}
}
void key_service()
{
switch(ucKeySec)
{
case 1:
switch(ucWd)
{
case 1:
uiWd1Part++;
if(uiWd1Part>9999)
{
uiWd1Part=9999;
}
buf[1]=uiWd1Part;
buf[0]=uiWd1Part>>8;
E2Write2Byte(buf,0x00,2);/*把要发送的数组元素所在的地址传给
void E2Write2Byte(unsigned char *buf,unsigned char addr,unsigned char len)的形参指针变量buf,
我们用EEPROM的0x00,0x01地址来装窗口1的参数uiWd1part。
*/
break;
case 2:
uiWd2Part++;
if(uiWd2Part>9999)
{
uiWd2Part=9999;
}
buf[3]=uiWd2Part;
buf[2]=uiWd2Part>>8;
//E2Write2Byte(buf,0x02,2);最开始写成这样了,这样表示把buf[0],buf[1]即uiWd1Part写到了EEPROM的0x02,0x03地址上。
E2Write2Byte(&buf[2],0x02,2);/*把要发送的数组元素所在的地址传给
void E2Write2Byte(unsigned char *buf,unsigned char addr,unsigned char len)的形参指针变量buf,
我们用EEPROM的0x02,0x03地址来装窗口2的参数uiWd2part。当然&buf[2]也可以写成buf+2,为保险起见还是写&buf[2]吧
*/
break;
case 3:
uiWd3Part++;
if(uiWd3Part>9999)
{
uiWd3Part=9999;
}
buf[5]=uiWd3Part;
buf[4]=uiWd3Part>>8;
//E2Write2Byte(buf,0x04,2);最开始写成这样了,这样表示把buf[0],buf[1]即uiWd1Part写到了EEPROM的0x04,0x05地址上。
E2Write2Byte(&buf[4],0x04,2);/*把要发送的数组元素所在的地址传给
void E2Write2Byte(unsigned char *buf,unsigned char addr,unsigned char len)的形参指针变量buf,
我们用EEPROM的0x04,0x05地址来装窗口2的参数uiWd2part。当然&buf[4]也可以写成buf+4,为保险起见还是写&buf[4]吧
*/
break;
case 4:
uiWd4Part++;
if(uiWd4Part>9999)
{
uiWd4Part=9999;
}
buf[7]=uiWd4Part;
buf[6]=uiWd4Part>>8;
//E2Write2Byte(buf,0x06,2);最开始写成这样了,这样表示把buf[0],buf[1]即uiWd1Part写到了EEPROM的0x06,0x07地址上。
E2Write2Byte(&buf[6],0x06,2);/*把要发送的数组元素所在的地址传给
void E2Write2Byte(unsigned char *buf,unsigned char addr,unsigned char len)的形参指针变量buf,
我们用EEPROM的0x06,0x07地址来装窗口2的参数uiWd2part。当然&buf[6]也可以写成buf+6,为保险起见还是写&buf[6]吧
*/
break;
default:
break;
}
uiBeepTimeCnt = const_voice_short;
ucKeySec = 0;
break;
case 2:
switch(ucWd)
{
case 1:
uiWd1Part--;
if(uiWd1Part>9999)
{
uiWd1Part=0;
}
buf[1]=uiWd1Part;
buf[0]=uiWd1Part>>8;
E2Write2Byte(buf,0x00,2);
break;
case 2:
uiWd2Part--;
if(uiWd2Part>9999)
{
uiWd2Part=0;
}
buf[3]=uiWd2Part;
buf[2]=uiWd2Part>>8;
// E2Write2Byte(buf,0x02,2);
E2Write2Byte(&buf[2],0x02,2);
break;
case 3:
uiWd3Part--;
if(uiWd3Part>9999)
{
uiWd3Part=0;
}
buf[5]=uiWd3Part;
buf[4]=uiWd3Part>>8;
// E2Write2Byte(buf,0x04,2);
E2Write2Byte(&buf[4],0x04,2);
break;
case 4:
uiWd4Part--;
if(uiWd4Part>9999)
{
uiWd4Part=0;
}
buf[7]=uiWd4Part;
buf[6]=uiWd4Part>>8;
// E2Write2Byte(buf,0x06,2);
E2Write2Byte(&buf[6],0x06,2);
break;
default:
break;
}
uiBeepTimeCnt = const_voice_short;
ucKeySec = 0;
break;
case 3:
ucWd++;
if(ucWd>4)
{
ucWd = 1;
}
uiBeepTimeCnt = const_voice_short;
ucKeySec = 0;
break;
default:
break;
}
}
void dig_show()
{
switch(ucDigStep)
{
case 1:
ucDigStatus16_09 = ucLedBuff[0];
if(DigDot1 == 1)
{
ucDigStatus16_09 = ucDigStatus16_09|0x80;
}
dig_hc595_drive(ucDigStatus16_09,0xfe);
break;
case 2:
ucDigStatus16_09 = ucLedBuff[1];
if(DigDot2 == 1)
{
ucDigStatus16_09 = ucDigStatus16_09|0x80;
}
dig_hc595_drive(ucDigStatus16_09,0xfd);
break;
case 3:
ucDigStatus16_09 = ucLedBuff[2];
if(DigDot3 == 1)
{
ucDigStatus16_09 = ucDigStatus16_09|0x80;
}
dig_hc595_drive(ucDigStatus16_09,0xfb);
break;
case 4:
ucDigStatus16_09 = ucLedBuff[3];
if(DigDot4 == 1)
{
ucDigStatus16_09 = ucDigStatus16_09|0x80;
}
dig_hc595_drive(ucDigStatus16_09,0xf7);
break;
case 5:
ucDigStatus16_09 = ucLedBuff[4];
if(DigDot5 == 1)
{
ucDigStatus16_09 = ucDigStatus16_09|0x80;
}
dig_hc595_drive(ucDigStatus16_09,0xef);
break;
case 6:
ucDigStatus16_09 = ucLedBuff[5];
if(DigDot6 == 1)
{
ucDigStatus16_09 = ucDigStatus16_09|0x80;
}
dig_hc595_drive(ucDigStatus16_09,0xdf);
break;
case 7:
ucDigStatus16_09 = ucLedBuff[6];
if(DigDot7 == 1)
{
ucDigStatus16_09 = ucDigStatus16_09|0x80;
}
dig_hc595_drive(ucDigStatus16_09,0xbf);
break;
case 8:
ucDigStatus16_09 = ucLedBuff[7];
if(DigDot8 == 1)
{
ucDigStatus16_09 = ucDigStatus16_09|0x80;
}
dig_hc595_drive(ucDigStatus16_09,0x7f);
break;
default:
break;
}
ucDigStep++;
if(ucDigStep>8)
{
ucDigStep = 1;
}
}
void key_scan()
{
if(key_sr1 == 1)
{
uiKeyTimeCnt1 = 0;
KeyLock1 = 0;
}
else if(KeyLock1==0)
{
uiKeyTimeCnt1++;
if(uiKeyTimeCnt1>const_key_time)
{
uiKeyTimeCnt1 = 0;
KeyLock1 = 1;
ucKeySec = 1;
}
}
if(key_sr2 == 1)
{
uiKeyTimeCnt2 = 0;
KeyLock2 = 0;
}
else if(KeyLock2==0)
{
uiKeyTimeCnt2++;
if(uiKeyTimeCnt2>const_key_time)
{
uiKeyTimeCnt2 = 0;
KeyLock2 = 1;
ucKeySec = 2;
}
}
if(key_sr3 == 1)
{
uiKeyTimeCnt3 = 0;
KeyLock3 = 0;
}
else if(KeyLock3==0)
{
uiKeyTimeCnt3++;
if(uiKeyTimeCnt3>const_key_time)
{
uiKeyTimeCnt3 = 0;
KeyLock3 = 1;
ucKeySec = 3;
}
}
}
void delay_long(unsigned int uiDelayLong)
{
unsigned int i;
unsigned int j;
for(i = 0;i<uiDelayLong;i++)
{
for(j=0;j<500;j++)
{
;
}
}
}
void T0_time() interrupt 1
{
TF0 = 0;
TR0 = 0;
key_scan();
if(uiBeepTimeCnt!= 0)
{
uiBeepTimeCnt--;
beep_dr = 0;
}
else
{
;
beep_dr = 1;
}
dig_show();
TH0 = 0xfc;
TL0 = 0x67;
TR0 = 1;
}
void dig_hc595_drive(unsigned char ucDigStatusTemp16_09,unsigned char ucDigStatusTemp08_01)
{
unsigned char i;
unsigned char ucTempdata;
dig_hc595_sh_dr = 0;
dig_hc595_st_dr = 0;
ucTempdata = ucDigStatusTemp16_09;
for(i=0;i<8;i++)
{
if(ucTempdata&0x80)
{
dig_hc595_ds_dr = 1;
}
else
{
dig_hc595_ds_dr = 0;
}
dig_hc595_sh_dr = 0;
_nop_();
_nop_();
dig_hc595_sh_dr = 1;
_nop_();
_nop_();
ucTempdata <<= 1;
}
ucTempdata = ucDigStatusTemp08_01;
for(i=0;i<8;i++)
{
if(ucTempdata&0x80)
{
dig_hc595_ds_dr = 1;
}
else
{
dig_hc595_ds_dr = 0;
}
dig_hc595_sh_dr = 0;
_nop_();
_nop_();
dig_hc595_sh_dr = 1;
_nop_();
_nop_();
ucTempdata <<= 1;
}
dig_hc595_st_dr = 0;
_nop_();
_nop_();
dig_hc595_st_dr = 1;
_nop_();
_nop_();
dig_hc595_sh_dr = 0;
dig_hc595_st_dr = 0;
dig_hc595_ds_dr = 0;
}
void initial_myself()
{
key_sr1 = 1;
key_sr2 = 1;
key_sr3 = 1;
key_gnd_dr = 0;
beep_dr = 1;
TMOD&=0xf0;
TMOD |= 0x01;
TH0 = 0xfc;
TL0 = 0x67;
}
void initial_peripheral()
{
DigDot1=0;
DigDot2=0;
DigDot3=0;
DigDot4=0;
DigDot5=0;
DigDot6=0;
DigDot7=0;
DigDot8=0;
E2Read2Byte(buf,0x00,2);//从EEPROM中的地址0X00,0X01读出的数据构成uiWd1Part
uiWd1Part = buf[0];
uiWd1Part = uiWd1Part<<8;
uiWd1Part = uiWd1Part+buf[1];
// E2Read2Byte(buf,0x02,2);//最开始写成这样,表示从EEPROM中的地址0X02,0X03读出的数据放在buf[0],buf[1]构成uiWd1Part
E2Read2Byte(&buf[2],0x02,2);//从EEPROM中的地址0X02,0X03读出的数据构成uiWd2Part
uiWd2Part = buf[2];
uiWd2Part = uiWd2Part<<8;
uiWd2Part = uiWd2Part+buf[3];
// E2Read2Byte(buf,0x04,2);//最开始写成这样,表示从EEPROM中的地址0X02,0X03读出的数据放在buf[0],buf[1]构成uiWd1Part
E2Read2Byte(&buf[4],0x04,2);//从EEPROM中的地址0X04,0X05读出的数据构成uiWd3Part
uiWd3Part = buf[4];
uiWd3Part = uiWd3Part<<8;
uiWd3Part = uiWd3Part+buf[5];
// E2Read2Byte(buf,0x06,2);//最开始写成这样,表示从EEPROM中的地址0X02,0X03读出的数据放在buf[0],buf[1]构成uiWd1Part
E2Read2Byte(&buf[6],0x06,2);//从EEPROM中的地址0X06,0X07读出的数据构成uiWd4Part
uiWd4Part = buf[6];
uiWd4Part = uiWd4Part<<8;
uiWd4Part = uiWd4Part+buf[7];
EA = 1;
ET0 = 1;
TR0 = 1;
}