本帖最后由 新塘初级用户 于 2020-7-31 10:21 编辑
我做了一个ML51串口接收数据,然后把数据存入数组,再把数组打印出来,但是不知道为什么,我把例程里面的if(receiveFLAG)那个判断条件删了,他反而要执行好几次接收才能返回#include "ML51.H"
#include "BC26.H"
unsigned char uart_receive_data;
bit receiveFlag,bufOverFlag;
void Serial_ISR (void) interrupt 4
{
if (RI)
{
receiveFlag = 1;
uart_receive_data = SBUF;
nbiot_receive_process_event(uart_receive_data); //把SBUF数据依次存入数组
clr_SCON_RI; // Clear RI (Receive Interrupt).
}
if (TI)
{
clr_SCON_TI; // Clear TI (Transmit Interrupt).
}
}
void Uart0_SendChar(unsigned char Udat)
{
SBUF=Udat;
while(!TI);
TI=0;
}
void Uart0_SendString(unsigned char *PBuf)
{
while(*PBuf!='\0')
{
Uart0_SendChar(*PBuf);
PBuf++;
}
}
void main(void)
{
/* Initial UART0 */
MFP_P31_UART0_TXD;
P31_PUSHPULL_MODE;
MFP_P30_UART0_RXD;
P30_INPUT_MODE;
UART_Open(24000000,UART0_Timer3,115200); /*condition is: Fsys, UART0 or UART1 , Baudrate */
ENABLE_UART0_PRINTF;
ENABLE_UART0_INTERRUPT; /* Enable UART0 interrupt */
ENABLE_GLOBAL_INTERRUPT; /* Global interrupt enable */
/* while receive data from RXD, send this data to TXD */
while(1)
{
//if (receiveFlag)
// {
receiveFlag = 0;
BC26_Init();
Delay_ms(1000);
Clear_Buffer(); //清空数组
// }
}
}
|