This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Toggling LED

Hello all

I am quite new to Keil STR9 Series. I was just learning the whole thing by going through and trying some small examples with it.
I want to know how to control just one LED ( say 7.0) to blink at a time.

   while (1)
         {
            for (n = 0x01; n <= 0xFF; n <<= 1)
            {
               GPIO7->DR[0x3FC] = n;
            }
         }

This piece of code turns on the all 8 LEDS at the same time. How can i blink just one LED (7.0) every 1 second?

Thanks

Parents
  • So your first reference to wait(ms) was just a random chance? Not based on you having found such a function in any runtime library documentation for any runtime library you are using? Is that a good way to write code?

    Your next attempt - did you test to search about delays on this forum? If you did, you would have found quite a number of discussions about the problems with using busy-loops in C without binding the delay time to some real hardware property.

    Another thing - how long do you think your puny 1000-step delay takes? Do you really expect that your eye will be able to see any result of such a short delay?

    Yet another thing - if you want to blink a LED, you need to repeatedly do:
    - Turn on the LED.
    - Wait for x milliseconds.
    - Turn off the LED.
    - Wait for 1000-x milliseconds.

    Based on the documentation for your processor:
    - Do you see code both for turning on and for turning off any LED?
    - Does the processor documentation suggest that a 1000-step for loop would be a suitable delay?

    Note that turn on/turn off can be handled by the same primitive, if you use a primitive that toggles the pin state.

Reply
  • So your first reference to wait(ms) was just a random chance? Not based on you having found such a function in any runtime library documentation for any runtime library you are using? Is that a good way to write code?

    Your next attempt - did you test to search about delays on this forum? If you did, you would have found quite a number of discussions about the problems with using busy-loops in C without binding the delay time to some real hardware property.

    Another thing - how long do you think your puny 1000-step delay takes? Do you really expect that your eye will be able to see any result of such a short delay?

    Yet another thing - if you want to blink a LED, you need to repeatedly do:
    - Turn on the LED.
    - Wait for x milliseconds.
    - Turn off the LED.
    - Wait for 1000-x milliseconds.

    Based on the documentation for your processor:
    - Do you see code both for turning on and for turning off any LED?
    - Does the processor documentation suggest that a 1000-step for loop would be a suitable delay?

    Note that turn on/turn off can be handled by the same primitive, if you use a primitive that toggles the pin state.

Children
No data