Super stopwatch, with timing function, pause function, timer function, it is super fun to use.
The microcontroller source program is as follows:
#ifndef _TM1638_H
#define _TM1638_H
#include #define DATA_COMMAND 0X40 #define DISP_COMMAND 0x80 #define ADDR_COMMAND 0XC0 //TM1638 module pin definition sbit DIO=P1^0; sbit CLK=P1^1; sbit STB=P1^2; //Common cathode digital tube display code unsigned char code tab[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07, 0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71}; void TM1638_Write(unsigned char DATA) //Write data function { unsigned char i; for(i=0;i<8;i++) { CLK=0; if(DATA&0x01) { PART=1; } else { PART=0; } CLK=1; DATA>>=1; } } unsigned char TM1638_Read(void) // read data function { unsigned char i; unsigned char temp=0x00; PART=1; for(i=0;i<8;i++) { temp>>=1; CLK=0; if(DIO) { temp|=0x80; } else { temp&=0x7f; } CLK=1; } return temp; } void Write_COM(unsigned char cmd) //Send command word { STB=0; TM1638_Write(cmd); STB=1; } unsigned char Read_key() { unsigned char Key[4],i,Keyvalue=0; STB=0; // Write_COM(0x42); TM1638_Write(0x42); for(i=0;i<4;i++) { Key[i]=TM1638_Read(); } STB=1; for(i=0;i<4;i++) { Keyvalue|=Key[i]< } for(i=0;i<8;i++) { if((0x01< {break;} } return i; } /* unsigned char Read_key(void) { unsigned char c[4],i,key_value=0; STB=0; TM1638_Write(0x42); //Read key scan data command for(i=0;i<4;i++) c[i]=TM1638_Read(); STB=1; //4 bytes of data are combined into one byte for(i=0;i<4;i++) key_value|=c[i]< for(i=0;i<8;i++) if((0x01< break; return i; } */ void Write_DATA(unsigned char add,unsigned char DATA) //Write data to the specified address { Write_COM(0x44); STB=0; TM1638_Write(0xc0|add); TM1638_Write(DATA); STB=1; } /* void Write_oneLED(unsigned char num,unsigned char flag) //Control a LED function individually, num is the LED number to be controlled, flag is off when 0, and is on when not 0 { if(flag) Write_DATA(2*num+1,1); else Write_DATA(2*num+1,0); } */ void Write_allLED(unsigned char LED_flag) //Control all LED functions, LED_flag indicates the status of each LED { unsigned char i; for(i=0;i<8;i++) { if(LED_flag&(1< //Write_DATA(2*i+1,3); Write_DATA(2*i+1,1); else Write_DATA(2*i+1,0); } } //TM1638 initialization function void init_TM1638(void) { unsigned char i; Write_COM(0x8b); //Brightness (0x88-0x8f) 8 levels of brightness adjustable Write_COM(0x40); //Add address automatically plus 1 STB=0; // TM1638_Write(0xc0); //Set the starting address for(i=0;i<16;i++) //Transmit 16 bytes of data TM1638_Write(0x00); STB=1; } #endif Copy code #include #include "tm1638.h" #define u16 unsigned int #define u8 unsigned char /* The requirements for making a stopwatch are: a. It can measure at least 10 minutes with an accuracy of 0.01s and display the current time in real time on the digital tube; b. Press S1 to start timing; press S2 to pause/start; press S3 to end timing; c. (Optional) Add a mode selection key and a number input key, which can be pressed to switch between timing mode and setting mode. In the setting mode, you can set a time (using the keys to enter). When you switch back to the timing mode, the buzzer will sound when the set time is reached. */ u16 TIMERBAT=0; bit flag=0; u8 state=0; //0: not started timing or paused 1: started timing 2: set mode u8 hym; //key code control void Timer0Init(void); void Display(); void Set_Bell(); void Clock_System(); void CLR_Time(); void CLRBell(); bit Judge_Baba(); u8 code distab[17] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40}; u8 shijian[5]; //0 Dad 1 second 2 minutes 3 hours u8 shijianshezhi[4]; //0 seconds 1 minute 2 hours void main() { init_TM1638(); Timer0Init(); flag=0; while(1) { if(state==2) { Set_Bell(); } else { Clock_System(); } } } void Set_Bell() { TR0=0; while(state==2) { hym=Read_key(); if(hym!=8) { switch(hym) { case 3:state=0;break; case 4:shijianshezhi[2]++;shijianshezhi[2]%=24;break; case 5:shijianshezhi[1]++;shijianshezhi[1]%=60;break; case 6:shijianshezhi[0]++;shijianshezhi[0]%=60;break; case 7:CLRBell();break; } while(Read_key()==hym); } Display(); } } void Clock_System() { while(state!=2) { TR0=state; hym=Read_key(); if(hym!=8) { switch(hym) { case 0:state=1;break; case 1:if(state==1){state=0;} else{state=1;}break; case 2:state=0;CLR_Time();break; case 3:state=2;break; } while(Read_key()==hym); } if(flag) { flag=0; shijian[0]++; } if(shijian[0]==100) { shijian[0]=0; shijian[1]++; } if(shijian[1]==60) { shijian[1]=0; shijian[2]++; } if(shijian[2]==60) { shijian[2]=0; shijian[3]++; shijian[3]%=24; } Display(); if(Judge_Baba()) { Write_allLED(0xff); } else { Write_allLED(0x00); } } } void CLR_Time() { u8 i; for(i=0;i<4;i++) { shijian[i]=0; ……………………
Previous article:HT1621 display driver chip MCU source code
Next article:Production of 5*4 matrix keyboard calculator with single chip microcomputer
- 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
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- Recruitment of part-time MCU software programming
- A brief tutorial on DSP interrupt settings
- Application of MSP430F415 in LCD air conditioner infrared remote control
- Please tell me why the 5V can't be turned off in this picture
- Transimpedance
- Allegro display problem
- Can Tantalum Capacitors Replace MLCC?
- Design of USB interface based on DSP
- Power relay contacts sticking
- Teach you step by step how to operate a multimeter!