⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex2l.c

📁 uC/os原码 ,大家可以自由下载研究,共同进步, 共同研究,有心得共享呀
💻 C
📖 第 1 页 / 共 2 页
字号:
		ScrCache[i][MAX_X] = '\0';
	}

	memset(s, 0xCD, MAX_X + 2);
	s[0] = 0xC9; s[MAX_X + 1] = 0xBB; s[MAX_X + 2] = '\0';
	PC_DispStr(START_X, START_Y - 1, s, DISP_FGND_WHITE + DISP_BGND_BLUE);

	for (i = 0; i < LEN_Y; i++) {
		memset(s, 0x20, MAX_X + 2);
		s[0] = 0xBA; s[MAX_X + 1] = 0xB0; s[MAX_X + 2] = '\0';
		PC_DispStr(START_X, i + START_Y, s, DISP_FGND_WHITE + DISP_BGND_BLUE);
	}

	memset(s, 0xCD, MAX_X + 2);
	s[0] = 0xC8; s[MAX_X + 1] = 0xBC; s[MAX_X + 2] = '\0';
	PC_DispStr(START_X, START_Y + LEN_Y, s, DISP_FGND_WHITE + DISP_BGND_BLUE);

	PC_DispChar(START_X + MAX_X + 1, START_Y, 0x1E,
				DISP_FGND_WHITE + DISP_BGND_BLUE);

	PC_DispChar(START_X + MAX_X + 1, START_Y + LEN_Y - 1, 0x1F,
				DISP_FGND_WHITE + DISP_BGND_BLUE);

	PC_DispChar(START_X + MAX_X + 1, START_Y + 1, 0x12,
				DISP_FGND_BLACK + DISP_BGND_BLUE);

	PC_DispStr(31, START_Y - 1, "[ Window  Test ]",
			   DISP_FGND_WHITE + DISP_BGND_BLUE);

	PosY = 0;
	DispSign();
	DisplaySign(1, PosY);

}
/*$PAGE*/
/*
*********************************************************************************************************
*                                            	Move()
*********************************************************************************************************
*/

void   Move(UBYTE x)
{
	PC_DispChar(START_X + MAX_X + 1, ((LEN_Y - 2) * NowY -1)/
				(MAX_Y - LEN_Y) + START_Y + 1, 0xB0,
				DISP_FGND_WHITE + DISP_BGND_BLUE);

	switch(x)
	{
		case 0x00:
			if (NowY != 0) NowY--;
			break;
		case 0x01:
			if (NowY != MAX_Y - LEN_Y) NowY++;
			break;
	}
	PC_DispChar(START_X + MAX_X + 1, ((LEN_Y - 2) * NowY -1)/
				(MAX_Y - LEN_Y) + START_Y + 1, 0x12,
				DISP_FGND_BLACK + DISP_BGND_BLUE);

	Display();
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                            DisplaySign()
*********************************************************************************************************
*/

void DisplaySign(UBYTE i, UBYTE j)
{
	if (j >= NowY && j < NowY + LEN_Y)
		PC_DispChar(START_X + i + 1, START_Y + j - NowY, '_',
					DISP_FGND_WHITE + DISP_BGND_BLUE + DISP_BLINK);
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                            CacheOver()
*********************************************************************************************************
*/

void CacheOver(void)
{
	UBYTE i,j;
	for(i = 0; i < MAX_Y; i++)
		for(j = 0; j < MAX_X - 1; j++)
			ScrCache[i][j] = ScrCache[i + 1][j];

	memset(ScrCache[MAX_Y - 1], 0x20, MAX_X);
	ScrCache[MAX_Y - 1][MAX_X] = '\0';
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                             DispLine()
*********************************************************************************************************
*/

void DispLine(char *s)
{
	DispStr(0, PosY, s);

	if (PosY < NowY + LEN_Y - 1) {
		if (PosY < MAX_Y - 1) PosY++;
		else CacheOver();
	}
	else {
		if (PosY < MAX_Y - 1) PosY++;
		else CacheOver();
		Move(0x01);
	}
	DispSign();
	DisplaySign(1, PosY);
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                              DispStr()
*********************************************************************************************************
*/

void DispStr(UBYTE i, UBYTE j, char *s)
{
	UBYTE x;

	x = 0;
	while(s[x] != '\0' && (x + i) < (MAX_X - 1)) {
		ScrCache[j][i + x] = s[x];
		x++;
	}
	PC_DispStr(START_X + 1, j - NowY + START_Y, ScrCache[j],
			   DISP_FGND_WHITE + DISP_BGND_BLUE);
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                              DispSign()
*********************************************************************************************************
*/

void DispSign(void)
{
	DispChar(0, PosY, '-');
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                              Command()
*********************************************************************************************************
*/

void Command(char *sCmd)
{
	if (strstr(sCmd, "ver") == sCmd) CmdWork(0x01, &sCmd[3]);
	else if (strstr(sCmd, "help") == sCmd) CmdWork(0x02, &sCmd[4]);
	else if	(strstr(sCmd, "exit") == sCmd) CmdWork(0x03, &sCmd[4]);
	else if (strstr(sCmd, "change") == sCmd) CmdWork(0x04, &sCmd[6]);
	else if (strstr(sCmd, "start") == sCmd) CmdWork(0x05, &sCmd[5]);
	else if (strstr(sCmd, "stop") == sCmd) CmdWork(0x06, &sCmd[4]);
	else DispLine("Bad command!");
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                              CmdWork()
*********************************************************************************************************
*/

void CmdWork(UBYTE index, char *sPara)
{
	struct MsgType  PMsg;
	struct MsgType *RMsg;
	INT8U 		    err;

	if (sPara[0] != '\0' && sPara[0] != 0x20) DispLine("Bad command!");
	else {
		switch(index) {
			case 0x01:
				if (sPara[0] == '\0') colprint("uC/OS-II SHELL TEST V%3.2f",1.00);
				else DispLine("No parameter!");
				break;
			case 0x02:
				if (sPara[0] == '\0') {
					colprint("SHELL HELP:");
					colprint("Format: ver");
					colprint("This Command will show the version of the system.");
					colprint("Format: help");
					colprint("This Command will show the help.");
					colprint("Format: exit");
					colprint("This Command will close the system and return to DOS.");
					colprint("Format: change <TaskID> <Direction> <Speed>");
					colprint("This Command will change the state of the task.");
					colprint("Format: start <TaskID>");
					colprint("This Command will let the task work.");
					colprint("Format: stop <TaskID>");
					colprint("This Command will stop the task.");
				}
				else colprint("No parameter!");
				break;
			case 0x03:
				if (sPara[0] == '\0') PC_DOSReturn();
				else colprint("No parameter!");
				break;
			case 0x04:
				if (sPara[0] == '\0') colprint("Format: change <TaskID> <Direction> <Speed>");
				else {
					if (sPara[1] != '1' && sPara[1] != '2')
						PMsg.TaskID = 0x00;
					else {
						if (sPara[1] == '1') PMsg.TaskID = 0x01;
						if (sPara[1] == '2') PMsg.TaskID = 0x02;
						if (sPara[2] != 0x20) PMsg.Info = 0x00;
						else {
							if (sPara[3] != '0' && sPara[3] != '1')
								PMsg.Info = 0x00;
							else {
								if (sPara[3] == '0') PMsg.Info = 0x00;
								if (sPara[3] == '1') PMsg.Info = 0x80;
								if (sPara[4] != 0x20) PMsg.Info = 0x00;
								else {
									UBYTE i = 5,t = 0;
									while(sPara[i] >= '0' && sPara[i] <= '9') {
										t = t * 10 + sPara[i] - 0x30;
										i++;
									}
									if (sPara[i] == '\0' && t > 0 && t < 128) {
										PMsg.Info += t;
									}
									else PMsg.Info = 0x00;
								}
							}
						}
					}
					if (PMsg.TaskID != 0x00 && PMsg.Info != 0x00) {
						OSQPost(MsgQueue,(void *)&PMsg);
						RMsg = (struct MsgType *)OSQPend(MsgQueue, 0, &err);
						while(RMsg == NULL || RMsg->TaskID != 0x00) {
							if (RMsg->TaskID != 0x00 )
								OSQPostFront(MsgQueue,(void *)RMsg);
							OSTimeDly(10);
							RMsg = (struct MsgType *)OSQPend(MsgQueue, 0, &err);
						}
						if (err == OS_NO_ERR)
							colprint("Task%d State Change Finished!",RMsg->Info);
					}
					else colprint("Wrong parameter!");
				}
				break;
			case 0x05:
				if (sPara[0] == '\0') colprint("Format: start <TaskID>");
				else {
					if (sPara[1] == '1' && sPara[2] == '\0')
						OSTaskResume(TASK_1_PRIO);
					else if (sPara[1] == '2' && sPara[2] == '\0')
						OSTaskResume(TASK_2_PRIO);
					else colprint("Wrong parameter!");
				}
				break;
			case 0x06:
				if (sPara[0] == '\0') colprint("Format: stop <TaskID>");
				else {
					if (sPara[1] == '1' && sPara[2] == '\0')
						OSTaskSuspend(TASK_1_PRIO);
					else if (sPara[1] == '2' && sPara[2] == '\0')
						OSTaskSuspend(TASK_2_PRIO);
					else colprint("Wrong parameter!");
				}
				break;
		}
	}
}

void	colputchar(char ch)
{
	static UBYTE PosX = 0;

	if (ch == '\n' || ch == '\0') {
		if (PosY < NowY + LEN_Y - 1) {
			if (PosY < MAX_Y - 1) PosY++;
			else CacheOver();
		}
		else {
			if (PosY < MAX_Y - 1) PosY++;
			else CacheOver();
			Move(0x01);
		}
		if (ch == '\0') {
			DispSign();
			DisplaySign(1, PosY);
		}
		PosX = 0;
	}
	else {
		DispChar(PosX, PosY, ch);
		PosX++;
	}
}

void	colprintn(int n, const char* fmt )
{
	char buf[50], c;
	int i = 0;
	sprintf( buf, fmt, n);
	while(i<50)
	{
		c=buf[i];
		if (c=='\0') return;
		colputchar(c);
		i++;
	}

}
void	colprintf(float n, const char* fmt)
{
	char buf[50], c;
	int i = 0;
	sprintf( buf, fmt, n);
	while(i<50)
	{
		c=buf[i];
		if (c=='\0') return;
		colputchar(c);
		i++;
	}
}

void	colprint(const char* fmt,...)
{
	register char *s, *n, *p, par[8];
	register *adx, c, cn;

	adx = &fmt+1;			//point to first param
loop:
	while((c = *fmt++) != '%' )
	{
		colputchar(c);
		if(c=='\0') return;
	}
	c = *fmt++;
	if( c=='d')
	{
		colprintn(*(int*)adx, "%d" );
		adx+=1;
	}
	else if( c=='f')
	{
		colprintf(*(double*)adx, "%f" );
		adx+=4;
	}
	else if( c=='s')
	{
		s=*(char**)adx;
		while(c=*s++)
		{
			if( c=='\0') break;
			colputchar(c);
		}
		adx+=2;
	}
	else if( c>=48 && c<58 || c=='.' )	//格式输出 %3.2f %3f %.3f %3.f
	{
		n = fmt-2;
		memcpy( par, n, 8 );

		if ( (p=strstr(par,"d")) != NULL )
		{
			*(p+1) = '\0';
			colprintn( *(int*)adx, par );
			fmt +=p-par-1;
			adx+=1;
		}
		
		if ( (p=strstr(par,"f")) != NULL )
		{
			*(p+1) = '\0';
			colprintf( *(double*)adx, par );
			fmt +=p-par-1;
			adx+=4;
		}
	}
	else
	{
		colputchar('%');
		fmt--;
	}

	goto loop;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -