• Main Page
  • Modules
  • Index
  • File List
  • Globals

projects/nrfgo_sdk/uart_example/main.c

Go to the documentation of this file.
00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is confidential property of Nordic
00004  * Semiconductor ASA.Terms and conditions of usage are described in detail
00005  * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  *
00011  * $LastChangedRevision: 133 $
00012  */
00013 
00028 //lint -e732
00029 //lint -e713
00030 //lint -e640
00031 
00032 #include <stdio.h>
00033 #include "nrf24le1.h"
00034 #include "hal_uart.h"
00035 #include "hal_clk.h"
00036 
00037 // Cusomization of low level stdio function. Used by for example printf().
00038 #ifdef __ICC8051__
00039 int putchar(int c)
00040 #else /*presume C51 or other accepting compilator*/
00041 char putchar(char c)
00042 #endif
00043 {
00044   hal_uart_putchar(c);
00045   return c;
00046 }
00047 
00048 // Cusomization of low level stdio function. Used by for example gets().
00049 #ifdef __ICC8051__
00050 int getchar(void)
00051 #else /*presume C51 or other accepting compilator*/
00052 char getchar(void)
00053 #endif
00054 {
00055   return hal_uart_getchar();
00056 }
00057 
00058 // Repeated putchar to print a string
00059 void putstring(char *s)
00060 {
00061   while(*s != 0)
00062     putchar(*s++);
00063 }
00064 
00065 void main(void)
00066 {
00067   // Configure TXD pin as output.
00068   // P0.5, P0.3 and P1.0 are configured as outputs to make the example run on
00069   // either 24-pin, 32-pin or 48-pin nRF24LE1 variants.
00070   P0DIR = 0xD7;
00071   P1DIR = 0xFE;
00072 
00073    // Initializes the UART
00074   hal_uart_init(UART_BAUD_9K6);
00075 
00076   // Wait for XOSC to start to ensure proper UART baudrate
00077   while(hal_clk_get_16m_source() != HAL_CLK_XOSC16M)
00078   {}
00079 
00080   // Enable global interrupts
00081   EA = 1;
00082 
00083   // Print "Hello World" at start-up
00084   putstring("\r\nHello World!\r\n");
00085 
00086   for(;;)
00087   {
00088     // If any characters received
00089     if( hal_uart_chars_available() )
00090     {
00091             P3 = 0x11;
00092       // Echo received characters
00093       putchar(getchar());
00094     }
00095   }
00096 }

Generated on Fri Apr 20 2012 14:11:45 for nRFGo SDK by  doxygen 1.7.2