I'm a struggling learner who took a few months out of all this - I wish I hadn't now!
Anyway, I'm re-starting with a different (simpler!) chip - a 12f683 - just getting back to the basics right now....AtoD.
I found some code posted by Bruce on here that I shamelessly used (changing the pins to suit my setup)...
Code:
@MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON
@MyConfig = MyConfig & _MCLRE_OFF
CMCON0 = 7 ' Disable comparator
ANSEL = %00000010 ' Set GPIO.1 to A/D
ADCON0.7 = 1 ' Right justify for 10-bit
TRISIO = %00000010 ' GP.0 = serial out, GPIO.1 = A/D in, rest outputs
DEFINE OSC 8 ' Internal 8MHz
DEFINE DEBUG_REG GPIO ' Define DEBUG port
DEFINE DEBUG_BIT 0 ' Set GPIO.0 as DEBUG serial output pin
DEFINE DEBUG_BAUD 9600 ' DEBUG baud rate = 9600 bps
DEFINE DEBUG_MODE 0 ' 1 = inverted, 0 = true
DEFINE ADC_BITS 10 ' 10-bit resolution
DEFINE ADC_CLOCK 5 ' Set clock source to Frc/16
DEFINE ADC_SAMPLEUS 50 ' Sample time in uS before A/D is started
Quanta CON 1251 ' For 10-bit A/D +Vref = 5V : 5V/1023*256=1.251=Quanta
' PIN# NAME USE & CONNECTION
' 1 Vdd +5VDC power supply
' 2 GPIO.5 N/C (N/C = NO CONNECTION)
' 3 GPIO.4 N/C
' 4 GPIO.3 N/C
' 5 GPIO.2 N/C
' 6 GPIO.1 A/D input pin
' 7 GPIO.0 Serial output pin to PC serial port RX pin
' 8 Vss Power supply ground (also connect to DB-9 pin #5)
'-------------------------------------------------------------------------
ADval VAR WORD ' A/D result
MAIN:
ADCIN 1, ADval ' Read A/D
DEBUG DEC ADval DIG 3,".",DEC3 ADval,"V",13, 10
PAUSE 500
GOTO MAIN
END
the thing is it'll read 5V for 0V presented on pin 6 GP1 (I view the AtoD result using the PICkit 2 Usart tool)- but nothing in between (only two states!)
Any ideas please before I just give this all up as a bad job and turn to constructing replica stately homes out of discarded matchsticks.
Bookmarks