Discussion in "8051 Discussion Forum" started by    engwas    Oct 9, 2014.
Thu Oct 09 2014, 12:59 pm
#1
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
sbit test=P1^6;
sbit Latch = P3^5;
sbit Data = P3^6;
sbit Clock = P3^7;
sbit seconds = P2^2;
sbit SetKey = P3^2;
sbit UpKey = P3^3;
sbit DownKey = P3^4;
sbit OE =P2^0;
unsigned char i;
unsigned char pSetArray[]={0,13,4,Tuesday,4,10,14,1}; //sec,min,hour,day,date,month,year,PMorAM
unsigned char *pInfoArray=&pSetArray;
void select_display(int digit,select1,select2)
{unsigned char i,value;
Latch=0;
value=Seven_Segment_Selector[select2];
for(i=0;i<8;++i)
{Data=value&0x01;
Clock=0;
Clock=1;
value>
>
=1;}
value=Seven_Segment_Selector[select1];
for(i=0;i<8;++i)
{Data=value&0x01;
Clock=0;
Clock=1;
value>
>
=1;}
value=Seven_Segment_Digit[digit];
for(i=0;i<8;++i)
{Data=value&0x01;
Clock=0;
Clock=1;
value>
>
=1;}
Latch=1;
delay(1);
}     

void main()
    {    IT0 = 1;  
    EX0 = 1;  
          
    InitI2C();    // Initialize i2c pins                                           

    // Set initial time
    Set_DS1307_RTC_Info(pInfoArray);
    seconds=1;
    while(1)
    {OE=1;test=1;seconds=~seconds;
    EA = 1;
    pInfoArray=Get_DS1307_RTC_Info();
    test=0;OE=0;
    for(i=0;i<183;++i){
    select_display( pInfoArray[0]/10,0,8 );//Seconds higher nibble
    select_display( pInfoArray[0]%10,1,8 );//Seconds lower nibble
    select_display( pInfoArray[1]/10,2,8 );//min MSB
    select_display( pInfoArray[1]%10,3,8 );//min LSB
    if(pInfoArray[2]/10==0);else select_display( pInfoArray[2]/10,4,8 );
    select_display( pInfoArray[2]%10,5,8 );
    if(pInfoArray[4]/10==0);else select_display( pInfoArray[4]/10,6,8 );
    select_display( pInfoArray[4]%10,7,8 );
    if(pInfoArray[5]/10==0);else select_display( pInfoArray[5]/10,8,0 );
    select_display( pInfoArray[5]%10,8,1);
    select_display( pInfoArray[6]/10,8,2 );
    select_display( pInfoArray[6]%10,8,3 );
    select_display( 2,8,4 );
    select_display( 0,8,5 );
    if(pInfoArray[7]==1)select_display(0,8,6 );   
    }   
    }


Fri Oct 10 2014, 12:02 am
#2

7 segment take 0.42ms to display digit and go of for 5.88ms


after displaying are you turning off the display? Instead of doing the loop for 183 times, You can reduce the loop time and increase the time a bit so that all the displays get enough time to remain on. try with 10ms first for each display to remain on.

Also the best way of doing this kind of stuff is.. use interrupt to refresh display which is called periodically. lets say ever 30 or 50 ms you call interrupt which refreshes display.. so your main loop just do the job of getting the data from RTC rest is done in interrupt.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm
Robertgurse
Wed Apr 24 2024, 02:43 pm
Richardedils
Wed Apr 24 2024, 04:07 am
ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am
Richardrit
Tue Apr 23 2024, 09:54 am