本人做课设,遇到很简单的一个问题。。。。。。。但是解决不了。。。。
我的源码如下
/************************************************************************************************
// 本实验要求实现部分
//1、MainTask中按键消息获取,处理
//2、按键处理函数OnKey()函数
//3、创建串口处理任务Serial_Receive_Task(void *Id)
//4、实现串口消息换取,处理(在LCD或数码管上显示)函数OnReceive(char nRdata)
//
************************************************************************************************/
#include"..\ucos-ii\includes.h" /* uC/OS interface */
#include "..\ucos-ii\add\osaddition.h"
#include "..\inc\drv.h"
#include
extern int Zlg7289SIOBand;
extern int Zlg7289SIOCtrl;
#pragma import(__use_no_semihosting_swi) // ensure no functions that use semihosting
///******************任务定义***************///
OS_STK Main_Stack[STACKSIZE*8]={0, }; //Main_Test_Task堆栈
void Main_Task(void *Id); //Main_Test_Task
#define Main_Task_Prio 13
OS_STK Serial_Receive_Stack[STACKSIZE*8]={0, }; //Serial_Receive_Task堆栈
void Serial_Receive_Task(void *Id) ; //Serial_Receive_Task
#define Serial_Receive_Task_Prio 12
//串口接收Task
void search(void);
void count();
void buyticket();
void choose(int);
/**************已经定义的OS任务*************
tcp监控任务 11
以太网物理层监控任务 8
触摸屏任务 9
键盘任务 10
lcd刷新任务 59
系统任务 1
*****************************************************/
///*****************事件定义*****************///
OS_EVENT *Nand_Rw_Sem; //Nand_Flash读写控制权旗语
//and you can use it as folloeing:
// Nand_Rw_Sem=OSSemCreate(1); //创建Nand-Flash读写控制权旗语,初值为1满足互斥条件//
// OSSemPend(Nand_Rw_Sem,0,&err);
// OSSemPost(Nand_Rw_Sem);
OS_EVENT *Uart_Rw_Sem; //Uart读写控制权旗语
//and you can use it as folloeing:
// Uart_Rw_Sem=OSSemCreate(1); //创建Uart读写控制权旗语,初值为1满足互斥条件//
// OSSemPend(Uart_Rw_Sem,0,&err);
// OSSemPost(Uart_Rw_Sem);
//////////////////////////////////////////////////////////
void initOSGUI() //初始化操作系统的图形界面
{
initOSMessage();
initOSList();
initOSDC();
initOSCtrl();
initOSFile();
}
/////////////////////////////////////////////////////
// Main function. //
////////////////////////////////////////////////////
INT8U err;
char didian [6][12]={"","nan chang"," bei jing ","shang hai"," guang zhou"," ji nan "};
int jiage[6][6]={0,0,0,0,0,0,
0,0,200,300,400,500,
0,200,0,600,700,800,
0,300,600,0,50,450,
0,400,700,50,0,500,
0,500,800,450,500,0};
int sumpiao[6][6]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int mykey=-1;
void jiemian(){
int i=0;
for( i=1;i<6;i++){
Uart_Printf("---%s",didian);
}
Uart_Printf("\n");
Uart_Printf("xuan ze cao zuo\n");
Uart_Printf("1 mai piao\n");
Uart_Printf("2 cha chun che ci\n");
Uart_Printf("3 tong ji jin tian liu liang \n");
Uart_Printf("0 tui chu \n");
Delay(2000);
}
void choose(int mykey){
switch(mykey){
case 1:Uart_Printf(" mai piao\n");
buyticket();
break;
case 2:Uart_Printf ("cha xun che ci\n");
search();
break;
case 3: Uart_Printf("tong ji jin tian liu liang \n");
count();
break;
}
}
void search(void){
int begin=0,end=0;
Uart_Printf("chu fa di \n");
Delay(300);
begin=mykey;
Uart_Printf("%d---%s\n",begin,didian[begin]);
Uart_Printf("mu di di \n");
end=mykey;
Uart_Printf("%d---%s\n",end,didian[end]);
if(begin==end){
Uart_Printf("chu fa di he mu di di xiang tong cuo wu \n");
Uart_Printf("chu fa di \n");
begin=mykey;
Uart_Printf("mu di di \n");
end=mykey;
}
if(jiage[begin][end]!=0){
Uart_Printf("you che ci, che piao jia qian %d\n",jiage[begin][end]);
}
}
void count(void){
int i=0,j=0;
int x=0;
for(i=1;i<6;i++){
x=0;
for( j=1;j<6;j++){
x=sumpiao[j]+x;
}
Uart_Printf("jin tian dao %s de you %d ren\n",didian,x);
}
}
void buyticket(){
int begin=0,end=0,num=0;
Uart_Printf("chu fa di \n");
begin=mykey;
Uart_Printf("mu di di \n");
end=mykey;
if(begin==end){
Uart_Printf("chu fa di he mu di di xiang tong cuo wu \n");
Uart_Printf("chu fa di \n");
begin=mykey;
Uart_Printf("mu di di \n");
end=mykey;
}
Uart_Printf("mai de piao shu \n");
num=mykey;
if(jiage[begin][end]!=0){
Uart_Printf("jia qian %d\n",jiage[begin][end]);
sumpiao[begin][end]=sumpiao[begin][end]+num;
Uart_Printf("chu fa di %s mu di di %s piaoshu %d money %d\n",didian[begin],didian[end],num,num*jiage[begin][end]);
}
}
int main(void)
{
ARMTargetInit(); //开发板初始化
OSInit(); //操作系统初始化
uHALr_ResetMMU();//复位MMU
LCD_Init(); //初始化LCD模块
LCD_printf("LCD initialization is OK\n");//向液晶屏输出数据
LCD_printf("320 x 240 Text Mode\n");
initOSGUI();//初始化图形界面
LoadFont();//调Unicode字库
LoadConfigSys();//使用config.sys文件配置系统设置
LCD_printf("Create task on uCOS-II...\n");
OSTaskCreate(Main_Task, (void *)0, (OS_STK *)&Main_Stack[STACKSIZE*8-1], Main_Task_Prio);// 创建系统任务
////////////////////////////////////////////////////
OSTaskCreate( Serial_Receive_Task, (void *)0, (OS_STK *)&Serial_Receive_Stack[STACKSIZE*8-1], Serial_Receive_Task_Prio );// 创建串口任务
////////////////////////////////////////////////////
OSAddTask_Init();//创建系统附加任务
LCD_printf("Starting uCOS-II...\n");
LCD_printf("Entering graph mode...\n");
LCD_ChangeMode(DspGraMode);//变LCD显示模式为文本模式
InitRtc();//初始化系统时钟
Nand_Rw_Sem=OSSemCreate(1); //创建Nand-Flash读写控制权旗语,初值为1满足互斥条件//
OSStart();//操作系统任务调度开始
//不会执行到这里
return 0;
}
char *KeyTable[]={"NumLock","/","*","-","7","8","9","+","4","5","6","1","2","3","Enter","0","."};
void onKey(int nkey, int fnkey)
{
/* PDC pdc;//创建绘图设备上下文结构
U16 ch[10];
ClearScreen();//清屏
pdc=CreateDC();//创建绘图设备上下文
Uart_Printf("key=%d\n",nkey);
Int2Unicode(nkey,ch);//将数据转化成Unicode 转化函数参考\\INC\\DRV\\ustring.h
TextOut(pdc,20,20,ch,TRUE,FONTSIZE_MIDDLE);//文本模式下显示文字
DestoryDC(pdc);//删除绘图设备上下文 */
}
void OnReceive(int nRdata)
{
Uart_Printf("key=%d\n",nRdata);
ZLG7289_ENABLE();//使zlg7289占有同步串口
Delay(5);//延时
WriteSDIO(ZLG7289_CMD_DATA1|7);//数码管以方式0译码,第一个数码管亮
WriteSDIO(nRdata%10);//显示个位
Delay(10);//延时
if(nRdata>9)
{//键值大于9显示十位
WriteSDIO(ZLG7289_CMD_DATA1|6);//发送十位数据
WriteSDIO((nRdata/10)%10);
Delay(10);
}
if(nRdata>=100)
{//键值小于10不显示十位
WriteSDIO(ZLG7289_CMD_DATA1|5);//使bai位数码管显示
WriteSDIO( nRdata/100);
Delay(10);
}
WriteSDIO(ZLG7289_CMD_HIDE);//使bai位数码管显示
WriteSDIO(0xff);
ZLG7289_DISABLE();//zlg7289放弃同步串口控制权
mykey=nRdata;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Main_Task(void *Id) //Main_Test_Task
{
POSMSG pMsg=0;//创建消息结构
ClearScreen();//清屏
jiemian();
//消息循环
for(;;){
pMsg=WaitMessage(0); //等待消息
switch(pMsg->Message){
case OSM_KEY://键盘消息
onKey((int)pMsg->WParam,(int)pMsg->LParam);
break;
case OSM_SERIAL:
OnReceive((int)(pMsg->WParam-48)) ; //串口消息 消息定义参考\\UCOS-II\\ADD\\OSMessage.h
break;
}
DeleteMessage(pMsg);//删除消息,释放资源
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Serial_Receive_Task(void *Id) //串口接收Task
{
POSMSG pMsg=0;//创建消息结构
char c1[1];
U32 key;
char result=FALSE;
for(;;){
result=Uart_Getch(c1,0,500);
if(result==TRUE){
key=c1[0];
pMsg=OSCreateMessage(NULL,OSM_SERIAL, key,0);
if(pMsg)
SendMessage(pMsg);
}
}
}
但是我的输入没法得到。。。。。。求高手解决(得不到输入值)