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
  • wow... that really an easy method.

    I did it like this

    while(1) {
    RTC_GetTime(BINARY,&time);
            if (old_time != time.seconds)
                    {
                            old_time = time.seconds;
                            GPIO_Write(GPIO7, old_time &0x1);
                      }
             }
    


    but how is the port bit organised ??
    Is it LED 7.0 = bit 1,LED 7.1 = bit 2,... and so on ?

    when i gave 0x1 , LED 7.0 blinked every 1 second. It was jus a random guess. How does it work with other LEDs? what is the port bit for other LEDs?

    thnx

Reply
  • wow... that really an easy method.

    I did it like this

    while(1) {
    RTC_GetTime(BINARY,&time);
            if (old_time != time.seconds)
                    {
                            old_time = time.seconds;
                            GPIO_Write(GPIO7, old_time &0x1);
                      }
             }
    


    but how is the port bit organised ??
    Is it LED 7.0 = bit 1,LED 7.1 = bit 2,... and so on ?

    when i gave 0x1 , LED 7.0 blinked every 1 second. It was jus a random guess. How does it work with other LEDs? what is the port bit for other LEDs?

    thnx

Children
  • There is a schematic that you can check for connections - you should check it before writing your code. I believe it is in the Keil folder when you installed the s/w. Normally, I would make a summary of connections for easy lookup.

    IC6 74LVC244 P7.7 => LED7 (1 = ON) P7.6 => LED6 (1 = ON) P7.5 => LED5 (1 = ON) P7.4 => LED4 (1 = ON) P7.3 => LED3 (1 = ON) P7.2 => LED2 (1 = ON) P7.1 => LED1 (1 = ON) P7.0 => LED0 (1 = ON)

  •             IC6
             74LVC244
      P7.7      =>     LED7 (1 = ON)
      P7.6      =>     LED6 (1 = ON)
      P7.5      =>     LED5 (1 = ON)
      P7.4      =>     LED4 (1 = ON)
      P7.3      =>     LED3 (1 = ON)
      P7.2      =>     LED2 (1 = ON)
      P7.1      =>     LED1 (1 = ON)
      P7.0      =>     LED0 (1 = ON)