#include
#include
***it SO=P1^0;
***it SCK=P1^1;
***it CS=P1^2;
***it p1=P3^3;
***it p2=P3^2;
***it p3=P3^1;
***it p4=P3^0;
unsigned char code table[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char code table_2[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
unsigned char i,j,shiwei,gewei,shifen,baifen;
unsigned char table_3[16];
unsigned int temp,wendu,tt=0;
void stop(unsigned int z);
void display(shiwei,gewei,shifen,baifen);
unsigned int convert();
main()
{
TMOD=0x01;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(tt==20)
{
tt=0;
wendu=convert();
if(wendu<400)
{
wendu=wendu*25;
baifen=wendu%10;
wendu=wendu/10;
shifen=wendu%10;
wendu=wendu/10;
gewei=wendu%10;
shiwei=wendu/10;
}
}
}
}
void exter() interrupt 1
{
TH0=(65536-20000)/256; //初值 高八位
TL0=(65536-20000)%256; //初值 低八位
tt++;
display(shiwei,gewei,shifen,baifen);
}
//unsigned int convert()
{
CS=1;
SCK=0;
_nop_();
CS=0;
for(i=0;i<16;i++)
{
_nop_();
_nop_();
SCK=1;
table_3[i]=SO;
_nop_();
SCK=0;
_nop_();
}
temp=table_3[1]*2048+table_3[2]*1024+table_3[3]*512+table_3[4]*256+table_3[5]*128+table_3[6]*64+table_3[7]*32+table_3[8]*16+table_3[9]*8+table_3[10]*4+table_3[11]*2+table_3[12]*1;
SCK=0;
_nop_();
CS=1;
return temp;
}
void stop(unsigned int z)
{
unsigned int x, y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(shiwei,gewei,shifen,baifen)
{
p1=0;
P0=table[baifen];
stop(5);
p1=1;
P0=0xff;
p2=0;
P0=table[shifen];
stop(5);
p2=1;
P0=0xff;
p3=0;
P0=table_2[gewei];
stop(5);
p3=1;
P0=0xff;
p4=0;
P0=table[shiwei];
stop(5);
p4=1;
P0=0xff;
}
1
|
|
|
|