Temperature measurement entails knowing the degree of hotness or coldness of an object. it comes in handy to have an idea of the temperature of an object.
BASIC CODE ( Language : CCS C):
#include <18F2550.h>
#DEVICE ADC = 10
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOUSBDIV //USB clock source comes from primary oscillator
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES MCLR //Master Clear pin enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
// LCD PINS
#define LCD_DB4 PIN_B0
#define LCD_DB5 PIN_B1
#define LCD_DB6 PIN_B2
#define LCD_DB7 PIN_B3
#define LCD_E PIN_C0
#define LCD_RS PIN_C1
#include <flex_lcd.c>
#include <math.h>
float reading;
float temperature, fahrenheitTemp;
void main()
{
setup_adc(ADC_CLOCK_INTERNAL); // ADC clock
setup_adc_ports(AN0); // ADC channel combination
lcd_init(); // initializes the LCD
lcd_putc("\f"); // Clear the LCD
delay_ms(500);
while(true)
{
set_adc_channel(0); // Select channel
reading = read_adc(); // Get input
delay_ms(1000); // Wait 1 sec
temperature = (((reading*0.0048828125f))*100); // Scales input to Celsius, needs some calibration.
fahrenheitTemp = (temperature*1.8) + 32; // conversion to Fahrenheit
printf(lcd_putc,"\n%3.2f%CC, %3.2fF",temperature,0xdf, fahrenheitTemp);
}
}
This simple mini-project is built around a PIC18F2550 microcontroller and a industrial type "K" thermocouple. The thermocouple has a range of -270degrees celsius to about 1330 degrees celsius( please, refer to the datasheet for specification). The voltage from the thermocouple is conditioned using AD595 (0 degrees Celsius to 500degrees Celsius). Please, note that this is for educational purposes ONLY.
METHODOLOGY:
1. Sample the voltage readings from the thermocouple by using the internal ADC( in 10 bit mode for higher accuracy ) feature of the PIC microcontroller.
2. Scale the sample voltage to 10mV/C (as specified in the AD595 datasheet).
3. Output the signal using a Liquid Crystal Display(LCD).
The LCD driver can be found at www.ccsinfo.com/forum just place a search string for it.
The LCD driver can be found at www.ccsinfo.com/forum just place a search string for it.
...hope you would find this helpful! I would be glad to entertain suggestions, corrections, contributions, and questions.
Best regards.
BASIC CODE ( Language : CCS C):
#include <18F2550.h>
#DEVICE ADC = 10
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOUSBDIV //USB clock source comes from primary oscillator
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES MCLR //Master Clear pin enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
// LCD PINS
#define LCD_DB4 PIN_B0
#define LCD_DB5 PIN_B1
#define LCD_DB6 PIN_B2
#define LCD_DB7 PIN_B3
#define LCD_E PIN_C0
#define LCD_RS PIN_C1
#include <flex_lcd.c>
#include <math.h>
float reading;
float temperature, fahrenheitTemp;
void main()
{
setup_adc(ADC_CLOCK_INTERNAL); // ADC clock
setup_adc_ports(AN0); // ADC channel combination
lcd_init(); // initializes the LCD
lcd_putc("\f"); // Clear the LCD
delay_ms(500);
while(true)
{
set_adc_channel(0); // Select channel
reading = read_adc(); // Get input
delay_ms(1000); // Wait 1 sec
temperature = (((reading*0.0048828125f))*100); // Scales input to Celsius, needs some calibration.
fahrenheitTemp = (temperature*1.8) + 32; // conversion to Fahrenheit
printf(lcd_putc,"\n%3.2f%CC, %3.2fF",temperature,0xdf, fahrenheitTemp);
}
}