Single chip calculator design

Publisher:数据迷航者Latest update time:2013-04-02 Source: 51heiKeywords:MCU  Calculator  AT89S51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Experimental tasks

(1. When powered on, the display shows “0”

(2. When the button is pressed for the first time, "D1" is displayed; when it is pressed for the second time, "D1D2" is displayed; when it is pressed for the third time, "D1D2D3" is displayed. When all 8 are displayed, a "beep" tone is given when the button is pressed again.

2. Circuit diagram

Click to browse the next page

Figure 4.23.1

3. Hardware connection on the system board

(1. Connect the P1.0 port in the "MCU System" area to the SPK IN port in the "Audio Amplifier Module" area with a wire;

(2. Connect the P3.0-P3.7 ports in the "MCU System" area to the C1-C4 R1-R4 ports in the "4X4 Column Keyboard" area using an 8-core cable;

(3. Connect the P0.0-P0.7 ports in the "MCU System" area to the A-H ports in the "Dynamic Digital Display" area using an 8-core cable;

(4. Connect the P2.0-P2.7 ports in the "MCU System:" area to the S1-S8 ports in the "Dynamic Digital Display" area using an 8-core cable;

4. Related programming content

(1. Determinant keyboard input and key function setting;

(2. Dynamic digital display;

(3. Digital display processing;

5. Assembly source program

(slightly)

6. C language source program

#include

unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,

0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};

unsigned char code dispbitcode[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

unsigned char dispbuf[8]={0,16,16,16,16,16,16,16};

unsigned char dispbitcount;

unsigned char temp;

unsigned char i,j;

unsigned char key;

unsigned char keypos;

bit alarmflag;

void change(unsigned char *p,unsigned char count)

{

  while(count>0)

    {

      *(p+count)=*(p+count-1);

      count--;

    }

} [page]

void main(void)

{

  TMOD=0x01;

  TH0=(65536-4000) / 256;

  TL0=(65536-4000) % 256;

  TR0=1;

  ET0=1;

  EA=1;

  while(1)

    {

      P3=0xff;

      P3_4=0;

      temp=P3;

      temp=temp & 0x0f;

      if (temp!=0x0f)

        {

          for(i=50;i>0;i--)

          for(j=200;j>0;j--);

          temp=P3;

          temp=temp & 0x0f;

          if (temp!=0x0f)

            {

              temp=P3;

              temp=temp & 0x0f;             

              switch(temp)

                {

                  case 0x0e:

                    key=7;

                    break;

                  case 0x0d:

                    key=8;

                    break;

                  case 0x0b:

                    key=9;

                    break;

                  case 0x07:

                    key=10;

                    break;

                }

              if ((key>=0) && (key<10))

              {

                keypos++;

                if(keypos<8)

                  {

                    change(dispbuf,keypos);

                    dispbuf[0]=key;

                  }

                  else

                    {

                      keypos=8;

                      alarmflag=1;

                    }

              }

              temp=P3;

              P1_0=~P1_0;

              temp=temp & 0x0f;             

              while(temp!=0x0f)

                {

                  temp=P3;

                  temp=temp & 0x0f;             

                }

              alarmflag=0;

            }

        }

      P3=0xff;

      P3_5=0;

      temp=P3;

      temp=temp & 0x0f;

      if (temp!=0x0f)

        {

          for(i=50;i>0;i--)

          for(j=200;j>0;j--);

          temp=P3;

          temp=temp & 0x0f;

          if (temp!=0x0f)

            {

              temp=P3;

              temp=temp & 0x0f;             

              switch(temp)

                {

                  case 0x0e:

                    key=4;

                    break;

                  case 0x0d:

                    key=5;

                    break;

                  case 0x0b:

                    key=6;

                    break;

                  case 0x07:

                    key=11;

                    break;

                }

              if ((key>=0) && (key<10))

              {

                keypos++;

                if(keypos<8)

                  {

                    change(dispbuf,keypos);

                    dispbuf[0]=key;

                  }

                  else

                    {

                      keypos=8;

                      alarmflag=1;

                    }

              }

              temp=P3;

              P1_0=~P1_0;

              temp=temp & 0x0f;             

              while(temp!=0x0f)

                {

                  temp=P3;

                  temp=temp & 0x0f;             

                }

              alarmflag=0;

            }

        } [page]

      P3=0xff;

      P3_6=0;

      temp=P3;

      temp=temp & 0x0f;

      if (temp!=0x0f)

        {

          for(i=50;i>0;i--)

          for(j=200;j>0;j--);

          temp=P3;

          temp=temp & 0x0f;

          if (temp!=0x0f)

            {

              temp=P3;

              temp=temp & 0x0f;             

              switch(temp)

                {

                  case 0x0e:

                    key=1;

                    break;

                  case 0x0d:

                    key=2;

                    break;

                  case 0x0b:

                    key=3;

                    break;

                  case 0x07:

                    key=12;

                    break;

                }

              if ((key>=0) && (key<10))

              {

                keypos++;

                if(keypos<8)

                  {

                    change(dispbuf,keypos);

                    dispbuf[0]=key;

                  }

                  else

                    {

                      keypos=8;

                      alarmflag=1;

                    }

              }

              temp=P3;

              P1_0=~P1_0;

              temp=temp & 0x0f;             

              while(temp!=0x0f)

                {

                  temp=P3;

                  temp=temp & 0x0f;              

                }

              alarmflag=0;

            }

        }

      P3=0xff;

      P3_7=0;

      temp=P3;

      temp=temp & 0x0f;

      if (temp!=0x0f)

        {

          for(i=50;i>0;i--)

          for(j=200;j>0;j--);

          temp=P3;

          temp=temp & 0x0f;

          if (temp!=0x0f)

            {

              temp=P3;

              temp=temp & 0x0f;             

              switch(temp)

                {

                  case 0x0e:

                    key=0;

                    break;

                  case 0x0d:

                    key=13;

                    break;

                  case 0x0b:

                    key=14;

                    break;

                  case 0x07:

                    key=15;

                    break;

                }

              if ((key>=0) && (key<10))

              {

                keypos++;

                if(keypos<8)

                  {

                    change(dispbuf,keypos);

                    dispbuf[0]=key;

                  }

                  else

                    {

                      keypos=8;

                      alarmflag=1;

                    }

              }

              temp=P3;

              P1_0=~P1_0;

              temp=temp & 0x0f;             

              while(temp!=0x0f)

                {

                  temp=P3;

                  temp=temp & 0x0f;             

                }

              alarmflag=0;

            }

        }

    }

}

void t0(void) interrupt 1 using 0

{

  TH0=(65536-4000) / 256;

  TL0=(65536-4000) % 256;

  P0=dispcode[dispbuf[dispbitcount]];

  P2=dispbitcode[dispbitcount];

  dispbitcount++;

  if (dispbitcount==8)

    {

      dispbitcount=0;

    }

  if (alarmflag==1)

    {

      P1_1=~P1_1;

    }

}

Keywords:MCU  Calculator  AT89S51 Reference address:Single chip calculator design

Previous article:Design of single chip digital clock
Next article:DS18B20 Digital Thermometer Microcontroller Interface Application

Recommended ReadingLatest update time:2024-11-16 22:42

A feasible EMS technology method for single chip microcomputer system
  EMC electromagnetic compatibility includes EMI (interference) and EMS (susceptibility), that is, electromagnetic interference and electromagnetic interference resistance. The single-chip system used in the production site is susceptible to various electromagnetic interferences, which directly affect the reliability o
[Microcontroller]
[MCU framework][OS layer] FreeRTOS middleware public functions
Repackage the freertos function to adapt to RTX4 /RTX5 / FREERTOS_NRF_RTC. FreeRTOS is a class of RTOS designed to be small enough to run on microcontrollers—although its use is not limited to microcontroller applications. A microcontroller is a small, resource-constrained processor that integrates the processor i
[Microcontroller]
Microcontroller drives buzzer C51 program
#include reg51.h #include intrins.h #include absacc.h #define uchar unsigned char #define uint unsigned int sbit k1=P1^4; //Button 1 sbit k2=P1^5; //Button 2 sbit beep=P3^7; //Connect buzzer /************************************************************ This program
[Microcontroller]
A discussion on the “screen erasure” of digital display controlled by microcontroller
Among the many CNC and digital display intelligent devices, a large part work day and night (such as intelligent street light clock controllers in the power department, intelligent temperature controllers in dry-type transformers, etc.). In this way It has a great impact on the service life of digital display componen
[Power Management]
51 MCU: Use ADC0832 to do analog-to-digital conversion and measure voltage
Question Requirements Using 51 single chip microcomputer and an ADC0832 analog-to-digital converter, design a circuit that can measure voltage in real time. The measurement voltage range is 0-5V (allowable error), and the measured voltage is required to be displayed in real time with a digital tube, accurate to two de
[Microcontroller]
51 MCU: Use ADC0832 to do analog-to-digital conversion and measure voltage
Using single chip microcomputer to simulate 2272 software decoding
In the field of wireless remote control, PT2262/2272 is one of the most commonly used chips. However, the chip requires to be used in pairs, which greatly affects the use of the chip. Starting from the waveform characteristics of PT2262 and combining with the actual application, the author proposes software decoding
[Microcontroller]
Design of single chip microcomputer for sending and receiving short messages
0 Introduction The GSM (Global System for Mobile communication) system is a relatively mature, complete and widely used system in the current mobile communication system based on time division multiple access technology. The GSM digital cellular mobile communication network that has been built to cover the whole cou
[Microcontroller]
Design of single chip microcomputer for sending and receiving short messages
How to use MCU to improve the performance of automotive design
Introduction In today's automobile design, people are paying more and more attention to the two aspects of intelligence and environmental protection. Because intelligent cars can bring people a high degree of safety and comfort, in terms of environmental protection, the use of digital technology can achieve the goal o
[Microcontroller]
How to use MCU to improve the performance of automotive design
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号