Department of Electronics & Communication Engineering
ELEC 20007 Microcontrollers Lab
Program 4: Interfacing Seven Segment Display.
Write an embedded C program to control the 2 seven segment displays to display a 00 to 99 counter. Maintain a delay of 0.5 sec between each count.
Interfacing Connections:
In the common cathode display, all the cathode connections of the LED segments are joined together to logic “0” or ground. The individual segments are illuminated by application of a “HIGH”, or logic “1” signal via microcontroller pin.
Table below shows the hexadecimal values of a common cathode 7-Segment display connected to a port of a microcontroller from bit 0 to bit 7.
Program:
#define _XTAL_FREQ 12000000
#include
void main()
{
unsigned char value[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
unsigned char i, j;
TRISC = 0x00;
TRISD = 0x00;
while(1)
{
for (i=0;i<10;i++)
{
PORTC=value[i];
for(j=0;j<10;j++)
{
PORTD=value[j];
__delay_ms(500);
} } } }
Result:
Press the play button in Proteus Professional software and observe the counting in two seven segment displays.