Hi, Bobbo
Your main problem was scaling temps before displaying ...
try this one :
Interesting parts have been explained ...Code:'**************************************************************** '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 05/03/2010 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** '* Name : Temp 675'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_on,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 ANSEL = %00111000 ' Set ADC clock = Frc, GPIO.4, 1 = A/D ADCON0 = %10001100 ' Right justify, use Vdd as Vref ' Select channel 3 !!! CMCON = 7 '---------Define Vairables samples VAR WORD ' Multiple A/D sample accumulator dummy var word ' DIV32 intermediate value sample VAR BYTE ' Holds number of samples to take temp VAR BYTE ' Temperature storage ... might be a WORD !!! ( 0 - 1023 !!! ) CLEAR ' clear Variables 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 GPIO = 0 TRISIO = %010000 'set GPIO.0, GPIO.1, GPIO.2 as output (LEDs) & GPIO.4 as input '---------Main Program 'Flash White LED on Start HIGH LED0 Pause 500 LOW LED0 While 1 TEMP_READ: 'Subroutine to measure temp input = 10 mv/°C ~250 mv 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 result is ~ 50 ( .25 / 5 * 1024 ) samples = samples + temp PAUSE 12 ' Wait 1/4 seconds per display ... (20 x 12 ms ) NEXT sample temp = samples/20 'Average over 20 samples (Every 5 seconds) result is ~ 50 ' temp=(temp* 10)/2 ' Result is 250 ... may overflow !!! so, the mult is no use !!! '******************************************************************************* ' Trim to scale '******************************************************************************** Dummy = 500 * temp ' 500 = 5000 mv full scale / 10 mv per degree temp = DIV32 1024 ' Number is Deg C Now ... '******************************************************************************** SELECT CASE temp CASE is < 20 'Less than 20deg - White LED HIGH LED0 LOW LED1 LOW LED2 CASE is < 31 'Between 20deg and 30deg - Blue LOW LED0 HIGH LED1 LOW LED2 CASE is < 45 'Greater than 30deg - but less than 45 deg Red HIGH LED2 LOW LED1 LOW LED0 CASE Else ' Too cold !!! or dangerously hot ... let's blink everyting !!! HIGH LED0 HIGH LED1 HIGH LED2 PAUSE 250 LOW LED0 LOW LED1 LOW LED2 END SELECT wend END
now, have a good bath ... you've sweat a lot on this one ... ROFL.




Bookmarks