These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers uart_irda_transmit.c Source File

uart_irda_transmit.c

00001 /***
00002  * @file        uart_irda_transmit.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 
00023 /* Example group ----------------------------------------------------------- */
00024 /** @defgroup UART_IrDA_Transmit    Transmit
00025  * @ingroup UART_IrDA_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 #define TEST_IRDA LPC_UART3
00038 
00039 /************************** PRIVATE VARIABLES *************************/
00040 uint8_t menu1[] = "Hello NXP Semiconductors \n\r";
00041 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 transmits infrared signals\n\r";
00042 uint8_t menu3[] = "\t\t- Press Esc to terminate this demo \n\r\t\t- Press 'r' to re-print this menu \n\r";
00043 uint8_t menu4[] = "\n\rUART demo terminated!";
00044 uint8_t menu5[] = "\n\rEnter a hex byte value to transmit: 0x";
00045 /************************** PRIVATE FUNCTIONS *************************/
00046 void print_menu(void);
00047 
00048 /*-------------------------PRIVATE FUNCTIONS------------------------------*/
00049 /*********************************************************************//**
00050  * @brief       Print Welcome menu
00051  * @param[in]   none
00052  * @return      None
00053  **********************************************************************/
00054 void print_menu(void)
00055 {
00056     UART_Send(TEST_UART, menu1, sizeof(menu1), BLOCKING);
00057     UART_Send(TEST_UART, menu2, sizeof(menu2), BLOCKING);
00058     UART_Send(TEST_UART, menu3, sizeof(menu3), BLOCKING);
00059 }
00060 
00061 
00062 
00063 /*-------------------------MAIN FUNCTION------------------------------*/
00064 /*********************************************************************//**
00065  * @brief       c_entry: Main UART program body
00066  * @param[in]   None
00067  * @return      int
00068  **********************************************************************/
00069 int c_entry(void)
00070 {
00071     // UART Configuration structure variable
00072     UART_CFG_Type UARTConfigStruct;
00073     // UART FIFO configuration Struct variable
00074     UART_FIFO_CFG_Type UARTFIFOConfigStruct;
00075     // Pin configuration for UART
00076     PINSEL_CFG_Type PinCfg;
00077     uint32_t idx,len;
00078     __IO FlagStatus exitflag;
00079     uint8_t buffer,temp;
00080 
00081 #if (UART_PORT == 0)
00082     /*
00083      * Initialize UART0 pin connect
00084      */
00085     PinCfg.Funcnum = 1;
00086     PinCfg.OpenDrain = 0;
00087     PinCfg.Pinmode = 0;
00088     PinCfg.Pinnum = 2;
00089     PinCfg.Portnum = 0;
00090     PINSEL_ConfigPin(&PinCfg);//P0.2 TXD0
00091     PinCfg.Pinnum = 3;
00092     PINSEL_ConfigPin(&PinCfg);//P0.3 RXD0
00093 #endif
00094 
00095 #if (UART_PORT == 1)
00096     /*
00097      * Initialize UART1 pin connect
00098      */
00099     PinCfg.Funcnum = 2;
00100     PinCfg.OpenDrain = 0;
00101     PinCfg.Pinmode = 0;
00102     PinCfg.Pinnum = 0;
00103     PinCfg.Portnum = 2;
00104     PINSEL_ConfigPin(&PinCfg);
00105     PinCfg.Pinnum = 1;
00106     PINSEL_ConfigPin(&PinCfg);
00107 #endif
00108     /*
00109      * Initialize UART3 pin connect
00110      */
00111     PinCfg.Funcnum = 3;
00112     PinCfg.OpenDrain = 0;
00113     PinCfg.Pinmode = 0;
00114     PinCfg.Pinnum = 25;
00115     PinCfg.Portnum = 0;
00116     PINSEL_ConfigPin(&PinCfg);//P0.25 TXD3
00117 
00118     /* Initialize UART Configuration parameter structure to default state:
00119      * Baudrate = 9600bps
00120      * 8 data bit
00121      * 1 Stop bit
00122      * None parity
00123      */
00124     UART_ConfigStructInit(&UARTConfigStruct);
00125 
00126     // Initialize UART0 & UART3 peripheral with given to corresponding parameter
00127     UART_Init(TEST_UART, &UARTConfigStruct);
00128     UART_Init(TEST_IRDA, &UARTConfigStruct);
00129     /* Initialize FIFOConfigStruct to default state:
00130      *              - FIFO_DMAMode = DISABLE
00131      *              - FIFO_Level = UART_FIFO_TRGLEV0
00132      *              - FIFO_ResetRxBuf = ENABLE
00133      *              - FIFO_ResetTxBuf = ENABLE
00134      *              - FIFO_State = ENABLE
00135      */
00136     UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);
00137 
00138     // Initialize FIFO for UART0 & UART3 peripheral
00139     UART_FIFOConfig(TEST_UART, &UARTFIFOConfigStruct);
00140     UART_FIFOConfig(TEST_IRDA, &UARTFIFOConfigStruct);
00141 
00142     //Configure and enable IrDA mode on UART
00143     UART_IrDACmd(TEST_IRDA,ENABLE);
00144     // Enable UART Transmit
00145     UART_TxCmd(TEST_UART, ENABLE);
00146     UART_TxCmd(TEST_IRDA, ENABLE);
00147     // print welcome screen
00148     print_menu();
00149 
00150     // Reset exit flag
00151     exitflag = RESET;
00152     idx=0;buffer=0;
00153 
00154     /* Read some data from the buffer */
00155     while (exitflag == RESET)
00156     {
00157         if(idx==0)
00158         {
00159             UART_Send(TEST_UART, menu5, sizeof(menu5), BLOCKING);
00160         }
00161         len=0;
00162         while(len==0)
00163         {
00164             len = UART_Receive(TEST_UART, &temp, 1, NONE_BLOCKING);
00165         }
00166         if(temp==27)
00167         {
00168             UART_Send(TEST_UART, menu4, sizeof(menu4), BLOCKING);
00169             exitflag=SET;
00170         }
00171         else if(temp=='r')
00172         {
00173             idx=0;buffer=0;
00174             print_menu();
00175             UART_Send(TEST_IRDA, &buffer, 1, BLOCKING);
00176         }
00177         else
00178         {
00179             idx++;
00180             switch(temp)
00181             {
00182             case '0': buffer=(buffer<<4)|0x00;break;
00183             case '1': buffer=(buffer<<4)|0x01;break;
00184             case '2': buffer=(buffer<<4)|0x02;break;
00185             case '3': buffer=(buffer<<4)|0x03;break;
00186             case '4': buffer=(buffer<<4)|0x04;break;
00187             case '5': buffer=(buffer<<4)|0x05;break;
00188             case '6': buffer=(buffer<<4)|0x06;break;
00189             case '7': buffer=(buffer<<4)|0x07;break;
00190             case '8': buffer=(buffer<<4)|0x08;break;
00191             case '9': buffer=(buffer<<4)|0x09;break;
00192             case 'a': buffer=(buffer<<4)|0x0A;break;
00193             case 'A': buffer=(buffer<<4)|0x0A;break;
00194             case 'b': buffer=(buffer<<4)|0x0B;break;
00195             case 'B': buffer=(buffer<<4)|0x0B;break;
00196             case 'c': buffer=(buffer<<4)|0x0C;break;
00197             case 'C': buffer=(buffer<<4)|0x0C;break;
00198             case 'd': buffer=(buffer<<4)|0x0D;break;
00199             case 'D': buffer=(buffer<<4)|0x0D;break;
00200             case 'e': buffer=(buffer<<4)|0x0E;break;
00201             case 'E': buffer=(buffer<<4)|0x0E;break;
00202             case 'f': buffer=(buffer<<4)|0x0F;break;
00203             case 'F': buffer=(buffer<<4)|0x0F;break;
00204             default: idx=0;buffer=0;break;
00205             }
00206             if(idx==2)
00207             {
00208                 temp=buffer>>4;
00209                 if(temp <= 9)temp=temp+ 0x30;
00210                 else temp=temp+0x37;
00211                 UART_Send(TEST_UART, &temp, 1, BLOCKING);
00212                 temp=(buffer&0x0F);
00213                 if(temp <= 9)temp=temp+ 0x30;
00214                 else temp=temp+0x37;
00215                 UART_Send(TEST_UART, &temp, 1, BLOCKING);
00216 
00217                 UART_Send(TEST_IRDA, &buffer, 1, BLOCKING);
00218                 idx=0;buffer=0;
00219             }
00220         }
00221     }
00222     // wait for current transmission complete - THR must be empty
00223     while (UART_CheckBusy(TEST_UART) == SET);
00224     while (UART_CheckBusy(TEST_IRDA) == SET);
00225     // DeInitialize UART0 & UART3 peripheral
00226     UART_DeInit(TEST_UART);
00227     UART_DeInit(TEST_IRDA);
00228     /* Loop forever */
00229     while(1);
00230     return 1;
00231 }
00232 
00233 /* With ARM and GHS toolsets, the entry point is main() - this will
00234    allow the linker to generate wrapper code to setup stacks, allocate
00235    heap area, and initialize and copy code and data segments. For GNU
00236    toolsets, the entry point is through __start() in the crt0_gnu.asm
00237    file, and that startup code will setup stacks and data */
00238 int main(void)
00239 {
00240     return c_entry();
00241 }
00242 
00243 
00244 #ifdef  DEBUG
00245 /*******************************************************************************
00246 * @brief        Reports the name of the source file and the source line number
00247 *               where the CHECK_PARAM error has occurred.
00248 * @param[in]    file Pointer to the source file name
00249 * @param[in]    line assert_param error line source number
00250 * @return       None
00251 *******************************************************************************/
00252 void check_failed(uint8_t *file, uint32_t line)
00253 {
00254     /* User can add his own implementation to report the file name and line number,
00255      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00256 
00257     /* Infinite loop */
00258     while(1);
00259 }
00260 #endif
00261 /*
00262  * @}
00263  */