#include
#define uchar unsigned char
#define uint unsigned int
uchar code seg_data1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code seg_data2[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
sbit p20=P2^0;
sbit p21=P2^1;
sbit p22=P2^2;
//sfr ADC_CONTR=0xBC;
//sfr P1ASF=0x9D;
//sfr ADC_RES=0xBD;
void delay(uint a1);
void input();
void display(uint count);
void main()
{
uint x;
while(1)
{
input();
x=5*(ADC_RES*50)/255;
display(x);
}
}
void input()
{
P1ASF=0x01;
ADC_CONTR=0x88;
delay(25);
IE=0xA0;
}
void drop() interrupt 5
{
ADC_CONTR=0X88;
}
void display(uint count)
{
uchar i;
for (i=0;i<5;i++)
{
P0=seg_data1[count%10];
p20=0;
delay(25);
p20=1;
P0=seg_data2[count/10%10];
p21=0;
delay(25);
p21=1;
if(count>=100)
{
P0=seg_data1[count/100];
p22=0;
delay(25);
p22=1;
}
}
}
void delay(uint a1) //误差 0us
{
unsigned char a,b,c;
for(c=a1;c>0;c--)
for(b=142;b>0;b--)
for(a=2;a>0;a--);
}
这是我自己写的,用数码管显示,你只需要把void display(uint count)函数改为12864的显示函数即可