12F675温度显示程序
扫描二维码
随时随地手机看文章
;title"DS1620-12F675温度LCD显示
;ShiftData:
;Bit1-AlwaysHigh(Gatefor"E")
;Bit2-RSBit
;Bit3-LCDD4
;Bit4-LCDD5
;Bit5-LCDD6
;Bit6-LCDD7
;
;
;12F6754MHz
;GPIO.0istheLCDDataBit
;GPIO.1istheLCDCLOCkBit
;GPIO.2istheDS1620DataBit
;GPIO.3isMCLR
;GPIO.4istheDS1620ClockBit
;GPIO.5istheDS1620ResetBit
;
;
LISTP=12F675,R=DEC
INCLUDE"p12f675.inc"
#DEFINEDataGPIO,0
#DEFINEClockGPIO,1
#DEFINEDSDQGPIO,2
;MCLRusesGPIO,3
#DEFINEDSCLKGPIO,4
#DEFINEDSRSTGPIO,5
org0
bsfSTATUS,RP0
MOVlw0x00
MOVwfTRISIO
MOVlwb’11011100’
MOVwfOPTION_REG
clrfANSEL
bcfSTATUS,RP0
clrfSTATUS
clrfINTCON
clrfGPIO
MOVlw0x07
MOVwfCMCON
callInitLCD
callSndMsg
callInitDS
MAINMOVlw0xc0;line2onLCD
callSendINS
callGetTemp;读温度
callSendDEC;LCD显示
gotoMAIN
;---------------------------------------------------------------
;DS1620子程序
StartCMACRO
bsfDSRST
ENDM
StopCMACRO
bcfDSRST
ENDM
InitDSStartC
MOVlw0x0c
callSndByte
MOVlwb’00001010’
callSndByte
StopC
nop
StartC
MOVlw0xEE
callSndByte
StopC
return
GetTempMOVlw0xAA
StartC
callSndByte
nop
callRdByte
StopC
return
SndByteMOVwfNOTemp
MOVlw8
MOVwfNOTmp1
DSLoop1
bcfDSCLK
rrfNOTemp,f
btfssSTATUS,C
gotoDSCLR
bsfDSDQ
gotoDSLp1
DSCLRbcfDSDQ
nop
DSLp1bsfDSCLK
decfszNOTmp1,f
gotoDSLoop1
return
RdByteclrfNOTemp
MOVlw8
MOVwfNOTmp1
bsfSTATUS,RP0
bsfTRISIO,2
bcfSTATUS,RP0
DSLoop2
bcfDSCLK
nop
rrfNOTemp,f
btfssDSDQ
gotoDSCLR2
bsfNOTemp,7
gotoDSLp2
DSCLR2bcfNOTemp,7
nop
DSLp2bsfDSCLK
decfszNOTmp1,f
gotoDSLoop2
bsfSTATUS,RP0
bcfTRISIO,2
bcfSTATUS,RP0
MOVfwNOTemp
return
;--------------------------------------------
;LCDSubroutines
Message
addwfPCL,f
dt"HelloDS1620",0
SndMsgclrfFSR
OutLoop
MOVfFSR,w
incfFSR,f
callMessage
iorlw0
btfscSTATUS,Z
gotoRtnSnd
callSendCHAR
gotoOutLoop
RtnSndreturn
InitLCD
callDlay5
callDlay5
callDlay5
callDlay5
bcfSTATUS,C
MOVlw0x03
callNybbleOut
callDlay5
EStrobe
callDlay160
EStrobe
callDlay160
bcfSTATUS,C
MOVlw0x02
callNybbleOut
callDlay160
MOVlw0x028
callSendINS
MOVlw0x008
callSendINS
MOVlw0x001
callSendINS
callDlay5
MOVlw0x006
callSendINS
MOVlw0x00F
callSendINS
return
SendDEC
MOVwfTempBIN
bcfpt5,0
btfscTempBIN,0
bsfpt5,0
rrfTempBIN,f
clrfTens
MOVlw0x0A
count10subwfTempBIN,f
btfssSTATUS,C
gotoSDEC1
incfTens,f
gotocount10
SDEC1addwfTempBIN,w
MOVwfUnits
MOVfwTens
addlwa’0’
callSendCHAR
MOVfwUnits
addlwa’0’
callSendCHAR
btfsspt5,0
gotoDEGC
MOVlwa’.’
callSendCHAR
MOVlwa’5’
callSendCHAR
DEGCMOVlwa’’
callSendCHAR
MOVlwa’D’
callSendCHAR
MOVlwa’e’
callSendCHAR
MOVlwa’g’
callSendCHAR
MOVlwa’C’
callSendCHAR
MOVlwa’’
callSendCHAR
MOVlwa’’
callSendCHAR
return
SendBIN
MOVwfTempBIN;存温度值
MOVlwa’1’
btfssTempBIN,7
MOVlwa’0’
callSendCHAR
MOVlwa’1’
btfssTempBIN,6
MOVlwa’0’
callSendCHAR
MOVlwa’1’
btfssTempBIN,5
MOVlwa’0’
callSendCHAR
MOVlwa’1’
btfssTempBIN,4
MOVlwa’0’
callSendCHAR
MOVlwa’1’
btfssTempBIN,3
MOVlwa’0’
callSendCHAR
MOVlwa’1’
btfssTempBIN,2
MOVlwa’0’
callSendCHAR
MOVlwa’1’
btfssTempBIN,1
MOVlwa’0’
callSendCHAR
MOVlwa’1’
btfssTempBIN,0
MOVlwa’0’
callSendCHAR
return
SendCHAR
MOVwfTemp
swapfTemp,w
bsfSTATUS,C
callNybbleOut
MOVfTemp,w
bsfSTATUS,C
callNybbleOut
return
SendINS
MOVwfTemp
swapfTemp,w
bcfSTATUS,C
callNybbleOut
MOVfTemp,w
bcfSTATUS,C
callNybbleOut
callDlay5
return
NybbleOut
MOVwfNOTemp
swapfNOTemp,f
bsfNOTemp,0
btfssSTATUS,C
bcfNOTemp,0
MOVlw6
MOVwfNOTmp1
bcfData
NOLoop1
ClockStrobe
decfszNOTmp1,f
gotoNOLoop1
bsfData
ClockStrobe
bcfData
bsfSTATUS,C
btfssNOTemp,0
bcfSTATUS,C
rlfGPIO,f
ClockStrobe
MOVlw4
MOVwfNOTmp1
NOLoop2
rlfNOTemp,f
bcfData
rlfGPIO,f
ClockStrobe
decfszNOTmp1,f
gotoNOLoop2
EStrobe
return
;--------------------------------------------
;Delay
Dlay160
MOVlw256-(160/4)
addlw1
btfssSTATUS,C
goto$-2
return
Dlay100callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
callDlay5
return
Dlay5
MOVlw4
MOVwfDlyTmp
MOVlw256-0x0E8
addlw1
btfscSTATUS,Z
decfszDlyTmp,f
goto$-3
return
org0x3ff
fill0x34a4,1
end