Experiment Name: Timer 1 Experiment
Wiring Instructions:
Experiment Phenomenon: After downloading the program, the D1 indicator light flashes at an interval of 1s.
Notes:
************************ *************************************************** *************/
#include "reg52.h"
typedef unsigned int u16; //Redefine the system default data type
typedef unsigned char u8;
//Define LED1 pin
sbit LED1=P2^0;
/****************************************************** ****************************
* Function name: delay_10us
* Function function: Delay function, when ten_us=1, the delay is approximately 10us
* Input: ten_us
* Output: None
**************************************** ***************************************/
void delay_10us(u16 ten_us)
{
while(ten_us --);
}
/****************************************************** ******************************
* Function name: time1_init
* Function function: Timer 1 interrupt configuration function, by setting TH and TL can determine the timing time
* Input: None
* Output: None
************************************ *******************************************/
void time1_init(void)
{
TMOD|=0X10;//Select timer 0 mode, working mode 1
TH1=0XFC; //Assign initial value to timer, timing 1ms
TL1=0X18;
ET1=1;//Turn on timer 1 interrupt enable
EA= 1;//Turn on the total interrupt
TR1=1;//Turn on the timer
}
/****************************************************** ******************************
* Function name: main
* Function function: main function
* Input: None
* Output: None
* *************************************************** ******************************/
void main()
{
time1_init();//Timer 1 interrupt configuration
while(1)
{
}
}
void time1() interrupt 3 //Timer 1 interrupt function
{
static u16 i; //Define static variable i
TH1=0XFC; //Assign initial value to timer, time 1ms
TL1=0X18;
i++;
if(i== 1000)
{
i=0;
LED1=!LED1;
}
}
Previous article:51 microcontroller learning: serial communication experiment
Next article:51 microcontroller learning: timer 0 experiment
- 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
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- Taiwan Sun Yat-sen University ASIC Laboratory Comprehensive Script Tutorial
- How can I find out the maximum output power of a DCDC buck chip from its technical documentation?
- The ESP32 branch of MicroPython now has dual cores enabled by default
- Vehicle CAN bus network data access and research significance
- Zigbee Topology Research
- Hands-on learning about power supply Season 1: DIY small fan, fan all summer long!
- Watch the HDC 2022 developer keynote speech, and a demo will explain the Hongmeng development kit
- TE Live | How to effectively respond to the challenges in the current test and measurement field? Hot recruitment
- stm32 pwm fails after eight cycles
- A preliminary study on STEVAL-MKI109V3 debugging and logic construction