As 8051 Microcontroller is concerned, we all know that Its a Microcontroller in which we program our code and make it work. The 8051 microcontroller, I have used in this post is AT89C51. I have also designed this project on hardware and have tested code and it works fine. The crystal oscillator I have used in this project is of 16MHz. You can also download the Proteus Simulation along with programming code and hex file designed in keil uvision 3, at the end of this post. So, now let's get started with it. You may also wanna read the below projects on 8051 Microcontroller:
#include<reg51.h>
void cct_init(void);
void delay(int);
void DisplayOn7Segment(char);
int main(void)
{
char ch = '0'; // Character to be displayed on 7seg
cct_init(); // Make all ports zero
while(1)
{
DisplayOn7Segment(ch); // Display ch on 7seg
delay(30000); // About 1 sec delay
switch(ch) // Update ch with new value to be displayed
{
case '0': ch = '1'; break;
case '1': ch = '2'; break;
case '2': ch = '3'; break;
case '3': ch = '4'; break;
case '4': ch = '5'; break;
case '5': ch = '6'; break;
case '6': ch = '7'; break;
case '7': ch = '8'; break;
case '8': ch = '9'; break;
case '9': ch = '0'; break;
default: ch = '0'; break;
}
}
}
void cct_init(void)
{
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x00;
}
void delay(int a)
{
int i;
for(i=0;i<a;i++); //null statement
}
void DisplayOn7Segment(char ch) // ch can have a value from '0' to 'F' only
{
switch(ch)
{
case '0': P2 = 0x3F; break;
case '1': P2 = 0x06; break;
case '2': P2 = 0x5B; break;
case '3': P2 = 0x4F; break;
case '4': P2 = 0x66; break;
case '5': P2 = 0x6D; break;
case '6': P2 = 0x7D; break;
case '7': P2 = 0x07; break;
case '8': P2 = 0x7F; break;
case '9': P2 = 0x6F; break;
default: P2 = 0x3F; break;
}
}
That's all for today, I hope now you can quite easily interface this seven segment display with 8051 Microcontroller. In the next post, we will have a look at some new project with 8051 Microcontroller. So, till then take care and have fun !!! :)
JLCPCB – Prototype 10 PCBs for $2 (For Any Color)
China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w