📄 wenduceshiyi
字号:
call keyinidis
movf lcdcode,0
movwf maxl
call keycheck2
call savemax
return
savemax
movf maxh,0
movwf maxh_temp
movf maxl,0
movwf maxl_temp
return
keycheck2
call scankeys
comf value,0
btfsc status,2 ;判断是否有按键
goto keycheck2 ;如果没有按键则返回keycheck2
movlw 02h
movwf 22h
call delay ;键盘防抖动,延时30ms*2=60ms
call scankeys
comf value,0 ;判断是否有按键
btfsc status,2
goto keycheck2 ;如果没有按键则返回keycheck2
movf value,w
xorlw b'11101101' ;按"E"储存
btfsc status,2
return ;显示时间其实就是调用"键盘无输入,显示时间子程序"
goto keycheck2
changemin
call inilcd
call clearlcd
bsf porte,0
movlw b'01010011' ;显示"S"
call inlcd
call delaylcd
bsf porte,0
movlw b'01100101' ;显示"e"
call inlcd
call delaylcd
bsf porte,0
movlw b'01110100' ;显示"t"
call inlcd
call delaylcd
bsf porte,0
movlw b'00100000' ;显示" "
call inlcd
call delaylcd
bsf porte,0
movlw b'01101101' ;显示"m"
call inlcd
call delaylcd
bsf porte,0
movlw b'01101001' ;显示"i"
call inlcd
call delaylcd
bsf porte,0
movlw b'01101110' ;显示"n"
call inlcd
call delaylcd
bsf porte,0
movlw b'00100000' ;显示" "
call inlcd
call delaylcd
bsf porte,0
movlw b'01110100' ;显示"t"
call inlcd
call delaylcd
bsf porte,0
movlw b'01100101' ;显示"e"
call inlcd
call delaylcd
bsf porte,0
movlw b'01101101' ;显示"m"
call inlcd
call delaylcd
bsf porte,0
movlw b'01110000' ;显示"p"
call inlcd
call delaylcd
bsf porte,0
movlw b'00111010' ;显示":"
call inlcd
call delaylcd
movlw b'11000000' ;换行显示
bcf porte,0
call inlcd
call afterdatalcd
bsf porte,0
movlw b'00100000' ;显示" "
call inlcd
call delaylcd
bsf porte,0
movlw b'00100000' ;显示" "
call inlcd
call delaylcd
bsf porte,0
movlw b'00100000' ;显示" "
call inlcd
call delaylcd
bsf porte,0
movlw b'00100000' ;显示" "
call inlcd
call delaylcd
call keyinidis
movf lcdcode,0
movwf minh
call keyinidis
movf lcdcode,0
movwf minl
call keycheck2
call savemin
return
savemin
movf minh,0
movwf minh_temp
movf minl,0
movwf minl_temp
return
keyinidis
;首先建表
movlw 77h ;将键盘的值"1"(01110111)传入41H
movwf 41h
movlw 7bh ;将键盘的值"2"(01111011)传入42H
movwf 42h
movlw 7dh ;将键盘的值"3"(01111101)传入43H
movwf 43h
movlw 7eh ;将键盘的值"4"(01111110)传入44H
movwf 44h
movlw 0xb7 ;将键盘的值"5"(10110111)传入45H
movwf 45h
movlw 0xbb ;将键盘的值"6"(10111011)传入46H
movwf 46h
movlw 0xbd ;将键盘的值"7"(10111101)传入47H
movwf 47h
movlw 0xbe ;将键盘的值"8"(10111110)传入48H
movwf 48h
movlw 0xd7 ;将键盘的值"9"(11010111)传入49H
movwf 49h
movlw 0xdb ;将键盘的值"0"(11011011)传入40H
movwf 40h
check
call scankeys ;进行键盘扫描
comf value,0 ;对按键值取反判断是否有键按下
btfsc status,2 ;无则VALUE取反全零,STATUS的Z为1
goto check ;没按下继续扫描,有则跳过
movlw 01h ;以下是通过delay延时来防抖动
movwf 22h
call delay ;延时30ms
call scankeys
comf value,0
btfsc status,2
goto check
call translate ;确定有键按下了,对按键进行译码
call display ;确认后,进行送显
return
;************************************************
scankeys ;RD7~RD4为行线,RB3~RB0为列线
;有键按下时value为位置码无按下时value为ff
bsf status,rp0 ;选择体1,使得D和B端口为输入
bcf option_reg,7 ;启动B口上拉电阻
movlw 0fh ;D端口的低4位为输入,高4位为输出
movwf trisd
movlw 0ffh ;B端口全为输入(这一步是为了从RB3~RB0获得列码)
movwf trisb
bcf status,rp0 ;恢复到体0
movlw 00h ;4条行线输出全0
movwf portd
nop
nop
movf portb,0 ;读取列线状态
andlw 0fh ;取出B端口的低4位
movwf value ;将其值送到value
xorlw 0fh ;检测是否有按键按下,没有按键则结果为全0
btfsc status,2 ;是0就跳过下条指令,说明有键按下
goto nokey ;没按键则调用"没有按键子程序"
row1 movlw 70h ;行线输出为01110000
movwf portd
nop ;等待输出稳定
nop
movf portb,0 ; 读取输入
andlw 0fh ;屏蔽高四位
xorlw 0fh ;与0f比较
btfsc status,2 ;状态位是否为0?否,在第一行
goto row2 ;是,不在第一行
movlw 70h ;将行码与列码
iorwf value,1 ;合并,送入value
return
row2 movlw 0b0h ;行线输出为10110000
movwf portd
nop ;等待输出稳定
nop
movf portb,0 ;读输入
andlw 0fh
xorlw 0fh ;与0f比较
btfsc status,2 ;状态位是否为0?否,在第二行
goto row3 ;是,不在第二行
movlw 0b0h ;将行码和列码合并,送入value
iorwf value,1
return
row3 movlw 0d0h ;行线输出为11010000
movwf portd
nop ;等待输出稳定
nop
movf portb,0;读输入
andlw 0fh;屏蔽高四位
xorlw 0fh;与0f比较
btfsc status,2 ;状态位是否为0?否,在第三行
goto row4;是,不在第三行
movlw 0d0h;将行码和列码合并,送入value
iorwf value,1
return
row4 movlw 0e0h ;行线输入为11100000
movwf portd
nop;等待
nop
movf portb,0;读输入
andlw 0fh
xorlw 0fh;与0f比较
btfsc status,2 ;状态位是否为0?否,在第四行
goto nokey;否,无键按下
movlw 0e0h;将行码和列码合并,送入value
iorwf value,1
return
nokey ;没有按键按下value为0ffh
movlw 0ffh
movwf value
return
;*******************************************************************
inlcd movwf portd ;将输出数据调到e端口
bsf porte,1 ;给与下降沿
nop
nop
nop
nop
nop
bcf porte,1
call delaylcd ;调用液晶延时
return
;*******************************************************
translate
movlw 40h
movwf fsr
loopt1
movf 0,0
xorwf value,0
btfsc status,2
goto loopt2
incf fsr,1
btfss fsr,5
goto loopt1
movlw 0aah
movwf fsr
return
loopt2
bcf fsr,6
return
;******************************************************
display
movf fsr,0
iorlw 30h
movwf lcdcode
bsf status,5
clrf trisd
clrf trise
bcf status,5
movf lcdcode,0
bsf porte,0
call inlcd
movlw 1ah
movwf 22h
call delay ;26*30ms=780ms的延时
return
;*********************************************************
clearlcd ;清除当前屏幕的显示
bcf porte,0;
movlw 01h ;液晶清屏的命令
call inlcd
return
;*******************************************************
delaylcd ;5ms的延时
movlw 8h ;将外层循环参数值8h经过W
movwf count1 ;送入用作外循环变量的20H单元
ylp0
movlw 0ffh ;将内层循环参数值0FFH经过
movlw count2 ;送入用作外循环变量的21H单元
ylp1
nop
decfsz count2,1
goto ylp1
decfsz count1,1
goto ylp0
return
;********************************************
delay
lp3 movlw 64h
movwf 20h
lp0 movlw 64h
movwf 21h
lp1 decfsz 21h,1
goto lp1
decfsz 20h,1
goto lp0
decfsz 22h,1
goto lp3
return
;************************************使用18b20(包括显示)****************************************
play18b20
bsf status,5 ;初始时令RC0为输入
bsf trisc,0
bcf status,5
call ini ;调用初始化18B20
call skipid ;写cch,跳过读取序列号
call convert ;写入转换命令,进行转换
call delay250ms ;2s左右的转换时间
call delay250ms
call delay250ms
call delay250ms
call delay250ms
call delay250ms
call delay250ms
call delay250ms
bsf status,5
movlw 00h ;令D端口为输出
movwf trisd
bcf status,5
call delay1ms ;显示当前温度前清屏
call clearlcd
call ini ;读取温度先初始化
call skipid ;再发送跳过读序列号命令
call resignal ;发送读命令
call byte_rx ;一次收取两个字节的数据
call tempdisplay ;显示温度
call compare
return
;***********************
compare
movf comp_h,0
subwf maxh_temp,0
btfss status,0
call sound
movf comp_l,0
subwf maxl_temp,0
btfss status,0
call sound
movf minh_temp,0
subwf comp_h,0
btfss status,0
call sound
movf minl_temp,0
subwf comp_l,0
btfss status,0
call sound
return
;***********************************温度显示子程序*********************************************
;**********************************************************************************************
tempdisplay
movlw b'01010100' ;显示"T "
bsf porte,0
call inlcd
call afterdatalcd
movlw b'01100101' ;显示"e "
bsf porte,0
call inlcd
call afterdatalcd
movlw b'01101101' ;显示"m "
bsf porte,0
call inlcd
call afterdatalcd
movlw b'01110000' ;显示"p "
bsf porte,0
call inlcd
call afterdatalcd
movlw b'01100101' ;显示"e "
bsf porte,0
call inlcd
call afterdatalcd
movlw b'01110010' ;显示"r "
bsf porte,0
call inlcd
call afterdatalcd
movlw b'01100001' ;显示"a "
bsf porte,0
call inlcd
call afterdatalcd
movlw b'01110100' ;显示"t "
bsf porte,0
call inlcd
call afterdatalcd
movlw b'01110101' ;显示"u "
bsf porte,0
call inlcd
call afterdatalcd
movlw b'01110010' ;显示"r "
bsf porte,0
call inlcd
call afterdatalcd
movlw b'01100101' ;显示"e "
bsf porte,0
call inlcd
call afterdatalcd
movlw b'11000000' ;换行显示
bcf porte,0
call inlcd
call afterdatalcd
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -