( one ) interrupt
( two ) timer , Counter interrupt
TL0 The lower eight bits are stored first , achieve 0XF, One step up , Until the high and low eight bits are full, interrupt or control can be generated TF0 mouth .
(1).
TMOD Low four bit control T0, High four bit control T1.
GATE:( Gate control position )
(2) Control register TCON:( Low four bit control external interrupt , High four bit control counter start and interrupt application )
(3) Four working modes of timer :
Working principle of timer on :
Four ways of working :( Machine cycle ( pulse ) and T0 Pin to determine the trigger circuit )
The difference is that TH0 and TL0 Number of bits and output )
Commonly used 1 and 2
1.
2. Pulse signal transmitter for accurate comparison :
3.
Programmed step :
calculation : initial value ==2^n-N( The formula depends on the way you use it 0.1.2.3 Four ways ), for example (65535-1000+1),N=1000 namely 1ms/1us=1000, To overflow, to achieve 65536, So timing one millisecond is the initial value 64536=FC18H( hexadecimal )
( three ) timer interrupt :
Timer operation code :
#include"reg52.h" typedef signed char int8; typedef signed int int16; typedef
signed long int32; typedef unsigned char uint8; // character typedef unsigned int
uint16; typedef unsigned long uint32; sbit led=P2^0; //D1
//***《 This function needs to be familiar with the above notes 》***// void Time0Init () {
// Or operation is equivalent to TMOD=TMOD||0X01, As long as one is one, one is one TMOD |=0X01; // Timing counting selection , Working mode selection , Gating conditions TH0=0XFC;
// Timer initial value FC18H, Time one millisecond TL0=0X18; ET0 =1; // Timer control interrupt allow bit EA =1; // Master switch TR0 =1; // Start timing counter
} // No timer function required , Because we need a timer //void delay(uint16 x_ms) // Delay MS //{ // uint16 i, j;
// for (i = x_ms; i > 0; i--) // for (j = 114; j > 0; j--); //} void Time0()
interrupt0 { static uint16 i; //1 second =1000 millisecond TH0=0XFC; //TH and TL Every time , time consuming 1 millisecond TL0=0X18;
i++; if(i==1000) // therefore i To accumulate to 1000 { led=~led; } } void main() { Time0Init(); while
(1); }
Technology
Daily Recommendation