• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users




(1) 2 3 »


Re: Interrupt疑問
#21
資深會員
資深會員


查看用戶資訊
參照:

Iori 寫道:
我寫這樣的時候就變成中斷失去作用 不曉得原因在哪
感謝你的意見與指教


去探討 有或沒有while的時候,到底為什麼有中斷沒中斷
實在是沒意義的事
會不會中斷和while無關

我並不清楚你是怎樣判定沒有中斷的,且你也沒說明
是真的沒中斷? 還是"感覺"沒中斷?

既然現在問題是沒中斷
那就該先解決中斷的問題才是
是中斷設定有錯呢
還是沒有中斷訊號進來
先自行確認一下吧

發表於: 2009/7/23 12:52
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Interrupt疑問
#20
資深會員
資深會員


查看用戶資訊
你用這樣去試試吧,斷線設在接收中斷部分...
用PC發信號看看能不能中斷有沒有被觸發
沒有的話就是 INIT沒設好
有的話,再while 加入你要的功能.
先澄清你的UART及中斷部分是否正確.

你先前沒加while(1) 能產生中斷,可能是程式結束都從頭又跑了一次,每次都跑到INIT所以能中斷
一加入while(1)就無法中斷了,有可能是中斷旗標沒清,或是那裡動到UART造成無法再中斷.
以下主程式什麼事都沒做,可以專注確認是否為INIT UART設定問題.



main(void)
{
// I/O 初始化
// 周邊初始化
// 中斷權、參數等初始化
// 其他周邊初始化, ex. LCM
LCDInit();
UART2Init();
    
    while(
1)
    {
    
//主程式區 
         
NOP();
         
NOP();
                
NOP();
    }

}

發表於: 2009/7/22 10:36
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Interrupt疑問
#19
新會員
新會員


查看用戶資訊
奇怪的是 當我沒加上while(1)
並沒出現nicecookie大哥所說的情況
中斷有執行 只是stage的值就只有在中斷的時候變
一跳出中斷又不見了 程式還是正常WORK


參照:

nicecookie 寫道:
WHILE迴圈功能就像y大說的那樣

main ()
{

LCDInit();
UART2Init();

switch (stage)
{
case 1:
workdis();
break;
case 2:
empty();
break;
default:
DisplayStart();
break;
}
Delay(1); //你覺得這行執行完後, 接下來程式會跳到哪執行? 答案是沒人知道, 因為後面沒程式了, 結果可能就是錯亂或當機

}


總之, 不管你main()執行到最後有沒有工作要執行
都不能沒有程式給他跑
最最少也要有個空迴圈
像是

while(1);

發表於: 2009/7/22 8:04
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Interrupt疑問
#18
新會員
新會員


查看用戶資訊
to nicecookie
因為我在放上while()這部分有問題暫時先刪掉了
不曉得nicecookie大哥要看的是這個重點
我補上while的部分如下
main ()
{

LCDInit();

UART2Init();

while(1)
{

switch (stage)
{

case 1:
workdis();
break;
case 2:
empty();
break;
default:
DisplayStart();
break;
}

Delay(1);
}

}
我寫這樣的時候就變成中斷失去作用 不曉得原因在哪
感謝你的意見與指教

發表於: 2009/7/22 7:59
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Interrupt疑問
#17
資深會員
資深會員


查看用戶資訊
main() 架構很單純, 大部分就是這樣


main(void)
{
    
// I/O 初始化
    // 周邊初始化
    // 中斷權、參數等初始化
    // 其他周邊初始化, ex. LCM
    
    
while(1)
    {
        
//主程式區 
        
funA();
        
funB();
        
funC();
    }

}

發表於: 2009/7/21 17:18
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Interrupt疑問
#16
資深會員
資深會員


查看用戶資訊
WHILE迴圈功能就像y大說的那樣

main ()
{

LCDInit();
UART2Init();

switch (stage)
{
case 1:
workdis();
break;
case 2:
empty();
break;
default:
DisplayStart();
break;
}
Delay(1); //你覺得這行執行完後, 接下來程式會跳到哪執行? 答案是沒人知道, 因為後面沒程式了, 結果可能就是錯亂或當機

}


總之, 不管你main()執行到最後有沒有工作要執行
都不能沒有程式給他跑
最最少也要有個空迴圈
像是

while(1);

發表於: 2009/7/21 17:09
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Interrupt疑問
#15
資深會員
資深會員


查看用戶資訊
N大的意思是說,沒加while()程式只跑一次就會出包了....
印象中沒加while() main結束程式,有時會像reset 有時會亂跑
變成無法預測的情況發生.


main()
{
        while()
        {
         
//主程式寫在這裡,無窮回圈才會不斷的執行
         //... 


        
}
}

發表於: 2009/7/21 15:40
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Interrupt疑問
#14
新會員
新會員


查看用戶資訊
你好~我想請教一下
我在寫C還是算新手

但while()最主要不是只能當判斷式用嗎?
還是有其它的用法?

發表於: 2009/7/21 14:05
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Interrupt疑問
#13
資深會員
資深會員


查看用戶資訊
坦白說
只看了main()部分, 就知道其他連看都不用看了

因為你的while迴圈還是沒加上去阿

想問你
你知道main()裡面的while()代表的作用嗎
這可是寫C 很基本的問題

發表於: 2009/7/21 9:55
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Interrupt疑問
#12
新會員
新會員


查看用戶資訊
以下是code的部份
static unsigned char stage;
unsigned char temp;
void Delay ( int count)
{
while(count!=0)
{
int i;
for(i = 0; i < 0x9900; i++);
count--;
}
}

main ()
{

LCDInit();

UART2Init();


switch (stage)
{

case 1:
workdis();
break;
case 2:
empty();
break;
default:
DisplayStart();
break;
}
Delay(1);
}


DisplayStart()
{
LCDClear();
LCDL1Home(); // Set cursor to Line 1 of LCD
char *T = " Welcome ";
putrsLCD(T);
}

void _ISR _U1RXInterrupt()
{
_U1RXIF = 0;
temp = UART2GetChar();
stage = 1;
}

workdis()
{
LCDClear();
LCDL1Home(); // Set cursor to Line 1 of LCD
char *T = " Working ";
putrsLCD(T);
Delay(5);
stage = 2;
}

empty()
{
char *T =" It's empty!!";
LCDClear();
LCDHome();
putrsLCD(T);
}
//--------------------------------Uart init
void UART2Init()
{
// Set directions of UART IOs
UART2_TX_TRIS = 0;
UART2_RX_TRIS = 1;
U2BRG = BAUDRATEREG2;
U2MODE = 0x8000;//Enable Uart for 8-bit data
//no parity, 1 STOP bit

U2STA = 0;
U2MODEbits.UARTEN = 1;
U2STAbits.UTXEN = 1;
// reset RX flag
IFS1bits.U2RXIF = 0;

IPC3bits.U1TXIP2 = 1; //Set Uart TX Interrupt Priority
IPC3bits.U1TXIP1 = 0;
IPC3bits.U1TXIP0 = 0;
IPC2bits.U1RXIP2 = 1; //Set Uart RX Interrupt Priority
IPC2bits.U1RXIP1 = 0;
IPC2bits.U1RXIP0 = 0;
U1STAbits.UTXEN = 1; //Enable Transmit
IEC0bits.U1TXIE = 1; //Enable Transmit Interrupt
IEC0bits.U1RXIE = 1; //Enable Receive Interrupt

}

發表於: 2009/7/21 9:39
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------