#include
#include
#include
/***************************
* Define hardware pin connections
****************************/
sbit p1_0=P1^0;
/*****************************
* Define global variables
***********************/
// Byte data intrCounter; // Number of timer interrupts
// Byte data beginNum; // Time to start countdown
//Byte data counterBack; // Store the number of interrupts in it for later use
unsigned char intrCounter;
unsigned char beginNum;
unsigned char counterBack;
void IT0_Init(void);
void Timer0_Overflow();
void GetCounter(void);
void main()
{
p1_0=1;
GetCounter() ;Change once every second;
p1_0=!p1_0;;
}
/*********************************
* GetCounter
*
* Description: Get the preset countdown time
*******************************/
void GetCounter(void)
{
//beginNum=1;//When all switches are not turned, the countdown is 1 second, which is better than setting it to 0 seconds
intrCounter=20;//The number of interrupts corresponding to each second is 20 times
}
/********************************
* IT0_Init
* Description: Initialize the status of timer T0
********************************/
void IT0_Init(void)
{
TMOD=0x01;//Set T0 to work in mode 1
TH0=0x3C;
TL0=0xAF;//These two registers store the starting value of the counter. It is found that the sum of these two values is exactly 50ms after overflow
ET0=1;//Enable T0 interrupt to overflow
EA=1;//Enable total interrupt
TF0=0;//Clear overflow bit
TR0=1;//Enable T0
}
/******************************
* Timer0_Overflow() interrupt 1
* Description: Interrupt overflow service routine, using interrupt mode 1, it is best not to add "using" to select the register group to avoid conflicts with the registers used by the system in the main program
*********************************/
void Timer0_Overflow() interrupt 1
{
static unsigned char second=20;//Use 20 interrupts to determine 1 second
TH0=0x3C;
TL0=0xAF;
second--;
intrCounter--;
if (second==0) //Operation every second
{
second=20; //Reassign the counter per second
}
if (intrCounter==0)
{
TR0=0; //Close T0 counter
}
Previous article:51 baud rate calculation formula
Next article:Timing calculation method of single chip microcomputer timer
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- 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
- "【TGF4042 Signal Generator】" Dual-channel signal measurement
- Design of low voltage dropout buck regulator circuit
- Bluetooth Air Capture
- Analysis of ZIGBEE report mechanism
- [Qinheng Trial] Received the CH559EVT development board and tried USB download
- Use of Zero-knowledge development board and infrared human body sensing module
- msp430f5529 capture plus serial port source code
- #idlemarket#Multiple board replacements (stm32, 51, NRF51822)
- EEWORLD University ---- TI GaN-based high-frequency (1.2MHz) high-efficiency 1.6kW high-density critical mode (CrM) totem pole power factor correction (PFC) converter application introduction
- PT100 temperature measurement circuit