 |
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,894
|
|
نشاط [ F.Abdelaziz ]
قوة السمعة:332
|
|
12-03-2012, 05:35 PM
المشاركة 5
|
|
كود:
/* This project measures the temperature with a Thermistor and
* then displays on a LCD
Eng.F.Abdelaziz
http://www.eeecb.com/vb/index.php
*/
// LCD module connections
sbit LCD_RS at RC0_bit;
sbit LCD_EN at RC1_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISC0_bit;
sbit LCD_EN_Direction at TRISC1_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections
float Vt,Rt,temp,y; // Floating-point Types
char temperature[4] ;// string array
void main()
{
/* Initialize the microcontroller */
TRISA=0xFF; //configure PORTA as Input direction
TRISB=0; //configure PORTB as Output direction
TRISC=0; //configure PORTD as Output direction
PORTA=0; //Clear
PORTB=0;
PORTC=0;
//===============================================
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // CLEAR display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"Thermistor TEMP.");
while(1) {
Vt = ADC_Read(0); // Get 10-bit results of AD conversion any number from 0-1023
Vt = Vt *5 /1024 ; // change to volt
/* Calculate thermistor resistance Rt : Rt=Vt * [Rs/ (Vs-Vt) */
Rt = Vt*10000.0/(5.0-Vt) ; // Change to Resistance
/* Calculate temperature temp :Change to temperaure in steps */
y = log(0.0001*Rt) ;
y = 3.354/1000+y*2.272/10000;
y=1/y ;
temp = y-273.15 ;// Change from K to C
ByteToStr(temp,temperature); // Change to string
Lcd_Out(2,6,temperature); // Display
Lcd_Chr(2, 9, 223);// Add degree character
Lcd_Chr(2, 10, 'C');// Add letter "c"
delay_ms(2000);
//==============
}
}
|