예제 #1
0
int main (void){
	//Do setup here

	serial1_init(9600, 8, 0, 1);

	psx_init(&PORTB, PINB1, //Data (Brown)
		&PORTB, PINB0, //Clock (Blue)
		&PORTB, PINB2, //Command (Orange)
		&PORTB, PINB3); //Attention (Yellow)

	//Main program loop
	while (1){
		_delay_ms(10);

		psx_read_gamepad();
		
		/*
		serial1_write_s("0x");
		serial1_write_s(itoa(psx_stick(0), temp, 16));
		serial1_write_s(", 0x");
		serial1_write_s(itoa(psx_stick(1), temp, 16));
		serial1_write_s(", 0x");
		serial1_write_s(itoa(psx_stick(2), temp, 16));
		serial1_write_s(", 0x");
		serial1_write_s(itoa(psx_stick(3), temp, 16));
		serial1_write_s(", 0x");
		serial1_write_s(itoa(psx_stick(4), temp, 16));
		serial1_write_s(", 0x");
		serial1_write_s(itoa(psx_stick(5), temp, 16));
		serial1_write_s(", 0x");
		serial1_write_s(itoa(psx_stick(6), temp, 16));
		serial1_write_s(", 0x");
		serial1_write_s(itoa(psx_stick(7), temp, 16));
		serial1_write_s(", 0x");
		serial1_write_s(itoa(psx_stick(8), temp, 16));
		serial1_write_s(", 0x");
		serial1_write_s(itoa(psx_stick(9), temp, 16));
		serial1_write_s(", 0x");
		serial1_write_s(itoa(psx_stick(10), temp, 16));
		serial1_write_s(", 0x");
		serial1_write_s(itoa(psx_stick(11), temp, 16));
		serial1_write_s("\n\r");
		*/
		
		if (psx_button(PSB_SELECT)) serial1_write_s("Select\n\r");
		if (psx_button(PSB_L1)) serial1_write_s("Left 1\n\r");
		if (psx_button(PSB_L2)) serial1_write_s("Left 2\n\r");
		if (psx_button(PSB_L3)) serial1_write_s("Left 3\n\r");
		if (psx_button(PSB_R1)) serial1_write_s("Right 1\n\r");
		if (psx_button(PSB_R2)) serial1_write_s("Right 2\n\r");
		if (psx_button(PSB_R3)) serial1_write_s("Right 3\n\r");
		if (psx_button(PSB_START)) serial1_write_s("Start\n\r");
		if (psx_button(PSB_PAD_UP)) serial1_write_s("Pad Up\n\r");
		if (psx_button(PSB_PAD_LEFT)) serial1_write_s("Pad Left\n\r");
		if (psx_button(PSB_PAD_DOWN)) serial1_write_s("Pad Down\n\r");
		if (psx_button(PSB_PAD_RIGHT)) serial1_write_s("Pad Right\n\r");
		if (psx_button(PSB_TRIANGLE)) serial1_write_s("Triangle\n\r");
		if (psx_button(PSB_CIRCLE)) serial1_write_s("Circle\n\r");
		if (psx_button(PSB_CROSS)) serial1_write_s("Cross\n\r");
		if (psx_button(PSB_SQUARE)) serial1_write_s("Square\n\r");

		if (psx_stick(PSS_LX) != last_LX){
			last_LX = psx_stick(PSS_LX);
			serial1_write_s("LX: ");
			serial1_write_s(itoa(last_LX, temp, 16));
			serial1_write_s("\n\r");
		}
		if (psx_stick(PSS_LY) != last_LY){
			last_LY = psx_stick(PSS_LY);
			serial1_write_s("LY: ");
			serial1_write_s(itoa(last_LY, temp, 16));
			serial1_write_s("\n\r");
		}
		if (psx_stick(PSS_RX) != last_RX){
			last_RX = psx_stick(PSS_RX);
			serial1_write_s("RX: ");
			serial1_write_s(itoa(last_RX, temp, 16));
			serial1_write_s("\n\r");
		}
		if (psx_stick(PSS_RY) != last_RY){
			last_RY = psx_stick(PSS_RY);
			serial1_write_s("RY: ");
			serial1_write_s(itoa(last_RY, temp, 16));
			serial1_write_s("\n\r");
		}
	}
}
예제 #2
0
int main(void) {
	/* configure PPM output port */
	PPM_DDR |= (1<<PPM_BIT);
	PPM_PORT &= ~(1<<PPM_BIT);

	/* configure LED output port */
	LED_DDR |= (1<<LED_BIT);
	LED_PORT |= (1<<LED_BIT);

	/* configure VOL(tage) warning port */
	VOL_DDR &= ~(1<<VOL_BIT);
	VOL_PORT |= (1<<VOL_BIT); // enable pullup

	serial_init();
	serial_write_str("Serial Active\n\r");
	/* configure switches */
	sw_init();
	serial_write_str("Switches Inited\n\r");
	/* configure PS2 pad */
	serial_write_str("Activating PS2 Pad...");
	psx_init(PSX_SPI,PSX_DAT,PSX_SPI,PSX_CLK,PSX_SPI,PSX_COM,PSX_ATT,PSX_ATN);
	serial_write_str("Done\n\r");
	/* configure ADC */
	adc_init();
/*
	// configure watchfog timer to reset after 60ms 
	wdt_enable(WDTO_60MS);

	// configure timer 

	// enable CTC waveform generation (TOP == OCR1A) 
	TCCR1B |= (1<<WGM12);
	// set compare value for the stop pulse to 300µs 
	OCR1B = STOP_US;
	// set pulse width to max for now 
	OCR1A = ~0;
	// set Timer 1 to clk/8, giving us ticks of 1 µs 
	TCCR1B |= (1<<CS11);

	// Timer 2 generates overflows at 1kHz 
#if defined(TCCR2) // e.g. ATMega8 
#define TIMER2_COMP_IRQ TIMER2_COMP_vect
	TCCR2 = (1<<WGM21 | 1<<CS22);
	OCR2 = 0x7D;
	// enable compare and overflow interrupts 
	TIMSK = (1<<OCIE2 | 1<<OCIE1B | 1<<OCIE1A);
#elif defined(TCCR2A) // e.g. ATMega{8,16,32}8 
#define TIMER2_COMP_IRQ TIMER2_COMPA_vect
	TCCR2A = (1<<WGM21);
	TCCR2B = (1<<CS22);
	OCR2A = 0x7D;
	// enable compare and overflow interrupts 
	TIMSK1 = (1<<OCIE1B | 1<<OCIE1A);
	TIMSK2 = (1<<OCIE2A);
#else
#error "Unable to determine timer 2 configuration registers"
#endif

	// initialize channel data 
	start_ppm_frame();
	set_ppm(1);
	start_ppm_pulse();

	// enable interrupts 
	sei();
*/
	serial_write_str("Welcome!\n");
	while (1) {
		/* reset watchdog */
//		wdt_reset();

		/* keep sampling adc data */
//		adc_query();

		/* query switches */
//		sw_query();

		/* query PS2 Pad */
		ps2_query();

		/* prepare Datenschlag data frames */
//		ds_prepare();

		//if (psx_stick(5)>=140) serial_write_str("Over  140\r");
		//if (psx_stick(5)<=100) serial_write_str("Under 100\r");
		serial_write_str("Triangle=");
		if (psx_button(PSB_TRIANGLE)) serial_write_str("1");
		else serial_write_str("0");
		
		serial_write_str(" Square=");
		if (psx_button(PSB_SQUARE)) serial_write_str("1");
		else serial_write_str("0");
		
		serial_write_str(" Cross=");
		if (psx_button(PSB_CROSS)) serial_write_str("1");
		else serial_write_str("0");

		serial_write_str(" Circle=");
		if (psx_button(PSB_CIRCLE)) serial_write_str("1");
		else serial_write_str("0");
		serial_write_str("\r");
		/* check voltage */
		//if ((~VOL_PIN) & 1<<VOL_BIT) {
		if ((VOL_PIN) & 1<<VOL_BIT) {
			// everything OK
			//LED_PORT |= (1<<LED_BIT);
			LED_PORT &= ~(1<<LED_BIT);
		} else {
			// voltage dropped, alert the user!
			if (millis/250 % 2) {
				LED_PORT |= (1<<LED_BIT);
			} else {
				LED_PORT &= ~(1<<LED_BIT);
			}

		}
	}
	return 0;
}