本帖最后由 新塘初级用户 于 2020-7-30 09:49 编辑
<div class="blockcode"><blockquote>#include "ML51.h"
#include "BC26.h"
unsigned char uart_receive_data,bufhead;
bit receiveFlag,bufOverFlag;
unsigned char temp;
void Uart0_Init(void);
void Uart0_SendChar(unsigned char Udat);
void Uart0_SendString(unsigned char *PBuf);
typedef struct _UART_BUF //定义数组
{
char buf [BUFLEN+1];
unsigned int index ;
}UART_BUF;
void Clear_Buffer(void) //清空数组
{
Delay_ms(30);
buf_uart2.index=0;
memset(buf_uart2.buf,0,BUFLEN);
}
void nbiot_receive_process_event(unsigned char ch ) //将SBUF保存进数组
{
if(buf_uart2.index >= BUFLEN)
{
buf_uart2.index = 0 ;
}
else{
buf_uart2.buf[buf_uart2.index] = ch;
buf_uart2.index++;
}
}
void BC26_Init(void) //打印数组
{
Uart0_SendString(buf_uart2.buf);
}
void USART2_IRQHandler() interrupt 4 //串口接收中断
{
if (RI)
{
RI=0;
temp=SBUF;
nbiot_receive_process_event(temp);
BC26_Init();
}
if (TI)
{
TI=0;
}
}
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)
{
MFP_P46_GPIO;
P46_PUSHPULL_MODE;
MFP_P31_UART0_TXD;
MFP_P30_UART0_RXD;
P31_QUASI_MODE;
P30_QUASI_MODE;
UART_Open(24000000,UART0_Timer1,115200);
UART_Interrupt_Enable(UART0,Enable);
ENABLE_GLOBAL_INTERRUPT;
while(1)
{
Delay_ms(10000);
Clear_Buffer();
}
}
我用N76E003做串口通信,将16M改成16.6M才使得串口波特率误差小,现在要把N76E003移植到ML51,结果发现ML51产生的波特率误差较大,有没有人会改ML51时钟 |