PIC18F45K22 ADC不工作,定时器计数太快

时间:2015-08-11 09:59:30

标签: assembly timer microcontroller pic adc

正如我所说,两个主要问题是我的ADC转换不起作用,并且不知何故,计时器的速度比它应该的要快。

如果我有8 MHz XT振荡器,这意味着计数器工作在8/4 = 2 Mhz,这意味着每个计数为0.5 us,没有预分频器。我将timer0配置为16位定时器。

对于ADC ......我完全不知道它有什么问题。

注意:A0引脚是模拟的,我从一个传感器获得直流信号。

源代码:http://pastebin.com/U8YynkES

提前致谢并欢呼!

a   list p=18f45K22     ;list directive to define processor
#include <p18F45K22.inc>
    errorlevel -302     ;suppress "not in bank 0" messa

    CONFIG FOSC = XT    ; Oscillator (LP,XT,HSHP,HSMP,RC,RCIO6,ECHP,ECHPIO6; INTIO67,INTIO7,ECMPIO6,ECLP,ECLPIO6)
    CONFIG PLLCFG = OFF    ; 4X PLL Enable
    CONFIG PRICLKEN = OFF   ; Primary clock Enable
    CONFIG FCMEN = OFF      ; Fail-Safe Clock Monitor Enable
    CONFIG IESO = OFF       ; Internal/External Oscillator Switchove

    CBLOCK  0x30
    RESULTHI
    RESULTLO
    amnt
    ENDC

    ORG 0x0000
    goto ResetCode

ResetCode:
    CLRF PCLATH

MAIN:
    banksel TRISA
    clrf PORTA
    clrf PORTB
    clrf PORTC
    clrf PORTD
    MOVLW B'00000000'
    MOVWF TRISC
    MOVWF TRISB
    MOVWF TRISD
    MOVWF amnt
MAIN1:
    MOVLW B'10000111'
    CLRF TMR0
    MOVWF T0CON
TIMER1:
    BTFSS INTCON, TMR0IF
    GOTO TIMER1
    INCF amnt
    CLRF T0CON
    BCF INTCON, TMR0IF
ADC1:
    BTFSS amnt, 4
    GOTO MAIN1
    COMF PORTB
    CLRF amnt
    MOVLW B'10101110' ;right justify, Frc,
    MOVWF ADCON2 ; & 12 TAD ACQ time
    MOVLW B'00000000' ;ADC ref = Vdd,Vss
    MOVWF ADCON1 ;
    BSF TRISA,0 ;Set RA0 to input
    BSF ANSELA,0 ;Set RA0 to analog
    MOVLW B'00000001' ;AN0, ADC on
    MOVWF ADCON0 ;
    BSF ADCON0,GO ;Start conversion
ADCPoll:
    BTFSC ADCON0,GO ;Is conversion done?
    BRA ADCPoll ;No, test again
    ; Result is complete - store 2 MSbits in
    ; RESULTHI and 8 LSbits in RESULTLO
    MOVFF ADRESH,RESULTHI
    MOVFF ADRESL,RESULTLO
    CLRF ADCON0

    CLRF PORTD
    MOVLW RESULTLO
    MOVWF PORTD
    ;MOVLW b'00000000'
    ;MOVWF IPR4
    GOTO MAIN1
    END

0 个答案:

没有答案