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

📄 ovencal.asm

📁 pic系列单片机得控制程序 主要进行温度采集和转换控制
💻 ASM
📖 第 1 页 / 共 4 页
字号:
              rcall DisplayC
              movff TBLPTRH, OLDTBLPTRH
              movff TBLPTRL, OLDTBLPTRL
            ;ENDIF_
L46
          ;ENDIF_
L45

          ;IF_ CALIBRATE, 4 == 1       ; If the calibration is still in progress
          btfss CALIBRATE,4
          bra	L47
            rcall Wait10Sec            ; Continue the 10 sec wait
          ;ENDIF_
L47
        ;ENDIF_
L44

        TESTSCREEN 6
        ;IF_ .Z.
        bnz	L48
          ;IF_ CALIBRATE, 1 == 0       ; Check for a 1 point calibration
          btfsc CALIBRATE,1
          bra	L49
            MOVLF 1,SCREEN             ; Reset the screen index
            DISPLAYONCE  TemperatureStr
          ;ELSE_
          bra	L50
L49
            DISPLAYONCE CalibrateStr
            DISPLAYONCE BoilStr
            DISPLAYONCE BeginStr

            ;IF_  PBSTATE,ISA == 1     ; Fast pulse
            btfss PBSTATE,ISA
            bra	L51
              ;IF_ CALIBRATE, 4 == 0   ; If calibration not in progress
              btfsc CALIBRATE,4
              bra	L52
                bsf CALIBRATE, 4       ; Set the Calibration In Progress flag
                bsf CALIBRATE, 3       ; Set the calibration flag for boil

                MOVLF 100, CALIBRATIONRANGE  ; Reset the calibration range
                movff CALIBRATIONRANGE, EEDATA  ; Save the new calibration range to EEPROM
                MOVLF 0x03, EEADR
                rcall WriteEEPROM

                MOVLF WaitTime, WAITCOUNTER  ; Reset the wait counter
                MOVLF LoopCounterThr, LOOPCOUNTER  ; Reset teh loop counter
                POINT ClearBeginStr
                rcall DisplayC
                POINT Bar1             ; Start the progress bar
                rcall DisplayC
                movff TBLPTRH, OLDTBLPTRH  ; Save table location for next
                movff TBLPTRL, OLDTBLPTRL  ;  status bar character
              ;ENDIF_
L52
            ;ENDIF_
L51

            ;IF_ CALIBRATE, 4 == 1	If calibration is still in progress
            btfss CALIBRATE,4
            bra	L53
              rcall Wait10Sec          ; Continue the 10 sec wait
            ;ENDIF_	
L53
          ;ENDIF_
L50
        ;ENDIF_ 
L48
        
        return


;;;;;; GetTemperature Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine handles the serial interface to the 6674x and sets the new
;  value for TMEPERATUREH and TEMPERATUREL.
;

GetTemperature
        bcf PORTB, RB1                 ; Clear chip select
        bcf PIR1, SSPIF                ; Clear the flag
        MOVLF 0xFF, SSPBUF             ; Start the transfer

        ;REPEAT_
L54
        ;UNTIL_ PIR1, SSPIF == 1       ; Wait until transfer is complete
        btfss PIR1,SSPIF
        bra	L54
RL54

        movff SSPBUF, TEMPERATUREH     ; First byte is the high byte
        bcf PIR1, SSPIF                ; Clear the flag
        movff TEMPERATUREH, SSPBUF     ; Start the trnsfer

        ;REPEAT_
L55
        ;UNTIL_ PIR1, SSPIF == 1       ; Wait until transfer is complete
        btfss PIR1,SSPIF
        bra	L55
RL55

        movff SSPBUF, TEMPERATUREL     ; Second byte is the low byte
        bsf PORTB, RB1                 ; Set the chip select

        ;IF_ TEMPERATUREL, 4 == 1      ; Check for open circuit
        btfss TEMPERATUREL,4
        bra	L56
          POINT ErrorStr               ; Display error message
          rcall DisplayC
          bcf CALIBRATE, 4             ; Cancel any calibrations
        ;ELSE_
        bra	L57
L56
          rcall AdjustTemperatureVal   ; Adjust the temperature value for
                                       ;  calibrations and units F/C
        ;ENDIF_
L57
        
        return

;;;;;; AdjustTemperatureVal Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine is used to take the binary value from the 667x and transform
;  it into a real temperature complete with calibration corrections.
;

AdjustTemperatureVal
        ;IF_ CALIBRATE, 7 == 0         ; 6674 chip
        btfsc CALIBRATE,7
        bra	L58
          MOVLF 5, SHIFTVALUE          ; Set the number of places to shift
        ;ELSE_
        bra	L59
L58
          MOVLF 3, SHIFTVALUE
        ;ENDIF_
L59

        rcall ShiftRight               ; Shift the temperature data

        movff TEMPERATUREH, AARGB0     ; Make the temperature cover the entire
        movff TEMPERATUREL, AARGB1     ;  range

        ;IF_ CALIBRATE, 7 == 0         ; 6674 chip
        btfsc CALIBRATE,7
        bra	L60
          ;IF_ CALIBRATE, 6 == 1       ; Display in Celcius
          btfss CALIBRATE,6
          bra	L61
            MOVLF 125, BARGB0          ; Incremnts .125 degrees
          ;ELSE_                       ; Display in Farenheit
          bra	L62
L61
            MOVLF 225, BARGB0          ; Increments .225 degrees, 32 will be added later
          ;ENDIF_
L62
        ;ELSE_                         ; 6675 chip
        bra	L63
L60
          ;IF_ CALIBRATE, 6 == 1       ; Display in Celcius
          btfss CALIBRATE,6
          bra	L64
            MOVLF 25, BARGB0           ; Increments .25 degrees
          ;ELSE_                       ; Display in Farenheit
          bra	L65
L64
            MOVLF 45, BARGB0           ; Increments .45 degrees, 32 will be added later
          ;ENDIF_
L65
        ;ENDIF_
L63

        call FXM1608U

        ;IF_ CALIBRATE, 7 == 0         ; 6674 chip
        btfsc CALIBRATE,7
        bra	L66
          MOVLF 0x03, BARGB0           ; Divide by 1000
          MOVLF 0xE8, BARGB1
        ;ELSE_                         ; 6675 chip
        bra	L67
L66
          clrf BARGB0
          MOVLF 100, BARGB1            ; Divide by 100
        ;ENDIF_
L67

        call FXD2416U
        
        movff AARGB1, TEMPERATUREH     ; Save the result
        movff AARGB2, TEMPERATUREL

;; The following will use the calibration constants to adjust the temperature
;;  measurement by the following equation ---
;;
;;	Celcius -> temp = (temp from chip - CALIBRATIONOFFSET) * (100 / CALIBRATIONRANGE)
;;    Farenheit -> temp = (temp from chip - CALIBRATIONOFFSET) * (180 / CALIBRATIONRANGEF

        ;IF_ CALIBRATE, 6 == 1         ; Display in Celcius
        btfss CALIBRATE,6
        bra	L68
          movf CALIBRATIONOFFSET, W
        ;ELSE_                         ; Display in Farenheit
        bra	L69
L68
          movff CALIBRATIONOFFSET, AARGB0  ; Adjust the calibration offset by 9/5
          MOVLF 9, BARGB0
          call FXM0808U
          MOVLF 5, BARGB0
          call FXD1608U
          movf AARGB1, W
        ;ENDIF_
L69
        
        subwf TEMPERATUREL, F          ; Subtract the calibration offset
        clrf WREG
        subwfb TEMPERATUREH, F

        ;IF_ .B.                       ; Limit minimum temp to 0 degrees
        bc	L70
          clrf TEMPERATUREH
          clrf TEMPERATUREL
        ;ENDIF_
L70

        movff TEMPERATUREH, AARGB0     ; Load the math variables
        movff TEMPERATUREL, AARGB1
        
        ;IF_ CALIBRATE, 6 == 1         ; Display in Celcius
        btfss CALIBRATE,6
        bra	L71
          MOVLF 100, BARGB0            ; Multiply by 100
        ;ELSE_                         ; Display in Farenheit
        bra	L72
L71
          MOVLF 180, BARGB0            ; Multiply by 180
        ;ENDIF_
L72
        
        call FXM1608U

        movff AARGB0, TEMPERATUREU     ; Save the result
        movff AARGB1, TEMPERATUREH
        movff AARGB2, TEMPERATUREL
        
        ;IF_ CALIBRATE, 6 == 1         ; Display in Celcius
        btfss CALIBRATE,6
        bra	L73
          movff CALIBRATIONRANGE, BARGB0
        ;ELSE_                         ; Display in Farenheit
        bra	L74
L73
          movff CALIBRATIONRANGE, AARGB0  ; Adjust the calibration range by 9/5
          MOVLF 9, BARGB0
          call FXM0808U
          MOVLF 5, BARGB0
          call FXD1608U
          movff AARGB1, BARGB0
        ;ENDIF_
L74

        movff TEMPERATUREU, AARGB0
        movff TEMPERATUREH, AARGB1
        movff TEMPERATUREL, AARGB2

        call FXD2408U                  ; Divide by the calibration range

        movff AARGB1, TEMPERATUREH     ; Set the new temperature
        movff AARGB2, TEMPERATUREL

        return

;;;;;; ShiftRight Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine will shift the temperature data to the right due to
;  the way the 667x sends the data to the PIC.
;

ShiftRight
        ;REPEAT_
L75
          bcf STATUS, C                ; Shift a 2 byte number to the right
          rrcf TEMPERATUREH, F
          rrcf TEMPERATUREL, F
          decf SHIFTVALUE, F
        ;UNTIL_ .Z.
        bnz	L75
RL75

        return

;;;;;; ChipSelect Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine displays the chip in use, 6674 or 6675.
;

ChipSelect
        ;IF_ CALIBRATE, 7 == 0         ; Check the current chip
        btfsc CALIBRATE,7
        bra	L76
          POINT Chip6674Str
        ;ELSE_
        bra	L77
L76
          POINT Chip6675Str
        ;ENDIF_
L77

        rcall DisplayC                 ; Display the current chip

        return

;;;;;; DisplayYesNo Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine displays the YES or NO choice for the user.
;

DisplayYesNo
        ;IF_ CALIBRATE, 0 == 0         ; Check to see if the user wants to calibrate
        btfsc CALIBRATE,0
        bra	L78
          POINT NoStr
        ;ELSE_
        bra	L79
L78
          POINT YesStr
        ;ENDIF_
L79

        rcall DisplayC                 ; Display choice for the user to view

        return

;;;;;; DisplayPoint Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine displays the 1 or 2 point calibration choice.
;

DisplayPoint
        ;IF_ CALIBRATE, 1 == 0         ; Check to see if the user chose 1 or 2 point calibration
        btfsc CALIBRATE,1
        bra	L80
          POINT OneStr
        ;ELSE_                         ; 2 point calibration
        bra	L81
L80
          POINT TwoStr
        ;ENDIF_
L81

        rcall DisplayC                 ; Display the choice to the user
        POINT PointStr
        rcall DisplayC

        return

;;;;;; DisplayUnit Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine displays the unit the user has chosen, F or C.
;

DisplayUnit
        ;IF_ CALIBRATE, 6 == 0         ; If Farenheit
        btfsc CALIBRATE,6

⌨️ 快捷键说明

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