Delay function not working in Atmel Studio 7

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, 

 

A beginner here. Trying to make a blink LED program but the _delay_ms() function is not working. Pls assist. 

 

/*
 * GccApplication1.c
 *
  

#define F_CPU
#define F_CPU 16000000UL 

#endif

#include <avr/io.h>
#include <delay.h>

int main(void)
{
    
    DDRD=0xFF;
    
    while (1) 
    {
        PORTD=0xFF;
        _delay_us(1000)
        PORTD=0x00;
        _delay_us(1000)
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

#include <util/delay.h>

 

https://onlinedocs.microchip.com...

 

Also, what doesnt work... You will usually get much better answers if you tell us that :)

:: Morten

 

(yes, I work for Microchip, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Hi @meolsen. I checked the avr functions and tried with <util/delay.h> but it still gives me a main.o error. Error ss attached. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try renaming "E:\New Folder" to remove the space from the name.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yelo95 wrote:
the _delay_ms() function is not working.

yelo95 wrote:
 _delay_us(1000)

 

Also, how about a semicolon to end statements?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


 

 

still not working. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What does not work? How do you know that it does not work?   Nevermind, it  hidden at the bottom of the listing.

 

We really need more of the error list than "recipe failed". That is about like saying "the night is dark".

 

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Tue. Apr 14, 2020 - 11:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yelo95 wrote:
still not working
A thoroughly unhelpful diagnostic statement.

 

What are you expecting to happen?

What is happening?

What have you done to investigate?

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And, of course, you realize that defining F_CPU doesn't really change the frequency of the device...

How are the fuses set?

Is CKDIV8 programmed?

David

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think that the blinking cycle of 500Hz (ON: 1ms, OFF: 1ms) is invisible to the human eye.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yelo95,

 

This has been pointed out several times before:  You are using  _delay_us(1000) so the delay is 1000 micro seconds

 

Change those to _delay_ms(1000) and it just might work.

 

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius