用函數(shù)指針數(shù)組賦值的方式處理按鍵不能正確讀取
key_obj?input_key[CLICK_KEY_NUM];

__attribute__((section(".highcode")))
uint8_t?key1_read(void)
{
????return?IN1_READ();
}
__attribute__((section(".highcode")))
uint8_t?key2_read(void)
{
????return?IN1_READ();
}
__attribute__((section(".highcode")))
uint8_t?key3_read(void)
{
????return?IN1_READ();
}
__attribute__((section(".highcode")))
uint8_t?key4_read(void)
{
????return?IN1_READ();
}
__attribute__((section(".highcode")))
uint8_t?key5_read(void)
{
????return?IN1_READ();
}

void?*key_read_func[CLICK_KEY_NUM]?=?{key1_read,key2_read,key3_read,key4_read,key5_read};

static?void?key_obj_init(key_obj?*obj,?uint8_t?key_cnt)
{
????uint8_t?i;
????for(i?=?0;?i?<?key_cnt;?i?++)
????{
????????(*(obj?+?i)).act_level?=?ACTIVE_LEVEL_HIGH;
????????(*(obj?+?i)).cnts?=?0;
????????(*(obj?+?i)).code?=?CODE_NONE;
????????(*(obj?+?i)).cur_status?=?0;
????????(*(obj?+?i)).key_read?=?key_read_func[i];
????}
}

中斷讀取

__attribute__((section(".highcode")))
void?button_obj_handle(key_obj?*obj,?uint8_t?key_cnt)
{
????uint8_t?i;
????for(i?=?0;?i?<?key_cnt;?i?++)
????{
????????if((*(obj?+?i)).cur_status?==?0)
????????{
????????????if(((*(obj?+?i)).key_read)?==?(*(obj?+?i)).act_level)
????????????{
????????????????(*(obj?+?i)).cur_status?=?1;
????????????}
????????}
????????else?if((*(obj?+?i)).cur_status?==?1)
????????{
????????????if(((*(obj?+?i)).key_read)?==?(*(obj?+?i)).act_level)
????????????{
????????????????(*(obj?+?i)).cur_status?=?2;
????????????}
????????????else
????????????{
????????????????(*(obj?+?i)).cur_status?=?0;
????????????}
????????????(*(obj?+?i)).cnts?=?0;
????????}
????}
}

十幾測試讀不到正確的電平,不清楚是不是編譯器或者語法問題

是需要定義一個函數(shù)數(shù)組嗎?

改一改uint8_t?(*key_read_func[CLICK_KEY_NUM])(void)?=?{key1_read,key2_read,key3_read,key4_read,key5_read};

image.png


發(fā)現(xiàn)原因了,按原先的定義數(shù)組,要加個括號才能調(diào)用函數(shù),開始編譯器沒報錯以為那么寫也是對的呢

key_level = (uint8_t)((*(obj + i)).key_read());? ? 現(xiàn)在是這種寫法,順便再問一句,有沒有CH573的看門狗的例程@TECH_JW


CH573 CH582 CH579 看門狗使用 - debugdabiaoge - 博客園 (cnblogs.com)
參考上篇博客。


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频