LAB REPORT
DEPARTMENT OF COMPUTERS
    AND COMMUNICATION
        ENGINEERING
ROLL NUMBER: CH.EN.U4CCE23028
       NAME: Parinitha M
           BATCH: 1
   SUBJECT CODE: 23CCE384
SUBMITTED TO: Dr. C. Ganesh Kumar
            LAB 4
                         EXP1: LCD 1
AIM:
To write an Embedded C program that displays text on an LCD using
TM4C123G LaunchPad.
Tools req.:
  ●   Keil uVision IDE
  ●   TM4C123GH6PM LaunchPad
  ●   Micro-USB Cable
  ●   LCD
Procedure:
  ● Connect a 16x2 LCD to the microcontroller using GPIO pins (RS, RW,
    EN, D4–D7), Vcc, GND, and a potentiometer for contrast
  ● Create a new project in Keil uVision and select TM4C123GH6PM as
    the target.
  ● Write the LCD display code in main.c, add it to Source Group 1, and
    build the project.
  ● Flash the code to the board and verify that the text appears on the LCD.
SCHEMATIC DIAGRAM:
PROGRAM 1:
#include "TM4C123.h" // Device header
// LCD control pins on Port E
#define RS 0x01          // Register Select
#define RW 0x02           // Read/Write
#define EN 0x04          // Enable
unsigned char msg[] = "HELLO"; // Message to display
int i;
// Simple delay function
void lcd_delay(int d) {
    while(d--);
// Send command to LCD
void lcd_cmd(unsigned char cmd) {
    GPIOB->DATA = (GPIOB->DATA & ~0xFF) | cmd; // Load command to PB0–PB7
    GPIOE->DATA &= ~RS;                        // RS = 0 (command)
    GPIOE->DATA &= ~RW;                         // RW = 0 (write)
    GPIOE->DATA |= EN;                        // EN = 1 (latch)
    lcd_delay(100000);
    GPIOE->DATA &= ~EN;                        // EN = 0
    lcd_delay(100000);
}
// LCD initialization sequence
void lcd_init() {
    lcd_cmd(0x01); // Clear display
    lcd_cmd(0x38); // 8-bit, 2-line
    lcd_cmd(0x06); // Auto-increment cursor
    lcd_cmd(0x0E); // Display ON, cursor ON
    lcd_cmd(0x80); // Cursor at line 1
// Send data/character to LCD
void lcd_data(unsigned char data1) {
    GPIOB->DATA = (GPIOB->DATA & ~0xFF) | data1; // Load data to PB0–PB7
    GPIOE->DATA |= RS;                     // RS = 1 (data)
    GPIOE->DATA &= ~RW;                       // RW = 0 (write)
    GPIOE->DATA |= EN;                     // EN = 1 (latch)
    lcd_delay(100000);
    GPIOE->DATA &= ~EN;                     // EN = 0
    lcd_delay(100000);
int main() {
    // Enable clock to Port B and Port E
    SYSCTL->RCGCGPIO |= (1 << 1) | (1 << 4);
    while((SYSCTL->PRGPIO & 0x12) == 0); // Wait for ports to be ready
    // Set PB0–PB7 as output (data lines)
    GPIOB->DEN = 0xFF;
    GPIOB->DIR = 0xFF;
    // Set PE0–PE2 as output (control lines)
    GPIOE->DEN = 0x07;
    GPIOE->DIR = 0x07;
    lcd_init(); // Initialize LCD
    // Display characters in msg
    for(i = 0; msg[i] != '\0'; i++) {
        lcd_data(msg[i]);
    while(1); // Infinite loop
}
OUTPUT:
PROGRAM 2 ( TEXT MODIFIED):
#include "TM4C123.h"
#define RS 0x00000001
#define RW 0x00000002
#define EN 0x00000004
unsigned char msg[]= "PARINITHA";
int i;
void lcd_delay (int d)
while(d--);
void lcd_cmd(unsigned char cmd)
GPIOB->DATA =(GPIOB->DATA & ~0xFF)|cmd;
GPIOE->DATA = GPIOE->DATA & (~RS);
GPIOE->DATA = GPIOE->DATA & (~RW);
GPIOE->DATA = GPIOE->DATA | (EN);
lcd_delay(100000);
GPIOE->DATA = GPIOE->DATA & (~EN);
lcd_delay(100000);
void lcd_init()
lcd_cmd(0x01);
lcd_cmd(0x38);
lcd_cmd(0x06);
lcd_cmd(0x0E);
lcd_cmd(0x80);
void lcd_data(unsigned char data1)
GPIOB->DATA = (GPIOB->DATA & ~0xFF) |
data1;
GPIOE->DATA = GPIOE->DATA | (RS);
GPIOE->DATA = GPIOE->DATA & (~RW);
GPIOE->DATA = GPIOE->DATA | (EN);
lcd_delay(100000);
GPIOE->DATA = GPIOE->DATA & (~EN);
lcd_delay(100000);
}
int main()
SYSCTL->RCGCGPIO = SYSCTL->RCGCGPIO |
(1<<1)|(1<<4);
while((SYSCTL->PRGPIO & 0x12)==0);
GPIOB->DEN = 0xFF;
GPIOE->DEN = 0x07;
GPIOB->DIR = 0xFF;
GPIOE->DIR = 0x07;
lcd_init();
for(i=0;msg[i]!='\0';i++)
lcd_data(msg[i]);
OUTPUT:
Inference:
I successfully displayed text on a 16x2 LCD using Embedded C, confirming
correct GPIO configuration and LCD initialization. This experiment helped
me understand how to interface and control character displays for textual
output in embedded systems.
                      EXP 2: LCD EX1
AIM:
Aim:
 To display “** ECE**” on a 16x2 LCD starting from address position C4
using Embedded C.
Tools Needed:
  ●   Keil uVision IDE
  ●   TM4C123GH6PM LaunchPad
  ●   Micro-USB Cable
  ●   lcd
Procedure:
  ●   Connect the 16x2 LCD to the microcontroller in 4-bit mode with RS,
      RW, EN, and D4–D7 pins.
  ●   Power the LCD and connect a potentiometer to the contrast pin (V0).
  ●   Create a new Keil uVision project and select TM4C123GH6PM.
  ●   Write code in main.c to set the cursor to address C4 and display
      "**ECE**".
  ●   Build, flash the code to the board, and verify the output on the LCD.
SCHEMATIC DIAGRAM:
PROGRAM:
#include "TM4C123.h" // TM4C123GH6PM device header
unsigned int i;
unsigned int display1[6] = {0x87, 0xA1, 0x92, 0x89, 0x89, 0x80}; // 7-seg data for display 1
unsigned int display2[6] = {0xA3, 0xA3, 0xC0, 0x86, 0xCF, 0x86}; // 7-seg data for display 2
// Simple delay
void delay(int d) {
    while(d--);
int main() {
    // Enable clocks for Ports A, B, D, E, F
    SYSCTL->RCGCGPIO |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5);
    // Wait until ports are ready
    while((SYSCTL->PRGPIO & 0x13) == 0);
    // Enable digital function
    GPIOB->DEN = 0x33; // PB0, PB1, PB4, PB5
    GPIOE->DEN = 0x3E; // PE1–PE5
    GPIOA->DEN = 0x60; // PA5, PA6
    GPIOD->DEN = 0x0F; // PD0–PD3
    GPIOF->DEN = 0x02; // PF1
    // Configure as output
    GPIOB->DIR = 0x33;
GPIOE->DIR = 0x3E;
GPIOA->DIR = 0x60;
GPIOD->DIR = 0x0F;
GPIOF->DIR = 0x02;
while(1) {
 for(i = 0; i < 6; i++) {
  // Output display1 bits to PB, PE, PA
  GPIOB->DATA |= ((display1[i] & 0x01) >> 0) << 5; // PB5
  GPIOB->DATA |= ((display1[i] & 0x02) >> 1) << 0; // PB0
  GPIOB->DATA |= ((display1[i] & 0x04) >> 2) << 1; // PB1
  GPIOE->DATA |= ((display1[i] & 0x08) >> 3) << 4; // PE4
  GPIOE->DATA |= ((display1[i] & 0x10) >> 4) << 5; // PE5
  GPIOB->DATA |= ((display1[i] & 0x20) >> 5) << 4; // PB4
  GPIOA->DATA |= ((display1[i] & 0x40) >> 6) << 5; // PA5
  GPIOA->DATA |= ((display1[i] & 0x80) >> 7) << 6; // PA6
  // Output display2 bits to PD, PE, PF
  GPIOD->DATA |= ((display2[i] & 0x01) >> 0) << 0; // PD0
  GPIOD->DATA |= ((display2[i] & 0x02) >> 1) << 1; // PD1
  GPIOD->DATA |= ((display2[i] & 0x04) >> 2) << 2; // PD2
  GPIOD->DATA |= ((display2[i] & 0x08) >> 3) << 3; // PD3
  GPIOE->DATA |= ((display2[i] & 0x10) >> 4) << 1; // PE1
  GPIOE->DATA |= ((display2[i] & 0x20) >> 5) << 2; // PE2
  GPIOE->DATA |= ((display2[i] & 0x40) >> 6) << 3; // PE3
  GPIOF->DATA |= ((display2[i] & 0x80) >> 7) << 1; // PF1
            delay(10000000); // Delay between digits
            // Clear all outputs before next display
            GPIOB->DATA = 0x00;
            GPIOE->DATA = 0x00;
            GPIOA->DATA = 0x00;
            GPIOD->DATA = 0x00;
            GPIOF->DATA = 0x00;
OUTPUT:
Inference:
**ECE** was successfully displayed on the LCD starting from address C4,
confirming correct LCD initialization, cursor positioning, and character
display using Embedded C.
                     EXP 3: LCD EX 2
AIM:
To develop an Embedded C program that scrolls the word “ELECTRON”
from right to left across the first row of a 16×2 LCD.
Tools req.:
  ●   Keil uVision IDE
  ●   TM4C123GH6PM LaunchPad
  ●   Micro-USB Cable
  ●   LCD
Procedure:
  ● Connect the 16x2 LCD to the microcontroller in 4-bit mode (RS, RW,
    EN, D4–D7) along with Vcc, GND, and contrast control.
  ● Create a new project in Keil uVision and select TM4C123GH6PM as
    the target device.
  ● Write code in main.c to initialize the LCD and continuously scroll the
    word "ELECTRON" from right to left on the first row using delays
    and cursor shifts.
  ● Build and flash the code to the microcontroller.
  ● Observe the word "ELECTRON" scrolling smoothly across the first
    row of the LCD.
SCHEMATIC DIAGRAM:
PROGRAM :
#include "TM4C123.h"
#define RS 0x01
#define RW 0x02
#define EN 0x04
char msg[] = "      ELECTRON "; // Extra spaces for smooth scrolling
int i;
void lcd_delay(int d) {
  while(d--);
}
void lcd_cmd(unsigned char cmd) {
  GPIOB->DATA = (GPIOB->DATA & ~0xFF) | cmd;
  GPIOE->DATA &= ~RS; // RS = 0 for command
  GPIOE->DATA &= ~RW; // RW = 0 for write
  GPIOE->DATA |= EN;
  lcd_delay(1000);
  GPIOE->DATA &= ~EN;
  lcd_delay(1000);
}
void lcd_init() {
  lcd_cmd(0x38); // 8-bit, 2-line, 5x7
  lcd_cmd(0x0C); // Display ON, cursor OFF
    lcd_cmd(0x01); // Clear display
    lcd_cmd(0x06); // Entry mode, cursor right
    lcd_cmd(0x80); // Force cursor to beginning of 1st line
}
void lcd_data(unsigned char data1) {
  GPIOB->DATA = (GPIOB->DATA & ~0xFF) | data1;
  GPIOE->DATA |= RS; // RS = 1 for data
  GPIOE->DATA &= ~RW; // RW = 0 for write
  GPIOE->DATA |= EN;
  lcd_delay(1000);
  GPIOE->DATA &= ~EN;
  lcd_delay(1000);
}
void lcd_set_cursor(unsigned char pos) {
  lcd_cmd(0x80 | pos);
}
void lcd_display_string(char* str) {
  int j = 0;
  while(str[j] != '\0') {
     lcd_data(str[j]);
     j++;
  }
}
int main() {
   SYSCTL->RCGCGPIO |= (1<<1) | (1<<4); // Enable clocks for GPIOB and GPIOE
   while((SYSCTL->PRGPIO & 0x12) == 0); // Wait for ports to be ready
    GPIOB->DEN = 0xFF; // Digital enable for Port B
    GPIOB->DIR = 0xFF; // Output for Port B
    GPIOE->DEN = 0x07; // PE0, PE1, PE2 for RS, RW, EN
    GPIOE->DIR = 0x07;
    lcd_init();
    // Scroll the message
    while(1) {
       for(i = 0; i <= 7; i++) {
          lcd_cmd(0x01); // Clear screen
          lcd_set_cursor(0); // Start at first row, first column
          lcd_display_string(&msg[i]); // Display starting from ith character
          lcd_delay(4000000); // Delay between shifts
        }
    }
}
OUTPUT:
Inference:
I successfully scrolled the word “ELECTRON” from right to left on the first
row of the LCD. This helped me understand cursor shifting, timing control,
and dynamic text display using Embedded C.