【发布时间】:2012-02-13 09:01:09
【问题描述】:
我正在编写 AVR MCU。
它有一个可以读取模拟引脚的 POT。似乎中断被不断调用,并且必须在 LCD_display 方法期间调用它,因为它正在弄乱我的 LCD。
有没有办法在块运行之前停止干扰?
int main(void)
{
/*Turn on ADC Interrupt */
ADCSRA |= (1 << ADIE);
/*Turn On GLobal Interrupts*/
sei();
/* Intalise LCD */
lcd_init(LCD_DISP_ON); /* initialize display, cursor off */
lcd_clrscr();
lcd_puts("READY");
DDRB &= ~(1 << PINB5); //set input direction
ADC_Init(128, 0); //initalize ADC
while (1)
{
if (!bit_is_clear(PINB, 5))
{
_delay_ms(500);
if (!pressed)
{
lcd_gotoxy(0,0);
lcd_clrscr();
lcd_puts("test"); //Doesnt work unless I dont comment out the last line of interrupt
pressed = 1;
}
}
/* INTERRUPTS */
//ADC INTERRUPT
ISR(ADC_vect)
{
char adcResult[4];
uint8_t theLowADC = ADCL;
uint16_t theTenBitResults = ADCH<<8 | theLowADC;
itoa(theTenBitResults, adcResult, 10);
ADCSRA |= (1 << ADSC); //next conversion *if i comment out this line it works*
}
【问题讨论】:
-
什么是ADCSRA?它被定义为易失性吗?它是否同时控制显示器和 ADC?您是否需要中断控制器和/或 I/O 设备的特殊中断确认操作?您的 ISR 是否足够慢以至于错过了一些中断?
-
@AlexeyFrunze -
ADCSRA是一个特殊功能寄存器,可直接操作硬件设置。它被定义为 volatile。