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

📄 ovencal.asm

📁 pic系列单片机得控制程序 主要进行温度采集和转换控制
💻 ASM
📖 第 1 页 / 共 4 页
字号:
        bra	L82
          POINT FarenheitStr
        ;ELSE_                         ; If Celcius
        bra	L83
L82
          POINT CelsiusStr
        ;ENDIF_
L83
        
        rcall DisplayC                 ; Display temperature unit

        return

;;;;;; Calibrate Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine gets the latest temperature values and loads
;  the FIFO array that will be used to determine the new calibration
;  data.
;

Calibrate
        ;IF_ CALIBRATE, 5 == 1         ; If conversion is done
        btfss CALIBRATE,5
        bra	L84
          ;IF_ CALIBRATE, 6 == 0       ; If in Farenheit mode
          btfsc CALIBRATE,6
          bra	L85
            bsf CALIBRATE, 6           ; Force to celcius
            call GetTemperature        ; Determine temperature in celcius
            bcf CALIBRATE, 6           ; Reset to farenheit
          ;ELSE_
          bra	L86
L85
            call GetTemperature
          ;ENDIF_
L86

          rcall LoadFIFO               ; Load the FIFO
          
          bcf CALIBRATE, 5             ; Clear the conversion done flag
          MOVLF ConversionTime, CONVERSIONCOUNTER  ;Reset the conversion counter.
        ;ENDIF_
L84

        return
        

;;;;;; LoadFIFO Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine updates FIFO array with 2 byte numbers.
;

LoadFIFO
        lfsr 0, FIFO + FIFOSize - 3    ; Set pointer to low byte of second to last number
        lfsr 1, FIFO + FIFOSize - 1    ; Set pointer to low byte of last number


        ;REPEAT_
L87
          movff POSTDEC0, POSTDEC1     ;Move the data to the right in the FIFO array
          incf FSR0L, W                ;Done?
          sublw low FIFO
        ;UNTIL_ .Z.
        bnz	L87
RL87

        movff TEMPERATUREH, PREINC0    ; Load the latest temperature into the first 2 bytes
        movff TEMPERATUREL, PREINC0    ;  of the FIFO, high byte first
        
        return

;;;;;; Average Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine averages the temperature values located in the FIFO array.
;

Average
        lfsr 0, FIFO + FIFOSize - 1    ; Set pointer to last byte of the FIFO

        clrf CALIBRATEAVERAGEL         ; Reset the average
        clrf CALIBRATEAVERAGEH

        ;REPEAT_
L88
          movf POSTDEC0, W             ; Load the low byte into W
          addwf CALIBRATEAVERAGEL, F   ; Add to Average low
          movf POSTDEC0, W             ; Load the high byte into W
          addwfc CALIBRATEAVERAGEH, F  ; Add to Average high
          incf FSR0L, W                ;Done?
          sublw low FIFO
        ;UNTIL_ .Z.
        bnz	L88
RL88

        movff CALIBRATEAVERAGEH, AARGB0  ; Load the math variables
        movff CALIBRATEAVERAGEL, AARGB1
        movlw FIFOSize/2               ; Divide by number of 2 byte values in the FIFO
        movwf BARGB0
        call FXD1608U

        return

;;;;;; Wait10Sec Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine waits 10 sec during calibrations before setting the new
;  calibration limits.  A status bar is diplayed to the screen while this
;  function is being called.
;

Wait10Sec
        movf LOOPCOUNTER, F
        ;IF_ .Z.                       ; Is 1 second up
        bnz	L89
          decf WAITCOUNTER             ; Are 10 seconds up
          ;IF_ .Z.                     ; Yes
          bnz	L90
            bcf CALIBRATE, 4           ; Clear the calibration in progress bit
            POINT EndStr               ; Let the user know calibration has completed
            rcall DisplayC

            ;IF_ CALIBRATE, 2 == 1     ; if freeze is done
            btfss CALIBRATE,2
            bra	L91
              bcf CALIBRATE, 2         ; Reset the freeze calibration done flag

              rcall Average            ; Average most recent temperatures
              movf AARGB1, W           ; Move the new offset to W
              movwf CALIBRATIONOFFSET  ; Set the new offset
              movff CALIBRATIONOFFSET, EEDATA  ; Save the new calibration to EEPROM
              MOVLF 0x02, EEADR
              rcall WriteEEPROM
              
              MOVLF 100, CALIBRATIONRANGE  ; Reset the calibration range for a 1 point
                                       ;  calibration
              movff CALIBRATIONRANGE, EEDATA  ; Save the new calibration range to EEPROM
              MOVLF 0x03, EEADR
              rcall WriteEEPROM
            ;ENDIF_
L91

            ;IF_ CALIBRATE, 3 == 1     ; if boil is done
            btfss CALIBRATE,3
            bra	L92
              bcf CALIBRATE, 3         ; Reset the boil calibration done flag
              
              rcall Average            ; Average most recent temperatures
              movf AARGB1, W           ; Move the new range to W

              movwf CALIBRATIONRANGE   ; Set the new range
              movff CALIBRATIONRANGE, EEDATA  ; Save the new calibration range to EEPROM
              MOVLF 0x03, EEADR
              rcall WriteEEPROM
            ;ENDIF_
L92
          ;ELSE_
          bra	L93
L90
            movff OLDTBLPTRH, TBLPTRH  ; Reset the table pointer to the next status
            movff OLDTBLPTRL, TBLPTRL  ;  character
            MOVLF LoopCounterThr, LOOPCOUNTER  ; Reset the loop counter
            incf TBLPTRL               ; Get the next status bar character
            clrf WREG
            addwfc TBLPTRH,F
            rcall DisplayC             ; Display status bar or 'END'
            movff TBLPTRH, OLDTBLPTRH  ; Save the table pointer to the next status
            movff TBLPTRL, OLDTBLPTRL  ;  character
          ;ENDIF_
L93
        ;ENDIF_
L89

        rcall Calibrate                ; Call the calibrate routine


        return

;;;;;; ReadEEPROM Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Reads the EEPROM and initializes the RAM data to whatever is in the EEPROM
;  addresses.  On the very first time this function will initialize the EEPROM
;  data.
;

ReadEEPROM
        clrf EEADR
        bsf EECON1, RD                 ; Read the first location in EEPROM
        movf EEDATA, W
        xorlw B'10101010'              ; Check for very first time
        
        ;IF_ .Z.                       ; Not first time
        bnz	L94
          MOVLF 0x01, EEADR            ; Load the EEPROM address
          bsf EECON1, RD               ; Set the read bit
          movff EEDATA, CALIBRATE      ; Get last saved CALIBRATE
          
          MOVLF 0x02, EEADR            ; Load the EEPROM address
          bsf EECON1, RD               ; Set the read bit
          movff EEDATA, CALIBRATIONOFFSET  ; Get last saved offset
          
          MOVLF 0x03, EEADR            ; Load the EEPROM address
          bsf EECON1, RD               ; Set the read bit
          movff EEDATA, CALIBRATIONRANGE  ; Get last saved range
        ;ELSE_                         ; Very first time
        bra	L95
L94
          MOVLF B'10101010', EEDATA    ; Load in our first time number into address 0x00
          MOVLF 0x00, EEADR            ; Load the EEPROM address
          rcall WriteEEPROM            ; Write to the EEPROM

          clrf CALIBRATE               ; Set initial CALIBRATE
          movff CALIBRATE, EEDATA
          MOVLF 0x01, EEADR            ; Load the EEPROM address
          rcall WriteEEPROM            ; Write to the EEPROM

          clrf CALIBRATIONOFFSET       ; Set intial OFFSET
          movff CALIBRATIONOFFSET, EEDATA
          MOVLF 0x02, EEADR            ; Load the EEPROM address
          rcall WriteEEPROM            ; Write to the EEPROM

          MOVLF 100, CALIBRATIONRANGE  ; Set initial range
          movff CALIBRATIONRANGE, EEDATA
          MOVLF 0x03, EEADR            ; Load the EEPROM address
          rcall WriteEEPROM            ; Write to the EEPROM
        ;ENDIF_
L95
        
        return

;;;;;; WriteEEPROM Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Writes whatever is in EEDATA to the address already loaded in EEADR.  This
;  is used for non volatile data.
;

WriteEEPROM
        bcf PIR2, EEIF                 ; Set up the EEPROM for writing
        bsf EECON1, WREN               ; Set the write enable
        bcf INTCON, GIEH               ; Disable interrupts
        MOVLF 0x55, EECON2             ; Set the magic number
        MOVLF 0xAA, EECON2
        bsf EECON1, WR                 ; Set the write bit

        ;REPEAT_
L96
        ;UNTIL_ PIR2, EEIF == 1        ; Wait until the writing is done
        btfss PIR2,EEIF
        bra	L96
RL96
        bcf EECON1, WREN               ; Clear the write enable
        bsf INTCON, GIEH               ; Reenable interrupts

        return


;;;;;; DisplayDecimal Subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Displays the temperature as a decimal number.
;

DisplayTemperature
        lfsr 0,DECSTR+6		
        movff TEMPERATUREH, AARGB0     ; Get the temperature values ready
        movff TEMPERATUREL, AARGB1     ;  to display
        MOVLF 10,BARGB0                ;Set the divisor

        ;REPEAT_
L97
          bsf PORTB, RB0               ;Toggle this pin to view with scope
          call FXD1608U                ;Divide
          bcf PORTB, RB0               ;Toggle this pin to view with scope
          movf REMB0,W                 ;Put the remainder in the WREG
          iorlw 0x30                   ;Convert to ASCII
          movwf POSTDEC0               ;Move ASCII code to string
          movf AARGB0, W               ;Check for zero quotient
          iorwf AARGB1, W
        ;UNTIL_ .Z.
        bnz	L97
RL97
        
        movf FSR0L,W                   ;At the begining?
        sublw low DECSTR

        ;IF_ .NZ.
        bz	L98
          ;REPEAT_
L99
            movlw 0x20                 ;Load ASCII code for a space into WREG
            movwf POSTDEC0             ;Move the ASCCII code to the string
            movf FSR0L,W               ;Done?
            sublw low DECSTR
          ;UNTIL_ .Z.
          bnz	L99
RL99
        ;ENDIF_
L98
        
        MOVLF 0xC0,INDF0               ;Add cursor position to the string
        clrf DECSTR+7                  ;Add end-of-string terminator
        rcall DisplayV		

        return


;;;;;;; Constant strings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

LCDstr  db  0x33,0x32,0x28,0x01,0x0c,0x06,0x00  ;Initialization string for LCD
TemperatureStr db  "\x80  TEMP  \x00"   ; Display TEMP title
ChipSelStr  db  "\x80CHIP SEL\x00"     ; Display chip selection title
CalibrateStr db  "\x80CALIBRAT\x00"    ; Display caibrate title
FarenheitStr db "\xC6\xDFF\x00"        ; Display 'degree symbol'F
CelsiusStr db "\xC6\xDFC\x00"          ; Display 'degree symbol'C
NoStr db "\xC0      NO\x00"            ; Display NO choice
YesStr db "\xC0     YES\x00"           ; Display YES choice
Chip6674Str db "\xC0    6674\x00"      ; Display 6674 chip
Chip6675Str db "\xC0    6675\x00"      ; Display 6675 chip
BeginStr db "\xC5BGN\x00"              ; Let the user know calibration is ready to start
ClearBeginStr db "\xC5    \x00"        ; Clear the BeginStr
EndStr db "\xC5END\x00"                ; Let the user know calibration is done
FreezeStr db "\x00\xC0FREZ \x00"       ; Freeze calibration title
BoilStr db "\x00\xC0BOIL \x00"         ; Boil calibration title
PointStr db "\x00\xC1 POINT \x00"      ; For 1 or 2 point calibration choice
OneStr db "\x00\xC01\x00"              ; Write '1' to the screen
TwoStr db "\x00\xC02\x00"              ; Write '2' to the screen
Clear1  db  "\x80        \x00"         ;Clear line 1	; Clear top line of display
Clear2  db  "\xC0        \x00"         ;Clear line 2	; Clear bottom line of the display
ErrorStr db "\xC0 ERROR  \x00"         ; Display error string

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; User defined characters to display a progress bar
;;
;;

Block1 db 0x48, 0x80, 0x80, 0x90, 0x90, 0x90, 0x80, 0x80, 0x80, 0x00
Block2 db 0x50, 0x80, 0x80, 0x98, 0x98, 0x98, 0x80, 0x80, 0x80, 0x00
Block3 db 0x58, 0x80, 0x80, 0x9C, 0x9C, 0x9C, 0x80, 0x80, 0x80, 0x00
Block4 db 0x60, 0x80, 0x80, 0x9E, 0x9E, 0x9E, 0x80, 0x80, 0x80, 0x00
Block5 db 0x68, 0x80, 0x80, 0x9F, 0x9F, 0x9F, 0x80, 0x80, 0x80, 0x00
Bar1 db 0x00, 0xC6, 0x01, 0x00
Bar2 db 0x00, 0xC6, 0x02, 0x00
Bar3 db 0x00, 0xC6, 0x03, 0x00
Bar4 db 0x00, 0xC6, 0x04, 0x00
Bar5 db 0x00, 0xC6, 0x05, 0x00
Bar6 db 0xC6, 0x05, 0x01, 0x00
Bar7 db 0xC6, 0x05, 0x02, 0x00
Bar8 db 0xC6, 0x05, 0x03, 0x00
Bar9 db 0xC6, 0x05, 0x04, 0x00
Bar10 db 0xC6, 0x05, 0x05, 0x00

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Math include files
;;
;;

#include <C:\MATH18\FXD0808U.INC>
#include <C:\MATH18\FXD1608U.INC>
#include <C:\MATH18\FXD2408U.INC>
#include <C:\MATH18\FXD2416U.INC>
#include <C:\MATH18\FXM0808U.INC>
#include <C:\MATH18\FXM1608U.INC>

        end

⌨️ 快捷键说明

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