简易电动车程序.docx
《简易电动车程序.docx》由会员分享,可在线阅读,更多相关《简易电动车程序.docx(38页珍藏版)》请在冰豆网上搜索。
简易电动车程序
简易电动车程序
;PCONEQU87H
;***********LCM103LCM101TEST*************
;MCS-51:
89C2051,89C51,89C52;fo=2.45MHz
;/CS=P1.4/WR=P1.3DATA=P1.2*************
;RAM20H:
COMMANDCODE********************
;RAM21H:
LCDADDR***
;RAM25H:
LCDDATA***
ORG0000H
AJMPMAIN
ORG000BH
AJMPwto
ORG0013H
AJMPPINT1
ORG0030H
MAIN:
;ACALLSTOP
CLRP3.0
MOVP2,#0F0H
acallql
acallstart
;ACALLDELAY
;ACALLLLL
;ACALLRDNBYT
;MOV31H,41H
;MOV32H,42H
;MOV33H,43H
;MOV2FH,#08H
;ACALLWRNBYT
;ACALLDELAY1
;ACALLSTART
main2:
MOVSP,#5FH
MOVTMOD,#52H
MOVTL0,#06H
MOVTH0,#06H
MOVIE,#82H
SETBIT1
MAIN3:
ACALLKEY1;按键操纵,进步,清零,翻页
;============
CLRP2.0
SETBP2.1
ACALLCHUAN1
ZHI:
MOVA,TL1;直道行驶
CLRC
SUBBA,#30;230=S=(TH1,TL1)*14/6
JNCWAN
ACALLKUAI
AJMPZHI
;===========================
;弯道行驶
;=============================
WAN:
SETB20H.2;弯道标记位
;CLRP2.3
;SETBP2.2
CLRP2.1
SETBP2.0
MOV5DH,#02H
DJNZ5DH,$
CLRP2.0
SETBP2.1
ACALLMAN;达到弯道
JB20H.3,ZHANG
ajmpwan
;====================
;障碍物行驶
;===================
ZHANG:
mov20h,#00h
clrp2.3
setbp2.2
CLRP2.1
SETBP2.0
MOV5EH,#50
S50:
MOV5DH,#0FFH
DJNZ5DH,$
DJNZ5EH,S50
CLRP2.0
SETBP3.0
mov3fh,#05;准时器5秒法度榜样
ffdd:
jnb20h.0,$
clr20h.0
CPLP3.0
djnz3fh,FFDD
clrp2.3
SETBp2.2
clrp2.0
setbp2.1
setbEX1;启用/INT1
MOV5BH,#0FFH
DTDT:
MOV5AH,#0FFH
DJNZ5AH,$
DJNZ5BH,DTDT
OK:
mOVA,P0
ANLA,#7FH
cjnea,#7FH,K2LZG
AJMPSTOP2
k2lzg:
JBP2.6,KKLZG
ACALLLZHUAN
AJMPOK
KKLZG:
ACALLRZHUAN
AJMPOK
STOP2:
MOVP2,#00H
MOVIE,#00H
setbp3.0
clrtr0
CLRP2.1
setbp2.0
ACALLDELAY1
ACALLDELAY1
ACALLDELAY1
nop
CLRP2.0
CLRP3.0
LKLK:
ACALLAAA
ACALLKEY1
ACALLAAA
AJMPLKLK
SJMP$
;======================
;外部中断1
;=====================
PINT1:
CLREX1
PUSHACC
PUSHPSW
QQ:
CLRP2.0;前
CPLP2.1
CLRP2.3
SETBP2.2
SETBP2.1
NOP
NOP
JNBP3.3,QQ
SETBP2.1
SETBEX1
POPPSW
POPACC
RETI
;=====================
;慢速进步
;======================
MAN:
CLRP2.0;进步
SETBP2.1
MOV5AH,#01H
CHU11:
JB20H.3,OUTI2
ACALLCHUAN2
CLRP2.1
;SETBP2.0
ACALLCHUAN2
CLRP2.0
SETBP2.1
ACALLCHUAN2
DJNZ5AH,CHU11
CLRP2.1;停
MOV5BH,#9FH
CHU12:
JB20H.3,OUTI
CPLP2.1
ACALLCHUAN2
DJNZ5BH,CHU12
CLRP2.0
SETBP2.1
NOP
NOP
NOP
NOP
outi2:
RET
;============================
;快速进步
;==========================
KUAI:
CLRP2.0;进步
SETBP2.1
MOV5AH,#01H
CHU1:
JB20H.3,OUTI
ACALLCHUAN2
DJNZ5AH,CHU1
CLRP2.1;停
MOV5BH,#0FFH
CHU2:
JB20H.3,OUTI
CLRP2.1
ACALLCHUAN2
DJNZ5BH,CHU2
NOP
outi:
RET
;=====================
;光电传感器检测子法度榜样
;=====================
CHUAN1:
MOVA,P0
ANLA,#7FH
CJNEA,#00H,GGH
AJMPCHUAN1
GGH:
SETBTR1;启动计数器
AJMPCHUAN2
OUTOUT2:
AJMPOUTOUT
;============
CHUAN2:
JB20H.3,OUTOUT2
JBP0.7,GGGOOO
JB20H.1,GGGO3
JB20H.2,OUTOUT2
INC35H
MOVA,35H
CJNEA,#01,QQ23
MOV51H,TH1
MOV50H,TL1
QQ23:
MOVA,35H
CJNEA,#02,QQ3
MOV53H,TH1
MOV52H,TL1
QQ3:
MOVA,35H
CJNEA,#03,QQQQQ
MOV55H,TH1
MOV54H,TL1
QQQQQ:
SETB20H.1
;ACALL
AJMPCHUAN2
RET
GGGOOO:
CLR20H.1
GGGO3:
MOVA,P0
ANLA,#03H
CJNEA,#03H,GGGOO1
AJMPLZHUAN
GGGOO1:
MOVA,P0
ANLA,#60H
CJNEA,#60H,GGGOO2
AJMPRZHUAN
GGGOO2:
MOVA,P0
ANLA,#07H
CJNEA,#00H,RZHUAN
MOVA,P0
ANLA,#78H
CJNEA,#00H,LZHUAN
GOOUT:
CLRP2.2
CLRP2.3
RET
LZHUAN:
CLRP2.3;左转
NOP
SETBP2.2
MOV5AH,#30H
DJNZ5AH,$
CLRP2.1
NOP
NOP
NOP
NOP
SETBP2.1
CLRP2.2
RET
RZHUAN:
CLRP2.2;右转
SETBP2.3
SETBP2.1
MOV5AH,#30H
DJNZ5AH,$
CLRP2.1
NOP
NOP
NOP
NOP
NOP
NOP
SETBP2.1
CLRP2.3
RET
QIAN:
CLRP2.0;进步
SETBP2.1
RET
NOP
NOP
NOP
NOP
NOP
CLRP2.1
RET
HOU:
CLRP2.1;撤退撤退
SETBP2.0
RET
OUTOUT:
SETB20H.3
CLRP2.1
SETBP2.0
NOP
NOP
NOP
NOP
CLRP2.0
RET
;========================
;按键按制子法度榜样
;========================
KEY1:
JBP1.5,KEY2;清零键
JNBP1.5,$
MOV35H,#00
ACALLAAA
AJMPKEY2
KEY2:
JBP1.6,KEY3;翻页键
JNBP1.6,$
MOVA,35H
CJNEA,#03H,RRR21
MOVR2,55H
MOVR3,54H
MOV35H,#03
ACALLAAA
ACALLDELAY
ACALLDELAY
MOV35H,#03
AJMPJHG
RRR21:
MOVA,35H
CJNEA,#02,RRR1
JHG:
MOVR2,53H
MOVR3,52H
MOV35H,#02
ACALLAAA
ACALLDELAY
ACALLDELAY
MOV35H,#02
AJMPJHG2
RRR1:
MOVA,35H
CJNEA,#01,RRR0
JHG2:
MOVR2,51H
MOVR3,50H
MOV35H,#01
ACALLAAA
ACALLDELAY
ACALLDELAY
RRR0:
AJMPKEY3
KEY3:
JBP1.7,KEY1;启动
JNBP1.7,$
ACALLDELAY
setbtr0;开准时器0
;setbtr1
MOVTL1,#01H
CLRP2.0;进步
SETBP2.1
CLRP2.2
CLRP2.3
RET
;=============================
;准时器中断子法度榜样
;=============================
WTO:
PUSHACC
MOVR0,#30H
INC@R0
MOVA,#200
XRLA,@R0
JNZOUT
MOV@R0,A
;==================
ACALLLUCHENG
;================
MOVR0,#31H
INC@R0
MOVA,#10
XRLA,@R0
JNZOUT
MOV@R0,A
SETB20H.0
MOVR2,01
LFT:
INCR0
INC@R0
MOVA,#10;
XRLA,@R0
JNZOUT
MOV@R0,A
DJNZR2,LFT
INCR0
INC@R0
MOVA,#9;
XRLA,@R0
JNZOUT
MOV@R0,A
MOV33H,#09
MOVIE,#00H
MOVP2,#00H
CLRTR0
UUUU:
ACALLKEY1
AJMPUUUU
OUT:
POPACC
RETI
;=================================
LUCHENG:
MOVR2,TH1;路程转化
MOVR3,TL1
MOVR6,#00H
MOVR7,#30
ACALLMULD
MOVR6,#00
MOVR7,#2
ACALLDIVD
MOVA,R2
MOVR6,A
MOVA,R3
MOVR7,A
ACALLHB2
MOV37H,R5
ANL37H,#0FH
MOVA,R5
ANLA,#0F0H
SWAPA
MOV38H,A
MOVA,R4
ANLA,#0FH
ADDA,#11
MOV39H,A
MOVA,R4
ANLA,#0F0H
SWAPA
MOV3AH,A
ACALLAAA
ORLP1,#1CH
RET
;=================================
QL:
MOV20H,#0
MOVR2,#0fh
MOVR1,#30H
CLRA
LQ:
MOV@R1,A
INCR1
DJNZR2,LQ
RET
QL2:
MOVR2,#0AH
MOVR1,#35H
MOVA,#0AH
LQ1:
MOV@R1,A
INCR1
DJNZR2,LQ1
RET
;(37H38H)中16位二进制整数转换为紧缩BCD码十进
;制整数送(3DH,3EH,3FH)
;法度榜样:
IBTD2:
NOP
MOV37H,TH1
MOV38H,TL1
CLRA
MOV3DH,A
MOV3EH,A
MOV3FH,A
;MOVTH1,A
;MOVTL1,A
MOVR7,#16
LOOP2:
CLRC
MOVA,38H
RLCA
MOV38H,A
MOVA,37H
RLCA;(C)为Bi
MOV37H,A
;(34H35H36H)+(34H35H36H)+C
;=(34H35H36H)*2+C(十进制加)
MOVA,3FH
ADDCA,3FH
DAA
MOV3FH,A
MOVA,3EH
ADDCA,3EH
DAA
MOV3EH,A
MOVA,3DH
ADDCA,3DH
DAA
MOV3DH,A
DJNZR7,LOOP2
NOP
RET
;=====================================
;液晶显示子法度榜样
;=====================================
START:
ORLP1,#1CH
SETBP3.7
CALLDLY500
MOV0H,#00100100B;INITIALIZE
CALLWRCOM
MOV20H,#00010100B;32768HZ
CALLWRCOM
MOV20H,#00000001B;SYSEN
CALLWRCOM
MOV20H,#00000011B;LCDON
CALLWRCOM
aaa:
CALLWR123
ORLP1,#1CH
ret
;==========================
;===========================
;=======================
;****LCDDRIVERMODESUB.**************
;WRITECOMMANDSUB.***********
WRCOM:
SETBP1.4;/CS=1
NOP
CALLDLY5
CLRP1.4;/CS=0
CALLDLY5
CLRP1.3;/WR=0
CALLDLY5
NOP
SETBP1.2;D=1(100)
CALLDLY5
NOP
SETBP1.3;/WR=1
CALLDLY5
NOP
CLRP1.3;/WR=0
CALLDLY5
NOP
CLRP1.2;D=0
CALLDLY5
NOP
SETBP1.3;/WR=1
CALLDLY5
NOP
CLRP1.3;/WR=0
CALLDLY5
NOP
CLRP1.2;D=0
CALLDLY5
NOP
SETBP1.3;/WR=1
CALLDLY5
NOP
MOVR7,#9;LOOP=DATA8BIT+1X
CLRC
LOOPWR:
NOP
CALLDLY5
CLRP1.3
CALLDLY5
MOVA,20H
RLCA
MOV20H,A
JCWR1
CLRP1.2;DATA=0
CALLDLY5
JMPWRR
WR1:
SETBP1.2;DATA=1
CALLDLY5
WRR:
SETBP1.3
CALLDLY5
DJNZR7,LOOPWR
RET
;************************************************************
;LOOPWRDASUB
WALP:
ST1:
MOV21H,23H
MOVA,21H
ADDA,#00000100B
MOV21H,A
MOV23H,A
incr6
CALLWRDD
MOV25H,27H
CALLWRDA
cjneR6,#29,st1
RET
;WRITEDATASUB.*********************************************
WRDD:
SETBP1.4;/CS=1
CALLDLY5
NOP
CLRP1.4;/CS=0
CALLDLY5
CLRP1.3;/WR=0
CALLDLY5
SETBP1.2;D=1(101)
CALLDLY5
SETBP1.3;/WR=1
CALLDLY5
CLRP1.3;/WR=0
CALLDLY5
CLRP1.2;D=0
CALLDLY5
SETBP1.3;/WR=1
CALLDLY5
CLRP1.3;/WR=0
CALLDLY5
SETBP1.2;D=1
CALLDLY5
SETBP1.3;/WR=1
CALLDLY5
MOVR4,#6
MOV22H,21H
ADDWR2:
NOP
CALLDLY5
CLRP1.3
CALLDLY5
MOVA,21H
RLCA
MOV21H,A
JCWR11
CLRP1.2;DATA=0
CALLDLY5
JMPWRR1
WR11:
NOP
CALLDLY5
SETBP1.2;DATA=1
CALLDLY5
WRR1:
NOP
CALLDLY5
SETBP1.3
CALLDLY5
DJNZR4,ADDWR2
RET
WRDAMOVR5,#4;LOOP=DATA4BIT
ADDWR3:
NOP
CALLDLY5
CLRP1.3
CALLDLY5
MOVA,25H
RRCA
MOV25H,A
JCWR12
CLRP1.2;DATA=0
CALLDLY5
JMPWRR2
WR12:
NOP
CALLDLY5
SETBP1.2;DATA=1
CALLDLY5
WRR2:
NOP
CALLDLY5
SETBP1.3
CALLDLY5
DJNZR5,ADDWR3
RET
DLY5:
NOP
NOP
NOP
NOP
RET
DLY25M:
MOVR1,#250;12M/2.5MS
DLOP:
CALLDLY5
CALLDLY5
DJNZR1,DLOP
RET
DLY1S:
MOVR0,#20;1S
DLOP1:
CALLDLY25M
CALLDLY25M
DJNZR0,DLOP1
RET
DLY500:
MOVR0,#5
DLOP11:
CALLDLY25M
CALLDLY25M
DJNZR0,DLOP11
RET
;lianxvwrsub==============
wr123:
nop
SETBP1.4;/CS=1
CALLDLY5
NOP
CLRP1.4;/CS=0
CALLDLY5
CLRP1.3;/WR=0
CALLDLY5
SETBP1.2;D=1(101)
CALLDLY5
SETBP1.3;/WR=1
CALLDLY5
CLRP1.3;/WR=0
CALLDLY5
CLRP1.2;D=0
CALLDLY5
SETBP1.3;/WR=1
CALLDLY5
CLRP1.3;/WR=0
CALLDLY5
SETBP1.2;D=1
CALLDLY5
SETBP1.3;/WR=1
CALLDLY5
MOVR2,#6
LOOP:
CLRP1.3;/WR=0
CALLDLY5
CLRP1.2;D=0
CALLDLY5
SETBP1.3;/WR=1
CALLDLY5
DJNZR2,LOOP
mOVR3,#10
MOVDPTR,#TABDA
MOV34H,#0AH
;MOV35H,#0AH
MOV36H,#0AH
movr0,#31h
mov42h,r0
LOOP1:
MOVA,42H
CJNEA,#32H,WU
MOVA,@R0
ADDA,#11
AJMPYOU
WU:
mova,@r0
YOU:
movb,#03h
mulab
mov41h,a
MOVCA,@A+DPTR
MOV25H,A
CALLWRDA
inc41h
mova,41h
movca,@a+dptr
mov25h,a
callwrda
inc