send.c 978 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. void init_interrupt()
  13. {
  14. MCUSR = 0;
  15. wdt_disable();
  16. DDRB &= ~(1<<PB4); /* Set PB0 as input */
  17. PORTB |= (1<<PB4); /* Activate PULL UP resistor */
  18. PCMSK |= (1 << PCINT4); /* Enable PCINT0 */
  19. GIMSK |= (1 << PCIE); /* Activate interrupt on enabled PCINT7-0 */
  20. sei ();
  21. }
  22. int main()
  23. {
  24. unsigned long last=0;
  25. unsigned long current_data = 0;
  26. bus_t bus;
  27. init();
  28. init_write_pin(PIN_DATA,PIN_CLK,PIN_ACK);
  29. pinMode(PIN_IN, INPUT);
  30. pinMode(PIN_LED, OUTPUT);
  31. bus_init_send(&bus, PIN_DATA, PIN_CLK, PIN_ACK);
  32. pinMode(PIN_IN, INPUT);
  33. while(1)
  34. {
  35. while(digitalRead(PIN_IN)) delay(1);
  36. while(!digitalRead(PIN_IN)) delay(1);
  37. current_data=micros()-last;
  38. if(current_data<10000) continue;
  39. last=micros();
  40. bus_write_sync(&bus, &current_data, 4);
  41. }
  42. }