/*--------------------------------------------------------------------------
Custom REG52 header file
@auth lei
@date 2017-05
--------------------------------------------------------------------------*/
#ifndef __REG52_H__
#define __REG52_H__
/* One byte register */
sfr P0 = 0x80; //Bidirectional IO, external output needs to be connected to a pull-up resistor
sfr P1 = 0x90; //quasi-bidirectional IO, as input, it must be set to 1 first
sfr P2 = 0xA0; //quasi-bidirectional IO, as input, it must be set to 1 first
sfr P3 = 0xB0; //quasi-bidirectional IO, as input, it must be set to 1 first, and has a second function
sfr PSW = 0xD0;
sfr ACC = 0xE0;
sfr B = 0xF0;
sfr SP = 0x81;
sfr DPL = 0x82;
sfr DPH = 0x83;
sfr PCON = 0x87;
sfr TCON = 0x88; //Interrupt control register
sfr TMOD = 0x89; //Timer working mode register
sfr TL0 = 0x8A; //Timer/Counter 0 low 8 bits
sfr TL1 = 0x8B; //Timer/Counter 1 low 8 bits
sfr TH0 = 0x8C; //Timer/Counter 0 high 8 bits
sfr TH1 = 0x8D; //Timer/Counter 1 high 8 bits
sfr IE = 0xA8; //Interrupt enable register
sfr IP = 0xB8; //Interrupt priority register
sfr SCON = 0x98;
sfr SBUF = 0x99;
/* 8052 MCU extended registers */
sfr T2CON = 0xC8;
sfr RCAP2L = 0xCA;
sfr RCAP2H = 0xCB;
sfr TL2 = 0xCC;
sfr TH2 = 0xCD;
/* One bit register */
/* PSW */
sbit CY = PSW^7;
sbit AC = PSW^6;
sbit F0 = PSW^5;
sbit RS1 = PSW^4;
sbit RS0 = PSW^3;
sbit OV = PSW^2;
sbit P = PSW^0; //8052 specific
/*------------Detailed explanation of interruption content----------------------------
* Related registers
* 1.IE interrupt enable register
* 2.TCON timing control register
* 3.IP interrupt priority register (not commonly used)
* 4.TMOD timer working mode register (only used for timer/counter interrupt)
*Steps to use interrupts:
* 1. Interrupt initialization function (only need to be called once, do not put it in a loop and call it repeatedly)
* 2. Write interrupt handling function
* 3. Call the interrupt initialization function in the main function
*------------Detailed explanation of interruption content----------------------------/
/* TCON timing control register */
sbit TF1 = TCON^7; // Flag bit in timer/counter:
sbit TR1 = TCON^6; //Timer/counter 1 starts and stops:
sbit TF0 = TCON^5; //0 flag bit in timer/counter:
sbit TR0 = TCON^4; //Timer/Counter Interrupt 0 start, stop:
sbit IE1 = TCON^3; //External interrupt 1 interrupt flag: hardware set to 1 when an interrupt occurs, hardware set to 0 after the interrupt function is processed
sbit IT1 = TCON^2; //External interrupt 1 trigger mode: 0 for level, 1 for falling edge
sbit IE0 = TCON^1; //External interrupt 0 interrupt flag: hardware set to 1 when an interrupt occurs, hardware set to 0 after the interrupt function is processed
sbit IT0 = TCON^0; //External interrupt 0 trigger mode: 0 is level, 1 is falling edge
/* IE interrupt enable register */
sbit EA = IE^7; //interrupt master switch
sbit ET2 = IE^5; // 8052 specific
sbit ES = IE^4;
sbit ET1 = IE^3; //Timer/Counter Interrupt 1 Switch
sbit EX1 = IE^2; //External interrupt 1 switch
sbit ET0 = IE^1; //Timer/Counter Interrupt 0 Switch
sbit EX0 = IE^0; //External interrupt 0 switch
/* IP interrupt priority register */
sbit PT2 = IP^5;
sbit PS = IP^4;
sbit PT1 = IP^3;
sbit PX1 = IP^2;
sbit PT0 = IP^1;
sbit PX0 = IP^0;
/*------------------Detailed explanation of TMOD register-----------------
The 8 bits from high to low are: GATE C/T M1 M0 GATE C/T M1 M0
{----Configure timer 1----} {----Configure timer 0----}
GATE: Gating bit, the external pin (T0, T1) is used as the main switch to start the timer: when GATE=0, T0 and T1 are invalid; when GATE=1, the timer can only be started when T0 or T1 switch is turned on (high level)
C/T: Counting mode selection, when C/T=0, it is used as a timer, when C/T=1, it is used as a counter
M1, M0: working mode selection bit, 00 is working mode 0, 13-bit timer/counter, TH stores the upper 8 bits, TL stores the lower 5 bits
01 is working mode 1, 16-bit timer/counter, TH stores the upper 8 bits, TL stores the lower 8 bits (commonly used)
10 is working mode 2, 8-bit timer/counter with automatic initial value loading (commonly used)
11 is working mode 3, T0 is divided into two 8-bit independent counters, and T1 stops working
*------------------Detailed explanation of TMOD register-----------------/
/* The second function of P3 port */
sbit RD = P3^7; // external memory read strobe signal
sbit WR = P3^6; //External memory write select signal
sbit T1 = P3^5; // Start of external control timer/counter 1 (valid only when bit 7 of TMOD register GATE = 1), 1 means start, 0 means stop
sbit T0 = P3^4; // Start of external control timer/counter 0 (valid only when bit 3 of TMOD register GATE = 1), 1 means start, 0 means stop
sbit INT1 = P3^3; //External interrupt 1 input
sbit INT0 = P3^2; //External interrupt 0 input
sbit TXD = P3^1; //Serial output
sbit RXD = P3^0; //Serial input
/* SCON serial port control register */
sbit SM0 = SCON^7;
sbit SM1 = SCON^6;
sbit SM2 = SCON^5;
sbit REN = SCON^4;
sbit TB8 = SCON^3;
sbit RB8 = SCON^2;
sbit TI = SCON^1;
sbit RI = SCON^0;
/* P1 port second function */
sbit T2EX = P1^1; // 8052 only
sbit T2 = P1^0; // 8052 specific
/* T2CON */
sbit TF2 = T2CON^7;
sbit EXF2 = T2CON^6;
sbit RCLK = T2CON^5;
sbit TCLK = T2CON^4;
sbit EXEN2 = T2CON^3;
sbit TR2 = T2CON^2;
sbit C_T2 = T2CON^1;
sbit CP_RL2 = T2CON^0;
#endif
Previous article:Homemade 51 MCU package library
Next article:Digital-to-Analog Converter ADC08009 Application
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- UC3525 extended duty cycle solution
- GD32VF103 serial port of Gigabit RISC-V core reads PM2.5 sensor
- Summary of the basic knowledge of lead-acid batteries
- Want to build a smart home, how to start? Receive this collection of information
- Problems with the 5V3-pin DCDC voltage reference chip
- EEWORLD University Hall----Live Replay: Future Perception is Predicted by Me-The Latest Application of Sensors in the Internet of Things
- Design of Power Amplifier Circuit for MSP430F449 Single Chip Microcomputer
- Senior Sales Engineer
- [MM32 eMiniBoard Review] + Reunion with Smart Development Board
- [2022 Digi-Key Innovation Design Competition] Home Smart Dashboard - LVGL transplantation and testing