+/EE445L
embedded systems
git clone https://git.julia.blue/+/EE445L
99480b6
master
1// UART.h 2// Runs on LM4F120/TM4C123 3// Use UART0 to implement bidirectional data transfer to and from a 4// computer running PuTTy. Interrupts and software FIFOs are used. 5// Daniel Valvano 6// September 20, 2018 7#ifndef _UARTH_ 8#define _UARTH_ 9#include <stdint.h> 10/* This example accompanies the book 11"Embedded Systems: Real Time Interfacing to Arm Cortex M Microcontrollers", 12ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2018 13Program 5.11 Section 5.6, Program 3.10 14 15Copyright 2018 by Jonathan W. Valvano, valvano@mail.utexas.edu 16You may use, edit, run or distribute this file 17as long as the above copyright notice remains 18THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED 19OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 20MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. 21VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, 22OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. 23For more information about my classes, my research, and my books, see 24http://users.ece.utexas.edu/~valvano/ 25*/ 26 27// U0Rx (VCP receive) connected to PA0 28// U0Tx (VCP transmit) connected to PA1 29 30// standard ASCII symbols 31#define CR 0x0D 32#define LF 0x0A 33#define BS 0x08 34#define ESC 0x1B 35#define SP 0x20 36#define DEL 0x7F 37 38//------------UART_Init------------ 39// Initialize the UART for 115,200 baud rate (assuming 80 MHz clock), 40// 8 bit word length, no parity bits, one stop bit, FIFOs enabled 41// Input: none 42// Output: none 43void UART_Init (uint32_t priority ); 44 45//------------UART_InChar------------ 46// Wait for new serial port input 47// Input: none 48// Output: ASCII code for key typed 49char UART_InChar (void ); 50 51// input ASCII character from UART 52// return 0 if RxFifo is empty 53char UART_InCharNonBlock (void ); 54 55//------------UART_OutChar------------ 56// Output 8-bit to serial port 57// Input: letter is an 8-bit ASCII character to be transferred 58// Output: none 59void UART_OutChar (char data ); 60 61//------------UART_OutString------------ 62// Output String (NULL termination) 63// Input: pointer to a NULL-terminated string to be transferred 64// Output: none 65void UART_OutString (char * pt ); 66 67//------------UART_InUDec------------ 68// InUDec accepts ASCII input in unsigned decimal format 69// and converts to a 32-bit unsigned number 70// valid range is 0 to 4294967295 (2^32-1) 71// Input: none 72// Output: 32-bit unsigned number 73// If you enter a number above 4294967295, it will return an incorrect value 74// Backspace will remove last digit typed 75uint32_t UART_InUDec (void ); 76 77//-----------------------UART_OutUDec----------------------- 78// Output a 32-bit number in unsigned decimal format 79// Input: 32-bit number to be transferred 80// Output: none 81// Variable format 1-10 digits with no space before or after 82void UART_OutUDec (uint32_t n ); 83 84//---------------------UART_InUHex---------------------------------------- 85// Accepts ASCII input in unsigned hexadecimal (base 16) format 86// Input: none 87// Output: 32-bit unsigned number 88// No '$' or '0x' need be entered, just the 1 to 8 hex digits 89// It will convert lower case a-f to uppercase A-F 90// and converts to a 16 bit unsigned number 91// value range is 0 to FFFFFFFF 92// If you enter a number above FFFFFFFF, it will return an incorrect value 93// Backspace will remove last digit typed 94uint32_t UART_InUHex (void ); 95 96//--------------------------UART_OutUHex---------------------------- 97// Output a 32-bit number in unsigned hexadecimal format 98// Input: 32-bit number to be transferred 99// Output: none 100// Variable format 1 to 8 digits with no space before or after 101void UART_OutUHex (uint32_t number ); 102 103//------------UART_InString------------ 104// Accepts ASCII characters from the serial port 105// and adds them to a string until <enter> is typed 106// or until max length of the string is reached. 107// It echoes each character as it is inputted. 108// If a backspace is inputted, the string is modified 109// and the backspace is echoed 110// terminates the string with a null character 111// uses busy-waiting synchronization on RDRF 112// Input: pointer to empty buffer, size of buffer 113// Output: Null terminated string 114// -- Modified by Agustinus Darmawan + Mingjie Qiu -- 115void UART_InString (char * bufPt ,uint16_t max ); 116 117#endif