0
#include
#define unchar unsigned char
#define uint unsigned int
uchar ge,shi,bai,temp;
***it wx=P2^7; //位选锁存端
***it dx=P2^6;//段选锁存端
***it OE=P2^5;
***it EOC=P2^4;
***it C=P2^3;
***it B=P2^2;
***it A=P2^1;
***it ST=P2^0;
uchar code TB1[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,
0x7d,0x07,0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};//段码
uchar code TB2[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//位码
void init();
void star_read();
void display();
/********延时约1MS*/
void delay1ms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=120;y>0;y--);
}
void main()
{
init();
while(1)
{
star_read();
display();
}
}
/********ADC0809初始化*/
void init()
{
ST=0; //初始化ADC0809 选中模拟通道IN0
OE=0;
C=0;
B=0;
A=0;
P3=0xff;//P3口置1 准备读取转换后的数据
}
/********启动并读取转换数据*/
void star_read()
{
ST=1;
ST=0;
delay1ms(10);
OE=1;
temp=P3;
delay1ms(10);
OE=0;
}
/********显示*/
void display()
{
bai=temp/100; //将得到的数分离并显示
shi=temp%100/10;、//若P3=temp=0x80则对应在数码管显示128。5V的参考电压对应模拟输入2.5V
shi=temp%100/10;
ge=temp%10;
wx=1;
P1=TB2[0];
wx=0;
dx=1;
P1=TB1[bai];
dx=0;
delay1ms(5)
wx=1;
P1=TB2[1];
wx=0;
dx=1;
P1=TB1[shi];
dx=0;
delay1ms(5);
wx=1;
P1=TB2[2];
wx=0;
dx=1;
P1=TB1[ge];
dx=0;
delay1ms(5);
}
|
|