[SOLVED] Error (timer0 AVR microcontroller)

Status
Not open for further replies.

Don_dody

Full Member level 1
Joined
Nov 4, 2012
Messages
96
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Indonesia
Visit site
Activity points
1,921
I want to make 1s delay using TIMER0 and Here is the code:

Code:
#include <mega8535.h>

interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
delay = delay + 1
}

void main(void)
{
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 3.906 kHz
// Mode: Normal top=FFh
TCCR0=0x05;
TCNT0=0xD9;
// Timer0 enable
TIMSK=0x01;
// Global enable interrupts
#asm("sei")

while (1)
      {
       delay(100);   //(100*10ms=1000ms)
      };
}

void delay(int delay_ms)
{
   TCNT0=0xD9;  //timer interval= 10 ms
   delay=0
   while(delay<=delay_ms)
   {
    }
}

I got error messages as follow:
1. undefined symbol 'delay'
2. the expression must be a modifiable lvalue

Whats wrong here?
 

You can't use delay before declaring the delay function.

either move the delay function before main or add the prototype of the delay function before main so that the compiler is informed about it

Code:
void delay(int delay_ms);
 

OK, I've modified it become:

Code:
#include <mega8535.h>

void delay(int delay_ms)
{
   TCNT0=0xD9;  //timer interval = 10 ms
   delay=0
   while(delay<=delay_ms)
   {
    }
}

interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
delay = delay + 1
}



void main(void)
{
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 3.906 kHz
// Mode: Normal top=FFh
TCCR0=0x05;
TCNT0=0xD9;
// Timer0 enable
TIMSK=0x01;
// Global enable interrupts
#asm("sei")

while (1)
      {
       delay(100);   //(100*10ms=1000ms)
      };
}

However I still got error:
Error: the expression must be a modifiable lvalue
 

delay represents in your code a function that doesn't return any result,
You cant use
Code:
while(delay<=delay_ms)
//or
delay = delay + 1
 

Still error hmmm

Well do you have any example or references to make delay using timer?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…