0% found this document useful (0 votes)
68 views8 pages

Solution SS 3

This document describes an experiment involving interfacing a PIC18 microcontroller with a 7-segment display. It provides 4 problems to solve involving displaying different numbers on the display by changing the microcontroller port output and adding a switch. The solutions include code examples and circuit diagrams to simulate the problems in Proteus software.

Uploaded by

Harsh Thakur
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)
68 views8 pages

Solution SS 3

This document describes an experiment involving interfacing a PIC18 microcontroller with a 7-segment display. It provides 4 problems to solve involving displaying different numbers on the display by changing the microcontroller port output and adding a switch. The solutions include code examples and circuit diagrams to simulate the problems in Proteus software.

Uploaded by

Harsh Thakur
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/ 8

ADVANCED MICROCONTROLLER AND EMBEDDED SYSTEM (EE 425T)

Semester-VII ELECTRICAL ENGINEERING

Experiment No:- 03
Interfacing with seven segment display

Requirements:-
MPLAB and Proteus software

Department of Electrical Engineering , SOT, PDPU


ADVANCED MICROCONTROLLER AND EMBEDDED SYSTEM (EE 425T)
Semester-VII ELECTRICAL ENGINEERING

SIMULATION SET- 3
INTERFACING WITH SEVEN SEGMENT DISPLAY

1) Attach a seven segment display to the port C of PIC18 microcontroller via resistors of

220 Ω and display number 8. Connect the seven segment display such that a , b , c , d , e , f

and g are connected to pins RC1, RC2, RC3, RC4, RC5, RC6 and RC7 respectively.

2) With the physical arrangement as given in problem (1), display numbers 0 to 9 once

with a time delay after every number. Note that the display should take place only once,

thereafter the display should show 9 endlessly i.e. till the program runs.

3) With the physical arrangement as given in problem (1), add a switch to pin RC0 of port C

such that operation of the switch results in display of number 8.

4) The physical arrangement is as given in problem (3). Write a C18 program wherein

operation of the switch would result in display of numbers 0 to 9. Once the display

reaches 9 it should resume the counting from the beginning.

Department of Electrical Engineering , SOT, PDPU


ADVANCED MICROCONTROLLER AND EMBEDDED SYSTEM (EE 425T)
Semester-VII ELECTRICAL ENGINEERING

SOLUTION OF SET- 3
INTERFACING WITH SEVEN SEGMENT DISPLAY

1) Attach a seven segment display to the port B of PIC18 microcontroller via resistors of

220 Ω and display number 8. Connect the seven segment display such that a , b , c , d , e , f

and g are connected to pins RB1, RB2, RB3, RB4, RB5, RB6 and RB7 respectively.

Header file:

Same as in problem (1) of Simulation set 1

Source file:

/* File: XC8.c
* Simulation set 3: Solution to problem 1 */

#include <stdlib.h>
#include <stdio.h>
#include "XC8.h"

void main(void)
{
TRISB = 0;
while(1)
{
LATB = 0xFE;
}
}

Output & comments on the obtained output:

As narrated in the problem, hardware is simulated in Proteus software using a seven


segment display connected to port B of PIC18 microcontroller via resistors of 220 Ω for
each segment. Pins RB1, RB2, RB3, RB4, RB5, RB6 and RB7 are connected to segments

Department of Electrical Engineering , SOT, PDPU


ADVANCED MICROCONTROLLER AND EMBEDDED SYSTEM (EE 425T)
Semester-VII ELECTRICAL ENGINEERING

a , b , c , d , e , f and g. In order to display number 8, port B must be given 1111 1110 as


output. Figure 1 shows the physical implementation of the above code.

Figure 1

Department of Electrical Engineering , SOT, PDPU


ADVANCED MICROCONTROLLER AND EMBEDDED SYSTEM (EE 425T)
Semester-VII ELECTRICAL ENGINEERING

2) With the physical arrangement as given in problem (1), display numbers 0 to 9 once

with a time delay after every number. Note that the display should take place only once,

thereafter the display should show 9 endlessly i.e. till the program runs.

Header file:

Same as in problem (1) of Simulation set 1

Source file:

/* File: XC8.c
* Simulation set 3: Solution to problem 2 */

#include <stdlib.h>
#include <stdio.h>
#include "XC8.h"

void delay_timer (void); //declaration of user-defined timer


void main(void)
{
TRISB = 0;
unsigned char num_display[]={0xFE,0x0C,0xB6,0x9E,0xCC,0xDA,0xFB,0x0E,0xFE,0xDE};
unsigned char z;
for (z=0;z<=9;z++)
{
LATB = num_display[z];
delay_timer();
}
while(1);
}
void delay_timer (void) //code for user-defined timer
{
unsigned char i;
for (i=0; i<=255; i++);
}

Output & comments on the obtained output:

Circuit simulation in Proteus software is same as problem (1) and output is as required
by the problem.

Department of Electrical Engineering , SOT, PDPU


ADVANCED MICROCONTROLLER AND EMBEDDED SYSTEM (EE 425T)
Semester-VII ELECTRICAL ENGINEERING

3) With the physical arrangement as given in problem (1), add a switch to pin RC0 of port C

such that operation of the switch results in display of number 8.

Header file:

Same as in problem (1) of Simulation set 1

Source file:

/* File: XC8.c
* Simulation set 3: Solution to problem 3 */

#include <stdlib.h>
#include <stdio.h>
#include "XC8.h"

void main(void)
{
TRISB = 0;
TRISCbits.RC0 = 1;
while(1)
{
if (PORTCbits.RC0==0)
LATB = 0xFE;
else
LATB=0;

}
}

Output & comments on the obtained output:

Circuit simulation in Proteus software is as shown in figure 2. Switch is connected to


pinRC0 of port C in pull up resistor configuration while seven segment display is
connected to port B via resistors of 220 Ω each. When the switch is closed, number 8 is
displayed while the opening of switch results in the seven segment display going blank.

Department of Electrical Engineering , SOT, PDPU


ADVANCED MICROCONTROLLER AND EMBEDDED SYSTEM (EE 425T)
Semester-VII ELECTRICAL ENGINEERING

Figure 2

Department of Electrical Engineering , SOT, PDPU


ADVANCED MICROCONTROLLER AND EMBEDDED SYSTEM (EE 425T)
Semester-VII ELECTRICAL ENGINEERING

4) The physical arrangement is as given in problem (3). Write a C18 program wherein

operation of the switch would result in display of numbers 0 to 9. Once the display

reaches 9 it should resume the counting from the beginning.

Header file:

Same as in problem (1) of Simulation set 1

Source file:

/* File: XC8.c
* Simulation set 3: Solution to problem 4 */
#include <stdlib.h>
#include <stdio.h>
#include "XC8.h"
void main(void)
{
TRISB=0;
TRISCbits.RC0=1;
unsigned char num_display[]={0x7E,0x0C,0xB6,0x9E,0xCC,0xDA,0xFB,0x0E,0xFE,0xDE};
unsigned char z=0;
while(1)
{
if (PORTCbits.RC0==0)
{
LATB = num_display[z];
for (i=0; i<=225; i++); //for loop used as user-defined timer
if (z<9)
z++;
else
z=0;
}
else
{}
}
}
Output & comments on the obtained output:

Circuit simulation in Proteus software is same as problem (3) and output is as required
by the problem.

Department of Electrical Engineering , SOT, PDPU

You might also like