我正在尝试使用 MPLAB X 模拟器模拟以下程序,但 ADC 似乎无法正常工作。我已将具有“0303”值的激励文件附加到 ADRESL 寄存器,但我没有读取数据,并且在模拟器控制台中我收到警告“ADC-W101:所选通道配置为数字 IO。所选通道:0。”。此外,一旦置位,即使 ADIF 被触发,ADCON0 GO 位也不会被清除。图片是16f88。是 MPLAB X 模拟器的问题吗?我已经用 16f88 检查了 MPLABX sim 的限制,但没有关于 ADC 的内容。
processor 16f88
include <P16F88.INC>
errorlevel 0, -302 ; suppress messages about bank selection
__CONFIG _CONFIG1, _WDT_OFF & _FOSC_INTOSCIO & _MCLR_ON & _LVP_OFF
udata
LIGHT_SENS res 2
TEMP_W res 1
TEMP_STATUS res 1
TEMP_PCLATH res 1
FLAGS res 1
TIME1 equ h'00000'
ADC equ h'00001'
reset code 0x00
pagesel main
goto main
isr code 0x04
_isr_entry:
movwf TEMP_W
swapf STATUS, W
clrf STATUS
movwf TEMP_STATUS
movf PCLATH, W
movwf TEMP_PCLATH
clrf PCLATH
_isr_test_tmr0:
banksel INTCON
btfss INTCON, TMR0IF
goto _isr_test_adc
_tmr0_isr:
_tmr0_isr_entry:
banksel TMR0
movlw d'100'
movwf TMR0
bsf FLAGS, TIME1
_tmr0_isr_exit:
banksel INTCON
bcf INTCON, TMR0IF
_isr_test_adc:
banksel PIR1
btfss PIR1, ADIF
goto _isr_exit
_adc_isr:
_adc_isr_entry:
banksel FLAGS
bsf FLAGS, ADC
_adc_isr_exit:
banksel PIR1
bcf PIR1, ADIF
_isr_exit:
movf TEMP_PCLATH, W
movwf PCLATH
swapf TEMP_STATUS, W
movwf STATUS
swapf TEMP_W, F
swapf TEMP_W, W
retfie
;===============================================================================
main code
main
_setup_oscillator:
banksel OSCCON
movlw b'01100000' ; 4 MHz Internal Oscillator Clock Speed
movwf OSCCON
clrf OSCTUNE ; Center frequency
;===============================================================================
_setup_pin:
banksel PORTA
clrf PORTA ; clears the latch on PORTA before configuring it
banksel PORTB
clrf PORTB ; clears the latch on PORTB before configuring it
_setup_tmr0:
banksel TMR0
movlw d'100'
movwf TMR0
banksel OPTION_REG
movlw b'11010101' ; Prescaler is assigned to Timer0, rate 1:256, Timer mode
movwf OPTION_REG
bsf INTCON, TMR0IE ; enables Timer0 Overflow Interrupt
_setup_adcs:
banksel TRISA ; set PORTA pin direction
movlw h'01' ; RA0 is analog input
movwf TRISA
banksel ANSEL ; select analog pins
movlw h'01' ; AN0 is analog I/O
movwf ANSEL
banksel ADCON0 ; A/D channel selection
movlw b'10000000' ; channel AN0 selected
movwf ADCON0
banksel ADCON1 ; voltage reference, result justification, A/D clock
movlw b'10000000' ; right just, Vdd/Vss ref
movwf ADCON1
banksel ADCON0
bsf ADCON0, ADON
banksel PIE1
bsf PIE1, ADIE
banksel PIR1 ; enables A/DC interrupt
bcf PIR1, ADIF
banksel INTCON
bsf INTCON, GIE ; enables global interrupt
bsf INTCON, PEIE ; enables peripheral interrupt
_setup_application:
clrf FLAGS
_main_loop:
call CheckAdc
_main_loop_exit:
clrf FLAGS
goto _main_loop
;===============================================================================
CheckAdc
_CheckAdc_entry:
banksel FLAGS
btfss FLAGS, ADC ; tests if ADC is ready
goto _CheckAdc_restart
banksel ADRESL
movf ADRESL, W
banksel LIGHT_SENS
movwf LIGHT_SENS
banksel ADRESH
movf ADRESH, W
banksel LIGHT_SENS
movwf LIGHT_SENS+1
_CheckAdc_restart:
banksel FLAGS
btfss FLAGS, TIME1 ; tests if 1ms timer run out
goto _CheckAdc_exit
banksel ADCON0
btfss ADCON0, GO
bsf ADCON0, GO
_CheckAdc_exit:
return
end ; End Of Program