SHARE
TWEET

Arduino based CW beacon

a guest Apr 12th, 2012 904 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Arduino simply CW beacon
  2. // (c) 2012 Max Klimenko
  3. // emaster [at] mail.ru
  4.  
  5. // Beacon message
  6. const char message[] = "VVV CQ CQ CQ DX DE BEACON BAND 40M 8000KHZ";
  7.  
  8. // Period of single point (ms)
  9. const int point_time = 80;
  10.  
  11. // Carrier frequency divider.
  12. // Carrier freq. (MHz) = 16 / (2 * (1 + freq_div))
  13. const unsigned char freq_div = 1;
  14.  
  15. //////////////////////////////////////////////////////////////////
  16. struct s_abc
  17. {
  18.         char letter;
  19.         char sign[7];
  20. };
  21.  
  22. const s_abc abc[] = {
  23.         'A',".-", 'B',"-...", 'W',".--", 'G',"--.", 'D',"-..",
  24.         'E',".", 'V',"...-", 'Z',"--..", 'I',"..",
  25.         'J',".---", 'K',"-.-", 'L',".-..", 'M',"--", 'N',"-.",
  26.         'O',"---", 'P',".--.", 'R',".-.", 'S',"...",
  27.         'T',"-", 'U',"..-", 'F',"..-.", 'H',"....", 'C',"-.-.",
  28.         'Q',"--.-", 'Y',"-.--", 'X',"-..-", '1',".----",
  29.         '2',"..---", '3',"...--", '4',"....-", '5',".....",
  30.         '6',"-....", '7',"--...", '8',"---..", '9',"----.",
  31.         '0',"-----", '.',"......", ',',".-.-.-", ':',"---...",
  32.         ';',"-.-.-.", '(',"-.--.-", '`',".----.",
  33.         '"',".-..-.", '-',"-....-", '/',"-..-.", '?',"..--..",
  34.         '!',"--..--", '@',".--.-.", '\\',"..-.-" };
  35.  
  36. unsigned char abc_size = sizeof(abc) / sizeof(abc[0]);
  37.  
  38. void setup()
  39. {
  40.   PORTB = 0;
  41.   DDRB |= 1<<1;
  42.  
  43.   OCR1A = freq_div;
  44.   TCCR1A = 0x48;
  45.   TCCR1B = 0x09;
  46.  
  47.   pinMode(13, OUTPUT);
  48.   digitalWrite(13, HIGH);   // set the LED on
  49. }
  50.  
  51. void send_letter(char l)
  52. {
  53.   if (l == ' ')
  54.   {
  55.     delay(point_time * 7);
  56.     return;
  57.   }
  58.  
  59.   unsigned char idx = 255;
  60.   for (unsigned char i = 0; i < abc_size; i++)
  61.     if (abc[i].letter == l)
  62.     {
  63.       idx = i;
  64.       break;
  65.     }
  66.    
  67.   if (idx == 255) return;
  68.  
  69.   const char *s = abc[idx].sign;
  70.  
  71.   for (unsigned char c = 0; s[c] != 0; c++)
  72.   {
  73.     char q = s[c];
  74.    
  75.     DDRB |= 1<<1;
  76.     digitalWrite(13, HIGH);   // set the LED on
  77.    
  78.     if (q == '.') delay(point_time);
  79.     else delay(point_time * 3);
  80.    
  81.     DDRB &= ~(1<<1);
  82.     digitalWrite(13, LOW);   // set the LED off
  83.    
  84.     delay(point_time);
  85.   }
  86.  
  87.   delay(point_time * 2);
  88. }
  89.  
  90. void loop()
  91. {
  92.   for (int n = 0; message[n] != 0; n++)
  93.     send_letter(message[n]);
  94.  
  95.   delay(2000);
  96. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top