帮我看看吧~!
#include "Em78p458.h"
#define uchar unsigned char
#define uchar unsigned char
#define uint unsigned int
const uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f};//共阳码
const uchar table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
0x87,0xff,0xef};//带小数点的共阳码
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void into()
{
PORT6=0x01;
PORT5=0xE0;
ADCOM=0x08;
GCON=0x00;
ADCMPCON=0x01;
ADPD=0x01;
delay(10);
}
uint get_ad()
{
uint adval;//十六位的数要用 uint来存储
float advalf;
ADGO=1;
while(ADGO);
adval=ADRESH;//00000000 00000011
advalf=adval/255.0*5;//注意,在这句话中255要加“.0”是因为结果出来要是浮点数
adval=advalf*1000;
return (adval);
}
void main()
{ uint i;
uint a,b,c,d;
into();
while(1)
{i=get_ad();
a=i/1000;
b=i%1000/100;
c=i%100/10;
d=i%10;
disp(a,b,c,d);
}
} |