コード例 #1
0
ファイル: serial_test.c プロジェクト: simonz05/mon-sensor
__attribute__((noreturn)) int main () {
    double c = 24.0;

    /* setup uart */
    serial_baud_4800();
    serial_mode_8n1(); 
    serial_transmitter_enable();
    stdout = &mystdout;

    pin_mode_output(XBEE);
    pin_mode_output(LED_1);

    while(1) {
        
        xbee_hibrinate_disable();
        pin_high(LED_1);

        printf("i%2.1f,", 4.0);
        printf("v%2.1f,", 12.0);
        printf("c%2.1f,", 24.0);
        printf("lux%2.1f", 3.0);
        printf(";");

        while(!serial_writeable())
            ;

        // xbee_hibrinate_enable();
        pin_low(LED_1);
        _delay_ms(500);
    }
}
コード例 #2
0
ファイル: mfrc522.c プロジェクト: labitat/doorduino
void
init_mfrc522(void)
{
  pin_mode_output(MFRC522_NRSTPD);
  pin_high(MFRC522_NRSTPD);
  /* Slave select pin, high (deselected) initially. */
  pin_mode_output(MFRC522_SS);
  pin_high(MFRC522_SS);
  pin_mode_output(MFRC522_MOSI);
  pin_low(MFRC522_MOSI);
  pin_mode_input(MFRC522_MISO);
  pin_mode_output(MFRC522_SCK);
  pin_low(MFRC522_SCK);

  spi_mode_master();
  spi_enable();

  mfrc522_init();
}
コード例 #3
0
ファイル: doorduino.c プロジェクト: labitat/doorduino
int
door_main(void)
{
	serial_init(9600, 8e2);

	pin_mode_output(PIN_RFID_ENABLE);

	pin_mode_input(PIN_CLK);         /* clk             */
	pin_mode_input(PIN_DATA);        /* data            */
	pin_mode_output(PIN_GREEN_LED);  /* green led lock  */
	pin_mode_output(PIN_YELLOW_LED); /* yellow led lock */
	pin_mode_output(PIN_OPEN_LOCK);  /* open            */
	pin_mode_output(PIN_DAYMODE);    /* stay open       */
	pin_mode_output(PIN_STATUS_LED); /* yellow status   */

	pin_high(PIN_OPEN_LOCK);
	pin_high(PIN_DAYMODE);
	pin_high(PIN_GREEN_LED);
	pin_high(PIN_YELLOW_LED);

	/* trigger pin2 interrupt when the clock
	 * signal goes high */
	pin2_interrupt_mode_rising();
	pin2_interrupt_enable();

	data_reset();

	/* setup timer1 to trigger interrupt a 4 times a second */
	timer1_mode_ctc();
	timer1_compare_a_set(62499);
	timer1_clock_d64();
	timer1_interrupt_a_enable();

        softserial_init();
	pin_mode_output(PIN_RFID_ENABLE);
	pin_low(PIN_RFID_ENABLE);

        init_mfrc522();

	sleep_mode_idle();

	while (1) {
		/*
		 * sleep if no new events need to be handled
		 * while avoiding race conditions. see
		 * http://www.nongnu.org/avr-libc/user-manual/group__avr__sleep.html
		 */
		cli();
		if (events == EV_NONE && !ev_softserial) {
			sleep_enable();
			sei();
			sleep_cpu();
			sleep_disable();
			continue;
		}
		sei();

		if (events & EV_SERIAL) {
			handle_serial_input();
			continue;
		}

		if (ev_softserial) {
			handle_rfid_input();
		}

		events &= ~EV_DATA;
		if (cnt > 0 && data[cnt - 1] == 0xB4) {
			if (cnt >= 10) {
				struct sha1_context ctx;
				char digest[SHA1_DIGEST_LENGTH];

				sha1_init(&ctx);
				sha1_update(&ctx, (char *)data, 256);
				sha1_final(&ctx, digest);
				serial_print("HASH+");
				serial_hexdump(digest, SHA1_DIGEST_LENGTH);
				serial_print("\n");
			}
			data_reset();
			continue;
		}

                if (events & EV_TIME)
                {
                  char buf[20];
                  uint8_t len;

                  len = check_mfrc522(buf, sizeof(buf));
                  handle_mfr_input(buf, len);
                }

		events &= ~EV_TIME;

                /*
                  This code can be used during development, to simulate the
                  press of the '#' button 8 seconds after every idle timeout:

                if (second == 32 && cnt < 255)
                {
                  data[cnt] = 0xB4;
                  cnt++;
                  events |= EV_DATA;
                }
                */

		if (second > 10*4) {
			serial_print("ALIVE\n");
			second = 0;
			data_reset();
			continue;
		}
	}
}
コード例 #4
0
ファイル: onewire.c プロジェクト: knielsen/blipduino
static void
ow_low(void)
{
    pin_mode_output(OW_PIN);
    pin_low(OW_PIN);
}