// ------ When Fcpu = 32 m, filter rate setting ------------ # defineUART_RATE_1200 (uint16) 6661 # average (uint16) 3331 # average (uint16) 1666 # define (uint16) 833 # defineUART_RATE_19200 (uint16) 417 //************************************* // Function Name: init_Uart // function: Serial Port initialization // entry parameter: // exit parameter: // baud rate formula: Fosc/[4 (n + 1)] //************************************** * void Init_Uart (uint16 Tcon) {SPBRGH = (Tcon> 8 );/ /Set the baud rate SPBRGL = (Tcon & 0XFF); TXSTA = 0X04; // enable serial transmission, select high-speed baud rate RCSTA = 0X80; // enable serial operation, continuous receiving enable receiver BAUDCON = (1 <3); // 16-bit baud rate generator TXEN = 1; // enable sending // RX9 = 1; // The ninth-digit receiving enable CREN = 1; // enable receiving RCIE = 1; // enable receiving interruption }//******************************* * ***** // Function Name: uartSendByte // function: Send one byte of data through the serial port // entry parameter: data to be sent // exit parameter: NONE // return value: none //************************************* ** void Uart1SendByte (uint8 Byte) {while (! TRMT); // when the sending data register is full, wait for TXREG = Byte ;} //*************************************/ /function name: uartSendByte // function: Send a series of data via serial port // entry parameter: data to be sent // exit parameter: NONE // return value: none //************************************* ** void Uart1SendString (uint8 *, uint8 DatLong) {uint8 I = 0; for (I = DatLong; I> 0; I --, a ++) {while (! TRMT); // The data sending register is not empty. Wait TXREG = * a ;}// ---- application instance ---- // serial port initialization Init_Uart (UART_RATE_1200); // initialize UART baud rate 1200