 |
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,894
|
|
نشاط [ F.Abdelaziz ]
قوة السمعة:333
|
|
06-06-2015, 11:32 AM
المشاركة 3
|
|
برنامج المتحكم :
برنامج المتحكم :
كود:
///////////////////////////////////////////////////////////////////////////////////////////////////////
/*
PIC16F877A and LM35-LCD Based Temperature Monitor
*/
#include <16f877a.h>
#device adc=10 // Set ADC resolution to 10Bit
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#include <lcd.c>
#define LOAD PIN_B7 //Relay
#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()
{
/* 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.
/* 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(1) // 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
printf("Temperature is: %2.1f C\r\n",temp); // print value on RS232
if(temp>=THRES) output_high(LOAD); // if temp.>=30 then Control Load on
else output_low(LOAD); //else off
delay_ms(1000); // 1 second delay between readings
}
}
http://fathallaabdelaziz.forumarabia.com/
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|