Advertisement
Guest User

Untitled

a guest
Nov 8th, 2017
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.96 KB | None | 0 0
  1. #include <si5351.h>
  2. #include <Encoder.h>
  3. #include <MCUFRIEND_kbv.h>
  4. #include <Adafruit_GFX.h>
  5. #include <Wire.h>
  6.  
  7. //define constants for the digital inputs here
  8.  
  9. Encoder myEnc(20, 21); //setup the pins for the rotary encoder-must be interrupts!
  10.  
  11. const int encoderbutton = 22; //encoder button
  12. const int button2 = 23; //top button
  13. const int button3 = 24; //middle button
  14. const int button4 = 25; //bottom button
  15. const int MicKey = 17; //mic key switch
  16.  
  17. //define constants for the digital outputs here
  18.  
  19. const int SelectBand1 = 12; //output to band 1 relay stack
  20. const int SelectBand2 = 13; //output to band 2 relay stack
  21. const int SelectBand3 = 14; //output to band 3 relay stack
  22. const int SelectBand4 = 15; //output to band 4 relay stack
  23. const int TXenable = 16; //output to control RX/TX relay stack
  24.  
  25. //define constants for analog inputs here
  26. int PAtemp = A0; //PF0
  27. int TXPower = A1; //PF1
  28. int AGClevel = A2; //PF2
  29.  
  30. //define variables for digital inputs here
  31. int Encoderbutton = 0;
  32. int Button2 = 0;
  33. int Button3 = 0;
  34. int Button4 = 0;
  35. int MicKeybutton = 0;
  36.  
  37. //define working variables here
  38. int MenuSelect = 0;
  39. int BandSelect = 0;
  40. int ModeSelect = 0;
  41. int FilterMode = 0;
  42.  
  43. //define variables for digital outputs here
  44. int band1 = 0;
  45. int band2 = 0;
  46. int band3 = 0;
  47. int band4 = 0;
  48. int RXTX = 0;
  49.  
  50. //define variables for analog inputs here
  51. int PAtempvalue = 0;
  52. int TXPowervalue = 0;
  53. int AGClevelvalue = 0;
  54.  
  55. //invoke the display
  56. MCUFRIEND_kbv tft;
  57.  
  58. //invoke the clock generator
  59. Si5351 si5351;
  60.  
  61. //Define some colors:
  62. #define BLACK   0x0000
  63. #define BLUE    0x001F
  64. #define RED     0xF800
  65. #define GREEN   0x07E0
  66. #define CYAN    0x07FF
  67. #define MAGENTA 0xF81F
  68. #define YELLOW  0xFFE0
  69. #define WHITE   0xFFFF
  70.  
  71. //VFO setup variables and stuff
  72. volatile uint32_t vfo = 7000000L; //start freq - change to suit
  73. //volatile uint32_t LSB = 8970000L;
  74. //volatile uint32_t USB = 9000000L; //might need this later
  75. volatile uint32_t bfo = 9000000L;   //start bfo freq
  76. volatile uint32_t radix = 1000; //start step size
  77. boolean changed_f = 0;
  78. String tbfo = "LSB";
  79.  
  80. long oldPosition = -999;
  81.  
  82. void setup() {
  83.   Serial.begin(9600);
  84.   Serial.println("serial console works");
  85.  
  86.  
  87.   // setup the digital inputs here
  88.   pinMode(Encoderbutton, INPUT);
  89.   pinMode(button2, INPUT_PULLUP);
  90.   pinMode(button3, INPUT_PULLUP);
  91.   pinMode(button4, INPUT_PULLUP);
  92.   pinMode(MicKey, INPUT);
  93.   Serial.println("digital inputs setup");
  94.  
  95.   //setup the digital outputs here
  96.   pinMode(SelectBand1, OUTPUT);
  97.   pinMode(SelectBand2, OUTPUT);
  98.   pinMode(SelectBand3, OUTPUT);
  99.   pinMode(SelectBand4, OUTPUT);
  100.   pinMode(TXenable, OUTPUT);
  101.   Serial.println("digital outputs setup");
  102.  
  103.   //setup the ADC here
  104.  
  105.   //setup the analog inputs here
  106.  
  107.   //setup the display
  108.   tft.reset(); //reset the display
  109.   tft.begin(0x9341); //start up the display
  110.   tft.fillScreen(BLACK); //black out the screen so everything is on a black background
  111.   Serial.println("started the display, boss");
  112.  
  113.   //setup the Wire library
  114.   Wire.begin();
  115.  
  116.   //setup the SI5351
  117.   // Start serial and initialize the Si5351
  118.   si5351.init(SI5351_CRYSTAL_LOAD_10PF, 0, 0);
  119.   //si5351.set_correction(-388600); //correction factor defined here-test using calibration sketch first!
  120.   si5351.set_pll(SI5351_PLL_FIXED, SI5351_PLLA); // Set CLK0 to output 7 MHz with a fixed PLL frequency
  121.   si5351.set_freq(vfo, SI5351_CLK0); // Set CLK0 to output the VFO with a fixed PLL frequency
  122.   //si5351.set_freq(frequency1, 0, SI5351_CLK1); // Set CLK1 to output 20 MHz
  123.   si5351.set_freq( bfo, SI5351_CLK2); // Set CLK2 to output BFO variable-normally 9Mhz
  124.   si5351.drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA);
  125.   //si5351.drive_strength(SI5351_CLK1,SI5351_DRIVE_2MA);
  126.   si5351.drive_strength(SI5351_CLK2,SI5351_DRIVE_8MA);
  127. }
  128.  
  129.  
  130. void loop() {
  131.  
  132. Encoderbutton = digitalRead(encoderbutton);
  133. Button2 = digitalRead(button2);
  134. Button3 = digitalRead(button3);
  135. Button4 = digitalRead(button4);
  136.  
  137. //read the encoder
  138. long newPosition = myEnc.read()>>2;
  139.   if (newPosition != oldPosition) {
  140.     oldPosition = newPosition;
  141.   }
  142.  
  143. //do some buttonpresses
  144. if (Encoderbutton == LOW) {
  145.     // encoder button was pressed, increment menu position
  146.     MenuSelect++;
  147.     if (MenuSelect >= 8) {
  148.         MenuSelect = 0;
  149.     }
  150.     else (MenuSelect);
  151. }
  152. else (MenuSelect);{
  153. }
  154.  
  155. Serial.print("Menuselect is ");
  156. Serial.println(MenuSelect);
  157.  
  158. if (Button2 == LOW) {
  159.     // turn LED on:
  160.     //Serial.println("Button 2 pushed");
  161.     BandSelect++;
  162.     if (BandSelect >= 4) {
  163.         BandSelect = 0;
  164.     }
  165.         else (BandSelect);
  166. }
  167. else (BandSelect);{}
  168.  
  169. if (Button3 == LOW) {
  170.     // turn LED on:
  171.     //Serial.println("Button 3 pushed");
  172.     ModeSelect++;
  173.     if (ModeSelect > 2) {
  174.         ModeSelect = 0;
  175.     }
  176.         else (ModeSelect);
  177. }
  178. else (ModeSelect);{}
  179.  
  180.   if (Button4 == LOW) {
  181.     // turn LED on:
  182.     //Serial.println("Button 4 pushed");
  183.   } else {
  184.     // turn LED off:
  185.    // Serial.println("");
  186.   }
  187.  
  188.  
  189.   tft.setRotation(1); //landscape mode with data pins on the top and address lines on the bottom
  190.  
  191.   //Filter Indicator
  192.   tft.setCursor(6,6);
  193.   tft.setTextColor(CYAN, BLACK);
  194.   tft.setTextSize(2);
  195.   if(FilterMode == 0){  
  196.      tft.println("3Khz Filter");
  197.   }
  198.   else if(FilterMode == 1){
  199.        tft.println("6Khz Filter");
  200.   }
  201.   else{}
  202.  
  203.   //Band Indicator, display indicated band
  204.   tft.setCursor(6,25);
  205.   tft.setTextColor(CYAN, BLACK);
  206.   tft.setTextSize(2);
  207.   if(BandSelect == 0){  
  208.        tft.println("40M Band");
  209.   }
  210.   else if(BandSelect == 1){
  211.        tft.println("20M Band");
  212.   }
  213.   else if(BandSelect == 2){
  214.        tft.println("10M Band");
  215.   }
  216.   else if(BandSelect == 3){
  217.        tft.println("6M Band ");
  218.   }
  219.   else{}
  220.  
  221.  //Setup to display Mode Indication, select only one at a time
  222.   tft.setCursor(40, 180);
  223.   tft.setTextColor(CYAN,BLACK);
  224.   tft.setTextSize(3);
  225.   if(ModeSelect == 0){
  226.        tft.println("LSB");
  227.        FilterMode = 0; //select 3Khz filter
  228.   }
  229.   else if(ModeSelect == 1){
  230.        tft.println("AM ");
  231.        FilterMode = 1; //select 6Khz filter
  232.   }
  233.   else if(ModeSelect == 2){
  234.        tft.println("USB");
  235.        FilterMode = 0; //might have to change this to a "3" later to select a third filter-not sure yet. Could just move the BFO frequency, but will still need to set this to a 3
  236.   }
  237.   else{}
  238.  
  239.   //Setup Main TX Tuning Display
  240.   tft.setCursor(6, 80); //Don't get closer than "6" from the edge, it's too close.
  241.   tft.setTextColor(RED, BLACK);
  242.   tft.setTextSize(2); //text size 2 is about 3/16" tall
  243.   tft.println("TX");
  244.   tft.setCursor(60, 80);
  245.   tft.setTextColor(GREEN, BLACK);
  246.   tft.setTextSize(3); //text size 4 is about 1/4" tall
  247.   tft.println("Mhz"); //Make the "123" the Transmit Mhz tuning, "456" the Transmit khz tuning, and "789" the Transmit hz tuning later
  248.   tft.setCursor(110, 80);
  249.   tft.println("."); //seperator
  250.   tft.setCursor(128, 80);
  251.   tft.println("Khz"); //Khz tuning
  252.   tft.setCursor(180, 80);
  253.   tft.println("."); //seperator
  254.   tft.setCursor(198, 80);
  255.   tft.println("hz_"); //hz tuning
  256.   tft.setCursor(280, 80);
  257.   tft.setTextColor(YELLOW, BLACK);
  258.   tft.setTextSize(2);
  259.   tft.println("MHz");
  260.  
  261.    //Setup Main RX Tuning Display
  262.   tft.setCursor(6, 136); //Don't get closer than "6" from the edge, it's too close.
  263.   tft.setTextColor(RED, BLACK);
  264.   tft.setTextSize(2); //text size 2 is about 3/16" tall
  265.   tft.println("RX");
  266.   tft.setCursor(60, 130);
  267.   tft.setTextColor(GREEN, BLACK);
  268.   tft.setTextSize(3); //text size 4 is about 1/4" tall
  269.   tft.println("123"); //Make the "123" the Recive Mhz tuning, "456" the Recieve khz tuning, and "789" the Recieve hz tuning later
  270.   tft.setCursor(110, 130);
  271.   tft.println("."); //seperator
  272.   tft.setCursor(128, 130);
  273.   tft.println("456"); //Khz tuning
  274.   tft.setCursor(180, 130);
  275.   tft.println("."); //seperator
  276.   tft.setCursor(198, 130);
  277.   tft.println("789"); //hz tuning
  278.   tft.setCursor(280, 136);
  279.   tft.setTextColor(YELLOW, BLACK);
  280.   tft.setTextSize(2);
  281.   tft.println("MHz");
  282.   //delay(50); //slow the redraw flicker down for testing
  283.  
  284. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement