viernes, 4 de marzo de 2016

RTOS (Programa sencillo)

Saludos les dejo un programa interesante y muy sencillo de comprender la lógica de RTOS/CCS Pic.
#include <18F452.h>
#FUSES XT
#FUSES NOWDT
#FUSES PROTECT
#use delay(clock=4M)
#use RTOS(timer=0,minor_cycle=1ms) 
#include <lcd.c>

// DEFINICIONES DE PIN A USAR PARA LOS SEMAFOROS

#define ON   PIN_A0
#define A2   PIN_B0
#define V2   PIN_B1
#define R3   PIN_B2
#define A3   PIN_B3
#define V3   PIN_B4
#define R4   PIN_B5
#define A4   PIN_B6
#define V4   PIN_B7
#define R1   PIN_C4
#define A1   PIN_C5
#define V1   PIN_C6
#define R2   PIN_C7

// TAREAS 

#task (rate=1ms,max=1ms)
void INICIO();

#task (rate=1ms,max=1ms,enabled=false)
void ROJO1();

#task (rate=10s,max=1ms,enabled=false)  
void AMARILLO1();

#task (rate=2s,max=1ms,enabled=false)  
void VERDE1();

#task (rate=6s,max=1ms,enabled=false)  
void AMARILLO12();



void main()

  setup_timer_0(RTCC_INTERNAL| RTCC_DIV_1);
  rtos_run();
}

void INICIO()
{
   if(input(ON))   
   rtos_enable(ROJO1);   
}

void ROJO1()
{
rtos_disable(INICIO);
output_low(A1);
output_high(R1);
rtos_disable(ROJO1);
rtos_enable(AMARILLO1); 
}

void AMARILLO1()
{
output_low(R1);
output_high(A1);
rtos_disable(AMARILLO1);   
rtos_enable(VERDE1);
}

void VERDE1()
{
output_low(A1);
output_high(V1);
rtos_disable(VERDE1);
rtos_enable(AMARILLO12);
}

void AMARILLO12()
{
output_low(V1);
output_high(A1);
rtos_disable(AMARILLO12);  
rtos_enable(ROJO1);
}


/*
SEGUNDO SEMAFORO
*/

No hay comentarios:

Publicar un comentario