0
\$\begingroup\$

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?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ What compiler are you using? The way you manipulate ports in C is dependent both on the microcontroller architecture and the compiler syntax. \$\endgroup\$
    – tcrosley
    May 21, 2013 at 23:00
  • \$\begingroup\$ @tcrosley I am using gcc for linux (specifically raspberry pi) and nasm for the assembly \$\endgroup\$
    – Coder404
    May 21, 2013 at 23:06

1 Answer 1

7
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ Where can I get the LPC13xx.h file? \$\endgroup\$
    – Coder404
    May 21, 2013 at 23:07
  • \$\begingroup\$ Go to www.lpcware.com and download one of their sample code bundles for the lpc1313 or the FreeRTOS files for the lpc13xx. You could also try downloading the lpcxpresso software and digging around in those files. You'll learn a lot by looking at the examples on the NXP sites. \$\endgroup\$
    – Joe Hass
    May 21, 2013 at 23:50
  • \$\begingroup\$ I found it here and here. Which one do I use? First or second? \$\endgroup\$
    – Coder404
    May 22, 2013 at 23:56
  • \$\begingroup\$ They look pretty much the same to me, except for comments and formatting. \$\endgroup\$
    – Joe Hass
    May 23, 2013 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.