here is an example of reading an AD input on a 12F683... you will have to adapt it to your needs.
don't forget that pin RA4 is analog input 3. also don't forget that RA3 defaults to MCLR and also can ONLY be an input, never an Output.
Code:
'12F683
'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 12/24/2007 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
DEFINE DEBUG_REGG GPIO 'set debug port to gpio
DEFINE DEBUG_BIT 0 'use pin 0 for debug
DEFINE DEBUG_BAUD 2400 'set baud rate to 2400
DEFINE DEBUG_MODE 0 'communicate in true mode
' -----[ Initialization ]--------------------------------------------------
Reset:
TRISIO = %11001100 'configure GPIO.0,1,4,5 as outputs, gpio.2 as input
ansel = %00000100 'and set gpio.2 as analog
cmcon0 = %00000111 'turn off the comparator
adcon0 = %00001011 'left jstfied,vdd,x,x,an2,an2,start,adc on
define adc_bits 8 'set up the a/d converter
define adc_clock 3
define adc_sampleus 50
adval var byte
' -----[ Program Code ]----------------------------------------------------
main:
adcin 2,adval
if adval=0 then main
debug "ad val= ",#adval,$0D,$0A
'pause 500
goto main
Bookmarks