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


Browsing this Thread:   1 Anonymous Users






PIC18f2221關於 DIO 輸出輸入問題
#1
中級會員
中級會員


查看用戶資訊
請問一下
我將RA4設為輸出,當產生中斷後
RA4 輸出"恆"為1
可是現在有個問題...
我用LATAbits.LATA4=1 讓它輸出為1
可是當跑完這行程式後 它輸出狀態又跑回去0
並不會恆為 1 ,RA4照理說應該會鎖住在1才對吧?
有時我用debug模式讓他run還會跑出數錯誤的訊息
我是在main裡把他寫在while迴圈中
是否有高手前輩可以指點一下問題出在哪?

以下是source code
#include <p18f2221.h>
#include <usart.h>
#include <delays.h>
#include <timers.h>

char RX_Temp;
unsigned char aaaa=0;
void isr_high(void);
void isr_low(void);

//==================================
#pragma code lo_vector=0x18
void isr_low_code(void)
{
_asm GOTO isr_low _endasm
}
#pragma code

#pragma interrupt isr_low
void isr_low(void)
{
PIR1bits.RCIF=0;
RX_Temp = ReadUSART();
}
//==================================
#pragma code hi_vector=0x08
void isr_high_code(void)
{
_asm GOTO isr_high _endasm
}
#pragma code

#pragma interrupt isr_high
void isr_high(void)
{
if(INTCONbits.INT0IF==1)
{
INTCONbits.INT0IF = 0;
aaaa=1;
LATAbits.LATA4 = 1;
}

if(INTCON3bits.INT1IF==1)
{
INTCON3bits.INT1IF = 0;
}
}

void main()
{
OSCCON = 0x62;
OSCTUNE = 0x80;
OpenUSART(USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
25);

PIR1bits.RCIF=1;
PIE1bits.RCIE=1;
IPR1bits.RCIP=0;
RCONbits.IPEN=1;

INTCONbits.GIE=1;
INTCONbits.PEIE=1;
INTCONbits.TMR0IE=0;
INTCONbits.INT0IE=1;
INTCONbits.RBIE=0;

INTCON2bits.RBPU=1;
INTCON2bits.INTEDG0=1;
INTCON2bits.INTEDG1=1;
INTCON2bits.TMR0IP=0;
INTCON2bits.RBIP=0;

INTCON3bits.INT1IE=1;
INTCON3bits.INT2IE=0;
INTCON3bits.INT1IP=1;
INTCON3bits.INT2IP=0;

ADCON0bits.CHS0=0;
ADCON0bits.CHS1=0;
ADCON0bits.CHS2=0;
ADCON0bits.CHS3=0;
ADCON0bits.ADON=0;
ADCON1 = 0x0f;
CMCON = 0x07;

TRISAbits.TRISA0 = 1; //RA0 Input (DI0)

TRISAbits.TRISA3 = 0; //RA3 Output (CS)
TRISAbits.TRISA4 = 0; //RA4 Output (DO0)

LATAbits.LATA3 = 0;
LATAbits.LATA4 = 0;

TRISBbits.TRISB4 = 0;
LATBbits.LATB4 = 1;

while(1)
{
if(aaaa==1)
{
LATAbits.LATA4 = 1;
}
}
}

發表於: 2008/12/23 10:44
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... ]

教育訓練中心

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