ES Module4
ES Module4
Module IV
19ECS431: Embedded Systems
UART programming
3. IOxDIR (GPIO Port Direction control register) : This is a 32-bit wide register. This
register individually controls the direction of each port pin. Setting a bit to ‘1’
configures the corresponding pin as an output pin. Setting a bit to ‘0’ configures the
corresponding pin as an input pin.
4. IOxCLR (GPIO Port Output Clear register) : This is a 32-bit wide register. This register
is used to make pins of Port LOW. Writing one to specific bit makes that pin LOW.
Writing zeroes has no effect.
#include <lpc214x.h>
while(1)
{
IOSET1 = 0xffffffff; // Make all the Port pins as high
delay_ms(1000);
GPIO
Timer
VPB DIV UART
ADC
DAC
I2C
SPI
Crystal Input Clock in
LPC2148
Oscillator PLL CPU
PR
Pcl Tcl
k k
PR+1 =
60MHz/1KHz
= 60,000
PR = 59999
For 1 us
Tick
Tclk =
Pclk = 60 1MHz
PR
MHz
TC0
PR+1 =
60MHz/1MHz
= 60
PR = 59
Blinking of LED using timer -
Program
#include<lpc214x.h>
int main()
{ T0CTCR=0X00;
T0PR=0XEA5F;
IO1DIR=0X00FF0000;
while(1)
{
IO1SET=0X00FF0000;
T0TC=0X0;
T0TCR=0X00000001; while(T0TC < 10);
T0TC=0X0;
IO1CLR=0X00FF0000;
T0TCR=0X00000001; while(T0TC < 10);
}
}
UAR
T • Two Identical UARTs UART0 & UART1
• We are using UART0 for our example.
CPU
Oscillator PLL
Pclk
GPIO
Timer
VPB DIV UART
ADC
DAC
I2C
SPI
02/05/2025 19ECS431: Embeded Systems; Module IV C Programs, Dept of EECE
Crystal Input UART Clock in
LPC2148
Oscillator PLL CPU
Baud Rate
Divisor = Pclk / (Baud rate x 16) x 16
= 60M/(16*9600)
=391 VPB DIV Divisor UART
=0187H
Load DLL with 0x87 and DLM with 0x01
DLL: Divisor latch LSB
DLM: Divisor latch MSB
DLM DLL
1 1 1
02/05/2025
U0LCR =
19ECS431: Embeded Systems; Module IV C Programs, Dept of EECE
UART0 Line Status Register
- U0LSR
U0DL U0DL
M L
Read/Write(RW): This signal is used to write the data/cmd to LCD and reads the busy flag
of LCD. For write operation the RW should be LOW and for read operation the R/W should
be HIGH.
Enable(EN): This pin is used to send the enable trigger to LCD. After sending the data/cmd,
Selecting the data/cmd register, Selecting the Write operation. An HIGH-to-LOW pulse has
to be sent on this enable pin which will latch the info into the LCD register and triggers the
LCD to act accordingly.
02/05/2025 19ECS431: Embeded Systems; Module IV C Programs, Dept of EECE
LCD -
Commands