用ICC-AVR模数转换的问题,数据显示不正常,AD输入接PA7,四位数码管位选接PA0~PA3,段选接Pc口,参考电压选择2,56v基准电压,实际测定的电压是1.49v,预期数码管应该显示的是596,但结果却显示1023,而且改变他的电压数据会变化,但结果还是不变,望哪位大神指教下,谢谢!以下是程序:
#include <iom16v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char smg_du[]={0xee,0x28,0xb6,0xba,0x78,0xda,0xde,0xa8,0xfe,0xfa};
unsigned char smg_we[]={0x01,0x02,0x04,0x08};
uchar table[8]={0,0,0,0,0,0,0,0};
void init (void)
{
DDRA=0x0f;
PORTA=0;
DDRC=0xff; //01111000
PORTC=0;
}
void delay(void)
{
uint a;
for(a=0;a<300;a++);
}
/*
void display(uchar *p)
{
uchar i;
for(i=0;i<4;i++)
{
PORTA=smg_we[i];
PORTC=smg_du[table[i]];
delay();
}
}
*/
adc_init(void)
{
DDRA&=~BIT(7);
PORTA&=~BIT(7);
ADMUX=0xc7;
ADCSRA=0xe8;
SFIOR=0x00;
SREG|=BIT(7);
}
void data_pro(uint temp_1,uint temp_h)
{
uint i,temp1,temp2;
temp1=temp_h*256;
temp2=temp1+temp_1;
table[0]=temp2/1000;
temp1=temp2%1000;
table[1]=temp1/100;
temp2=temp1%100;
table[2]=temp2/10;
table[3]=temp2%10;
for(i=0;i<4;i++)
{
PORTA=smg_we[i];
PORTC=smg_du[table[i]];
delay();
}
}
void main(void)
{
init();
adc_init();
while(1);
}
#pragma interrupt_handler adc_isr:15
void adc_isr(void)
{
uint adc_1,adc_h;
if(ADCSRA=0xe8)
{
adc_1=ADCL;
adc_h=ADCH;
data_pro(adc_1,adc_h);
}
}
|