#include "reg51.h"
#include "intrins.h"
#define ad_con P2
#define addata P0
#define Disdata P1
#define uchar unsigned char
#define unit unsigned int
sbit ALE=P2^3;
sbit START=P2^4;
sbit OE=P2^5;
sbit EOC=P3^7;
uchar code dis_7[11]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77};
char code scan_con[4]={0xFE,0xFD,0xFB,0xF7};
char data ad_data[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
char data dis[5]={0x00,0x00,0x00,0x00,0x00};
//
delay1ms(unit t)
{
unit i,j;
for(i=0;i<t;i++)
for(j=0;j<120;j++)
;
}
//
scan()
{
uchar k,n;
unit h;
dis[3]=0x00;
for(n=0;n<8;n++)
{
dis[2]=ad_data[n]/100;
dis[4]=ad_data[n]%100;
dis[1]=dis[4]/10;
dis[0]=dis[4]%10;
for(h=0;h<500;h++)
{
for(k=0;k<4;k++)
{
Disdata=dis_7[dis[k]];P3=scan_con[k];delay1ms(1);P3=0xFF;
}
}
dis[3]++;
}
}
//
test()
{
char m;
char s=0x00;
ad_con=s;
for(m=0;m<8;m++)
{
ALE=1;_nop_();_nop_();ALE=0;
START=1;_nop_();_nop_();START=0;
_nop_();_nop_();_nop_();_nop_();
while(EOC==0);
OE=1;ad_data[m]=addata;OE=0;s++;ad_con=s;
}
ad_con=0x00;
}
//
main()
{
P0=0xFF;
P2=0x00;
P1=0xFF;
P3=0xFF;
while(1)
{
scan();
test();
}
} |