コード例 #1
0
// Basic command interpreter for controlling port pins
int main(void)
{
	char buf[32];
	uint8_t n;

	// set for 16 MHz clock, and turn on the LED
	CPU_PRESCALE(0);
	LED_CONFIG;
	LED_ON;

	// initialize the USB, and then wait for the host
	// to set configuration.  If the Teensy is powered
	// without a PC connected to the USB port, this 
	// will wait forever.
	usb_init();
	while (!usb_configured()) /* wait */ ;
	_delay_ms(1000);

	while (1) {
		// wait for the user to run their terminal emulator program
		// which sets DTR to indicate it is ready to receive.
		while (!(usb_serial_get_control() & USB_SERIAL_DTR)) /* wait */ ;

		// discard anything that was received prior.  Sometimes the
		// operating system or other software will send a modem
		// "AT command", which can still be buffered.
		usb_serial_flush_input();

		// print a nice welcome message
		send_str(PSTR("\r\nTeensy USB Serial Example, "
			"Simple Pin Control Shell\r\n\r\n"
			"Example Commands\r\n"
			"  B0?   Read Port B, pin 0\r\n"
			"  C2=0  Write Port C, pin 1 LOW\r\n"
			"  D6=1  Write Port D, pin 6 HIGH  (D6 is LED pin)\r\n\r\n"));

		// and then listen for commands and process them
		while (1) {
			usb_serial
			send_str(PSTR("> "));
			n = recv_str(buf, sizeof(buf));
			if (n == 255) break;
			send_str(PSTR("\r\n"));
			parse_and_execute_command(buf, n);
		}
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: h42i/atlas.gpio
// Basic command interpreter for controlling port pins
int main(void)
{
	char buf[32];
	uint8_t n;

	// set for 16 MHz clock, and turn on the LED
	CPU_PRESCALE(0);
	LED_CONFIG;
	LED_ON;

	// initialize the USB, and then wait for the host
	// to set configuration.  If the Teensy is powered
	// without a PC connected to the USB port, this 
	// will wait forever.
	usb_init();
	while (!usb_configured()) /* wait */ ;
	_delay_ms(1000);

	while (1) {
		// wait for the user to run their terminal emulator program
		// which sets DTR to indicate it is ready to receive.
		while (!(usb_serial_get_control() & USB_SERIAL_DTR)) /* wait */ ;

		// discard anything that was received prior.  Sometimes the
		// operating system or other software will send a modem
		// "AT command", which can still be buffered.
		usb_serial_flush_input();

		// and then listen for commands and process them
		while (1) {
			n = recv_str(buf, sizeof(buf));
			if (n == 255) break;
			parse_and_execute_command(buf, n);
		}
	}
}
コード例 #3
0
// Basic command interpreter for controlling port pins
int main(void)
{
	char rx_buf[8];// the buffer to store received characters
	uint8_t n = 0;  // to store the number of bytes read from the serial port
    uint8_t counter = 0; //keep count of the number of cycles in the while loop
    // coordinates of the middle of the screen
    int x=LCD_X/2; 
    int y=LCD_Y/2;

	//set clock speed to 8MhZ
    set_clock_speed(CPU_8MHz);
    
    
    //initialise LCD and ports
	Init();

	// initialize the USB, and then wait for the host
	// to set configuration.  If the Teensy is powered
	// without a PC connected to the USB port, this 
	// will wait forever.
	usb_init();
	while (!usb_configured()) /* wait */ ;
	  _delay_ms(1000);


   //keep looping until the character 'q' is received
	while (rx_buf[0]!='q') {
        counter++;
		// wait for the user to run their terminal emulator program
		// which sets DTR to indicate it is ready to receive.
		while (!(usb_serial_get_control() & USB_SERIAL_DTR)) /* wait */ ;

		// discard anything that was received prior.  Sometimes the
		// operating system or other software will send a modem
		// "AT command", which can still be buffered.
		usb_serial_flush_input();


		// and then listen for commands and process them
		while (1) {
            
            //send some characters to the other side
             //send_str(PSTR("> \n"));
            
            if (usb_serial_available())
			  n = recv_str(rx_buf, sizeof(rx_buf)); //read serial port
			else
			  break;	 
            
            
            parse_and_execute_command(rx_buf, n);
            
            
            clear_screen();
            draw_string(x-40,y,"receiving: ");
            show_screen();
            draw_char(x+20,y,rx_buf[0]);
            show_screen();
            
		}
		
	}	 
	return 0;
}