فى هذا الإطار يمكن استخدام الحساس والميكروكونترولر PIC 16F877A فى تنفيذ البرنامج , راقب وحلل كود البرنامج التالى :
كود:
//LCD Pins Definition
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
// LCD TRIS Definition
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
void main( void )
{
// Variables Declaration .
unsigned int Radc, TemI;
float Tem;
char Text[16];
//Sets the ADC module with pin AN3
//as positive reference voltage.
ADCON1 = 0b11000001;
//LCD initiation
Lcd_Init();
//Clearing the cursor.
Lcd_Cmd(_LCD_CURSOR_OFF);
//Printing text.
Lcd_Out( 1, 1, "Temperatura:");
while(1) //Infinite Loop.
{
//Reading ADC channel 0.
Radc = ADC_Read(0);
//Using the equation
Tem = 0.244*Radc;
//Converts the result to an integer.
TemI = Tem;
//Integer converted to a string.
IntToStr( TemI, Text );
//Prints the result.
Lcd_Out( 2, 1, Text);
//Delay 100m seconds.
delay_ms(100);
}
}


