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

📄 z.txt

📁 pic系列单片机得控制程序 主要进行温度采集和转换控制
💻 TXT
📖 第 1 页 / 共 3 页
字号:
; 
 
; Computer Case Climate Controller 计算机气候控制器

       list  P=PIC16F877, F=INHX8M, C=160, N=77, ST=OFF, MM=OFF, R=DEC, X=OFF
        #include P16F877.inc
;       __config(_CP_OFF & _PWRTE_ON & _XT_OSC & _WDT_OFF & _BODEN_OFF)

Bank0RAM equ    H'20'    ; Bank 0 
Bank1RAM equ    H'A0'    ; Bank 1 
Bank2RAM equ    H'110'   ; Bank 2 
Bank3RAM equ    H'190'   ;Start of Bank 3 RAM area

CrossBankRAM equ H'70'   ;影射

MaxCount equ    10       ;半秒循环计数

MaxOuter equ    10
MaxInner equ    100

CR       equ    H'0d'
XON      equ    H'11'
XOFF     equ    H'13'

Freq     equ    4
SDA      equ    4
SCL      equ    3

MechDelayConst equ 100

;-----------------------------------
    cblock    Bank0RAM
    BLNKCNT         
    BLINKTEMP       
    INDEX   
       
; I2C 子程序
    DATAIN
    DATAOUT
    DEVADD
    INTADD
    TXBUFF
    RXBUFF

    GeneralCycle

    DutyCycle0
    DutyCycle1
    DutyCycle2
    DutyCycle3
    DutyCycle4
    DutyCycle5
    DutyCycle6
    DutyCycle7

    CurrentCount0
    CurrentCount1
    CurrentCount2
    CurrentCount3
    CurrentCount4
    CurrentCount5
    CurrentCount6
    CurrentCount7
    ;
    Temp0
    Temp1
    Temp2
    Temp3
    Digit0
    Digit1
    Digit2
    TempX
    ;
    DESIREDTEMP
    DIFF0
    DIFF1
    DIFF2
    DIFF3
    ADD1
    ADD2
    ;
        RPGNUMBER               ;Variable controlled by RPG
        OLDRPG                  ;Old bits from RPG
        DELTARPG                ;Value of +1, 0, -1 from table for RPG change
    ;
    FSPEED0H
    FSPEED0L
    FSPEED1H
    FSPEED1L
    FANSPEEDH
    FANSPEEDL
    ;
    SCREENNUM
    ;
    endc

    cblock    Bank1RAM
    endc

    cblock    Bank2RAM
    endc

    cblock    Bank3RAM
    endc

    cblock  CrossBankRAM
    DIS_TEMP        ; temp var for Display
    TEMP            ; just a temp var
    W_TEMP          ; W save value
    STATUS_TEMP     ; STATUS save value
    TEMPNUM         ; temp for checking 0-9 status
    LOOPTIME        ; determines what loop we are on
    endc


;;;;;;; Macro definitions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MOVLF       macro    literal,dest
    movlw   literal
    movwf   dest
    endm

MOVFF       macro    source,dest
    movf    source,W
    movwf   dest
    endm

NEWLINE     macro
    movlw   H'0d'
    call    TXbyte
    movlw   H'0a'
    call    TXbyte
    endm

VFDNEWLINE  macro
    movlw   _Newline-Message_Start
    call    DisplayC
    endm

_VFDSPACE   macro
    movlw   H'20'
    call    VFDbyte
    endm

_SPACE      macro
    movlw   H'20'
    call    TXbyte
    endm

SEND_XOFF   macro
    movlw   XOFF
    call    TXbyte
    endm

SEND_XON    macro
    movlw   XON
    call    TXbyte
    endm

DEGREES     macro
    movlw   H'DF'
    call    VFDbyte
    movlw   A'C'
    call    VFDbyte
    endm

BANK0       macro
    bcf     STATUS,RP0
    ;bcf     STATUS,RP1
    endm

BANK1       macro
    bsf     STATUS,RP0
    ;bcf     STATUS,RP1
    endm

BANK2       macro
    bcf     STATUS,RP0
    bsf     STATUS,RP1
    endm

BANK3       macro
    bsf     STATUS,RP0
    bsf     STATUS,RP1
    endm

TWOCOMP      macro reg
    comf     reg,F
    movlw    1
    addwf    reg,F
    endm

; this used so that the fan duty cycles never go above 100%
ADD_NOWRAP    	macro dest,source1,source2
    movf    source2,W
    addwf   source1,F
    bsf     STATUS,C
    movlw   100
    subwf   source1,W
    btfss   STATUS,C
    addlw   100
    btfsc   STATUS,C
    movlw   100
    movwf   dest
    endm

SUB1616 macro   A0,A1,B0,B1,C0,C1
; subtract A0,A1` from B0, B1 and put results in C0,C1
        movf    A1,W
        subwf   B1,W            ; low byte, carry set possibly
        movwf   C1              ; save it
        movf    A0,W            ; get high byte
        btfss   STATUS,C        ; skip if no borrow from low byte
        addlw   1               ; There was a borrow
        subwf   B0,W            ; high order difference
        movwf   C0              ; save it
        endm

SUB_NOWRAP	macro dest, source1, source2
    bsf	    STATUS,C
    movf    source2,W
    subwf   source1,W
    btfss   STATUS,C
    movlw   0
    movwf   dest
    endm

    noexpand
delay       macro freq4,freq10,freq20
    if      Freq==4
    fill    (nop),freq4
    endif
    if      Freq==10
    fill    (nop),freq10
    endif
    if      Freq==20
    fill    (nop),freq20
    endif
    endm

;;;;;;; Vectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    org    H'003'            ;Reset vector
    goto   Mainline    ;Branch past tables
    org    H'004'
    goto   IntService
    nop
    nop

;;;;;;;DisplayC_Table subroutine;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine is called with VFD_TEMP containing the offset from CDS
; to the desired byte.

DisplayC_Table
    movf    DIS_TEMP,W      ;Copy VFD_TEMP to W
    addwf   PCL,F           ;add adequate offset to PCL

Message_Start
_Info1
    retlw   H'80'
    dt      "Initializing...."
    retlw   0
_Info2
    retlw   H'C0'
    dt      "C.C.C.C.  aka C4"
    retlw   0
_Desired
    retlw   H'80'
    dt      "Desired Temp:"
    retlw   0
_Newline
    retlw   H'C0'
    retlw   0
_1
    retlw   H'80'
    dt      "1:"
    retlw   0
_2
    retlw   H'88' ;Changed to 88 -Domnitz
    dt      "2:"
    retlw   0
_3
    retlw   H'C0'
    dt      "3:"
    retlw   0
_4
    retlw   H'C8' ;Changed to C8 -Domnitz
    dt      "4:"
    retlw   0
;;; Only for Terminal Usage
_Prompt
    dt      "$ "
    retlw   0

;;;;;;; RPGtable subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine takes the two RPG outputs from ten milliseconds ago and the
; present two RPG outputs in W and returns +1, 0, or -1 on their basis

RPGtable
        addwf   PCL,F           ;Go to proper table entry
        retlw   0               ;00 -> 00
        retlw   -1              ;00 -> 01
        retlw   +1              ;00 -> 10
        retlw   0               ;00 -> 11 (don't care)
        retlw   +1              ;01 -> 00
        retlw   0               ;01 -> 01
        retlw   0               ;01 -> 10 (don't care)
        retlw   -1              ;01 -> 11
        retlw   -1              ;10 -> 00
        retlw   0               ;10 -> 01 (don't care)
        retlw   0               ;10 -> 10
        retlw   +1              ;10 -> 11
        retlw   0               ;11 -> 00 (don't care)
        retlw   +1              ;11 -> 01
        retlw   -1              ;11 -> 10
        retlw   0               ;11 -> 11

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
ScreenTable
    addwf   PCL,F
    goto    Screen1
    goto    Screen2
    goto    Screen3
    goto    Screen4

;;;;;;; End of Tables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;; Mainline program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Mainline
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    call    Initial             ;Initialize variables and system
    call    InitVFD             ;Initialize the VFD

    movlw   _Info1-Message_Start ; Print message on VFD
    call    DisplayC
    movlw   _Info2-Message_Start
    call    DisplayC

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; MainLoop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MainLoop

    call    RPGchange
    call    RPG
    call    DecrementFans       ; sets up the fans to blow according to thier duty cycle
                                ; Stan Gryskiewicz
    call    LoopTime            ; Force loop time to be ten milliseconds

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    decf    LOOPTIME,F              ; decrement looptime and determine if it's zero
    movf    LOOPTIME,W
    btfss   STATUS,Z
    goto    MainLoop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    bsf     PORTA,2
    bsf     PORTA,1
    MOVLF   MechDelayConst,LOOPTIME

    ; The "once a second subroutines"

    call    GetTemp             ; get the temperature and puts them in degree format into 4 variables
                                ; Justin Dominitz
    call    ControlFan          ; this function converts degrees to power cycles for a fan
                                ; Erik Rainey
    call    ResetFans           ; resets the duty cycles of the fans
                                ; Stan Gryskiewicz
    call    GetFanSpeeds        ; doesn't actually compute fans speeds, it nabs them from the CCp1 registers and chages the mux over every once in a while.
                                ; Erik Rainey
    call    DisplayInfo         ; prints out the information to the VFD, or termial if we wish
                                ; Erik Rainey
    bcf     PORTA,2
    bcf     PORTA,1

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    goto    MainLoop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;; Initial subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine performs all initializations of variables and registers.

Initial
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    BANK1                       ; Set register access to bank 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    MOVLF   B'00000110',ADCON1  ; Select PORTE pins for all digital I/O
    clrf    TRISA               ; Set up PORTA
    clrf    TRISB               ; Set up PORTB
    MOVLF   B'10011111',TRISC   ; Set up PORTC
    clrf    TRISD               ; Set up PORTD
    clrf    TRISE               ; Set up PORTE
    MOVLF   249,PR2             ; Set up Timer2 for a looptime of 10 ms
    bsf     PIE1,RCIE           ; we want to jump right to RC stuff though
    bsf     PIE1,CCP1IE         ; enable interrupts on CCP1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    BANK0                       ; Set register access back to bank 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    clrf    PORTA               ; Clear Lights, Buzzer, etc...
    MOVLF   H'FF',PORTD         ; Reset Fan Control Lines
    MOVLF   MechDelayConst,LOOPTIME
    MOVLF   B'01001101',T2CON   ; Finish set up of Timer2 (see page 62)
    MOVLF   B'00000101',CCP1CON
    MOVLF   1,BLNKCNT           ; Initialize BLNKCNT

    MOVLF   100,GeneralCycle

    MOVFF   GeneralCycle,DutyCycle0
    MOVFF   GeneralCycle,DutyCycle1
    MOVFF   GeneralCycle,DutyCycle2
    MOVFF   GeneralCycle,DutyCycle3
    MOVFF   GeneralCycle,DutyCycle4
    MOVFF   GeneralCycle,DutyCycle5
    MOVFF   GeneralCycle,DutyCycle6
    MOVFF   GeneralCycle,DutyCycle7

    MOVLF   25,DESIREDTEMP
    MOVLF   0,SCREENNUM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                                ; cross bank stuff
    clrf    TEMPNUM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    return


;;;;;;; InitVFD subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Initialize the Noritake 16x2 character VFD.
; (Initialize PIC ports prior to calling this subroutine.)
; This subroutine uses a one-byte RAM variable called VFD_TEMP.

InitVFD
    bsf     PORTD,7
    MOVLF   25,DIS_TEMP     ;Wait 1/4 second
InitVFD_1
    call    LoopTime        ;Call LoopTime 25 times
    decfsz  DIS_TEMP,F
    goto    InitVFD_1

    ;VFD_TEMP now equals 0

    bcf     PORTA,4      ;We're writing!

    bcf     PORTA,3      ;RS=0

    MOVLF   H'0C',PORTB  ; Display ON!
    bsf     PORTA,5      ;Drive E high
    bcf     PORTA,5      ;Drive E low so VFD will process input
    call    T40          ;Wait 40 usec

    bsf     PORTA,3      ;RS=1

⌨️ 快捷键说明

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