任何人都可以帮我理解这个PIC微控制器程序吗?

时间:2011-11-27 14:04:20

标签: assembly microcontroller pic

我是一名工科学生,我对这个课程感到有些困惑。任何人都可以帮我填写计划中每一行的剩余评论吗?我是这个节目的新手。

#INCLUDE<P16F88.INC> ; PIC definitions

SET_UPPER   EQU 0x20
SET_LOWER   EQU 0x21
READ_UPPER  EQU 0x22
READ_LOWER  EQU 0x23
P_gain      EQU 0x24
I_gain      EQU 0x25
D_gain      EQU 0x26
Prop        EQU 0x27
Int         EQU 0x28
Diff        EQU 0x29
DError      EQU 0x30
IError      EQU 0x31
temp        EQU 0x32

    ORG 0h
;****************************
;       INITIZLIZATION
;****************************

    BANKSEL TRISA           ;SELECT TRISA BANL
    MOVLW   B'00000011'     ;MAKE PIN0  AND 1 INPUT
    MOVWF   TRISA           ;Writing to TRISA register
    BANKSEL ANSEL
    MOVLW   B'00000011'     ;MAKE PA0 AND PA1 ANALOG INPUT
    MOVWF   ANSEL
    BANKSEL PORTA
    MOVLW   0x80            ;FOSC/32 AND CHANNEL0
    MOVWF   ADCON0
    MOVLW   0x00
    CLRF    ADCON1          ;LEFT JUSTIFIED ADC VALUE
    CLRF    CCP1CON         ;PWM MODULE
    CLRF    TRISB           ;MAKE PORT B O/P FOR PWM
    MOVLW   0xFF
    MOVWF   PR2
    CLRF    CCPR1L          ;0 DUTY CYCLE AT START
    MOVLW   0x01
    MOVWF   T2CON           ;PRESCALER 4 AND POSTSCALAR 1
    BSF     T2CON,TMR2ON    ;SWITCH ON TIMER
;****************************
;           MAIN
;****************************
MAIN
    CALL    SET_POINT       ;READ SET POINT
    CALL    READ_TEMP       ;READ TEMPERTAURE
    CALL    COMPARE         ;COMPARE AND FIND GAIN VALUE
    CALL    CONTROL         ;MAP GAIN TO DUTY CYCLE
    GOTO    MAIN

;****************************
;       READ SET PT.
;****************************
SET_POINT
    MOVLW   0x80
    MOVWF   ADCON0          ;CHANNEL 0 ADC
    BSF     ADCON0,ADON     ;SWITCH ON ADC
    NOP                     ;WAIT ACQUISITION TIME
    NOP
    NOP
    NOP
    NOP
    BSF     ADCON0,GO
ADC 
    BTFSC   ADCON0,GO       ;WAIT TILL CONVERSION IS COMPLETE
    GOTO    ADC
    MOVF    ADRESH,W        ;READ ADC VALUES
    MOVWF   SET_UPPER
    BANKSEL ADRESL
    MOVF    ADRESL,W
    MOVWF   SET_LOWER
    BANKSEL PORTA
    RETURN
;****************************
;      READ TEMPERATURE
;****************************
READ_TEMP
    MOVLW   0x88            ;ADC CHANNEL 1 SELECT
    MOVWF   ADCON0
    BSF     ADCON0,ADON     ;SWITCH ON ADC
    NOP                     ;WAIT ACQUSITION TIME
    NOP
    NOP
    NOP
    NOP
    BSF     ADCON0,GO       ;START CONVERSION
ADC0    
    BTFSC   ADCON0,GO       ;WAIT TILL CONVERSION IS COMPLETE
    GOTO    ADC0
    MOVF    ADRESH,W
    MOVWF   READ_UPPER      ;READ ADC VALUE
    BANKSEL ADRESL
    MOVF    ADRESL,W
    MOVWF   READ_LOWER
    BANKSEL PORTA
    RETURN
;******************************
;   COMPUTE ERROR AND GAINS
;******************************
COMPARE
    MOVF    SET_UPPER,W
    SUBWF   READ_UPPER,W    ;SUBTRACT READ VALUE FROM SET POINT
    SUBWF   DError,F        ;COMPUTE INTEGRAL ERROR
    ADDWF   IError,F        ;COMPUTE DIFFERENTIAL ERROR

    MOVWF   Prop            ;MOVE COMPUTED ERROR TO PROP
    MOVF    P_gain,W        
    MOVWF   temp
    MOVF    Prop,W          
Prop_loop
    ADDWF   Prop,F          ;ADD PRPORTIONAL ERROR PROPORTIONAL GAIN TIMES
    DECFSZ  temp,F
    GOTO    Prop_loop

    MOVF    IError,W
    MOVWF   Int
    MOVF    I_gain,W
    MOVWF   temp
    MOVF    Int,W   
Int_loop
    ADDWF   Int,F           ;ADD INTEGRAL ERROR INTEGRAL GAIN TIMES
    DECFSZ  temp,F
    GOTO    Int_loop

    MOVF    DError,W
    MOVWF   Diff
    MOVF    D_gain,W
    MOVWF   temp
    MOVF    Diff,W  
Diff_loop
    ADDWF   Diff,F          ;ADD DIFFERENTIAL ERROR DIFFERENTIAL GAIN TIMES
    DECFSZ  temp,F
    GOTO    Diff_loop
    RETURN
;***************************
;   MAP GAIN TO PWM VALUE
;***************************
CONTROL
    MOVF    Prop,W          ;ADD ALL THREE COMPUTED VALUES
    ADDWF   Int,W
    ADDWF   Diff,W
    MOVWF   CCPR1L          ;MOVE TO CCPR1L TO MAKE IT HI TIME OF PWM
    RETURN

    END

1 个答案:

答案 0 :(得分:0)

我不会再对这样的程序添加任何评论。除非你有具体的问题要问,否则对我来说似乎很清楚。正如有人在评论中所说,它似乎是一个PID控制回路,它根据ADC的输入驱动PWM输出。

唯一不寻常的事情似乎是通过循环(各种DECFSZ temp,F; GOTO foo_loop循环)乘以整数增益。