#include<reg52.h>
typedef unsigned int uint;
typedef unsigned char uchar;
uchar code duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0XBF};
uchar code duan1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};//带小数点
uchar code wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar smg[4];
uchar flag;
sbit dq=P3^3;
void delay20us(uint i)
{ uchar j;
while(i--)
{
for(j=20;j>0;j--)
{;
}
}
}
void delay4us(uint i)
{ while(i--)
{
;;
}
}
bit init()
{
dq=1;
delay4us(1);
dq=0;
delay20us(25);
dq=1;
delay20us(2);
return (bit)dq ;
}
void writebyte(uchar dat)
{ uchar i;
for(i=0;i<8;i++)
{
dq=1;
delay4us(1);
dq=0;
delay4us(3);
dq=dat&0x01;
delay20us(2);
dq=1;
delay4us(1);
dat>>=1;
}
}
uchar readbyte()
{ uchar i,k;
for(i=0;i<8;i++)
{dq=1;
delay4us(1);
dq=0;
delay4us(2);
k=dq|0x80;
delay20us(1);
k>>=1;
}
return k;
}
void start()
{
init();
writebyte(0xcc);
writebyte(0x44);
delay20us(5);
writebyte(0xcc);
writebyte(0xbe);
}
void display()
{ uchar TL,TH , t,t1;
TL=readbyte();
TH=readbyte();
if (TH&0x80!=0x00)
{ flag=1;
TL=~TL;
TH=~TH;
TL=TL+1;
if(TL>255)
TH++;
t= (TH*256+TL)/16;
t1=(TL%16)*10/16;
}
else
{t= (TH*256+TL)/16;
t1=(TL%16)*10/16;
}
if(flag==1)
{ smg[3]=duan[11] ;
smg[2]=duan[t/10] ;
smg[1]=duan1[t%10];
smg[0]=duan[t1];
}
else
{
smg[3]=duan[t/100];
smg[2]=duan[t%100/10];
smg[1]=duan1[t%10];
smg[0]=duan[t1];
}
}
void display1()
{
uchar i;
for(i=0;i<4;i++)
{
P2=wei[i+4];
P0=smg
;
delay20us(50);
}
}
void main()
{ while(1)
{start();
display();
display1();
}
}
此帖出自小平头技术问答
一周热门 更多>