These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!
uart_polling_test.c
00001 /***********************************************************************//** 00002 * @file uart_polling_test.c 00003 * @purpose This example describes how to using UART in polling mode 00004 * @version 2.0 00005 * @date 21. May. 2010 00006 * @author NXP MCU SW Application Team 00007 *--------------------------------------------------------------------- 00008 * Software that is described herein is for illustrative purposes only 00009 * which provides customers with programming information regarding the 00010 * products. This software is supplied "AS IS" without any warranties. 00011 * NXP Semiconductors assumes no responsibility or liability for the 00012 * use of the software, conveys no license or title under any patent, 00013 * copyright, or mask work right to the product. NXP Semiconductors 00014 * reserves the right to make changes in the software without 00015 * notification. NXP Semiconductors also make no representation or 00016 * warranty that such application will be suitable for the specified 00017 * use without further testing or modification. 00018 **********************************************************************/ 00019 #include "lpc17xx_uart.h" 00020 #include "lpc17xx_libcfg.h" 00021 #include "lpc17xx_pinsel.h" 00022 00023 /* Example group ----------------------------------------------------------- */ 00024 /** @defgroup UART_Polling Polling 00025 * @ingroup UART_Examples 00026 * @{ 00027 */ 00028 00029 /************************** PRIVATE DEFINITIONS *************************/ 00030 #define UART_PORT 0 00031 00032 #if (UART_PORT == 0) 00033 #define TEST_UART LPC_UART0 00034 #elif (UART_PORT == 1) 00035 #define TEST_UART (LPC_UART_TypeDef *)UART1 00036 #endif 00037 00038 00039 /************************** PRIVATE VARIABLES *************************/ 00040 uint8_t menu1[] = "Hello NXP Semiconductors \n\r"; 00041 uint8_t menu2[] = "UART polling mode demo \n\r\t MCU LPC17xx - ARM Cortex-M3 \n\r\t UART0 - 9600bps \n\r"; 00042 uint8_t menu3[] = "UART demo terminated!"; 00043 00044 /************************** PRIVATE FUNCTIONS *************************/ 00045 void print_menu(void); 00046 00047 /*-------------------------PRIVATE FUNCTIONS------------------------------*/ 00048 /*********************************************************************//** 00049 * @brief Print Welcome menu 00050 * @param[in] none 00051 * @return None 00052 **********************************************************************/ 00053 void print_menu(void) 00054 { 00055 UART_Send(TEST_UART, menu1, sizeof(menu1), BLOCKING); 00056 UART_Send(TEST_UART, menu2, sizeof(menu2), BLOCKING); 00057 } 00058 00059 00060 00061 /*-------------------------MAIN FUNCTION------------------------------*/ 00062 /*********************************************************************//** 00063 * @brief c_entry: Main UART program body 00064 * @param[in] None 00065 * @return int 00066 **********************************************************************/ 00067 int c_entry(void) 00068 { 00069 // UART Configuration structure variable 00070 UART_CFG_Type UARTConfigStruct; 00071 // UART FIFO configuration Struct variable 00072 UART_FIFO_CFG_Type UARTFIFOConfigStruct; 00073 // Pin configuration for UART0 00074 PINSEL_CFG_Type PinCfg; 00075 00076 uint32_t idx, len; 00077 __IO FlagStatus exitflag; 00078 uint8_t buffer[10]; 00079 00080 #if (UART_PORT == 0) 00081 /* 00082 * Initialize UART0 pin connect 00083 */ 00084 PinCfg.Funcnum = 1; 00085 PinCfg.OpenDrain = 0; 00086 PinCfg.Pinmode = 0; 00087 PinCfg.Pinnum = 2; 00088 PinCfg.Portnum = 0; 00089 PINSEL_ConfigPin(&PinCfg); 00090 PinCfg.Pinnum = 3; 00091 PINSEL_ConfigPin(&PinCfg); 00092 #endif 00093 00094 #if (UART_PORT == 1) 00095 /* 00096 * Initialize UART1 pin connect 00097 */ 00098 PinCfg.Funcnum = 2; 00099 PinCfg.OpenDrain = 0; 00100 PinCfg.Pinmode = 0; 00101 PinCfg.Pinnum = 0; 00102 PinCfg.Portnum = 2; 00103 PINSEL_ConfigPin(&PinCfg); 00104 PinCfg.Pinnum = 1; 00105 PINSEL_ConfigPin(&PinCfg); 00106 #endif 00107 00108 /* Initialize UART Configuration parameter structure to default state: 00109 * Baudrate = 9600bps 00110 * 8 data bit 00111 * 1 Stop bit 00112 * None parity 00113 */ 00114 UART_ConfigStructInit(&UARTConfigStruct); 00115 00116 // Initialize UART0 peripheral with given to corresponding parameter 00117 UART_Init(TEST_UART, &UARTConfigStruct); 00118 00119 /* Initialize FIFOConfigStruct to default state: 00120 * - FIFO_DMAMode = DISABLE 00121 * - FIFO_Level = UART_FIFO_TRGLEV0 00122 * - FIFO_ResetRxBuf = ENABLE 00123 * - FIFO_ResetTxBuf = ENABLE 00124 * - FIFO_State = ENABLE 00125 */ 00126 UART_FIFOConfigStructInit(&UARTFIFOConfigStruct); 00127 00128 // Initialize FIFO for UART0 peripheral 00129 UART_FIFOConfig(TEST_UART, &UARTFIFOConfigStruct); 00130 00131 00132 // Enable UART Transmit 00133 UART_TxCmd(TEST_UART, ENABLE); 00134 00135 // print welcome screen 00136 print_menu(); 00137 00138 // Reset exit flag 00139 exitflag = RESET; 00140 00141 /* Read some data from the buffer */ 00142 while (exitflag == RESET) 00143 { 00144 len = 0; 00145 while (len == 0) 00146 { 00147 len = UART_Receive(TEST_UART, buffer, sizeof(buffer), NONE_BLOCKING); 00148 } 00149 00150 /* Got some data */ 00151 idx = 0; 00152 while (idx < len) 00153 { 00154 if (buffer[idx] == 27) 00155 { 00156 /* ESC key, set exit flag */ 00157 UART_Send(TEST_UART, menu3, sizeof(menu3), BLOCKING); 00158 exitflag = SET; 00159 } 00160 else if (buffer[idx] == 'r') 00161 { 00162 print_menu(); 00163 } 00164 else 00165 { 00166 /* Echo it back */ 00167 UART_Send(TEST_UART, &buffer[idx], 1, BLOCKING); 00168 } 00169 idx++; 00170 } 00171 } 00172 00173 // wait for current transmission complete - THR must be empty 00174 while (UART_CheckBusy(TEST_UART) == SET); 00175 00176 // DeInitialize UART0 peripheral 00177 UART_DeInit(TEST_UART); 00178 00179 /* Loop forever */ 00180 while(1); 00181 return 1; 00182 } 00183 00184 /* With ARM and GHS toolsets, the entry point is main() - this will 00185 allow the linker to generate wrapper code to setup stacks, allocate 00186 heap area, and initialize and copy code and data segments. For GNU 00187 toolsets, the entry point is through __start() in the crt0_gnu.asm 00188 file, and that startup code will setup stacks and data */ 00189 int main(void) 00190 { 00191 return c_entry(); 00192 } 00193 00194 00195 #ifdef DEBUG 00196 /******************************************************************************* 00197 * @brief Reports the name of the source file and the source line number 00198 * where the CHECK_PARAM error has occurred. 00199 * @param[in] file Pointer to the source file name 00200 * @param[in] line assert_param error line source number 00201 * @return None 00202 *******************************************************************************/ 00203 void check_failed(uint8_t *file, uint32_t line) 00204 { 00205 /* User can add his own implementation to report the file name and line number, 00206 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00207 00208 /* Infinite loop */ 00209 while(1); 00210 } 00211 #endif 00212 00213 /* 00214 * @} 00215 */
Generated on Tue Jul 12 2022 17:28:09 by 1.7.2