Exemple #1
0
int main(void)
{
	initIO();
	USART_init();
	sei();

	while(1)
	{
		//callAction();
		/*if(current != last)
		 {
		 USART_sendchar(current);
		 USART_sendchar('\n');

		 last = current;
		 }*/
		//USART_sendchar('\c');
		//USART_sendchar(state);
		while(packetn == 0)
			;

		USART_sendchar(packet[2]);
		current = packet[2];
		callAction();

		packetn = 0;
	}

	return 0;
}
Exemple #2
0
int main (void)
{
	TC_init();
	interrupt_init();
	USART_init();
	DDRA = 0b00000001; //set direction of PORTA, A0 is output for speaker

	
	sei();                    // turn on interrupts
	
while (1)
{	
	if( signal == 2 )//Once signaled that we have enough samples, we calculate the frequency
	{	
		duration = total / sample; //Find average duration
		freq = (unsigned int)(99990ul / (unsigned long)duration); //calculate frequency
		
		//If hit was valid, take away health from player and go into method that plays appropriate sounds
		if(freq > 200 && freq < 260){ 
			health -= 30;
			playSound(freq);
		}
	
		signal = 0;
		total = 0;
		sample = 0;
	}
}
	
	return 0;
}
Exemple #3
0
int main(void)
{
  unsigned char write_data=0x75, recv_data;
  int testn=0;
  USART_init();
  print_UART(" This is the test for TWI ");

  _delay_ms(1000);
  PORTD |= 0x80; ///turn led on
  _delay_ms(100);
  TWI_init_master();
  sei();
  print_UART(" Sending Start condition ");
  TWI_start();
  print_UART(" address= %x ", ((address<<1)|write));
  TWI_write_address((address<<1)|write);
  print_UART(" writing register = %x ", write_data);
  TWI_write_byte(write_data); //write register
  print_UART(" Repeat Start ");
  TWI_start(); //repeated start
  print_UART(" address read= %x ", ((address<<1)|read));
  TWI_write_address((address<<1)|read);
   print_UART(" read Data ");
  recv_data=TWI_read_byte(1); ///read byte and nack
  TWI_stop();
  print_UART(" This is the value of the register= %x  ", recv_data);
  PORTD &= 0x7F;
    
 
  return 0;
}
int main (void){
    uint16_t acc_val = 0;
    char acc_x_val_str[16];
    char acc_y_val_str[16];
    char acc_z_val_str[16];

    //Initialize the USART
    USART_init();
    USART_clean();

    //Init ADC
    adc_init();

    while(1) {
        acc_val = read_adc(6);
        //itoa(acc_val, acc_z_val_str, 10);
        //USART_putstring(acc_z_val_str);
        if (acc_val < 550 && acc_val > 450)
            USART_putstring("NORMAAL     \r");
        else if (acc_val < 550)
            USART_putstring("VOORWAARTS  \r");
        else if (acc_val > 450)
            USART_putstring("ACHTERWAARTS\r");
    }
}
Exemple #5
0
// main
int main(void)
{
    USART_init();
    DDRD = LED_MASK;
    char buf;
    char tmp[] = "blubjes\r\n";
    unsigned int l1 = 0;
    unsigned int l2 = 0;
    unsigned int l3 = 0;
    for (;;) {
        buf = USART_receive();
        l1++;
        l2++;
        l3++;
        if (l1 >= 20)
        {
            PORTD ^= (1 << 5);
            l1 = 0;
        }
        if (l2 >= 10)
        {
            PORTD ^= (1 << 6);
            l2 = 0;
        }
        if (l3 >= 5)
        {
            PORTD ^= (1 << 7);
            l3 = 0;
        }
        USART_putstring(tmp);
    }
    return 0;
}
Exemple #6
0
int main() {
  char ret;

  USART_init(51);

  USART_printstr("\r\n");
  USART_println("Initializing");
  USART_printstr(" SPI...");
  SPI_init();
  USART_println("done");

  USART_printstr(" SD...");
  if ((ret = SD_init())) {
    USART_printstr("error: ");
    USART_printhex(ret);
    USART_printstr("\r\n");
    return -1;
  }
  USART_println("done");

  USART_printstr(" FAT16...");
  if ((ret = FAT16_init())) {
    USART_printstr("error: ");
    USART_printhex(ret);
    USART_printstr("\r\n");
    return -1;
  }
  USART_println("done");

  return 0;
}
void init()
{
	GTCCR |= (1 << PSRSYNC);
	CPU_PRESCALE(0);

	USART_init(BAUD_RATE);
	USART_send_string("\n\nWe're online jack!\r\n");

	new_motor_state = 0;

	DDRD = 0xFF;
	PORTD = 0x50;

	sei();
	UCSR1B |= (1 << RXCIE1);
	if (UCSR1B & ~(1 << RXCIE1)){
		USART_send_string("Recieving Interrupt enabled.\r\n");
	}

	TCCR0B &= 0b11110000;
	TCCR0B |= 0b00000101;	//Max prescaling
	TCCR0A &= 0b11111100;	//Normal mode...
	OCR0A = 255;
	TIMSK0 |= 0b00000010;
	USART_send_string("Set timer to use CPU ticks, normal mode, with 255 comparison.");

}
Exemple #8
0
int main (void) {
  
  SystemCoreClockUpdate();

  USART_init(&usart, PIO0_18, PIO0_19);
  USART_begin(&usart, 9600);
  USART_puts(&usart, "Hello.\n");

  VCOM_Init();                              // VCOM Initialization

  USB_Init();                               // USB Initialization
  USB_Connect(TRUE);                        // USB Connect

  while (!USB_Configuration) ;              // wait until USB is configured

  while (1) {                               // Loop forever
    VCOM_Serial2Usb();                      // read serial port and initiate USB event
    VCOM_CheckSerialState();
	VCOM_Usb2Serial();
  } // end while											   
  
  SPI_init(&SPI0, PIO0_1, PIO0_1, PIO0_1, PIO0_2);			
	
  while ( 1 );
}
Exemple #9
0
void init(void) {

	servoInit();
	USART_init();



}
void init_all()
{
    init_io();
    init_periph();
    USART_init(UBBR_VALUE);
    init_timer1();
    set_sleep_mode(SLEEP_MODE_IDLE);
}
Exemple #11
0
int main(void) {
    USART_init(TX_COMPLETION_INTERRUPT | RX_COMPLETION_INTERRUPT, 51);
    USART_setRxCompletionInterruptListener(*rxEventListener);
    fdevopen(*USART_sendData, NULL);
    sei();
    printf("Initialized>>\n");
    while (1) {
    }
}
Exemple #12
0
void initialize(bool verbose)
{
	CPU_PRESCALE(0);

	USART_init(BAUD_RATE);
	USART_transmit('\f');	// Send form feed to clear the terminal.

	if (verbose)
		USART_send_string("WunderBoard initializing...\r\n");

	if (verbose)
		USART_send_string("\tSetting ADC prescaler and disabling free running "
				"mode...\r\n");

	setup_ADC(ADC_PRESCALER_32, FALSE);


	if (verbose)
		USART_send_string("\tEnabling ADC...\r\n");

	ADC_enable();


	if (verbose)
		USART_send_string("\tSetting ADC reference to Vcc...\r\n");

	ADC_set_reference(ADC_REF_VCC);


	// Configure IO //

	if (verbose)
		USART_send_string("\tConfiguring IO...\r\n");

	//DDRx corresponds to PORTx/PINx, dependng on direction of data flow --
	//PORT for output, PIN for input
	DDRA = 0x00;	// Buttons and switches
	DDRB = 0b11100111;	// Red enable, green enable and audio out
	DDRC = 0b11111111;	// Discrete LEDs
	DDRE = 0b01000111;	// LED Column
	DDRF = 0x00;	// Accelerometer

	// Disable pullups and set outputs low //
	PORTA = 0x00;
	PORTB = 0b00000001;
	PORTC = 0x00;
	PORTE = 0x00;
	PORTF = 0x00;


	if (verbose)
		USART_send_string("\tSetting SPI\r\n");

	//Set the SPI bus appropriately to use the LED array
	SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
}
Exemple #13
0
void init(void){
	GPIO_init();
	USART_init();
	CAN_Config();
	SysTick_init();
	accelerometer_init();
	ADC_init();
	TIM4_init();
	TIM2_init();
}
Exemple #14
0
int main(void)
{
	setupADC();	
	setupStepperMotor();
	startTimer();

	USART_init();
	
	mouse.velocity = 0;
	mouse.maxVelocity = 5000;
	mouse.acceleration = 2000;
	mouse.deceleration = 10000;

	enableDrive(1);
	turnOnTimers(1,1);
	
	for(int i = 0; i < 10; i++)
	{		
		int right = isWallRight();
		int front = isWallFront();
		int left = isWallLeft();
		
		if(!right)
		{
			rotateRight();
		}
		else if(front && !left)
		{
			rotateLeft();
		}
		else if(front)
		{
			moveBackwardsAndCorrect();
		}	
		
		if(left && right)		
			mouse.IR_CORRECT = 20;
		
		moveForwardAndStop();
		
		mouse.IR_CORRECT = 0;
		
		
	}

	
	turnOnTimers(0, 0);
	enableDrive(0);
	
	
	while(1==1)
	{

	}	
}
Exemple #15
0
int main()
{
	//free(malloc(5));
	
	USART_init();
	
	sp.init();
	
	rokenbok_interface rokinf;
	rokinf.process(sp);
}
Exemple #16
0
/* Echo program - for testing purposes */
int echo(void)
{
	/* USART initialization */
	USART_init();

	/* SPI initialization */
	SPI_init();

	/* AD9833 initialization as off */
	AD9833_init();

	/* Send word sequence to AD9833 via SPI */
	main_send_word_sequence_ad9833_uart( ad9833_words, AD9833_WORD_SEQUENCE );

	/* Infinite loop */
	for(;;)
	{
		uint32_t counter = 0;
		uint32_t delay   = 0;

		/* If all bytes were received */
		if ( data_ready != SIG_DATA_VALID ) continue;

		USART_sendbyte(reception_delay[0]);
		USART_sendbyte(reception_delay[1]);

		delay = main_get_delay( reception_delay, DELAY_BYTES );

		/* For each frequency */
		for ( ; counter < ( received_bytes - DELAY_BYTES ) / FREQUENCY_BYTES; counter++ )
		{
			double frequency;

			/* Reset word sequence */
			main_reset_word_sequence( ad9833_words, AD9833_WORD_SEQUENCE );

			/* Get received frequency */
			frequency = main_get_frequency( frequency_buffer[counter], FREQUENCY_BYTES );

			/* Create word sequence for AD9833 */
			main_create_word_sequence_ad9833( ad9833_words, AD9833_WORD_SEQUENCE, frequency );

			/* Send word sequence to AD9833 */
			main_send_word_sequence_ad9833_uart( ad9833_words, AD9833_WORD_SEQUENCE );

			/* Delay - the same for each frequency */
			delay_ms( delay );
		}
	}

	return 0;
}
Exemple #17
0
//-------------------------------------------------------------------------------------
// Function Purpose:	PartII: Send 5 messages out to putty via USART transmission.
//						Currently, only sends one message using the provided header 
//                      functions. 		
//-------------------------------------------------------------------------------------
int main(void)
{
	// Clock Variables:
	unsigned long sClk, pClk;
	cli();					// Clear Interrupts
	
	// Set up the serial clock
	SetSystemClock(CLK_SCLKSEL_RC2M_gc, CLK_PSADIV_1_gc, CLK_PSBCDIV_1_1_gc);
	GetSystemClocks(&sClk, &pClk);
	
	// Set up the timer:
	//TCC0_CTRLA = 0x04;						// Pre-scaler
	//TCC0_INTCTRLA = 0x02;						// Medium priority interrupts
	//TCC0_PER = 0xFFFF;						// Timer Period
	
	// BAUD Configurations 
	USART_init(&USARTinstance, OUTPUT_PORT, pClk,(_USART_TXCIL_LO | _USART_RXCIL_LO), 
				USART_BAUDRATE, NBSCALE_FACTOR, _USART_CHSZ_8BIT, _USART_PM_DISABLED, _USART_SM_1BIT);			
	
	// Buffer Configurations
	USART_buffer_init(&USARTinstance,160,80);						// Initialize buffer with 80 char for Tx and Rx
	USARTinstance.fInMode = _INPUT_ECHO | _INPUT_CR | _INPUT_TTY;	// Terminal Echo, Carriage Return Termination, and Keyboard Input
	USARTinstance.fOutMode = _OUTPUT_CR;							// Append Carriage Return to output
	
	USART_enable(&USARTinstance, USART_TXEN_bm | USART_RXEN_bm);		// Enable the Tx/Rx
	PMIC_CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;	// Enable low, medium, and high interrupts.

	sei();									// Enable interrupts
	
	// Port Configurations:
	PORTC_DIR |= 0x03;						
	PORTC_OUT &= 0xFE;						// Turn off PC0 to enable transceiver
	PORTC_OUT |= 0x02;						// Turn on PC1 to take transceiver out of shutdown mode
	
	// Messages to send:
	char* messages[5] = {"One\0", "Two\0", "Three\0", "Four\0", "Five\0"};
	PORTH_DIR = 0xFF;						// Used for visualizing function calls on LEDs
	
	// Test case || Attempted to send a string out to the putty console ||
	USART_send(&USARTinstance, "Testing Testing");
	while(USARTinstance.serStatus & _USART_TX_EMPTY	);		// Wait for the transmitter to be empty
	
	while(1)
	{
		// If the timer, toggled the semaphore, send a message.
		if(flag == true)
		{
			send_msg(messages[count]);
			count = (++count)%5;
		}
	}
}
Exemple #18
0
int main(void) {
  	//UART Port speed 115200  for the crystal freq. 7.3MHz
	USART_init();
	USART_transmit('O');
	USART_transmit('K');
  	init_all();
  	DDRD |= (1<<PD1); //TX for output
  	
  	DDRD &= ~(1<<PIN_315);
  	DDRB &= ~(1<<PB2); 	//PORTB for input
  	
   	while(1) {             // Infinite loop; define here the
	}
}
Exemple #19
0
int main(void){
USART_init();        //Call the USART initialization code
adc_init();
 
while(1){        //Infinite loop
 adc_value=read_adc(0);
 itoa(adc_value,buffer,10);
 USART_putstring(buffer);    //Pass the string to the USART_putstring function and sends it over the serial
 USART_send('\r');			//Carriage return
 USART_send('\n');			//Linefeed
 _delay_ms(500);
 }
 
return 0;
}
Exemple #20
0
int main (void)
{
    uint8_t command;
    
    USART_init();
    DDRC = 0xFF;
    
    while (1)   /* infinite loop */           
    {
        command = USART_get_char();

        if (command == LED_1ON)
        {
           PORTC |= _BV(PC2); 
        }  
        else if(command == LED_1OFF)
        {
           PORTC &= ~_BV(PC2);
        }
        if(command == LED_2ON)
        {
           PORTC |= _BV(PC3);
        }
        else if(command == LED_2OFF)
        {
           PORTC &= ~_BV(PC3); 
        }
        if (command == LED_3ON)
        {
           PORTC |= _BV(PC4);
        }
        else if (command == LED_3OFF)
        {
           PORTC &= ~_BV(PC4);
        }
        if (command == LED_4ON)
        {
           PORTC |= _BV(PC1);
        }
        else if (command == LED_4OFF)
        {
           PORTC &= ~_BV(PC1);
        }
        
        
}
return(0);
}
bool initialise()
{
	
	bool success = true;

	
	USART_init(USART_PC,9600);
	debug_println("Begininning Initialisation...");
	
	initTimers();
	
	if(gps_demonstration==true)
	{
		//GPS Demonstration
		altimeter_init();
		
		init_HMC5883L();
		
		
		gps_init();
		
		//Initialise a series of waypoints in a circle around the current coordinates..
		_delay_ms(1000);
		chris_waypoint_init();
	}
	else
	{
		//RX and servo Demonstration
		rx_init();
		quad_output_init();
	}
	
	
	debug_println("Initialization succeeded!");
	
	//beep some pattern I can recognize
	debug_beep_long();
	_delay_ms(250);
	debug_beep();
	_delay_ms(250);
	debug_beep();
	_delay_ms(250);
	debug_beep();
	_delay_ms(250);
	debug_beep_long();
	
	return success;
}
Exemple #22
0
//Reset and start all mouse constants and timers
void initializeMouse()
{
	setupADC();	
	setupStepperMotor();
	startTimer();
	
	USART_init();
	
	mouse.velocity = 0;
	mouse.maxVelocity = 2500;
	mouse.acceleration = 3000;
	mouse.deceleration = 12000;

	enableDrive(1);
	turnOnTimers(1,1);
}
Exemple #23
0
/**
 * This method handles the initilization of the project's hardware. Within the
 * hardware are both external and internal peripherals of the microcontroller
 *
 * @PARAM:      None
 * @PRE:        None
 * @POST:       The hardware (Modules and Peripherals) is initialized and is
 *                      ready for use.
 */
void initHardware(void){
	
	// Desactivamos las interrupciones
	cli();
	
	// Inicializamos la USART y habilitamos para transmisión y recepción
	USART_init();
	USART_EnableTx();
	USART_EnableRx();
	
	// Inicializamos y habilitamos el conversor Análogo-Digital
	ADC_Init();
	ADC_Enable();
	
	sei();
}
Exemple #24
0
void inits( void) {
	cli();
	USART_init(MYUBRR, TRUE);
	can_init();
	spi_init_master();
	fm_init();
	timer0_init();
	timer1_init();
	//TODO: RUN timer3_init();
	timer3_init();
	prepare_rx(1, ID_steeringWheel, MASK_FRONT_MODULE, fm_msg_handler);
	printf("\r\nFront module initialized");
	sei();
	set_bit(DDRB, DDB6);
	clear_bit(PORTB, PB6);
}
Exemple #25
0
int main(void){
  uint16_t v0,v1,v2;
  double t0,t1,t2;
  char t_chr[7];

  memset(t_chr, '\0', sizeof(t_chr));

  USART_init(MYUBRR);
  /* Remove garbage from serial terminal */
  USART_transmit('\r');

  ADC_init();
  PWM_init();

  while(1){
    v0 = ADC_read(0);  /* read from ADC0 */
    v1 = ADC_read(1);  /* read from ADC0 */
    v2 = ADC_read(2);  /* read from ADC0 */

    t0 = v0 / 4;
    t1 = v1 / 4;
    t2 = v2 / 4;

    dtostrf(t0, 5, 1, t_chr);
    USART_write("0: ");
    USART_write(t_chr);
    USART_write("\r\n");

    dtostrf(t1, 5, 1, t_chr);
    USART_write("1: ");
    USART_write(t_chr);
    USART_write("\r\n");

    dtostrf(t2, 5, 1, t_chr);
    USART_write("2: ");
    USART_write(t_chr);
    USART_write("\r\n");

    OCR0A = t0;
    OCR0B = t1;
    OCR2A = t2;

    _delay_ms(500);
  }

  return 1;
}
Exemple #26
0
void main(void)
{
	unsigned long sClk, pClk;
	char recieveString[100];
	
	cli(); //
	
	SetSystemClock(CLK_SCLKSEL_RC32M_gc, CLK_PSADIV_1_gc,
	CLK_PSBCDIV_1_1_gc);
	GetSystemClocks(&sClk, &pClk);
	
	/*
	* Programmable interrupt controller configuration
	*/
	PMIC_CTRL = PMIC_HILVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm; //enable all levels of interrupts
	
	PORTH_DIR = 0xFF;
	PORTQ_DIR = 0x0F; //port q lower 3 bits control access to usb and other stuff so get access with these two lines
	PORTQ_OUT = 0x07; //if using port F make this hex 5.
	/*
	* Serial set up
	*/
	//initialize the usart d0 for 57600 baud with 8 data bits, no parity, and 1 stop bit, interrupts on low (porth set to this for debugging purposes)
	USART_init(&serialStruct, 0xD0, pClk, (_USART_RXCIL_LO | _USART_TXCIL_LO), 576, -4, _USART_CHSZ_8BIT, _USART_PM_DISABLED, _USART_SM_1BIT);
	USART_buffer_init(&serialStruct, 100, 100); //initialize the circular buffers
	USART_enable(&serialStruct, USART_TXEN_bm | USART_RXEN_bm); //enable the USART
	serialStruct.fOutMode = _OUTPUT_CRLF; //append a carriage return and a line feed to every output.
	serialStruct.fInMode = _INPUT_CR | _INPUT_TTY | _INPUT_ECHO; //echo input back to the terminal and set up for keyboard input.
	
	sei();

	
		
	while(1)
	{
		//USART_send(&serialStruct, "Hey, am I working?");
		
		if(serialStruct.serStatus & _USART_RX_DONE)
		{
			USART_read(&serialStruct, recieveString);
			USART_send(&serialStruct, recieveString);
		}
		
		while (!(serialStruct.serStatus & _USART_TX_EMPTY)) { ; }
	}
}
Exemple #27
0
void main (void)
{
	USART_init();	
	USART_enable_rx_interrrupt();
	stepper_init();

	sei();

	char *ptr=0;
	while(true)
	{
		_delay_ms(1000);	
		
		stepx(300);
		stepy(200);
		stepz(STEPS_PER_SEC/4);

		ptr=USART_get_rx_buffer();

		if(ptr)
		{
			USART_transmit_string(ptr);
		}else USART_enable_rx_interrrupt();

//		USART_transmit(USART_receive());	
	/*	
		char * ptr=rxBuffer;
		uint8_t flags=0;
		uint16_t number=0;
		for(;ptr<=rxPtr;ptr++)
		{
			if(!isdigit(*ptr))
			{
				if(flags==1)break;
				continue;
			}
			flags=1;
			number=number*10+(ptr-'0');
			
			//TODO wait for new data
*/
	}
	
//		step(atoi(USART_receive())); // XXX make anything like that
}
Exemple #28
0
int main(void)
{
    OSCCONbits.IRCF = 0x0D; // INTOSC frequency 4MHz

    USART_init();

    USART_puts("Init complete!\n");

    INTCONbits.PEIE = 1;    // enable peripheral interrupts
    INTCONbits.GIE = 1;     // enable interrupts

    while(1)
    {

    }

    return 0;
}
int main(void)
{
	struct LCD_Geometry *pointCurrent= &Current;
	struct LCD_Properties *pointProperties= &Properties;
	FILE lcd_str = FDEV_SETUP_STREAM(TerminalChar, NULL, _FDEV_SETUP_RW);
	//FILE lcd_str = FDEV_SETUP_STREAM(USART_send, NULL, _FDEV_SETUP_RW);
	char *hellow = "hello";
	stdout = &lcd_str;

	USART_init();
	SPI_MasterInit();
	SSD1289_Initalize();
	

	
	testLibrary(); 

		
	//ReadBMP_ARRAY(40,40,BMP_IMAGE);
}
Exemple #30
0
int main(void)
{	
	// Activate external memory
	MCUCR |= (1 << SRE);
		
	// Initialize	
	USART_init(MYUBRR);
	joy_init();
	oled_init();
	can_init();
	menu_init();
	
	
	// Starts the FSM
	while(1)
	{
		menu_fsm();
		_delay_ms(20);
	}	
}