#define InitUART( BRGVal, BRGHighVal ) { \
UARTTxD = UARTTxDInit; \
DirUARTTxD = DirOutput; \
DirUARTRxD = DirInput; \
SPBRG2 = BRGVal; \
TXSTA2bits.BRGH = BRGHighVal; \
TXSTA2bits.SYNC = 0; \
TXSTA2bits.TX9 = 0; \
TXSTA2bits.TXEN = 1; \
RCSTA2bits.SPEN = 1; \
RCSTA2bits.RX9 = 0; \
IPR3bits.RC2IP = 1; \
IPR3bits.TX2IP = 0; \
PIE3bits.TX2IE = 0; \
PIE3bits.RC2IE = 1; \
RCSTA2bits.CREN = 0; \
}
对于最后一行,为什么需要将 RCSTA2bits.CREN 设置为 0?如果设置为o,我如何接收传入的数据?
使用高优先级接收中断初始化 UsART2
InitUART (9600,1);// initialise the USART2 with high priority receive interrupt
这是我的高中断代码
//when some data is transmitted in through USART2
if (UARTRxIntFlag == 1) {
//receive interrupt occurs, do receive function(UARTChIn = ?)
}
这是我的低中断代码
rom unsigned char * szHello = "Hello\r\n";
if (IsSWI( SWI_LMTData ) ){
unsigned char ch = *LMTRxCh;
// if the received character from USART1 is an 'H'
if (ch=='h' || ch=='H'){
// say hello back through USART1
LMTTransmit( szHello, 0, 7, 255, LogicalChannel );
// send 'H' through USART2
UARTChOut = ch;
}
// remove the character from the receive buffer
LMTRxAdvanceCh;
//Receive enable for USART2(RCSTA2bits.CREN = 1;)
UARTEnable = 1;
ClearSWI( SWI_LMTData ); // Clear interrupt flag
return;
}
if (IsSWI( SWI_Tick ) ){
ClearSWI( SWI_Tick ); // Clear interrupt flag
return;
}
第 106 页 0F http://www.flexipanel.com/Docs/Toothpick%202.1%20DS484.pdf
这段代码不起作用,我不知道为什么。你们能帮我吗?