Here's an example of reading an analog voltage with a 12F683. I'll let you figure out the LED part...;}
Code:@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF DEFINE OSC 8 ' Internal 8MHz DEFINE DEBUG_REG GPIO ' Define DEBUG port DEFINE DEBUG_BIT 1 ' Set GPIO.1 as DEBUG serial output pin DEFINE DEBUG_BAUD 9600 ' DEBUG baud rate = 9600 bps DEFINE DEBUG_MODE 1 ' 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 conversion 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 Serial output pin to PC serial port RX pin ' 7 GPIO.0 A/D input pin ' 8 Vss Power supply ground (also connect to DB-9 pin #5) '------------------------------------------------------------------------- CMCON0 = 7 ' Disable comparator ANSEL = %00000001 ' Set GPIO.0 to A/D ADCON0.7 = 1 ' Right justify for 10-bit TRISIO = %00000001 ' GP.1 = serial out, GPIO.0 = A/D in, rest outputs OSCCON = %01110000 ' Internal 8MHz osc ADval VAR WORD ' A/D conversion result MAIN: ADCIN 0, ADval ' Read A/D ADval = ADval */ Quanta DEBUG DEC ADval DIG 3,".",DEC3 ADval,"~" PAUSE 200 GOTO MAIN END




Bookmarks