send.c 1014 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "io.h"
  5. #define PIN_DATA 1
  6. #define PIN_CLK 2
  7. #define PIN_ACK 0
  8. #define PIN_IN 4
  9. #define PIN_LED 3
  10. #include "bus.h"
  11. #include "timer.h"
  12. #ifndef __linux__
  13. void init_interrupt()
  14. {
  15. MCUSR = 0;
  16. wdt_disable();
  17. DDRB &= ~(1<<PB4); /* Set PB0 as input */
  18. PORTB |= (1<<PB4); /* Activate PULL UP resistor */
  19. PCMSK |= (1 << PCINT4); /* Enable PCINT0 */
  20. GIMSK |= (1 << PCIE); /* Activate interrupt on enabled PCINT7-0 */
  21. sei ();
  22. }
  23. #endif
  24. int main()
  25. {
  26. unsigned long last=0;
  27. unsigned long current_data = 0;
  28. bus_t bus;
  29. init();
  30. init_write_pin(PIN_DATA,PIN_CLK,PIN_ACK);
  31. pinMode(PIN_IN, INPUT);
  32. pinMode(PIN_LED, OUTPUT);
  33. bus_init_send(&bus, PIN_DATA, PIN_CLK, PIN_ACK);
  34. pinMode(PIN_IN, INPUT);
  35. while(1)
  36. {
  37. while(digitalRead(PIN_IN)) delay(1);
  38. while(!digitalRead(PIN_IN)) delay(1);
  39. current_data=micros()-last;
  40. if(current_data<10000) continue;
  41. last=micros();
  42. bus_write_sync(&bus, &current_data, 4);
  43. }
  44. }