金牌会员
 
- 积分
- 1276
- 金钱
- 1276
- 注册时间
- 2016-5-31
- 在线时间
- 499 小时
|
发表于 2016-9-6 14:05:41
|
显示全部楼层
楼主请看如下的程序片段:
说明: 1、上电之前Esc+Space按键同时按下,执行:虚拟U盘功能---->设置键盘功能。
2、如果上述按键没有按下,执行正常的键盘功能.
稍微修改一下,完全可以实现你的 “通过按键切换不同程序的执行”!
#define FirmwareUpgradeAddress ((uint32_t)0x08018400) //固件升级程序地址
#define ApplicationAddress ((uint32_t)0x08010000)
#define KEY_MAPS_FILE_ADDR ((uint32_t)0x08018000) //0x08013000+0x5000
typedef void (*pFunction)(void);
pFunction Jump_To_Application;
void Run_Process_Exchanged(void)
{
/* Jump to code loaded in NOR memory and execute it ******/
JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
Jump_To_Application = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) ApplicationAddress);
Jump_To_Application();
}
void FirmwareUpgrade_Process_Exchanged(void)
{
/* Jump to code loaded in NOR memory and execute it *********/
JumpAddress = *(__IO uint32_t*) (FirmwareUpgradeAddress + 4);
Jump_To_Application = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) FirmwareUpgradeAddress);
Jump_To_Application();
}
/****************************************************************************
* 功 能: 主函数
*-----------------------------------------------------------------------------------------------------------*
* 入口参数:
* 出口参数:
****************************************************************************/
int main(void)
{
Set_System();
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x18400); //必须设置中断向量表
USART_Config();
TM1629_GPIO_Configuration();
TM1629_Display_Init();
memset(keymaps_udisk,0,1024);
memset(custom_buf,0,16*8); //清除数据
Keymaps_ReadFlash_Data(KEY_MAPS_FILE_ADDR);
flag_keymaps_rdok=Keymaps_Config_Process();
update_key(); //读取矩阵键盘扫描值
//usb键盘上电前,Esc+Space按键同时按下
if((key_matrix[0][0]==0)&&(key_matrix[3][5]==0)){
Run_Process_Exchanged(); //执行虚拟U盘功能---->设置键盘功能
while(1);
}
Key_BackLight_Ctrl(1);
TM1629_Display(&kled_disp,0); //关闭键盘控制板---背光照明
uart_printf ("\r +------------------------------------------------+ \n");
uart_printf ("\r | CooCox RTOS Running........................... | \n");
uart_printf ("\r +------------------------------------------------+ \n\n");
if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET){ //如果系统已经从独立看门狗复位
RCC_ClearFlag();//清除复位标志
}
Get_UserKey_Data();
Get_UserTDESKey_Data();
CoInitOS(); /*!< Initial CooCox RTOS */
CoCreateTask(Task_Init, (void *)0, 10,&Task_Init_Stk[TASK_STK_SIZE-1], TASK_STK_SIZE);
CoStartOS();
while (1);
}
|
|