Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <si5351.h>
- #include <Encoder.h>
- #include <MCUFRIEND_kbv.h>
- #include <Adafruit_GFX.h>
- #include <Wire.h>
- //define constants for the digital inputs here
- Encoder myEnc(20, 21); //setup the pins for the rotary encoder-must be interrupts!
- const int encoderbutton = 22; //encoder button
- const int button2 = 23; //top button
- const int button3 = 24; //middle button
- const int button4 = 25; //bottom button
- const int MicKey = 17; //mic key switch
- //define constants for the digital outputs here
- const int SelectBand1 = 12; //output to band 1 relay stack
- const int SelectBand2 = 13; //output to band 2 relay stack
- const int SelectBand3 = 14; //output to band 3 relay stack
- const int SelectBand4 = 15; //output to band 4 relay stack
- const int TXenable = 16; //output to control RX/TX relay stack
- //define constants for analog inputs here
- int PAtemp = A0; //PF0
- int TXPower = A1; //PF1
- int AGClevel = A2; //PF2
- //define variables for digital inputs here
- int Encoderbutton = 0;
- int Button2 = 0;
- int Button3 = 0;
- int Button4 = 0;
- int MicKeybutton = 0;
- //define working variables here
- int MenuSelect = 0;
- int BandSelect = 0;
- int ModeSelect = 0;
- int FilterMode = 0;
- //define variables for digital outputs here
- int band1 = 0;
- int band2 = 0;
- int band3 = 0;
- int band4 = 0;
- int RXTX = 0;
- //define variables for analog inputs here
- int PAtempvalue = 0;
- int TXPowervalue = 0;
- int AGClevelvalue = 0;
- //invoke the display
- MCUFRIEND_kbv tft;
- //invoke the clock generator
- Si5351 si5351;
- //Define some colors:
- #define BLACK 0x0000
- #define BLUE 0x001F
- #define RED 0xF800
- #define GREEN 0x07E0
- #define CYAN 0x07FF
- #define MAGENTA 0xF81F
- #define YELLOW 0xFFE0
- #define WHITE 0xFFFF
- //VFO setup variables and stuff
- volatile uint32_t vfo = 7000000L; //start freq - change to suit
- //volatile uint32_t LSB = 8970000L;
- //volatile uint32_t USB = 9000000L; //might need this later
- volatile uint32_t bfo = 9000000L; //start bfo freq
- volatile uint32_t radix = 1000; //start step size
- boolean changed_f = 0;
- String tbfo = "LSB";
- long oldPosition = -999;
- void setup() {
- Serial.begin(9600);
- Serial.println("serial console works");
- // setup the digital inputs here
- pinMode(Encoderbutton, INPUT);
- pinMode(button2, INPUT_PULLUP);
- pinMode(button3, INPUT_PULLUP);
- pinMode(button4, INPUT_PULLUP);
- pinMode(MicKey, INPUT);
- Serial.println("digital inputs setup");
- //setup the digital outputs here
- pinMode(SelectBand1, OUTPUT);
- pinMode(SelectBand2, OUTPUT);
- pinMode(SelectBand3, OUTPUT);
- pinMode(SelectBand4, OUTPUT);
- pinMode(TXenable, OUTPUT);
- Serial.println("digital outputs setup");
- //setup the ADC here
- //setup the analog inputs here
- //setup the display
- tft.reset(); //reset the display
- tft.begin(0x9341); //start up the display
- tft.fillScreen(BLACK); //black out the screen so everything is on a black background
- Serial.println("started the display, boss");
- //setup the Wire library
- Wire.begin();
- //setup the SI5351
- // Start serial and initialize the Si5351
- si5351.init(SI5351_CRYSTAL_LOAD_10PF, 0, 0);
- //si5351.set_correction(-388600); //correction factor defined here-test using calibration sketch first!
- si5351.set_pll(SI5351_PLL_FIXED, SI5351_PLLA); // Set CLK0 to output 7 MHz with a fixed PLL frequency
- si5351.set_freq(vfo, SI5351_CLK0); // Set CLK0 to output the VFO with a fixed PLL frequency
- //si5351.set_freq(frequency1, 0, SI5351_CLK1); // Set CLK1 to output 20 MHz
- si5351.set_freq( bfo, SI5351_CLK2); // Set CLK2 to output BFO variable-normally 9Mhz
- si5351.drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA);
- //si5351.drive_strength(SI5351_CLK1,SI5351_DRIVE_2MA);
- si5351.drive_strength(SI5351_CLK2,SI5351_DRIVE_8MA);
- }
- void loop() {
- Encoderbutton = digitalRead(encoderbutton);
- Button2 = digitalRead(button2);
- Button3 = digitalRead(button3);
- Button4 = digitalRead(button4);
- //read the encoder
- long newPosition = myEnc.read()>>2;
- if (newPosition != oldPosition) {
- oldPosition = newPosition;
- }
- //do some buttonpresses
- if (Encoderbutton == LOW) {
- // encoder button was pressed, increment menu position
- MenuSelect++;
- if (MenuSelect >= 8) {
- MenuSelect = 0;
- }
- else (MenuSelect);
- }
- else (MenuSelect);{
- }
- Serial.print("Menuselect is ");
- Serial.println(MenuSelect);
- if (Button2 == LOW) {
- // turn LED on:
- //Serial.println("Button 2 pushed");
- BandSelect++;
- if (BandSelect >= 4) {
- BandSelect = 0;
- }
- else (BandSelect);
- }
- else (BandSelect);{}
- if (Button3 == LOW) {
- // turn LED on:
- //Serial.println("Button 3 pushed");
- ModeSelect++;
- if (ModeSelect > 2) {
- ModeSelect = 0;
- }
- else (ModeSelect);
- }
- else (ModeSelect);{}
- if (Button4 == LOW) {
- // turn LED on:
- //Serial.println("Button 4 pushed");
- } else {
- // turn LED off:
- // Serial.println("");
- }
- tft.setRotation(1); //landscape mode with data pins on the top and address lines on the bottom
- //Filter Indicator
- tft.setCursor(6,6);
- tft.setTextColor(CYAN, BLACK);
- tft.setTextSize(2);
- if(FilterMode == 0){
- tft.println("3Khz Filter");
- }
- else if(FilterMode == 1){
- tft.println("6Khz Filter");
- }
- else{}
- //Band Indicator, display indicated band
- tft.setCursor(6,25);
- tft.setTextColor(CYAN, BLACK);
- tft.setTextSize(2);
- if(BandSelect == 0){
- tft.println("40M Band");
- }
- else if(BandSelect == 1){
- tft.println("20M Band");
- }
- else if(BandSelect == 2){
- tft.println("10M Band");
- }
- else if(BandSelect == 3){
- tft.println("6M Band ");
- }
- else{}
- //Setup to display Mode Indication, select only one at a time
- tft.setCursor(40, 180);
- tft.setTextColor(CYAN,BLACK);
- tft.setTextSize(3);
- if(ModeSelect == 0){
- tft.println("LSB");
- FilterMode = 0; //select 3Khz filter
- }
- else if(ModeSelect == 1){
- tft.println("AM ");
- FilterMode = 1; //select 6Khz filter
- }
- else if(ModeSelect == 2){
- tft.println("USB");
- 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
- }
- else{}
- //Setup Main TX Tuning Display
- tft.setCursor(6, 80); //Don't get closer than "6" from the edge, it's too close.
- tft.setTextColor(RED, BLACK);
- tft.setTextSize(2); //text size 2 is about 3/16" tall
- tft.println("TX");
- tft.setCursor(60, 80);
- tft.setTextColor(GREEN, BLACK);
- tft.setTextSize(3); //text size 4 is about 1/4" tall
- tft.println("Mhz"); //Make the "123" the Transmit Mhz tuning, "456" the Transmit khz tuning, and "789" the Transmit hz tuning later
- tft.setCursor(110, 80);
- tft.println("."); //seperator
- tft.setCursor(128, 80);
- tft.println("Khz"); //Khz tuning
- tft.setCursor(180, 80);
- tft.println("."); //seperator
- tft.setCursor(198, 80);
- tft.println("hz_"); //hz tuning
- tft.setCursor(280, 80);
- tft.setTextColor(YELLOW, BLACK);
- tft.setTextSize(2);
- tft.println("MHz");
- //Setup Main RX Tuning Display
- tft.setCursor(6, 136); //Don't get closer than "6" from the edge, it's too close.
- tft.setTextColor(RED, BLACK);
- tft.setTextSize(2); //text size 2 is about 3/16" tall
- tft.println("RX");
- tft.setCursor(60, 130);
- tft.setTextColor(GREEN, BLACK);
- tft.setTextSize(3); //text size 4 is about 1/4" tall
- tft.println("123"); //Make the "123" the Recive Mhz tuning, "456" the Recieve khz tuning, and "789" the Recieve hz tuning later
- tft.setCursor(110, 130);
- tft.println("."); //seperator
- tft.setCursor(128, 130);
- tft.println("456"); //Khz tuning
- tft.setCursor(180, 130);
- tft.println("."); //seperator
- tft.setCursor(198, 130);
- tft.println("789"); //hz tuning
- tft.setCursor(280, 136);
- tft.setTextColor(YELLOW, BLACK);
- tft.setTextSize(2);
- tft.println("MHz");
- //delay(50); //slow the redraw flicker down for testing
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement