初始化时是正确的。例如:
- int main(void)
- {
- USART1_Config(115200); //打印
- LCD_Config();
- printf("这是中文"); //打印正确
- SysTick_Init();
- while(1)
- {
- if(tick_10ms>9)
- {
- tick_10ms = 0;
- menu_task(&s_tMenuDemo); //傻孩子大师的新菜单
- }
-
- if(tick_100ms>99)
- {
- tick_100ms = 0;
- }
- }
- }
复制代码
在傻孩子大师的新菜单项中打印就乱码,直接printf打印串口显示的。显示到12864屏幕上也一样,请教各位,这是什么原因?
不知道是不是打开 #pragma anon_unions //匿名结构体需要
还有打勾了 -C99 的编译
- #ifndef __BSP_MENU_H__
- #define __BSP_MENU_H__
- #pragma anon_unions //匿名结构体需要
- #include <stdio.h> //printf( "
USART1 Initialize Success!
" );
- #include <string.h> //memset(buf,0,sizeof(buf));清零 memcpy(,,)
- #include "stm32f10x.h"
- #define this (*ptThis)
- #define UBOUND(__ARR) (sizeof(__ARR)/sizeof(__ARR[0]))
- #ifndef __FSM_RT_TYPE__
- #define __FSM_RT_TYPE__
- //!
ame finit state machine state
- //! @{
- typedef enum {
- fsm_rt_err = -1, //!< fsm error, error code can be get from other interface
- fsm_rt_cpl = 0, //!< fsm complete
- fsm_rt_on_going = 1, //!< fsm on-going
- fsm_rt_wait_for_obj = 2, //!< fsm wait for object
- fsm_rt_asyn = 3, //!< fsm asynchronose complete, you can check it later.
- } fsm_rt_t;
- //! @}
- #endif
- /*============================ MACROS ========================================*/
- /*============================ MACROFIED FUNCTIONS ===========================*/
- #define __declare_menu_item_template(__NAME)
- typedef struct __##__NAME __NAME;
- #define declare_menu_item_template(__NAME)
- __declare_menu_item_template(__NAME)
-
- #define __def_menu_item_template(__NAME)
- struct __##__NAME {
- menu_item_t;
- #define def_menu_item_template(__NAME)
- __def_menu_item_template(__NAME)
- #define end_def_menu_item_template(__NAME)
- };
- #define __def_menu(__NAME, __PARENT, __ENGINE, __TEMPLATE)
- extern const menu_t c_tMenu##__NAME;
- __TEMPLATE c_tMenu##__NAME##Items[] = {
- #define def_menu(__NAME, __PARENT, __ENGINE)
- __def_menu(__NAME, (__PARENT), (__ENGINE), default_menu_item_t)
-
- #define def_menu_ex(__NAME, __PARENT, __ENGINE, __TEMPLATE)
- __def_menu(__NAME, (__PARENT), (__ENGINE), __TEMPLATE)
- #define __end_def_menu(__NAME, __PARENT, __ENGINE, __TEMPLATE)
- };
- const menu_t c_tMenu##__NAME = {
- (menu_item_t *)c_tMenu##__NAME##Items,
- (sizeof(c_tMenu##__NAME##Items)/sizeof(__TEMPLATE)),
- (menu_t *)(__PARENT),
- (__ENGINE),
- };
- #define end_def_menu(__NAME, __PARENT, __ENGINE)
- __end_def_menu(__NAME, (__PARENT), (__ENGINE), default_menu_item_t)
- #define end_def_menu_ex(__NAME, __PARENT, __ENGINE, __TEMPLATE)
- __end_def_menu(__NAME, (__PARENT), (__ENGINE), __TEMPLATE)
-
- #define __extern_menu(__NAME) extern const menu_t c_tMenu##__NAME;
- #define extern_menu(__NAME) __extern_menu(__NAME)
- #define __menu(__NAME) c_tMenu##__NAME
- #define menu(__NAME) __menu(__NAME)
-
- #define __menu_item(__HANDLER, __CHILD_MENU, ...)
- {
- (__HANDLER),
- (menu_t *)(__CHILD_MENU),
- __VA_ARGS__,
- },
- #define menu_item(__HANDLER, __CHILD_MENU, ...)
- __menu_item((__HANDLER), (__CHILD_MENU), __VA_ARGS__)
- /*============================ TYPES =========================================*/
- typedef struct __menu_item menu_item_t; //菜单项
- typedef struct __menu menu_t; //菜单容器
- typedef struct __menu_engine_cb menu_engine_cb_t; //菜单引擎?
- typedef fsm_rt_t menu_item_handler_t(menu_item_t *); //菜单项消息处理引擎
- typedef fsm_rt_t menu_engine_t(menu_engine_cb_t *); //菜单容器消息处理引擎
- //菜单项 基类
- struct __menu_item {
- menu_item_handler_t *fnHandle; //!< handler
- menu_t *ptChild; //!< Child Menu
- };
- //菜单容器 基类
- struct __menu {
- menu_item_t *ptItems; //!< menu item list
- uint_fast8_t chCount; //!< menu item count
- menu_t *ptParent; //!< parent menu;
- menu_engine_t *fnEngine; //!< engine for process current menu
- };
- //菜单引擎?
- struct __menu_engine_cb {
- uint_fast8_t tState;
- const menu_t *ptCurrentMenu; //指向当前菜单容器
- uint_fast8_t chCurrentItemIndex; //当前菜单容器中的菜单项索引号
- };
- /*============================ 以上是基类 =========================================*/
- /*===================== 派生类 默认菜单项 ====================================*/
- typedef struct __default_menu_item_t default_menu_item_t; //派生类 默认菜单项
- struct __default_menu_item_t {
- //! inherit from base class menu_item_t
- menu_item_t;
- //! depends on your application, you can add/remove/change following members
- char *pchTitle; //!< Menu Title
- char *pchDescription; //!< Description for this menu item
- char chShortCutKey; //!< Shortcut Key value in current menu
- };
- /*===================== 派生类 默认菜单项初始化 ================================*/
- extern fsm_rt_t top_menu_engine(menu_engine_cb_t *ptThis); //菜单容器处理函数
- extern fsm_rt_t top_menu_item_a_handler(menu_item_t *ptItem); //菜单项a处理函数
- extern fsm_rt_t top_menu_item_b_handler(menu_item_t *ptItem); //菜单项b处理函数
- extern fsm_rt_t top_menu_item_c_handler(menu_item_t *ptItem); //菜单项c处理函数
- extern const menu_t c_tTopMenu; //顶层菜单容器
- void Display_top_menu(menu_engine_cb_t*ptThis);
- /*===================== 派生类 默认菜单项初始化 ================================*/
- extern fsm_rt_t lv2_menu_engine(menu_engine_cb_t *ptThis); //菜单容器处理函数
- extern fsm_rt_t lv2_menu_item_1_handler(menu_item_t *ptItem); //菜单项处理函数
- extern fsm_rt_t lv2_menu_item_2_handler(menu_item_t *ptItem); //菜单项处理函数
- extern fsm_rt_t lv2_menu_item_3_handler(menu_item_t *ptItem); //菜单项处理函数
- extern const menu_t lv2_menu_A; //菜单容器
- fsm_rt_t menu_task(menu_engine_cb_t *ptThis);
- #endif
复制代码
- //菜单项b处理函数
- fsm_rt_t top_menu_item_b_handler(menu_item_t *ptItem)
- {
- printf("这是 B "); //打印乱码成【杩欐槸 B 】
- return fsm_rt_cpl;
- }
复制代码
用notepad++将源文件转成ANSI格式,解决问题了。
多谢!
一周热门 更多>