unsigned char AT24C02ReivcePAGE(unsigned char *Rdata,unsigned char PAGEADDRESS,unsigned char RomAddress,unsigned char number) // unsigned char Rbeyts; PAGEADDRESS |= PAGEADDRESS; if(WaitAck()) I2cSendByte(RomAddress); return 1; PAGEADDRESS |= RDeivceAddress; if(WaitAck()) for(;number!=1;number--){ SDA=0; SCL=1; SCL=0; Rdata++; *Rdata=I2cReadByte(); Delay20us(); Delay20us(); Delay20us(); return 0; } u8 code smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
u8 code digital[10]={0x02,0x06,0x08,0x10,0x11,0x14,0x13,0x22,0x55,0xff};
u8 code rdigital[10];
void Keypros()
{
if(k1==0)
{
delay(1000); //消抖处理
if(k1==0)
{
At24c02WritePAGE(digital,0,0x00,10); //在地址内写入数据num
}
while(!k1);
}
if(k2==0)
{
delay(1000); //消抖处理
if(k2==0)
{
At24c02ReivcePAGE(rdigital,0,0x00,1);
num=rdigital[0];//读取EEPROM地址内的数据保存在num中
}
while(!k2);
}
if(k3==0)
{
delay(100); //消抖处理
if(k3==0)
{
num++; //数据加1
if(num>255)num=0;
}
while(!k3);
}
if(k4==0)
{
delay(1000); //消抖处理
if(k4==0)
{
num=0; //数据清零
}
while(!k4);
}
}void main()
{
num=0;
while(1)
{
Keypros(); //按键处理函数
datapros(); //数据处理函数
Digdisplay();//数码管显示函数
}
}
|