/***************************************************************************
 *   Copyright (C) 16.04.2004 by                                           *
 *   Matthias Kranz (matthias.kranz@ifi.lmu.de)                            *
 *   Paul Holleis (paul.holleis@ifi.lmu.de)                                *
 *                                                                         *
 *   Last modified 13.01.2005                                              *
 *                                                                         *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 **************************************************************************/

//********* GENERAL SETUP ****************************************************/
/// the pic to use
#include <18f452.h>
/// device directive must precede include
#device *=16 ADC=10
// delay must be defined before first use of
// #use rs232 (see compiler manual); 20MHz crystal used
#define CLOCKCYCLE 20000000
#use delay(clock=CLOCKCYCLE)
// fuses in general
// HS         = Oscillator
// NOWDT      = No Watchdog Timer
// NOBROWNOUT = No Brown Out Detection
// NOPROTECT  = No Protect
// NOLVP      = No Low Voltage Programming
// NOPUT      = No Power Up Timer
//#fuses HS, NOWDT, NOBROWNOUT, NOPROTECT, NOLVP, NOPUT
// no watchdogtimer (wdt), no low-voltage programming (lvp)
// oscillator = hs, no brownout, no code protect
#fuses NOWDT, HS, NOBROWNOUT
//, NOPROTECT, NOLVP

#include <std.h>
//********* PROGRAMMING STYLE ************************************************/
// case sensitive programming
#CASE
// see compiler handbook for description of warnings.
// we are glad with ignoring the following warnings.
#ignore_warnings 201,202,203,205,207,208,216

//********* ADDITIONAL INCLUDES **********************************************/
// (un)comment the following to (un)define the standard spm pins
//#define SPM_USED
#ifdef SPM_USED
	#include "spm2-433-28.h"	
#endif

// (un)comment the following to (un)define the standard i2c pins
//#define USE_I2C
#ifdef USE_I2C
	#include <i2c.h>
#endif

// (un)comment the following to (un)define the standard rf43392 pins
//#define RF43392
#ifdef RF43392
	#include <rf43392.h>
#endif

/// (un)comment if analog sensors are to be used
#ifndef USE_PORT_A_ANALOG
	#define USE_PORT_A_ANALOG
#endif

//********* COMMUNICATION SETUP **********************************************/
#ifdef __STD
  // serial line setup (STDSTREAM) & stdout (no stream)
  #use rs232(baud=STDSTREAM_SPEED,xmit=PIC_TX_PIN,rcv=PIC_RX_PIN,STREAM=STDSTREAM)
  #use rs232(baud=STDSTREAM_SPEED,xmit=PIC_TX_PIN,rcv=PIC_RX_PIN)
#else
  // stdout/sdtin (no stream)
  #use rs232(baud=STDOUT_SPEED,xmit=PIN_C6,rcv=PIN_C7)
#endif
#ifdef __SPM243328
  // spm out/in (SPMSTREAM)
  #use rs232(baud=SPM_SPEED, xmit=SPM_TX_PIN, rcv=SPM_RX_PIN,STREAM=SPMSTREAM)
#endif
#ifdef __RF43392
  // rf out/in (SPMSTREAM)
  #use rs232(baud=SPM_SPEED, xmit=RF433_TX_PIN, rcv=RF433_RX_PIN,STREAM=RF43392STREAM)
#endif

//********* MISCELLANEOUS ****************************************************/
// use fast io if it works for you (which is very rare...).
//#use fast_io(A)
//#use fast_io(B)

/******************************************************************************
 * defines
 *****************************************************************************/

/******************************************************************************
 * includes
 *****************************************************************************/
// use warnings only to translate compiler error codes to text.
// not needed during normal operation.
//#include <warnings.h>
// for standard definitions
//#include <stddef.h>
// for atoi or similar stuff, include the next line:
//#include <stdlib.h>
// for malloc, free or similar stuff, include the next line:
//#include <stdlibm.h>
// for max and mix sizes of data types!
//#include <limits.h>

/******************************************************************************
 * structs
 *****************************************************************************/

/******************************************************************************
 * global variables
 *****************************************************************************/

/******************************************************************************
 * function signatures
 *****************************************************************************/
void main();

/******************************************************************************
 * Code
 *****************************************************************************/
void main()
{
  // variables come first
	
  // pre-main, doing some general setup for the program
  #ifdef USE_PORT_A_ANALOG
    // if analog sensors are to be used
    setup_port_a( ALL_ANALOG );    
    // general analog/digital converter setup
    setup_adc( ADC_CLOCK_INTERNAL );
  #endif
  // spm setup
  #ifdef SPM_USED
    spm_init();
    // wait a little to let the spm init happen!
    delay_ms(50);
  #endif

  // your code below
  for (;;)
  {
	  fprintf(STDSTREAM, "hello world\n\r");
	  delay_ms(100);
	  
  }
}
