#include <16F877A.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES PUT //Power Up Timer
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NOPROTECT //Code not protected from reading
#use delay(crystal=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_c6,rcv=PIN_c7,bits=8)
char buffer_rx[2];
unsigned int8 banderas;
#bit buffer_rx_listo=banderas.0
#INT_RDA
void RDA_isr(void)
{
static unsigned int8 n_bytes;
buffer_rx[n_bytes++]=getc();
if(n_bytes==2)
{
n_bytes=0;
buffer_rx_listo=1;
}
}
void main()
{
output_b(0);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(TRUE)
{
while(!buffer_rx_listo);
buffer_rx_listo=0;
switch(buffer_rx)
{
case "A":
{
if (input(pin_b0))
{
output_high(pin_b1);
printf("Control automatico\r\nLuminaria encendida");
}
else
{
output_low(pin_b1);
printf("Control automatico\r\nLuminaria apagada ");
}
break;
}
case "B":
{
output_high(pin_b1);
printf("Control horario\r\nLuminaria encendida");
break;
}
case "C":
{
output_low(pin_b1);
printf("Control horario\r\nLuminaria apagada");
}
}
}
}