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

📄 maintask.c

📁 ucOS 模拟环境
💻 C
字号:
/*
*********************************************************************************************************
*                                                礐/GUI
*                        Universal graphic software for embedded applications
*
*                       (c) Copyright 2002, Micrium Inc., Weston, FL
*                       (c) Copyright 2000, SEGGER Microcontroller Systeme GmbH          
*
*              礐/GUI is protected by international copyright laws. Knowledge of the
*              source code may not be used to write a similar product. This file may
*              only be used in accordance with a license and should not be redistributed 
*              in any way. We appreciate your understanding and fairness.
*
* File        : MainTask.c
* Purpose     : Application program in windows simulator
*********************************************************************************************************
*/


#include "GUI.h"
#include "GUIDEMO.h"
#include "includes.h"
#include "EDIT.h"
#include "PinYinDemo.h"
extern const GUI_BITMAP bmMicriumLogo;
extern const GUI_BITMAP bmMicriumLogo_1bpp;
#define  TASK_STK_SIZE                 2048       /* Size of each task's stacks (# of WORDs)            */
#define  N_TASKS                        10       /* Number of identical tasks                          */
#define TaskStart_Prio	1
#define Task1_Prio		2
#define Task2_prio		3
/*
*********************************************************************************************************
*                                               VARIABLES
*********************************************************************************************************
*/
OS_STK  TaskStk[N_TASKS][TASK_STK_SIZE];    // Tasks stacks
/*
*********************************************************************************************************
*                                           FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void TaskStart(void * pParam) ;
void Task1(void * pParam);
void VCInit(void);						//初始化相关变量,一定需要
void VCInit(void)
{
	HANDLE cp,ct;
	Context.ContextFlags = CONTEXT_CONTROL;
	cp = GetCurrentProcess();	//得到当前进程句柄
	ct = GetCurrentThread();	//得到当前线程伪句柄
	DuplicateHandle(cp, ct, cp, &mainhandle, 0, TRUE, 2);	//伪句柄转换,得到线程真句柄
		
}
void TaskStart(void * pParam) 
{	
	char err;	
	OS_EVENT *sem1;

	timeSetEvent(1000/OS_TICKS_PER_SEC, 0, OSTickISR, 0, TIME_PERIODIC);	//开启一个定时器线程,感觉10 ticks/s比较好
	sem1 = OSSemCreate(0);
	while(1)
	{		
		OSSemPend(sem1, 0, &err);   //sleep ,wait for sem1,run shell
	}
}
/*
  *******************************************************************
  *
  *              main()
  *
  *******************************************************************
*/
void MainTask(void) {
 
  //modify source code here 080402 dengtieshan, add ucOS kernel
  VCInit();	//initialization variables
  OSInit();
  OSTaskCreate(TaskStart, 0, &TaskStk[0][TASK_STK_SIZE-1], TaskStart_Prio);
  OSTaskCreate(Task1, 0, &TaskStk[1][TASK_STK_SIZE-1], Task1_Prio);
  OSStart();	


}
static void _DemoEdit(void)
{
  EDIT_Handle hEdit;
  char aBuffer[28];
  int Key;
  GUI_SetBkColor(GUI_BLACK);
  GUI_Clear();
  GUI_SetColor(GUI_WHITE);
  GUI_SetFont(&GUI_Font24_ASCII);
  GUI_DispStringHCenterAt("WIDGET_Edit - Sample", 160, 5);
  GUI_SetFont(&GUI_Font8x16);
  GUI_DispStringHCenterAt("Use keyboard to modify string...", 160, 90);
  /* Create edit widget */
  hEdit = EDIT_Create( 50, 110, 220, 25, ' ', sizeof(aBuffer), 0 );
  /* Modify edit widget */
  EDIT_SetText(hEdit, "Press <ENTER> when done...");
  EDIT_SetFont(hEdit, &GUI_Font8x16);
  EDIT_SetTextColor(hEdit, 0, GUI_RED);
  /* Set keyboard focus to edit widget */
  WM_SetFocus(hEdit);
  /* Handle keyboard until ESC or ENTER is pressed */
  do {
    WM_Exec();
    Key = GUI_GetKey();
  } while ((Key != GUI_KEY_ENTER) && (Key != GUI_KEY_ESCAPE));
  /* Fetch result from edit widget */
  if (Key == GUI_KEY_ENTER) {
    EDIT_GetText(hEdit, aBuffer, sizeof(aBuffer));
  }
  /* Delete the edit widget */
  EDIT_Delete(hEdit);
  GUI_ClearRect(0, 50, 319, 239);
  /* Display the changed string */
  if (Key == GUI_KEY_ENTER) {
    GUI_Delay(250);
    GUI_DispStringHCenterAt("The string you have modified is:", 160, 90);
    GUI_DispStringHCenterAt(aBuffer, 160, 110);
    GUI_Delay(3000);
    GUI_ClearRect(0, 50, 319, 239);
  }
  GUI_Delay(500);
}

#define	PIN_YIN_TEST	1
#define	DEMO_TEST		1
#define	JPEG_TEST		1
#define	GIF_TEST			1

void Task1(void * pParam)
{
	int Cnt =0;
	int i,YPos;
	int LCDXSize = LCD_GET_XSIZE();
	int LCDYSize = LCD_GET_YSIZE();
	const GUI_BITMAP *pBitmap;
	GUI_Init();
	// the frist Demo program
	GUI_SetBkColor(GUI_RED); GUI_Clear();
	OSTimeDly(10);
	GUI_SetBkColor(GUI_BLUE); GUI_Clear();
	//GUI_Delay(1000);
	OSTimeDly(10);
	GUI_SetColor(GUI_WHITE);
	for (i=0; i<1000; i+=10) {
	 GUI_DrawHLine(i,0,100);
	 GUI_DispStringAt("Line ",0,i);
	 GUI_DispDecMin(i);
	}
	OSTimeDly(100);
	GUI_SetColor(0x0);
	GUI_SetBkColor(0xffffff);
	for (i=0; i<160; i++) {
	 int len = (i<80) ? i : 160-i;
	 GUI_DrawHLine(i,20,len+20);
	}
	OSTimeDly(100);
	GUI_Clear();
	if (LCD_GET_YSIZE()>(100+bmMicriumLogo_1bpp.YSize)) {
	 pBitmap=&bmMicriumLogo;
	} else {
	 GUI_SetColor(GUI_BLUE);
	 pBitmap=&bmMicriumLogo_1bpp;
	}
	GUI_DrawBitmap(pBitmap,(LCDXSize-pBitmap->XSize)/2,10);
	YPos=20+pBitmap->YSize;
	GUI_SetFont(&GUI_FontComic24B_1);
	GUI_DispStringHCenterAt("www.micrium.com",LCDXSize/2,YPos);
	OSTimeDly(100);
	GUI_SetColor(GUI_RED);
	GUI_DispStringHCenterAt("

⌨️ 快捷键说明

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