基于单片机的自行车速度里程表设计 下载本文

摘 要

随着居民生活水平的不断提高,自行车不再仅仅是普通的运输、代步的工具,而是成为人们娱乐、休闲、锻炼的首选。自行车速度/里程表能够满足人们最基本的需求,让人们能清楚地知道当前的速度、里程等物理量。本论文主要阐述一种基于霍尔元件的自行车速度/里程表的设计。以 AT89S52 单片机为核心,A04E 霍尔传感器测转数,实现对自行车里程/速度的测量统计,并能将自行车的里程数及速度用LED实时显示。文章详细介绍了自行车速度/里程表的硬件电路和软件设计。硬件部分利用霍尔元件将自行车每转一圈的脉冲数传入单片机系统,然后单片机系统将信号经过处理送显示。软件部分用C语言进行编程,采用模块化设计思想。该系统硬件电路简单,子程序具有通用性,完全符合设计要求。

关键词:里程/速度;霍尔元件;单片机;LED显示

I

Abstract

With the developing of people’s life, the bicycle is not only the universal tool of transportation and substitute for walking, but becomes the first choice of entertainmenting and exercising. The bicycle mileage/speed can fulfill the basic need of people’s life, so that they can learn the speed and the mileage of the bicycle. In these paper, the bicycle mileage/speed design based on the Hall element is elaborated. By AT89S52 as kernel, using A04E Hall element to measure revolution, the measure and statistic are achieved. The bicycle speed can be displayed on LED. In this article, the hardware circuit and software design of bicycle mileage/speed instrument are introduced in detail. About the hardware, the pulse number is transmitted of one cycle of the bicycle into Single Chip Microcomputer system. Then the signal processed by Single Chip Microcomputer system is sent to display scream. About the software, in C language, the program is designed in the mode of modules. The system has simple hardware, common sub-program, and meet the demand of design.

Keywords: Mileage / speed; Hall element; Single Chip Microcomputer; LED

II

目 录

1 绪论 ................................................................................................................................... 1

1.1课题产生的背景 ...................................................................................................... 1 1.2课题的主要任务及内容 .......................................................................................... 2 2 自行车速度/里程表总体方案设计 .................................................................................. 4

2.1 任务分析与实现 ..................................................................................................... 4 2.2 自行车速度/里程表硬件方案设计 ........................................................................ 4

2.2.1 里程/速度测量传感器的设计 ...................................................................... 5 2.2.2 方案的确定 ................................................................................................... 7 2.3 自行车速度/里程表软件方案设计 ........................................................................ 7 3 自行车速度/里程表硬件电路设计 .................................................................................. 9

3.1 概述 ......................................................................................................................... 9 3.2 传感器及其测量系统 ............................................................................................. 9

3.2.1 霍尔传感器的测量原理 ............................................................................. 10 3.2.2 集成开关型霍尔传感器 ............................................................................. 11 3.3 单片机的原理及应用 ........................................................................................... 12

3.3.1 单片机原理简介 ......................................................................................... 12 3.3.2 单片机的引脚功能介绍 ............................................................................. 14 3.3.3 单片机中断系统介绍 ................................................................................. 17 3.3.4 单片机定时/计数功能介绍 ........................................................................ 18 3.4 单片机外围电路的设计 ....................................................................................... 19

3.4.1 时钟电路的设计 ......................................................................................... 19 3.4.2 复位电路的设计 ......................................................................................... 20 3.4.3 显示电路的设计 ......................................................................................... 21 3.4.4 报警电路的设计 ......................................................................................... 22

4 自行车速度/里程表软件程序设计 ................................................................................ 24

4.1 概述 ....................................................................................................................... 24 4.2 自行车速度/里程表总体程序设计 ...................................................................... 24 4.3 中断子程序的设计 ............................................................................................... 25 4.4 数据处理子程序的设计 ....................................................................................... 26 4.5 显示子程序的设计 ............................................................................................... 28 5 系统调试与分析 ............................................................................................................. 30

III