|
最近做板子采用新唐N79E814,由于功能多而繁雜,我決定采用RTX51_TINY (2.02版)作為RTOS系統(tǒng)
由于仿真調(diào)試確實(shí)方便,所以沒(méi)有下載到板子上觀察,使用T1定時(shí)器時(shí),仿真沒(méi)有問(wèn)題(T0被RTOS使用)
當(dāng)我使用定時(shí)器2時(shí),發(fā)現(xiàn)定時(shí)器2的中斷,無(wú)論怎么都進(jìn)不去,接下來(lái)花了一天排查各種可能的人為錯(cuò)誤
經(jīng)過(guò)排查,我堅(jiān)信,除了給老婆認(rèn)錯(cuò)之外(調(diào)代碼把老婆丟一邊),我是不可能向代碼認(rèn)錯(cuò)的
發(fā)現(xiàn)使用KEIL仿真邏輯分析儀波形顯示如下
波形.png (55.99 KB, 下載次數(shù): 89)
下載附件
2021-12-21 12:03 上傳
定時(shí)器T2的EIE寄存器的ET2(開(kāi)T2中斷)這個(gè)位,置1了,但是邏輯分析儀顯示為0,所以,應(yīng)該是不支持T2的仿真好吧,下載到板子上試一下~~單片機(jī)代碼如下:- #include <stdio.h>
- #include <rtx51tny.h>
- #include "N79E81x.h"
- #include "Typedef.h"
- #include "Define.h"
- #include "LOGIC.h"
- /*重要說(shuō)明**本程序使用N79E814A內(nèi)部11.0592M*/
- /*重要說(shuō)明**本程序使用N79E814A內(nèi)部11.0592M*/
- //Conf_tny.A51中INT_CLOCK 設(shè)置為 9216 正好是 100HZ滴答 時(shí)間片是10ms
- //Conf_tny.A51中TIMESHARING 設(shè)置為0時(shí),輪換執(zhí)行各任務(wù)
- //Conf_tny.A51中TIMESHARING 設(shè)置為1時(shí),每個(gè)任務(wù)分得10ms
- //Conf_tny.A51中TIMESHARING 設(shè)置為2時(shí),每個(gè)任務(wù)分得20ms
- /*因?yàn)槲易约菏褂眯盘?hào)來(lái)驅(qū)動(dòng)事件,所以TIMESHARING我設(shè)置為0*/
- /**********************************************************************************/
- /* Struct init & I/O init: */
- /**********************************************************************************/
- struct time ctime = { 12, 0, 0 }; /* storage for clock values */
- /***********************************************************************************/
- /* Task 0 'init': Initialize */
- /***********************************************************************************/
- void init (void) _task_ INIT { /* program execution starts here */
- ET2 = 1; //開(kāi)T2中斷使能,EA受到RTOS控制,不用寫(xiě)EA = 1
- os_create_task (CLOCK); /* create clock 1 task */
- os_create_task (KEYREAD); /* create key 2 task */
- //os_create_task (BUZZOUT); /* create key 2 task */
- os_delete_task (INIT); /* del init task (no longer needed) */
- }
- /***********************************************************************************/
- /* Task 1 'clock' @1HZ */
- /***********************************************************************************/
- void clock (void) _task_ CLOCK {
- while (1) { /* loop */
- if (++ctime.sec == 60) { /* calculate the second */
- ctime.sec = 0;
- if (++ctime.min == 60) { /* calculate the minute */
- ctime.min = 0;
- if (++ctime.hour == 24) { /* calculate the hour */
- ctime.hour = 0;
- }
- }
- }
- os_wait (K_IVL, 100, 0); /* wait interval: 1 second */
- P06 = ~P06; //每秒反轉(zhuǎn)一次
- TF2 = 1; //每秒置位一次T2中斷標(biāo)志,進(jìn)入T2中斷
- }
- }
- /***********************************************************************************/
- /* Task 2 'keyread': process key from push button or EC12 */
- /***********************************************************************************/
- struct PressedReg PressedReg = {0,0,0,0,0}; /* 按鍵被按下的次數(shù) */
- void keyread (void) _task_ KEYREAD {
- UINT8 Count;
- BIT Keys_in;
- while (1) { /* loop */
- Count = 0; /* 10 ms interrupt count */
- do
- {
- os_wait(K_TMO, 1, 0); //os_wait()用于把CPU交給其它任務(wù)使用
- } while (!Any_KeyPressed);
- os_wait(K_TMO,1,0);
- do
- {
- if(Any_KeyPressed&&Keys_in == UnLock)
- {
- Count = 0;
- Keys_in = Locked;
- //os_send_signal (BUZZOUT); /* signal to task BUZZOUT: Any_KeyPressed */
- os_wait (K_TMO, 1, 0); /* 10ms 消抖 */
- if(key1_pressed)
- {
- PressedReg.key1 ++;
- }
- if (key2_pressed)
- {
- PressedReg.key2 ++;
- }
- if (key3_pressed)
- {
- PressedReg.key3 ++;
- }
- if (EC12_key_pressed)
- {
- PressedReg.EC12_key ++;
- }
- }
- else
- {
- os_wait (K_TMO, 1, 0);
- Count ++;
- }
- if (All_KeyIdle)
- {
- Keys_in = UnLock;
- Count ++;
- os_wait (K_TMO, 1, 0);
- }
- //你可以更改 100為150,表示1500ms內(nèi)檢測(cè)按下次數(shù)
- } while (Count<=100); //檢測(cè)1000ms內(nèi)按下多少次,可以響應(yīng)單擊,雙擊,三擊,四擊,五擊。。。等
- if(key1_pressed&&PressedReg.key1==SingleClick) /* 單擊且1秒后還沒(méi)放手就是長(zhǎng)按*/
- {
- PressedReg.key1 = LongPressed;
- //os_send_signal (BUZZOUT);
- }
- if (key2_pressed&&PressedReg.key2==SingleClick)
- {
- PressedReg.key2 = LongPressed;
- //os_send_signal (BUZZOUT);
- }
- if (key3_pressed&&PressedReg.key3==SingleClick)
- {
- PressedReg.key3 = LongPressed;
- //os_send_signal (BUZZOUT);
- }
- if (EC12_key_pressed&&PressedReg.EC12_key==SingleClick)
- {
- PressedReg.EC12_key = LongPressed;
- //os_send_signal (BUZZOUT); /* signal to task BUZZOUT: Any_KeylongPressed 按下1秒又響了就是長(zhǎng)按 */
- }
- if(
- PressedReg.key1 != 0 || \
- PressedReg.key2 != 0 || \
- PressedReg.key3 != 0 || \
- PressedReg.EC12_key != 0 \
- )
- {
- //如果按鍵單擊,雙擊,三擊,四擊,長(zhǎng)按,執(zhí)行此處代碼,或者有按鍵動(dòng)作,就發(fā)送信號(hào)給your_TASK
- //os_send_signal (your_TASK); /* signal to task Logic: Any_KeyPressed */
- }
- PressedReg.key1 = 0;
- PressedReg.key2 = 0;
- PressedReg.key3 = 0;
- PressedReg.EC12_key = 0;
- }
-
- }
- /***********************************************************************************/
- /* T2 中斷函數(shù) */
- /***********************************************************************************/
- void Timer2_ISR(void) interrupt 5 // Vecotr @ 0x2B
- {
- P07 = ~P07; //反轉(zhuǎn)LED,使得LED閃爍
- TF2 = 0; //清除T2中斷標(biāo)志
- }
- /***********************************************************************************/
- /* Task 4 'buzzout'蜂鳴器: process buzz from push button or warning */
- /***********************************************************************************/
- void buzzout (void) _task_ BUZZOUT {
- while (1) { /* endless loop */
- os_wait(K_SIG,0,0); /* 等待按鍵任務(wù)發(fā)來(lái)信號(hào)*/
- /* your code PWM開(kāi) */
- //os_wait(K_TMO,10,0); //讓PWM開(kāi)100ms,os_wait()不會(huì)像delay()函數(shù)死死的占用CPU時(shí)間,
- /* your code PWM關(guān) */
- os_switch_task(); /* 把時(shí)間交給其它任務(wù) */
-
- }
- }
復(fù)制代碼
電路.png (20.45 KB, 下載次數(shù): 78)
下載附件
2021-12-21 12:03 上傳
結(jié)果就是,仿真不行,但是實(shí)際燒錄運(yùn)行后,能進(jìn)入Timer 2 中斷:P06每秒反轉(zhuǎn)表示正在運(yùn)行,P07發(fā)生翻轉(zhuǎn)表明進(jìn)入了中斷
本試驗(yàn)只用到了task CLOCK和中斷,按鍵部分的代碼只是分享出來(lái),萬(wàn)一你用得著呢~~~
完整代碼請(qǐng)下載
N79E814.zip
(79.13 KB, 下載次數(shù): 12)
2021-12-21 11:38 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|