A circuit based similar to the UART test is used to demonstrate the capability of auto baud rate generation.Using the code in the project file attached, It will 1st wait for a character "U" to be send over for baud rate calculation. Auto baud is enable using the 3 lines of code below. The UARTReadByte() will read and discard the byte after a successful configuration of baud rate. //AutoBaud Configuration BAUDCONbits.WUE = 0; BAUDCONbits.ABDEN = 1; UARTReadByte(); // read to clear data The LCD display will be the same as the image below after a successful program of the microcontroller. It is currently waiting for the character U to set the baud rate. After receiving U, the LCD will display the value for SPBRGH:SPBRG. In the case of the example, 9600 baud is used and the output is 00CE. It will send back the 2nd line of the LCD display back to the PC also. The hex character are display and send to the PC based on the 2 codes below. The lower and upper nibble of the byte must be converted to ASCII code so that it can be displayed to the LCD and the PC. char ConvertHex(char data){ switch(data){ case 0x0A: return 'A'; case 0x0B: return 'B'; case 0x0C: return 'C'; case 0x0D: return 'D'; case 0x0E: return 'E'; case 0x0F: return 'F'; default: return (data |0x30); } } void DisplayHex(char data){ char temp = data >> 4; temp = ConvertHex(temp); XLCDPut(temp); UARTSendByte(temp); temp = (data & 0x0F); temp = ConvertHex(temp); XLCDPut(temp); UARTSendByte(temp); } |
Guides >