[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] problems with timer0 on atmega128

From: Josh Thompson
Subject: [avr-gcc-list] problems with timer0 on atmega128
Date: Wed, 29 Jan 2003 19:46:36 -0500
User-agent: Mutt/1.3.28i


I am trying to figure out how to use a timer to run code while my main
program loop is doing something else.  I have 2 LEDs connected to an
atmega128, one to PORTD, the other to PORTA.  When running the attached
code, I would expect this to happen:

at start, LED on PORTA should be on steady
LED on PORTD should be flashing rapidly

after some amount of time,
LED on PORTA should go off and
LED on PORTD should be flashing slower

All that happens is that LED on PORTA comes on.

Here is how I'm compiling it:

avr-gcc -mmcu=atmega128 main.c -o main

Thanks for your help; this is driving me crazy!!

#include <avr/iom128.h>
#include <sig-avr.h>
#include <interrupt.h>
#include <io.h>


volatile static unsigned char timerCounter;

void initTimer(void) {
   outb(TCCR0, 5);        // set timer0 prescaler
   outb(OCR0, 0xff);       // set compare0 to 0xff
   sbi(TIMSK, OCIE0);    // interrupt on compare
   timerCounter = 0;


int main() {
   volatile static unsigned int count;
   volatile static unsigned int max;

   DDRD = 0xff;    PORTD = 0X00;
   DDRA = 0xff;    PORTA = 0x01;

   max = 1000;

   for(;;) {
      PORTD = 0x60;
      for(count = 0; count < max; count++);
      PORTD = 0x00;
      for(count = 0; count < max; count++);

      if (timerCounter > TIMERCOUNTER_PERIODIC_TIMEOUT) {
         cbi(TIMSK, OCIE0);
         PORTA = 0x00;
         max = 5000;
avr-gcc-list at http://avr1.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]