Interfacing The 7 Segment Display with 8051 Micro Controller
The AT 89c51 Micro Controller is interfacing with The 6 Digit 7 Segment Display, The Number of counts is incremented with the external INT0 Interrupt, and the input pin witch is connected with the port 3.4 id used to reset the count value.
Here the source code and the Screen Shot of the Proteus Simulator Model is added wit this.
Source Code:
#include <reg51.h>
sbit clear = P3^4;
unsigned char code DSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90, 0xff};
//unsigned char code Scan_BITs[]={0x20,0x10,0x08,0x04,0x02,0x01};
unsigned char code Scan_BITs[]={0x01,0x02,0x04,0x08,0x010,0x20};
unsigned char data Buffer_Counts[]={0,0,0,0,0,0};
unsigned int Count=0;
void DelayMS(unsigned int x)
{
unsigned char t;
while(x--)
{
for(t=0;t<120;t++);
}
}
void Show_Counts()
{
unsigned int i;
Buffer_Counts[3] = Count / 1000;
Buffer_Counts[2] = Count % 1000 / 100;
Buffer_Counts[1] = Count % 100 / 10;
Buffer_Counts[0] = Count % 10;
for(i=0;i<4;i++)
{
P2 = Scan_BITs[i];
P1 = DSY_CODE[Buffer_Counts[i]];
DelayMS(1);
}
}
void main()
{
IT0 = 1;
IE = 0x81;
while(1)
{
if(clear == 0)
Count = 0;
Show_Counts();
}
}
void EX_INT0() interrupt 0
{
Count++;
}
sbit clear = P3^4;
unsigned char code DSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90, 0xff};
//unsigned char code Scan_BITs[]={0x20,0x10,0x08,0x04,0x02,0x01};
unsigned char code Scan_BITs[]={0x01,0x02,0x04,0x08,0x010,0x20};
unsigned char data Buffer_Counts[]={0,0,0,0,0,0};
unsigned int Count=0;
void DelayMS(unsigned int x)
{
unsigned char t;
while(x--)
{
for(t=0;t<120;t++);
}
}
void Show_Counts()
{
unsigned int i;
Buffer_Counts[3] = Count / 1000;
Buffer_Counts[2] = Count % 1000 / 100;
Buffer_Counts[1] = Count % 100 / 10;
Buffer_Counts[0] = Count % 10;
for(i=0;i<4;i++)
{
P2 = Scan_BITs[i];
P1 = DSY_CODE[Buffer_Counts[i]];
DelayMS(1);
}
}
void main()
{
IT0 = 1;
IE = 0x81;
while(1)
{
if(clear == 0)
Count = 0;
Show_Counts();
}
}
void EX_INT0() interrupt 0
{
Count++;
}
Simulator Design:
Thanks Sherif. Your Blog is very use full for all, who love to start Embedded... Great .. I ll follow this
ReplyDeletenice work
ReplyDelete