Use timer interrupt 0 to flash LED1 (one second on and one second off)
#include typedef unsigned char u8; typedef unsigned int u16; sbit led=P2^0;//D1 void Timer0Init() { TMOD|=0x01; //Select timer 0 mode, mode 1, only TR0 controls start TR0=1; //Turn on timer 0 EA=1; //Total interrupt ET0=1; //Turn on timer 0 interrupt TH0=0xFC; TL0=0x18; //Assign initial value to timing 1ms } void main() { Timer0Init(); //Timer 0 initialization while(1); } void Timer0() interrupt 1 { static u16 i; TH0=0xFC; TL0=0x18; //Assign initial value to the timer i++; if(i==1000) { led=~led; i=0; } } Use timer interrupt 1 to flash LED1 (one second on and one second off) #include typedef unsigned char u8; typedef unsigned int u16; sbit led=P2^0;//D1 void Timer1Init() { TMOD|=0x10; Select timer 1 mode, mode 1, only TR1 control start TR1=1; EA=1; ET1=1; TH1=0xFC; TL1=0x18; } void main() { Timer1Init(); while(1); } void Timer1() interrupt 3 //Note that the interrupt number is 3 { static u16 i; TH1=0xFC; TL1=0x18; i++; if(i==1000) { led=~led; i=0; } } The last digit of the digital tube displays 0-F in a cycle with an interval of one second. #include typedef unsigned char u8; typedef unsigned int u16; sbit LSA=P2^2; sbit LSB=P2^3; sbit LSC=P2^4; u8 code smgduanxuan[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; void Timer1Init() { TMOD=0x10; Select timer 1 mode, mode 1, only TR1 control start EA=1; //Open the general interrupt ET1=1; //Open timer interrupt 1 TR1=1; //Turn on timer interrupt 0 TH1=0xFC; TL1=0x18; //Assign initial value, timing 1ms } void main() { LSA=0; LSB=0; LSC=0; Timer1Init(); while(1); } void Timer1() interrupt 3 { static u16 i; u8 n; TH1=0xFC; TL1=0x18; i++; if(i==1000) { P0=smgduanxuan[n++]; if(n==16) { n=0; //Return to zero when the 16th number is displayed } i=0; //Return to zero at 1s } }
Previous article:16.Serial communication
Next article:14. Timers and Counters
- 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?
- Some Problems in Automobile CAN Communication
- Several basic concepts of DSP software and hardware
- Q&A on Connectivity: Mesh Networking and the Growth of IoT Devices
- Problems with constant current source composed of op amp + MOS tube
- WeChat group voice Q&A at 2pm: Vicor power experts answer netizens' power design questions
- Ti's C28x series ADC experience
- How to judge whether an oil chromatograph is suitable for selection?
- Battery interface problem
- What is the relationship between STM32 and IoT?
- About the status of STC microcontroller IO port