لاستعراض العمل الفعلى لمثل هذا الحساس راقب وحلل كود المصدر للبرنامج التالى :
كود:
//LCD Pin 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, PreI;
float Pre;
char Text[16];
//LCD initiation.
Lcd_Init();
//Clearing the cursor.
Lcd_Cmd(_LCD_CURSOR_OFF);
//Printing text
Lcd_Out( 1, 1, "Pressure in KPa:");
while(1) //Infinite Loop.
{
//Reading ADC channel 0.
Radc = ADC_Read(0);
//Using the equation
Pre = 0.10861*Radc+10,5555;
//Forces the result to the integer part.
PreI = Pre;
//Converts the integer to a string.
IntToStr( PreI, Text );
//prints the result.
Lcd_Out( 2, 1, Text);
//Delay 100 m seconds.
delay_ms(100);
}
}