ADC0804應(yīng)用
#include
#define uint unsigned int
#define uchar unsigned char
sbit p20=P2^0;//數(shù)碼管位選端定義
sbit p21=P2^1;//數(shù)碼管位選端定義
sbit p22=P2^2;//數(shù)碼管位選端定義
sbit cs=P2^4;
sbit rd=P2^5;
sbit wr=P2^6;
unsigned char code tab[] =
{
0XC0,//;0
0XF9,//;1
0XA4,//;2
0XB0,//;3
0X99,//;4
0X92,//;5
0X82,//;6
0XF8,//;7
0X80,//;8
0X90,//;9
};
void delay(uchar z)
{
uint i;
while(z--)
for (i=0;i<120;i++);
}
void disp(uchar a,uchar b,uchar c)
{
p20=1;
p21=0;
p22=0;
P0=tab[a];
delay(5);
P0=0xff;
p20=0;
p21=1;
p22=0;
P0=tab[b];
delay(5);
P0=0xff;
p20=0;
p21=0;
p22=1;
P0=tab[c];
delay(5);
P0=0xff;
}
void stdc()
{
cs=0;
wr=1;
wr=0;
wr=1;
}
void main()
{
uchar A,B,C,d;
while(1)
{
stdc();
delay(10);
rd=1;
delay(1);
rd=0;
d=P3;
rd=1;
A=d/100;
B=d%100/10;
C=d%10;
disp(A,B,C);
}
}
評論