用 CMP 指令编写简单密码锁程序。系统密码假设为 5231(非统一要求),用户依次输入 5,2,3,1 对应的 BCD 码,每输入一个密码后按一下确认键,共需输入 4 个密码。程序将用户输 入的数值和程序里设定的密码进行比较,如果匹配,则系统自动开锁(Y0~Y7 全亮)。如果用 户输入的密码有错,则提示出错。按下复位键后又可重新输密码。 输入密码按钮:X10,X11,X12,X13(4 按键可形成 1 位 BCD 码) 确认键:X20 复位键:X21 开锁:Y0~Y7 密码错误指示灯:Y10
时间: 2023-06-15 17:04:04
浏览: 51
以下是使用CMP指令编写的简单密码锁程序:
$NOMOD
LD X10 ;读取第一位密码
CMP #5
JNE ERROR ;如果不匹配,跳转到[错误处理](https://geek.csdn.net/educolumn/09015d7487fe01148ae2ba36e386933b?spm=1055.2569.3001.10083)
LD X11 ;读取第二位密码
CMP #2
JNE ERROR ;如果不匹配,跳转到[错误处理](https://geek.csdn.net/educolumn/09015d7487fe01148ae2ba36e386933b?spm=1055.2569.3001.10083)
LD X12 ;读取第三位密码
CMP #3
JNE ERROR ;如果不匹配,跳转到[错误处理](https://geek.csdn.net/educolumn/09015d7487fe01148ae2ba36e386933b?spm=1055.2569.3001.10083)
LD X13 ;读取第四位密码
CMP #1
JNE ERROR ;如果不匹配,跳转到[错误处理](https://geek.csdn.net/educolumn/09015d7487fe01148ae2ba36e386933b?spm=1055.2569.3001.10083)
LD #255
OUT Y0-Y7 ;密码匹配,开锁
JMP END
ERROR:
LD #0
OUT Y10 ;密码错误指示灯亮
LD #0
OUT Y10 ;关闭密码错误指示灯
JMP START
JMP START
START:
LD X20 ;等待[确认](https://geek.csdn.net/educolumn/08ce1c98201e391e324feee424502262?spm=1055.2569.3001.10083)键按下
```
相关推荐

















