#include <REGX51.H>
#include <intrins.h>
#define Disdata P0
#define discan P2
sbit adrd=P3^7;
sbit adwr=P3^6;
sbit csad=P3^4;
sbit DIN=P0^7;
unsigned char j,k,ad_data,t;
unsigned char dis[4]={0x00,0x00,0x00,0x00};
unsigned char code dis_7[12]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x40};
unsigned char code scan_con[4]={0xfe,0xfd,0xfb,0xf7};
void delay(unsigned int t)
{
for(;t>0;t--)
{
;
}
}
void scan()
{
char k;
for(k=0;k<4;k++)
{
Disdata=dis_7[dis[k]];
if(k==1)
{
DIN=1;
}
discan=scan_con[k];
delay(90);
discan=0xff;
}
}
void ad0804()
{
P1=0xff;
csad=0;
adrd=0;
ad_data=P1;
adrd=1;
csad=1;
adwr=0;
}
void ad_compute()
{
unsigned char t_temp;
ad_data=ad_data-0x83;
t_temp=ad_data*2-4;
if(t_temp<=200)
{
dis[3]=t_temp/100;
dis[2]=t_temp/10-dis[3]*10;
dis[1]=t_temp%10;
dis[0]=t%5*2;
}
else
{
t_temp=256-t_temp;
dis[3]=11;
dis[2]=t_temp/10;
dis[1]=t_temp%10;
dis[0]=t%5*2;
}
}
void main()
{
while(1)
{
ad0804();
ad_compute();
scan();
}
}
链接:https://pan.baidu.com/s/1iFlHs2nka_32RpiBrqnF7Q 提取码:qdil
|