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

simple startup program

hi....i am just starting with ARM microcontrollers........
i want to make a program so that i can monitor a pin like P0.8 and if its high then LED should glow on P0.22

here is pseudocode for it

#include <LPC21xx.h>
#define led (1<<22)
#define sw (1<<8)
int main (void)
{ PINSEL0=sw;
IODIR0=0xFFFFFFF; if (sw == 1)

IOSET0 = (1<<22); else IOCLR0 = (1<<22);
}

Parents
  • Do your teachers not provide you with guidance, or notes?

    I have no idea what board you have, and I'm not much into NXP, but this would seem to be a more sensible solution. Note the use of PRE tags for source code, per the "Tips for Posting Messages"

    #include <LPC21xx.h>
    
    #define led (1<<22) // Led is bit 22
    #define sw (1<<8)  // Switch is bit 8
    
    int main (void)
    {
      IODIR0 &= ~sw; // Set as inputs
      IODIR0 |= led; // Set as outputs
    
      while(1)
      {
        if (IOPIN0 & sw) // Check switch state, reflect to led
          IOSET0 = led;
        else
          IOCLR0 = led;
      }
    }
    

Reply
  • Do your teachers not provide you with guidance, or notes?

    I have no idea what board you have, and I'm not much into NXP, but this would seem to be a more sensible solution. Note the use of PRE tags for source code, per the "Tips for Posting Messages"

    #include <LPC21xx.h>
    
    #define led (1<<22) // Led is bit 22
    #define sw (1<<8)  // Switch is bit 8
    
    int main (void)
    {
      IODIR0 &= ~sw; // Set as inputs
      IODIR0 |= led; // Set as outputs
    
      while(1)
      {
        if (IOPIN0 & sw) // Check switch state, reflect to led
          IOSET0 = led;
        else
          IOCLR0 = led;
      }
    }
    

Children