Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

[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
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?
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,377
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);
 

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
Activity points
1,921
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
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,377
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
 

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
Activity points
1,921
Still error hmmm

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

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
Activity points
1,921
I got it.
Now I can make a simple blinking led with 1s delay using timer.

Thanks.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top