Four digit seven segment display interfacing using 8051 Micro-Controller

SOFTWARE: KEIL MICRO VISION 4.0

SIMULATOR: PROTEUS 8.0


CIRCUIT DIAGRAM:





CIRCUIT WORKING:

I have used four digit seven segment common anode display panel.Four digit display panel has 8 segment pins to send the data and 4 control pins to control the operation of the display ( 4 single 7 segment display units).Segment pins are connected to port 1 and control pins(1,2,3,4) are connected to port(2.0,2.1,2.2,2.3) pins respectively.

It is common anode (CA) display so in order to activate segment I have provided logic 0 to respective segment (as mentioned in the below table given in the program description).

The four digit display panel consists of four 7 segment(ca) display units.To activate required display unit(single 7 segment display unit ) of 4 digit display panel we need to send logic 1 to the respective control pin of the display unit (single 7 segment display unit) and to deactivate the display unit(single 7 segment display unit) we need to send logic 0.


PROGRAM:

#include<reg51.h>
#define digit P1
sbit sw1=P2^0;
sbit sw2=P2^1;
sbit sw3=P2^2;
sbit sw4=P2^3;
unsigned char ch[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

void display (unsigned long int);
void delay(unsigned int i);


void main()
{
int a=0;
while(1)
{
if(a>1000)
{
a=0;
}

display(a); //pass the value to display
a++;
}
}



void display (unsigned long int n) // display number
{
if(n==1000) // number =1000
{
digit=ch[(n/1000)]; //pass the value to port 1
sw1=1;
delay(1);
sw1=0;
digit=ch[((n%1000)/100)]; //pass the value to port 1
sw2=1;
delay(1);
sw2=0;

digit=ch[((((n%1000)%100)/10))]; //pass the value to port 1
sw3=1;
delay(1);
sw3=0;

digit=ch[n%10]; //pass the value to port 1
sw4=1;
delay(1);
sw4=0;
}

else if((n>=100)&&(n<1000)) //for numbers ranging from 100 to 999
{
P2=0X00;
digit=ch[((n%1000)/100)]; //pass the value to port 1
sw2=1;
delay(1);
sw2=0;

digit=ch[((((n%1000)%100)/10))]; //pass the value to port 1
sw3=1;
delay(1);
sw3=0;

digit=ch[n%10]; //pass the value to port 1
sw4=1;
delay(1);
sw4=0;

}

if((n>=10)&&(n<100)) // for numbers ranging from 10 to 99
{

P2=0X00;

digit=ch[((((n%1000)%100)/10))]; //pass the value to port 1
sw3=1;
delay(1);
sw3=0;

digit=ch[n%10]; //pass the value to port 1
sw4=1;
delay(1);
sw4=0;
}

else if(n<10) // for numbers less than 10
{

P2=0x00;

digit=ch[n%10]; //pass the value to port 1
sw4=1;
delay(1);
sw4=0;
}
}

void delay (unsigned int i) // delay generation
{
while(i>0)
{
TMOD=0X01; //timer0 mode 1

TL0=0Xf2; // delay of 1/16 of sec
TH0=0x1d;
TR0=1; // start the timer0
while(TF0==0); // wait for rollover
TR0=0; // stop the timer0
TF0=0; // clear overflow flag of timer0
i--;
}
}


PROGRAM DESCRIPTION:


First I have send the data which needs to be displayed to port 1 where segment pins of display panel are connected.After that I have activated required displays((single 7 segment display unit)) on the display panel using control pins.

I have used persistence of vision to display data on the 4 digit display(ca) panel.In order to achieve this I have activated the required display(single 7 segment display unit)by providing logic 1 to respective control pin and then after (1/16) seconds of delay I have provided logic 0 to that control pin.

For providing the delay I have used timer 0 of 8051 in mode 1(16 bit mode).I have written the program to display number up to 1000.


Calculation of timer value loaded in TH0 and TL0 register:


In micro-controller 8051 frequency is internally divided by 12.
I have taken the micro-controller with 11.0592 MHZ frequency.So the calculation is
  • (11.0592 MHZ ) / 12 = 921600 HZ
  • 1 / (921600) = 1.08*10^-6
  • I want to generate delay of 1/16 seconds.
  • Count= required time / controller time
  • Count = (1/16) / (1.08*10^-6)
  • Count = 57870.370=57870
  • Value to be loaded in timer 0 register= 65536 - 57870 = 7666 = 1df2(hex)
  • So in TH0=0X1d and TL0 = 0Xf2


I have send the data to port 1 according to the below table.


VIDEO:





Comments

Popular posts from this blog

Digital Thermometer using 8051 and ADC 0808 Interfacing With 8051

how to display numbers on lcd?

To display custom characters on the lcd using 8051 micro-controller.