dgkadesewa
Jul 2 2009, 3:56 AM
hey every1....i'm programming a STK microcontroller which is an 8051 microcontroller in c language. the program makes the 7segmant count down from 9999 to 0 on a 4 7segment display. i want the 4 7segment to start blinking when it gets to 50 and blink till it gets to 0 i.e blink every second..and oh i forgot to add the delay is for 1 second.
i'v programmed the microcontroller and it counts down without a problem...bt d problem comes in the blinking part....d blinking is nt in uniform n i think its cos each digit is controlled separately at a different time....its blinkin could synchronize for 20secs and then go out of phase for d next 10 secs , go back in phase for d nxt 5 secs n ends out of phase......nxt time, it alternates i.e go out of phase for the 20 secs...go back in phase n d rest....sorrry i cnt give ma code now..bt i promise to do so..soon....
i desperately need an ansa..its drivin me nuts...PLSSSSS HELP....and oh!...am using d keil uvision compiler and proteus 7 professional simulator.....tnx in advance
dgkadesewa
Jul 2 2009, 8:51 AM
c'mon guysss....i tot we had geniuses on dis forum...quit viewin n nt repling...instead, view n reply.........plsss
ExperimenterUK
Jul 2 2009, 10:28 AM
If you could post your project.. code and proteus simulation it would help.
ali
Jul 2 2009, 9:01 PM
Decrement the value of unit place and also decrment a counter whihch will test for a count upto 950 as follows ( four user define counter cnt1 = ff, cnt2 = ff, cnt3 = ff ,cnt4 = 87h). As 950 occurs set a user define bit which will say the controller that already 950 count are completed now start dec with blinking
And you can now do the blinking with decrementing the unit place digit , setting all 7 segment OFF calling delay and setting all four 7 segment as per order,
Hai na simple...Reply me if this work or not.Plz PM me.
dgkadesewa
Jul 3 2009, 6:57 AM
ok.. dis is my source code..it counts down from 999 to 0 and starts blinking when it gets to 995...

CODE:
#include<reg51.h> //
void delay(){
int b;
for(b=0;b<23;b++){
TMOD=0x01;
TH0=0x00;
TL0=0x00;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}}

void delay2(){

TMOD=0x01;
TH0=0xF7;
TL0=0xF0;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
void delay21(){

TMOD=0x01;
TH0=0xF8;
TL0=0x00;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
void delay22(){

TMOD=0x01;
TH0=0xF8;
TL0=0xF0;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
void delay23(){

TMOD=0x01;
TH0=0xF9;
TL0=0xF0;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

void delay4(){

TMOD=0x01;
TH0=0xF9;
TL0=0xF0;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

void delay5(){

TMOD=0x01;
TH0=0xFA;
TL0=0xF0;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

void delay6(){

TMOD=0x01;
TH0=0xFF;
TL0=0xF0;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

void delay3(){

TMOD=0x01;
TH0=0xF7;
TL0=0xC0;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

int decode (int digit)
        {
        int acode;
        switch(digit)
                {
                case 0: acode = 0x40; break;
                case 1: acode = 0x79; break;
                case 2: acode = 0x24; break;
                case 3: acode = 0x30; break;
                case 4: acode = 0x19; break;
                case 5: acode = 0x12; break;
                case 6: acode = 0x02; break;
                case 7: acode = 0x78; break;
                case 8: acode = 0x00; break;
                case 9: acode = 0x10; break;
                case 24:acode = 0xff; break;
                }
        return acode;
        }
int thousands, hundreds, tens, units;
int  thingy(int count)
        {
        if(count<1000 && count>99){
        thousands = 24;
        hundreds = count%1000/100;
        tens = count%1000%100/10 ;
        units = count%1000%100%10;}

        else if(count<100 && count>9)
        {
        thousands=24;
        hundreds=24;
        tens = count%1000%100/10 ;
        units = count%1000%100%10;}
        else if(count<10)
        {
        thousands=24;
        hundreds=24;
        tens=24;
        units = count%1000%100%10;
        }
        else{
        thousands = count/1000;
        hundreds = count%1000/100;
        tens = count%1000%100/10 ;
        units = count%1000%100%10;}
        return thousands,hundreds,tens,units;
        }
void main()
{
        int countnum,time;
while(1){
{  
                for (countnum=999; countnum >= 0; countnum-- )
                        {
                       
                                if(countnum<=995)
                                        {
                                                thingy(countnum);
                                                P2=1;
                                                P3=decode(thousands);
                                                delay3();
                                                P3 = 0xff;
                                                delay2();
 

                                                P2=2;
                                            P3=decode(hundreds);
                                                delay4();
                                                P3 = 0xff;
                                                delay21();
 
 
                                                P2=4;
                                                P3=decode(tens);
                                                delay5();
                                                P3 = 0xff;
                                                delay22();
 
 
                                                P2=8;
                                                P3=decode(units);
                                                delay5();
                                                P3 = 0xff;
                                                delay();
 
                                        }          
                                       
                                        else{
                        thingy(countnum);
                       
                                for(time=0;time<82;time++)
                        {

                        P2 = 0x01;
                        P3 = decode(thousands);
                        delay2()        ;
                        P3 = 0xff;
                        delay2();
 
                        P2 = 0x02;
                        P3 = decode(hundreds);
                        delay2();
                        P3 = 0xff;
                        delay2();
 
                        P2 = 0x04;
                        P3 = decode(tens);
                        delay2();
                        P3 = 0xff;
                        delay2();
 
                        P2 = 0x08;
                        P3 = decode(units);
                        delay2();
                        P3 = 0xff;
                        delay2();

                        }}}}
 }
   }
 


pls help....
am having troubles uploadin d simulation..bt will do dat as soon as i can......1 more fin how can i attach a file in dis forum..
tweety bird
Jul 3 2009, 11:08 AM
u gotta be kiddin me... :mad
such a big code for such a small problem...!!
follow ari.mir10v suggestions..
n try make da code small.. !!! u using so many delay routines, just use 1 ...
dgkadesewa
Jul 4 2009, 3:30 AM
au wld i do dat?.....n i strted out wiv one delay bt i still had d same problems so i decided to av varyind routines and all...bt all i nid right now is the way forwad...help..
au wld i get to ari.mir10v suggestions....gogled it n didnt find anyfing.....
Ajay Bhargav
Jul 6 2009, 2:28 AM
to attach a file, zip the file and use the "POST REPLY" button on the top right or bottom right corner of forum.

or use the preview buttom of quick reply form.
dgkadesewa
Jul 6 2009, 4:11 AM
uhm..ajay..au abt an answer to my question concerning the 4 7segment display...thank you..
afilash
Jul 17 2009, 2:58 PM
adesewa,
here is the pseudo code, if you haven't got the answer yet :-)

// this will blink the display 10 times if count is less than 50

initialize_timerx for say 50ms
let var_b = 9999
let var_a = 20
blink = 0


here:
go to sleep -- idle mode
is var_b == 0( put blink as 0 ; var_b as 9999)
loop here


timerx_interrupt:
{
is var_b < 50 ?( compliment blink)

is blink == 0( display var_b else switch off display )

dec var_a

is var_a == 0? ( dec var_b and put var_a = 20 again )

}
Ajay Bhargav
Jul 18 2009, 9:10 AM
sorry i might have missed this post..

i think you need to make a good framework for your project..
like divide into segments.
e.g.

1. Display
2. Count
3. Blink display

Display has to refresh every fixed interval.. say every 60-100 ms so refresh display may be added in timer routine.. and will be done automatically.
so make this part first..

after that is count.. which can be added to your while(1) loop. all you need to do is increment and update the variables thousand, hundred, ten and ones etc. and timer will handle the display.

then is blink.. this is tricky you can use another timer to maintain that blink part (just swap between real values and 0xFF (no display).

if you move step by step you will feel simple and easy to do.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Rickey's World © 2003 - 2007