Solution SS 3
Solution SS 3
Experiment No:- 03
Interfacing with seven segment display
Requirements:-
MPLAB and Proteus software
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
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
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:
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;
}
}
Figure 1
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:
Source file:
/* File: XC8.c
* Simulation set 3: Solution to problem 2 */
#include <stdlib.h>
#include <stdio.h>
#include "XC8.h"
Circuit simulation in Proteus software is same as problem (1) and output is as required
by the problem.
3) With the physical arrangement as given in problem (1), add a switch to pin RC0 of port C
Header file:
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;
}
}
Figure 2
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
Header file:
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.