3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
純C/C++ 模擬TIMER效果 資料來源: https://github.com/0x1abin/MultiTimer GITHUB: https://github.com/jash-git/CPP_Timer Code #include #include #include #include #include #include "multi_timer.h" #define CCT (+8)//¥xÆW //https://github.com/0x1abin/MultiTimer using namespace std; struct Timer timer1; struct Timer timer2; void getTime(char *chrDateTimeBuf) { time_t rawtime; struct tm *tm_time; rawtime = time(NULL); tm_time = gmtime(&rawtime); rawtime = time(NULL); tm_time = gmtime(&rawtime); sprintf(chrDateTimeBuf,"%d/d/d d:d:d",1900+tm_time->tm_year,tm_time->tm_mon+1,tm_time->tm_mday,(tm_time->tm_hour+CCT), tm_time->tm_min,tm_time->tm_sec); } void timer1_callback() { char chrDateTimeBuf[80]; getTime(chrDateTimeBuf); printf("timer1 timeout ~ %s \r\n",chrDateTimeBuf); } void timer2_callback() { char chrDateTimeBuf[80]; getTime(chrDateTimeBuf); printf("timer2 timeout ~ %s \r\n",chrDateTimeBuf); } void HAL_SYSTICK_Callback(void) { Sleep(1); timer_ticks(); //1ms ticks } int main() { char chrDateTimeBuf[80]; getTime(chrDateTimeBuf); cout << "Hello world!\t" << chrDateTimeBuf << endl; timer_init(&timer2, timer2_callback, 00, 0); timer_start(&timer2); timer_init(&timer1, timer1_callback, 0, 70); //1s loop timer_start(&timer1); while(1) { timer_loop(); HAL_SYSTICK_Callback(); } return 0; }

本文由jashliaoeuwordpress提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦