单片机小车调速程序.docx
- 文档编号:24277170
- 上传时间:2023-05-26
- 格式:DOCX
- 页数:15
- 大小:16.49KB
单片机小车调速程序.docx
《单片机小车调速程序.docx》由会员分享,可在线阅读,更多相关《单片机小车调速程序.docx(15页珍藏版)》请在冰豆网上搜索。
单片机小车调速程序
;/********伪指令********/按键控制小车调速
ORG0000H
SJMPMAIN1
ORG0013H
LJMPZD
ORG0030H
MAIN1:
LCALLPWM
MAIN:
SETBEA
SETBEX1
SETBIT1
SJMP$
ZD:
PUSHACC
PUSH04H
PUSH05H
PUSH06H
MOVA,P2
ANLA,#0F0H
CJNEA,#70H,PD1
LCALLQJ
SJMPJS
PD1:
CJNEA,#0B0H,PD2
LCALLHT
SJMPJS
PD2:
CJNEA,#0D0H,PD3
LCALLZZ
SJMPJS
PD3:
CJNEA,#0E0H,JS
LCALLYZ
JS:
POP06H
POP05H
POP04H
POPACC
RETI
DEL05S:
MOVR4,#10
D3:
MOVR5,#200
D4:
MOVR6,#124
DJNZR6,$
DJNZR5,D4
DJNZR4,D3
RET
PWM:
MOVCMOD,#04H
MOVTMOD,#02H
MOVTH0,#130
MOVTL0,#130
SETBTR0
RET
TZ:
MOVCCON,#00H
SETBP1.4
SETBP1.5
SETBP1.6
SETBP1.7
MOVCCAPM1,#00H
MOVCCAPM2,#00H
MOVCCAPM3,#00H
MOVCCAPM4,#00H
RET
QJ:
LCALLTZ
MOVCCAPM2,#42H
MOVCCAPM4,#42H
MOVCCAP2H,#100
MOVCCAP4H,#100
MOVCCON,#40H
RET
ZZ:
LCALLTZ
MOVCCAPM2,#42H
MOVCCAPM4,#42H
MOVCCAP2H,#50
MOVCCAP4H,#100
MOVCCON,#40H
RET
YZ:
LCALLTZ
MOVCCAPM2,#42H
MOVCCAPM4,#42H
MOVCCAP2H,#100
MOVCCAP4H,#50
MOVCCON,#40H
RET
HT:
LCALLTZ
MOVCCAPM1,#42H
MOVCCAPM3,#42H
MOVCCAP1H,#100
MOVCCAP3H,#100
MOVCCON,#40H
RET
END
拍手控制小车调速
ORG0000H
SJMPMAIN1
ORG0003H
LJMPZD
ORG0030H
MAIN1:
LCALLPWM
MAIN:
SETBEA
SETBEX0
SETBIT0
CF:
MOVR7,#0
L:
CJNER7,#0,PD1
LCALLTZ
SJMPL
PD1:
CJNER7,#1,PD2
LCALLQJ
SJMPL
PD2:
CJNER7,#2,PD3
LCALLZZ
SJMPL
PD3:
CJNER7,#3,PD4
LCALLYZ
SJMPL
PD4:
CJNER7,#4,PD5
LCALLHT
SJMPL
PD5:
CJNER7,#5,L
SJMPCF
ZD:
INCR7
RETI
DEL05S:
MOVR4,#10
D3:
MOVR5,#200
D4:
MOVR6,#124
DJNZR6,$
DJNZR5,D4
DJNZR4,D3
RET
PWM:
MOVCMOD,#04H
MOVTMOD,#02H
MOVTH0,#130
MOVTL0,#130
SETBTR0
RET
TZ:
MOVCCON,#00H
SETBP1.4
SETBP1.5
SETBP1.6
SETBP1.7
MOVCCAPM1,#00H
MOVCCAPM2,#00H
MOVCCAPM3,#00H
MOVCCAPM4,#00H
RET
QJ:
LCALLTZ
MOVCCAPM2,#42H
MOVCCAPM4,#42H
MOVCCAP2H,#100
MOVCCAP4H,#100
MOVCCON,#40H
RET
ZZ:
LCALLTZ
MOVCCAPM2,#42H
MOVCCAPM4,#42H
MOVCCAP2H,#50
MOVCCAP4H,#100
MOVCCON,#40H
RET
YZ:
LCALLTZ
MOVCCAPM2,#42H
MOVCCAPM4,#42H
MOVCCAP2H,#100
MOVCCAP4H,#50
MOVCCON,#40H
RET
HT:
LCALLTZ
MOVCCAPM1,#42H
MOVCCAPM3,#42H
MOVCCAP1H,#100
MOVCCAP3H,#100
MOVCCON,#40H
RET
END
定时器控制
ORG0000H
SJMPMAIN
ORG0003H
SJMPZD1
ORG001BH
SJMPZD2
ORG0030H
MAIN:
CLRF0
CLRP1.0
MOVR7,#60
MOVTH1,#60
MOVTL1,#176
MOVTMOD,#10H
SETBIT0
SETBEX0
SETBEA
SETBET1
SETBTR1
SJMP$
ZD2:
MOVTH1,#60
MOVTL1,#176
JBF0,L
LCALLSSZXZ
DJNZR7,JS
CPLF0
MOVR7,#100
RETI
L:
LCALLNSZXZ
DJNZR7,JS
CPLF0
MOVR7,#60
JS:
RETI
ZD1:
SETBP1.4
SETBP1.5
SETBP1.6
SETBP1.7
SJMP$
RETI
SSZXZ:
SETBP1.4
SETBP1.7
MOVP0,#03H
CLRP1.5
CLRP1.6
RET
NSZXZ:
SETBP1.5
SETBP1.6
MOVP0,#9FH
CLRP1.4
CLRP1.7
RET
END
秒表ORG0000H
MAIN:
MOVDPTR,#TAB
MOV30H,#00H
MOVR0,#60
NEXT:
MOV42H,30H
LCALLSZZH
MOV41H,43H
MOVR1,#100
PCH:
LCALLXS
DJNZR1,PCH;刷100次,10ms=1S
INC30H
DJNZR0,NEXT
SJMPMAIN
XS:
MOVA,30H
ANLA,#0FH
MOVCA,@A+DPTR
SETBP1.0
CLRP1.1
MOVP0,A
LCALLDEL
MOVP0,#0FFH
MOVA,30H
SWAPA;十位个位想换
ANLA,#0FH
MOVCA,@A+DPTR
SETBP1.1
CLRP1.0
MOVP0,A
LCALLDEL
MOVP0,#0FFH
RET
SZZH:
MOVA,42H
MOVR2,A
JZEXIT
CLRA
CLRC
XH:
INCA
DAA
DJNZR2,XH
EXIT:
MOV43H,A
RET
TAB:
DB03H,9FH,25H,0DH,99H,49H,41H,1FH
DB01H,09H,11H,0C1H,63H,85H,61H,71H
DEL:
MOVR7,#1;5ms
DEL2:
MOVR6,#20
DEL1:
MOVR5,#123
DEL0:
DJNZR5,DEL0
DJNZR6,DEL1
DJNZR7,DEL2
RET
END
小车障碍物检测
ORG0000H
MAIN:
;CLRP1.0;位选
CLRP2.2;关闭左发
CLRP3.7;关闭右发
LCALLZB;呼叫左边检测子程序
CLRP2.2;关闭左发
LCALLYB;呼叫左边检测子程序
CLRP3.7;关闭右发
LCALLPJ;呼叫判决子程序
SJMPMAIN;跳转到开始
ZB:
MOVR0,#10/*设定10个脉冲*/
MOVR1,#0/*给寄存器清0*/
FS:
SETBP2.2/*发射红外线*/
LCALLDEL600us/*延时600us*/
JBP2.3,GB/*判断接收端是否是低电平*/
INCR1/*脉冲R1自加1*/
GB:
CLRP2.2/*关闭发射红外*/
LCALLDEL600us
DJNZR0,FS/*判断10个脉冲是否发送完毕*/
CJNER1,#6,PCH
PCH:
JCZH
SETB00H;左前有障碍物
RET
ZH:
CLR00H;左前没有障碍物
RET
YB:
MOVR2,#10;右边检测子程序
MOVR3,#0
FS1:
SETBP3.7
LCALLDEL600us
JBP3.3,GB1
INCR3
GB1:
CLRP3.7
LCALLDEL600us
DJNZR2,FS1
CJNER3,#6,PCH1
PCH1:
JCZH1
SETB01H;右前有障碍物
RET
ZH1:
CLR01H;右前没有障碍物
RET
PJ:
CLRP1.0
MOVA,20H;判决子程序,,把20H单元的内容给A
ANLA,#03H;A与03H相与
CJNEA,#00H,ZQ;A等于00H吗?
不相等跳转到左边判决
MOVP0,#03H
SETBP1.4
SETBP1.6
LCALLDEL05S
CLRP1.5
CLRP1.7;给P0端送段码,障碍物没有
RET
ZQ:
CJNEA,#01H,YQ;A等于01H吗?
不相等跳转到右边判决
MOVP0,#9FH
SETBP1.4
SETBP1.5
SETBP1.7;送断码,障碍物在左前
LCALLDEL05S
CLRP1.6
RET
YQ:
CJNEA,#02H,ZQ1;A等于02H吗?
不相等跳转到正前
MOVP0,#25H
SETBP1.5
SETBP1.6
SETBP1.7;送断码,障碍物在右前
LCALLDEL05S
CLRP1.4
RET
ZQ1:
MOVP0,#0DH
SETBP1.5
SETBP1.7;送断码,障碍物在正前
LCALLDEL05S
CLRP1.6
CLRP1.4
RET
DEL600us:
MOVR4,#200/*延时600us*/
DEL4:
NOP
DJNZR4,DEL4
RET
DEL05S:
MOVR5,#10
DEL2:
MOVR6,200
DEL1:
MOVR7,123
DEL0:
NOP
DJNZR7,DEL0
DJNZR6,DEL1
DJNZR5,DEL2
RET
END
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 单片机 小车 调速 程序