I'm trying to use the timer 0 on a mega 8. Everything works fine,
(I mean, i can see the timer TCNT0 incrementing) but when I want
to route the interrupt to an handler, I get a infinite reset.
Here a snipset of the code (full code, is attached)
SIGNAL(SIG_OVERFLOW0)
{
uptime ++;
return 0;
}
void inittimer()
{
// 1024 prescaler
sbi(TCCR0,CS02);
cbi(TCCR0,CS01);
sbi(TCCR0,CS00);
// set the interrupt handle
sbi(TIMSK,TOIE0);
uptime = 0;
}
If I comment the sbi(TIMSK..) all works fine. What can I do to fix
that .?
Thanks for any help.
/*
* Author: Jerome Kerdreux, Copyright: GPL
*
*
* Chip type : ATMEGA8
* Clock frequency : Internal clock 1 Mhz (factory default)
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include "test_avr.h"
#include "avr_compat.h"
#include "lcd.h"
#define TIMERINI 256-72
#define TIMERCON 0x05
volatile int uptime;
void delay_ms(unsigned short ms)
/* delay for a minimum of <ms> */
/* with a 1Mhz clock, the resolution is 1 ms */
{
uint8_t inner,inner1;
while (ms) {
inner = 100;
while (inner) {
inner--;
inner1 = 70;
while (inner1) {
inner1--;
}
}
ms--;
}
}
void flashled()
{
if bit_is_set(PORTD,PD5) { cbi(PORTD,PD5); }
else { sbi(PORTD,PD5); }
}
SIGNAL(SIG_OVERFLOW0)
{
uptime ++;
return 0;
}
void debug(char *msg)
{
lcd_gotoxy(0,0);
lcd_puts(msg);
delay_ms(1000);
}
void inittimer()
{
// 1024 prescaler
sbi(TCCR0,CS02);
cbi(TCCR0,CS01);
sbi(TCCR0,CS00);
// set the interrupt handle
//sbi(TIMSK,TOIE0);
uptime = 0;
}
int main(void)
{
char line[16];
sbi(DDRD,PD5);
lcd_init(LCD_DISP_ON);
lcd_clrscr();
debug("LCD Ok");
// init the the timer
sprintf(line,"TCCR0 %x" , TCCR0);
debug(line);
inittimer();
sprintf(line,"TCCR0 after %x" , TCCR0);
debug(line);
//
flashled();
sei();
debug("Sei Ok");
while (1)
{
delay_ms(500);
lcd_gotoxy(0,0);
sprintf(line,"Timer: %d " , uptime);
lcd_puts(line);
lcd_gotoxy(0,1);
sprintf(line,"TCNT0: %x " , TCNT0);
lcd_puts(line);
flashled();
}
return 0;
}
_______________________________________________
AVR-GCC-list mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list