Hello.
I'm trying to use ADCIN on 12F1840, here's the code:
The problem is that VOLTAGE variable always reads 1024, if input is not connected to ground.
Any ideas?
I'm trying to use ADCIN on 12F1840, here's the code:
Code:
;----[12F1840 Hardware Configuration]-------------------------------------------
#IF __PROCESSOR__ = "12F1840"
#DEFINE MCU_FOUND 1
#CONFIG
cfg1 = _FOSC_INTOSC ; INTOSC oscillator: I/O function on CLKIN pin
cfg1&= _WDTE_OFF ; WDT disabled
cfg1&= _PWRTE_OFF ; PWRT disabled
cfg1&= _MCLRE_OFF ; MCLR/VPP pin function is digital input
cfg1&= _CP_OFF ; Program memory code protection is disabled
cfg1&= _CPD_OFF ; Data memory code protection is disabled
cfg1&= _BOREN_ON ; Brown-out Reset enabled
cfg1&= _CLKOUTEN_OFF ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
cfg1&= _IESO_ON ; Internal/External Switchover mode is enabled
cfg1&= _FCMEN_ON ; Fail-Safe Clock Monitor is enabled
__CONFIG _CONFIG1, cfg1
cfg2 = _WRT_OFF ; Write protection off
cfg2&= _PLLEN_OFF ; 4x PLL disabled
cfg2&= _STVREN_ON ; Stack Overflow or Underflow will cause a Reset
cfg2&= _BORV_19 ; Brown-out Reset Voltage (Vbor), low trip point selected.
cfg2&= _LVP_OFF ; High-voltage on MCLR/VPP must be used for programming
__CONFIG _CONFIG2, cfg2
#ENDCONFIG
#ENDIF
;----[Verify Configs have been specified for Selected Processor]----------------
; Note: Only include this routine once, after all #CONFIG blocks
#IFNDEF MCU_FOUND
#ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
#ENDIF
OSCCON = %11110000 'SET INTOSC TO 32MHZ
TRISA=%00110000 'set LATAA.4 as input
ANSELA=%00010000 'set LATAA.4 as analog
ADCON0=%00001101 'ENABLE AND CONFIGURE ADC
ADCON1=%11100011 'JUSTIFY
CM1CON0=%00000000 'DISABLE COMPARATORS
DEFINE OSC 32
DEFINE ADC_BITS 10
DEFINE ADC_SAMPLEUS 50
DEFINE ADC_CLOCK 3
VOLTAGE VAR WORD
SHEMAVALI VAR LATA.4
LED VAR LATA.2
'PACUKA:
'HIGH LED
'PAUSE 200
'LOW LED
'PAUSE 200
'GOTO PACUKA
CIKLURI:
ADCIN 3,VOLTAGE
IF VOLTAGE=>1023 THEN
HIGH LED
else
low led
endif
pause 5
GOTO CIKLURI
Any ideas?