Proteus Simulation on four seven segment multiplexing
Code: upcounter on seven segments
#include <REGX51.H>
#define seg_data P2
sbit seg1=P3^3;
sbit seg2=P3^2;
sbit seg3=P3^1;
sbit seg4=P3^0;
int num=0;
int ones=0,tens=0,hundreds=0,thousands=0;
void display_digit(unsigned char c);
void delay(int x);
void display(int);
void main()
{
int num,j;
while(1)
{
for(num=0;num<10000;num++)
{
for(j=0;j<60;j++)
display(num);
}
}
}
void delay(int x)
{
int i;
for(i=0;i<x;i++);
}
void display(int num)
{
ones=num%10;
tens=(num/10)%10;
hundreds=(num/100)%10;
thousands=(num/1000);
display_digit(ones);
seg1=0;
delay(50);
seg1=1;
display_digit(tens);
seg2=0;
delay(50);
seg2=1;
display_digit(hundreds);
seg3=0;
delay(50);
seg3=1;
display_digit(thousands);
seg4=0;
delay(50);
seg4=1;
}
void display_digit(unsigned char c)
{
switch(c)
{
case 0:
seg_data=0x3f;
break;
case 1:
seg_data=0x06;
break;
case 2:
seg_data=0x5b;
break;
case 3:
seg_data=0x4f;
break;
case 4:
seg_data=0x66;
break;
case 5:
seg_data=0x6d;
break;
case 6:
seg_data=0x7d;
break;
case 7:
seg_data=0x07;
break;
case 8:
seg_data=0x7f;
break;
case 9:
seg_data=0x6f;
break;
}
}
Code: upcounter on seven segments
#include <REGX51.H>
#define seg_data P2
sbit seg1=P3^3;
sbit seg2=P3^2;
sbit seg3=P3^1;
sbit seg4=P3^0;
int num=0;
int ones=0,tens=0,hundreds=0,thousands=0;
void display_digit(unsigned char c);
void delay(int x);
void display(int);
void main()
{
int num,j;
while(1)
{
for(num=0;num<10000;num++)
{
for(j=0;j<60;j++)
display(num);
}
}
}
void delay(int x)
{
int i;
for(i=0;i<x;i++);
}
void display(int num)
{
ones=num%10;
tens=(num/10)%10;
hundreds=(num/100)%10;
thousands=(num/1000);
display_digit(ones);
seg1=0;
delay(50);
seg1=1;
display_digit(tens);
seg2=0;
delay(50);
seg2=1;
display_digit(hundreds);
seg3=0;
delay(50);
seg3=1;
display_digit(thousands);
seg4=0;
delay(50);
seg4=1;
}
void display_digit(unsigned char c)
{
switch(c)
{
case 0:
seg_data=0x3f;
break;
case 1:
seg_data=0x06;
break;
case 2:
seg_data=0x5b;
break;
case 3:
seg_data=0x4f;
break;
case 4:
seg_data=0x66;
break;
case 5:
seg_data=0x6d;
break;
case 6:
seg_data=0x7d;
break;
case 7:
seg_data=0x07;
break;
case 8:
seg_data=0x7f;
break;
case 9:
seg_data=0x6f;
break;
}
}
No comments:
Post a Comment