Interfacing Two multiplexed seven segment with 8051

Discussion in 'Embedded Systems and Microcontrollers' started by bobparihar, Aug 1, 2014.

  1. bobparihar

    Thread Starter Member

    Jul 31, 2014
    93
    0
    Having problem in Interfacing Two multiplexed seven segment with 8051
    my code is

    Code ( (Unknown Language)):
    1.  
    2. #include<reg51.h>
    3. sbit a=P3^0;
    4. sbit b=P3^1;
    5. void main()
    6. {
    7. unsigned char ar[]={0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
    8.     unsigned int i,j,k;
    9.     while(1)
    10.     {
    11.     for(i=0;i<100;i++)
    12.     {
    13.         a=0;
    14.         b=1;
    15.         P2=ar[i/10];
    16.          
    17.         for(k=0;k<35000;k++);     // delay
    18.          
    19.             a=1;
    20.             b=0;
    21.             P2=ar[i%10];
    22.             for(k=0;k<35000;k++);
    23.        }
    24.            
    25.    
    26.    }
    27.     }
    28.  
    can't figure out what is the problem here, counting up to 99 is happening but seven segment is getting on and off... sorry for the bad english
     
    Last edited by a moderator: Aug 1, 2014
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,397
    497
    No code comments, no help.
     
  3. bobparihar

    Thread Starter Member

    Jul 31, 2014
    93
    0
    Having problem in Interfacing Two multiplexed seven segment with 8051
    my code is

    Code ( (Unknown Language)):
    1.  
    2.  #include<reg51.h>
    3. sbit a=P3^0;                           // to  on off seven segment
    4. sbit b=P3^1;                                                       //  "  "     "       "       " (same  as above)
    5. void main()  
    6. {
    7. unsigned char ar[]={0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};    
    8. unsigned int i,j,k;
    9.     while(1)
    10.     {    
    11. for(i=0;i<100;i++)
    12.     {
    13.         a=0;                                       // on the 7 seg at tenth place
    14.         b=1;                                           // off the 7 seg at ones place
    15.         P2=ar[i/10];                  // sending 0-9 to port 2 to 7 seg
    16.                   for(k=0;k<35000;k++);                      // delay
    17.                        
    18. a=1;                                                          // off 7 seg at tenth place
    19.  b=0;                                                    // on seven seg at ones place
    20.  P2=ar[i%10];
    21.  for(k=0;k<35000;k++);           // delay
    22.  }
    23.  }
    24.  }
    25.  
     
    Last edited by a moderator: Aug 2, 2014
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Hello bobparihar, welcome to the forums!

    First off, when you post code could you please use the code tags? It's the # button above the place you type. Code tags format your code as in the first post. It makes it more readable that way.

    I read your code, it looks reasonable and I do not see any obvious mistakes.

    Can you describe "but seven segment is getting on and off" in some more detail? Both or just one segment? Every number or just as certain points?

    Can you see all the numbers 0 1 2 3 4 5 6 7 8 and 9?
     
  5. bobparihar

    Thread Starter Member

    Jul 31, 2014
    93
    0
    Dear ErnieM thanks for your concern to solve my problem
    " seven segment is getting on and off" means first the seven segments at the tenth

    place is showing 0, and then its goes to off and the seven segments at the ones

    place is showing 0 then its goes to off. and so on the numbers from 0 to 99 is showing.

    I did achieve the counting but not in the desired manner, the display is not continues
     
  6. bobparihar

    Thread Starter Member

    Jul 31, 2014
    93
    0
    " seven segment is getting on and off" means first the seven segments at the tenth

    place is showing 0, and then its goes to off and the seven segments at the ones

    place is showing 0 then its goes to off. and so on the numbers from 0 to 99 is showing.

    I did achieve the counting but not in the desired manner, the display is not continues
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Hi bobparihar, I’m glad you bumped your post. This time when I read it I saw what you are talking about. Last time I thought you meant something that I could not see in the code, this time I think I get it.

    “place is showing 0, and then its goes to off and the seven segments at the ones”

    Exactly, that is what your code is telling the display to do.
    Let’s look at you display code:
    Code ( (Unknown Language)):
    1.  
    2. for(i=0;i<100;i++)
    3. {
    4.  a=0;                         // on the 7 seg at tenth place
    5.  b=1;                         // off the 7 seg at ones place
    6.  P2=ar[i/10];               // sending 0-9 to port 2 to 7 seg
    7.  for(k=0;k<35000;k++); // delay
    8.  
    9.  a=1;                         // off 7 seg at tenth place
    10.  b=0;                         // on seven seg at ones place
    11.  P2=ar[i%10];
    12.  for(k=0;k<35000;k++); // delay
    13. }
    14.  
    That says “display the lower digit, then wait some. Next display the higher digit, then wait some more. Then increment the number and do it again.”

    That is just what you see, but not what you want.

    To get what you want you want to use the human phenomena of http://en.wikipedia.org/wiki/Persistence_of_vision]”Persistence of vision”[/url] where if you see something that changes fast you don’t see the change.

    What you want is to speed up the display code above until both numbers seem to be always on by making the delays much shorter. While you work that out take out the “for(i=0;i<100;i++)” loop and just assign I to some (any) fixed value. You can just drop in another statement such as “i = 16;” just after the “for” statement to do that.

    When you are happy with how one number displays wrap the display code with a counter, and run and rerun the display code a “number” of times. That number is equal to how long you want each digit to display divided by twice the digit delay; twice because you have two delays, one for each digit.

    You don’t have to be exact with that number as you may want to experiment with different values.
    Good luck and let us know how it goes!
    sample of code to try:
    Code ( (Unknown Language)):
    1.  
    2. for(i=0;i<100;i++)
    3. {
    4.  i = 16;                   // fixed value for test
    5.  a=0;                      // on the 7 seg at tenth place
    6.  b=1;                      // off the 7 seg at ones place
    7.  P2=ar[i/10];            // sending 0-9 to port 2 to 7 seg
    8.  for(k=0;k<200;k++); // much shorter delay
    9.  
    10.  a=1;                      // off 7 seg at tenth place
    11.  b=0;                      // on seven seg at ones place
    12.  P2=ar[i%10];
    13.  for(k=0;k<200;k++); // much shorter delay
    14. }
    15.  
     
  8. bobparihar

    Thread Starter Member

    Jul 31, 2014
    93
    0
    dear erniem if i use for(i=0;i<200;i++); as a shorter delay.. then i would get 0 to 9 at the ones place in just a second..and it will b not visible to me that number is incremanting at the ones place.. though tenth place digit works fine... but there is always 8 at the ones place.. because 0 to 9 is incrementing too fast.
     
  9. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    If you left in the increment that is what you will see if the two delays are still too long.

    Remove the increment (or just block it as I did in line 3)

    Run the code again. If you do not see two solid numbers of same brightness that do not blink then shorten the delay and run the code again.

    You need to get the delay short enough so your displays can multiplex. After you get that complete then worry about incrementing or counting.
     
Loading...