Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <JTEncode.h>
- // DDS pins:
- #define W_CLK 12
- #define FQ_UD 8
- #define DATA 10
- #define RESET 9
- // pin for PA control: 1 = TX ON ; 0 = TX OFF
- #define TXPIN 5
- // base frequency
- uint32_t frequency = 14076000;
- ///////////////////////////////////////////////////////////////////////
- #define MODE_JT65 1
- #define MODE_JT9 2
- #define MODE_WSPR 3
- #define JT65_SYMBOLTIME 372
- #define JT65_SYMLENGTH 126
- #define JT65_SYMSHIFT 2.6917
- #define JT9_SYMBOLTIME 580
- #define JT9_SYMLENGTH 85
- #define JT9_SYMSHIFT 1.736
- #define WSPR_SYMBOLTIME 682
- #define WSPR_SYMLENGTH 162
- #define WSPR_SYMSHIFT 50.33701670912
- int SYMBOLTIME=0;
- int SYMLENGTH=0;
- double SYMSHIFT=0;
- int DELAYAFTER=0;
- int freq_shift = 0;
- #define pulseHigh(pin) {digitalWrite(pin, HIGH); digitalWrite(pin, LOW); }
- void tfr_byte(byte data)
- {
- for (int i=0; i<8; i++, data>>=1) {
- digitalWrite(DATA, data & 0x01);
- pulseHigh(W_CLK);
- }
- }
- void sendFrequency(double frequency) {
- int32_t freq = frequency * 34.359738368;
- for (int b=0; b<4; b++, freq>>=8) {
- tfr_byte(freq & 0xFF);
- }
- tfr_byte(0x000);
- pulseHigh(FQ_UD);
- }
- JTEncode jtencode;
- int x=0, mode, messagelen;
- char message[15];
- uint8_t symbols[162];
- void setup() {
- pinMode(FQ_UD, OUTPUT);
- pinMode(W_CLK, OUTPUT);
- pinMode(DATA, OUTPUT);
- pinMode(RESET, OUTPUT);
- pinMode(TXPIN, OUTPUT);
- digitalWrite(TXPIN, LOW);
- pulseHigh(RESET);
- pulseHigh(W_CLK);
- pulseHigh(FQ_UD);
- Serial.begin(9600);
- }
- int serialInt() {
- int ret = 0;
- char c;
- while(1) {
- while(!Serial.available()) {}
- c = Serial.read();
- if(!(c>='0' && c<='9')) {
- return ret;
- }
- else {
- ret = ret*10 + c-'0';
- }
- }
- }
- void readSerialMessage() {
- uint8_t x=0;
- char c;
- while(1) {
- while(!Serial.available()) {}
- c = Serial.read();
- if(c == '\n' || c == '\r') {
- message[x] = 0x00;
- messagelen = x;
- return;
- }
- else {
- message[x] = c;
- x++;
- }
- }
- }
- // transmitting in JT
- void tx_jt() {
- // enable PA
- digitalWrite(TXPIN, HIGH);
- for(x=0;x<SYMLENGTH;x++) { // transmit all symbols
- sendFrequency(frequency+freq_shift+symbols[x]*SYMSHIFT);
- delay(SYMBOLTIME);
- }
- // disable PA
- digitalWrite(TXPIN, LOW);
- }
- void loop() {
- { // read mode, frequency and message from serial port
- mode = serialInt();
- Serial.print("Mode OK: ");
- Serial.println((mode==1)?"JT65":"JT9");
- readSerialMessage();
- Serial.print("Message is: ");
- Serial.println(message);
- freq_shift = serialInt();
- Serial.print("TX freq: ");
- Serial.println(frequency+freq_shift);
- }
- // load settings for chosen transmission mode, encode message and start TXing
- switch(mode) {
- case MODE_JT65:
- {
- SYMBOLTIME = JT65_SYMBOLTIME;
- SYMLENGTH = JT65_SYMLENGTH;
- SYMSHIFT = JT65_SYMSHIFT;
- jtencode.jt65_encode(message, symbols);
- tx_jt();
- break;
- }
- case MODE_JT9:
- {
- SYMBOLTIME = JT9_SYMBOLTIME;
- SYMLENGTH = JT9_SYMLENGTH;
- SYMSHIFT = JT9_SYMSHIFT;
- jtencode.jt9_encode(message, symbols);
- tx_jt();
- break;
- }
- }
- // back to base frequency
- sendFrequency(frequency);
- // restart the program
- asm volatile (" jmp 0");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement