閉環(loop)打斷(break),
如果(if)一會兒(while),
三(TRIS)港口(PORT),
中斷(interrupt)睡覺(SLEEP),
呼叫跳轉返回(call jump return),
頭都大埋,我唔明點會咁!
#pragma code _INTERRUPT_VECTORH = 0x003300
#pragma interrupt InterruptVectorH
void InterruptVectorH(void)
{
if (INTCONbits.INT0IF==1)
{
INTCONbits.RBIE=0;
T2CONbits.TMR2ON=0;
INTCONbits.INT0IF=0;
wake=1;
reset_timer1();
WriteCmdXLCD(0x01);
}
else if (INTCONbits.RBIF==1)
{
INTCONbits.RBIF=0;
INTCONbits.RBIE=0;
PIR1bits.RCIF=0;------------->this line is L1
PIE1bits.RCIE=0;------------->this line is L2
wake=2;
}
else if(PIR1bits.RCIF)
{
USART_Status = 0;
if(RCSTAbits.RX9)
{
USART_Status = 0;
if(RCSTAbits.RX9D)
USART_Status |= 1;
};
if(RCSTAbits.FERR)
USART_Status|= 2;
if(RCSTAbits.OERR)
USART_Status|= 4;
if (TXSTAbits.TX9)
{
TXSTAbits.TX9D = 0;
};
Received_DATA = RCREG;
TXREG = Received_DATA;
switch(Received_DATA&~0x20)
{
case 'T': Tx(0x0D);
Tx(0x0A);
Tx('R');
break;
default:
break;
};
if(RCSTAbits.RX9)
{
TXREG = USART_Status+0x30;
while (!TXSTAbits.TRMT);
while (!TXSTAbits.TRMT);
};
wake=1;
};
}
#pragma code
PORTB.RB4 is tied to RX.
Two instruction is executed before _asm SLEEP _endasm
INTCONbits.RCIF=0 and INTCONbits.RCIE=1
fight with it for a long time till realize that L1 and L2 is necessary to wake up by serial port.
Tuesday, June 17, 2008
Posted by roy at 10:12 PM Labels: Normal Day
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment