Пример #1
0
int main(int argc, char **argv)
{
   initialize();
   initialize_TIMER0();
   clear_array();
   PORTC = 0;
   USART_send_string("Currently outputing color: \n");
   while(1){
      for(unsigned int i = 0; i < 8; ++i){
	 PORTE = i;
	 switch (state){
	    case RED:
	       //PORTE = 1;
	       update_row(224,0,0);
		checkState();
	       break;
	    case GREEN:
	       update_row(0,7,0);
	       checkState();
	       break;
	    case YELLOW:
	       led_off();
	       update_row(yellowRow,0,0);
	       update_row(yellowRow,0,0);
	       update_row(yellowRow,yellowRow,0);
	       update_row(yellowRow,0,0);
	       update_row(yellowRow,0,0);
	       led_off();
	       checkState();
	       break;
	 }
      }
   }
}	
struct motor_state* allocate_motors()
{
	int motor_array_size = sizeof(struct motor_state) * num_motors;
	motor_buf = malloc(motor_array_size);
	struct motor_state* motors = malloc(motor_array_size);
	
	if (motors == NULL || motor_buf == NULL){
		USART_send_string("Error: Could not allocate all required motor storage information. Terminating.\r\n");
		exit(1);
	} else {
		buf_dest = (unsigned char*) motor_buf + motor_array_size - 1;
		memset(motors, 0, motor_array_size);
		memset(motor_buf, 0, motor_array_size);
		USART_send_string("Motor state structures allocated!\r\n");
	}

	return motors;
}
Пример #3
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);
}