Привет всем любителям AVR.
Впервые в своей жизни решил настроить прерывание и как вы думаете?
НЕПОЛУЧИЛОСЬ :-)
Подскажите кто может в чем проблема. Код приведен ниже.
Работаю в ICC AVR.
#include <iom128v.h>
#include <macros.h>
#include "PU_v1.h"
unsigned char EVENT_REG=0;
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x10; //m103 output only
DDRC = 0x10;
PORTD = 0x01;
DDRD = 0x00;
PORTE = 0x00;
DDRE = 0x00;
PORTF = 0x00;
DDRF = 0x00;
PORTG = 0x01;
DDRG = 0x1F;
}
//Watchdog initialize
// prescale: 2048K
void watchdog_init(void)
{
WDR(); //this prevents a timout on enabling
WDTCR = 0x0F; //WATCHDOG ENABLED - dont forget to issue WDRs
}
#pragma interrupt_handler int0_isr:2
void int0_isr(void)
{
PORTG|=BIT(Led_ERR);
EVENT_REG|=BIT(Ena_SER_DATA);
while (EVENT_REG&BIT(Ena_SER_DATA))
{
PORTG|=BIT(0);
delay3us();
delay3us();
PORTG&=~BIT(0);
EVENT_REG&=~BIT(Ena_SER_DATA);
}
}
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
XDIV = 0x00; //xtal divider
XMCRA = 0x00; //external memory
port_init();
watchdog_init();
MCUCR = 0x00;
EICRA = 0x03; //extended ext ints
EICRB = 0x00; //extended ext ints
EIMSK = 0x01;
TIMSK = 0x00; //timer interrupt sources
ETIMSK = 0x00; //extended timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void delay3us(void)
{
unsigned int i=0;
for (i=0;i<48;i++)
{
NOP();
}
}
void main(void)
{
init_devices();
while(1)
{
WDR();
PORTG|=BIT(Led_RUN);
}
}