#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define delay4us() {_nop_();_nop_();_nop_();_nop_();}
sbit CS = P1^0;
sbit CLK = P1^1;
sbit DIO = P1^2; uchar Display_Buffer[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x3f,0x06,0x5b}; void DelayMS(uint ms)
{
uchar i;
while(ms--)
{
for(i=0;i<120;i++);
}
}
uchar Get_AD_Result()
{
uchar i,dat1=0,dat2=0;
CS = 0;
CLK = 0;
DIO = 1; _nop_(); _nop_();
CLK = 1; _nop_(); _nop_();
CLK = 0;DIO = 1; _nop_(); _nop_();
CLK = 1; _nop_(); _nop_();
CLK = 0;DIO = 1; _nop_(); _nop_();
CLK = 1;DIO = 1; _nop_(); _nop_();
CLK = 0;DIO = 1; _nop_(); _nop_();
for(i=0;i<8;i++)
{
CLK = 1; _nop_(); _nop_();
CLK = 0; _nop_(); _nop_();
dat1 = dat1 << 1 | DIO;
}
for(i=0;i<8;i++)
{
dat2 = dat2 << ((uchar)(DIO)<<i);
CLK = 1; _nop_(); _nop_();
CLK = 0; _nop_(); _nop_();
}
CS = 1;
return (dat1 == dat2) ? dat1:0;
} void main()
{
uint A,B,C;
uint d;
DelayMS(10);
while(1)
{
d = Get_AD_Result()*500.0/255/100;
A=d/100;
B=d/10%10;
C=d%10;
P2=0x01;
P0=~Display_Buffer[A];
DelayMS(1);
P2=0x02;
P0=~Display_Buffer;
DelayMS(1);
P2=0x04;
P0=~Display_Buffer[C];
DelayMS(1);
}
}
|