📄 13组源程序.txt
字号:
call delay4ms
;**************关显示*********************
setcommand
movlw 08h
movwf portd
clearcommand
call delay4ms
;*************显示开关控制 增量方式 光标移位 **************
setcommand
movlw 0x0e
movwf portd
clearcommand
call delay4ms
;************设定输入方式***************
setcommand
movlw 06h
movwf portd
clearcommand
call delay4ms
;************清屏**************
setcommand
movlw 01h
movwf portd
clearcommand
call delay4ms
return
;**********************************
showstring
clrf temp_reg
waitchar
call stringtable ;显示"WELCOME USE"
call sendchar
incf temp_reg,1
movlw 0x0b
subwf temp_reg,0
btfss status,z
goto waitchar
return
;*************************************
sendchar
movwf temp_char
movlw 03h
movwf porte
movf temp_char,w
movwf portd
movlw 00h
movwf porte
call delay4ms
return
;***************************************
delay4ms ;延时4毫秒
lp2 movlw d'37'
movwf data2
loop2 movlw d'31'
movwf data1
loop3 decfsz data1,1
goto loop3
decfsz data2,1
goto loop2
return
;**************************************************************
;***********************矩阵键盘扫描与按键识别*****************
line1
movlw 00h ;计数器清零
movwf count3
call jian ;调用键盘扫描程序
sublw 0ah ;识别按键是否为'A'
btfss status,z
goto line1 ;继续等待'A'
goto line2 ;开始输入密码
;***************键盘扫描************************
jian
bcf status,rp1 ;体1
bsf status,rp0
movlw 00fh ;端口b设置
movwf trisb
movlw 0f0h ;端口d设置
movwf trisd
bcf status,rp0 ;体0
;****************键盘位置码表*************************
movlw 0dbh ;0
movwf 40h
movlw 77h ;1
movwf 41h
movlw 7bh ;2
movwf 42h
movlw 7dh ;3
movwf 43h
movlw 7eh ;4
movwf 44h
movlw 0b7h ;5
movwf 45h
movlw 0bbh ;6
movwf 46h
movlw 0bdh ;7
movwf 47h
movlw 0beh ;8
movwf 48h
movlw 0d7h ;9
movwf 49h
movlw 0ddh ;a
movwf 4ah
movlw 0deh ;b
movwf 4bh
movlw 0e7h ;c
movwf 4ch
movlw 0ebh ;d
movwf 4dh
movlw 0edh ;e
movwf 4eh
movlw 0eeh ;f
movwf 4fh
;****************************************
check
call keyscan ;调用键盘扫描子程序
comf value,0 ;位置码取反
btfsc status,z ;测试有键按下否
goto check ;没有,继续检测
movlw .13 ;预置外循环变量
movwf data2 ;产生10毫秒延时
call delay ;调用延时子程序,消除抖动影响
call keyscan ;调用键盘扫描子程序
comf value,0 ;位置码取反
btfsc status,z ;测试有键按下否
goto check ;没有,继续检测
call translate ;调用键值翻译子程序
check1
movlw .117 ;预置外循环变量
movwf data2 ;产生100毫秒延时
call delay ;调用延时子程序,消除抖动影响
call keyscan ;调用键盘扫描子程序
comf value,0 ;位置码取反
btfss status,z ;测试按键释放否
goto check1 ;否继续检测
movf fsr,0 ;键值送w
return
;***************************************************
;***************键盘扫描子程序**********************
keyscan
bcf status,rp1 ;初始化
bsf status,rp0
bcf option_reg,rbup
movlw 00h
movwf trisd
movlw 0ffh
movwf trisb
bcf status,rp0
;***************************************
movlw 07fh ;判断第一行
movwf portd ;d端口输入01111111
nop
nop
movf portb,0 ;取出b端口的值(列号)
andlw 0fh ;保留低四位
movwf value ;保存到value
xorlw 0fh ;判断是否变化
btfss status,z
goto nokey1
;*******************************
movlw 0bfh ;没变化判断第二行
movwf portd ;d端口输入10111111
nop
nop
movf portb,0 ;取出b端口的值(列号)
andlw 0fh ;保留低四位
movwf value ;保存到value
xorlw 0fh ;判断是否变化
btfss status,z
goto nokey2
;****************************************
movlw 0dfh ;没变化判断第三行
movwf portd ;d端口输入11011111
nop
nop
movf portb,0 ;取出b端口的值(列号)
andlw 0fh ;保留低四位
movwf value ;保存到value
xorlw 0fh ;判断是否变化
btfss status,z
goto nokey3
;***********************************
movlw 0efh ;没变化判断第四行
movwf portd ;d端口输入11101111
nop
nop
movf portb,0 ;取出b端口的值(列号)
andlw 0fh ;保留低四位
movwf value ;保存到value
xorlw 0fh ;判断是否变化
btfss status,z
goto nokey4
goto nokey
nokey
movlw 0ffh
movwf value
return
nokey1
movlw 070h ;行号与列号组合
iorwf value,1
return
nokey2
movlw 0b0h
iorwf value,1
return
nokey3
movlw 0d0h
iorwf value,1
return
nokey4
movlw 0e0h
iorwf value,1
return
;******************************************
;*************键值翻译程序*****************
translate
movlw 40h
movwf fsr
loopt1
movf 0,0
xorwf value,0
btfsc status,z
goto loopt2
incf fsr,1
btfss fsr,4
goto loopt1
movlw 0aah
movwf fsr
return
loopt2
bcf fsr,6
return
;********延时程序**********
delay
lp0 movlw n2
movwf data1
lp1 decfsz data1,1
goto lp1
decfsz data2,1
goto lp0
return
;******************************************
line2
call clearcommand1 ;清屏
call showstring1 ;输出提示语'ENTER THE CODE'
movlw 02h ;光标换行
movwf porte
movlw 0c0h
movwf portd
movlw 00h
movwf porte
call delay4ms
movlw 092h ;上锁状态显黄灯
movwf portc
goto line3 ;键盘扫描,识别密码
;***************清屏子程序********************
clearcommand1
bsf status,rp0 ;体1
bcf status,rp1
clrf trise ;端口设置
clrf trisd
bcf status,rp0 ;体0
setcommand
movlw 01h
movwf portd
clearcommand
call delay4ms
return
;************************************
showstring1 ;输出'ENTER THE CODE'
clrf temp_reg
waitchar1
call stringtable1
call sendchar
incf temp_reg,1
movlw 0x0e
subwf temp_reg,0
btfss status,z
goto waitchar1
return
;******************************************
line3
call jian ;键盘扫描,识别密码
call cunm1
call jian
call cunm2
call jian
call cunm3
call jian
call cunm4
call jian
call cunm5
call jian
call cunm6
jian1
call jian
sublw 0bh ;识别按键是否为'B'
btfss status,z
goto jian1
bsf status,rp0
bsf status,rp1
clrf addr
call read
call cunym1
call read
call cunym2
call read
call cunym3
call read
call cunym4
call read
call cunym5
call read
call cunym6
call bijiao
movf mm6,0
sublw 06h
btfss status,z
call showwrong ;"code is wrong"
call showstring2 ;"code is right"
goto line5 ;选择是否更改密码
;*************************************************
;***************读取密码EEPROM********************
read
bcf status,rp0
bsf status,rp1 ;体2
movf addr,w
movwf eeadr ;取地址
bsf status,rp0 ;体3
bcf eecon1,eepgd ;选定EEPROM为访问对象
bsf eecon1,rd ;启动读操作
bcf status,rp0 ;体2
movf eedata,w ;取数据
bcf status,rp1 ;体0
incf addr,f ;地址加1
return
;**************暂存原密码*****************
cunym1
movwf ym1
return
cunym2
movwf ym2
return
cunym3
movwf ym3
return
cunym4
movwf ym4
return
cunym5
movwf ym5
return
cunym6
movwf ym6
return
;**************暂存输入密码********************
cunm1
movwf m1
call xianmima
return
cunm2
movwf m2
call xianmima
return
cunm3
movwf m3
call xianmima
return
cunm4
movwf m4
call xianmima
return
cunm5
movwf m5
call xianmima
return
cunm6
movwf m6
call xianmima
return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -