#include <stc_new_8051.H>
#define uchar unsigned char
#define uint unsigned int
sbit duan=P2^7;
sbit wei=P2^6;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0xbf,0x86,
0xdb,0xcf,0xe6,0xed,
0xfd,0x87,0xff,0xef};
void delayms(uint xms)
{
uint i,j;
for (i=xms;i>0;i--)
for (j=110;j>0;j--);
}
void display(uchar bai ,uchar shi,uchar ge)
{
duan=1;
P0=table[bai];
duan=0;
P0=0xff;
wei=1;
P0=0x7e;
wei=0;
delayms(5);
duan=1;
P0=table[shi];
duan=0;
P0=0xff;
wei=1;
P0=0x7d;
wei=0;
delayms(5);
duan=1;
P0=table[ge];
duan=0;
P0=0xff;
wei=1;
P0=0x7b;
wei=0;
delayms(5);
}
void main()
{
uchar A1,A2,A3,wendu,adval;
uint i;
ADC_CONTR|=0x80;//开AD转换电源
for (i=0;i<10000;i++);
P1ASF=0x01; //选P1.0作为转换通道
for (i=0;i<10000;i++);
ADC_CONTR|=0xE0;//
AUXR1|=0x04; //ADRJ=1
ADC_CONTR|=0x08; //启动
EADC=1; //开AD中断
EA=1;
while(1); //等待中断
adval=ADC_RESL;
wendu=(adval*0.00527+1)/0.0075;
A1=wendu/100;
A2=wendu%100/10;
A3=wendu%10;
display(A1,A2,A3);
}
void ADC_ISR (void) interrupt 5 //中断函数
{
uchar adval;
adval=ADC_RESL;
wendu=(adval*0.00527+1)/0.0075;
A1=wendu/100;
A2=wendu%100/10;
A3=wendu%1;
display(A1,A2,A3);
ADC_CONTR&=0xE7; //将标志位清零
adval=ADC_RESL;
ADC_CONTR|=0x08; //重新启动AD
}
程序运行不成功,请大侠指点一下呗。 |