请各位大神帮忙看看,小女子感激不尽。
目前在做AD转换,用的单片机是ATmega32,在做到AD转换时用定时器溢出触发AD转换,发现似乎没办法连续转换,请高人指点。
下面是我的程序:
//****************定时器0初始化程序*****************
void init_avrtimer0()
{
TCCR0=0x03; //预分频64
TCNT0=256-10000000/64*0.625*0.001; //晶振10MHz,设定定时器初值为0.625MS
TIMSK=0x01; //使能TC0溢出中断
}
//=======================ADC初始化====================//
void init_ADC(int16u address)
{
ADMUX = address;
ADCSRA = (1<<ADEN)|(1<<ADATE)|(1<<ADIF);
SFIOR=0x80;
ADCSRA |= (1<<ADIE)|(1<<ADSC);
}
//********************************************************
void main()
{
DDRD=0xff;
PORTD=0xff;
DDRA&=0x01;
PORTA&=0x01;
DDRB=0x0F;
PORTB=0x0F;
CLK_1();
DIN_1();
STB_1();
send_data(0x80);//关显示
display0(0,0,0,0x01);
STB_1();
send_data(0x89);//开显示
delayms(2000);
STB_1();
send_data(0x80);//关显示
init_avrtimer0();
init_ADC(0x43);
sei();
while(1)
{
SET();
TIMSK=0x00;
addata=ADCL;
addata=addata+ADCH*256-512;
ADCSRA|=1<<(ADIF);
ADCSRA=0;
display(addata,0,0);
TIMSK=0X01;
}
}
//*************************************
ISR(TIMER0_OVF_vect)
{
TCNT0=256-10000000/64*0.625*0.001;
sign1++;
}
ISR(ADC_vect)
{
TIFR |= (1<<TOV0);
}
|