Saturday, 21 November 2015

Home Automation System using PIC

USART---Inputs     L>>Lights
                              F>>Fan
Speed and Brightness control using PWM (according to the options entered through USART)

#include<pic.h>
void main()
{
char e,a;
TRISC=0X80;
TRISB=0X00;
PORTB=0X03;
TMR2ON=1;

TXSTA=0X24;
RCSTA=0X90;
SPBRG=0X19;
while(1)
{
while(RCIF==0);
a=RCREG;
RCIF=0;
if(a=='F')
{CCP1CON=0X0C;
CCP2CON=0X00;
while(RCIF==0);
e=RCREG;
RCIF=0;
switch(e)
{case '1':
{CCPR1L=0;
break;
}
case '2':
{CCPR1L=50;
break;
}
case '3':
{CCPR1L=150;
break;
}
case '4':
{CCPR1L=255;
break;
}
}
}
if(a=='L')
{CCP1CON=0X00;
CCP2CON=0X0C;
while(RCIF==0);
e=RCREG;
RCIF=0;
switch(e)
{case '1':
{CCPR2L=0;
break;
}
case '2':
{CCPR2L=50;
break;
}
case '3':
{CCPR2L=150;
break;
}
case '4':
{CCPR2L=255;
break;
}
}
}
}
}

No comments:

Post a Comment