#include #define AD_JINGDU 10 volatile unsigned int value=0; #include #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< 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< DATA_H; else DATA_L; SCLK_H; delay_us(2); SCLK_L; } } void segDisplay(char num,char data) { LCLK_L; sendData(~(1< 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 编译不过去,,问什么?? |
|
来自: 昵称34440942 > 《aaa》