Topic : how can i make seconds?

Forum : 8051

Original Post
Post Information Post
May 17, 2007 - 2:56pm
Guest

Hi,

I wanna make a project to show seconds ( after that i will make a clock )
the problem is I can't find the right way to make seconds. ( I'm using an AT89C2051 controller)

This is my simple program :

 #include 
 
void Show(int J) {    // show seconds on two displays ( 7seg)
 char unsigned I=0;
 if (J > 99) { J=99; }
 while (J >= 10) {
 J = J - 10;
 I++;
 } // show result
 if (I<0) {I=0;}
  if (I==0){P1_3=0;P1_2=0;P1_1=0;P1_0=0;} 
  if (I==1){P1_3=0;P1_2=0;P1_1=0;P1_0=1;} 
  if (I==2){P1_3=0;P1_2=0;P1_1=1;P1_0=0;} 
  if (I==3){P1_3=0;P1_2=0;P1_1=1;P1_0=1;} 
  if (I==4){P1_3=0;P1_2=1;P1_1=0;P1_0=0;} 
  if (I==5){P1_3=0;P1_2=1;P1_1=0;P1_0=1;} 
  if (I==6){P1_3=0;P1_2=1;P1_1=1;P1_0=0;} 
  if (I==7){P1_3=0;P1_2=1;P1_1=1;P1_0=1;} 
  if (I==8){P1_3=1;P1_2=0;P1_1=0;P1_0=0;}
  if (I==9){P1_3=1;P1_2=0;P1_1=0;P1_0=1;} 
  if (J==0){P1_7=0;P1_6=0;P1_5=0;P1_4=0;} 
  if (J==1){P1_7=0;P1_6=0;P1_5=0;P1_4=1;} 
  if (J==2){P1_7=0;P1_6=0;P1_5=1;P1_4=0;} 
  if (J==3){P1_7=0;P1_6=0;P1_5=1;P1_4=1;} 
  if (J==4){P1_7=0;P1_6=1;P1_5=0;P1_4=0;} 
  if (J==5){P1_7=0;P1_6=1;P1_5=0;P1_4=1;} 
  if (J==6){P1_7=0;P1_6=1;P1_5=1;P1_4=0;} 
  if (J==7){P1_7=0;P1_6=1;P1_5=1;P1_4=1;} 
  if (J==8){P1_7=1;P1_6=0;P1_5=0;P1_4=0;}
  if (J==9){P1_7=1;P1_6=0;P1_5=0;P1_4=1;} 
}

void main() {
 float I;
 while (1) {
 I++;
 Show(I/4070); // To get seconds, each second will be shown
 }
}

everything works, but the number 4070 doesn't corresponds correctly with seconds.

I hope u can help me out. Thx

Greets,
Phil

Replies
Post Information Post
+1
0
-1
May 18, 2007 - 2:31pm
Guest

everything works, but the number 4070 doesn't corresponds correctly with seconds.
I do not see the number 4070 in the scribbles (nothing without comments desrve to be called 'code') you show.

I hope u can help me out. Thx
Since you specifically hope 'micro' (u) can help you, I will not interfere.

Erik

+1
0
-1
May 18, 2007 - 6:20pm
Guest

erikm wrote:
everything works, but the number 4070 doesn't corresponds correctly with seconds.
I do not see the number 4070 in the scribbles (nothing without comments desrve to be called 'code') you show.

I hope u can help me out. Thx
Since you specifically hope 'micro' (u) can help you, I will not interfere.

Erik


hi there,

I mean the formule : Show(I/4070); I can get close to seconds, but I don't know how you make perfectly seconds.

the 'u' is simply intend for someone who knows more.

regards, Phil

+1
0
-1
May 21, 2007 - 11:29am
Raisonance Support Team

Hi,

For getting precise seconds, you cannot rely on a counting loop, especially if it is written in C. You'll have to use a timer. (and for a clock you might want to use an external 32KHz oscillator too.)

You can use the RTOS to easily configure the timer. (not the 32K) Look at the examples in "C:\RIDE\EXAMPLES\8051\GENERAL\RTOS\...".
If you don't want to do that, then you'll have to configure the timer by hand... but here is not the place to learn how to do this.

Best Regards,

Vincent

+1
0
-1
June 17, 2007 - 5:29am
Guest

Hi Guys,

I have worked with the PIC microcontrollers, now Iam having a try with the silicon Labs 8051C35x series of micro. I have down loaded the demo version of the IDE & compiler. Usually the PIC compilers i have used have software delay loops as library functions to generate not so accurate but fairly good enough delays for us(micro seconds), ms & seconds. We declare the clock freq in the pragma command & the compiler generates the necessary code for the delays. example delay_ms(200);
do we have such lib in raisonance compiler?

Regards
Raghunathan.

+1
0
-1
June 18, 2007 - 9:43am
Raisonance Support Team

Hi,

Yes, there is the RTOS (KRX) that can do this. Please look in the documentation for more information on KRX.

Best Regards,

Vincent

+1
0
-1
June 18, 2007 - 5:48pm
Guest

the 'u' is simply intend for someone who knows more.

about WHAT? Stupid Monkey Shit (abbreviated: SMS)?

Erik