Calling ports in C on the microcontroller

assemblycmicrocontrolleroperating system

I have been developing a small OS for my lpc1313fbd48. I am sending all of the C and assembly code in a binary file. I want to be able to call the ports in C and have an LED turn on for a few seconds and then turn on my vibrating motor (both of which are connected to the IOs on the microcontroller). How would I call the ports in C?

Best Answer

You don't "call" an IO port, you manipulate the registers that control it. You should have the LPC13xx.h file from NXP, which defines C data structures that you can use to access the ports. After including this file you can control the port pins in C with something like:

LPC_GPIO3->DIR  |= (1 << 4);  // make P3.4 an output pin
LPC_GPIO3->DATA |= (1 << 4);  // set P3.4 high
LPC_GPIO3->DATA &= ~(1 << 4); // set P3.4 low

Of course you need to add a delay loop of some kind if you want to see the LED turn on and off.