Title: The first three digits of the digital tube display a stopwatch, running from 000 to 999 at a speed of 0.01 seconds. When an independent button is pressed, the stopwatch stops, and the second button starts counting, and the third button resets the count value and starts from the beginning. (Using timer interrupt method)
Solution: (C language programming)
#include
#include
#define uint unsigned int
#define uchar unsigned char
uchar bai,shi,ge,num;
uint shu;
sbit s=P1^0;
sbit s2=P1^1;
sbit s3=P1^2;
sbit le=P3^6;
void delay(uint a);
void dis();
void display(uchar ba,uchar sh,uchar g);
uchar code tabledu[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x89,0x86,0xc7,0xc7,0xc0,0xff};
uchar code tablewe[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x 7f};
void init()
{
shu=0;
bai=0;
shi=0;
ge=0;
TMOD=0x11;
TH0=0xd8;
TL0=0xf0;
EA=1;
ET0=1;
TR0=1;
}
void main()
{
init();
while(1){
if(s==0){
delay(5);
if(s==0){
TR0=0;
dis();
}
}
if(s2==0){
delay(5);
if(s2==0){
TR0=1;
dis();
}
}
if(s3==0){
delay(5);
if(s3==0){
TR0=1;
shu=0;
dis();
}
}
dis();
}
}
void time0() interrupt 1
{
TH0=0xd8;
TL0=0xf0;
num++;
shu++;
999)
shu=0;
bai=shu/100;
shi=shu%100/10;
ge=shu%10;
}
void display(uchar ba,uchar sh,uchar g)
{
le=1;
P2=tablewe[1];
le=0;
le=1; P0
=tabledu[ba] ; le=0
;
delay(5); le=1; P0=tabledu[sh]; le=0; delay(5); le =1; P2=tablewe[3]; le = 0 ; le=1; , ge ) ; } }
void
delay
(uint a) {
uint i,j;
for ( j=a;j> 0 ; j--) for ( i = 250;i>0;i--
) ; }
Reference address:Microcontroller Learning - Independent Button 2
Solution: (C language programming)
#include
#include
#define uint unsigned int
#define uchar unsigned char
uchar bai,shi,ge,num;
uint shu;
sbit s=P1^0;
sbit s2=P1^1;
sbit s3=P1^2;
sbit le=P3^6;
void delay(uint a);
void dis();
void display(uchar ba,uchar sh,uchar g);
uchar code tabledu[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x89,0x86,0xc7,0xc7,0xc0,0xff};
uchar code tablewe[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x 7f};
void init()
{
}
void main()
{
}
void time0() interrupt 1
{
}
void display(uchar ba,uchar sh,uchar g)
{
Previous article:Microcontroller Learning - Independent Button 3
Next article:MCU learning - independent button P1^0
- 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
- China Chip Recruitment. Listed on Shanghai Science and Technology Innovation Board, focusing on the research and development of IoT wireless communication chips and solutions. Salary open + stock
- mRNA vaccine badge
- Generate compensation ramp
- TI's Ultrasonic Sensing Technology for Flow Measurement
- [Visible] Intangible necessities
- Purgatory Legend-RAM War.pdf
- AD19, making 3D animation, "The 3D Movie Panel is disabled in 2D" How to solve it?
- Guitar Shaped Audio PCB Amplifier
- 26 "Wanli" Raspberry Pi car - program startup
- Among the working modes of switching power supplies, which switching mode is both economical and affordable?