Infrared tax calculator based on single chip microcomputer

Publisher:QingfangLatest update time:2012-08-31 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

#include   
unsigned 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;   
}
Keywords:MCU Reference address:Infrared tax calculator based on single chip microcomputer

Previous article:Text code of homemade bootloader
Next article:DIY 1602 clock with adjustable display

Recommended ReadingLatest update time:2024-11-16 16:37

What is the direction of general-purpose MCUs in the future?
Source: 21ic Electronic Network   At the 2023 STM32 Summit, look at the future development direction of general MCUs. Since the release of the STM32F1, the first chip of the STM32 family, in 2007, ST has embarked on a legendary journey in the field of general-purpose MCUs. From 1 billion in 2013, 6 billion in 2020
[Embedded]
What is the direction of general-purpose MCUs in the future?
Design of universal industrial wireless remote control system based on single chip microcomputer and PLC
     1. Introduction     Industrial wireless remote control system can digitally process the control instructions of the operator or machine, transmit them to the remote receiving system through the transmitting system, and then convert them into control instructions through decoding to realize the control of variou
[Microcontroller]
Design of universal industrial wireless remote control system based on single chip microcomputer and PLC
Temperature control system circuit design based on ATmega16L microcontroller
Introduction: Design a temperature control system based on ATmega16L microcontroller, and explain the hardware design of the system. Adopt modular design method and use incremental PID algorithm to make the temperature value of the controlled object tend to the given value. main controller The main controller of t
[Microcontroller]
Temperature control system circuit design based on ATmega16L microcontroller
The second lesson of the C language tutorial for single-chip microcomputers: a preliminary understanding of the 51 chip
In the last lesson, our first project was completed. Some friends who know C language may say, "This is not much different from the C language on the PC." Indeed, there is not much difference. C language is just a general term for a programming language. There will be some details of the C language related to different
[Microcontroller]
The second lesson of the C language tutorial for single-chip microcomputers: a preliminary understanding of the 51 chip
Design of communication and data management system software based on 89C51 microcontroller and VB5.0
1 Introduction With the continuous development of communication technology, computer network system communication is an important direction of today's technological development. However, using the existing telephone network as the communication channel in the network system is the most economical, convenient and relia
[Microcontroller]
Design of communication and data management system software based on 89C51 microcontroller and VB5.0
Circuit Design of Robot System Based on Single Chip Microcomputer
The programming mode of AT89S51 can be divided into parallel mode and serial mode. As the parallel port has been gradually eliminated in current PC desktops and notebooks, the parallel port programmer has been gradually eliminated. The ISP programmer using the USB interface is more suitable for experimental use. The c
[Microcontroller]
Circuit Design of Robot System Based on Single Chip Microcomputer
Frequency Measurement Technology Based on 8051 Single Chip Microcomputer
0Introduction With the development and popularization of radio technology, "frequency" has become a physical quantity familiar to the general public. The emergence of single-chip microcomputers has brought many major leaps in various measurement technologies, including frequency measurement. However, advantages
[Microcontroller]
Frequency Measurement Technology Based on 8051 Single Chip Microcomputer
Make a good MCU 89C51 programmer according to the crooked circuit diagram
Last time I used the 89C51 microcontroller , the K1200 programmer had some problems. I didn't know whether it was the programmer or the microcontroller that had problems, so I made a simple 89C51 programmer myself, mainly because I didn't want to spend any money and used local materials. The circuit diagram was refere
[Power Management]
Make a good MCU 89C51 programmer according to the crooked circuit diagram
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号