Descarga este documento en formato PDF - Ucontrol
Descarga este documento en formato PDF - Ucontrol
Descarga este documento en formato PDF - Ucontrol
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
8 de 22<br />
T<strong>en</strong>emos un total de 4 tareas <strong>en</strong> la aplicación y el control de la ejecución será el sigui<strong>en</strong>te:<br />
Al inicio solam<strong>en</strong>te la tarea LED_R estará habilitada, una vez que LED_R ha concluido inicia la tarea LED_V y<br />
se autodeshabilita.<br />
Cuando LED_V concluye habilita LED_A y se autodeshabilita.<br />
Cuando LED_V concluye habilita LEDS y se autodeshabilita.<br />
Cuando LEDS se inicia por primera vez habilita LED_R, LED_V y LED_A cuando le toca de nuevo el turno se<br />
autodeshabilita y deshabilita a LED_V y LED_A<br />
Veamos el código:<br />
Código:<br />
#include "D:\Docum<strong>en</strong>tos\Projects\RTOS\RTOS.h"<br />
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)<br />
//Como el reloj de <strong>este</strong> micro se ha puesto a correr con 20MHz el Timer0 no ti<strong>en</strong>e<br />
//mayor resolución que 10ms, es por eso que el tiempo mínimo de ejecución es de 10ms<br />
#use RTOS(timer=0, minor_cycle=10ms)<br />
int1 iB0, iB1, iB2;<br />
int1 iLEDS = 0;<br />
int8 iCountR = 0;<br />
int8 iCountV = 0;<br />
int8 iCountA = 0;<br />
int8 iCount = 0;<br />
#task (rate=10ms, max=10ms)<br />
void Task_Disabler();<br />
#task (rate=250ms, max=10ms)<br />
void LED_R();<br />
#task (rate=350ms, max=10ms)<br />
void LED_V();<br />
#task (rate=450ms, max=10ms)<br />
void LED_A();<br />
#task (rate=5s, max=10ms)<br />
void LEDS();<br />
void main()<br />
{<br />
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);<br />
rtos_run();<br />
}<br />
//esta es una función trucul<strong>en</strong>ta porque las tareas no pued<strong>en</strong> crearse deshabilitadas<br />
//y no se pued<strong>en</strong> deshabilitar hasta que el RTOS esté funcionando. Lo considero una<br />
//defici<strong>en</strong>cia sustancial de <strong>este</strong> RTOS<br />
void Task_Disabler()<br />
{<br />
rtos_disable(LED_V);<br />
rtos_disable(LED_A);<br />
rtos_disable(LEDS);<br />
rtos_disable(Task_Disabler);<br />
}<br />
//cada tarea ti<strong>en</strong>e un contador para llevar la cantidad de veces que se pasa por la<br />
//función y cuando se cumple el tiempo establecido <strong>en</strong>tonces habilita y deshabilita<br />
//las tareas correspondi<strong>en</strong>tes<br />
void LED_R()<br />
{<br />
iB0 = !iB0;<br />
output_bit( PIN_B0, iB0);<br />
if (iCountR++==20)<br />
{<br />
iCountR = 0;<br />
rtos_disable(LED_R);<br />
rtos_<strong>en</strong>able(LED_V);<br />
}<br />
}