#include "..\uc_os_II\includes.h"

OS_STK xdata Task1Stack[CPU_MAX_STK_SIZE];
OS_STK xdata Task2Stack[CPU_MAX_STK_SIZE];

void Task1(void xdata * ppdata) reentrant
{
	ppdata = ppdata;
	while(1)
	{
		OSTimeDlyHMSM(0, 0, 1, 0);
		printf("\n1");
	}
}

void Task2(void xdata * ppdata) reentrant
{
	ppdata = ppdata;
	while(1)
	{
		OSTimeDlyHMSM(0, 0, 2, 0);
		printf("\n2");
	}
}
void SerialInitial()
{
	/* set TI to 1, set TR1 to 1 */
	SCON = 0x52;/* SM0 SM1 =1 SM2 REN TB8 RB8 TI RI */
	TMOD = 0x20;/* GATE=0 C/T-=0 M1 M0=2 GATE C/T- M1 M0 */
	TH1 = 0xE6;	/* TH1=E6 4800bit/s when at 24MHz,TH1=F3,9600bit/s,24MHz */
	PCON = 0x80;
	TCON = 0x40;/* 01101001 TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT */
}
void InterruptInitial()
{
	/* set timer. 50ms, THTL = 3caf when cpu at 12MHz */
	TMOD |= 0x01;
	TH0 = 0x70;
	TL0 = 0x00;
	/* TR0 is set in OSStart() */
	ET0 = 1;
}
main()
{
	SerialInitial();
	InterruptInitial();
    OSInit();
    printf("\nstart");
    OSTaskCreate(Task1, (void xdata *)0, &Task1Stack[0],2);
	OSTaskCreate(Task2, (void xdata *)0, &Task2Stack[0],3);
    OSStart();
}
