Example #1
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;
}
Example #2
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;
}
Example #3
0
void setup() {
  uart0Init();
  uartSetBaudRate(0, 9600);
  rprintfInit(uart0SendByte);
  //rprintf("Hello.."); rprintfCRLF();
  rprintf("$Id: psp_joystick.c,v 1.1.1.1 2007/08/21 05:14:23 julian Exp $");
  vt100Init();

  sbi(DDRD, DDD4); // output PD4
  sbi(PORTD, PD4); // set it high
  cbi(DDRD, DDD5); // input PD5
  sbi(PORTD, PD5); // set it low

  cbi(DDRA, DDA0); // input (one axis)
  cbi(DDRA, DDA1); // input (the other axis)
  //cbi(DDRA, DDA2); // input
  //sbi(DDRA, DDA3); // output
  //sbi(PORTA, PA0);
  //sbi(PINA, PINA0); // set high
  //sbi(PINA, PA3);
  a2dInit();

  // 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

  // set up and enable the power pulse thing
  TCNT0 = 0x00;
  sbi(TIMSK0, TOIE0);

  sbi(DDRB, DDB3); // output on the LED
  sbi(PORTB, PB3); // turn it on
  u08 i, j;
  for(j=0; j<1; j++) {
  for(i=0; i<10; i++) {
  	_delay_ms(32);
  }
  cbi(PORTB, PB3);
  for(i=0; i<10; i++) {
  	_delay_ms(32);
  }
  sbi(PORTB, PB3);
  for(i=0; i<10; i++) {
	  _delay_ms(32);
  }
  }
  cbi(PORTB, PB3);
  sei();
}
Example #4
0
void init_peripherals()
{

	// LED
	DDRC |= (1<<2);

	// accel pins
	lis3l_init();



	// UART
	uartInit();
	uartSetBaudRate(19200);
	uartSetFrameFormat(8, 0, 1);
	rprintfInit(uartAddToTxBuffer);
	cbi(DDRB, 1);		// XBee CTS on PB1 


	// I2C
	itg3200_i2cInit(200);
	sbi(PORTC, 0);	// i2c SCL on ATmega163,323,16,32,etc
	sbi(PORTC, 1);	// i2c SDA on ATmega163,323,16,32,etc
	cbi(TWCR, TWIE); // disable interrupt
//	itg3200_i2cSetBitrate(200); // todo, check if if w ecan do 200

	// SPI
	mySpiInit();

	// a2d
	a2dInit();
	a2dSetReference(ADC_REFERENCE_256V);
	a2dSetChannel(7);
	cbi(PORTA, 7);
	cbi(DDRA, 7);
	a2dStartConvert();

	_delay_ms(50);

	// accel
	BOOL accelOkay = lis3l_Reset();
	itg3200_init();


	// switch xbee to higher baudrate
//	rprintfStr("+++");
//	_delay_ms(55);
//	rprintfStr("ATBD6,CN\r");

}
int main(void)
{
	uartInit();
	uartSetBaudRate(115200);
	rprintfInit(uartSendByte);

	a2dInit();
	timerInit();
	vt100Init();




	return 0;
}
Example #6
0
int main(void) {
	configure_ports(); 
    a2dInit();  
	a2dSetPrescaler(ADC_PRESCALE_DIV32);  
	a2dSetReference(ADC_REFERENCE_AVCC); 
    
    init_servos();
	LED_on();
    
    neutral();
    hold_pos();
    
    while (1) {
        move_forward();
    //    sustain_pos();
    }
    
	return 0;
}
Example #7
0
//----- Begin Code ------------------------------------------------------------
int main(void)
{
	uint8_t a=0;

	// initialize our libraries
	// initialize the UART (serial port)
	uartInit();
	// make all rprintf statements use uart for output
	rprintfInit(uartSendByte);
	// turn on and initialize A/D converter
	a2dInit();
	// initialize the timer system
	timerInit();
	// print a little intro message so we know things are working
	rprintf("\r\nWelcome to AVRlib!\r\n");
	
	// initialize LCD
	lcdInit();
	// direct printf output to LCD
	rprintfInit(lcdDataWrite);

	// print message on LCD
	rprintf("Welcome to AVRlib!");

	DDRA = 0x00;
	PORTA = 0x00;

	// display a bargraph of the analog voltages on a2d channels 0,1
	while(1)
	{
		lcdGotoXY(0,0);
		lcdProgressBar(a2dConvert8bit(0), 255, 20);
		rprintf(" X: %d", a2dConvert8bit(0));
		rprintf(" Sample: %d", a++);
		lcdGotoXY(0,1);
		lcdProgressBar(a2dConvert8bit(1), 255, 20);
		rprintf(" Y: %d", a2dConvert8bit(1));
	}

	return 0;
}
Example #8
0
int main (void)
{
	// initialize
	uartInit();
	timerInit();
	a2dInit();
	glcdInit();
	outb(DDRA, 0x00);
	
	// send rprintf output to serial port
	rprintfInit(uartSendByte);
	// print welcome message to serial port
	rprintfProgStrM("\r\nWelcome to glcdtest...\r\n");
	// send rprintf output to lcd display
	rprintfInit(glcdWriteChar);

	// perform basic functionality tests
	rprintfProgStrM("All initialized...");

	glcdSetAddress(4,LINE2);
	glcdWriteChar('H');
	glcdWriteChar('E');
	glcdWriteChar('L');
	glcdWriteChar('L');
	glcdWriteChar('O');

	glcdSetAddress(4,LINE3);
	rprintfProgStrM("line 3");
	glcdSetAddress(4,LINE4);
	rprintfProgStrM("line 4");
	glcdSetAddress(4,LINE5);
	rprintfProgStrM("line 5");

	// run application program
	//oscope();
	lcdtest();

	return 0;   
}
Example #9
0
int main(void)
{
    /* Voyant ON */
    DDRD |= (1<<DDD7);
    PORTD |= (1<<PD7);

    /* Voyant POWER */
    DDRB |= (1<<DDB3);
    PORTB |= (1<<PB3);
    TCCR2 = (0<<FOC2)|(1<<WGM20)|(1<<COM21)|(0<<COM20)|(1<<WGM21)|(0<<CS22)|(0<<CS21)|(1<<CS20);
    OCR2=0;


    init_uart();
    init_output();

    a2dInit(); // init analog to digital converter

//	pos=0x00; // MIN
    pos=0x7F; // MED
//	pos=0xFF; // MAX

    while (1)
    {
        //pos=a2dConvert8bit(0);
        //pos=a2dConvert8bit(0);
        pos=a2dConvert10bit(0);
        //OCR1A=(pos<<2) + MIN_WIDTH; // 1000 approx 1024
        //OCR1A=((((double) pos)*1000.0)/255.0) + MIN_WIDTH;
        OCR1A=((((double) pos)*1000.0)/1023.0) + MIN_WIDTH;
        OCR2=pos>>2; /* voyant POWER */
        rprintf("Testeur de servo en cours...Sebastien CELLES... %d\r\n",OCR2);
    };

    return 0;
}
Example #10
0
void init(void)
{
	//Make outputs low
	cbi(PWM_PORT, PWM_BIT);
	cbi(SD_PORT, PWM_BIT);
	
	//Make outputs outputs
	sbi(PWM_DDR, PWM_BIT);

	//Pull-up swithces
	sbi(ESTOP_PORT, ESTOP_BIT);
	sbi(BRAKE_PORT, BRAKE_BIT);
	
	//RGB Outputs
	sbi(RGB_DDR, RED);
	sbi(RGB_DDR, GREEN);
	sbi(RGB_DDR, BLUE);
	
	//RGB Off
	sbi(RGB_PORT, RED);
	sbi(RGB_PORT, GREEN);
	sbi(RGB_PORT, BLUE);
	
	//Initialise the ADC 
	a2dInit();
	
	//Initialise timer 1
	timer1Init();
	timer1SetPrescaler(TIMER_CLK_DIV1);
	timer1PWMInitICR(TOP_COUNT); //Enable PWM with top count
	timer1PWMAOn(); //Turn PWM on
	
	rgb(green);

	sei(); //Enable interupts
}
void setup() {

  uart0Init();
  uartSetBaudRate(0, 9600);
  rprintfInit(uart0SendByte);
  rprintf("$Id$");

  // this goes to the switch common
  sbi(DDRA, DDA0); // output on PA0
  sbi(PORTA, PA0); // take it high

  cbi(DDRA, DDA1); 
  cbi(DDRA, DDA2);
  cbi(DDRA, DDA3);
  cbi(DDRA, DDA4);
  cbi(DDRA, DDA5);

  a2dInit();
  a2dSetReference(ADC_REFERENCE_AVCC);
  a2dSetPrescaler(ADC_PRESCALE_DIV128);

  sbi(DDRB, PB3); // output for the LED
  sbi(PORTB, PB3);
 }
Example #12
0
File: Axon.c Project: abarbu/axon
int main(void)
{
  /****************INITIALIZATIONS*******************/
  //other stuff Im experimenting with for SoR
  uartInit();  // initialize the UART (serial port)
  uartSetBaudRate(0, 9600); // set UARTE speed, for Bluetooth
  uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection, up to 500k, try 115200 if it
  uartSetBaudRate(2, 57600); // set UARTH speed
  uartSetBaudRate(3, 57600); // set UARTJ speed, for Blackfin
  //G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx)

  // initialize rprintf system and configure uart1 (USB) for rprintf
  rprintfInit(uart1SendByte);

  configure_ports(); // configure which ports are analog, digital, etc.

  LED_on();

  rprintf("\r\nSystem Warming Up");

  // initialize the timer system (comment out ones you don't want)
  init_timer0(TIMER_CLK_1024);
  init_timer1(TIMER_CLK_64);
  init_timer2(TIMER2_CLK_64);
  init_timer3(TIMER_CLK_64);
  init_timer4(TIMER_CLK_64);
  init_timer5(TIMER_CLK_1024);
  //timer5Init();

  a2dInit(); // initialize analog to digital converter (ADC)
  a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
  a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

  int i = 0, j = 0;
  //let system stabelize for X time
  for(i=0;i<16;i++)
  {
    j=a2dConvert8bit(i);//read each ADC once to get it working accurately
    delay_cycles(5000); //keep LED on long enough to see Axon reseting
    rprintf(".");
  }

  LED_off();

  rprintf("Initialization Complete \r\n");

  reset_timer0();
  reset_timer1();
  reset_timer2();
  reset_timer3();
  reset_timer4();
  reset_timer5();

  while(1)
  {
    control();
    delay_cycles(100);
    //an optional small delay to prevent crazy oscillations
  }

  return 0;
}
Example #13
0
void prvSetupHardware(){

	int i, j;

	//add 1.7s delay for potential power issues
	delay_cycles(65535);
	delay_cycles(65535);
	delay_cycles(65535);
	delay_cycles(65535);
	delay_cycles(65535);
	delay_cycles(65535);
	delay_cycles(65535);
	
	

	uartInit();  // initialize the UART (serial port)
    uartSetBaudRate(0, 38400); // set UARTE speed, for Bluetooth
    uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection, up to 500k, try 115200 if it doesn't work
    uartSetBaudRate(2, 38400); // set UARTH speed
    uartSetBaudRate(3, 38400); // set UARTJ speed, for Blackfin
	//G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx)

	rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf

	configure_ports(); // configure which ports are analog, digital, etc.

	LED_on();

	//rprintf("\r\nSystem Warmed Up");

	// initialize the timer system
 	init_timer0(TIMER_CLK_1024);
// 	init_timer1(TIMER_CLK_64); // Timer 1 is initialized by FreeRTOS
 	init_timer2(TIMER2_CLK_64);
 	init_timer3(TIMER_CLK_64);
 	init_timer4(TIMER_CLK_64);
 	init_timer5(TIMER_CLK_64);

	a2dInit(); // initialize analog to digital converter (ADC)
	a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
	a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

	//let system stabelize for X time
	for(i=0;i<16;i++)
		{
		j=a2dConvert8bit(i);//read each ADC once to get it working accurately
		delay_cycles(5000); //keep LED on long enough to see Axon reseting
		rprintf(".");
		}

	LED_off();

	rprintf("Initialization Complete \r\n");

	//reset all timers to zero
	reset_timer0();
	reset_timer1();
	reset_timer2();
	reset_timer3();
	reset_timer4();
	reset_timer5();



	/********PWM Setup***********/
	prvPWMSetup();

}