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 goto temp_read END
Bookmarks