📄 wenduceshiyi
字号:
swapf lbyte_date,w ;以下是对收到的两个字节进行处理
andlw 0x0f ;将高字节的低4位与低字节的高4位组成一个字节
movwf w_temp
swapf hbyte_date,w
andlw 0xf0
iorwf w_temp,w
movwf L_byte ;将组成的字节作为二进制数转BCD码子程序的入口参数
movlw 0x00
movwf H_byte ;无需用到高字节,直接赋0
call btobcd ;调用二进制数转BCD码子程序(Btobcd在页1,所以要选页)
swapf R2,w ;以下对转换后的结果处理再送显
andlw 0x0f ;将bcd码高位取出变ASCII码送显
iorlw 30h
movwf comp_h
bsf porte,0
call inlcd
call afterdatalcd
movf R2,w ;将bcd码低位取出变ASCII码送显
andlw 0x0f
iorlw 30h
movwf comp_l
bsf porte,0
call inlcd
call afterdatalcd
btfsc lbyte_date,3 ;以下判断浮点
call decimal5 ;低字节第4位是1就显示.5
btfss lbyte_date,3 ;低字节第4位是0就显示.0
call decimal0
bsf porte,0 ;显示"o"
movlw b'11011111'
call inlcd
call afterdatalcd
bsf porte,0 ;显示"C"
movlw b'01000011'
call inlcd
call afterdatalcd
call delay250ms
call delay250ms
call delay250ms
call delay250ms
call delay250ms
call delay250ms
call delay250ms
call delay250ms
; call keycheck1 ;返回键盘扫描
return
;***************************温度的小数位显示为.5的子程序*****************************************
decimal5
bsf porte,0
movlw b'00101110' ;显示"."
call inlcd
call afterdatalcd
bsf porte,0
movlw b'00110101' ;显示"5"
call inlcd
call afterdatalcd
return
;**************************温度的小数位显示为.0的子程序*****************************************
decimal0
bsf porte,0
movlw b'00101110' ;显示"."
call inlcd
call afterdatalcd
bsf porte,0
movlw b'00110000' ;显示"0"
call inlcd
call afterdatalcd
return
;********************************18b20初始化的子程序*********************************************
;************************************************************************************************
ini
bsf status,5
bcf trisc,0 ;rc0置为输出
bcf status,5
nop
bcf portc,0
movlw .172
movwf count1
inilp ;(172+1)*3=519us的延时
decfsz count1,1
goto inilp
nop;
bsf status,5
bsf trisc,0 ;rc0置为输入
bcf status,5
movlw .20
movwf count1
inilp2 ;(20+1)*3=63us的延时
decfsz count1,1
goto inilp2
btfsc portc,0 ;检测是否收到18b20拉低总线的应答
goto ini ;否!重新初始化
movlw .172
movwf count1
inilp3 ;收到应答信号,(172+1)*3=519us的延时
decfsz count1,1
goto inilp3
return;
;****************************************18b20的写1的子程序**************************************
;************************************************************************************************
write1
bsf status,5
bcf trisc,0 ;Rc0置为输出
bcf status,5
bcf portc,0 ;主机拉低总线
nop
nop
nop
bsf status,5
bsf trisc,0 ;5us<15us,rc0置为输入(释放总线)
nop;
bcf status,5
movlw .22
movwf count1
wr1lp
decfsz count1,1 ;(20+1)*3=63us间隔
goto wr1lp
return;
;*****************************************18b20的写0子程序**************************************
;***********************************************************************************************
write0
bsf status,5
bcf trisc,0 ;rc0置为输出
bcf status,5
nop;
bcf portc,0 ;主机拉低总线
movlw .22
movwf count1
wr0lp
decfsz count1,1
goto wr0lp ;(20+1)*3=63us>60us的间隔
bsf status,5
bsf trisc,0 ;rc0置为输入(释放总线)
nop
nop
bcf status,5
nop
return
;*********************************收取18b20的一位数据子程序*************************************
;***********************************************************************************************
bit_rx
bsf status,5
bcf trisc,0 ;rc0置为输出
bcf status,5
bcf portc,0 ;主机拉低总线
nop
nop
bsf status,5
bsf trisc,0 ;rc0置为输入
nop
nop
bcf status,5
nop
movf portc,0 ;8us<15us收取18b20发送来的信号
andlw 01h ;就取收到的该位,并存于temp中
movwf temp
movlw .22
movwf count1
rxlp ;(20+1)*3=63us>60us的间隔
decfsz count1,1
goto rxlp
return;
;************************一次过收取18b20发送来两个字节的数据子程序*****************************
;**********************************************************************************************
byte_rx
clrf lbyte_date ;低字节数据存于lbyte_date
call bit_rx ;读一位,收取该位数据
movf temp,0
iorwf lbyte_date,1 ;以或(每位相加)的形式存于lbyte_date
rrf lbyte_date,1 ;lbyte_date右移一位
;以下相同,一共读八次,收取一个字节
call bit_rx
movf temp,0
iorwf lbyte_date,1
rrf lbyte_date,1
call bit_rx
movf temp,0
iorwf lbyte_date,1
rrf lbyte_date,1
call bit_rx
movf temp,0
iorwf lbyte_date,1
rrf lbyte_date,1
call bit_rx
movf temp,0
iorwf lbyte_date,1
rrf lbyte_date,1
call bit_rx
movf temp,0
iorwf lbyte_date,1
rrf lbyte_date,1
call bit_rx
movf temp,0
iorwf lbyte_date,1
rrf lbyte_date,1
call bit_rx
movf temp,0
iorwf lbyte_date,1
rrf lbyte_date,1
rrf lbyte_date,1
clrf hbyte_date ;高字节数据存于hbyte_date
call bit_rx ;读一位,收取该位数据
movf temp,0 ;以或(每位相加)的形式存于hbyte_date
iorwf hbyte_date,1 ;hbyte_date右移一位
rrf hbyte_date,1 ;以下相同,一共读八次,收取一个字节
call bit_rx
movf temp,0
iorwf hbyte_date,1
rrf hbyte_date,1
call bit_rx
movf temp,0
iorwf hbyte_date,1
rrf hbyte_date,1
call bit_rx
movf temp,0
iorwf hbyte_date,1
rrf hbyte_date,1
call bit_rx
movf temp,0
iorwf hbyte_date,1
rrf hbyte_date,1
call bit_rx
movf temp,0
iorwf hbyte_date,1
rrf hbyte_date,1
call bit_rx
movf temp,0
iorwf hbyte_date,1
rrf hbyte_date,1
call bit_rx
movf temp,0
iorwf hbyte_date,1
rrf hbyte_date,1
rrf hbyte_date,1
return;
;***************************************读命令(0xbe)子程序**********************************
;*******************************************************************************************
resignal
call write0
nop
call write1
nop
call write1
nop
call write1
nop
call write1
nop
call write1
nop
call write0
nop
call write1
return
;***************************************转换命令(0x44)子程序**********************************
;*********************************************************************************************
convert
call write0
nop
call write0
nop
call write1
nop
call write0
nop
call write0
nop
call write0
nop
call write1
nop
call write0
return
;************************************跳过序列号检测命令(0xcc)子程序****************************
;**********************************************************************************************
skipid
call write0
nop;
call write0
nop;
call write1
nop;
call write1
nop;
call write0
nop;
call write0
nop;
call write1
nop;
call write1
return;
;*******************************************
;----------------sound------------------
sound bsf status,rp0
movlw 00h
movwf trisc
movlw 02h
movwf option_reg
bcf status,rp0
clrf portc
movlw 01h
movwf count4
t3lop call tone1s
decfsz count4,1
goto t3lop
return
;****************************
tone1s
movlw .10
movwf count2
t1lop
call tone500
call tone630
decfsz count2,1
goto t1lop
return
;*************************
tone500
movlw .50
movwf count
t5lop
bcf intcon,t0if
movlw .131
movwf tmr0
t5here
btfss intcon,t0if
goto t5here
movlw b'00100000'
xorwf portc,1
decfsz count,1
goto t5lop
return
;******************************
tone630
movlw .63
movwf count1
t6lop
bcf intcon,t0if
movlw .157
movwf tmr0
t6here
btfss intcon,t0if
goto t6here
movlw b'00100000'
xorwf portc,1
decfsz count1,1
goto t6lop
return
;******************************************************************************************
btobcd
bcf status,0 ; clear the carry bit
movlw .16
movwf count
clrf R0
clrf R1
clrf R2
loop16 rlf L_byte,1
rlf H_byte,1
rlf R2,1
rlf R1,1
rlf R0,1
;
decfsz count,1
goto adjDEC
RETLW 0
;
adjDEC movlw R2
movwf fsr
call adjBCD
;
movlw R1
movwf fsr
call adjBCD
;
movlw R0
movwf fsr
call adjBCD
;
goto loop16
;
adjBCD movlw 3
addwf 0,W
movwf temp
btfsc temp,3 ; test if result > 7
movwf 0
movlw 30
addwf 0,W
movwf temp
btfsc temp,7 ; test if result > 7
movwf 0 ; save as MSD
RETLW 0
;******************************************
afterdatalcd
movlw 0x00 ;使得rs(e端口最低位)为0
movwf porte
call delaylcd ;调用液晶延时
return
;*****************************************************************************************
delay1ms
movlw .6
movwf count1
de1mslp1
movlw .5
movwf count2
de1mslp2
nop
decfsz count2,1
goto de1mslp2
decfsz count1,1
goto de1mslp1
retlw 0
;*************************************************
delay250ms
movlw .251
movwf count1
de1
movlw .250
movwf count2
de2
nop
decfsz count2,1
goto de2
decfsz count1,1
goto de1
retlw 0
mainend
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -