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

📄 main.c

📁 博创2410的实验代码
💻 C
字号:
/***************************************************************************\
	Copyright (c) 2004-2007 threewater@up-tech.com, All rights reserved.
	by threewter	2004.5.12
\***************************************************************************/
/***************************************************************************\
    #说明: C  main 函数,ucos-ii初始化等定义
	----------------------------------  Bug  --------------------------------------

	----------------------------------  TODO list  --------------------------------------

	----------------------------------修正--------------------------------------
	2004-5-12	创建

\***************************************************************************/

#include"../ucos-ii/includes.h"               /* uC/OS interface */
#include "../ucos-ii/add/osaddition.h"
#include "../inc/drivers.h"

#include "../inc/sys/lib.h"
#include "../src/gui/gui.h"
#include <string.h>
#include <stdio.h>
#include <string.h>

#pragma import(__use_no_semihosting_swi)  // ensure no functions that use semihosting 
unsigned char savedstr1[60];
unsigned char savedstr[60][80];
unsigned short printstr[60][80];
int x,y,pos;
FILE* pfile;//定义文件结构指针
///******************任务定义***************///

OS_STK Main_Stack[STACKSIZE]={0, };   //Main_Test_Task堆栈
void Main_Task(void *Id);             //Main_Test_Task
#define Main_Task_Prio     12

OS_STK test_Stack[STACKSIZE]={0, };   //test_Test_Task堆栈
void test_Task(void *Id);             //test_Test_Task
#define test_Task_Prio     15


/**************已经定义的OS任务*************
#define SYS_Task_Prio				1
#define Touch_Screen_Task_Prio		9
#define Main_Task_Prio     12
#define Key_Scan_Task_Prio      58
#define Lcd_Fresh_prio           59
#define Led_Flash_Prio           60

***************************************/////////

char TextFilename[]="/sys/ucos/fj/test1.txt";

int writeline(char* str, int n, FILE *pfile)
{
	int i;
	for(i=0; i<n; i++){
		if(fwrite(str, 1, 1, pfile)!=1)
			return 0;
		    str++;
	}

	return i;
}


///*****************事件定义*****************///


/////////////////////////////////////////////////////
//                  Main function.                //
////////////////////////////////////////////////////
int main(void)
{

	ARMTargetInit();        // do target (uHAL based ARM system) initialisation //

	OSInit();               // needed by uC/OS-II //

	OSInitUart();

	initOSFile();
#if USE_MINIGUI==0
	initOSMessage();
	initOSList();
	initOSDC();
	initOSCtrl();
	LoadFont();
#endif

	loadsystemParam();
	
	// create the tasks in uC/OS and assign increasing //
	// priorities to them so that Task3 at the end of  //
	// the pipeline has the highest priority.          //
	LCD_printf("Create task on uCOS-II...\n");
	OSTaskCreate(Main_Task,  (void *)0,  (OS_STK *)&Main_Stack[STACKSIZE-1],  Main_Task_Prio);
//	OSTaskCreate(test_Task,  (void *)0,  (OS_STK *)&test_Stack[STACKSIZE-1],  test_Task_Prio);

	OSAddTask_Init(1);
  
	LCD_printf("Starting uCOS-II...\n");
	LCD_printf("Entering graph mode...\n");
	LCD_ChangeMode(DspGraMode);

	OSStart();              // start the OS //

	// never reached //
	return 0;
}//main

void onKey(unsigned int nkey, int fnkey)
{
	PDC pdc;//创建绘图设备上下文结构
	U16 ch[10],i,j;
	char *str, skey[10];
	
	if((nkey&KEY_DOWN)==0)
		return;

	ClearScreen();//清屏
	pdc=CreateDC();//创建绘图设备上下文f

	switch(nkey&0xff){
	case 'N':
		{str="NumLock";
		nkey='n';
		savedstr1[pos++]='n';
		break;
		}
	case '\r':
		{str="Enter";
		
		x++;
		y=0;
		savedstr1[pos++]='\n';
		break;
		}
	case '.':
	    {str="Del";
	     if(y==0&&x>0)
	     {x--;
	     i=0;
	     while(savedstr[x][i++]);
	     if(i>0)
	     y=i-1;
	     }
	     if(y>0)
	     y--;
	     savedstr[x][y]=0;
         if(pos>0);
         pos--;
	     savedstr1[pos]=0;
	    break;
	    
	    }	
	case '0': //0键
	       str="0";
	       savedstr1[pos]='\n';
	       //while(writeline(str, sizeof(str), pfile))//以行的方式写文件;    
	       pfile=fopen(TextFilename,"w");
	       if(pfile==NULL){
	       LCD_printf("Can't Open file!\n");
	  	   return;
	      }
	       fwrite(savedstr1,sizeof(savedstr1),1, pfile);//写文件
	       fclose(pfile);
      	   Uart_Printf(0,"\n write file success!\n");
	       break;
	default:
		{skey[0]=nkey;
		skey[1]=0;
		str=skey;
		/*i=0;
	    while(savedstr[x][i++]);
	    i--;*/
	    if(y==59)
	    {savedstr[x][y]=0;
	     x++;
	     y=0;
	    }
	    savedstr[x][y++]=nkey;
	    savedstr[x][y]=0;
	    savedstr1[pos++]=nkey;
	    break;
	    }
	}

	printf("key=%s\n",str);
	for(j=0;j<x+1;j++)
	{printf("savedstr[%d]=%s\n",j,savedstr[j]);
	strChar2Unicode(printstr[j], savedstr[j]);//将整形数据转化成Unicode
	TextOut(pdc, 0, j*16, printstr[j], TRUE, FONTSIZE_MIDDLE);//文本模式下显示文字
	}
	//strChar2Unicode(ch, str);//将整形数据转化成Unicode
	
	//TextOut(pdc, 150, 100, ch, TRUE, FONTSIZE_MIDDLE);//文本模式下显示文字
	DestoryDC(pdc);//删除绘图设备上下文	
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Main_Task(void *Id)             //Main_Test_Task
{
	POSMSG pMsg=0;//创建消息结构
	//U16 str1[10],str2[10],str3[10],str4[10];

	ClearScreen();//清屏
	memset(savedstr1,0,100);//数组清0	Added by lgd
	memset(savedstr,0,80*60);//数组清0	Added by lgd
	memset(printstr,0,80*60);//数组清0	Added by lgd
	x=0;
	y=0;               //数组位置计数器	Added by lgd  
	pos=0;
	/*pfile=fopen(TextFilename,"w");//打开文件
	if(pfile==NULL){//文件打开失败
		LCD_printf("Can't Open file!\n");
		for(;;)
			OSTimeDly(1000);
	}*/


	//消息循环
	for(;;){
		pMsg=WaitMessage(0); //等待消息
		switch(pMsg->Message){
		case OSM_KEY://键盘消息
			onKey(pMsg->WParam,pMsg->LParam);
			break;
		}
		DeleteMessage(pMsg);//删除消息,释放资源
	}
}

⌨️ 快捷键说明

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