#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit ACC_7=ACC^7;
sbit sclk=P1^7;
sbit dio=P2^3;
sbit ce=P1^3;
uchar shi,fen,miao;
uchar code table[]={
0xC0,/*0*/
0xF9,/*1*/
0xA4,/*2*/
0xB0,/*3*/
0x99,/*4*/
0x92,/*5*/
0x82,/*6*/
0xF8,/*7*/
0x80,/*8*/
0x90,/*9*/
};
void delay(uchar z)
{
uchar i,j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
void y6c()
{
P2 |= 0xC0;
P2 &= 0x1F;
}
void y7c()
{
P2|=0xe0;
P2&=0x1f;
}
void write(uchar add,dat)
{
uchar i,temp;
ce=0;
sclk=0;
ce=1;
for(i=8;i>0;i--)
{
sclk=0;
temp=add;
dio=(bit)(temp&0x01);
add>>=1;
sclk=1;
}
for(i=8;i>0;i--)
{
sclk=0;
temp=dat;
dio=(bit)(temp&0x01);
add>>=1;
sclk=1;
}
ce=0;
}
uchar read(uchar add)
{
uchar i,temp,dat1,dat2;
ce=0;
sclk=0;
ce=1;
for(i=8;i>0;i--)
{
sclk=0;
temp=add;
dio=(bit)(temp&0x01);
add>>=1;
sclk=1;
}
for(i=8;i>0;i--)
{
ACC_7=dio;
sclk=1;
ACC>>=1;
sclk=0;
}
ce=0;
dat1=ACC;
dat2=dat1/16;
dat1=dat1%16;
dat1=dat1+dat2*10;
return dat1;
}
void init()
{
write(0x8e,0x00);
write(0x80,0x00);
write(0x82,0x22);
write(0x84,0x32);
write(0x8e,0x80);
}
void display(uchar miao,fen,shi)
{
uchar shi1,shi2,shi3,ge1,ge2,ge3;
shi1=miao/10;
ge1=miao%10;
shi2=fen/10;
ge2=fen%10;
shi3=shi/10;
ge3=shi%10;
P0=table[ge1];
y7c();
P0=0x80;
y6c();
delay(4);
P0=table[shi1];
y7c();
P0=0x40;
y6c();
delay(4);
P0=table[ge2];
y7c();
P0=0x20;
y6c();
delay(4);
P0=table[shi2];
y7c();
P0=0x10;
y6c();
delay(4);
P0=table[ge3];
y7c();
P0=0x08;
y6c();
delay(4);
P0=table[shi3];
y7c();
P0=0x04;
y6c();
delay(4);
}
void main()
{
init();
while(1)
{
display(read(0x81),read(0x83),read(0x85));
}
} |