Browsing this Thread:
1 Anonymous Users
|
PIC18f2221關於 DIO 輸出輸入問題
|
|
中級會員
Joined
: 2007/12/26 17:11 最後登入時間
: 2009/6/16 14:53
Group:
註冊會員
Level : 6 HP : 0 / 128 MP : 17 / 6283 EXP : 12
|
請問一下 我將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
|
|
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.