Home > other >  Single chip microcomputer main program affect the timer count?
Single chip microcomputer main program affect the timer count?

Time:11-23

Is I use on STC software source code as follows, timing function directly copy the/ps I always don't understand how to write the timer code,
If the timer function in a loop inside, it is necessary to perform again only after the whole cycle timer function, it should lead to counting inaccurate?
Excuse me, how can achieve accurate count a second?
 
//digital tube clock program
#include
#include
# define uint unsigned int
# define uchar unsigned char
Sbit du=P2 ^ 6;
Sbit we=P2 ^ 7;

Int num=0;
Int shi=3;
Int fen=2;
Int miao=0;
//uchar hour=8, minute=5, the SEC=1;
Int miao2=0, fen2=5, shi2=2;
SFR AUXR=0 x8e;

Uchar duan []={x5b x3f 0, 0 x06, 0, 0 x4f, 0 x66, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f};//section of the code
Uchar wei []={XFD 0 xfe, 0, 0 XFB, 0 xf7, 0 xef, 0 XDF, 0 XBF, 0 x7f};//a

Void Timer1Init (void)//1 millisecond @ 11.0592 MHz
{
AUXR |=0 x40;//timer 1 t model
TMOD & amp;=0 x0f;//set the timer mode
TL1=0 XCD;//set the timer initial
TH1=0 xd4;//set the timer initial
TF1=0;//remove TF1 sign
TR1=1;//timing starts the timer 1
Num++;
}

Void delay (uint k)//software delay
{
Uint I;
uint j;

for(i=0; I & lt; k; I++)
for(j=0; J & lt; 80; j++);//raw data j & lt; 114
}

Void jisuan ()
{
If (num==100)
{
Miao++;
Num=0;
}
If (miao==10)
{
Miao2 + +;
Miao=0;
}

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
If (miao2==6)
{
Fen + +;
Miao2=0;
}
If (fen==10)
{
Fen2 + +;
Fen=0;
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
If (fen2==6)
{
Shi++;
Fen2=0;
}
If (shi==10)
{
Shi2 + +;
Shi=0;
}
If (shi2==2 & amp; Shi==4)
{
Shi=0;
Shi2=0;
}
}
//=============the main function================
//=============the main function================
Void main ()
{
While (1)
{
Timer1Init ();
Jisuan ();
Du=1;
P0=duan (miao),
Du=0;
We=1;
P0=wei [7];
We=0;
Delay (1);
Du=1;
P0=duan [miao2];
Du=0;
We=1;
P0=wei [6].
We=0;
Delay (1);
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Du=1;
P0=0 x40;
Du=0;
We=1;
P0=wei [5];
We=0;
Delay (1);
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Du=1;
P0=duan (fen);
Du=0;
We=1;
P0=wei [4];
We=0;
Delay (1);
Du=1;
P0=duan [fen2];
Du=0;
We=1;
P0=wei [3].
We=0;
Delay (1);
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Du=1;
P0=0 x40;
Du=0;
We=1;
P0=wei [2];
We=0;
Delay (1);
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Du=1;
P0=duan (shi);
Du=0;
We=1;
P0=wei [1];
We=0;
Delay (1);
Du=1;
P0=duan [shi2];
Du=0;
We=1;
P0=wei [0];
We=0;
Delay (1);
}
}

CodePudding user response:

51 cheat chicken egg use interrupts are not accurate, only using an external clock chip can more accurately,

CodePudding user response:

With external crystals, but seem to call after the program or can't obtain accurate time

CodePudding user response:

Why Timer1Init into the loop?
  • Related