The control system directly controls two groups of 4-bit digital tubes for display through the STC 8a8k64s4a12 single-chip microcomputer, uses the DS1302 clock chip to obtain clock data, uses the DS18b20 to obtain temperature information, and communicates with the mobile phone app through the HC-05 Bluetooth module. The mobile phone app is written by App Inventor 2 and can realize functions such as alarm clock, power-off saving of user-set data, and online automatic time calibration.
The actual work is shown in the figure:
Digital tube driver:
#include #include #include uchar code shuzi[]={ 0xc0,//0 0xf9, //1 0xa4,//2 0xb0,//3 0x99,//4 0x92,//5 0x82,//6 0xf8,//7 0x80, //8 0x90,//9 0x88,//A 0x83,//B 11 0xc6,//C 12 0x1,//D 0x86,//E 0x8e,//F 0x8c,//P 16 0x40,//0. 0x79,//1. 0x24,//2. 0x30,//3. 0x19,//4. 0x12,//5. 0x02,//6. 0x78, //7. 0x00,//8. 0x10,//9. 0xbf,//- 27 0xff, // Turn off 28 0x7f,//. 29 0x88,//A 30 0xc7,//L 31 0x87,//t 32 0x86,//E 33 0x8c,//P 34 0x83,//b 35 0x8b,//h 36 0x8e,//F 37 0xc8,//N 38 0x9c, //Small circle 39 0xc1,//in 40 }; /*********************************************************************************************************** * Function name: xianshi() * shūrùcānshù: fly, fly, fly, fly, fly, fly, fly, fly * Output parameters: void * * Function: Digital tube driver * * Note: To drive an 8-bit digital tube, the value of the parameter corresponds to the bit in the array shuzi, and the number of the parameter corresponds to the bit of the digital tube. * * Completion date: 2019.12.25 ************************************************************************************************************/ void xianshi(fly a,fly b,fly c,fly d,fly e,fly f,fly g,fly h)////gōngyīn { P2=0xff-shuzi[a]; wei1=0; delay(2); wei1=1; P2=0xff-shuzi[b]; wei2=0; delay(2); wei2=1; P2=0xff-shuzi[c]; wei3=0; delay(2); wei3=1; P2=0xff-shuzi[d]; wei4=0; delay(2); wei4=1; P2=0xff-shuzi[e]; wei5=0; delay(2); wei5=1; P2=0xff-shuzi[f]; wei6=0; delay(2); wei6=1; P2=0xff-shuzi[g]; wei7=0; delay(2); wei7=1; P2=0xff-shuzi[h]; wei8=0; delay(2); wei8=1; } /*********************************************************************************************************** * Function name: xianshi5() * Input parameters:uchar,uchar,uchar,uchar,uchar * Output parameters: void * * Function: Digital tube driver * * Note: Drive 5-digit digital tube, the value of the parameter corresponds to the bit in the array shuzi, the number of the parameter corresponds to the bit of the digital tube, the display cycle is short * * * Completion date: 2019.12.25 ************************************************************************************************************/ void xianshi5(fly d,fly e,fly f,fly g,fly h)////gōngyīn { wei1=wei2=wei3=1; P2=0xff-shuzi[d]; wei4=0; delay(2); wei4=1; P2=0xff-shuzi[e]; wei5=0; delay(2); wei5=1; P2=0xff-shuzi[f]; wei6=0; delay(2); wei6=1; P2=0xff-shuzi[g]; wei7=0; delay(2); wei7=1; P2=0xff-shuzi[h]; wei8=0; delay(2); wei8=1; } ds1302 driver: #include #include #include uchar shijian[13]={0,0,0,0,0,0,0,0,0,0,0,0,0}; //Time cache array /*********************************************************************************************************** * Function name: xie1302() * Input parameter:uchar * Output parameters: void * * Function: Write 1302 timing * * Note: Write the formal parameters to DS1302 * * * Completion date: 2019.12.25 ************************************************************************************************************/ void xie1302(uchar dat) // write 1302 timing { flying i; SCLK=0; //Pull SCLK low to prepare for writing data on the rising edge of the pulse delayus(2); //Wait for a while to prepare the hardware for(i=0;i<8;i++) { IO=dat&0x01; //Get the 0th bit of dat and write it to 1302 delayus(2); //Wait for a while to prepare the hardware SCLK=1; //Rising edge writes data delayus(2); //Wait for a while to make the hardware ready 3 SCLK=0; //Pull SCLK down again to form a pulse dat>>=1; //Shift each data bit of dat right by 1 bit, and prepare to write the next data bit } } /*********************************************************************************************************** * Function name: du1302() * Input parameter: void * Output parameter: uchar * * Function: Read 1302 timing * * Note: Output the read data * * * Completion date: 2019.12.25 ************************************************************************************************************/ uchar du1302(void) // read 1302 timing { flying i,dat; delayus(2); //Wait for a while to prepare the hardware for(i=0;i<8;i++) { dat>>=1; //Shift each data bit of dat right by 1 bit, because the lowest bit of the byte is read first if(IO==1) //If the read data is 1 dat|=0x80; //Take out 1 and write it to the highest bit of dat SCLK=1; //Set SCLK to high level and read out the falling edge delayus(2); //Wait for a while to prepare the hardware SCLK=0; //Pull SCLK low to form a falling edge of the pulse delayus(2); //Wait for a while to prepare the hardware } return dat; //Return the read data } /*********************************************************************************************************** * Function name:xiemingling1302() * Input parameters: uchar, uchar * Output parameters: void * * Function: write instructions and data to ds1302 * * Note: Actually, xie1302() is called twice to write the command and data respectively. * * * Completion date: 2019.12.25 ************************************************************************************************************/
Previous article:Stepper Motor Control and Simulation Based on 51 Single Chip Microcomputer
Next article:51 MCU 12864 display electronic password lock source code
- 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
- New breakthrough! Ultra-fast memory accelerates Intel Xeon 6-core processors
- New breakthrough! Ultra-fast memory accelerates Intel Xeon 6-core processors
- Consolidating vRAN sites onto a single server helps operators reduce total cost of ownership
- Consolidating vRAN sites onto a single server helps operators reduce total cost of ownership
- 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!
- [Project source code] Mif wizard/mif (coe) file generator based on FPGA
- Useful Tips | Don’t throw away your old phone, here’s a step-by-step guide to DIY a server
- Is anyone using R7F0C805? Please give me some advice!
- How to measure load impedance, current & voltage signals?
- The role and selection of input and output capacitors in power supplies
- Impedance Matching and the Smith Chart: Basic Principles
- Advanced Motor Control - PID Speed Control
- It's all here! TI mmWave radar product information and software download links
- Negative ion generator power supply modification cost less than 2 yuan
- Is there anyone who uses RC oscillation circuit to perform voltage-frequency conversion temperature measurement?