51 MCU common knowledge points

Publisher:骄阳少年Latest update time:2020-09-01 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

First of all,

the timer/
counter is very important. It is the heart of the microcontroller.
First of all, let's talk about some concepts.
Clock frequency: fosc (provided by the crystal oscillator, 51 is generally 12Mhz and 11.0592Mhz)
12 division: fosc/12 (I set it to fT here)
Machine cycle: T=1/fT

There are two configurations for the timer.
The first is the working mode: timer/counter.
The second is the four working modes.

Then there are two registers
TMOD&TCON
working mode register and control register

working mode register TMOD
(1) GATE - When the gate bit
GATE=0, only the control bit TRX (X=0, 1) starts the timer/counter.
When GATE=1, the high level on TRX (X=0, 1) and the interrupt pin (INT0 and INT1) jointly starts the timer/counter.
(2) M0, M1 -
There are four encodings for the working mode selection bits M0 and M1, corresponding to the four working modes. Corresponding relationship
M1 M0 Working mode
0 0 Mode 0, 13-bit timer/counter
0 1 Mode 1, 16-bit timer/counter
1 0 Mode 2, 8-bit timer/counter 1 with 8-bit initial value automatically reloaded
1 Mode 3, only applicable to T0, divided into two 8-bit counters, T1 stops counting
(3) C/T——Counter mode and timer mode selection bit
C/T=0, timer mode
C/T=1, counter mode, the counter counts the external pulse (negative jump) of the external input pin T0 (P3.4 pin) or T1 (P3.5 pin).

Timer/counter control register TCON
The byte address of TCON is 88H, which can be bit-addressed, and the bit address is 88H~8FH.
The lower four bits are related to interrupts, and the upper four bits
(1) TF0, TF1——T0, T1 count overflow flag bit
When the counter counts overflow, this position is "1". When using the query mode, this bit is used as a status bit for the CPU to query, but it should be noted that after the query is valid, the bit should be cleared to 0 in a timely manner by software. When using the interrupt mode, this bit is used as an interrupt request flag bit and is automatically cleared to 0 by hardware after entering the interrupt service program .
(2) TR0, TR1 - counting operation control bit
TR1 bit (or TR0 bit) = 1, a necessary condition for starting the timer/counter, and is also related to the GATE bit.
TR1 bit (or TR0 bit) = 0, turns off the timer/counter.

Regarding the initial value calculation of several working modes,
the first working mode is a 13-bit timer.
Its maximum value is 213=81922
13
=8192.
The initial value calculation is,
for example, to time 1ms.
1ms is the time, which corresponds to the number of steps taken by the microcontroller.
First, calculate how much time one step takes, which is the machine cycle 12/fosc.
You can calculate a total of fosc/(12*1000) steps.
Subtract this number of steps from the maximum value of the timer to get the initial value of the timer.
The second working mode is similar.
The third is automatic reload. The values ​​of its high and low registers are the same.

Reference address:51 MCU common knowledge points

Previous article:C51 universal serial port data transmission and reception C language program
Next article:Single chip microcomputer controls stepper motor, LCD1602 displays

Recommended ReadingLatest update time:2024-11-17 03:05

s3c6410 hardware WATCHDOG TIMER watchdog timer
  First, let's briefly describe the working process of the watchdog. The watchdog is actually a timer with a counter inside. Every time a clock signal arrives, the counter register decreases by one. If it decreases to 0, the system will restart; if the system sets the counter to a larger value before it decreases to 0,
[Microcontroller]
s3c6410 hardware WATCHDOG TIMER watchdog timer
MCU timer (timer0 working mode 2)
; Let the LED light change every R1ms COUNT EQU 92; for a crystal oscillator of 11.0592, 92 is equivalent to 100us LED EQU P1.1   ORG 0000H   MOV R0,#00H   DJNZ R0,$     MOV SP,#60H   MOV R1,#00H ; Use R1 as the overall count and use   MOV R2,#00H   //MOV A,TMOD   //ANL A,#11110000B    //CLR ACC.3   //CL
[Microcontroller]
PIC16F1829 TIMER1 Initialization Procedure
Introduction: Here I share with you a PIC16F1829 TIMER1 initialization program. Interested friends can take a look. //timer1 frequency division value #define TIMER1_DIV1 (0 4) #define TIMER1_DIV2 (1 4) #define TIMER1_DIV4 (2 4) #define TIMER1_DIV8 (3 4) //------------- #define T1_DARK (1 6) #define T1_FOS
[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号