请教关于atmega16 ad转换的问题

2019-07-16 03:30发布

#include <mega16.h>
#define AD_JINGDU 10
volatile unsigned int value=0;
#include <delay.h>
#define DATA_H PORTC|=1
#define DATA_L PORTC&=~1
#define LCLK_H PORTC|=(1<<1)
#define LCLK_L PORTC&=~(1<<1)
#define SCLK_H PORTC|=(1<<2)
#define SCLK_L PORTC&=~(1<<2)
char SegNum[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
void port_init(void)
{
    PORTA = 0x00;
    DDRA = 0x00;
    PORTB = 0x00;
    DDRB = 0xFF;
    PORTC = 0x00; //m103 output only
    DDRC = 0x00;
    PORTD = 0x00;
    DDRD = 0x00;
}


void adc_init(void)
{
    ADCSRA = 0x00; //disable adc
    ADMUX = 0x00; //select adc input 0
    ACSR = 0x80;
    ADCSRA = 0xCE;
}

void adc_single_init(unsigned char adc_input)
{
    ADCSRA = 0x00; //disable adc
    #if AD_JINGDU ==10
    ADMUX=0xE0|adc_input;
    #endif
    #if AD_JINGDU == 8
    ADMUX=0xC0|adc_input;
    #endif
    //ADMUX=0x40|adc_input; //AVCC, AREF 引脚外加滤波电容
    //ADMUX=adc_input; //AREF, 内部Vref 关闭, AREF 引脚外加滤波电容
    ACSR |= 0x80;     //禁用模拟比较器
    /*ADCSRA = (1<<ADEN)|(1<<ADSC)|(1<<ADATE)|(1<<ADIE)|0x06; *///允许AD,启动转换,自动触发使能,中断使能,64分频
    ADCSRA=0B11110110;
    SFIOR &=~ 0xe0;//自动中断源选择,连续转换模式
}

#pragma interrupt_handler adc_isr:15
void adc_isr(void)
{
    //conversion complete, read value (int) using...
    #if AD_JINGDU ==10
     value=ADCL;         //Read 8 low bits first (important)
    value|=(int)ADCH << 8; //read 2 high bits and shift into top byte
    #endif
    #if AD_JINGDU ==8
    value = ADCH;
    #endif
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
    //disable all interrupts
    port_init();
    adc_init();
    adc_single_init(0);

    MCUCR = 0x00;
    GICR = 0x00;
    TIMSK = 0x00; //timer interrupt sources
    #asm("sei") //re-enable interrupts
//all peripherals are now initialized
}


void sendData(char data)
{
    char i;
    SCLK_L;
    for(i=0;i<8;i++)
    {
        if((data<<i)&0x80)
            DATA_H;
        else
            DATA_L;
        SCLK_H;
        delay_us(2);
        SCLK_L;
    }
}
void segDisplay(char num,char data)
{
    LCLK_L;
    sendData(~(1<<num));
    sendData(SegNum[data]);
    LCLK_H;
    delay_us(2);
}
void main(void)
{
    init_devices();
    MCUCSR=0x80;
    MCUCSR=0x80;
    DDRC|=0b00000111;
    #asm("sei")
    while(1)
    {
      segDisplay(0,value%10);
      segDisplay(0,(value/10)%10);
      segDisplay(0,(value/10)/10);
    }
}


代码如上,编译出错,#pragma interrupt_handler adc_isr:15   编译不过去,,问什么??






友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。