Connection method: JP10 to J12; JP8 to JP16; P3^2 to GND; P2^0 to LED;
Only when the global switch is turned on can the switches of other units be turned on.
All switches are turned on when the value is 1 and turned off when the value is 0.
|
||||||||
Bit number
|
D0
|
D1
|
D2
|
D3
|
D4
|
D5
|
D6
|
D7
|
illustrate
|
External interrupt 0
|
Timing/Counting 0
|
External interrupt 1
|
Timing/Counting 1
|
Serial port interrupt
|
Timing/Counting 2
(52 single chip microcomputer)
|
Invalid bit
|
Global interrupt bit
|
Bit symbol (directly referenced when writing a program)
|
EX0
|
ET0
|
EX1
|
ET1
|
ES
|
ET2
|
--
|
EA
|
Bit Address
|
A8H
|
A9H
|
AAH
|
ABH
|
ACH
|
ADH
|
--
|
AFH
|
EA: total enable bit
ES: serial port interrupt enable bit
ET1: timer counter 1 interrupt enable bit
EX1: external interrupt 1 interrupt enable bit
ET0: timer counter 0 interrupt enable bit
EX0: external interrupt 0 interrupt enable bit
The relationship between the 6 interrupt sources in the 52 single-chip microcomputer and the single-chip microcomputer ports:
1 The interrupt request line INT0 of external interrupt 0 is the P3.2 port line of P3 port
2 The interrupt request line INT1 of external interrupt 1 is the P3.3 port line of P3 port
3 The external counting input end of counter 0 is the P3.4 port line of P3 port of the single-chip microcomputer (timer 0 is an internal interrupt)
4 The external counting input end of counter 1 is the P3.5 port line of P3 port of the single-chip microcomputer (timer 1 is an internal interrupt)
5 Serial port interrupt (divided into serial port receive interrupt RXD, which is the P3.0 port line of P3 port of the single-chip microcomputer; serial port send interrupt TXD, which is the P3.1 port line of P3 port of the single-chip
microcomputer 6 The external counting input end of counter 2 is the P1.0 port line of P1 port of the single-chip microcomputer (timer 2 is an internal interrupt)
TCON
TCON (Timer Control Register) Timer/Counter Control Register
TCON is in the special function register, the byte address is 88H, because of the bit address, it is very convenient to perform bit operations.
The function of TCON is to control the start and stop of the timer, and mark the timer overflow and interrupt.
The format of TCON is shown in the figure below. Among them, TF1, TR1, TF0 and TR0 are used for timer/counter; IE1, IT1, IE0 and IT0 are used for interrupt system.
The definition of each bit is as follows:
TF1: Timer 1 overflow flag. When timer 1 overflows, TF1 is set to "1" by hardware and an interrupt is requested. After entering the interrupt service routine, it is automatically cleared to "0" by hardware, and cleared to "0" by software in query mode.
TR1: Timer 1 operation control bit. Clear "0" by software to turn off timer 1. When GATE=1 and INT1 is high, TR1 is set to "1" to start timer 1; when GATE=0, TR1 is set to "1" to start timer 1.
TF0: Timer 0 overflow flag. Its function and operation are the same as TF1.
TR0: Timer 0 run control bit. Its function and operation are the same as TR1.
IE1: External interrupt 1 request flag.
IT1: External interrupt 1 trigger mode selection bit. When IT1=0, it is low level trigger mode; when IT1=1, it is falling edge trigger mode.
IE0: External interrupt 0 request flag.
IT0: External interrupt 0 trigger mode selection bit. When IT0=0, it is low level trigger mode; when IT0=1, it is falling edge trigger mode.
The lower 4 bits of TCON are related to interrupts. Since TCON is bit addressable, if you only want to clear overflow or start the timer, you can use bit operation commands. For example: after executing "CLR TF0", the overflow of timer 0 is cleared; after executing "SETB TR1", timer 1 can be started to work (of course, the mode must be set before). [page]
code:
//Level trigger
#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit D1=P2^0;
uchar num;
uchar wnum=0x00;
uchar code dbit[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //Segment selection, select the number to be displayed
//uchar code wnum[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F}; //Eight-bit digital tube
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=0;y<113;y++)
{
}
}
}
void main()
{
P1=wnum;
EA=1;//Turn on the main interrupt switch
EX0=1;//Turn on external interrupt 0, P3.2 select
IT0=0;//Select level trigger mode
while(1)
{
for(num=0;num<10;num++)
{
P0=dbit[num];
delay(500);
}
}
}
void duan() interrupt 0
{
D1=1;
delay(500);
D1=0;
delay(500);
}
//Edge trigger mode
#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit D1=P2^0;
uchar num;
uchar wnum=0x00;
uchar code dbit[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//Segment selection, select the number to be displayed
//uchar code wnum[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F};//Eight-bit digital tube
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=0;y<113;y++)
{
}
}
}
void main()
{
P1=wnum;
EA=1;//Turn on the main interrupt switch
EX0=1;//Turn on external interrupt 0, P3.2 select
IT0=1;//Select edge trigger mode
while(1)
{
for(num=0;num<10;num++)
{
P0=dbit[num];
delay(500);
}
}
}
void duan() interrupt 0
{
D1=1;
delay(500);
D1=0;
delay(500);
}
Previous article:Data on I_2C bus A_D_D_A conversion based on PCF8591
Next article:About the serial port control register SCON
Recommended ReadingLatest update time:2024-11-16 04:16
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Introduction to the mobile station development board: ultra-low power python board
- USB to JTAG
- DSP28335 SCI communication problem summary and problem summary
- Beetle ESP32-C3 test (IV) IDF method to provide AP connection
- Several questions about 7S3P battery pack circuit
- MSP430G2553 clock system configuration
- Award-winning live broadcast: Microchip&avnet series live broadcast third collection
- [Vicor White Paper Recommendation] Power Averaging Design Method with Voltage Regulation: Ideal Power Supply Solution for Pulse Loads
- Bear Pie Huawei IoT Operating System LiteOS Kernel Tutorial - IoT-Studio Introduction and Installation
- How to use C language to find the corresponding value in the table in the microcontroller