单片机源程序如下:
#include "includes.h"
#define F_OSC 8000000 /* Crystal frequence 10Mhz*/
#define LED_ON() { DDRF = 0xff; PORTF = 0x0; }
#define LED_OFF() ( PORTF = 0xff )
/* ***********************************
* TimerInit()
* Fun: Initial the system timer for os, using timer 0
* ************************************ */
void TimerInit( void )
{
TCCR2 = 1<<3; /* work in CTC mode */
OCR2 = 98; /* 100 hz */
TCNT2 = 0;
TIMSK |= 1<<7; /* Enable CTC interrupt */
TCCR2 |= 3; /* start timer, F_OSC/1024 */
}
OS_EVENT * mbox;
OS_STK stk0[80], stk1[80];
void task0( void * pdata )
{
INT8U error;
while(1)
{
OSMboxPend( mbox, 0, &error );
LED_ON();
OSTimeDly(400);
OSMboxPost( mbox, (void *)1 );
}
}
void task1( void * pdata )
{
INT8U error;
TimerInit();
while(1)
{
OSMboxPend( mbox, 0, &error );
LED_OFF();
OSTimeDly(400);
OSMboxPost( mbox, (void *)1 );
}
}
int main()
{
INT8U error;
OSInit();
mbox = OSMboxCreate( (void *)1 );
OSTaskCreate( task0, (void *)0, &stk0[99], 2 );
OSTaskCreate( task1, (void *)0, &stk1[99], 3 );
OSStart();
return 0;
……………………
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』