Detailed explanation of MCS-51 microcontroller special function registers

Publisher:tony520Latest update time:2015-08-07 Source: 21icKeywords:MCS-51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. Timer/Counter Mode Register TMOD

TMOD is an 8-bit special function register, the corresponding address is 89H, and it is not bit addressable. A mainly completes three functions:
*Determine whether to select a timer or a counter;
*Select which working mode;
*Whether to use external interrupts to control the start and stop of the timer and counter;
B The lower 4 bits of TMOD are the field that controls T0 (T0--P3.4 Timer/Counter 0 external event pulse input terminal)

The upper 4 bits of TMOD are the field that controls T1 (T1--P3.5 Timer/Counter 1 external event pulse input terminal)
C The format and meaning of the control word

a. GATE (TMOD.7)
is divided into two cases: GATE=0, the start and stop of the timer has nothing to do with INT1, but only depends on TR0;
GATE=1, the start and stop of the timer is not only controlled by TR0, but also by the control of the INT1 pin.
The timer starts working only when both are high levels;

b. C/T (TMOD.6)

is divided into two cases: C/T=0, used as a timer;
C/T=1, used as a counter;

d. M1 (TMOD.5), M0 (TMOD.4)
use M1 and M0 to control the 4 working modes of the timer/counter:
* Mode 0: M1=0, M0=0. 13-bit timer/counter mode
* Mode 1: M1=0, M0=1. 16-bit timer/counter
* Mode 2, M1=1, M0=0. 8-bit timer/counter with 8-bit initial value automatically reloaded
* Mode 3, M1=1, M0=1. Only applicable to T0, divided into two 8-bit counters, T1 stops counting

2. Timer/counter control register TCON
TCON is an 8-bit special function register, the corresponding address is 88H, which can be addressed.
A. Format and meaning of control word
a. TF1 (TCON.7), TF0 (TCON.5) ---- T1, T0 count overflow flag bit
When the counter count overflows, 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 time by software method. When using the interrupt
mode, this bit is used as the interrupt request flag bit. It is automatically cleared to 0 by the hardware after entering the interrupt service routine.
b. TR1 (TCON.6), TR0 (TCON.4) ---- Counting operation control bit
TR1 (TR0) = 1, a necessary condition for starting the timer/counter, and is also related to the state of the GATE bit.
TR1 (TR0) = 0, stops the timer/counter.
This bit can be set to 1 or cleared to 0 by software .
C. IE1 (TCON.3), IE0 (TCON.1) ---- Interrupt request flag bit of external interrupt INT1 (P3.3), INT0 (P3.2)
When there is an external interrupt request, INT1 (INT0) = 1 (completed by hardware), after the CPU responds to the interrupt,
IE1 (IE0) is cleared to 0 by the hardware
. d. IT1 (TCON.2), IT0 (TCON.0) ---- INT1 (INT0) trigger mode control bit
can be set and reset by software. IT0(IT1)=0, INT0(INT1) is a low level trigger mode;
IT0(IT1)=1, INT0(INT1) is a negative jump trigger mode;

3. Interrupt enable register IE
In the 51 interrupt system, the enable or disable of interrupts is
controlled by the 8-bit interrupt enable register IE that can be bit-addressed in the chip

EA(IE.7): main switch, if it is equal to 0, all interrupts are not allowed;
ES(IE.4): serial port interrupt enable;
ET1: timer 1 interrupt enable;
EX1: external interrupt 1 interrupt enable;
ET0: timer 0 interrupt enable;
EX0; external interrupt 0 interrupt enable;
4. The priority of the 5 interrupt sources
The interrupt service entry address of the microcontroller is as follows, and their natural priority is arranged from high to low.
External interrupt 0: 0003H;
Timer 0: 000BH;
External interrupt 1: 0013H;
Timer 1: 001BH;
Serial port: 0023H;
Using the c51 programming language, the complete syntax of the interrupt service function of this language is as follows:
Return value function name ([parameter]) [mode] [reentry] interrupt n [using n]
interrupt corresponds to the number of the interrupt source, and [using] determines the group number of the register used. Here, a
brief explanation of the register group number is required. There are 4 register groups in the 51 system, and the specific location depends on
the settings of the two bits RS0 and RS1 of psw (program status word). When running an interrupt task, different register groups are used. In c51
, the selection of the register group depends on the specification of the variable after using, which is an integer from 0 to 3.
Here are the C51 program writing methods for different interrupt service routines:
*External interrupt INT0--------void intsvr0(void) interrupt 0 using 1
*Timer/Counter T0-----void timer0(void) interrupt 1 using 1
*External interrupt INT1--------void intsvr0(void) interrupt 2 using 1
*Timer/Counter T1-----void timer0(void) interrupt 3 using 1
*Serial port interrupt-------------void serial0 interrupt 4 using 1
Alternative function of port P3
Register address B0H, bit addressing B7H~B0H.
Pinout P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P3.7
Replacement function RxD TXD /INT0 /INT1 T0 T1 /WR /RD

TCON: Timer control register
Register address 88H, bit addressing 8FH~88H.
Bit Address 8F 8E 8D 8C 8B 8A 89 88
Bit Notation TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
TF0(TF1)——Count overflow flag, when the counter overflows, this position is set to 1.
TR0(TR1)——Timer operation control bit
When TR0(TR1)=0 , stop the timer/counter
When TR0(TR1)=1, start the timer/counter
IE0(IE1)——External interrupt request flag
When the CPU samples P3.2(P3.3) and a valid interrupt request appears, this bit is set to 1 by hardware. After the interrupt response is completed and the interrupt service is turned, it is automatically cleared to 0 by hardware.
IT0(IT1)——External interrupt request signal mode control bit
When IT0(IT1)=1 Pulse mode (negative jump of the trailing edge is valid)
When IT0(IT1)=0 Level mode (low level is valid) This bit is set to 1 or cleared to 0 by software.
TF0(TF1)——Count overflow flag
When the counter overflows, this bit is set to 1 by hardware. When the interrupt service is turned, it is automatically cleared to 0 by hardware. There are two situations in which the count overflow flag is used: when the interrupt mode is used, it is used as an interrupt request flag; when the query mode is used, it is used as a query status bit. [page]
TMOD: Operation mode control register
Register address 89H, not bit addressable.
Sequence B7 B6 B5 B4 B3 B2 B1 B0
Bit Notation GATE C/T M1 M0 GATE C/T M1 M0
 
GATE——Gating bit
When = 0, start or disable the timer and counter by running TR0 (or TR1)
When = 1, start or disable the timer and counter by TR0*/INT0 (or TR1*/INT1)
GATE=0 Start the timer with TR0 (TR1)
GATE=1 Start the timer with INT0 (INT1)
C/T=0 Timing/counting working mode selection bit
M1M0——Working mode selection bit

T2MOD: Working mode control register
Register address 0C9H, not bit addressable
- - - - - - T2O DCEN
 
T2OE: Timer 2 output enable bit, when = 1, P1.0/T2 pin outputs continuous pulse signal
DCEN: When = 1, T2 is configured as an up-down counter
T2CON: Timer control register
Register address 0C8H, bit addressing 0C8H~0CFH.
Bit Address CF CE CD CC CB CA C9 C8
Bit Notation TF2 EXF2 RCLK TCLK EXEN2 TR2 C/T2 CP/RL2
 
TF2: T2 overflow flag
When T2 overflows, TF2=1, TD2 can only be cleared by software
When RCLK=1 or TCLK=1, TF2 will not be set
EXF2: T2 external flag
When EXEN2=1, the negative transition on the T2EX/P1.1 pin causes the capture/reload operation of T2, at which time EXF2=1. When T2 interrupt is enabled, EXF2=1 will cause an interrupt, and EXF2 can only be cleared by software. In the up-counting and down-counting modes of T2 (DCEN=1), the setting of EXF2 will not cause an interrupt.
RCLK: Receive clock enabled
When RCLK=1, the overflow pulse of T2 can be used as the receive clock signal of the serial port, suitable for serial port modes 1 and 3. When RCLK=0, the overflow pulse of T1 is used as the receive clock signal of the serial port.
TCLK: Transmit clock enabled
EXEN2: T2 external event (external signal causing capture/reload) enabled
When EXEN2=1, if T2 does not output serial clock (ie RCLK+TCLK=0), the jump of T2EX/P1.1 pin will cause T2 capture/reload operation ;
When EXEN2 = 0, negative transitions on the T2EX pin will not work
TR2: T2 start/stop control
C/T2: count timing
CP/RL2: capture/reload selection
When CP/RL2 = 1 and EXEN2 = 1, negative transitions on the T2EX/P1.1 pin will cause a capture operation
When CP/RL2 = 0 and EXEN2 = 1, negative transitions on the T2EX/P1.1 pin will cause a reload operation
When CP/RL2 = 0 and EXEN2 = 0, overflow of T2 will cause an automatic reload operation of T2
When RCLK+TCLK=1, the CP/RL2 control bit has no effect and T2 is forced to work in reload mode. The reload mode occurs when T2 overflows and is often used as a baud rate generator.
SCON: Serial port control register
Register address 98H, bit addressing 9FH~98H.
Bit Address 9F 9E 9D 9C 9B 9A 99 98
Bit Notation SM0 SM1 SM2 REN TB8 RB8 TI RI
 
SM0, SM1: Serial port working mode selection bit
SM2: Multi-machine communication control bit
REN: Control bit to enable/disable serial port reception
TB8: In mode 2 and mode 3, it is the 9th data bit sent, which can be set to 1 or cleared by software as needed, and can also be used as a parity bit. In mode 1, it is a stop bit.
RB8: In mode 2 and mode 3, it is the 9th data bit received (from the TB8th bit); in mode 1, RB8 receives the stop bit, which is not used in mode 0.
TI - Serial port transmit interrupt request flag bit
When a frame of serial data is sent, it is set to 1 by hardware; after turning to the interrupt service program, it is cleared to 0 by software.
RI - Serial port receive interrupt request flag bit
After receiving a frame of serial data, it is set to 1 by hardware; after turning to the interrupt service routine, it is cleared to 0 by software.
IE: Interrupt enable control register
Register address A8H, bit addressing AFH~A8H.
Bit Address AF AE AD AC AB AA A9 A8
Bit Notation EA / ET2 ES ET1 EX1 ET0 EX0
EA: Interrupt enable control bit
When EA=0, interrupts are always disabled.
When EA=1, interrupts are always enabled, and the disablement and enablement of interrupts are set by the interrupt enable control bit of each interrupt source.
EX0 (EX1): External interrupt enable control bit
When EX0 (EX1) = 0, external interrupts are disabled
When EX0 (EX1) = 1, external interrupts are enabled
ET0 (EX1): Timing/counting interrupt enable control bit
When ET0 (ET1) = 0 , timing (or counting) interrupts are disabled
When ET0 (ET1) = 1, timing (or counting) interrupts are enabled
ET2: Timer 2 interrupt enable control bit, in AT89S52 and AT89C52
ES: Serial interrupt enable control bit
When ES = 0, serial interrupts are disabled
When ES = 1, serial interrupts are enabled

IP: Interrupt priority control register
Register address B8H, bit addressing BFH~B8H.
Bit Address BF BE BD BC BB BA B9 B8
Bit Notation / / PT2 PS PT1 PX1 PT0 PX0
PX0——External interrupt 0 priority setting bit
PT0——Timer interrupt 0 priority setting bit
PX1——External interrupt 1 priority setting bit
PT1——Timer interrupt 1 priority setting bit
PS——Serial port interrupt priority setting bit
PT2——Timer 2 priority setting bit
PSW: Program Status Word
Register address D0H, bit addressing D7H~D0H.
Bit Address D7 D6 D5 D4 D3 D2 D1 D0
Bit Notation CY AC F0 RS1 RS0 OV - P
 
CY——Carry mark
AC——Half carry mark
F0——User set mark
RS1, RS0——Selection bits of 4 working register areas.
VO——Overflow mark
P——Parity check mark

PCON: Power controller and baud rate selection register
Byte address = 87H, not bit addressable
SMOD - - POF GF1 GF0 PD IDL
 
SMOD——Baud rate multiplication bit
GF1, GF0——User general mark
PD——Power-down mode control bit, when PD=1, it enters power-down mode
IDL——Idle mode control bit, when IDL=1, it enters idle mode
In AT89S51, PCON.4 is the power-off flag POF, which is 1 when powered on.
Entering idle mode: PCON = 0x01; previously executed AUXR = 0xFF; defines that the watchdog WDT does not count in idle mode.
PCON: Power controller and baud rate selection register
byte address = 87H, not bit addressable
SMOD - - POF GF1 GF0 PD IDL
SMOD——Baud rate multiplication bit
GF1, GF0——User general mark
PD——Power-down mode control bit, when PD=1, enter power-down mode
IDL——Idle mode control bit, when IDL=1, enter idle mode
Sina.com In AT89S51, PCON.4 is the power-off mark bit POF, which is 1 when powered on
 
Keywords:MCS-51 Reference address:Detailed explanation of MCS-51 microcontroller special function registers

Previous article:51 MCU read and write SD card program
Next article:I^2C Bus EEPROM Programming Experience

Recommended ReadingLatest update time:2024-11-16 22:00

Design of radar simulation training card based on MCS-51 single chip microcomputer
0 Introduction Moving target reconnaissance radar usually uses a single pulse fully coherent pulse Doppler working mechanism to effectively extract moving target signals under complex ground clutter. This method can effectively track moving targets and extract useful information such as the target's distance, a
[Microcontroller]
Design of radar simulation training card based on MCS-51 single chip microcomputer
Design of Temperature Control System with MCS-51 Single Chip Microcomputer
0Introduction In modern industrial production, current, voltage, temperature, pressure, flow, flow rate and switch quantity are the main commonly used controlled parameters. For example: in many fields such as metallurgical industry, chemical production, power engineering, papermaking industry, machinery manufa
[Microcontroller]
Real-time online environmental monitoring system based on MCS-51 single chip microcomputer
1 Introduction The data collector based on GPRS and MCS-51 single-chip microcomputer is a real-time online environmental monitoring system. It uses the packet wireless service GPRS to transmit the real-time online detected environmental conditions to the monitoring information processing center of t
[Microcontroller]
Real-time online environmental monitoring system based on MCS-51 single chip microcomputer
The 4 I/O ports of the MCS-51 microcontroller
The four I/O ports of the 8051 microcontroller are basically the same in structure, but each has its own characteristics. These four ports are all 8-bit bidirectional ports, each of which includes a latch, an output driver and an input buffer. In a system without external expansion memory, each of these four ports can
[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号