
上QQ阅读APP看书,第一时间看更新
3.2 项目训练——天塔之光程序设计与调试
如图3-1所示,天塔之光由L1~L12共12盏灯组成,控制要求如下:按下启动按钮SB1,指示灯L1首先点亮;延时5s后,指示灯L1熄灭,指示灯L2、L3、L4、L5点亮;延时5s后,指示灯L2、L3、L4、L5熄灭,指示灯L6、L7、L8、L9点亮;延时5s后,指示灯L6、L7、L8、L9熄灭,指示灯L10、L11、L12点亮;延时5s后,指示灯L10、L11、L12熄灭,指示灯L1点亮,并不断循环。按下停止按钮SB2后,所有指示灯全部熄灭。
3.2.1 I/O地址分配
根据任务分析,对控制系统的I/O地址进行合理分配,如表3-4所示。
表3-4 I/O地址分配

(续)

3.2.2 硬件设计
根据任务分析,I/O接线图如图3-15所示。

图3-15 I/O接线图
3.2.3 软件程序设计
按下启动按钮SB1, 指示灯L1点亮,程序如图3-16所示。
延时5s后,指示灯L1熄灭,指示灯L2、L3、L4、L5点亮,程序如图3-17所示。

图3-16 指示灯L1点亮程序

天塔之光控制实施过程

图3-17 指示灯L2、L3、L4、L5点亮程序
延时5s后,指示灯L2、L3、L4、L5熄灭,指示灯L6、L7、L8、L9点亮,程序如图3-18所示。

图3-18 指示灯L6、L7、L8、L9点亮程序
延时5s后,指示灯L6、L7、L8、L9熄灭,指示灯L10、L11、L12点亮,程序如图3-19所示。
指示灯程序如图3-20~图3-23所示。

图3-19 指示灯L10、L11、L12点亮程序

图3-20 指示灯L1程序

图3-21 指示灯L2、L3、L4、L5程序

图3-22 指示灯L6、L7、L8、L9程序

图3-23 指示灯L10、L11、L12程序

天塔之光控制调试过程