Summary:
First, I wanted to do it right from the beginning, but I didn’t know where the error occurred.
Second, because we went in the wrong direction at the beginning, it took a long time.
Third, since I can’t debug, I don’t know how to check where the error is.
Fourth, I wrote sub-functions and called them one by one later.
5. Because I called the POW function at the beginning, I don’t know why this function took up a lot of space, causing the program to respond very slowly
Not to mention, because the code is a bit long, it can't be compiled. It took a long time to find the reason. Later, I had to write a function myself, so in the future
Try not to call functions randomly, and write your own code if you can.
Final summary: First, modularize the tasks and start with the simplest.
Second, you must think it through before you start typing.
Third, the most important thing is to pay attention to details. Since the maximum input value exceeds 65535, when I call the function, it returns an int.
As a result, I still don't know where the error is. If it is a variable, I should easily think of overflow, but this is the first time I have encountered overflow of function return value. Download address of the complete version of this program: http://www.51hei.com/f/suishoujisu.rar
//This MCU's infrared is directly connected to external interrupt 1 to input your salary via infrared, and then calculate the tax you have to pay through the tax formula //Press external interrupt 0 to indicate that the input is completed
#includeunsigned a[5],b[5],flag; unsigned char table[]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; int wei; long temp=0 ; double recond; sbit hwx=P3^3; //define infrared receiving pin, char cout; unsigned char l_lhj[66] ; //Define a 66-bit array variable to store the received time parameters void delay (void) //5 empty instructions { unsigned char i=13; while(i) i--; } void delay1() { int i=100 ; while(i--); } long power( int i) //10 to power i function { long sum=1; unsigned char j; for(j=0;j=2) { for(i=0;i =cout-1) break; P1++; } } void main() { EA=1; EX0=1; EX1=1; IT0=1; IT1=1; while(1) { if(flag==0) show(); else { display(); //Display integer displayf(); //Display decimals } } } void zhongduan() interrupt 0 { flag++; intandfloat(); //separate integers and decimals tax(); //Tax function chuli(temp); //Process integers EX0=0; } void hongwai(void) interrupt 2
//External interrupt 1, INT1 (P3^3) connects to the infrared receiving IC data pin { unsigned char i,j,tmp; unsigned int tmp2; EX1=0; // hwx=1; j=33; i=0; tmp2=0; while(!hwx){ tmp2++; if(tmp2==1000) break; } if(tmp2<1000){ //If the count is less than 1000, it is considered as interference and the reception is exited EX1=1; return; } //P2=0x76; //The digital tube output displays H as an indication of infrared reception while(j){ tmp=0; l_lhj[i]=1; while(!hwx){ //Detect changes in high and low levels l_lhj[i]++; //No change, continue to add 1 delay();
//The delay is added because we use 8-bit binary to store. If no delay is added, the time will be full. tmp++; //This variable is used to prevent dead loop caused by interference if(tmp==250) break; } i++; tmp=0; l_lhj[i]=1; //Time starts from 1 while(hwx){ //Detect changes in high and low levels l_lhj[i]++; //No change, continue to add 1 delay(); //same as above tmp++; if(tmp==250) break; } i++; j--; } i=255; //Add loop delay to process data while(i){ tmp=255; while(tmp){ P2=0XF0; tmp--; } i--; } tmp=0; //All four segments of code are shown here, including two segments of address bits and two segments of control bits, each segment is separated by a dot for(i=35;i<51;i++,i++) // Same as above, here we process the first 8 bits of the control bit { tmp>>=1; if(l_lhj[i]>30) tmp+=0x80; } b[cout]=tmp%16; cout++; EX1=1; }
Previous article:Text code of homemade bootloader
Next article:DIY 1602 clock with adjustable display
Recommended ReadingLatest update time:2024-11-16 16:37
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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
- What basics are needed to learn programming?
- [National Technology N32G457 Review] Implementation of Environmental Status Detection Device
- [BearPi-HM Nano, play Hongmeng "Touch and Go"] Part 2: Setting up the environment is so simple
- Failed to set default vias in Altium Designer?
- ESP8266 most complete application documentation
- LED light flickering problem, help
- Realization of various wavelet transforms based on FPGA
- Book a live broadcast with prizes: Enjoy purity - ams active noise reduction and proximity sensing bring a new level of headphone design
- Analog Front End AFE
- Is there any special way to route the wiring of this type of seat?