Example #1
0
int
main(void)
{
	watchdog_off();
	clock_init_1MHz();

	/* set all pins to output high */
	port1_direction = 0xFF;
	port1_output = 0xFF;

	/* initialize serial clock, tx and rx parts */
	serial_init_clock();
	serial_init_tx();
	serial_init_rx();

	/* enable interrupts */
	__eint();

	pin_low(LED1);
	pin_high(LED2);

	while (1) {
		unsigned char c;

		pin_toggle(LED1);
		pin_toggle(LED2);

		c = serial_getchar();
		serial_putchar(c);
		if (c == '\r')
			serial_putchar('\n');
	}
}
Example #2
0
int
main(void)
{
	watchdog_off();
	clock_init_1MHz();

	port1_direction = 0xFC; // 1111 1011 --> p1.2 is Rx
  port2_direction = 0xFF; // 1111 1111
  port1_output   &= 0x00; // turn off motors or it'll heat up!
  port2_output   &= 0x00; // turn off motors or it'll heat up!

  delay(0xffff); // wait for initialization or something

	/* initialize serial clock, tx and rx parts */
	serial_init_clock();
	serial_init_tx();
	serial_init_rx();

	/* enable interrupts */
	__eint();

	while (1) {
	  unsigned int i;
    unsigned char c;

    c = serial_getchar();
    //debug_char(c);

    if (c == 'o') { // open
      flash();
      for (i=0; i<ROTATE_AMOUNT; i++) {
        port1_output = 0x20; // 0010 0000
        port2_output = 0x05; // 0000 0101
        delay(DELAY);
        port1_output = 0x28; // 0010 1000
        port2_output = 0x04; // 0000 0100
        delay(DELAY);
        port1_output = 0x20; // 0010 0000
        port2_output = 0x06; // 0000 0110
        delay(DELAY);
        port1_output = 0x30; // 0011 0000
        port2_output = 0x04; // 0000 0100
        delay(DELAY);
      }
      port1_output &= 0x00; // turn off motors!
      port2_output &= 0x00; // turn off motors!
    }

    else if (c == 'c') { // close
      flash();
      flash();
      for (i=0; i<ROTATE_AMOUNT; i++) {
        port1_output = 0x30; // 0011 0000
        port2_output = 0x04; // 0000 0100
        delay(DELAY);
        port1_output = 0x20; // 0010 0000
        port2_output = 0x06; // 0000 0110
        delay(DELAY);
        port1_output = 0x28; // 0010 1000
        port2_output = 0x04; // 0000 0100
        delay(DELAY);
        port1_output = 0x20; // 0010 0000
        port2_output = 0x05; // 0000 0101
        delay(DELAY);
      }
      port1_output &= 0x00; // turn off motors!
      port2_output &= 0x00; // turn off motors!
    }

	}
}