#include
#include
unsigned char LED_segment[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x80};
unsigned char scan[]={0x0e,0x0d,0x0b,0x07};
unsigned int counter[]={0,0,0,0};
int scan_times;
sbit STS=P1^0;
sbit CS=P1^1; //定义端口
sbit RC=P1^6;
sbit A0=P1^2;
sbit CE=P1^3;
sbit S=P1^5;
void delay(x) //延迟程序
{
unsigned char i;
while(x--){
for(i=0;i<20;i++){; }
}
}
unsigned int dec(unsigned int n) //将二进制转化成十进制
{
unsigned int a[4];
unsigned int m;
a[0]=n/4096;
a[1]=n@96/256;
a[2]=n%6/16;
a[3]=n;
m=a[0]*4096+a[1]*256+a[2]*16+a[3];
return m;
}
main()
{
unsigned int i,result,AS,DH,DL;
CE=1;
RC=0;
A0=1;
CS=0;
delay(1);
while(STS==1);
S=0; // 等待转换结束
RC=1;
A0=0;
DH =P1;
delay(2);
//delay(2);
//A0=1;
//DL=P1;
//DL=DL&0x0f ;
result=DH;
AS=dec(result);
AS=AS*10;
AS=AS/4096;
//AS=AS*10000000;
P2=LED_segment[AS] ;
P3=scan[0] ;
/*counter[3]=AS/10000000;
counter[2]=AS000000/1000000;
counter[1]=AS00000/100000;
counter[0]=AS0000/10000;
while(1)
{
P2=LED_segment[counter];
P3=scan;
i++;
if(i==4) i=0;
}*/
} |