📄 z.txt
字号:
MOVLF 2,PORTB ; medium intensity
bsf PORTA,5 ;Drive E high
bcf PORTA,5 ;Drive E low so VFD will process input
call T40 ;Wait 40 usec
bcf PORTA,3 ;RS=0 for command
MOVLF H'01',PORTB ;Clear Display
bsf PORTA,5 ;Drive E high
bcf PORTA,5 ;Drive E low so VFD will process input
call LoopTime
call LoopTime
call LoopTime
MOVLF H'06',PORTB ;Entry Mode Set
bsf PORTA,5 ;Drive E high
bcf PORTA,5 ;Drive E low so VFD will process input
call T40 ;Wait 40 usec
MOVLF H'14',PORTB ;Cursor Display Shift
bsf PORTA,5 ;Drive E high
bcf PORTA,5 ;Drive E low so VFD will process input
call T40 ;Wait 40 usec
MOVLF H'30',PORTB ;Eight-Bit Interface
bsf PORTA,5 ;Drive E high
bcf PORTA,5 ;Drive E low so VFD will process input
call T40 ;Wait 40 usec
bcf PORTD,7
return
;;;;;;; T40 subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Pause for 40 microseconds (assumes 4 MHz crystal).
T40
movlw 12
movwf TEMP
T40_1
decfsz TEMP,F
goto T40_1
return
;;;;;;; RPGchange subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine looks at the old and new values of the Bourns RPG outputs and
; returns 00000001 for a CW change, 00000000 for no change, or 11111111
; for a CCW change. This result is returned in DELTARPG.
RPGchange
movf PORTC,W ;Put bottom bits of Port C (RPG) into W
andlw B'00000011' ;Mask off extraneous bits
iorwf OLDRPG,W ;Form four bit value of oldC,oldB,newC,newB
movwf DELTARPG ;Use DELTARPG as temporary variable to hold value
movwf OLDRPG ; as well as OLDRPG
movlw B'00001100' ;Form mask in W
rlf OLDRPG,F ;Move new bits to bit positions 3 and 2
rlf OLDRPG,F
andwf OLDRPG,F ;Zero all but the new bits in positions 3 and 2
movf DELTARPG,W ;Restore offset into table
call RPGtable ;Get +1, 0, or -1
movwf DELTARPG ;and return it in DELTARPG
return
;;;;;;; RPG subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Whenever the rotary pulse generator (RPG) increments, this subroutine
; increments or decrements the binary number displayed on the lower five LEDs.
RPG
movf DELTARPG,W ;Get +1, 0, or -1 value formed by RPGchange
addwf DESIREDTEMP,F
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
ControlFan
; ok, we get the temperatures from the temp0-3 variables. we must somehow
; now convert them into desired DutyCycles.
; we have two variables, DESIRETEMP and SUMDIFF which are used in this subroutine
; Simple method: uses only one sensor and a single fan
movf Temp0,W
subwf DESIREDTEMP,W ; find differnce between actual and desired
movwf DIFF0
movf Temp1,W
subwf DESIREDTEMP,W ; find differnce between actual and desired
movwf DIFF1
movf Temp2,W
subwf DESIREDTEMP,W ; find differnce between actual and desired
movwf DIFF2
movf Temp3,W
subwf DESIREDTEMP,W ; find differnce between actual and desired
movwf DIFF3
; now that we have a diff we add that (it can be negative) to the DutyCycle
; this creates a 1:1 relation ship with temp and duty cycle
btfsc DIFF0,7 ; if DIFF0 is a negative number, bit 7=1
goto Control0Negative
goto Control0Positive
Control0Positive
SUB_NOWRAP DutyCycle4,DutyCycle4,DIFF0
goto Control0End
Control0Negative
TWOCOMP DIFF0 ; two complement DIFF0
movf DIFF0,W
ADD_NOWRAP DutyCycle4,DutyCycle4,DIFF0
Control0End
btfsc DIFF1,7 ; if DIFF1 is a negative number, bit 7=1
goto Control1Negative
goto Control1Positive
Control1Positive
SUB_NOWRAP DutyCycle5,DutyCycle5,DIFF1
goto Control1End
Control1Negative
TWOCOMP DIFF1 ; two complement DIFF1
movf DIFF1,W
ADD_NOWRAP DutyCycle5,DutyCycle5,DIFF1
Control1End
btfsc DIFF2,7 ; if DIFF2 is a negative number, bit 7=1
goto Control2Negative
goto Control2Positive
Control2Positive
SUB_NOWRAP DutyCycle0,DutyCycle0,DIFF2
SUB_NOWRAP DutyCycle1,DutyCycle1,DIFF2
SUB_NOWRAP DutyCycle2,DutyCycle2,DIFF2
SUB_NOWRAP DutyCycle3,DutyCycle3,DIFF2
goto Control2End
Control2Negative
TWOCOMP DIFF2 ; two complement DIFF2
movf DIFF2,W
ADD_NOWRAP DutyCycle0,DutyCycle0,DIFF2
ADD_NOWRAP DutyCycle1,DutyCycle1,DIFF2
ADD_NOWRAP DutyCycle2,DutyCycle2,DIFF2
ADD_NOWRAP DutyCycle3,DutyCycle3,DIFF2
Control2End
btfsc DIFF3,7 ; if DIFF3 is a negative number, bit 7=1
goto Control3Negative
goto Control3Positive
Control3Positive
SUB_NOWRAP DutyCycle6,DutyCycle6,DIFF3
SUB_NOWRAP DutyCycle7,DutyCycle7,DIFF3
goto Control3End
Control3Negative
TWOCOMP DIFF3 ; two complement DIFF3
movf DIFF3,W
ADD_NOWRAP DutyCycle6,DutyCycle6,DIFF3
ADD_NOWRAP DutyCycle7,DutyCycle7,DIFF3
Control3End
; this simple method will most likely result in an underdamped system.
return
;;;;;;; GetFanSpeeds ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; nab the 16 bit number from the Fan speed stuff
; and switch the mux
GetFanSpeeds
; nab fan speed
MOVFF FSPEED1H,FANSPEEDH
MOVFF FSPEED1L,FANSPEEDL
; switch to another input
movf PORTE,W
addlw 1
andlw 3
movwf PORTE
; that's it!
return
;;;;;;; DecrementFans ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Decrements Fan coutners for duty cycle powering.
DecrementFans
movf CurrentCount0,W
btfss STATUS,Z
decf CurrentCount0,F
movf CurrentCount0,W
btfsc STATUS,Z
bcf PORTD,0
movf CurrentCount1,W
btfss STATUS,Z
decf CurrentCount1,F
movf CurrentCount1,W
btfsc STATUS,Z
bcf PORTD,1
movf CurrentCount2,W
btfss STATUS,Z
decf CurrentCount2,F
movf CurrentCount2,W
btfsc STATUS,Z
bcf PORTD,2
movf CurrentCount3,W
btfss STATUS,Z
decf CurrentCount3,F
movf CurrentCount3,W
btfsc STATUS,Z
bcf PORTD,3
movf CurrentCount4,W
btfss STATUS,Z
decf CurrentCount4,F
movf CurrentCount4,W
btfsc STATUS,Z
bcf PORTD,4
movf CurrentCount5,W
btfss STATUS,Z
decf CurrentCount5,F
movf CurrentCount5,W
btfsc STATUS,Z
bcf PORTD,5
movf CurrentCount6,W
btfss STATUS,Z
decf CurrentCount6,F
movf CurrentCount6,W
btfsc STATUS,Z
bcf PORTD,6
movf CurrentCount7,W
btfss STATUS,Z
decf CurrentCount7,F
movf CurrentCount7,W
btfsc STATUS,Z
bcf PORTD,7
return
;;;; ResetFans ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; resets the value of the fan counters
ResetFans
MOVFF DutyCycle0,CurrentCount0
MOVFF DutyCycle1,CurrentCount1
MOVFF DutyCycle2,CurrentCount2
MOVFF DutyCycle3,CurrentCount3
MOVFF DutyCycle4,CurrentCount4
MOVFF DutyCycle5,CurrentCount5
MOVFF DutyCycle6,CurrentCount6
MOVFF DutyCycle7,CurrentCount7
movf CurrentCount0,W
btfss STATUS,Z
bsf PORTD,0
btfsc STATUS,Z
bcf PORTD,0
movf CurrentCount1,W
btfss STATUS,Z
bsf PORTD,1
btfsc STATUS,Z
bcf PORTD,1
movf CurrentCount2,W
btfss STATUS,Z
bsf PORTD,2
btfsc STATUS,Z
bcf PORTD,2
movf CurrentCount3,W
btfss STATUS,Z
bsf PORTD,3
btfsc STATUS,Z
bcf PORTD,3
movf CurrentCount4,W
btfss STATUS,Z
bsf PORTD,4
btfsc STATUS,Z
bcf PORTD,4
movf CurrentCount5,W
btfss STATUS,Z
bsf PORTD,5
btfsc STATUS,Z
bcf PORTD,5
movf CurrentCount6,W
btfss STATUS,Z
bsf PORTD,6
btfsc STATUS,Z
bcf PORTD,6
movf CurrentCount7,W
btfss STATUS,Z
bsf PORTD,7
btfsc STATUS,Z
bcf PORTD,7
return
;;;; SMBus Suroutines ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
GetTemp
; Device 0
MOVLF B'00110000',DEVADD
; MOVLF H'00',INTADD ;Read Local Temp
MOVLF H'01',INTADD ;Read Remote Temp
; MOVLF H'02',INTADD ;Read Status Register
call I2Cin
movf DATAIN, W
; movlw -55 ;Debug
movwf Temp0
nop
nop
nop
nop
nop
nop
nop
nop
; Device 1
MOVLF B'10011000',DEVADD
; MOVLF H'00',INTADD ;Read Local Temp
MOVLF H'01',INTADD ;Read Remote Temp
; MOVLF H'02',INTADD ;Read Status Register
call I2Cin
movf DATAIN, W
movwf Temp1
nop
nop
nop
nop
nop
nop
nop
nop
; Device 2
MOVLF B'00110010',DEVADD
; MOVLF H'00',INTADD ;Read Local Temp
MOVLF H'01',INTADD ;Read Remote Temp
; MOVLF H'02',INTADD ;Read Status Register
call I2Cin
movf DATAIN, W
movwf Temp2
nop
nop
nop
nop
nop
nop
nop
nop
; Device 3
MOVLF B'10011100',DEVADD
; MOVLF H'00',INTADD ;Read Local Temp
MOVLF H'01',INTADD ;Read Remote Temp
; MOVLF H'02',INTADD ;Read Status Register
call I2Cin
movf DATAIN, W
movwf Temp3
nop
nop
nop
nop
nop
nop
nop
nop
return
;;;; Hex2Ascii ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; converts hex to ascii
Hex2Ascii
andlw H'0F'
addlw 256-10 ; sub 10
btfsc STATUS,C ; if C==0 then it was a number else a letter
addlw H'07' ; add extra letter offset
addlw H'3A' ; add the 10 back plus enough to make it ASCII
return
;;;; Ascii2Hex ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; converts an ascii character to a hex nibble
Ascii2Hex
addlw 256-48 ; subtract 'F'
movwf TEMP ; save in temp
addlw 256-10 ; subtract 10
movf TEMP,W ; save
btfsc STATUS,C ; check for borrow
addlw 256-7 ; subtract 7
andlw H'0F' ; mask bits
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
DisplayInfo
call VFDReset
; alternate between tempurature readings and fan speeds and desired temp
; and a promo screen!
incf SCREENNUM,F
movlw 3
andwf SCREENNUM,F
movf SCREENNUM,W
call ScreenTable
return
Screen1
movlw _1-Message_Start
call DisplayC
movf Temp0,W
call VFDdecimal
DEGREES
movlw _2-Message_Start
call DisplayC
movf Temp1,W
call VFDdecimal
DEGREES
; line 2 now...
movlw _3-Message_Start
call DisplayC
movlw H'20'
call VFDbyte
movlw A'X'
call VFDbyte
movlw A'X'
call VFDbyte
DEGREES
movlw _4-Message_Start
call DisplayC
movf Temp3,W
call VFDdecimal
DEGREES
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -