These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!
uart_irda_receive.c
00001 /*** 00002 * @file uart_irda_receive.c 00003 * @purpose This example describes how to using UART in irDA mode 00004 * @version 2.0 00005 * @date 07. June. 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 #include "lpc17xx_gpio.h" 00023 00024 /* Example group ----------------------------------------------------------- */ 00025 /** @defgroup UART_IrDA_Receive Receive 00026 * @ingroup UART_IrDA_Examples 00027 * @{ 00028 */ 00029 00030 /************************** PRIVATE DEFINITIONS *************************/ 00031 #define UART_PORT 0 00032 00033 #if (UART_PORT == 0) 00034 #define TEST_UART LPC_UART0 00035 #elif (UART_PORT == 1) 00036 #define TEST_UART (LPC_UART_TypeDef *)UART1 00037 #endif 00038 #define TEST_IRDA LPC_UART3 00039 00040 /************************** PRIVATE VARIABLES *************************/ 00041 uint8_t menu1[] = "Hello NXP Semiconductors \n\r"; 00042 uint8_t menu2[] = "UART IrDA mode demo \n\r\t MCU LPC17xx - ARM Cortex-M3 \n\r\t UART0 - 9600bps communicates with PC \n\r\t UART3 - 9600bps receives infrared signal\n\r"; 00043 uint8_t menu3[] = "\t The demo keep reading input infrared signal and display through 8 led bank \n\r"; 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 UART_Send(TEST_UART, menu3, sizeof(menu3), BLOCKING); 00058 } 00059 00060 00061 00062 /*-------------------------MAIN FUNCTION------------------------------*/ 00063 /*********************************************************************//** 00064 * @brief c_entry: Main UART program body 00065 * @param[in] None 00066 * @return int 00067 **********************************************************************/ 00068 int c_entry(void) 00069 { 00070 // UART Configuration structure variable 00071 UART_CFG_Type UARTConfigStruct; 00072 // UART FIFO configuration Struct variable 00073 UART_FIFO_CFG_Type UARTFIFOConfigStruct; 00074 // Pin configuration for UART0 00075 PINSEL_CFG_Type PinCfg; 00076 uint32_t len; 00077 uint32_t led_mask[] = { 1<<28, 1<<29, 1UL<<31, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6 }; 00078 uint8_t buffer,i; 00079 00080 //Initialize for 8 led bank 00081 GPIO_SetDir(1, 0xB0000000, 1); /* LEDs on PORT1 defined as Output */ 00082 GPIO_SetDir(2, 0x0000007C, 1); /* LEDs on PORT2 defined as Output */ 00083 00084 GPIO_ClearValue(1, 0xB0000000); 00085 GPIO_ClearValue(2, 0x0000007C); 00086 00087 #if (UART_PORT == 0) 00088 /* 00089 * Initialize UART0 pin connect 00090 */ 00091 PinCfg.Funcnum = 1; 00092 PinCfg.OpenDrain = 0; 00093 PinCfg.Pinmode = 0; 00094 PinCfg.Pinnum = 2; 00095 PinCfg.Portnum = 0; 00096 PINSEL_ConfigPin(&PinCfg);//P0.2 TXD0 00097 #endif 00098 00099 #if (UART_PORT == 1) 00100 /* 00101 * Initialize UART1 pin connect 00102 */ 00103 PinCfg.Funcnum = 2; 00104 PinCfg.OpenDrain = 0; 00105 PinCfg.Pinmode = 0; 00106 PinCfg.Pinnum = 0; 00107 PinCfg.Portnum = 2; 00108 PINSEL_ConfigPin(&PinCfg); 00109 PinCfg.Pinnum = 1; 00110 PINSEL_ConfigPin(&PinCfg); 00111 #endif 00112 /* 00113 * Initialize UART3 pin connect 00114 */ 00115 PinCfg.Funcnum = 3; 00116 PinCfg.OpenDrain = 0; 00117 PinCfg.Pinmode = 0; 00118 PinCfg.Pinnum = 26; 00119 PinCfg.Portnum = 0; 00120 PINSEL_ConfigPin(&PinCfg);//P0.26 RXD3 00121 00122 /* Initialize UART Configuration parameter structure to default state: 00123 * Baudrate = 9600bps 00124 * 8 data bit 00125 * 1 Stop bit 00126 * None parity 00127 */ 00128 UART_ConfigStructInit(&UARTConfigStruct); 00129 00130 // Initialize UART0 & UART3 peripheral with given to corresponding parameter 00131 UART_Init(TEST_UART, &UARTConfigStruct); 00132 UART_Init(TEST_IRDA, &UARTConfigStruct); 00133 /* Initialize FIFOConfigStruct to default state: 00134 * - FIFO_DMAMode = DISABLE 00135 * - FIFO_Level = UART_FIFO_TRGLEV0 00136 * - FIFO_ResetRxBuf = ENABLE 00137 * - FIFO_ResetTxBuf = ENABLE 00138 * - FIFO_State = ENABLE 00139 */ 00140 UART_FIFOConfigStructInit(&UARTFIFOConfigStruct); 00141 00142 // Initialize FIFO for UART0 & UART3 peripheral 00143 UART_FIFOConfig(TEST_UART, &UARTFIFOConfigStruct); 00144 UART_FIFOConfig(TEST_IRDA, &UARTFIFOConfigStruct); 00145 //Configure and enable IrDA mode on UART 00146 UART_IrDACmd(TEST_IRDA,ENABLE); 00147 00148 // Enable UART Transmit 00149 UART_TxCmd(TEST_UART, ENABLE); 00150 00151 // print welcome screen 00152 print_menu(); 00153 00154 /* Read some data from the buffer */ 00155 while (1) 00156 { 00157 len=0; 00158 while(len==0) 00159 { 00160 len = UART_Receive(TEST_IRDA, &buffer, 1, NONE_BLOCKING); 00161 } 00162 if(buffer!=0) 00163 { 00164 for(i=0;i<8;i++) 00165 { 00166 if((buffer>>i)&0x01){//set 00167 if(i<3) 00168 GPIO_SetValue(1, led_mask[i]); 00169 else 00170 GPIO_SetValue(2, led_mask[i]); 00171 } 00172 else { //clear 00173 if(i<3) 00174 GPIO_ClearValue(1, led_mask[i]); 00175 else 00176 GPIO_ClearValue(2, led_mask[i]); 00177 } 00178 } 00179 } 00180 else //clear 8 led bank 00181 { 00182 GPIO_ClearValue(1, 0xB0000000); 00183 GPIO_ClearValue(2, 0x0000007C); 00184 } 00185 } 00186 00187 // wait for current transmission complete - THR must be empty 00188 //while (UART_CheckBusy(TEST_UART) == SET); 00189 00190 // DeInitialize UART0 peripheral 00191 //UART_DeInit(TEST_UART); 00192 00193 /* Loop forever */ 00194 //while(1); 00195 return 1; 00196 } 00197 00198 /* With ARM and GHS toolsets, the entry point is main() - this will 00199 allow the linker to generate wrapper code to setup stacks, allocate 00200 heap area, and initialize and copy code and data segments. For GNU 00201 toolsets, the entry point is through __start() in the crt0_gnu.asm 00202 file, and that startup code will setup stacks and data */ 00203 int main(void) 00204 { 00205 return c_entry(); 00206 } 00207 00208 00209 #ifdef DEBUG 00210 /******************************************************************************* 00211 * @brief Reports the name of the source file and the source line number 00212 * where the CHECK_PARAM error has occurred. 00213 * @param[in] file Pointer to the source file name 00214 * @param[in] line assert_param error line source number 00215 * @return None 00216 *******************************************************************************/ 00217 void check_failed(uint8_t *file, uint32_t line) 00218 { 00219 /* User can add his own implementation to report the file name and line number, 00220 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00221 00222 /* Infinite loop */ 00223 while(1); 00224 } 00225 #endif 00226 /* 00227 * @} 00228 */
Generated on Tue Jul 12 2022 17:28:09 by
![doxygen](doxygen.png)