您好,欢迎访问三七文档
16附:程序清单;PCONEQU87H;***********LCM103LCM101TEST*************;MCS-51:89C2051,89C51,89C52;fo=2.45MHz;/CS=P1.4/WR=P1.3DATA=P1.2*************;RAM20H:COMMANDCODE********************;RAM21H:LCDADDR***;RAM25H:LCDDATA***ORG0000HAJMPMAINORG000BHAJMPwtoORG0013HAJMPPINT1ORG0030HMAIN:;ACALLSTOPCLRP3.0MOVP2,#0F0Hacallqlacallstart;ACALLDELAY;ACALLLLL;ACALLRDNBYT;MOV31H,41H;MOV32H,42H;MOV33H,43H;MOV2FH,#08H;ACALLWRNBYT;ACALLDELAY1;ACALLSTARTmain2:MOVSP,#5FHMOVTMOD,#52HMOVTL0,#06HMOVTH0,#06HMOVIE,#82HSETBIT1MAIN3:ACALLKEY1;按键控制,前进,清零,翻页;============CLRP2.0SETBP2.1ACALLCHUAN1ZHI:MOVA,TL1;直道行驶CLRCSUBBA,#30;230=S=(TH1,TL1)*14/6JNCWANACALLKUAIAJMPZHI;===========================;弯道行驶;=============================WAN:SETB20H.2;弯道标志位;CLRP2.3;SETBP2.2CLRP2.1SETBP2.0MOV5DH,#02HDJNZ5DH,$CLRP2.0SETBP2.1ACALLMAN;到达弯道JB20H.3,ZHANGajmpwan;====================;障碍物行驶;===================ZHANG:mov20h,#00hclrp2.3setbp2.2CLRP2.1SETBP2.0MOV5EH,#50S50:MOV5DH,#0FFHDJNZ5DH,$DJNZ5EH,S50CLRP2.0SETBP3.0mov3fh,#05;定时器5秒程序ffdd:jnb20h.0,$clr20h.0CPLP3.0djnz3fh,FFDD17clrp2.3SETBp2.2clrp2.0setbp2.1setbEX1;启用/INT1MOV5BH,#0FFHDTDT:MOV5AH,#0FFHDJNZ5AH,$DJNZ5BH,DTDTOK:mOVA,P0ANLA,#7FHcjnea,#7FH,K2LZGAJMPSTOP2k2lzg:JBP2.6,KKLZGACALLLZHUANAJMPOKKKLZG:ACALLRZHUANAJMPOKSTOP2:MOVP2,#00HMOVIE,#00Hsetbp3.0clrtr0CLRP2.1setbp2.0ACALLDELAY1ACALLDELAY1ACALLDELAY1nopCLRP2.0CLRP3.0LKLK:ACALLAAAACALLKEY1ACALLAAAAJMPLKLKSJMP$;======================;外部中断1;=====================PINT1:CLREX1PUSHACCPUSHPSWQQ:CLRP2.0;前CPLP2.1CLRP2.3SETBP2.2SETBP2.1NOPNOPJNBP3.3,QQSETBP2.1SETBEX1POPPSWPOPACCRETI;=====================;慢速前进;======================MAN:CLRP2.0;前进SETBP2.1MOV5AH,#01HCHU11:JB20H.3,OUTI2ACALLCHUAN2CLRP2.1;SETBP2.0ACALLCHUAN2CLRP2.0SETBP2.1ACALLCHUAN2DJNZ5AH,CHU11CLRP2.1;停MOV5BH,#9FHCHU12:JB20H.3,OUTICPLP2.1ACALLCHUAN2DJNZ5BH,CHU12CLRP2.0SETBP2.1NOPNOPNOPNOPouti2:RET;============================;快速前进;==========================KUAI:CLRP2.0;前进SETBP2.1MOV5AH,#01H18CHU1:JB20H.3,OUTIACALLCHUAN2DJNZ5AH,CHU1CLRP2.1;停MOV5BH,#0FFHCHU2:JB20H.3,OUTICLRP2.1ACALLCHUAN2DJNZ5BH,CHU2NOPouti:RET;=====================;光电传感器检测子程序;=====================CHUAN1:MOVA,P0ANLA,#7FHCJNEA,#00H,GGHAJMPCHUAN1GGH:SETBTR1;启动计数器AJMPCHUAN2OUTOUT2:AJMPOUTOUT;============CHUAN2:JB20H.3,OUTOUT2JBP0.7,GGGOOOJB20H.1,GGGO3JB20H.2,OUTOUT2INC35HMOVA,35HCJNEA,#01,QQ23MOV51H,TH1MOV50H,TL1QQ23:MOVA,35HCJNEA,#02,QQ3MOV53H,TH1MOV52H,TL1QQ3:MOVA,35HCJNEA,#03,QQQQQMOV55H,TH1MOV54H,TL1QQQQQ:SETB20H.1;ACALLAJMPCHUAN2RETGGGOOO:CLR20H.1GGGO3:MOVA,P0ANLA,#03HCJNEA,#03H,GGGOO1AJMPLZHUANGGGOO1:MOVA,P0ANLA,#60HCJNEA,#60H,GGGOO2AJMPRZHUANGGGOO2:MOVA,P0ANLA,#07HCJNEA,#00H,RZHUANMOVA,P0ANLA,#78HCJNEA,#00H,LZHUANGOOUT:CLRP2.2CLRP2.3RETLZHUAN:CLRP2.3;左转NOPSETBP2.2MOV5AH,#30HDJNZ5AH,$CLRP2.1NOPNOPNOPNOPSETBP2.1CLRP2.2RETRZHUAN:CLRP2.2;右转SETBP2.3SETBP2.1MOV5AH,#30HDJNZ5AH,$CLRP2.1NOPNOPNOPNOPNOPNOP19SETBP2.1CLRP2.3RETQIAN:CLRP2.0;前进SETBP2.1RETNOPNOPNOPNOPNOPCLRP2.1RETHOU:CLRP2.1;后退SETBP2.0RETOUTOUT:SETB20H.3CLRP2.1SETBP2.0NOPNOPNOPNOPCLRP2.0RET;========================;按键按制子程序;========================KEY1:JBP1.5,KEY2;清零键JNBP1.5,$MOV35H,#00ACALLAAAAJMPKEY2KEY2:JBP1.6,KEY3;翻页键JNBP1.6,$MOVA,35HCJNEA,#03H,RRR21MOVR2,55HMOVR3,54HMOV35H,#03ACALLAAAACALLDELAYACALLDELAYMOV35H,#03AJMPJHGRRR21:MOVA,35HCJNEA,#02,RRR1JHG:MOVR2,53HMOVR3,52HMOV35H,#02ACALLAAAACALLDELAYACALLDELAYMOV35H,#02AJMPJHG2RRR1:MOVA,35HCJNEA,#01,RRR0JHG2:MOVR2,51HMOVR3,50HMOV35H,#01ACALLAAAACALLDELAYACALLDELAYRRR0:AJMPKEY3KEY3:JBP1.7,KEY1;启动JNBP1.7,$ACALLDELAYsetbtr0;开定时器0;setbtr1MOVTL1,#01HCLRP2.0;前进SETBP2.1CLRP2.2CLRP2.3RET;=============================;定时器中断子程序;=============================WTO:PUSHACCMOVR0,#30HINC@R0MOVA,#200XRLA,@R020JNZOUTMOV@R0,A;==================ACALLLUCHENG;================MOVR0,#31HINC@R0MOVA,#10XRLA,@R0JNZOUTMOV@R0,ASETB20H.0MOVR2,01LFT:INCR0INC@R0MOVA,#10;XRLA,@R0JNZOUTMOV@R0,ADJNZR2,LFTINCR0INC@R0MOVA,#9;XRLA,@R0JNZOUTMOV@R0,AMOV33H,#09MOVIE,#00HMOVP2,#00HCLRTR0UUUU:ACALLKEY1AJMPUUUUOUT:POPACCRETI;=================================LUCHENG:MOVR2,TH1;路程转化MOVR3,TL1MOVR6,#00HMOVR7,#30ACALLMULDMOVR6,#00MOVR7,#2ACALLDIVDMOVA,R2MOVR6,AMOVA,R3MOVR7,AACALLHB2MOV37H,R5ANL37H,#0FHMOVA,R5ANLA,#0F0HSWAPAMOV38H,AMOVA,R4ANLA,#0FHADDA,#11MOV39H,AMOVA,R4ANLA,#0F0HSWAPAMOV3AH,AACALLAAAORLP1,#1CHRET;=================================QL:MOV20H,#0MOVR2,#0fhMOVR1,#30HCLRALQ:MOV@R1,AINCR1DJNZR2,LQRETQL2:MOVR2,#0AHMOVR1,#35HMOVA,#0AHLQ1:MOV@R1,AINCR1DJNZR2,LQ1RET21;(37H38H)中16位二进制整数转换为压缩BCD码十进;制整数送(3DH,3EH,3FH);程序:IBTD2:NOPMOV37H,TH1MOV38H,TL1CLRAMOV3DH,AMOV3EH,AMOV3FH,A;MOVTH1,A;MOVTL1,AMOVR7,#16LOOP2:CLRCMOVA,38HRLCAMOV38H,AMOVA,37HRLCA;(C)为BiMOV37H,A;(34H35H36H)+(34H35H36H)+C;=(34H35H36H)*2+C(十进制加)MOVA,3FHADDCA,3FHDAAMOV3FH,AMOVA,3EHADDCA,3EHDAAMOV3EH,AMOVA,3DHADDCA,3DHDAAMOV3DH,ADJNZR7,LOOP2NOPRET;=====================================;液晶显示子程序;=====================================START:ORLP1,#1CHSETBP3.7CALLDLY500MOV0H,#00100100B;INITIALIZECALLWRCOMMOV20H,#00010100B;32768HZCALLWRCOMMOV20H,#00000001B;SYSENCALLWRCOMMOV20H,#00000011B;LCDONCALLWRCOMaaa:CALLWR123ORLP1,#1CHret
本文标题:简易电动车 程序
链接地址:https://www.777doc.com/doc-306517 .html