Hello ,
Does anyone have an example for this pic, I want an2 in adc and A0 as Tx and A1 as Rx. I've tried to derive some from other programs but I keep stumbling on the datasheet.
Hans
-- chip setup
include 12f1840
-- Internal oscillator at 8 MHz with PLL enabled -> 32 MHz
pragma target clock 32_000_000 -- oscillator frequency
pragma target OSC INTOSC_NOCLKOUT -- internal oscillator
pragma target WDT DISABLED -- watchdog off
pragma target PWRTE ENABLED -- power up delay
pragma target MCLR EXTERNAL -- reset externally
pragma target BROWNOUT DISABLED -- no brownout
pragma target CLKOUTEN DISABLED -- no clock out
pragma target IESO DISABLED -- no osc switchover
pragma target FCMEN DISABLED -- no clock monitoring
pragma target PLLEN ENABLED -- PLL enabled
pragma target LVP DISABLED -- allow LVP
OSCCON_IRCF = 0b1110 -- 8 MHz (+ PLL -> 32 MHz)
OSCCON_SCS = 0b00 -- Clock determined by fuses
-- OSCCON_PLLEN = TRUE -- PLL fixed enabled by configuration bits
enable_digital_io() -- all pins digital
const byte ADC_CHANNEL = 2 -- potmeter connected to pin_AN3
ADCON0_CHS2 = TRUE -- port 3 is analog input (default)
pin_AN2_direction = input
-- Step 2: Set VDD and VSS as Vref
FVRCON_FVREN = true
-- Step 3: Use Frc as ADC clock
ANSEL_ADCS = 0b011
const ADC_RSOURCE = 4_700 -- Input resistance: 4.7K potmeter
-- Now we can include the library
include adc
-- And initialize the whole with our parameters
adc_init()
var byte DIR
forever loop
DIR = adc_read_low_res(ADC_CHANNEL)
end loop