
 本例实验主要用到了延时子程序,clr,lcall,ajmp 指令, 通过轮流点亮p1.0 …..P1.7 实现效果。用户可以通过此程序的学习, 初步掌握单片机的IO端口操作。 参考程序: ;实验1最简单的8路跑马灯。用一条8PIN的数据排线把CPU部份的P1口(JP44)连接到八路指示灯部份的JP32 ;可以看到8路灯轮流闪烁 org 0000h ;开始 ajmp loop org 0030h ;到0030h处避开00-30的敏感地址 loop: mov p1,#0ffh;关闭所有灯 clr p1.0 ;点亮灯p1.0 lcall delay ;延时一段时间? clr p1.1 ;点亮灯p1.1 lcall delay clr p1.2 ;点亮灯p1.2 lcall delay clr p1.3 ;点亮灯p1.3 lcall delay clr p1.4 ;点亮灯p1.4 lcall delay clr p1.5 ;点亮灯p1.5 lcall delay clr p1.6 ;点亮灯p1.6 lcall delay clr p1.7 ;点亮灯p1.7 lcall delay AJMP LOOP;到最开始loop处重新运行 delay: mov r5,#20 ;延时。 d1: mov r6,#40 d2: mov r7,#248 djnz r7,$ djnz r6,d2 djnz r5,d1 ret end |