send.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #include "VirtualWire.h"
  25. void init_rf()
  26. {
  27. //vw_set_tx_pin(transmit_pin);
  28. vw_set_rx_pin(0);
  29. //vw_set_ptt_pin(transmit_en_pin);
  30. vw_set_ptt_inverted(true); // Required for DR3100
  31. vw_setup(2000); // Bits per sec
  32. //pinMode(led_pin, OUTPUT);
  33. }
  34. void send_sync(void* data, int length)
  35. {
  36. vw_send((uint8_t *)data, length);
  37. vw_wait_tx();
  38. }
  39. const int led_pin = 11;
  40. const int transmit_pin = 0;
  41. const int receive_pin = 2;
  42. const int transmit_en_pin = 3;
  43. int count = 1;
  44. int main()
  45. {
  46. /*
  47. unsigned long last=0;
  48. unsigned long current_data = 0;
  49. bus_t bus;
  50. init();
  51. init_write_pin(PIN_DATA,PIN_CLK,PIN_ACK);
  52. pinMode(PIN_IN, INPUT);
  53. pinMode(PIN_LED, OUTPUT);
  54. bus_init_send(&bus, PIN_DATA, PIN_CLK, PIN_ACK);
  55. pinMode(PIN_IN, INPUT);
  56. while(1)
  57. {
  58. while(digitalRead(PIN_IN)) delay(1);
  59. while(!digitalRead(PIN_IN)) delay(1);
  60. current_data=micros()-last;
  61. if(current_data<10000) continue;
  62. last=micros();
  63. bus_write_sync(&bus, &current_data, 4);
  64. }
  65. *
  66. char salut[10] = "Salut ";
  67. init_rf();
  68. salut[7]=3;
  69. salut[8]=4;
  70. salut[9]=5;
  71. send_sync(salut, 10);*/
  72. vw_set_tx_pin(transmit_pin);
  73. vw_set_rx_pin(receive_pin);
  74. vw_set_ptt_pin(transmit_en_pin);
  75. vw_set_ptt_inverted(true); // Required for DR3100
  76. vw_setup(2000); // Bits per sec
  77. pinMode(led_pin, OUTPUT);
  78. char msg[7] = {'h','e','l','l','o',' ','#'};
  79. msg[6] = count;
  80. digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  81. vw_send((uint8_t *)msg, 7);
  82. vw_wait_tx(); // Wait until the whole message is gone
  83. digitalWrite(led_pin, LOW);
  84. delay(1000);
  85. count = count + 1;
  86. }