本帖最后由 34af9uc 于 2016-1-17 21:47 编辑
void main()
{
char a1;
unsigned char a,b,c;
init();
write(1,1,0x32); write(1,2,0x30); write(1,3,0x31);// write(1,4,0x36);
P1ASF =0x80; //P1^7AD输入(该寄存器不可读)
ADC_CONTR =0xe7; //开AD电源 转换最快 选择1^7为AD
while(1)
{
ADC_CONTR|=0x08; //启动AD
delay(5);
ADC_CONTR&=0xef; //转换标志位清除
a=ADC_RES;
a=~a; //把负数变化变成正数变化
a1=a;
a1=a1-90; //0x5a(90)0度
if(a1>0){write(1,12,0x20);} //空格,清除减号
if(a1<0){write(1,12,0x2d);a1=~a1;} //减号;会有-0的数字
a1=a1/1.8; //1.8/度(实际不是成线性增长)
b=a1/10;
c=a1%10;
write(1,13,b+0x30);
write(1,14,c+0x30);
delay(100);
}
} |