 |
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,832
|
|
نشاط [ F.Abdelaziz ]
قوة السمعة:
|
|
26-04-2015, 01:50 AM
المشاركة 26
|
|
تدريب : استخدام المحول ADC لقياس درجة الحرارة بالحساس LM35 مع المترجم CCS C :
تدريب : استخدام المحول ADC لقياس درجة الحرارة بالحساس LM35 مع المترجم CCS C :
البرنامج :
كود:
/*
PIC16F877A and LM35 Based Temperature Monitor
*/
#include <16F877A.h>
#device adc=10 // Set ADC resolution to 10Bit
#use delay(clock=4000000)
#include "lcd.c"
#define LOAD PIN_B7
#define THRES 30.0 // load switching threshold in Celsius
int16 digital_reading; // ADC resolution is 10Bit, an 8Bit integer is not enough to hold the reading
float temp;
void main()
{
/* 1- ADC Initialization */
setup_adc(ADC_CLOCK_INTERNAL); // initialize ADC with a sampling rate of Crystal/4 MHz
setup_adc_ports(RA0_ANALOG); // set PIN_A0 as analog input channel
set_adc_channel(0); // point ADC to channel 0 for ADC reading
delay_ms(1); // ADC module is slow, needs some time to adjust.
/* 2- Peripherals Configurations */
lcd_init(); // Turn LCD ON, along with other initialization commands
output_low(LOAD); // the load is initially OFF
lcd_gotoxy(1,1); // point LCD cursor to col1 row1
lcd_putc("Temperature is:"); // print on LCD
while(TRUE) // infinite loop
{
digital_reading = read_adc(); // capture current temperature reading
delay_us(100); // 0.1ms delay for ADC stabilization
temp = digital_reading * 0.4883; // convert reading to Celsius
lcd_gotoxy(1,2); // point LCD cursor to col1 row2
printf(lcd_putc,"%2.1f C",temp); // print value on LCD,format % : 2digits.1digit
if(temp>=THRES) output_high(LOAD); // Control Load
else output_low(LOAD);
delay_ms(1000); // 1 second delay between readings
}
}

|