Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with writing C code for handling interrupt

Status
Not open for further replies.

cs181

Newbie level 1
Joined
Oct 6, 2005
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,292
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();
}
 

Have you the same problem with this?


SIGNAL (SIG_INTERRUPT1)
{
static unsigned char ucTestPort = 0;

PORTC = ucTestPort++;

// Enable global interupt (page 9)
SREG |= 0x80;
:
:

Gomez
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top