In-Depth Notes on Input/Output (IO) Programming
Module 3: INPUT/OUTPUT (IO) PROGRAMMING
Overview of IO programming:
- Involves interacting with various devices using microcontrollers.
- Includes components like Pin Connect Block, General Purpose Input and Output (GPIO) Registers, and GPIO configuration.
Key Components:
- Pin Connect Block (PCB):
- Configures pinout and pin functions.
- Allows assignment of input/output and interrupt functions to the pins.
- GPIO Registers:
- Manage the behavior of GPIO pins.
- Each pin can be configured as input/output during runtime.
Microcontroller Ports:
- Example: LPC1768 has 5 GPIO ports (P0 to P4), each with 32 bits.
- Total usable pins are 70 out of 100 available.
Memory Mapped I/O
- IO ports on embedded microcontrollers are typically memory mapped.
- Software can read/write directly to these ports, but I/O ports may behave differently than memory variables.
Types of I/O Interfaces
Parallel I/O Port
- A basic interface allowing simultaneous data access.
- Input Port:
- Read-only access to external digital signals.
- Triggered by reading from the port address, reflecting the current digital signals present.
Output Port
- Implemented using registers or flip-flops driven by write strobe.
- Data written to an output port is held until the next write operation.
GPIO Operations
- General-purpose operations like reading and writing from/to port pins.
- Used to control peripherals such as LEDs, motor drivers, and keypads.
Interfacing with Components
1. LED Interfacing
- Basic Steps:
- Initialize microcontroller, configure power supply, and clock rate.
- Assign pins and control the GPIO state to turn LEDs on/off.
2. Seven Segment Display
- Types:
- Common Cathode: All cathodes are connected to ground (logic 0).
- Common Anode: All anodes are powered (logic 1).
- Can display numbers 0-9 and some letters (A-F).
3. Stepper Motor Control
- Moves in discreet steps; control involves energizing phases in sequence.
- Basic connectivity includes phase A, B, C, D connections to GPIO pins.
4. LCD Interfacing
- Control Pins:
- RS (Register Select), RW (Read/Write), EN (Enable), and Data Pins (D0-D7).
- Commands include initializing, clearing, and controlling the LCD display.
5. 4x4 Keypad Interfacing
- A matrix format connecting buttons to the microcontroller.
- The controller scans input states from rows and columns, identifying pressed keys.
- Debouncing: Hardware used to handle key press noise.
Register Configuration
- Example Registers:
- PINSEL: Control the function of each pin on GPIO ports.
- FIODIR: Direction control for port pins (input/output).
- FIOSET/FIOCLR: Set or clear the output state of GPIO pins.
Programming Example (Pseudo Code)
```c
include
include
void main()
{
SystemInit();
LPCGPIO2->FIODIR |= (1<GPIO2->FIOCLR = (1<<29); // Turn LED OFF
delay_ms(1000);
}
}
```
- Initializes GPIO and continuously blinks LED connected to P1.29.
Summary
- IO Programming enables embedded systems to interact with various devices, controlling hardware based on software instructions.
- Proper understanding and manipulation of GPIO and related registers are crucial for effective microcontroller programming.
References
- UM10360, LPC 176x/5x User Manual for additional details on GPIO programming.