#include #define uchar unsigned char #define uint unsigned int sbit gewei0=P1^6; //Allow units digit display. sbit shiwei0=P1^7; //Allow tens digit display. sbit key1=P1^2; //Key 1, each press adds 10 minutes. sbit key2=P1^1; //Key 2, each press adds 1 minute. sbit key3=P1^0; //Key 3, start countdown or pause. sbit beep=P1^3; //buzzer sbit led=P1^4; //second indicator light sbit jdq=P3^4; //relay uchar k; unsigned int s,m; void delayms(uchar); void delay(uint z); void keyscan(); void display(uchar); void init(); void xiang1(); void xiang2(); uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void main() { init(); //Call "initialization". while(1) { keyscan(); //Adjust "monitoring keys". display(k); //Adjust "display". }} void keyscan() //Monitor keys. { if(key20) { delayms(26); if(key20) { k++; if(k>=99) //k==99 is consistent with the interrupt. k=0; while(!key2); //When key2 is released, the result of k+2 is displayed. } } if(key10) { delayms(26); if(key10) { k=k+10; if(k>=99) //k99 is consistent with the interrupt. k=0; while(!key1); } } if(key30) { delayms(26); if(key3==0) { xiang1(); //Start the "countdown" prompt. delayms(246); TR0=~TR0; jdq=~jdq; //Relay status flips with the start/stop button while(!key3); }}} void delayms(uchar z) //delay. { uchar i,j; for(i=z;i>0;i–) for(j=110;j>0;j–); } void delay(uint z) { while(z–); } void display(uchar k) //Display. { uchar shi,ge; shi=k/10; ge = k%10; gewei0=0; P2=table[ge]; delayms(21); gewei0=1; shiwei0=0; P2=table[shi]; delayms(21); shiwei0=1; } void init() // Initialization. Set the interrupt and timer values. { TMOD = 0x01; TH0=(65536-50000)/256; //Crystal oscillator 12MHz, timing 50ms. TL0=(65536-50000)%256; EA=1; ET0=1; } void xiang1() //Timer starts prompt tone. {undefined uchar q; for(q=0;q<100;q++) {undefined beep=0; delayms(6); beep=1; delayms(4); } delayms(64); } void xiang2() //Timeout reminder sound – beep. {undefined unsigned int m; uchar n,i; for(i=3;i>0;i–) {undefined for(n=123;n>0;n–) {undefined beep=0; delay(100); beep=1; delay(100); } for(m=3456;m>0;m–); for(n=123;n>0;n–) {undefined beep=0; delay(90); beep=1; delay(90); } 1 for(m=56789;m>0;m–); } } void time0()interrupt 1 //0 interrupt, interrupt number 1. { uint zxc=65432; TH0=0xb1; //Crystal oscillator 12MHz, timing 20ms. TL0=0xe0; s++; if(m25) //Indicate seconds. { m=0; led = ~led;} m++; //uchar m; defined as a global variable. if(s3000) //3000×20ms=60000ms÷1000ms=60s(1 minute) { s=0; //Reset to zero. Wait for the next 1 minute. k–; } //Countdown, minus 1 minute. if(k<=0) //If it reaches 0, make a sound and turn off the interrupt. {undefined k=0; xiang2(); TR0=0; //When the scheduled time is up, turn off interrupt 0 and stop. jdq=1; //Relay release }}
Previous article:Single chip incandescent lamp dimming program
Next article:C51 single chip microcomputer independent button
- Popular Resources
- Popular amplifiers
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
- [Mill Edge AI Computing Box FZ5 Review] EasyDL realizes the construction of flower classification and recognition network
- Design examples + a little error for new students to learn from
- Code Analysis of Event Kernel in RSL10 SDK (Part 2)
- Noise conditions and countermeasures in 5G communication environment
- A complete solution for testing, modeling and verification of GaN RF power devices
- Rental housing accidents happen frequently, how can we solve them thoroughly?
- [Chuanglong Technology Allwinner A40i Development Board] C and Python Development Experience
- How should ferrite beads be used and how should they be selected for gate drive circuits?
- TriQuint and RFMD have merged to form Qorvo, a new global leader in RF solutions.
- Summary of wifi7 popular science posts