• 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 »


Re: PORTB中斷
#17
中級會員
中級會員


查看用戶資訊
回應Ryang大:

是否要運用您之前提到的, 在中斷中僅執行flag的動作就好了; 將比較花費時間的動作拉到main()裡去.

我現在用的是APP013的板子, 外頻接24MHz的震盪器, 所以依照計算Delay10KTCYx(200)的時間為1/3秒.

至於中斷時間, 小弟還不知道如何計算, 請Ryang大指教?

另外再請教, 因為主程式末段有一個無窮回圈, 如果欲將中斷變成旗標的方式, 旗標執行的子程式也不曉得應該放在哪一塊?

發表於: 2008/3/7 14:02
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PORTB中斷
#16
版主
版主


查看用戶資訊
回到之前依職給你的建議,中斷裡不要做那嚜多的事情。
參照:
void isr_low(void)
{
PIR1bits.TMR2IF=0;

k++;
itoa(k,LCD_String); ???
LCD_Set_Cursor(0,2); ???
putsLCD(LCD_String); ???
Delay10KTCYx(200); ??? 尤其是這個 Delay
}
你知道這段程式要花多久時間嗎? 你還沒做完中斷裡的事,Timer2 又發生中斷了,所以想出中斷也難。。。

發表於: 2008/3/7 13:37
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PORTB中斷
#15
中級會員
中級會員


查看用戶資訊
小弟又遇到問題了....

我現在做兩個中斷, PORTB為高優先中斷, Timer2為低優先中斷, 可是在執行後會一直去Timer2中斷, 並不會跳回main裡的while loop, 請教這是因為什麼原因?

void main(void)
{
TRISD=0;
TRISB=1;

RCONbits.IPEN=1; IPR1bits.TMR2IP=0;
INTCONbits.GIEH=1;
INTCONbits.GIEL=1;
k=PORTBbits.RB5;
INTCONbits.RBIF=0;
INTCONbits.RBIE=1;
OpenLCD();
OpenPORTB(0xFF);
OpenTimer2 ( TIMER_INT_ON & T2_PS_1_16
& T2_POST_1_10);

while (1)
{
i++;
itoa(i,LCD_String);
LCD_Set_Cursor(0,0);
putsLCD(LCD_String);
Delay10KTCYx(200);
}
}

#pragma code isrhighcode = 0x0008

void isr_high_direct(void)
{ . .
.
}
#pragma code

#pragma interrupt isr_high

void isr_high(void)
{ .
.
.
}

#pragma code isrlowcode = 0x0018

void isr_low_direct(void)
{
_asm
goto isr_low
_endasm
}
#pragma code

#pragma interrupt isr_low

void isr_low(void)
{
PIR1bits.TMR2IF=0;

k++;
itoa(k,LCD_String);
LCD_Set_Cursor(0,2);
putsLCD(LCD_String);
Delay10KTCYx(200);
}

發表於: 2008/3/6 17:09
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PORTB中斷
#14
版主
版主


查看用戶資訊
恭喜你! Interrupt-On Pin Change 可以動作了。
改為 Sleep Mode 很簡單,試試看。不過要不要試試看把中斷裡的 LCD 顯示程序拿到主程式底下做,中斷只用設定Flag 的方式後交給主程式。

發表於: 2008/3/5 10:54
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PORTB中斷
#13
中級會員
中級會員


查看用戶資訊
剛剛打電話請教了, 終於調整出想要的動作; 在此我將程式貼出來, 也感謝諸位幫助過我的大大

#include <p18f4550.h>
#include "P18F_LCD.h"
#include <delays.h>
#include <portb.h>

int i=0;

char LCD_String[8];

void OpenLCD(void);
void isr_high(void);

void main(void)
{
TRISD=0;
TRISBbits.TRISB4=1;
TRISBbits.TRISB5=1;

RCONbits.IPEN=1; // Enable Interrupt High Priority bit
INTCONbits.GIEH=1; // Enable Global Interrupt bit
k=PORTBbits.RB4; // Read value of PORTB while initialing
INTCONbits.RBIF=0; // Clear PORTB change interrupt flag
INTCONbits.RBIE=1; // Enable High Priority Interrupt

OpenLCD();
OpenPORTB(0xFF);

while (1);


#pragma code isrhighcode = 0x0008

void isr_high_direct(void)
{
_asm //begin in-line assembly
goto isr_high //go to isr_high function
_endasm //end in-line assembly
}
#pragma code

#pragma interrupt isr_high

void isr_high(void)
{
i++;
itoa(i,LCD_String);
LCD_Set_Cursor(0,0);
putsLCD(LCD_String);

k=PORTBbits.RB4;
INTCONbits.RBIF=0;
}

==============分隔線===================分隔線==================

1. 直接針對SW1 and SW2定義, 將這兩pin I/O設定為輸入.
2. 在initial時, 要依照順序定義:

a. 讀取PORTB的值.
b. INTCONbits.RBIF=0
c. INTCONbits.RBIE=1

3. 進入中斷後, 最後一組的動作最好為:
a. 讀取PORTB的值.
b. INTCONbits.RBIF=0


==============分隔線===================分隔線==================

接下來試試看用這種方式使PIC從睡眠模式中醒來....

發表於: 2008/3/3 17:46
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PORTB中斷
#12
中級會員
中級會員


查看用戶資訊
Hi Ryang大,

不好意思, 少貼了一行程式, 在main()裡面, 最後是到了while(1).

發表於: 2008/3/3 15:39
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PORTB中斷
#11
中級會員
中級會員


查看用戶資訊
小弟已經將程式改寫成以下內容, 現在變成, 只有第一次執行會進入中斷, 之後即使按下SW2, 程式也不進行中斷, 可否幫小弟看看是哪裡有問題, 謝謝

#include <p18f4550.h>
#include "P18F_LCD.h"
#include <delays.h>
#include <portb.h>

int i=0;
int j=0;
int k=0;

char LCD_String[8];

void OpenLCD(void);
void isr_high(void);


void main(void)
{
TRISD=0;
TRISB=1;

RCONbits.IPEN=1; // Enable Interrupt High Priority bit
INTCONbits.GIEH=1; // Enable Global Interrupt bit
INTCONbits.RBIE=1; // Enable High Priority Interrupt

k=PORTBbits.RB4;
INTCONbits.RBIF=0; // Clear PORTB change interrupt flag

OpenLCD();
OpenPORTB(0x0);
}

#pragma code isrhighcode = 0x0008

void isr_high_direct(void)
{
_asm //begin in-line assembly
goto isr_high //go to isr_high function
_endasm //end in-line assembly
}
#pragma code

#pragma interrupt isr_high

void isr_high(void)
{
k=PORTBbits.RB4;

INTCONbits.RBIF=0;

OpenLCD();
LCD_Set_Cursor(0,0);
putrsLCD("Shutdown");
Delay10KTCYx(200);
}

發表於: 2008/3/3 15:34
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PORTB中斷
#10
版主
版主


查看用戶資訊
程式怎麼那麼奇怪! main( ) 涵數裡程式最後不知道去哪裡了,可能會造成當機?

發表於: 2008/3/3 15:22
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PORTB中斷
#9
中級會員
中級會員


查看用戶資訊
小弟已經將程式改寫成以下內容, 現在變成, 只有第一次執行會進入中斷, 之後即使按下SW2, 程式也不進行中斷, 可否幫小弟看看是哪裡有問題, 謝謝

#include <p18f4550.h>
#include "P18F_LCD.h"
#include <delays.h>
#include <portb.h>

int i=0;
int j=0;
int k=0;

char LCD_String[8];

void OpenLCD(void);
void isr_high(void);


void main(void)
{
TRISD=0;
TRISB=1;

RCONbits.IPEN=1; // Enable Interrupt High Priority bit
INTCONbits.GIEH=1; // Enable Global Interrupt bit
INTCONbits.RBIE=1; // Enable High Priority Interrupt

k=PORTBbits.RB4;
INTCONbits.RBIF=0; // Clear PORTB change interrupt flag

OpenLCD();
OpenPORTB(0x0);

while(1);
}

#pragma code isrhighcode = 0x0008

void isr_high_direct(void)
{
_asm //begin in-line assembly
goto isr_high //go to isr_high function
_endasm //end in-line assembly
}
#pragma code

#pragma interrupt isr_high

void isr_high(void)
{
k=PORTBbits.RB4;

INTCONbits.RBIF=0;

OpenLCD();
LCD_Set_Cursor(0,0);
putrsLCD("Shutdown");
Delay10KTCYx(200);
}

發表於: 2008/3/3 15:18
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PORTB中斷
#8
版主
版主


查看用戶資訊
/RBPU 位元是用來設定內部提升電阻(約200K ohm),如果環境干擾不大,且沒有另外拉外接線的話是可以使用內部提升電阻,如果有拉線出去建議使用外皆較低阻抗的電阻會比較好。

所以有外接電阻的話,RBPU 位元可以不管,如用內部提升電阻就要致能。

發表於: 2008/3/3 11:05
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... ]

教育訓練中心

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