51单片机简易电梯控制程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

51单片机简易电梯控制程序

ORG 00H

N1 EQU 0020H ;系统初始化

ORG 0030H

MOV R0,#8

MOV R7,#0

MOV N1,#0

START: MOV R2,#15

CALL XS ;显示数据

JNB P3.5,$ ;检测急停键是否弹起

CALL XIAODOU

JNB P3.5,$

CALL XINCEN

CALL ANJ

JMP START

XINCEN: ;扫描急停键

JB P3.5,B0

CALL XIAODOU

JB P3.5,B0

CALL XIAODOU

JB P3.5,B0

CALL XIAODOU

JB P3.5,B0

CALL XIAODOU

JB P3.5,B0

SETB P0.7 ;关闭输出

SETB P0.5

MOV N1,#0 ;清空指令代码

MOV R2,#0

JMP START ;返回开始

RET

B0: JB P0.3,B1 ;扫描一楼行程,获取楼层信号

CALL XIAODOU

JB P0.3,B1

CALL XIAODOU

JB P0.3,B1

CALL XIAODOU

JB P0.3,B1

CALL XIAODOU

JB P0.3,B1

MOV R0,#1 ;载入1层代码1,2表示1层半,3表示2层,4表

示2层半,5表示3层,6表示3层半,7表示4层

MOV R7,#1

CALL XS ;显示数据

RET

B1: JB P0.2,B2 ;扫描2楼行程,获取楼层信号CALL XIAODOU

JB P0.2,B2

CALL XIAODOU

JB P0.2,B2

CALL XIAODOU

JB P0.2,B2

CALL XIAODOU

JB P0.2,B2

MOV R0,#3 ;载入2层代码

MOV R7,#2

CALL XS

RET

B2: JB P0.1,B3 ;扫描3楼行程,获取楼层信号CALL XIAODOU

JB P0.1,B3

CALL XIAODOU

JB P0.1,B3

CALL XIAODOU

JB P0.1,B3

CALL XIAODOU

JB P0.1,B3

MOV R0,#5 ;载入3层代码

MOV R7,#3

CALL XS

RET

B3: JB P0.0,ANJ ;扫描4楼行程,获取楼层信号CALL XIAODOU

JB P0.0,ANJ

CALL XIAODOU

JB P0.0,ANJ

CALL XIAODOU

JB P0.0,ANJ

CALL XIAODOU

JB P0.0,ANJ

MOV R0,#7 ;载入4层代码

MOV R7,#4

CALL XS

RET

ANJ: JB P2.0,C1 ;扫描按键,获取目的层CALL XIAODOU

JB P2.0,C1

CALL XIAODOU

JB P2.0,C1

CALL XIAODOU

JB P2.0,C1

CALL XIAODOU

JNB P2.0,$

MOV N1,#1 ;载入目的1楼代码,R6为副寄存器MOV R6,#1

MOV R2,#10

CALL XS

CALL BIJAO

RET

C1: JB P2.1,C2

CALL XIAODOU

JB P2.1,C2

CALL XIAODOU

JB P2.1,C2

CALL XIAODOU

JB P2.1,C2

CALL XIAODOU

JNB P2.1,$

MOV N1,#3 ;载入目的2楼代码,R6为副寄存器

MOV R6,#3

MOV R2,#11

CALL XS

CALL BIJAO

RET

C2: JB P2.2,C3

CALL XIAODOU

JB P2.2,C3

CALL XIAODOU

JB P2.2,C3

CALL XIAODOU

JB P2.2,C3

CALL XIAODOU

JNB P2.2,$

MOV N1,#5 ;载入目的3楼代码,R6为副寄存器MOV R6,#5

MOV R2,#12

CALL XS

CALL BIJAO

RET

C3: JB P2.3,TIAO

CALL XIAODOU

JB P2.3,TIAO

CALL XIAODOU

JB P2.3,TIAO

CALL XIAODOU

JB P2.3,TIAO

CALL XIAODOU

JNB P2.3,$

MOV N1,#7 ;载入目的4楼代码,R6为副寄存器

MOV R6,#7

MOV R2,#4

CALL XS

CALL BIJAO

RET

TIAO:JMP XINCEN

RET

BIJAO: ;楼层比较子程序

MOV A,R0 ;楼层数与目的层不相等则转到大小比较段,比较大小

CJNE A,N1,DIFF

JMP START

DIFF: JNC NEXT ;没有进位,说明目的层小于楼层,转到下行段JMP UP ;有进位,说明目的层大于楼层,转到上行段RET

NEXT: JMP DOWN

RET

UP: CLR P0.4 ;输出关门指令

CALL OPEN ;关门时间延时

SETB P0.4 ;关门完成

CALL OPENDOOR

K1: SETB P0.5 ;上行子程序段,禁止向下动作,输出上行指令CLR P0.7

CALL XINCEN ;扫描行程,按键

CALL CUZUO ;检测否出错

MOV A,R0

CJNE A,N1,D1 ;判断是否到达指定层,没有则继续上行,到达则关闭上行,返回开始

SETB P0.7

CALL OPENDOOR

CLR P0.6 ;输出开门指令

CALL OPEN ;关门时间延时

相关文档
最新文档