#include "reg52.h"
#include "i2c.h"//子文件都正确,且有起始,结束,读入,发送,接受信号
typedef unsigned int u16;
typedef unsigned char u8;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
sbit k1=P3^1;
sbit k2=P3^0;
sbit k3=P3^2;
sbit k4=P3^3;
u8 disp[8];
char num=0;
u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay(u16 i)
{
while(i--);
}
void Keypros()
{
if(k2==0)
{
delay(1000);
if(k2==0)
{
At24c02Write(1,num);
num=At24c02Read(1);
}
while(!k2);
}
if(k3==0)
{
delay(1000);
if(k3==0)
{
num=0;
}
while(!k3);
}
}
void DigDisplay()
{
u8 i;
for(i=0;i<8;i++)
{
switch(i)
{
case(0):
LSA=1;LSB=1;LSC=1; break;
case(1):
LSA=0;LSB=1;LSC=1; break;
case(2):
LSA=1;LSB=0;LSC=1; break;
case(3):
LSA=0;LSB=0;LSC=1; break;
case(4):
LSA=1;LSB=1;LSC=0; break;
case(5):
LSA=0;LSB=1;LSC=0; break;
case(6):
LSA=1;LSB=0;LSC=0; break;
case(7):
LSA=0;LSB=0;LSC=0; break;
}
P0=disp[i];
delay(100);
P0=0x00;
}
}
void datapros()
{
u8 a;
while(1)
{
for(a=1;a<11;a++)
{
if(a<11)
{
disp[7]=smgduan[a%10];
disp[6]=smgduan[a/10];
delay(50000);
}
else
{
a=0;
num=num+1;
disp[3]=smgduan[num%10];
disp[2]=smgduan[num/10];
delay(50000);
}
}
}
}
void main()
{
while(1)
{
Keypros();
datapros();
DigDisplay();
}
} |