Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views14 pages

Lab 3

The lab report details three experiments involving the use of Embedded C to control 7-segment displays with a Tiva C TM4C123G LaunchPad. Each experiment focuses on displaying digits or words using different GPIO configurations and multiple ports. The report includes procedures, schematic diagrams, and code implementations for each experiment, along with inferences on the learning outcomes.

Uploaded by

parinithamohan19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views14 pages

Lab 3

The lab report details three experiments involving the use of Embedded C to control 7-segment displays with a Tiva C TM4C123G LaunchPad. Each experiment focuses on displaying digits or words using different GPIO configurations and multiple ports. The report includes procedures, schematic diagrams, and code implementations for each experiment, along with inferences on the learning outcomes.

Uploaded by

parinithamohan19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

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 3
EXP1: 7 Segment: Program 1
AIM:
To write an Embedded C program that displays digits 0 to 9 on a 7-segment
display using GPIO Port B of the Tiva C TM4C123G LaunchPad.

Tools Used:
● Keil uVision IDE
● Tiva C TM4C123G LaunchPad
● 7-Segment Display (Common Cathode)
Procedure:
● Launch Keil uVision IDE and start a new project.
● Select the microcontroller TM4C123GH6PM from the device list.
● When prompted, include the startup code.
● Create a new .c file and write the 7-segment display logic in it.
● Save the file with the name main.c and add it to Source Group 1.
● Compile the project and ensure there are no errors.
● Connect the Tiva C board to your computer via USB.
● Flash the code to the microcontroller and run it.
● The 7-segment display should cycle through digits 0 to 9 continuously.

SCHEMATIC DIAGRAM:
PROGRAM:
#include "TM4C123.h" /* TM4C123 definitions */

unsigned int seg[10] = { /* 7-segment codes 0-9 */

0x3F,0x06,0x5B,0x4F,0x66,

0x6D,0x7D,0x07,0x7F,0x67

};

void delay(int d) /* crude time delay */

while (d--);

int main(void)

SYSCTL->RCGCGPIO |= (1U<<1); /* enable clock to Port B */

while(!(SYSCTL->PRGPIO & (1U<<1))); /* wait until ready */

GPIOB->DIR = 0xFF; /* PB0-PB7 as outputs */


GPIOB->DEN = 0xFF; /* digital enable PB0-PB7 */

while (1) /* main loop */

for (int i = 0; i < 10; i++)

GPIOB->DATA = seg[i]; /* display digit */

delay(10000000); /* hold */

GPIOB->DATA = 0x00; /* clear display */

OUTPUT:

Inference
I successfully implemented the 7-segment display program, where digits 0 to
9 were shown sequentially on a common cathode display. This confirmed
correct GPIO configuration and deepened my understanding of controlling
segment patterns using embedded C.

EXP2: 7 Segment:Program 2
AIM:
To write an Embedded C program that displays digits 0 to 9 on a 7-segment
display using multiple GPIO Ports of the Tiva C TM4C123G LaunchPad.

Tools req.:
● Keil uVision IDE
● TM4C123GH6PM LaunchPad
● Micro-USB Cable
● 7 segment

Procedure:
● Create a new project in Keil uVision and select TM4C123GH6PM as
the target.
● Add the startup file when prompted.
● Write the 7-segment display code in main.c using multiple GPIO ports.
● Add main.c to Source Group 1 and build the project.
● Flash the code to the board and run it.
● Verify that digits 0–9 appear sequentially on the common cathode
display.
SCHEMATIC DIAGRAM:

PROGRAM:
#include "TM4C123.h" // Device-specific header
unsigned int i;

unsigned int display[10] = {

0x3F, 0x06, 0x5B, 0x4F, 0x66,

0x6D, 0x7D, 0x07, 0x7F, 0x6F // 7-segment hex codes for digits 0-9

};

// Simple delay function

void delay(int d) {

while(d--);

int main(void) {

// Enable clock to GPIOA (bit 0), GPIOB (bit 1), and GPIOE (bit 4)

SYSCTL->RCGCGPIO |= (1 << 0) | (1 << 1) | (1 << 4);

// Wait until ports A, B, and E are ready

while((SYSCTL->PRGPIO & 0x13) == 0);

// Enable digital function on selected pins:

// PB5, PB0, PB1 (0x33), PE4, PE5 (0x30), PA5, PA6 (0x60)

GPIOB->DEN = 0x33;

GPIOE->DEN = 0x30;

GPIOA->DEN = 0x60;

// Set the above pins as output

GPIOB->DIR = 0x33;

GPIOE->DIR = 0x30;

GPIOA->DIR = 0x60;

while(1) {

for(i = 0; i < 10; i++) {


// Map each bit of display[i] to appropriate pin

GPIOB->DATA |= ((display[i] & 0x01) >> 0) << 5; // PB5

GPIOB->DATA |= ((display[i] & 0x02) >> 1) << 0; // PB0

GPIOB->DATA |= ((display[i] & 0x04) >> 2) << 1; // PB1

GPIOE->DATA |= ((display[i] & 0x08) >> 3) << 4; // PE4

GPIOE->DATA |= ((display[i] & 0x10) >> 4) << 5; // PE5

GPIOB->DATA |= ((display[i] & 0x20) >> 5) << 4; // PB4

GPIOA->DATA |= ((display[i] & 0x40) >> 6) << 5; // PA5

GPIOA->DATA |= ((display[i] & 0x80) >> 7) << 6; // PA6

delay(10000000); // Hold the digit display

// Clear all pins before next digit

GPIOB->DATA = 0x00;

GPIOE->DATA = 0x00;

GPIOA->DATA = 0x00;

OUTPUT:
Inference:
I successfully displayed digits 0 to 9 on a common cathode 7-segment display
using multiple GPIO ports. This helped me understand how to manage and
coordinate outputs across different ports using embedded C.

EXP3: 7 Segment - Exercise


AIM:
To write an Embedded C program to display 2-letter words using two
common anode 7-segment displays.

Tools Needed:
● Keil uVision IDE
● TM4C123GH6PM LaunchPad
● Micro-USB Cable
● 2 7 segments

Procedure:
● Connect two common anode 7-segment displays to suitable GPIO ports
on the board using a breadboard.
● In Keil uVision, create a new project, select TM4C123GH6PM, and
add the startup file.
● Write the code in main.c to display 2-letter words using multiple GPIO
ports and add it to Source Group 1.
● Build the project, flash the code to the board, and observe the 2-letter
words on the displays.
SCHEMATIC DIAGRAM:

PROGRAM:
#include "TM4C123.h" // TM4C123GH6PM header

unsigned int i;

unsigned int display1[6] = {0x87, 0xA1, 0x92, 0x89, 0x89, 0x80}; // Segment values for
display 1

unsigned int display2[6] = {0xA3, 0xA3, 0xC0, 0x86, 0xCF, 0x86}; // Segment values for
display 2

void delay(int d) {

while(d--); // crude delay

int main(void) {

// Enable clocks to ports A, B, D, E, F

SYSCTL->RCGCGPIO |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5);

// Wait until ports are ready (check PRGPIO)

while((SYSCTL->PRGPIO & 0x13) == 0);

// Enable digital functions

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


// Set pins as outputs

GPIOB->DIR = 0x33;

GPIOE->DIR = 0x3E;

GPIOA->DIR = 0x60;

GPIOD->DIR = 0x0F;

GPIOF->DIR = 0x02;

while(1) {

for(i = 0; i < 6; i++) {

// Display1 bits → 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

// Display2 bits → 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); // Wait before clearing

// Clear all outputs before next digit

GPIOB->DATA = 0x00;

GPIOE->DATA = 0x00;

GPIOA->DATA = 0x00;

GPIOD->DATA = 0x00;

GPIOF->DATA = 0x00;

OUTPUT:

Inference:
I successfully implemented the program to display 2-letter words using two
common anode 7-segment displays. This enhanced my understanding of
coordinating multiple GPIO ports and controlling multiple displays
simultaneously using embedded C.

You might also like