LPC1768 – Sending a Byte output to a port

Just  a Simple code snippet that allows you to send a byte over a 8-bit wide parallel bus when using 32 bit devices such as those based on the ARM architecture.

While programming AVRs this usually would suffice to send a BYTE over a parallel 8-bit wide port.Here’s an avr-gcc example

PORTC = data;

But with the a 32-bit microcontroller For example the LPC1768 from NXP.

Each port is 32 bits wide and in order to send  a byte over an 8-bit section of the 32 bit wide ports

a write to the PIN register of the respective port doesnt work.The Arm cortex-m3 has registers called SET,CLR,MASK and PIN for each of the ports.The purpose of the registers is pretty obvious and for more info refer to the datasheet of the LPC1768 .

now in order to send an 8 bit data over a section of the port beginning at byte number 19

LPC_GPIO2->FIOSET |= (data << 19);

data ^= 0xFF;

LPC_GPIO2->FIOCLR |= (data << 19);

sends the data over the 8 bit section of port 2 beginning from pin 19 to pin 26 of the LPC1768.

1.First the pins corresponding to all the ones present in the 8-bit data are set.

2.The data is exored with FF.This sets all the zeroes in the data to ones and all the ones to zeroes

3.Then the data containing the ones in place where the original data had zeroes is used to clear the port.Hence only those pins corresponding to the Zeroes in the data are cleared.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s