使用PIC18LF6722中的高优先级接收中断初始化UART
对于最后一行,为什么需要将RCSTA2bits.CREN设置为0? 如果设置为o,如何接收输入的数据 使用高优先级接收中断初始化UsART2使用PIC18LF6722中的高优先级接收中断初始化UART,c,pic,pic18,C,Pic,Pic18,对于最后一行,为什么需要将RCSTA2bits.CREN设置为0? 如果设置为o,如何接收输入的数据 使用高优先级接收中断初始化UsART2 #define InitUART( BRGVal, BRGHighVal ) { \ UARTTxD = UARTTxDInit; \ DirUARTTxD = DirOut
#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; \
}
这是我的高中断代码
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 = ?)
}
这是我的低中断代码
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 = ?)
}
第106页0F
这个代码不起作用,我不知道为什么。你们能帮我一下吗?这是连续接收启用位,您可能需要将其设置为1
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;
}
这将使接收器处于异步模式
哦,您可能希望以这种方式初始化寄存器:
RCSTA2bits.CREN = 1; //Enable UART Receiver
这样,如果您参考数据表,您可以直接将寄存器与正在写入的值进行比较,而不是写入单个位,而不考虑其他位的左边(ADDEN)
还要考虑到CREN
bit覆盖SREN
为什么这是一个宏?它是初始化代码,因此可能只发生一次。让它成为一个函数!我已经编辑了这些问题。你能帮我吗?我想使用异步模式。我已经编辑了问题。你能帮我一下吗?一般来说,你在哪里启用中断?它在头文件InitUART(BRVal,BRGHighVal){}中,到底什么不起作用?你有没有被打断,你有没有进入ISR/handler?它总是卡在这条线上。UARTEnable=1;