multiplexed seven segment

Status
Not open for further replies.

bobparihar

New Member
i am doing a project in which i have to show counting from 0 to 99 on two multiplexed seven segments connected to a single port of 8051 ie. P2
my code is
C:
#include<reg51.h>
sbit a=P3^0;  // to on off seven segment
sbit b=P3^1;  // " " " " " (same as above)
void main()
{
   unsigned char ar[]={0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
   unsigned int i,j,k;
   while(1)
   {
     for(i=0;i<100;i++)
     {
       for(j=0;j<30;j++)
       {
         a=0;        // on the 7 seg at tenth place
         b=1;        // off the 7 seg at ones place
         P2=ar[i/10];      // sending 0-9 to port 2 to 7 seg
         for(k=0;k<1275;k++);    // delay
         a=1;        // off 7 seg at tenth place
         b=0;       // on seven seg at ones place
         P2=ar[i%10];
         for(k=0;k<1275;k++);   // delay
       }
     for(k=0;k<30000;k++);       // large delay for increment of number at ones place
     }
   }
}
the problem here is i am not getting the desired output on simulation..first the ones place shows and it increments after some delay the tens place shows and then goes to off.. though it shows counting from 0-99 but not in a desired way..
 
Last edited by a moderator:
Simulation? which simulator... You need to get your duty cycle right.... time on against time off..

I will bang this code on my simulator to see what gives....
 
The multiplexing loop stops when the large delay k=....
starts.
You should place the multiplexing loop inside the large delay:
for i= 0 to ...
{
for k=0 to ...
{ for j=0 to ...
 
C:
#include<reg51.h>
sbit a=P3^0;  // to on off seven segment
sbit b=P3^1;  // " " " " " (same as above)
void main()
{
   unsigned char ar[]={0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
   unsigned int i,j,k;
   while(1)
   {
     for(i=0;i<100;i++)
     {
       for(j=0;j<10;j++)
       {
         a=0;        // on the 7 seg at tenth place
         b=1;        // off the 7 seg at ones place
         P2=ar[i/10];      // sending 0-9 to port 2 to 7 seg
         for(k=0;k<1275;k++);    // delay
         a=1;        // off 7 seg at tenth place
         b=0;       // on seven seg at ones place
         P2=ar[i%10];
         for(k=0;k<1275;k++);   // delay
       }    
   }
}

This runs reasonable...
 
Can I suggest that to prevent ghosting you swap the code to,
Code:
       for(j=0;j<10;j++)
       {
         b=1;       // off the 7 seg at ones place
         P2=ar[i/10];     // sending 0-9 to port 2 to 7 seg
         a=0;       // on the 7 seg at tenth place     Moved
         for(k=0;k<1275;k++);   // delay
         a=1;       // off 7 seg at tenth place
         P2=ar[i%10];
         b=0;     // on seven seg at ones place
         for(k=0;k<1275;k++);// delay
       }
Also, if the count is too fast change the J loop to a larger value. E.G for(j=0;j<100;j++)

Mike.
 
Ghosting is also known as no inter-digit blanking. I helped Fezder with this same issue on his blog. You have to turn the digit COMPLETELY OFF for a short time before setting up the segments of the next scanned digit.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…