⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lxy.asm

📁 DS1620 - 12F675温度lcd显示
💻 ASM
字号:
;title "DS1620 - 12F675温度lcd显示 
;*************************************************************
;**------------ 歌林电子制作工作室 www.nbglin.com -----------**
;**tel:0574-88464538 email:picworld@126.com **
;************************************************************

; Shift Data:
; Bit 1 - Always High (Gate for "E")
; Bit 2 - RS Bit
; Bit 3 - LCD D4
; Bit 4 - LCD D5
; Bit 5 - LCD D6
; Bit 6 - LCD D7
;
; 
; 12F675 4 MHz 
; GPIO.0 is the LCD Data Bit
; GPIO.1 is the LCD Clock Bit
; GPIO.2 is the DS1620 Data Bit
; GPIO.3 is MCLR
; GPIO.4 is the DS1620 Clock Bit
; GPIO.5 is the DS1620 Reset Bit
;
;
LIST P=12F675, R=DEC 
INCLUDE "p12f675.inc"

#DEFINE Data GPIO,0
#DEFINE Clock GPIO,1
#DEFINE DSDQ GPIO,2
; MCLR uses GPIO,3
#DEFINE DSCLK GPIO,4
#DEFINE DSRST GPIO,5

org 0

bsf STATUS,RP0
movlw 0x00 
movwf TRISIO
movlw b'11011100' 
movwf OPTION_REG
clrf ANSEL 
bcf STATUS,RP0

clrf STATUS
clrf INTCON 
clrf GPIO

movlw 0x07
movwf CMCON 
call InitLCD
call SndMsg 
call InitDS

MAIN movlw 0xc0 ; line 2 on LCD
call SendINS

call GetTemp ; 读温度
call SendDEC ; LCD显示

goto MAIN
;---------------------------------------------------------------
; DS1620 子程序
StartC MACRO
bsf DSRST
ENDM

StopC MACRO
bcf DSRST
ENDM

InitDS StartC
movlw 0x0c 
call SndByte
movlw b'00001010' 
call SndByte
StopC

nop

StartC
movlw 0xEE 
call SndByte
StopC
return

GetTemp movlw 0xAA 
StartC
call SndByte 
nop
call RdByte 
StopC
return

SndByte movwf NOTemp 
movlw 8 
movwf NOTmp1
DSLoop1
bcf DSCLK
rrf NOTemp,f 
btfss STATUS,C 
goto DSCLR 
bsf DSDQ 
goto DSLp1
DSCLR bcf DSDQ
nop
DSLp1 bsf DSCLK
decfsz NOTmp1,f 
goto DSLoop1
return

RdByte clrf NOTemp 
movlw 8 
movwf NOTmp1
bsf STATUS,RP0 
bsf TRISIO,2
bcf STATUS,RP0
DSLoop2
bcf DSCLK 
nop
rrf NOTemp,f 
btfss DSDQ 
goto DSCLR2 
bsf NOTemp,7 
goto DSLp2
DSCLR2 bcf NOTemp,7
nop
DSLp2 bsf DSCLK
decfsz NOTmp1,f 
goto DSLoop2
bsf STATUS,RP0 
bcf TRISIO,2
bcf STATUS,RP0
movfw NOTemp 
return

;--------------------------------------------
; LCD Subroutines
Message 
addwf PCL,f 
dt "Hello DS1620",0

SndMsg clrf FSR 
OutLoop
movf FSR,w 
incf FSR,f
call Message
iorlw 0 
btfsc STATUS,Z
goto RtnSnd 
call SendCHAR 
goto OutLoop
RtnSnd return

InitLCD
call Dlay5 
call Dlay5
call Dlay5
call Dlay5

bcf STATUS,C 
movlw 0x03 
call NybbleOut 

call Dlay5 
EStrobe
call Dlay160 
EStrobe
call Dlay160 

bcf STATUS, C 
movlw 0x02 
call NybbleOut 
call Dlay160

movlw 0x028 
call SendINS

movlw 0x008 
call SendINS

movlw 0x001 
call SendINS
call Dlay5 

movlw 0x006 
call SendINS

movlw 0x00F 
call SendINS

return

SendDEC 
movwf TempBIN
bcf pt5,0 
btfsc TempBIN,0 
bsf pt5,0 
rrf TempBIN,f 
clrf Tens 
movlw 0x0A
count10 subwf TempBIN,f 
btfss STATUS,C 
goto SDEC1
incf Tens,f
goto count10
SDEC1 addwf TempBIN,w 
movwf Units
movfw Tens 
addlw a'0' 
call SendCHAR
movfw Units
addlw a'0' 
call SendCHAR
btfss pt5,0 
goto DEGC 
movlw a'.' 
call SendCHAR
movlw a'5'
call SendCHAR
DEGC movlw a' '
call SendCHAR
movlw a'D'
call SendCHAR
movlw a'e'
call SendCHAR
movlw a'g'
call SendCHAR
movlw a'C'
call SendCHAR
movlw a' '
call SendCHAR
movlw a' '
call SendCHAR
return

SendBIN 
movwf TempBIN ; 存温度值

movlw a'1'
btfss TempBIN,7
movlw a'0'
call SendCHAR

movlw a'1'
btfss TempBIN,6
movlw a'0'
call SendCHAR

movlw a'1'
btfss TempBIN,5
movlw a'0'
call SendCHAR

movlw a'1'
btfss TempBIN,4
movlw a'0'
call SendCHAR

movlw a'1'
btfss TempBIN,3
movlw a'0'
call SendCHAR

movlw a'1'
btfss TempBIN,2
movlw a'0'
call SendCHAR

movlw a'1'
btfss TempBIN,1
movlw a'0'
call SendCHAR

movlw a'1'
btfss TempBIN,0
movlw a'0'
call SendCHAR

return


SendCHAR 
movwf Temp 

swapf Temp,w 
bsf STATUS,C 
call NybbleOut

movf Temp,w 
bsf STATUS,C
call NybbleOut
return

SendINS 
movwf Temp 

swapf Temp,w 
bcf STATUS,C 
call NybbleOut

movf Temp,w 
bcf STATUS,C
call NybbleOut

call Dlay5
return

NybbleOut 
movwf NOTemp 
swapf NOTemp,f 
bsf NOTemp,0 
btfss STATUS,C
bcf NOTemp,0

movlw 6 
movwf NOTmp1

bcf Data
NOLoop1
ClockStrobe
decfsz NOTmp1,f
goto NOLoop1

bsf Data 
ClockStrobe
bcf Data 
bsf STATUS,C 
btfss NOTemp,0
bcf STATUS,C
rlf GPIO,f
ClockStrobe
movlw 4 
movwf NOTmp1
NOLoop2
rlf NOTemp,f 
bcf Data 
rlf GPIO,f 
ClockStrobe
decfsz NOTmp1,f
goto NOLoop2

EStrobe 

return


;--------------------------------------------
; Delay 
Dlay160 
movlw 256 - ( 160 / 4 )
addlw 1
btfss STATUS,C
goto $-2
return

Dlay100 call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
call Dlay5
return

Dlay5 
movlw 4 
movwf DlyTmp
movlw 256 - 0x0E8
addlw 1
btfsc STATUS, Z
decfsz DlyTmp,f
goto $-3
return

org 0x3ff 
fill 0x34a4,1
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -