I
计算器一般是指“电子计算器”,能进行数学运算的手持机器,拥有集成电路芯片,
结构简单,功能较弱,但由于它使用方便、操作简单、价格低廉,因而广泛运用于
商业交易中,也是必备的办公用品。
近年来随着科技的飞速发展,单片机的应用正在不断深入,同时带动传统控制
检测技术日益更新。在实时检测和自动控制的单片机应用系统中,单片机往往作为
一个核心部件来使用,但仅单片机方面的知识是不够的,还应根据具体硬件结构、
软硬件结合,来加以完善。因此,单片机的应用已经越来越贴近生活,用单片机来
实现一些电子设计也变得容易起来。计算器在人们的日常中是比较的常见的电子产
品之一。可是它还在发展之中,以后必将出现功能更加强大的计算器,基于这样的
理念,本次设计是用单片机来设计的计算器。该设计系统是以 AT89S52 为单片机,
P1 口作为输入端,外接 4X4 的键盘。通过键盘扫描来对输入数的控制,在 P0 口、
P2 口接了驱动电路,用来保证 LCD 的工作正常。计算器将完成的功能有加,减,
乘,除等功能。
关键词:计算器;单片机;LCD;矩阵键盘
II
ABSTRACT
Calculator generally refers to the electronic calculator, and the term is introduced to
China by the Japanese. The calculator with the IC chip, simple structure, and weak
function is able to perform mathematical operations on handheld machine. But it is easy
using, simple operation and low price. So it is widely used in commercial transactions, and
is also an essential office supplies.
With the rapid development of science and technology in recent years, the application
of SCM is the deepening and promote the traditional controlling detection technologies
that are increasingly updated. In real-time detection and automatic control of
microcomputer application system, the microcontroller is often used as a core component
to use, but only the knowledge of the microcontroller is not enough, and should be based
on the specific hardware architecture, hardware and software combination to make it
perfect. So the application of SCM is more and more close to life, so using of single chip
to achieve some electronic designs also become easy. In the people daily life the calculator
is one of the common electronic products. But it is still in development, it will become
more powerful calculator in the future. According to such idea, the design is that SCM
design calculator. The design system is based on AT89S52 microcontroller, P0 port as
input, external 4X4 keyboard. In P1, P2mouth is connected with the drive circuit to ensure
the normal work of LED. The calculator will complete add, subtract, multiply, divide and
other function.
Keywords: calculator, MCU, LCD, Matrix keyboard
III
前 言
计算器(calculator;counter)一般是指“电子计算器”,能进行数学运算的手持机
器,拥有集成电路芯片,结构简单,功能较弱,但由于它使用方便、操作简单、价
格低廉,因而广泛运用于商业交易中,也是必备的办公用品之一。计算器一般由运
算器、控制器、存储器、键盘、显示器、电源和一些可选外围设备及电子配件通过
人工或机器设备组成。随着科学技术的不断发展及计算器应用的普及,人们发现在
工业控制中,有很多时候需要在恶劣的环境中进行各种数据的采集、运算和控制。
本设计是由单片机实现的模拟计算器,它不仅能实现数据的加减乘除运算,而且还
能使数据及其计算结果在数码管上显示出来,能够实现 0-256 的数字四则运算。本设
计是用单片机 AT89S52 来控制,采用 LCD1602 液晶显示读取数据,软件部分是由 C
语言来编写的。利用键盘和 LCD1602 设计一个简单的数学计算器,可以完成简单的
如加,减,乘,除的四则运算,并将运算结果在 LCD1602 上显示出来。
I
目 录
第一章 绪论..............................................................................................................................................1
1.1 研究背景......................................................................................................................................1
1.1.1 单片机发展现状...............................................................................................................1
1.1.2 计算器系统现状...............................................................................................................2
1.1.3 选题意义及现状...............................................................................................................2
第二章 总体方案及设计..........................................................................................................................3
2.1 设计目的......................................................................................................................................3
2.2 设计任务......................................................................................................................................3
2.3 设计思路......................................................................................................................................3
2.3.1 方案构思...........................................................................................................................3
2.3.2 方案比较与选择............................................................................................................4
2.3.3 系统总体模块图...............................................................................................................4
第三章 系统硬件设计..............................................................................................................................5
3.1 主控模块设计.............................................................................................................................5
3.2 键盘输入模块设计....................................................................................................................11
3.3 LCD 显示模块设计...................................................................................................................12
3.3.1 LCD1602 主要技术参数...............................................................................................13
3.3.2 引脚功能说明...............................................................................................................13
3.4 清零、音乐开关、开方和多次方运算功能模块设计............................................................14
3.5 电源模块设计............................................................................................................................15
3.6 运算模块(单片机控制).......................................................................................................16
第四章 软件设计....................................................................................................................................17
4.1 显示程序设计............................................................................................................................17
4.2 键扫程序设计............................................................................................................................17
4.3 清零程序设计............................................................................................................................19
4.4 声音开关程序设计....................................................................................................................20
4.5 总体设计....................................................................................................................................21
第五章 系统仿真....................................................................................................................................23
5.1 Proteus 仿真...............................................................................................................................23
第六章 系统调试....................................................................................................................................27
6.1 问题与分析................................................................................................................................27
6.1.1 硬件常见故障.................................................................................................................27
6.1.2 软件调试.........................................................................................................................27
第七章 总结与展望................................................................................................................................30
7.1 总结............................................................................................................................................30
7.2 展望............................................................................................................................................30
致谢..........................................................................................................................................................35
参考文献..................................................................................................................................................32
附录..........................................................................................................................................................33