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

nid help on LED blinking

i have problem with the led blinking. I using the exmaple program given by keil using uVision3. When i run the program, the LED on the development board didnt blink, it just stay on! wat should i do?

thanks!

Parents
  • 
      unsigned char j;                    /* LED var */
    
    .
    .
    .
    
        for (j=0x01; j< 0x80; j<<=1)
        {
          .
          .
          .
        }
    

    Because j is an unsigned char, the test for j<0x80 will always be true and you will never exit the loop.

    Pass#1 j = 0x01
    Pass#2 j = 0x02
    Pass#3 j = 0x04
    Pass#4 j = 0x08
    Pass#5 j = 0x10
    Pass#6 j = 0x20
    Pass#7 j = 0x40
    Pass#8 j = 0x80
    Pass#9 j = 0x00
    ...
    Pass#n j = 0x00

Reply
  • 
      unsigned char j;                    /* LED var */
    
    .
    .
    .
    
        for (j=0x01; j< 0x80; j<<=1)
        {
          .
          .
          .
        }
    

    Because j is an unsigned char, the test for j<0x80 will always be true and you will never exit the loop.

    Pass#1 j = 0x01
    Pass#2 j = 0x02
    Pass#3 j = 0x04
    Pass#4 j = 0x08
    Pass#5 j = 0x10
    Pass#6 j = 0x20
    Pass#7 j = 0x40
    Pass#8 j = 0x80
    Pass#9 j = 0x00
    ...
    Pass#n j = 0x00

Children