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.

[SOLVED] Error (timer0 AVR microcontroller)

Status
Not open for further replies.

Don_dody

Full Member level 1
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
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top