N76E003 8位是不是串口接收每次只能接收一个字符,多字符就会出现乱码。- #include "N76E003.h"
- #include "SFR_Macro.h"
- #include "Common.h"
- #include "Delay.h"
- #include "Function_define.h"
- #define BUFFER_SIZE 16
- UINT8 UART_BUFFER[BUFFER_SIZE],temp;
- UINT16 u16CNT=0,u16CNT1=0;
- bit riflag;
- /**
- * FUNCTION_PURPOSE: serial interrupt, echo received data.
- * FUNCTION_INPUTS: P0.7(RXD) serial input
- * FUNCTION_OUTPUTS: P0.6(TXD) serial output
- */
- void SerialPort0_ISR(void) interrupt 4
- {
- if (RI==1)
- { /* if reception occur */
- clr_RI; /* clear reception flag for next reception */
- UART_BUFFER[u16CNT] = SBUF;
- u16CNT ++;
- riflag =1;
- }
- if(TI==1)
- {
- clr_TI; /* if emission occur */
- }
- }
- /************************************************************************************************************
- * Main function
- ************************************************************************************************************/
- void main (void)
- {
- P12_PushPull_Mode;
- P06_Quasi_Mode;
- P07_Quasi_Mode;
- InitialUART0_Timer1(115200); /* 115200 Baud Rate from timer1*/
- SCON = 0xD0; // Special setting the mode 3 and 0xD0
- TMOD |= 0x20; //Timer1 Mode1
-
- set_SMOD; //UART0 Double Rate Enable
- set_T1M;
- clr_BRCK; //Serial port 0 baud rate clock source = Timer1
- TH1 = 256 - (1000000/115200+1); /*16 MHz */
- //TH1 = 256 - (1037500/38400); /*16.6 MHz */
- set_TR1;
-
- set_RB8; //This bit is for setting the stop bit 2 high/low status,
-
- clr_TI;
- set_ES; //enable UART interrupt 启用串口中断
- set_EA; //enable global interrupt 启用全局中断
- while(1)
- {
- if (riflag)
- {
- P12 = ~P12; //In debug mode check UART_BUFFER[u16CNT] to check receive data
- temp = SBUF; //This part send the receive data from RXD to TXD
- Send_Data_To_UART0(temp);
- Send_Data_To_UART0(0x5c);
- Send_Data_To_UART0(0x6e);
- Send_Data_To_UART0(0x00);
- Send_Data_To_UART0(0x48);
- Send_Data_To_UART0(0x65);
- Send_Data_To_UART0(0x6c);
- Send_Data_To_UART0(0x6c);
- Send_Data_To_UART0(0x6f);
- riflag = 0;
-
- //u16CNT = 0;
- }
|