cs181
Newbie level 1
winavr sleep_mode
Below is the C code for handling an external interrupt.
The initial value on PORTC is 0;
When an interrupt occurs it increment the PORTC by 1;
I used the WinAVR to convert the c code into hex code, then loaded the hex code onto the chip (avr atmega8) for test. The values on PORTC change randomly every an interrupt occurs.
Can anyone tell me whats wrong with the code? Thank you.
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/sleep.h>
SIGNAL (SIG_INTERRUPT1)
{
PORTC = PORTC + 1;
// Enable global interupt (page 9)
SREG |= 0x80;
/** Sleep Mode **/
set_sleep_mode(SLEEP_MODE_IDLE);
sleep_mode();
}
int main (void)
{
DDRC |= 0xFF;
PORTC = 0x00;
/** Record button interupt **/
// Any logical change on INT1 generates an interupt
MCUCR |= 0x04;
// Enable external interupt pin INT1
GICR |= 0x80;
// Enable global interupt (page 9)
SREG |= 0x80;
/** Sleep Mode **/
set_sleep_mode(SLEEP_MODE_IDLE);
sleep_mode();
}
Below is the C code for handling an external interrupt.
The initial value on PORTC is 0;
When an interrupt occurs it increment the PORTC by 1;
I used the WinAVR to convert the c code into hex code, then loaded the hex code onto the chip (avr atmega8) for test. The values on PORTC change randomly every an interrupt occurs.
Can anyone tell me whats wrong with the code? Thank you.
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/sleep.h>
SIGNAL (SIG_INTERRUPT1)
{
PORTC = PORTC + 1;
// Enable global interupt (page 9)
SREG |= 0x80;
/** Sleep Mode **/
set_sleep_mode(SLEEP_MODE_IDLE);
sleep_mode();
}
int main (void)
{
DDRC |= 0xFF;
PORTC = 0x00;
/** Record button interupt **/
// Any logical change on INT1 generates an interupt
MCUCR |= 0x04;
// Enable external interupt pin INT1
GICR |= 0x80;
// Enable global interupt (page 9)
SREG |= 0x80;
/** Sleep Mode **/
set_sleep_mode(SLEEP_MODE_IDLE);
sleep_mode();
}