《单片机考试综合大题编程》由会员分享,可在线阅读,更多相关《单片机考试综合大题编程(9页珍藏版)》请在金锄头文库上搜索。
1、#includesbitgate=P20;voidmain(void)unsignedinti,j;while(1)for(i=50000;i0;i-);for(j=50000;j0;j-);gate=!gate;汇编:org 0000h start:clr p2.0 acall delay setb p2.0 acall delay ajmp startdelay: mov r3,#0ffhdel2: mov r4,#0ffhdel1: nop djnz r4,del1 djnz r3,del2 ret end点亮小灯闪烁点亮小灯闪烁定时器隔定时器隔500ms500ms输出方波输出方波ORG
2、0000HMOVR0,#250MAIN:MOVTMOD,#00HMOVTH0,#0E0HMOVTL0,#018HSETBTR0SETBET0SETBEAAJMP$ORG000BHAJMPINQPINQP:MOVTH0,#0E0HMOVTL0,#018HDJNZR0,MAINCPLP1.0RETIENDlp:movr1,#7movr2,#6mova,#0fehmovp2,#0fehacalldelaylp1:rlamovp2,aacalldelaydjnzr1,lp1lp2:rramovp2,aacalldelaydjnzr2,lp2ajmplpdelay:lp3:movr3,#0F4H八八只只
3、灯灯闪闪间间隔隔0 0. .5 5秒秒del2:movr4,#0FFHdel1:NOPNOPdjnzr4,del1djnzr3,del2djnzr0,lp3retend模拟霓虹灯org0000hstart:clrp2.0clrp2.1clrp2.2clrp2.3acalldelaysetbp2.0setbp2.1setbp2.2setbp2.3acalldelayajmpstartdelay:movr3,#0ffhdel2:movr4,#0ffhdel1:nopdjnzr4,del1djnzr3,del2retend汽车转向灯控制汽车转向灯控制Org0000hStart:setb20hmovc
4、,20hcplcmovacc.0,csetb21hmovc,21hcplcmovacc.3,cNext:movp2,aacalldelay195msmovp2,#0ffHacalldelay195mssjmpnextdelay195ms:movr3,#07fhdel2:movr4,#0ffhdel1:nopdjnzr4,del1djnzr3,del2retendOrg0000hStart:movp1,#0ffHmova,p1jbacc.0,L1setbacc.0jmpL2L1:clracc.0L2:jbacc.1,L3setbacc.3jmpnextL3:clracc.3Next:movp2,
5、aacalldelay195msmovp2,#0ffHacalldelay195mssjmpstartdelay195ms:movr3,#07fhdel2:movr4,#0ffhdel1:nopdjnzr4,del1djnzr3,del2retend汽汽车车转转向向灯灯模模拟拟控控制制Org0000hsjmpstartorg0003hljmpshacheorg0080hStart:movie,#81hmovtcon,00hmovp1,#0ffHmova,p1jbacc.0,L1setbacc.0汽汽车车转转向向灯灯模模拟拟控控制制刹刹车车情情况况jmpL2L1:clracc.0L2:jbacc
6、.1,L3setbacc.3jmpnextL3:clracc.3Next:movp2,aacalldelay195msmovp2,#0ffHacalldelay195mssjmpstartshache:clracc.0clracc.3movp2,aacalldelay195msretidelay195ms:movr3,#07fhdel2:movr4,#0ffhdel1:nopdjnzr4,del1djnzr3,del2retend汽车转向灯控制全中断汽车转向灯控制全中断Org0000hsjmpstartorg0003hljmpzhongduan1org0080hStart:movie,#81h
7、movtcon,00hmovp2,#0ffHsjmpstartzhongduan1:movp1,#0ffHmova,p1jnbacc.0,shachejnbacc.1,leftjnbacc.2,rightretishache:clracc.0clracc.3movp2,aacalldelay195msretileft:clracc.0setbacc.3movp2,aacalldelay195msmovp2,#0ffHacalldelay195msretiright:setbacc.0clracc.3movp2,aacalldelay195msmovp2,#0ffHacalldelay195ms
8、retidelay195ms:movr3,#07fhdel2:movr4,#0ffhdel1:nopdjnzr4,del1djnzr3,del2retend汽车四个转向灯汽车四个转向灯Sw4Sw4控制左转向灯,控制左转向灯,sw5sw5控制右控制右转向灯,转向灯,sw3sw3控制刹车灯控制刹车灯d1d1,d2d2Org0000hsjmpstartorg0003hljmpzhongduan1org0080hStart:movie,#81hmovtcon,00hmovp2,#0ffHsjmpstartzhongduan1:movp1,#0ffHmova,p1jnbacc.0,shachejnbac
9、c.1,leftjnbacc.2,rightretishache:setbacc.0setbacc.3clrp0.0clrp0.3movp2,aacalldelay195msretileft:clracc.0setbacc.3movp2,aacalldelay195msmovp2,#0ffHacalldelay195msretiright:setbacc.0clracc.3movp2,aacalldelay195msmovp2,#0ffHacalldelay195msretidelay195ms:movr3,#07fhdel2:movr4,#0ffhdel1:nopdjnzr4,del1djnzr3,del2retend