8051, 7 segment, 74595 and LEDs

Discussion in 'Embedded Systems and Microcontrollers' started by engwas, Oct 7, 2014.

  1. engwas

    Thread Starter Member

    Jan 9, 2009
    HI All
    I trying to build a digital time and date clock using 89S52 micro-controller and DS1307 with 7 segments and LED's, I use 74595 to multiplexing the 7 segments and LED the problem is i have a blink on display as i use Proteus simulation and the LED that indicate the PM blinking all the time, my code is take 3.6ms to read the information from the DS1307 and goto loop to display the info i use 14 (7 segments) to show the time and date LED to indicate the PM the loop repeat 183 times to complete 1 seconds then read the info again and display
    in loop every 7 segment take 0.42ms to display digit and go of for 5.88ms and repeat display every 6.3ms and the LED take a 0.42ms i use 74595 daisy-chain to multiplexing,
    i need to know how i calculate the POV correctly and how to display LED with 7 segment (the time) for each
    what is wrong with my code

    Code (Text):
    1. sbit test=P1^6;
    2. sbit Latch = P3^5;
    3. sbit Data = P3^6;
    4. sbit Clock = P3^7;
    5. sbit seconds = P2^2;
    6. sbit SetKey = P3^2;
    7. sbit UpKey = P3^3;
    8. sbit DownKey = P3^4;
    9. sbit OE =P2^0;
    10. unsigned char i;
    11. unsigned char pSetArray[]={0,13,4,Tuesday,4,10,14,1}; //sec,min,hour,day,date,month,year,PMorAM
    12. unsigned char *pInfoArray=&pSetArray;
    13. void select_display(int digit,select1,select2)
    14. {unsigned char i,value;
    15. Latch=0;
    16. value=Seven_Segment_Selector[select2];
    17. for(i=0;i<8;++i)
    18. {Data=value&0x01;
    19. Clock=0;
    20. Clock=1;
    21. value>>=1;}
    22. value=Seven_Segment_Selector[select1];
    23. for(i=0;i<8;++i)
    24. {Data=value&0x01;
    25. Clock=0;
    26. Clock=1;
    27. value>>=1;}
    28. value=Seven_Segment_Digit[digit];
    29. for(i=0;i<8;++i)
    30. {Data=value&0x01;
    31. Clock=0;
    32. Clock=1;
    33. value>>=1;}
    34. Latch=1;
    35. delay(1);
    36. }    
    38. void main()
    39.     {    IT0 = 1;  
    40.     EX0 = 1;  
    42.     InitI2C();    // Initialize i2c pins                                          
    44.     // Set initial time
    45.     Set_DS1307_RTC_Info(pInfoArray);
    46.     seconds=1;
    47.     while(1)
    48.     {OE=1;test=1;seconds=~seconds;
    49.     EA = 1;
    50.     pInfoArray=Get_DS1307_RTC_Info();
    51.     test=0;OE=0;
    52.     for(i=0;i<183;++i){
    53.     select_display( pInfoArray[0]/10,0,8 );//Seconds higher nibble
    54.     select_display( pInfoArray[0]%10,1,8 );//Seconds lower nibble
    55.     select_display( pInfoArray[1]/10,2,8 );//min MSB
    56.     select_display( pInfoArray[1]%10,3,8 );//min LSB
    57.     if(pInfoArray[2]/10==0);else select_display( pInfoArray[2]/10,4,8 );
    58.     select_display( pInfoArray[2]%10,5,8 );
    59.     if(pInfoArray[4]/10==0);else select_display( pInfoArray[4]/10,6,8 );
    60.     select_display( pInfoArray[4]%10,7,8 );
    61.     if(pInfoArray[5]/10==0);else select_display( pInfoArray[5]/10,8,0 );
    62.     select_display( pInfoArray[5]%10,8,1);
    63.     select_display( pInfoArray[6]/10,8,2 );
    64.     select_display( pInfoArray[6]%10,8,3 );
    65.     select_display( 2,8,4 );
    66.     select_display( 0,8,5 );
    67.     if(pInfoArray[7]==1)select_display(0,8,6 );  
    68.     }  
    69.     }
    Kindly need help
  2. Papabravo


    Feb 24, 2006
    You can't possibly expect us to infer the details of your design from a verbal description! For all I can determine your code is perfect and it is the hardware that is borked. How about posting a schematic diagram.

    The time you leave each digit on seems a bit short to me. Each digit should be on for 20-30 milliseconds to take advantage of the persistence effect.
    Last edited: Oct 7, 2014
  3. engwas

    Thread Starter Member

    Jan 9, 2009
    Dear Papabravo
    Many thanks
    How can i do this with 74595 multiplexing, Kindly help
    the schematic diagram as

    Last edited: Oct 7, 2014
  4. Papabravo


    Feb 24, 2006
    Your mistake is now obvious to me. You cannot use an HC device to supply power to a seven segment display. If you read the datasheet you will see that an HC output can supply only a limited amount of current. This is typically 6 mA, which is far to small. If each segment requires 10-20 mA, displaying a '8' will take 80-160 mA. Traditionally a common anode display would be powered from a transistor switch that could source the required current. Using a decoder for the select lines is way more efficient and guarantees that only one will be on at a time which is what you want for a multiplexing scheme.

    Making implied connections via net names (OE) almost tripped me up. Try to use something more explicit. When OE is disabled all the lines to the displays are floating is this what you intend?
  5. engwas

    Thread Starter Member

    Jan 9, 2009
    thanks for reply
    i see many circuits use HC to multiplexing i plan to use current sink or seek after i finish the code and everything go ok
    i see circuit using 5 (74595) to drive 24 (7 segment ca) with 8 transistor via 4 wire connection with 8051 i see the top view of circuit not the all connection. so if i use transistor the led will not blink i mean the pm led
    i use oe someone said the solution on it i try some code not work
    i think the solution on POV time but i have no idea this what i wrote in code and hardware and hope to get answer from you

    Any help

    I attached my work, kindly see the PM LED it blinking and it should not (light on when PM time) and i notice a simple blink on 7 segment kindly any help

    I put a 32 led and drive then with new code (same method with 74595 multiplexing daisy chain) the led not light ON it blink (it should ON all the led), I attached the code and circuit hope anyone give me what go wrong?
    Last edited by a moderator: Oct 8, 2014
  6. engwas

    Thread Starter Member

    Jan 9, 2009
    HELP !
  7. engwas

    Thread Starter Member

    Jan 9, 2009
    Any Idea ?
  8. MrCarlos

    Active Member

    Jan 2, 2010
    Hello engwas

    I did a run of your design in Proteus ISIS.

    It looks good, and yes, the PM LED flashes.
    I think it's the speed of the PC.

    But, if you have armed you with your design real components and has the same problem, I suggest you use another port on the AT89C52 to turn on or off the LED PM.
    Of course, you'd have to modify the code of your program.

    By the way: What compiler you use to get the HEX file ??
  9. engwas

    Thread Starter Member

    Jan 9, 2009
    Dear MrCarlos
    Thanks for reply
    I use KEIL uVision 4 compiler
  10. MrCarlos

    Active Member

    Jan 2, 2010
    Hello engwas

    Well, I do not know that compiler.
    But the issue here is flashing LED PM.

    We can say that all electronic circuits simulators make the same effect.
    Something that should not blink, blinks.
    Why the 7-segment displays do not flicker?. . . Probably the SoftWare (Proteus ISIS) has a higher priority for those 7-segment displays while for LED’s has lower priority.
    Surely you did an experiment with simple 7-segment displays, and noticed some flickering.

    The only reason I can find is this: the different components that make up a circuit have different priority to act or not to act in a particular circuit.

    So: if you have armed the circuit with real components and the problem persists you will have to change the PM LED to a port of AT89C52 to turn it off or turn it on as needed.
    absf likes this.
  11. absf

    Senior Member

    Dec 29, 2010
    I totally agree with MrCarlos. A simulator is a simulator. It will never replace real hardware.......unless you can afford a supercomputer running a version of proteus written for supercomputers.

    Last edited: Oct 10, 2014
  12. xainnasir

    New Member

    Nov 8, 2012
  13. dannyf

    Well-Known Member

    Sep 13, 2015
    You run the display routines in the main loop, together with the i2c routine which is very slow.

    A better approach is to run the display routines in a timer isr and then the slow i2c routine in the main.