普通高等教育“十三五”规划教材
ST 首批认证“STM32 精品课程”教材
“蓝桥杯”嵌入式设计与开发竞赛培训教材
“蓝桥杯”
全国软件和信息技术专业人才大赛
(电子类)实训指导书
彭大海 主编
蒋水秀 郭书军 副主编
朱青建 审核
Publishing House of Electronics Industry
北京·BEIJING
内 容 简 介
本书分别以“蓝桥杯”大赛单片机竞赛实训平台和嵌入式竞赛实训平台为硬件环境,在介绍实训平台模块程
序设计的基础上,介绍单片机设计与开发项目和嵌入式设计与开发项目的试题解析。
全书分为 6 章,第 1 章为大赛简介与经验交流,第 2 章为单片机和嵌入式的开发环境与工具,第 3 章为单片
机设计与开发项目模块程序设计,第 4 章为单片机设计与开发项目往届试题解析,第 5 章为嵌入式设计与开发项
目模块程序设计,第 6 章为嵌入式设计与开发项目往届试题解析。书后附有竞赛实训平台简介和竞赛大纲。
本书所有设计程序均为原创,并经过多次实验反复改进,内容简单易懂,特别适合用于大赛的实训指导。本
书可以作为单片机和嵌入式系统设计教材,供电子、通信和自动化等相关专业的学生使用。
未经许可,不得以任何方式复制或抄袭本书之部分或全部内容。
版权所有,侵权必究。
图书在版编目(CIP)数据
“蓝桥杯”全国软件和信息技术专业人才大赛(电子类)实训指导书 / 彭大海主编. —北京:电子工业出版社,2019.11
ISBN 978-7-121-37655-9
Ⅰ. ①蓝… Ⅱ. ①彭… Ⅲ. ①软件开发-高等学校-教学参考资料②微型计算机-高等学校-教学参考资料
Ⅳ. ①TP311.52②TP36
中国版本图书馆 CIP 数据核字(2019)第 242314 号
责任编辑:赵玉山
印 刷:北京丰源印刷厂
装 订:三河市鹏成印业有限公司
出版发行:电子工业出版社
北京市海淀区万寿路 173 信箱 邮编 100036
开 本:787×1 092 1/16 印张:18 字数:460 千字
版 次:2019 年 11 月第 1 版
印 次:2019 年 11 月第 1 次印刷
定
价:59.00 元
凡所购买电子工业出版社图书有缺损问题,请向购买书店调换。若书店售缺,请与本社发行部联系,联系及
邮购电话:(010)88254888,88258888。
质量投诉请发邮件至 zlts@phei.com.cn,盗版侵权举报请发邮件至 dbqq@phei.com.cn。
本书咨询联系方式:(010)88254556,zhaoys@phei.com.cn。
前 言
为促进软件和信息领域专业技术人才培养,提升高校毕业生的就业竞争力,工业和信息化部
人才交流中心主办了“蓝桥杯”大赛。截至 2019 年 6 月,“蓝桥杯”大赛已经连续举行了 10 届,
包括清华大学、北京大学在内的超过 1200 所院校、30 万名选手报名参加了大赛,已成为具有重
大社会影响力和行业认可度的 IT 类学科竞赛。
“蓝桥杯”大赛电子类竞赛目前开设单片机设计与开发和嵌入式设计与开发两个科目。单片机
科目选用宏晶科技的增强型 51 单片机 IAP15F2K61S2,支持串口调试;嵌入式科目选用意法半导
体 ARM Cortex M3 内核的中密度微控制器 STM32F103RBT6。大赛以封闭限时的方式考核选手单
片机、嵌入式基础知识的掌握和基于硬件的程序系统设计及调试能力。
一直以来,“蓝桥杯”大赛电子类竞赛的参赛师生都希望组委会编撰一本专门针对大赛单片机
设计与开发和嵌入式设计与开发两个科目的竞赛指导书。值此“蓝桥杯”成立十周年之际,大赛
组委会特委托北京国信长天科技有限公司组织编写了本书,以利于指导电子类竞赛的参赛师生
准备大赛。
本书结合“蓝桥杯”大赛电子类竞赛大纲要求,首先介绍了大赛采用的开发环境与工具,包
括 Keil C51、Realview MDK、软件开发包及相关调试和下载工具,然后按照模块化的方式由易到
难逐一介绍单片机和嵌入式竞赛实训平台上的硬件模块程序设计方法,最后结合历年电子类竞赛
真题,按照系统设计、初始化程序设计、处理程序设计和系统实现的思路对真题进行详细解析。
在本书的编写过程中,“蓝桥杯”大赛组委会副秘书长彭大海先生对本书做了全面的统筹规划
并编写了第 1 章,蒋水秀教授编写了 2.1 节、第 3 章和第 4 章等单片机科目相关内容,郭书军教
授编写了 2.2 节、第 5 章和第 6 章等嵌入式科目相关内容并对全书进行了统稿,本书的审核由大
赛组委会资深技术专家朱青建先生完成。此外,本书还特别组织了技术源厂商专家、用人单位专
家和参赛获奖师生就单片机和嵌入式的学习及实践,从各自的角度撰写了经验交流文章,邀请沈
孟锋老师、徐观生老师对本书部分程序进行了测试和验证工作,在此也一并向他们表示诚挚的
感谢!
编 者
2019 年 7 月
·V·
目 录
第
1
章
大赛简介与经验交流
································································································································
(
1
)
1.1
大赛简介
·················································································································································
(
1
)
1.2
经验交流
·················································································································································
(
2
)
1.2.1
意法半导体公司
·························································································································
(
2
)
1.2.2
宏晶科技公司(
STC
)
···············································································································
(
3
)
1.2.3
北京国信长天科技有限公司
······································································································
(
4
)
1.2.4
我对嵌入式人才的理解和期待
··································································································
(
5
)
1.2.5
参赛经验交流
·····························································································································
(
5
)
第
2
章
开发环境与工具
········································································································································
(
8
)
2.1
单片机设计与开发项目的开发环境与工具
···························································································
(
8
)
2.1.1 Keil C51
集成开发环境
··············································································································
(
8
)
2.1.2 STC-ISP
程序下载软件
············································································································
(
12
)
2.1.3 IAP15F2K61S2
程序调试方法
··································································································
(
14
)
2.2
嵌入式设计与开发项目开发环境与工具
·····························································································
(
18
)
2.2.1
软件开发包(
SDK
)
················································································································
(
18
)
2.2.2
集成开发环境(
IDE
)
·············································································································
(
19
)
2.2.3 Coocox
调试器设置
··················································································································
(
21
)
第
3
章
单片机设计与开发项目模块程序设计
···································································································
(
24
)
3.1 LED
程序设计
·······································································································································
(
24
)
3.2
中断程序设计
·······································································································································
(
26
)
3.3
定时器程序设计
···································································································································
(
29
)
3.4
数码管程序设计
···································································································································
(
34
)
3.5
矩阵键盘程序设计
································································································································
(
38
)
3.6
串口程序设计
·······································································································································
(
42
)
3.7 DS1302
时钟芯片驱动程序设计
··········································································································
(
45
)
3.8 DS18B20
温度传感器驱动程序设计
····································································································
(
50
)
3.9 PCF8591 ADC/DAC
驱动程序设计
······································································································
(
54
)
3.10 AT24C02
存储器驱动程序设计
··········································································································
(
57
)
3.11
超声波传感器驱动程序设计
··············································································································
(
60
)
3.12
频率测量程序设计
······························································································································
(
63
)
第
4
章
单片机设计与开发项目往届试题解析
···································································································
(
64
)
4.1
第七届预赛试题
—
模拟风扇控制系统
·····························································································
(
64
)
4.1.1
系统设计
···································································································································
(
65
)
4.1.2
系统实现
···································································································································
(
69
)
4.2
第七届决赛试题
—
电压频率采集设备
·····························································································
(
69
)
4.2.1
系统设计
···································································································································
(
71
)
4.2.2
系统实现
···································································································································
(
78
)
4.3
第八届预赛试题
—
电子钟
················································································································
(
78
)