مشروع لبيان درجة الحرارة الموجبة والسالبة باستخدام الحساس LM35 :
البرنامج :
كود:
//program Thermometer_with_LM35 + & -
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
unsigned temp; // unsigned (int) 0 .. 65535
unsigned tempn;
short tempout ; //(signed) short (int) - 128 .. 127
char res[5];
void main(){
TRISA = 0xFF; // designate PORTA as input
TRISB = 0; // as outputs
//Ideal standard
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"ENG.F.ABDELAZIZ"); // Write text in first row
Lcd_Out(2,1,"WELCOME"); // Write text in second row
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,1,"ROOM TEMP."); // Write text in first row
while (1) {
temp = ADC_read(0);
tempn = ADC_read(1);
temp = temp/2.046;
tempn = tempn/2.046;
tempout = temp - tempn;
/*
void ShortToStr(short input, char *output);
Converts input signed short number to a string
short t = -24;
char txt[5];
...
ShortToStr(t, txt); // txt is " -24" (one blank here)
*/
shortToStr(tempout,res);
Lcd_Out(2,1,res);
/*
Write character "i" at row 2, column 3:
Lcd_Chr(2, 3, 'i');
Write character "e" at current cursor position:
Lcd_Chr_Cp('e');*/
Lcd_Chr_Cp(223);
Lcd_Chr_Cp('C');
delay_ms(1000);
}
}