毕业设计(论文)-基于51单片机的双精度电子称设计

更新时间:2023-11-05 04:04:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

毕业设计(论文)

基于51单片机的双精度电子称设计

系 别 专业名称 班级学号 学生姓名 指导教师

自动化工程系 测控技术与仪器

2012年6月15日

东北大学秦皇岛分校毕业设计(论文) 第 I 页 基于51单片机的双精度电子称设计

摘 要

随着数字化技术的快速发展和应用,电子衡器称重技术同样也得到了广泛的发展和应用,各种数字化智能化的电子衡器逐渐问世,但商用电子称作为电子衡器的重要一部分,在中小型市场的智能化并没有得到普及,依然以杆秤、台秤和简易电子称为主的商用电子秤,存在着精度差、易损坏、难维修等缺陷,尤其是在进行轻微物体如茶叶、药材等的测量时误差更明显。

本文设计的双精度电子称主要以AT89S52单片机为核心,通过Proteus软件和KEIL软件实现了对电子称的功能仿真设计。主要分为五个模块:双精度的物体重量采集模块、单片机处理模块、键盘控制模块、数据显示模块以及软件驱动模块。以不同压力传感器采集压力参数,经过信号处理和A/D转换送给单片机,单片机通过重量参数自动选择12位精度值或8位精度值进行运算处理,最终将键盘输入的单价值和总价值在LCD12864液晶上进行实时显示。整个电子称系统能够智能化的实现双精度自动测量、自动报警、直观显示等功能,具有操作方便,双精度测量准确,成本低、稳定性可靠性高等特点,可以更好的应用于不同的应用场合,适应了中小型市场的需求。 关键词:双精度电子称,单片机 AT89S52,称重传感器,A/D转换,液晶显示器

东北大学秦皇岛分校毕业设计(论文) 第 II 页

Said design based on 51 single-chip double-precision electronic

Author:Jin Shan

Tutor:Qi Shiqing

Abstract

With the rapid development and application of digital technology, electronic weighing technology has been developed and applied extensively .And a variety of intelligent digital electronic weighing is emerging progressively, but in small and middle market, the commercial electronics, which is an important part of the electronic weighing, is still limited to the simple electronics said such as steelyard, platform scales and simple electronics. All these are known as the main commercial electronic scales, but the existence of accuracy, easily damage, and difficult to repair defects also affect itself. Especially during weighing some minor objects such as tea, medicinal herbs, mistakes is easy to appearance through measuring. This paper, the design of the double-precision electronic using microcontroller AT89S52 as the core, achieve the simulation capabilities of electronic design by using Proteus Software and KEIL software. Now dividing this paper into five main modules: how to collect the weight of the object with this double-precision electronic said module, how to deal with the data through single-chip machine, how to control keyboard module, the display module and how to drive software module. Fristly, use different pressure sensor to acquire pressure parameters. Secondly the signal processor and A / D conversion work out the data, finally given to the MCU. Thridly according to the data above the MCU will automatically select whether the 12 precision values or 8 precision value computing processor. Ultimately the input through the keyboard will be showed on the LCD12864 real-time display. The entire electronic system can intelligently accomplish double-precision measurement automatically, automatic alarm, visual display, at the same time, it’s easy to operate, accurate measurement, low cost, stability and high reliability. Based on the introduction above ,it can be used in different applications occasions, and it can adapt to the needs of small and medium-sized market.

Key Words: Double-precision electronic, AT89S52, Load sensor, A/D converter, LCD

display

东北大学秦皇岛分校毕业设计(论文) 第 1 页

目 录

1 绪论 ..................................................................................................................................... 3 1.1 课题研究背景 .............................................................................................................. 3 1.2 电子衡器的研究现状 .................................................................................................. 4 1.2.1 国内外发展情况 ................................................................................................. 4 1.2.2 电子称的发展方向 ............................................................................................. 5 1.3 课题的研究意义 .......................................................................................................... 5 1.4 本文的设计思路 .......................................................................................................... 5 2 系统方案论证与硬件选型 ................................................................................................. 8 2.1 系统总体设计方案的比较与论证 .............................................................................. 8 2.2 硬件方案设计与论证 ................................................................................................ 10 2.2.1 CPU的选择方案 .............................................................................................. 10 2.2.2 传感器的选择 ................................................................................................... 11 2.2.3 放大电路的选择方案 ....................................................................................... 13 2.2.4 A/D转换器的选择 ........................................................................................... 14 2.5 键盘处理部分方案的论证 ........................................................................................ 18 2.6 显示器部分的选择 .................................................................................................... 19 2.7 超量程报警部分的选择 ............................................................................................ 19 3 硬件电路设计 ................................................................................................................... 20 3.1 AT89S52单片机介绍 ............................................................................................... 20 3.1.1 AT89S52单片机综述 ....................................................................................... 20 3.1.2 AT89S52的最小系统电路构成 ....................................................................... 21 3.2 A/D转换器与AT89S52单片机接口电路............................................................... 22 3.3 显示电路与AT89S52单片机的接口电路 .............................................................. 25 3.3.1 12864点阵型LCD简介 .................................................................................. 25

东北大学秦皇岛分校毕业设计(论文) 第 2 页

3.3.2 点阵LCD的显示原理 ..................................................................................... 26 3.3.1 12864LCD指令系统 ........................................................................................ 27 3.4 键盘电路与AT89S52的接口电路设计 .................................................................. 29 4 系统软件设计 ................................................................................................................... 32 4.1 主程序设计 ................................................................................................................ 32 4.1.1 C语言在单片机中的应用 ............................................................................... 32 4.1.2 电子称的软件设计与实现 ............................................................................... 33 4.2 系统主程序流程图 .................................................................................................... 33 4.3 系统子程序设计 ........................................................................................................ 34 4.3.1 A/D转换启动及数据读取程序设计 ............................................................... 34 4.3.2 显示程序设计 ................................................................................................... 36 4.3.3 键盘输入控制程序设计 ................................................................................... 37 5 系统调试 ........................................................................................................................... 39 5.1 软件调试 .................................................................................................................... 39 5.2 故障分析与解决方案 ................................................................................................ 39 5.2.1 故障出现情况 ................................................................................................... 39 5.2.2 解决方案 ........................................................................................................... 40 5.3 功能测试 .................................................................................................................. 40 结论 ......................................................................................................................................... 41 致 谢 ................................................................................................................................. 42 参考文献 ................................................................................................................................. 43 附 录 ................................................................................................................................. 44 附录A ................................................................................................................................ 44 附录B ................................................................................................................................ 51 附录C ................................................................................................................................ 52

东北大学秦皇岛分校毕业设计(论文) 第 43 页

参考文献

[1] 黄坚,金惟伟.中小型电机产品近年出口情况简述[J].中小型电机,2005,32(1) 9--12.

[1]赵茂泰. 智能仪器原理及应用[M].北京:电子工业出版社.2004

[2]张毅刚. MCS-51单片机应用设计[M].哈尔滨:哈尔滨工业大学出版社.2003 [3]贾伯年, 俞朴.传感器技术[M].东南大学出版社.2000

[4]单成祥.传感器理论设计基础及其应用[M].北京:国防工业出版社.1999 [5]李道华,李玲,朱艳 .传感器电路分析与[M].武汉:武汉大学出版社.2000 [6]沙占友 ,王彦朋等. 智能传感器系统设计与应用[M].北京:电子工业出版社2004.6

[7]何希才,薛永毅. 传感器及其应用实例[J].北京:机械工业出版社.2004.1 [8]李群芳. 单片机微型计算机与接口技术[M].电子工业出版社. [9]周立功. 单片机实验与实践[M].北京航空航天大学出版社.2004.6

[10]全国大学生电子设计竞赛组委会.全国大学生电子设计竞赛获奖作品汇编[J].北京理工大学出版社.2005.11

[11]何立民 .单片机高级教材[M].北京:航空航天大学出版社.2000 [12]童诗白,华成英 .模拟电子技术基础[M]. 北京:北京高等教育出社.2001 [13]程林 ,超省电型电子秤的设计方案[J].福建:福建省计量科学技术研究所. 2008.3

[14] 美国国家仪器( NI )公司.技术支持.http://www.ni.com/support/zhs/. [15] 王丽丽.基于Wi-Fi 的无线数据采集系统研究[D].郑州:河南大学,2004. [16] LI Yue-qin. Arbitrary Waveform Generator based on LabVIEW[A]. International Conference on E-Leaning, E-Business, Enterprise Information Systems, and E-Government [C]. 2009.

东北大学秦皇岛分校毕业设计(论文) 第 44 页

附 录

附录A

AT89S52’S Description

The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8Kbytes of in-system programmable Flash memory. The device is manufactured using Atmel’s high-density nonvolatile memory technology and is compatible with the industry-standard 80C51 instruction set and pin out. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the Atmel AT89S52 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to many embedded control applications. he AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89S52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The Power-down mode saves the RAM contents but freezes the oscillator, disabling all other chip functions until the next interrupt or hardware reset.

Pin Description VCC

Supply voltage. GND Ground. Port 0

Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When 1sare written to port 0 pins, the pins can be used as high impedance

东北大学秦皇岛分校毕业设计(论文) 第 45 页

inputs. Port 0 can also be configured to be the multiplexed low order address/data bus during accesses to external program and data memory. In this mode, P0 has internal pullups. Port 0 also receives the code bytes during Flash programming and outputs the code bytes during program verification.

External pullups are required during program verification.

Port 1

Port 1 is an 8-bit bidirectional I/O port with internal pullups. The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the internal pullups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current (IIL) because of the internal pullups. In addition, P1.0 and P1.1 can be configured to be the timer/counter 2 external count input (P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX), respectively, as

shown in the following table. Port 1 also receives the low-order address bytes during Flash programming and verification.

Port 2

Port 2 is an 8-bit bidirectional I/O port with internal pullups. The Port 2 output buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled high by the internal pullups and can be used as inputs. As inputs,

Port 2 pins that are externally being pulled low will source current (IIL) because of the internal pullups. Port 2 emits the high-order address byte during fetches from external program memory and during accesses to external data memory that use 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses strong internal pull-ups when emitting 1s. During accesses to external data memory that use 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register. Port 2 also receives the high-order address bits and some control signals during Flash programming and verification.

Port 3

Port 3 is an 8-bit bidirectional I/O port with internal pullups. The Port 3 output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the internal pullups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will source current (IIL) because of the pull-ups Port 3 also serves the functions of various special features of the AT89S52, as shown in the following table. Port 3 also receives some control signals for Flash programming and verification.

东北大学秦皇岛分校毕业设计(论文) 第 46 页

RST

Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device. This pin drives High for 96 oscillator periods after the Watchdog times out. The DISRTO bit in SFR AUXR (address 8EH) can be used to disable this feature. In the default state of bit DISRTO, the RESET HIGH out feature is enabled

ALE/PROG

Address Latch Enable (ALE) is an output pulse for latching the low byte of the address during accesses to external memory. This pin is also the program pulse input (PROG)during Flash programming. In normal operation, ALE is emitted at a constant rate of1/6 the oscillator frequency and may be used for external timing or clocking purposes. Note, however, that one ALE pulse is skipped during each access to external data memory. If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is P1.0 T2 (external count input to Timer/Counter 2), clock-outP1.1 T2EX (Timer/Counter 2 capture/reload trigger and direction control)

P1.5 MOSI (used for In-System Programming) P1.6 MISO (used for In-System Programming) P1.7 SCK (used for In-System Programming) P3.0 RXD (serial input port) P3.1 TXD (serial output port) P3.2 INT0 (external interrupt 0) P3.3 INT1 (external interrupt 1) P3.4 T0 (timer 0 external input) P3.5 T1 (timer 1 external input)

P3.6 WR (external data memory write strobe) P3.7 RD (external data memory read strobe)

PSEN

Program Store Enable (PSEN) is the read strobe to external program memory. When the AT89S52 is executing code from external program memory, PSEN is activated twice each machine cycle, except that two PSEN activations are skipped during each access to external data memory.

EA/VPP

东北大学秦皇岛分校毕业设计(论文) 第 47 页

External Access Enable. EA must be strapped to GND in order to enable the device to fetch code from external program memory locations starting at 0000H up to FFFFH. Note, however, that if lock bit 1 is programmed, EA will be internally latched on reset. EA should be strapped to VCC for internal program executions. This pin also receives the 12-volt programming enable voltage(VPP) during Flash programming.

XTAL1

Input to the inverting oscillator amplifier and input to the internal clock operating circuit.

XTAL2

Output from the inverting oscillator amplifier. [9]

中文译文A AT89S52简述

AT89S52 是一种低功耗、高性能CMOS8位微控制器,具有 8K 在系统可编程 Flash 存储器。使用Atmel 公司高密度非易失性存储器技术制造,与工业80C51 产品指令和引脚完 全兼容。片上Flash允许程序存储器在系统可编程,亦适于 常规编程器。在单芯片上,拥有灵巧的8 位CPU 和在系统 可编程Flash,使得AT89S52为众多嵌入式控制应用系统提 供高灵活、超有效的解决方案。 AT89S52具有以下标准功能: 8k字节Flash,256字节RAM, 32 位I/O 口线,看门狗定时器,2 个数据指针,三个16 位 定时器/计数器,一个6向量2级中断结构,全双工串行口, 片内晶振及时钟电路。另外,AT89S52 可降至0Hz 静态逻 辑操作,支持2种软件可选择节电模式。空闲模式下,CPU 停止工作,允许RAM、定时器/计数器、串口、中断继续工 作。掉电保护方式下,RAM内容被保存,振荡器被冻结, 单片机一切工作停止,直到下一个中断或硬件复位为止。

P0 口:P0口是一个8位漏极开路的双向I/O口。作为输出口,每位能驱动8个TTL逻 辑电平。对P0端口写“1”时,引脚用作高阻抗输入。 当访问外部程序和数据存储器时,P0口也被作为低8位地址/数据复用。在这种模式下, P0不具有内部上拉电阻。 在flash编程时,P0口也用来接收指令字节;在程序校验时,输出指令字节。程序校验 时,

本文来源:https://www.bwwdw.com/article/9wa2.html

Top