Functions

UART "Hello World" example
[Projects]


This example writes the string "Hello World" on start-up. After this all characters received on the RXD input are echoed to the TXD output.

The example implements the low level stdio functions putchar() and getchar() so that standard IO functions such as printf() and gets() can be used by the application.

Functions

char putchar (char c)
char getchar (void)
void putstring (char *s)
void main (void)

Function Documentation

char putchar ( char  c )

Definition at line 41 of file main.c.

{
  hal_uart_putchar(c);
  return c;
}
char getchar ( void   )

Definition at line 52 of file main.c.

{
  return hal_uart_getchar();
}
void putstring ( char *  s )

Definition at line 59 of file main.c.

{
  while(*s != 0)
    putchar(*s++);
}
void main ( void   )

Definition at line 65 of file main.c.

{
  // Configure TXD pin as output.
  // P0.5, P0.3 and P1.0 are configured as outputs to make the example run on
  // either 24-pin, 32-pin or 48-pin nRF24LE1 variants.
  P0DIR = 0xD7;
  P1DIR = 0xFE;

   // Initializes the UART
  hal_uart_init(UART_BAUD_9K6);

  // Wait for XOSC to start to ensure proper UART baudrate
  while(hal_clk_get_16m_source() != HAL_CLK_XOSC16M)
  {}

  // Enable global interrupts
  EA = 1;

  // Print "Hello World" at start-up
  putstring("\r\nHello World!\r\n");

  for(;;)
  {
    // If any characters received
    if( hal_uart_chars_available() )
    {
            P3 = 0x11;
      // Echo received characters
      putchar(getchar());
    }
  }
}