|
我这个模数转换中断为什末执行不了? 用的是iccavr 开发工具
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long int
uint time62ms ;
uchar disbuf[4]={0,1,2,3};
uchar discode[10]={ 0xC0, 0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90 }; //段码表
uchar disbit[4] ={ 0xFE, 0xFD,0xFB,0xF7}; //段选表,从左到右 对应avr开发板
/******************************************************************************/
//延时函数
/***************************************************************************/
void delay(int q)
{uchar p;
for(p=0;p
}
/******************************************************************************/
//显示函数
/******************************************************************************/
void Display(void)
{
uchar i ;
for(i=0;i<4;i++)
{
PORTB=discode[disbuf] ;
//if(i == 3)
// { PORTB =PORTB|0x80 ;} //该语句为了显示小数点
PORTA=disbit ;
delay(300);
PORTA=0xff; //为0时,段选成功,此时全部关断
}
}
//************************
void adctodis(uint adc)
{ uchar n ;
for(n=3 ;n>=0 ; n--)
{
disbuf[n]=adc%10 ;
adc/=10 ;
}
}
/*#pragma interrupt_handler timer0_compa_isr:20
void timer0_compa_isr(void)
{
time62ms=1 ;
}
*/
#pragma interrupt_handler adc_isr:15
void adc_isr(void)
{ uint adcdata ,adcreal,temph ;
uint temp1,temp2;
temp1=(uint)ADCL;
temp2=(uint)ADCH;
adcdata=(temp2<<8)+temp1;//10位精度
adcreal= (ulong)((adcdata/1024)*2560) ;
adctodis(adcreal) ;
// delay();
//Display();
ADMUX=0xC7 ;
ADCSRA|=(1<
PORTD=0x00 ;
}
void main()
{ DDRD=0xFF ;
PORTD=0xFF ;
DDRA=0x0F ;
PORTA=0x00 ;
DDRB=0xFF ;
// TCCR0=0x0D ;// 1024分频, CTC模式,PB3为通用I/O口引脚
// TCNT0=0x00 ;// timer0的初值
// OCR0=0xF8 ; // 设定和TCNT0匹配时的值为248,即定时62ms后,比较匹配,同时TCNT0=0
// TIMSK=0X02 ; //使能T/C0比较匹配中断
ADCSRA=0x00 ;
ADMUX=0xC7 ; //内部参考源2.56V ?ADC7输入 ,J1连在左边两个排阵上
ADCSRA=0xCE ; // 我们选外部晶振8MHz, adc 的频率为125kHZ,即64分频。
// SFIOR&=0x1F ;
// SFIOR|=0x60 ;
SEI(); //使能全局中断
Display();
while(1)
{ //if(time62ms)
delay(1000) ;
// Display();
// time62ms=0 ;
}
} |
|