Hi All,

I'm a bit of a n00b when it comes to the PIC world, :-).

I have developed previously in C, Cobol, VB6 (and .net) and C++, however I have decided to use PIC Basic for my embedded projects. I started with the simple blink (with and without button input) with a few LEDs hanging off the various ports, then worked up to rotating beacons (using PWM).

My next mini learning project is to connect an LM35 to a 12F675. Along with the LM35 im connecting 3 LEDs, one white, one blue and one red simply to indicate a range of temps per color (i.e. if Temp < 30 then light the white LED etc) - Something I have got working through my Arduino and want to move to a more cost effective platform, :-).

I have spent a few evenings mulling over it and changing the code, flashing and testing with not much success. I think my issues are stemming from my lack of understanding of the various registers used i.e. ANSEL, TRISIO etc, although I think I have read the datasheet correctly its still not giving me the desired result.

Below is the code I have so far, please could you look and advise where I am going wrong?

Code:
'Using PIC 12F675 with White LED connected to Pin 7, Blue LED on Pin 6, 
'Red LED on pin 7. Vdd is supplied as a regulated 5v to pin 1, Ground to pin 8.
'LM 35 connected to Vdd and Ground + Centre pin connected to Pin 3 (AN3)
'Pin 4 disconnected - Have tried connecting to Vdd with 10K res and turning MCLR_on with no sucess 
                                               
@ device pic12F675,INTRC_OSC,wdt_off,pwrt_on,protect_off,MCLR_off
DEFINE CHAR_PACING 1000
DEFINE OSC 4                                      'Set internal osc. To 4MHz

'---------Define ADCin Parameters   
DEFINE ADC_BITS 10 'set number of bits in result
DEFINE ADC_CLOCK 3 'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS

'---------Define Vairables         
samples VAR WORD        ' Multiple A/D sample accumulator
sample  VAR BYTE        ' Holds number of samples to take
temp    VAR BYTE        ' Temperature storage
           ' clear Samples

LED0	Con	0	' GPIO.0 = White LED
LED1    CON 1   ' GPIO.1 = Blue LED              
LED2    CON 2   ' GPIO.2 = Red LED   
               
'--------Configuring I/O PORTS
TRISIO = %010000   'set GPIO.0, GPIO.1, GPIO.2 as output (LEDs) & GPIO.4 as input
ANSEL = %00111000 ' Set ADC clock = Frc, GPIO.4, 1 = A/D 
ADCON0 = %10000000 ' Right justify, use Vdd as Vref 
CMCON = 7

'---------Main Program 
'Flash White LED on Start
HIGH LED0
Pause 500
LOW LED0       
              
TEMP_READ:                                      'Subroutine to measure temp
            temp = 0                            'Clear temp register
            samples = 0                         'Clear samples register 
            FOR sample = 1 TO 20                'Take 20 samples
                ADCIN 3, temp                   ' Read AN3 into temp variable
                samples = samples + temp      
                PAUSE 250                       ' Wait 1/4 seconds per reading
            NEXT sample                         
                temp = samples/20               'Average over 20 samples (Every 5 seconds)
                temp=(temp* 10)/2               
                                                 
if TEMP <20 then      'Less than 20deg - White LED
    HIGH LED0
    LOW LED1
    LOW LED2
    GOTO             TEMP_READ              
ENDIF

IF TEMP >20 AND temp <30 then       'Between 20deg and 30deg - Blue
    LOW LED0
    HIGH LED1
    LOW LED2
    GOTO             TEMP_READ              
ENDIF

IF TEMP >30 then                    'Greater than 30deg - Red
    HIGH LED2
    LOW LED1
    LOW LED0
    GOTO             TEMP_READ              
endif

END