 Hello everyone. Myself Prithviraj Thambe working as an assistant professor in Department of Electronics Engineering at Vulture Institute of Technology, Solapool. Let us today learn one interfacing example for LPC176 at my controller. So at the end of this session, students will be able to write a simple program to interface GPIO devices like LEDs and switches, outline. So GPIO port pins are available through 5 General Purpose Bidational Digital IOPorts, port 0 to port 4, which you can use for interfacing General Purpose IO devices like LEDs, switches, relays, like devices. So let us review the registers, which we will require for writing a simple interfacing program. So from pin connect block, we may require pin function selector register, which controls the function of each port pin. Also for GPIO, we may require fast IO direction selection register, fast IO mass register, fast IO set register, fast IO clear register and fast IO pin register. So let us design this small example. So let us interface a LED and a switch to LPC176 at port pins P0.4 and P0.5 respectively as shown below. So this LED is connected through this small register to P0.4 in pull-down fashion and this switch is connected to P0.5. So let us write a C program to turn LED off when the switch is pressed and turn LED on when switch is released. So look at this switch. So by default P0.5 is connected to ground. So if you read the status of P0.5, by default it will read as a zero. So when the switch is pressed, then P0.5 is connected to 3.3 volt and when you read the status of P0.5, it will read as a logic high. So let us first configure P0.4 and P0.5 for GPIO functionality. So we require pin cell zero register. Let us calculate the hex value for pin cell zero, which configures P0.4 and P0.5 as a GPIO pin. So this pin cell zero is third-bit register. So we are interested in P0.4 and P0.5, that is why we are going to make these two pins GPIO pins by writing 00 in the particular bit of pin cell zero register. So bit 8, 9, 10 and 11 are responsible for this. So applying mask and then ordering the desired function, we will achieve this. So the value we will get is 0xfffff0ff. So this statement configures these two pins for GPIO functionality. Next set the direction of these two port pins. Now here LED is connected to P0.4, LED is the output device. So we should connect P0.4 as output and a switch is connected to P0.5. So P0.5 should be configured for input. So let us calculate these two values which configures these two pins for the desired direction. So if you write hex value, you will get the hex value for the direction as 0xfffffdf. So this statement selects the direction of P0.5 as an input and the second statement, the ordering statement selects the direction of P0.4 as an output. Now let us write the values for fast IO set register and fast IO clear register. So here if you make P0.4 high, then this LED will turn on. If you make P0.4 low, then LED will turn off. So fast IO set register is used to turn this LED on and fast IO clear register is used to turn LED off because this LED is connected in pull down fashion. So let us calculate the values for IO set and IO clear register. So after writing 32 bit format for IO set register, you will get 0x10 value for both IO set and IO clear register. So these two statements turns this LED on and off. Now how to read the status of switch? So as we mentioned before, by default P0.5 will be read as a 0. But when this switch is pressed, this status of P0.5 will change to high. So how to read the status of P0.5? So we have fast IO pin value register. So this pin value register you can use for reading the status of any port pin. So this statement fast IO pin ended with 0x20 will read the status of P0.5. So suppose the switch is open, then P0.5 is connected to ground through this R2 register. Then the result of this statement is 0. So you can use this 0 in if statement or for making decision. If you press this switch, then this P0.5 will be connected to 3.3 which is logic high. Then the result of this statement will be a non-zero value. Again you can use this for making the decision. So this ending is here used to make the decision whether this pin is whether this switch is pressed or not. So this is the program and these are the values we already calculated. So first statement is the include. So hash include LPC17xx.h includes the definitions of all these registers int main is our entry point of the program. So this first statement configures the function of P0.4 and P0.5 for a GPI functionality. First IODR register ended with 0xFFTF configures P0.5 as input. First IODR register odd with 0x10 configures P0.4 as output. Now here we have implemented our logic. So this is an infinite loop while 1. So this first statement checks the status of P0.5 whether the switch is pressed or not. So by default this switch is not pressed. So this fast IO pin ended with 0x20 returns 0. So this is a false condition. So not of a false becomes true and fast IO set is equal to 0x0010 will execute. So this statement will execute which turns the LAD on. Now suppose when this switch is pressed this condition will become true not of true which is false. So the else part will execute. So in else part we have fast IO clear statement. So this statement will turn off this LAD. So this is how you can interface a simple switch and LAD like input output devices to LPC176 at my controller. The values of registers can be calculated by referring the datasheets of LPC176 set and by referring the specifications of these LEDs and switches. References. Thank you.