UART
Contents
[hide]UART
UART_Init
{{#Widget:LibTable}}Defination | void UART_Init(uint32_t var_baudRate_u32) |
Input Arguments | *uint32_t : Baudrate to be configured. |
Return Value | none |
Description | This function is used to initialize the UART at specified baud rate. If the requested baud rate is not within the supported range then the default baud rate of 9600 is set. |
Usage | UART_Init(9600); //Initialize the uart module for 9600 baud rate; |
UART_SetBaudRate
{{#Widget:LibTable}}Defination | void UART_SetBaudRate(uint32_t var_baudRate_u32) |
Input Arguments | *uint32_t : Baudrate to be configured. |
Return Value | none |
Description | This function is used to Set/Change the baudrate on the fly. If the requested baud rate is not within the supported range then the default baud rate of 9600 is set. |
Usage | UART_SetBaudRate(9600); //Configures the uart module for 9600 baud rate; |
UART_TxChar
{{#Widget:LibTable}}Defination | void UART_TxChar(char var_uartData_u8) |
Input Arguments | char:Ascii value of the character to be transmitted. |
Return Value | none |
Description | This function is used to transmit a char through UART module. |
Usage |
char ch='A'; |
UART_RxChar
{{#Widget:LibTable}}Defination | char UART_RxChar() |
Input Arguments | none. |
Return Value | char: Ascii value of the character received |
Description | This function is used to receive a char from UART module. It waits till a char is received and returns its acsii value after reception. |
Usage |
char ch; |
UART_TxString
{{#Widget:LibTable}}Defination | void UART_TxString(char *ptr_stringPointer_u8) |
Input Arguments | char *:String(Address of the string) to be transmitted. |
Return Value | none |
Description | This function is used to transmit a NULL terminated string through UART. |
Usage |
char myString[]={"hello, world"}; |
UART_RxString
{{#Widget:LibTable}}Defination | void UART_RxString(char *ptr_stringPointer_u8) |
Input Arguments | char *: Address of the string/Buffer where the received data needs to be stored |
Return Value | none |
Description | This function is used to receive a ASCII string through UART till the carriage_return/New_line. The stream of data is copied to the buffer till carriage_return/New_line is encountered. |
Usage |
char buffer[50]; |
UART_TxNumber
{{#Widget:LibTable}}Defination | void UART_TxNumber ( NumericSystem_et e_typeOfNum_e8, uint32_t var_number_u32, uint8_t var_numOfDigitsToDisplay_u8) |
Input Arguments |
|
Return Value | none |
Description | This function is used to transmita max of 10digit decimal/Hex number OR specified number of bits for binary number. 1st parameter specifies type of number ENUM_BINARY(2),ENUM_DECIMAL(10), ENUM_Hex(16).
Decimal:
Hex:
|
Usage |
uint32_t decNumber = 123456; |
UART_Printf
{{#Widget:LibTable}}Defination | void UART_Printf(const char *argList, ...) |
Input Arguments | variable length arguments similar to printf |
Return Value | none |
Description | This function is similar to printf function in C. It takes the arguments with specified format and transmits accordingly .
The supported format specifiers are as below.
|
Usage |
void main()
{
uint16_t decNum=1234;//16-bit UART_Printf("%d %l %f %x %b %s",decNum,longDec,floatNum,hexNum,hexNum,myString); |
Usage guide
- #include"uart.h"
- int main()
- {
- char str_TxMsg_u8[]={"Good Morning"};
- char var_uartData_u8='A';
- uint16_t var_num_u16= 1234u;
- char str_readString_u8[50];
- char ch;
- UART_Init(9600);
- UART_TxString("\n\rProgram to illustrate the UART library usage ");
- UART_TxString(str_TxMsg_u8); /* Transmit the message stored in a string */
- UART_TxString("\n\rChar:");
- UART_TxChar('X'); /* Transmit the specified Ascii character */
- UART_TxChar(var_uartData_u8); /* Transmit the char stored in a variable */
- UART_TxString("\n\rDec:");
- UART_TxDecimalNumber(1234,5); /* Transmit the specified digits of a number */
- UART_TxString(" Hex:");
- UART_TxHexNumber(0xABCD,5); /* Note here the number of digits to transmit=5 */
- UART_TxString(" Bin:"); /* The number Transmitted on UART will be as below*/
- UART_TxBinaryNumber(0xABCD,16);/* dec=01234, hex=0ABCD, bin=1010101111001101*/
- UART_Printf("\n\rDec=%d Hex=%x Bin:%b str=%s",var_num_u16,var_num_u16,var_num_u16,a_TxMsg_u8);
- UART_Printf("\n\rDec=%d Hex=%x Bin:%b str=%s",123u,0xABCDu,0x55u,"hello,world");
- UART_Printf("\n\rEnter a String: ");
- UART_RxString(str_readString_u8);
- UART_Printf("\n\rEntered string is: %s",str_readString_u8);
- do
- {
- UART_Printf("\n\rEnter 'E' to exit: ");
- ch = UART_RxChar();
- UART_Printf("\n\rYou entered: %c",ch);
- }while((ch!='E') && (ch!='e'));
- UART_Printf("\n\rEnjoy Embedded Programming");
- while(1);
- return 0;
- }

Delay
DELAY This library provides the functions to generate the required delays. Basically it does the looping for the specified count to generate the delay. If the compiler provides the inbuilt...

ADC
ADC This library provides the functions for initializing the adc and to get the raw adc values. In case of AVR/PIC/ARM or other high end controllers the inbuilt adc is used. In case of 8051/8052...