51 MCU Series Serial 5 - Timer

Publisher:SereneWandererLatest update time:2015-09-10 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
In the previous section, we mentioned that the most obvious application of interrupts is timers. Next, we will introduce timers. In fact, timers are a kind of counters. The essence of timers/counters is a plus-1 counter (16) bits, which consists of two registers, the high 8 bits and the low 8 bits, mainly the two registers TMOD and TCON.

 

TMOD is the working mode register of the timer/counter, which determines the working mode and function; TCON is the control register, which controls the start and stop of T0 and T1 and sets the overflow flag. 

 

         51 MCU Series Serial 5 - Timer
    First, let's talk about the TMOD register. Its lower four bits are used for T0, and the upper four bits are used for T1. Its format is as follows:

 

51 MCU Series Serial 5 - Timer

 

Among them, GATE: gate bit. When GATE = 0, as long as TR0 or TR1 in TCON is set to 1 by software, the timer/counter can be started; when GATA = 1, TR0 or TR1 must be set to 1 by software, and the external interrupt pin or is also at a high level to start the timer/counter. That is, there is one more condition for starting the timer at this time. C/T: timing/counting mode selection bit. C/T = 0 is timing mode; C/T  = 1 is counting mode. M1M0: working mode setting bit. The timer/counter has four working modes, which are set by M1M0.

 

51 MCU Series Serial 5 - Timer

 

    The timer initialization procedure should complete the following tasks:

   (1) Assign values ​​to TMOD to determine the working mode of T0 and T1.

   (2) Calculate the initial value and write it into TH0, TL0 or TH1, TL1.

   (3) When in interrupt mode, assign a value to IE and enable interrupt.

   (4) Set TR0 or TR1 to start the timer/counter timing or counting.

 

    Next, let's focus on the calculation of the timer's initial value. Please remember the following formula:

                           t=T*(2L-C)

    Among them, t is the timing time, which is usually half of the machine cycle, T is the machine cycle, L is the length of the counter, and C is the counting constant, which is usually the initial value we need to find. Find an example to analyze and you will understand.

    Of course, this timer is used together with other contents, which will be introduced in more detail later, which is very interesting.

Reference address:51 MCU Series Serial 5 - Timer

Previous article:51 MCU Series Serial 6 - Timer Initialization Supplement
Next article:51 MCU Series Serial 4 - Interrupt

Recommended ReadingLatest update time:2024-11-16 19:54

MSP430 G2553 Timer Interrupt Summary
Currently, a total of four interrupt vectors are used. I think all the timer interrupts of G2553 have been used. There are two timers, TA0 and TA1, and each timer has two interrupt vectors. 1. The interrupt when CCR0 arrives is very useful in counting mode and is the basic function of the timer at ordinary times. 2. C
[Microcontroller]
Use of Stm8l051x timer library functions
Stm8l051x has 5 timers, of which timer1 is a 16-bit priority timer, timer2, timer3, timer5 are 16-bit general timers, and timer4 is an 8-bit reference timer (see datasheet for details). The official library function also provides these 5 timer interfaces for us to use. The specific steps for how to use these timers ar
[Microcontroller]
LPC1114_Timer16_0 interrupt program_MDK compilation environment
About Timer16_0 code:     LPC_SYSCON- SYSAHBCLKCTRL |= (1 7); //Start the timer clock   LPC_TMR16B0- PR=1000;//1000-1; //Prescaler counter   LPC_TMR16B0- MR0=12000; //match register   LPC_TMR16B0- TCR=0x1; //Start the timer counter   LPC_TMR16B0- MCR=3;//(1 0)&(1 1); //Match control--matching triggers an int
[Microcontroller]
TIMER0 delay time program in MODE0
        org 0000h ; start address          jmp main          org 0030h  main:       MOV tmod,#00h ;Set TIMER0 to work in MODE0  start:      clr c       MOV a,#0ffh ;A CC =FFH, shift left to initial value       MOV r2,#08 ;R2=08, set shift left eight times  loop:      rlc a ; shift left one position       MOV p2,a ; ou
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号