#include <18f452.h>
#fuses HS,NOWDT
#use delay(clock=20000000)
#use rs232(baud=19200,xmit=PIN_c6,rcv=PIN_c7,bits=8,parity=N)
#use RTOS(timer=0, minor_cycle=10ms)
#include <lcd.c>
#task (rate=10ms,max=1ms)
void puerto_serie();
#task (rate=100ms,max=1ms)
void leer_pulsadores();
/******************************************************************************
Tareas a ejectar
******************************************************************************/
#task (rate=100ms,max=1ms,enabled=false) //la terea no inicia automatocamente
void tarea1();
#task (rate=250ms,max=1ms,enabled=false) //la terea no inicia automatocamente
void tarea2();
#task (rate=350ms,max=1ms,enabled=false) //la terea no inicia automatocamente
void tarea3();
/*****************************************************************************/
void main()
{
lcd_init();
lcd_putc("T: | 1 | 2 | 3 |\n");
lcd_putc(" |off|off|off|");
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
rtos_run();
}
/******************************************************************************
Lee el estado del puerto serie
******************************************************************************/
void puerto_serie()
{
char dato_rx;
rtos_await(kbhit());
dato_rx=getc();
switch(dato_rx)
{
case 'r':
{
rtos_disable(tarea1);
output_low(pin_b0);
lcd_gotoxy(5,2);
lcd_putc("off");
putc(dato_rx);
break;
}
case 'v':
{
rtos_disable(tarea2);
output_low(pin_b1);
lcd_gotoxy(9,2);
lcd_putc("off");
putc(dato_rx);
break;
}
case 'a':
{
rtos_disable(tarea3);
output_low(pin_b2);
lcd_gotoxy(13,2);
lcd_putc("off");
putc(dato_rx);
break;
}
case 'c':
{
rtos_disable(tarea1);
rtos_disable(tarea2);
rtos_disable(tarea3);
output_low(pin_b0);
output_low(pin_b1);
output_low(pin_b2);
lcd_gotoxy(1,2);
lcd_putc(" |off|off|off|");
putc(dato_rx);
break;
}
}
}
/******************************************************************************
Lee los pulsadores y segun el caso habilita las tareas
******************************************************************************/
void leer_pulsadores()
{
if(input(pin_b4))
{
rtos_enable(tarea1);
lcd_gotoxy(5,2);
lcd_putc("on ");
}
if(input(pin_b5))
{
rtos_enable(tarea2);
lcd_gotoxy(9,2);
lcd_putc("on ");
}
if(input(pin_b6))
{
rtos_enable(tarea3);
lcd_gotoxy(13,2);
lcd_putc("on ");
}
}
void tarea1()
{
output_toggle(PIN_b0);
}
void tarea2()
{
output_toggle(PIN_b1);
}
void tarea3()
{
output_toggle(PIN_b2);
}