/******************************************************************************
*   Functions
******************************************************************************/
void uartDataTaskInit(void)
{
	// Initialization of communication
	uartInit();
	uartSetBaudRate(115200);
	stdout = &mystdout;
}
Exemple #2
0
// ----------- Initialise built in devices ------
void sysInitHardware(void){
	SWITCH_init(&_button_);
	setErrorLog(&uart1SendByte);
	rprintfInit(&uart1SendByte);
	uartInit(_C_uart1,115200);
	segled_init(&_led_display_);
}
Exemple #3
0
//----- Begin Code ------------------------------------------------------------
int main(void)
{
	// initialize our libraries
	// initialize the UART (serial port)
	uartInit();
	uartSetBaudRate(115200);
	// make all rprintf statements use uart for output
	rprintfInit(uartSendByte);
	// initialize the timer system
	timerInit();
	// initialize vt100 terminal
	vt100Init();

	timerPause(100);

	// print welcome message
	vt100ClearScreen();
	vt100SetCursorPos(1,0);
	rprintfProgStrM("\r\nWelcome to the MMC Test Suite!\r\n");

	timerPause(1000);

	mmcTest();

	return 0;
}
void cliInit()
{
  #if defined CFG_INTERFACE && defined CFG_PRINTF_UART
    // Check if UART is already initialised
    uart_pcb_t *pcb = uartGetPCB();
    if (!pcb->initialised)
    {
      uartInit(CFG_UART_BAUDRATE);
    }
  #endif

  #if CFG_INTERFACE_ENABLEIRQ != 0
    // Set IRQ pin as output
    LPC_GPIO->DIR[CFG_INTERFACE_IRQPORT] |= (1 << CFG_INTERFACE_IRQPIN);
    LPC_GPIO->SET[CFG_INTERFACE_IRQPORT] = (1 << CFG_INTERFACE_IRQPIN);
  #endif

  // init the msg ptr
  msg_ptr = msg;

  // Show the menu
  cliMenu();

  // Set the IRQ pin low by default
  #if CFG_INTERFACE_ENABLEIRQ  != 0
    LPC_GPIO->CLR[CFG_INTERFACE_IRQPORT] = (1 << CFG_INTERFACE_IRQPIN);
  #endif
}
//----- Begin Code ------------------------------------------------------------
int main(void)
{
	// initialize our libraries
	// initialize the UART (serial port)
	uartInit();
	// set the baud rate of the UART for our debug/reporting output
	uartSetBaudRate(9600);
	// initialize the timer system
	timerInit();

	// initialize rprintf system
	// - use uartSendByte as the output for all rprintf statements
	//   this will cause all rprintf library functions to direct their
	//   output to the uart
	// - rprintf can be made to output to any device which takes characters.
	//   You must write a function which takes an unsigned char as an argument
	//   and then pass this to rprintfInit like this: rprintfInit(YOUR_FUNCTION);
	rprintfInit(uartSendByte);

	// initialize vt100 library
	vt100Init();
	
	// clear the terminal screen
	vt100ClearScreen();
	
	// run the test
	rprintfTest();

	return 0;
}
Exemple #6
0
int main (void)
{
	sysclk_init();
	wdt_disable(WDT);
	initLeds();
//	rumblecationInit();
	uartInit();

	
	volatile int i;
	
	while(1) {
		//uart_write(UART0, 's');
		//i++;
		/*if(transmitBufRead != transmitBufWrite) {
			uart_write(UART0, transmitBuf[transmitBufRead]);
			transmitBufRead++;
		}*/
		if(uart_is_rx_ready(UART0)) {
			uint8_t in;
			uart_read(UART0, &in);
			uart_write(UART0, in);
		}
	}

}
Exemple #7
0
int main()
{
    AD1PCFGL = 0xFFFF;
    TRISB &= ~(1<<8);
    
    SPI_Init();
    uartInit();
    insight_init();

#ifdef ENC28J60_H
    enc28j60Initialize(mac);
#endif
#ifdef ENC624J600_H
    enc624j600Initialize(mac);
#endif
    sram_23lc1024_init();
    arpInit();
    arpAnnounce(mac, ip, gateway);
    ipv4Init();
    udpInit();
    tcpInit();
    //tcpListen(1234, 32, handleConnection);
    icmpInit();
    ntpInit();
    //ntpRequest(ntpServer);

    RtosTaskInit();
    RtosTaskCreate(&ethTask, "Eth", EthernetTask, 5, ethTaskStk, sizeof(ethTaskStk));
    RtosTaskCreate(&ledTask, "LED", LedTask, 1, ledTaskStk, sizeof(ledTaskStk));
    RtosTaskRun();

    while(1);
    return 0;
}
Exemple #8
0
int
main(void)
{
	struct ds1307_t rtc_tm;

	static const char infostring[] PROGMEM = "Demo - DS1307 RTC\r\n";
	char buffer[BUFFER_SIZE];

	uartInit(BAUDRATE);
	i2cInit(I2C_STD_MODE);
	sei();

	ds1307Init();
	ds1307SetTime(SYS_HOUR, SYS_MINS, SYS_SECS);
	ds1307SetDate(SYS_DAY, SYS_MONTH, SYS_YEAR);

	uartPutString_P(infostring);

	while (1) {
		/* Read Current Time from DS1307 and output to UART */
		ds1307GetTime(&rtc_tm);
		sprintf(buffer, "RTC: [%02d:%02d:%02d] - [%02d.%02d.%02d]\r\n",
		    rtc_tm.hours, rtc_tm.minutes, rtc_tm.seconds, rtc_tm.day,
		    rtc_tm.month, rtc_tm.year);
		uartPutString(buffer);
		_delay_ms(1000);
	}

	/* never reached */
	return (0);
}
Exemple #9
0
//----- Begin Code ------------------------------------------------------------
int main(void)
{
	// initialize our libraries
	// initialize the UART (serial port)
	uartInit();
	uartSetBaudRate(9600);
	// make all rprintf statements use uart for output
	rprintfInit(uartSendByte);
	// turn on and initialize A/D converter
	a2dInit();
	// initialize the timer system
	timerInit();
	// initialize vt100 terminal
	vt100Init();

	// configure port B for led output and pushbutton input
	outb(DDRB, 0x0F);
	// all LEDs on
	outb(PORTB, 0x00);
	// wait for hardware to power up
	timerPause(100);
	// all LEDs off
	outb(PORTB, 0x0F);

	// start command line
	goCmdline();

	return 0;
}
Exemple #10
0
int main(void){
	
	uint16_t byteCount = 0;
	char buffer0[32];
	
	HAL_Init();
	SYS_TimerInit();
	PHY_Init();
	NWK_Init();
	//SYS_INIT()
	timer3Init();
	uartInit();
	sei();

	while (1){
		
		SYS_TaskHandler();
		
		byteCount = uartAvailable();
		
		if(byteCount > 0){
			HAL_UartBytesReceived(byteCount);
			sprintf(buffer0, "Bytes to send: %i\n", byteCount);
			uartPuts(buffer0);
		}
		APP_TaskHandler();
	}
}
Exemple #11
0
//----- Begin Code ------------------------------------------------------------
int main(void)
{
	// initialize our libraries
	// initialize the UART (serial port)
	uartInit();
	// set the baud rate of UART 0 for our debug/reporting output
	uartSetBaudRate(0,9600);
	// set uart0SendByte as the output for all rprintf statements
	rprintfInit(uart0SendByte);
	// initialize the timer system
	timerInit();
	// initialize vt100 library
	vt100Init();
	
	// print a little intro message so we know things are working
	vt100ClearScreen();
	rprintf("\r\nWelcome to GPS Test!\r\n");
	
	// run example gps processing loop
	// (pick the one appropriate for your GPS packet format)
//	gpsTsipTest();
	gpsNmeaTest();
	
	return 0;
}
Exemple #12
0
void sysInit(void){
	
	PMOD_DDR |= _BV(PMOD0) | _BV(PMOD1) | _BV(PMOD2) | _BV(PORTD4);		//Set PMOD as outputs
	WIZ_DDR &= ~(_BV(INT_W5500));							//Int is an input
	WIZ_PORT |= _BV(INT_W5500);								//Enable pull up
	WIZ_DDR |= _BV(SS_W5500);								//Set SS as output 
	AUX_DDR &= ~(_BV(BTN0) | _BV(ISENSE) | _BV(VSENSE));	//Button set as input Isense and Vsense inputs(will be used for ADC)
	AUX_DDR |= _BV(WP_EEP);									//WP pin for eeprom as output
	LED_DDR |= _BV(LED_R) | _BV(LED_G) | _BV(LED_B);
	AUX_PORT |= _BV(BTN0);									//Enable pull up on btn
	
	PMOD_PORT |= _BV(PMOD0) | _BV(PMOD1) | _BV(PMOD2);		//Full auto
	
	
	uartInit();
	i2c_init();
	sei();
	
	DDRB |= _BV(PORTB2) | _BV(PORTB1) | _BV(PORTB0);
	SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);  // SPI enable, Master, f/16
	
	uartPutsP("\n\n[Base Station]\n");
	uartPutsP(">Pins init\n");
	timer0Init();
	uartPutsP(">Timer 0 init\n");
	timer1Init();
	uartPutsP(">Timer 1 init\n");

}
Exemple #13
0
int main() {
	GPIO2DIR = BIT11; //LED to show if powered/reset/in ISP mode
	GPIO2DATA = BIT11; // LED on
	uartInit();
	char rxc;
	// while(1){
		// while((U0LSR & BIT0) == 0){}; //wait for new char to be recieved
		// char rxc = U0RBR;
		// if(rxc == 'A') {
			// GPIO2DATA = 0; //off
			// for(volatile int i=0; i<1000000; i++){}; //delay
			// GPIO2DATA = BIT11; //on
		// } else {
			// U0THR = rxc;
		// }
	// }
	while(1){
		while((U0LSR & BIT0) == 0){}; //wait for new char to be recieved
		rxc = U0RBR;
		GPIO2DATA ^= BIT11;
		U0THR = rxc;	
	}
		
	return 0;
}
Exemple #14
0
/**
 * @brief GPS Init
 */
void gpsInit(uchar uartId)
{
	// Capture NMEA Sentence OFF
	gpsCaptureNMEASentence = 0;


	// Initialize Structs
	structNmeaGPRMC.isValid = 'N';
	structNmeaGPRMC.wasRead = 'Y';

	// Configure GPS Pins
	ioDigitalOutput(GPS_TX);
	ioDigitalInput(GPS_RX);
	ioDigitalWrite(GPS_ON_OFF,OFF);
	ioDigitalOutput(GPS_ON_OFF);
	ioDigitalInput(GPS_WAKE);

	// UART init Clock 4MHz
	uartInit(uartId);

	// UART Read Interrupt
	uartReadInterrupt(ON);

	// Start GPS
	ioDigitalWrite(GPS_ON_OFF,ON);
	delayMs(200);
	ioDigitalWrite(GPS_ON_OFF,OFF);

	// Wait for GPS WakeUp
	while(ioDigitalRead(GPS_ON_OFF));
}
Exemple #15
0
int main (void)
{
   cpuInit();
   uartInit(BAUDRATE);
   
#ifdef CLKOUT
   IOCON_PIO0_1 &= ~(0x3f);
   IOCON_PIO0_1 |= IOCON_PIO0_1_FUNC_CLKOUT;
   
   SCB_CLKOUTCLKSEL |= 0x3; // select system osci
   
   SCB_CLKOUTCLKUEN = SCB_CLKOUTCLKUEN_UPDATE;
   SCB_CLKOUTCLKUEN = SCB_CLKOUTCLKUEN_DISABLE;
   SCB_CLKOUTCLKUEN = SCB_CLKOUTCLKUEN_UPDATE;
   while( !(SCB_CLKOUTCLKUEN & SCB_CLKOUTCLKUEN_UPDATE));
   SCB_CLKOUTCLKDIV = SCB_CLKOUTCLKDIV_DIV1;
   
#endif   
   
      //initPWM(16, 0, (1<<0), 256, 0);
   printf("Starting in main\n");
   cmdInit();

   while (1)
   {
      cmdPoll();
   }
}
Exemple #16
0
void initialize_io_uart(void) {
    /* On reset (i.e., before calling mcgInit), the processor clocking
     * starts in FEI (FLL Engaged Internal) mode.  In FEI mode and with
     * default settings (DRST_DRS = 00, DMX32 = 0), the MCGFLLCLK, the
     * MCGOUTCLK (MCG (Multipurpose Clock Generator) clock), and the Bus
     * (peripheral) clock are all set to 640 * IRC.  IRC is the Internal
     * Reference Clock which runs at 32 KHz. [See K70 Sub-Family
     * Reference Manual, Rev. 2, Section 25.4.1.1, Table 25-22 on
     * page 657 and MCG Control 4 Register (MCG_C4) Section 25.3.4 on
     * page 641] */

    /* After calling mcgInit, MCGOUTCLK is set to 120 MHz and the Bus
     * (peripheral) clock is set to 60 MHz.*/

    /* Table 5-2 on page 221 indicates that the clock used by UART0 and
     * UART1 is the System clock (i.e., MCGOUTCLK) and that the clock
     * used by UART2-5 is the Bus clock. */

    const int busClock = 60000000;
    const int KHzInHz = 1000;
    const int busBaud = 115200;

    uartInit(UART2_BASE_PTR, busClock/KHzInHz, busBaud);
    intSerialIOInit();
}
void setup() {
  uartInit();
  uartSetBaudRate(0, 9600);
  rprintfInit(uart0SendByte);
  //rprintf("$Id$");

  // this goes to the switch common
  sbi(DDRD, PD4); // output on PD4
  cbi(PORTD, PD4); // take it low


  // rocker
  cbi(DDRD, PD5); // input on PD5
  sbi(PORTD, PD5); // tri-state the input

  // rocker
  cbi(DDRD, PD6);
  sbi(PORTD, PD6); // tri-state the input

  // rocker press
  cbi(DDRD, PD7);
  sbi(PORTD, PD7);

  sbi(DDRB, PB3); // output for the LED
  sbi(PORTB, PB3);
 }
Exemple #18
0
void cmdInit()
{
  #if defined CFG_INTERFACE && defined CFG_INTERFACE_UART
    // Check if UART is already initialised
    uart_pcb_t *pcb = uartGetPCB();
    if (!pcb->initialised)
    {
      uartInit(CFG_UART_BAUDRATE);
    }
  #endif

  #if CFG_INTERFACE_ENABLEIRQ != 0
    // Set IRQ pin as output
    gpioSetDir(CFG_INTERFACE_IRQPORT, CFG_INTERFACE_IRQPIN, gpioDirection_Output);
    gpioSetValue(CFG_INTERFACE_IRQPORT, CFG_INTERFACE_IRQPIN, 1);
  #endif

  // init the msg ptr
  msg_ptr = msg;

  // Show the menu
  cmdMenu();

  // Set the IRQ pin low by default
  #if CFG_INTERFACE_ENABLEIRQ  != 0
    gpioSetValue(CFG_INTERFACE_IRQPORT, CFG_INTERFACE_IRQPIN, 0);
  #endif
}
Exemple #19
0
// functions
void oscInit(void)
{
	// initialize uart (if not already done)
	uartInit();
	// set the default communication rate
	uartSetBaudRate(38400);
}
Exemple #20
0
MB_ErrorTypeDef MB_init(uint8_t devAddr, uint32_t baudRate, uint32_t cpuFrequency)
{
MB_ErrorTypeDef error = MB_ERROR_OK;
  if ((devAddr < MB_ADDR_MIN) || (devAddr > MB_ADDR_MAX) || (baudRate == 0)) {
    error = MB_ERROR_ILLVAL;
  }
  else {
    mbDevAddr = devAddr;

    uart.baudRate = baudRate;
    uart.cpuFrequency = cpuFrequency;
    uart.byte_received_cb = MB_byte_received_cb;
    uart.byte_sent_cb = MB_byte_sent_cb;
    uartInit(&uart);
    printf("UART initialized at %u bod\n", (unsigned int)uart.baudRate);

    if (cpuFrequency > MODBUS_BIG_BAUDRATE)                                                     //For baud rates more than 19200 fixed intervals used (1750us, 750us)
    {
      tChar = TCHAR;
    }
    else                                                                                        //else calculate these intervals
    {
      tChar = (uint16_t)(11 * cpuFrequency / baudRate);                                         //1 char (11bit per char)
    }

    mbState = MB_STATE_DISABLED;
    rxState = RX_STATE_IDLE;
    txState = TX_STATE_IDLE;
  }
  return error;
}
Exemple #21
0
static void bootstrap()
{
	const int moduleClock = 12000000;
	const int KHzInHz = 1000;
	const int baud = 115200;
	mcgInit();
	sdramInit();
	svcInit_SetSVCPriority(15);
	setSysTickPriority(14);
	setPendSVPriority(14);
	uartInit(UART2_BASE_PTR, moduleClock/KHzInHz, baud);
	lcdcInit();
	lcdcConsoleInit(&console);
	adc_init();
	vfs_init();
	ledInitAll();
	pushbuttonInitAll();
	TSI_Init();
	TSI_Calibrate();
	init_memory();
	//uinit();
	intSerialIOInit();
	flexTimerInit();
	sysTickInit();
}
void setup() {
  uartInit();
  uartSetBaudRate(0, 9600);
  rprintfInit(uart0SendByte);
  rprintf("Hello..\r\n");
  //vt100Init();


  cbi(DDRC, DDC3); // input 

  cbi(DDRA, DDA0); // input
  cbi(DDRA, DDA1); // input
  cbi(DDRA, DDA2); // input
  cbi(DDRA, DDA3); // input
  cbi(DDRA, DDA4);
  
  sbi(DDRA, DDA5); // output connected by select to PA4
  cbi(PORTA, PA5);
  
  sbi(PORTA, PA0); // pull-ups enabled
  sbi(PORTA, PA1);
  sbi(PORTA, PA2);
  sbi(PORTA, PA3);
  sbi(PORTA, PA4);
  cbi(PORTA, PA5);
  

  cbi(DDRD, DDD6); // input
  //cbi(PORTB, PB3);

  // We want PCINT30 enabled so we know when the charger is connected
  //  PCICR |= (1<<PCIE3); // enable pin change interrupt 3 for PCINT31..24. 
//  PCMSK3 |= 0xFF;//(1<<PCINT30); // enable PCINT30

  // arb switch
  PCICR |= (0<<PCIE3) | (0<<PCIE2) | (0<<PCIE1) | (1<<PCIE0);
  //  PCMSK3 |= (1<<PCINT30);
  //  PCMSK3 |= (1<<PCINT26);
  //  PCMSK2 |= (1<<PCINT19);
  PCMSK0 |= (1<<PCINT0) | (1<<PCINT1) | (1<<PCINT2) | (1<<PCINT3) | (1<<PCINT4) | (1<<PCINT5);


  // set up the power pulse LED
  
  TCCR0A |= (1<<WGM00) | (1<<COM0A1); // mode 1, phase-correct PWM
  TCCR0B |= (1<<CS02); // clk/256 from prescaler
  //TCCR0B |= (0<<CS02) | (1<<CS01) | (1<<CS00); // clk/64

  TCNT0 = 0x00;
  sbi(TIMSK0, TOIE0);

  sbi(DDRB, PB3);
  sbi(PORTB, PB3);
/*
  cbi(DDRD, PD6); // configure PD6 as input
  sbi(PORTD, PD6); // turn on pull-up resistor
*/
  sei();
}
Exemple #23
0
/**
 * @brief   HAL initialization.
 * @details This function invokes the low level initialization code then
 *          initializes all the drivers enabled in the HAL. Finally the
 *          board-specific initialization is performed by invoking
 *          @p boardInit() (usually defined in @p board.c).
 *
 * @init
 */
void halInit(void) {

  hal_lld_init();

#if HAL_USE_TM || defined(__DOXYGEN__)
  tmInit();
#endif
#if HAL_USE_PAL || defined(__DOXYGEN__)
  palInit(&pal_default_config);
#endif
#if HAL_USE_ADC || defined(__DOXYGEN__)
  adcInit();
#endif
#if HAL_USE_CAN || defined(__DOXYGEN__)
  canInit();
#endif
#if HAL_USE_EXT || defined(__DOXYGEN__)
  extInit();
#endif
#if HAL_USE_GPT || defined(__DOXYGEN__)
  gptInit();
#endif
#if HAL_USE_I2C || defined(__DOXYGEN__)
  i2cInit();
#endif
#if HAL_USE_ICU || defined(__DOXYGEN__)
  icuInit();
#endif
#if HAL_USE_MAC || defined(__DOXYGEN__)
  macInit();
#endif
#if HAL_USE_PWM || defined(__DOXYGEN__)
  pwmInit();
#endif
#if HAL_USE_SERIAL || defined(__DOXYGEN__)
  sdInit();
#endif
#if HAL_USE_SDC || defined(__DOXYGEN__)
  //KL All in Kl_sdc sdcInit();
#endif
#if HAL_USE_SPI || defined(__DOXYGEN__)
  spiInit();
#endif
#if HAL_USE_UART || defined(__DOXYGEN__)
  uartInit();
#endif
#if HAL_USE_USB || defined(__DOXYGEN__)
  usbInit();
#endif
#if HAL_USE_MMC_SPI || defined(__DOXYGEN__)
  mmcInit();
#endif
#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
  sduInit();
#endif
#if HAL_USE_RTC || defined(__DOXYGEN__)
  rtcInit();
#endif
}
Exemple #24
0
/**
 * @fn      void init( void );
 * @brief   Configuration des périphériques
 */
void init(void){

//    gpioInit();
    uartInit();
    timerInit();
    pwmInit();
    spiChannel = ads7885Pic32Open( CHN_SPI, 40 );
}
void initUart(void)
{
	uartInit();
	 // make all rprintf statements use uart for output
	rprintfInit(uartSendByte);
	 // initialize the timer system
	uartSetBaudRate(2400);
}
Exemple #26
0
static void resetUart(void)
{

    uartInit(baud.dword, parity, stopbit, databit);
    irptr    = 0;
    iwptr    = 0;
    urptr    = 0;
    uwptr    = 0;
}
Exemple #27
0
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_ADC1_Init();
  MX_I2C1_Init();
  MX_RTC_Init();
  MX_SPI2_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_TIM4_Init();
  MX_USART3_UART_Init();

  /* USER CODE BEGIN 2 */
	encoderInit();
	pwmInit();
//	adcInit();
	uartInit();
	timInterruptInit();
	gyroInit(GYROHIGH);
	calibrateGyro();

//	rotaryRight(800);
//	HAL_Delay(500);
//	rotaryLeft(800);
	drive(VEL);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
void serialInit(void)
{
	// Initialize the serial port for USB serial bridge
	uartInit(115200, 115200);
//	TURN_OFF_SYSTEM_MESSAGES();
	TURN_ON_SYSTEM_MESSAGES();
	system_os_task(taskHandler, USER_TASK_PRIO_0, taskQueue, taskQueueLen);
//	DISPLAY_MENU();
	DISPLAY_MENU_W_SPI();
}
Exemple #29
0
// Now create any global variables such as motors, servos, sensors etc
// This routine is called once only and allows you to do set up the hardware
// Dont use any 'clock' functions here - use 'delay' functions instead
void appInitHardware(void){
	a2dSetPrescaler(ADC_PRESCALE_DIV128);

	cyrf6936_Initialise_hard();


	// Initialise SPI bus as master. (RF modules connected to hardware SPI)
    spiBusInit(&bus, TRUE);
	spiDeviceSelect(&cyrf_0, TRUE);
	spiDeviceSelect(&cyrf_0, FALSE);
	spiDeviceSelect(&cyrf_1, TRUE);
	spiDeviceSelect(&cyrf_1, FALSE);

	// set I/O pins for RF module(s).
	pin_make_input(D4, FALSE);		// set PACTL pin to input. (module on connector J1)
	pin_make_input(D5, FALSE);		// set PACTLn pin to input. (module on connector J1)
	pin_make_input(D6, FALSE);		// set PACTL pin to input. (module on connector J2)
	pin_make_input(D7, FALSE);		// set PACTLn pin to input. (module on connector J2)

#ifdef RF_MODULE_ARTAFLEX
	//
	pin_make_output(D4, FALSE);			// set RXPA pin to output. (module on connector J1)
	pin_make_output(D5, FALSE);			// set TXPA pin to output. (module on connector J1)
	pin_make_output(D6, FALSE);			// set RXPA pin to output. (module on connector J2)
	pin_make_output(D7, FALSE);			// set TXPA pin to output. (module on connector J2)
#endif

	pin_make_input(E7, TRUE);		// set UNIGEN RF module IRQ pin to input. (module on connector J1)
	pin_make_input(E6, TRUE);		// set UNIGEN RF module IRQ pin to input. (module on connector J2)
	pin_make_output(G3, FALSE);			// set UNIGEN RF module RST pin to output. (both modules)
	//pin_low(G3);					// don't reset yet.

	// set I/O pins for status LEDs
	pin_make_output(C0, TRUE);			// set LED pin for output
	pin_make_output(C1, TRUE);			// set LED pin for output
	pin_make_output(C2, FALSE);			// set LED pin for output
	//pin_high(C0);					// LED off
	//pin_high(C1);					// LED off
	//pin_low(C2);					// LED on


	// Set UART1 to 19200 baud
    uartInit(UART1, 38400);
    // Tell rprintf to output to UART1
    rprintfInit(&uart1SendByte);


    // Initialise the servo controller using Hardware PWM
    servoPWMInit(&bank1);


    // Initialise WatchDog Timer
    wdt_enable( WDTO_500MS );

}
Exemple #30
0
//----- Begin Code ------------------------------------------------------------
int main(void)
{
	u16 a=0;
	u08 i=0;

	// initialize our libraries
	// initialize the UART (serial port)
	uartInit();
	// make all rprintf statements use uart for output
	rprintfInit(uartSendByte);
	// initialize the timer system
	timerInit();
	// turn on and initialize A/D converter
	a2dInit();

	// print a little intro message so we know things are working
	vt100ClearScreen();
	vt100SetCursorPos(1,1);
	rprintf("Welcome to the a2d test!\r\n");
	
	// configure a2d port (PORTA) as input
	// so we can receive analog signals
	DDRA = 0x00;
	// make sure pull-up resistors are turned off
	PORTA = 0x00;

	// set the a2d prescaler (clock division ratio)
	// - a lower prescale setting will make the a2d converter go faster
	// - a higher setting will make it go slower but the measurements
	//   will be more accurate
	// - other allowed prescale values can be found in a2d.h
	a2dSetPrescaler(ADC_PRESCALE_DIV32);

	// set the a2d reference
	// - the reference is the voltage against which a2d measurements are made
	// - other allowed reference values can be found in a2d.h
	a2dSetReference(ADC_REFERENCE_AVCC);

	// use a2dConvert8bit(channel#) to get an 8bit a2d reading
	// use a2dConvert10bit(channel#) to get a 10bit a2d reading

	while(1)
	{
		// sample all a2d channels and print them to the terminal
		vt100SetCursorPos(2,1);
		for(i=0; i<8; i++)
		{
			rprintf("Channel %d: %d   \r\n", i, a2dConvert8bit(i));
		}
		// print the sample number so far
		rprintf("Sample # : %d   \r\n", a++);
	}
	
	return 0;
}