Analyze the following program. Why is the following program interrupted? Reality 40 (I wanted to program it as a 40S countdown) Hint: The problem lies in the delay subroutine
#include
#define uchar unsigned char
#define uint unsigned int
sbit p14=P1^4;
sbit p13=P1^3;
uint i,t,z=50;
void delay()
{
while(z-- ); }
#define uchar unsigned char
#define uint unsigned int
sbit p14=P1^4;
sbit p13=P1^3;
uint i,t,z=50;
void delay()
{
while(z-- ); }
unsigned char code tab[] =
{
0XC0,//;0
0XF9,//;1
0XA4,//;2
0XB0,//;3
0X99,//;4
0X92,//;5
0X82,//;6
0XF8,//;7
0X80,//;8
0X90,//;9
};
void main()
{i=40;
t=0;
TMOD=1;//Set timer 0 to working mode 1
TH0=(65536-46080)/256;//Timer 50ms high 8 bits modulus
TL0=(65536-46080)%256;//Timer 50ms low 8 bits remainder
EA=1;//Open total interrupt
ET0=1;//Timer 0 interrupt
TR0=1;//Start timer 0
while(1)
{
if(t==20)//50ms interrupt 20 times
{
t=0;
i--;//The total countdown decreases by 1 per second
}
if(i>0)
{
p14=0;//Disable the ones digit of the digital tube
p13=1;//Enable the tens digit of the digital tube
P0=tab[i/10];//Display the tens digit data
delay();
P0=0xff;//Disable the segment selection of the digital tube
p14=1;//Disable the ones digit of the digital tube
p13=0;//Disable the tens digit of the digital tube
P0=tab[i%10];//Display the ones digit data
delay();
P0=0xff;//Disable the segment selection of the digital tube
}
else{i=40;}
}
}
void timer0() interrupt 1//Timer 0 interrupt entry
{TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
}
{
0XC0,//;0
0XF9,//;1
0XA4,//;2
0XB0,//;3
0X99,//;4
0X92,//;5
0X82,//;6
0XF8,//;7
0X80,//;8
0X90,//;9
};
void main()
{i=40;
t=0;
TMOD=1;//Set timer 0 to working mode 1
TH0=(65536-46080)/256;//Timer 50ms high 8 bits modulus
TL0=(65536-46080)%256;//Timer 50ms low 8 bits remainder
EA=1;//Open total interrupt
ET0=1;//Timer 0 interrupt
TR0=1;//Start timer 0
while(1)
{
if(t==20)//50ms interrupt 20 times
{
t=0;
i--;//The total countdown decreases by 1 per second
}
if(i>0)
{
p14=0;//Disable the ones digit of the digital tube
p13=1;//Enable the tens digit of the digital tube
P0=tab[i/10];//Display the tens digit data
delay();
P0=0xff;//Disable the segment selection of the digital tube
p14=1;//Disable the ones digit of the digital tube
p13=0;//Disable the tens digit of the digital tube
P0=tab[i%10];//Display the ones digit data
delay();
P0=0xff;//Disable the segment selection of the digital tube
}
else{i=40;}
}
}
void timer0() interrupt 1//Timer 0 interrupt entry
{TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
}
Previous article:External interrupt nesting operation
Next article:Typical program for implementing nested interrupts in assembly language
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- Application of INA series current detection devices in TWS battery box
- KL25 uses low power timer to wake up MCU with low power consumption
- [RVB2601 Creative Application Development] Unboxing
- Would you consider domestic DDR4 memory?
- Analysis of the advantages and disadvantages of UWB high-precision positioning technology
- GD32E231 DIY Contest (4) - How to get long and short keys?
- How to Choose the Correct Thermistor for Your Temperature Sensor
- How to read the timing diagram--Detailed explanation of nand flash read operation
- FPGA Experiment (VI) SignalTap II parameter setting and waveform generation
- [Mill MYB-YT507 development board trial experience] Use Python to obtain computer memory and CPU information