Sie sind auf Seite 1von 23

` ` ` ` ` ` ` ` `

Introduction GPIO overview Mode configuration GPIO initialization example Reading & Writing a GPIO pin GPIO_WRITE & GPIO_READ function Switch-LED Application 8-bit Counter Application Moving LED linear array

GPIO stands for General Purpose Input/Output. It is the most common peripheral that any microcontroller has . GPIO basically refers to simple digital pins that can have two states 0 or 1 . A GPIO can be configured as input or output . A collective block of pins that can be modified by means of common set of registers is known as GPIO port or sometimes parallel port .

LPC935 has four I/O ports: Port 0, Port 1, Port 2, and Port 3. Ports 0 , 1 , and 2 are 8-bit ports and Port 3 is a 2bit port .

8-bit mode registers


PxM1.y 0 0 1 1 PxM2.y 0 1 0 1 Port output mode Quasi-bidirectional Push-pull Input only ( high impedance ) Open drain

` ` ` `

void port_init () { P1M1 |= 0x10 ; // Configure port pin 1.4 as input only P1M2 &= ~0x10; P0M1 &= ~0x0F ; P0M2 |= 0x0F ; } // Configure port pin 0.0 to 0.3 as output

` ` `

` `

void main () { port_init () ; P0 |= 0x04 ; // Set pin 0.2 . P0 &= ~0x08 ; // Clear pin 0.3 while ( 1 ) ;

` `

void main () { unsigned char pin_state ; port_init () ; // Read value of P0.3 . pin_state = ( P0 >> 3 ) & 0x01 ; while ( 1 ) ;

/* Sets a value at a particular port pin . Params : Port_No => port to which pin belongs 0 means port 0 1 for port 1 2 for port 2 3 for port 3 Pin_No => pin no. of the pin to be set Can have values 0 to 7 . State => Value to be set on pin Can be either 0 or 1 . */ void gpio_write(unsigned char port_name , unsigned char pin_name , unsigned char data_write)

GPIO_ read function ( )

` `

Port0 is connected to switches . Port2 is connected to LED . Whenever switch connected to any gpio in port0 is pressed LED connected to corresponding port2 pin is switched ON else switched OFF .

To implement an 8-bit digital UP/DOWN Counter using GPIO port0 of LPC935 .

UP COUNTER

DOWN COUNTER

` `

We are given a linear LED array of 8 LEDs . We have to glow each LED alternatively to give it a moving effect from right to left or left to right . Only one LED will be active at any point of time .

LEFT to RIGHT

RIGHT to LEFT

Das könnte Ihnen auch gefallen