هذا هو البرنامج,,
unsigned short d2=0,i=0,i1=70,ch2=0,st=1,st1=1,i2=1,kp,m1=1,t1=0,t2=0,t3=0,sum=0;
unsigned short ch1=0,ch4,tc=0,n1=0,n0,t0=0,kp1,kp2,n45=0,n44=0,m=1,j=0;
unsigned short aab2(unsigned short k2),k2;
unsigned short aab3(unsigned short k3),k3;
void interrupt() {
d2++;
if(d2==250)
{
Usart_Write(sum);
Usart_Write(i1);
delay_ms(100);
}
if(d2>250)
d2=0;
TMR0 = 0;
INTCON = 0x20;
}
//----------------------------------------------------------------
void InitMain() {
LCD_Init(&PORTB); // initialize (4-bit interface connection)
LCD_Cmd(LCD_CURSOR_OFF); // send command to LCD (cursor off)
LCD_Cmd(LCD_CLEAR); // send command to LCD (clear LCD)
tc = "S/T:";
LCD_Out(2,1,tc);
tc = "T:";
LCD_Out(1,1,tc);
LCD_Chr(2,12,48+ch1);
LCD_Chr_CP(48+ch1);
LCD_Chr_CP(48+ch1);
LCD_Chr_CP('C');
LCD_Chr(1,12,48+ch1);
LCD_Chr_CP(48+ch1);
LCD_Chr_CP(48+ch1);
LCD_Chr_CP('C');
PIE1.F5=1;
TMR0 = 0x00; // clear TMRO
INTCON = 0xA0; // enable T0IE
ADCON1=0x00;
PORTA = 0;
TRISA = 0xFF;
PORTD = 0;
TRISD = 0x00;
OPTION_REG = 0x80;
TRISC=0;
PORTC=0;
Usart_Init(1200);
}//~ ------------------------------------------------------------------
void main() {
initMain();
do
{
t0= adc_read(0)/2; // Reading The Sensors
t1= adc_read(1)/2; // Reading The Sensors
t2= adc_read(2)/2; // Reading The Sensors
t3= adc_read(3)/2; // Reading The Sensors
sum=(t0+t1+t2+t3)/4;
delay_ms(50);
aab2(k2);
aab3(k3);
if ((Usart_Data_Ready())) // If data is received
{
i1= Usart_Read();
delay_ms(200);
PIR1.F5=0;
}
else
if((sum<=i1+3)&&(sum>(i1-3))) // If The Temp In The Range
{
PORTC.F1=0;//Fan
PORTC.F2=0;//Heater
}
if(sum {
PORTC.F1=0;
PORTC.F2=1;
}
if(sum>i1+3)
{
PORTC.F1=1;
PORTC.F2=0;
}
}
while(1);
}
unsigned short aab2 (unsigned short k2) //d {
ch2 = (sum/ 1000) %10;
ch2 = (sum/ 100) % 10;
LCD_Chr(1,12,48+ch2);
ch2 = (sum / 10) % 10;
LCD_Chr_CP(48+ch2);
ch2 = sum % 10;
LCD_Chr_CP(48+ch2);
LCD_Chr_CP('C');
delay_ms(10);
return(k2);
}
unsigned short aab3 (unsigned short k3) //
{
ch4 = ( i1/ 1000) %10;
ch4 = (i1 / 100) % 10;
LCD_Chr(2,12,48+ch4);
ch4 = (i1 / 10) % 10;
LCD_Chr_CP(48+ch4);
ch4 =i1 % 10;
LCD_Chr_CP(48+ch4);
LCD_Chr_CP('C');
delay_ms(10);
return(k3);
}