//////////////////////////////////////////////////////////////////////////////// // PGR : RTTY_EnCoder.ino // JI3BNB RTTY EnDECODER for ARDUINO UNO // 2014.09.17 v4.1 // DESIGNED FOR AMATEUR RADIO COMMUNICATION // REALTIME KEYBOARD INPUT, 5BIT-BAUDOT-CODE, 45.45baud // LCD 20x4 (UC-204) // SCHEMATIC http://k183.bake-neko.net/ji3bnb/page13.html // ** THIS PROGRAM IS IN THE PUBLIC DOMAIN ** // //////////////////////////////////////////////////////////////////////////////// // // -- BASIC SET UP AND PIN ASSIGNMENTS -- // //////////////////////////////////////////////////////////////////////////////// #include // ** NEED TO DOWNLOAD & INSTALL "TimerOne" LIBRARY ** // http://playground.arduino.cc/code/timer1 #define MARK 218 // 218 = (500000 / 2295 Hz) #define SPACE 235 // 235 = (500000 / 2125 Hz) // #define MARK 346 // 346 = (500000 / 1445 Hz) // #define SPACE 392 // 392 = (500000 / 1275 Hz) //////////////////////////////////////////////////////////////////////////////// #include // ** NEED TO DOWNLOAD & INSTALL "FlexiTimer2" LIBRARY ** // http://playground.arduino.cc/Main/FlexiTimer2 //////////////////////////////////////////////////////////////////////////////// #include // ** NEED TO DOWNLOAD & INSTALL "PS2Keyboard" LIBRARY ** // http://playground.arduino.cc/Main/PS2Keyboard PS2Keyboard keyboard; const int DataPin = 2; //IO2 = "DATA" PIN const int IRQpin = 3; //IO3 = "CLOCK" PIN (!!DO NOT CAHNGE THIS) const boolean jp106 = 0; // SELECT 0: ENGLISH/FRENCH/GERMAN KEYBOARD // SELECT 1: JAPANESE KEYBOARD 日本語キーボード //////////////////////////////////////////////////////////////////////////////// #include #include // 20x4 LCD DISPLAY (HITACHI HD44780 INTERFACE) LiquidCrystal lcd(4,5,6,7,8,9,10); // D10 : D7 // D9 : D6 // D8 : D5 // D7 : D4 // D6 : EN // D5 : R/W // D4 : RS //////////////////////////////////////////////////////////////////////////////// // YOU CAN ASSIGN 10CH MESSAGES TO EACH NUMBER KEY const char m1[] = "\rCQ CQ CQ DE F2XYZ F2XYZ F2XYZ -LOC AB12CD- PSE K "; const char m2[] = "\rQRZ? SRI PSE AGN DE F2XYZ K "; const char m3[] = "\rTNX FER CALL "; const char m4[] = "\rUR RST 599 599 599 "; const char m5[] = "\rQTH "; const char m6[] = "\rOP PAUL PAUL PAUL "; const char m7[] = "\rMY TX 100W / ANT BEAM "; const char m8[] = "\rRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRY "; const char m9[] = "\rTKS FB QSO HPE CUAGN "; const char m0[] = "\rTU GL SK.. "; const char* ms[] = {m0, m1, m2, m3, m4, m5, m6, m7, m8, m9}; //////////////////////////////////////////////////////////////////////////////// // D13 : ENCODER OUTPUT (AFSK AUDIO) //////////////////////////////////////////////////////////////////////////////// // D12 : ENCODER OUTPUT (0/5V TTL LEVEL) //////////////////////////////////////////////////////////////////////////////// // A0(=D14) : [Esc] Key INDICATOR LED // THIS INDICATOR MEANS "NOW IN <10CH MESSAGE MODE>" //////////////////////////////////////////////////////////////////////////////// // A1(=D15) : TX INDICATOR LED // AND ALSO PTT CONTROL VOLTAGE //////////////////////////////////////////////////////////////////////////////// // A4(=D18) : TX SW // CONNECT TO GND WHEN TX //////////////////////////////////////////////////////////////////////////////// // A5(=D19) : DECODER INPUT // 0/5V TTL LEVEL (NOT AUDIO SIGNAL) // EXTERNAL DEMODULATOR REQUIRED //////////////////////////////////////////////////////////////////////////////// // "BAUDOT" CODE HAS SOME TYPES OF VARIATION const boolean usFig = 1; // SELECT 0: "TONO THETA-5000E" COMPATIBLE (ALSO USED IN "MixW" SOFTWARE) // SELECT 1: "Fldigi" SOFTWARE COMPATIBLE (=USTTY, POPULARLY USED) //////////////////////////////////////////////////////////////////////////////// // DIDDLE ENABLE AND INTERVAL PERIOD const boolean ddl = 1; //ENABLE const int ddItv = 250; //INTERVAL (ms) //////////////////////////////////////////////////////////////////////////////// // SPECIAL KEY // [Esc] : GO INTO OR GO OUT OF <10CH MESSAGE MODE> //////////////////////////////////////////////////////////////////////////////// // // -- GLOBAL VARIABLES, FLAGS, COUNTERS etc -- // //////////////////////////////////////////////////////////////////////////////// boolean space; boolean shift; boolean crLf; boolean snd; boolean dsp; boolean fig; boolean fig_1; int fig_2; int ddCnt; byte tRx; byte rSq; byte ti; byte x; char ch; uint8_t baudot; uint8_t baudot_; //////////////////////////////////////////////////////////////////////////////// // // -- setup() -- // //////////////////////////////////////////////////////////////////////////////// void setup() { lcd.begin(20, 4); lcd.clear(); lcd.setCursor(0, 0); lcd.print("TERMINAL RTTY 45,45b"); delay(1000); lcd.setCursor(0,1); lcd.print("ARDUINO ATMEGA 328P"); delay(1000); lcd.setCursor(0,2); lcd.print("SOFT: JI3BNB"); delay(1000); lcd.setCursor(0,3); lcd.print("HARD: F6IDT"); delay(2000); lcd.clear(); lcd.cursor(); lcd.setCursor(0, 0); // For German Keyboard replace "French" by "German" keyboard.begin(DataPin, IRQpin, PS2Keymap_French); pinMode(12, OUTPUT); pinMode(13, OUTPUT); pinMode(14, OUTPUT); pinMode(15, OUTPUT); digitalWrite(12, 1); digitalWrite(18, 1); //INTERNAL PULL UP Timer1.initialize(); FlexiTimer2::set(1, timer2_interrupt); FlexiTimer2::start(); } //////////////////////////////////////////////////////////////////////////////// // // -- timer_interrupt -- // //////////////////////////////////////////////////////////////////////////////// //AFSK TONE GENERATOR void timer1_interrupt(void) { static boolean toggle; toggle = toggle ^ 1; digitalWrite(13, toggle); } //5BIT BAUDOT GENERATOR void timer2_interrupt(void) { static boolean bit1; static boolean bit2; static boolean bit3; static boolean bit4; static boolean bit5; if(tRx == 0 && digitalRead(18) == 0) { tRx = 1; } if(tRx == 0) { ti++; if(rSq == 0 && digitalRead(19) == 0) { rSq = 1; ti = 0; } if(rSq == 1 && ti == 10) { if(digitalRead(19) == 0) { rSq = 2; ti = 0; } else { rSq = 0; } } if(rSq == 2 && ti == 22) { bitWrite(baudot, 0, digitalRead(19)); } if(rSq == 2 && ti == 44) { bitWrite(baudot, 1, digitalRead(19)); } if(rSq == 2 && ti == 66) { bitWrite(baudot, 2, digitalRead(19)); } if(rSq == 2 && ti == 88) { bitWrite(baudot, 3, digitalRead(19)); } if(rSq == 2 && ti == 110) { bitWrite(baudot, 4, digitalRead(19)); dsp = 1; } if(rSq == 2 && ti == 135) { rSq = 0; } } if(tRx == 2) { if(ddCnt < 2000) { ddCnt++; } if(snd == 1) { if(ti == 0){ digitalWrite(12, 0); Timer1.setPeriod(SPACE); bit1 = baudot & B00001; bit2 = baudot & B00010; bit3 = baudot & B00100; bit4 = baudot & B01000; bit5 = baudot & B10000; } else if(ti == 22){ digitalWrite(12, bit1); if(bit1){Timer1.setPeriod(MARK);} else{Timer1.setPeriod(SPACE);} } else if(ti == 44){ digitalWrite(12, bit2); if(bit2){Timer1.setPeriod(MARK);} else{Timer1.setPeriod(SPACE);} } else if(ti == 66){ digitalWrite(12, bit3); if(bit3){Timer1.setPeriod(MARK);} else{Timer1.setPeriod(SPACE);} } else if(ti == 88){ digitalWrite(12, bit4); if(bit4){Timer1.setPeriod(MARK);} else{Timer1.setPeriod(SPACE);} } else if(ti == 110){ digitalWrite(12, bit5); if(bit5){Timer1.setPeriod(MARK);} else{Timer1.setPeriod(SPACE);} } else if(ti == 132){ digitalWrite(12, 1); Timer1.setPeriod(MARK); } else if(ti == 165){ snd = 0; } ti++; } } } //////////////////////////////////////////////////////////////////////////////// // // -- OTHER FUNCTIONS etc -- // //////////////////////////////////////////////////////////////////////////////// //CONTROLS 20x4 LCD DISPLAY void lcdChOut() { static byte y; static char c[61]; int i; lcd.print(ch); if(y == 1){c[ x] = ch;} if(y == 2){c[20 + x] = ch;} if(y == 3){c[40 + x] = ch;} x++; if(x == 20 && y == 0){x = 0, y = 1;} if(x == 20 && y == 1){x = 0, y = 2;} if(x == 20 && y == 2){x = 0, y = 3;} if(x == 20 && y == 3) { lcd.clear(); lcd.setCursor(0, 0); for(i = 0; i < 20; i++){lcd.print(c[ i]);} lcd.setCursor(0, 1); for(i = 0; i < 20; i++){lcd.print(c[20 + i]);} lcd.setCursor(0, 2); for(i = 0; i < 20; i++){lcd.print(c[40 + i]);} x = 0, y = 3; for(i = 0; i < 20; i++){c[ i] = c[20 + i];} for(i = 0; i < 20; i++){c[20 + i] = c[40 + i];} } lcd.setCursor(x, y); } void lcdCrLf() { byte rest = (20 - x); ch = ' '; for(int i; i < rest; i++) //FILL THE LINE WITH SPACES INSTEAD OF CR&LF { lcdChOut(); } } //LOOKUP TABLE void chTableT() { if(usFig == 1) //"Fldigi" SOFTWARE COMPATIBLE { fig_2 = -1; if(ch == ' ') { baudot = B00100; //SPACE space = 1; } else if(ch == 'A'){baudot = B00011; fig_2 = 0;} else if(ch == 'B'){baudot = B11001; fig_2 = 0;} else if(ch == 'C'){baudot = B01110; fig_2 = 0;} else if(ch == 'D'){baudot = B01001; fig_2 = 0;} else if(ch == 'E'){baudot = B00001; fig_2 = 0;} else if(ch == 'F'){baudot = B01101; fig_2 = 0;} else if(ch == 'G'){baudot = B11010; fig_2 = 0;} else if(ch == 'H'){baudot = B10100; fig_2 = 0;} else if(ch == 'I'){baudot = B00110; fig_2 = 0;} else if(ch == 'J'){baudot = B01011; fig_2 = 0;} else if(ch == 'K'){baudot = B01111; fig_2 = 0;} else if(ch == 'L'){baudot = B10010; fig_2 = 0;} else if(ch == 'M'){baudot = B11100; fig_2 = 0;} else if(ch == 'N'){baudot = B01100; fig_2 = 0;} else if(ch == 'O'){baudot = B11000; fig_2 = 0;} else if(ch == 'P'){baudot = B10110; fig_2 = 0;} else if(ch == 'Q'){baudot = B10111; fig_2 = 0;} else if(ch == 'R'){baudot = B01010; fig_2 = 0;} else if(ch == 'S'){baudot = B00101; fig_2 = 0;} else if(ch == 'T'){baudot = B10000; fig_2 = 0;} else if(ch == 'U'){baudot = B00111; fig_2 = 0;} else if(ch == 'V'){baudot = B11110; fig_2 = 0;} else if(ch == 'W'){baudot = B10011; fig_2 = 0;} else if(ch == 'X'){baudot = B11101; fig_2 = 0;} else if(ch == 'Y'){baudot = B10101; fig_2 = 0;} else if(ch == 'Z'){baudot = B10001; fig_2 = 0;} else if(ch == '0'){baudot = B10110; fig_2 = 1;} else if(ch == '1'){baudot = B10111; fig_2 = 1;} else if(ch == '2'){baudot = B10011; fig_2 = 1;} else if(ch == '3'){baudot = B00001; fig_2 = 1;} else if(ch == '4'){baudot = B01010; fig_2 = 1;} else if(ch == '5'){baudot = B10000; fig_2 = 1;} else if(ch == '6'){baudot = B10101; fig_2 = 1;} else if(ch == '7'){baudot = B00111; fig_2 = 1;} else if(ch == '8'){baudot = B00110; fig_2 = 1;} else if(ch == '9'){baudot = B11000; fig_2 = 1;} else if(ch == '-'){baudot = B00011; fig_2 = 1;} else if(ch == '?'){baudot = B11001; fig_2 = 1;} else if(ch == ':'){baudot = B01110; fig_2 = 1;} else if(ch == '('){baudot = B01111; fig_2 = 1;} else if(ch == ')'){baudot = B10010; fig_2 = 1;} else if(ch == '.'){baudot = B11100; fig_2 = 1;} else if(ch == ','){baudot = B01100; fig_2 = 1;} else if(ch == '/'){baudot = B11101; fig_2 = 1;} //"Fldigi" SOFTWARE COMPATIBLE else if(ch == '$' ){baudot = B01001; fig_2 = 1;} else if(ch == '\''){baudot = B01011; fig_2 = 1;} else if(ch == '!' ){baudot = B01101; fig_2 = 1;} else if(ch == '"' ){baudot = B10001; fig_2 = 1;} else if(ch == '#' ){baudot = B10100; fig_2 = 1;} else if(ch == '&' ){baudot = B11010; fig_2 = 1;} else if(ch == ';' ){baudot = B11110; fig_2 = 1;} else if(ch == '\r') { baudot = B01000; //CR crLf = 1; } else if(ch == PS2_ESC) { ////// } else { ch = ' '; baudot = B00100; //SPACE space = 1; } } else if(usFig == 0) //"TONO THETA-5000E" COMPATIBLE { fig_2 = -1; if(ch == ' ') { baudot = B00100; //SPACE space = 1; } else if(ch == 'A'){baudot = B00011; fig_2 = 0;} else if(ch == 'B'){baudot = B11001; fig_2 = 0;} else if(ch == 'C'){baudot = B01110; fig_2 = 0;} else if(ch == 'D'){baudot = B01001; fig_2 = 0;} else if(ch == 'E'){baudot = B00001; fig_2 = 0;} else if(ch == 'F'){baudot = B01101; fig_2 = 0;} else if(ch == 'G'){baudot = B11010; fig_2 = 0;} else if(ch == 'H'){baudot = B10100; fig_2 = 0;} else if(ch == 'I'){baudot = B00110; fig_2 = 0;} else if(ch == 'J'){baudot = B01011; fig_2 = 0;} else if(ch == 'K'){baudot = B01111; fig_2 = 0;} else if(ch == 'L'){baudot = B10010; fig_2 = 0;} else if(ch == 'M'){baudot = B11100; fig_2 = 0;} else if(ch == 'N'){baudot = B01100; fig_2 = 0;} else if(ch == 'O'){baudot = B11000; fig_2 = 0;} else if(ch == 'P'){baudot = B10110; fig_2 = 0;} else if(ch == 'Q'){baudot = B10111; fig_2 = 0;} else if(ch == 'R'){baudot = B01010; fig_2 = 0;} else if(ch == 'S'){baudot = B00101; fig_2 = 0;} else if(ch == 'T'){baudot = B10000; fig_2 = 0;} else if(ch == 'U'){baudot = B00111; fig_2 = 0;} else if(ch == 'V'){baudot = B11110; fig_2 = 0;} else if(ch == 'W'){baudot = B10011; fig_2 = 0;} else if(ch == 'X'){baudot = B11101; fig_2 = 0;} else if(ch == 'Y'){baudot = B10101; fig_2 = 0;} else if(ch == 'Z'){baudot = B10001; fig_2 = 0;} else if(ch == '0'){baudot = B10110; fig_2 = 1;} else if(ch == '1'){baudot = B10111; fig_2 = 1;} else if(ch == '2'){baudot = B10011; fig_2 = 1;} else if(ch == '3'){baudot = B00001; fig_2 = 1;} else if(ch == '4'){baudot = B01010; fig_2 = 1;} else if(ch == '5'){baudot = B10000; fig_2 = 1;} else if(ch == '6'){baudot = B10101; fig_2 = 1;} else if(ch == '7'){baudot = B00111; fig_2 = 1;} else if(ch == '8'){baudot = B00110; fig_2 = 1;} else if(ch == '9'){baudot = B11000; fig_2 = 1;} else if(ch == '-'){baudot = B00011; fig_2 = 1;} else if(ch == '?'){baudot = B11001; fig_2 = 1;} else if(ch == ':'){baudot = B01110; fig_2 = 1;} else if(ch == '('){baudot = B01111; fig_2 = 1;} else if(ch == ')'){baudot = B10010; fig_2 = 1;} else if(ch == '.'){baudot = B11100; fig_2 = 1;} else if(ch == ','){baudot = B01100; fig_2 = 1;} else if(ch == '/'){baudot = B11101; fig_2 = 1;} //"TONO THETA-5000E" COMPATIBLE else if(ch == '\''){baudot = B00101; fig_2 = 1;} else if(ch == '$' ){baudot = B01001; fig_2 = 1;} else if(ch == '!' ){baudot = B01101; fig_2 = 1;} else if(ch == '+' ){baudot = B10001; fig_2 = 1;} else if(ch == '#' ){baudot = B10100; fig_2 = 1;} else if(ch == '&' ){baudot = B11010; fig_2 = 1;} else if(ch == '=' ){baudot = B11110; fig_2 = 1;} else if(ch == '\r') { baudot = B01000; //CR crLf = 1; } else if(ch == PS2_ESC) { ////// } else { ch = ' '; baudot = B00100; //SPACE space = 1; } } } void chConvt() { if(jp106 == 1) //JP106 KEYBOARD { if(ch == '@' ){ch = '"' ;} else if(ch == '^' ){ch = '&' ;} else if(ch == '&' ){ch = '\'';} else if(ch == '*' ){ch = '(' ;} else if(ch == '(' ){ch = ')' ;} else if(ch == ')' ){ch = '~' ;} else if(ch == '_' ){ch = '=' ;} else if(ch == '=' ){ch = '^' ;} else if(ch == '+' ){ch = '\0';} else if(ch == '[' ){ch = '@' ;} else if(ch == '{' ){ch = '`' ;} else if(ch == ']' ){ch = '[' ;} else if(ch == '}' ){ch = '{' ;} else if(ch == ':' ){ch = '+' ;} else if(ch == '\''){ch = ':' ;} else if(ch == '"' ){ch = '*' ;} else if(ch == '\\'){ch = ']' ;} else if(ch == '|' ){ch = '}' ;} } if(usFig == 1) //"Fldigi" SOFTWARE COMPATIBLE { if(ch >= 97 && ch <= 122) //CONVERT LOWER CASE TO UPPER CASE { ch = ch - 32; } else if(ch == PS2_TAB ){ch = '\0';} //IGNORE THESE KEYS else if(ch == PS2_BACKSPACE ){ch = '\0';} else if(ch == PS2_DELETE ){ch = '\0';} else if(ch == PS2_PAGEUP ){ch = '\0';} else if(ch == PS2_PAGEDOWN ){ch = '\0';} else if(ch == PS2_UPARROW ){ch = '\0';} else if(ch == PS2_LEFTARROW ){ch = '\0';} else if(ch == PS2_DOWNARROW ){ch = '\0';} else if(ch == PS2_RIGHTARROW){ch = '\0';} else if(ch == '%' ){ch = '\0';} else if(ch == '=' ){ch = '\0';} else if(ch == '^' ){ch = '\0';} else if(ch == '~' ){ch = '\0';} else if(ch == '|' ){ch = '\0';} else if(ch == '@' ){ch = '\0';} else if(ch == '`' ){ch = '\0';} else if(ch == '[' ){ch = '\0';} else if(ch == '{' ){ch = '\0';} else if(ch == '+' ){ch = '\0';} else if(ch == '*' ){ch = '\0';} else if(ch == ']' ){ch = '\0';} else if(ch == '}' ){ch = '\0';} else if(ch == '<' ){ch = '\0';} else if(ch == '>' ){ch = '\0';} else if(ch == '\\' ){ch = '\0';} else if(ch == '_' ){ch = '\0';} } else if(usFig == 0) //"TONO THETA-5000E" COMPATIBLE { if(ch >= 97 && ch <= 122) //CONVERT LOWER CASE TO UPPER CASE { ch = ch - 32; } else if(ch == PS2_TAB ){ch = '\0';} //IGNORE THESE KEYS else if(ch == PS2_BACKSPACE ){ch = '\0';} else if(ch == PS2_DELETE ){ch = '\0';} else if(ch == PS2_PAGEUP ){ch = '\0';} else if(ch == PS2_PAGEDOWN ){ch = '\0';} else if(ch == PS2_UPARROW ){ch = '\0';} else if(ch == PS2_LEFTARROW ){ch = '\0';} else if(ch == PS2_DOWNARROW ){ch = '\0';} else if(ch == PS2_RIGHTARROW){ch = '\0';} else if(ch == '"' ){ch = '\0';} else if(ch == '%' ){ch = '\0';} else if(ch == '^' ){ch = '\0';} else if(ch == '~' ){ch = '\0';} else if(ch == '|' ){ch = '\0';} else if(ch == '@' ){ch = '\0';} else if(ch == '`' ){ch = '\0';} else if(ch == '[' ){ch = '\0';} else if(ch == '{' ){ch = '\0';} else if(ch == ';' ){ch = '\0';} else if(ch == '*' ){ch = '\0';} else if(ch == ']' ){ch = '\0';} else if(ch == '}' ){ch = '\0';} else if(ch == '<' ){ch = '\0';} else if(ch == '>' ){ch = '\0';} else if(ch == '\\' ){ch = '\0';} else if(ch == '_' ){ch = '\0';} } } void chTableR() { if(usFig == 1) //"Fldigi" SOFTWARE COMPATIBLE { ch = '\0'; if(baudot == B11111){fig = 0; } //LETTERS else if(baudot == B11011){fig = 1; } //FIGURES else if(baudot == B01000){ } //CR else if(baudot == B00010){ch = ' ';} //LF else if(baudot == B00100){ch = ' ';} //SPACE if(fig == 0) { if(baudot == B00011){ch = 'A';} else if(baudot == B11001){ch = 'B';} else if(baudot == B01110){ch = 'C';} else if(baudot == B01001){ch = 'D';} else if(baudot == B00001){ch = 'E';} else if(baudot == B01101){ch = 'F';} else if(baudot == B11010){ch = 'G';} else if(baudot == B10100){ch = 'H';} else if(baudot == B00110){ch = 'I';} else if(baudot == B01011){ch = 'J';} else if(baudot == B01111){ch = 'K';} else if(baudot == B10010){ch = 'L';} else if(baudot == B11100){ch = 'M';} else if(baudot == B01100){ch = 'N';} else if(baudot == B11000){ch = 'O';} else if(baudot == B10110){ch = 'P';} else if(baudot == B10111){ch = 'Q';} else if(baudot == B01010){ch = 'R';} else if(baudot == B00101){ch = 'S';} else if(baudot == B10000){ch = 'T';} else if(baudot == B00111){ch = 'U';} else if(baudot == B11110){ch = 'V';} else if(baudot == B10011){ch = 'W';} else if(baudot == B11101){ch = 'X';} else if(baudot == B10101){ch = 'Y';} else if(baudot == B10001){ch = 'Z';} } if(fig == 1) { if(baudot == B10110){ch = '0' ;} else if(baudot == B10111){ch = '1' ;} else if(baudot == B10011){ch = '2' ;} else if(baudot == B00001){ch = '3' ;} else if(baudot == B01010){ch = '4' ;} else if(baudot == B10000){ch = '5' ;} else if(baudot == B10101){ch = '6' ;} else if(baudot == B00111){ch = '7' ;} else if(baudot == B00110){ch = '8' ;} else if(baudot == B11000){ch = '9' ;} else if(baudot == B00011){ch = '-' ;} else if(baudot == B11001){ch = '?' ;} else if(baudot == B01110){ch = ':' ;} else if(baudot == B01111){ch = '(' ;} else if(baudot == B10010){ch = ')' ;} else if(baudot == B11100){ch = '.' ;} else if(baudot == B01100){ch = ',' ;} else if(baudot == B11101){ch = '/' ;} //"Fldigi" SOFTWARE COMPATIBLE else if(baudot == B01001){ch = '$' ;} else if(baudot == B01011){ch = '\'';} else if(baudot == B01101){ch = '!' ;} else if(baudot == B10001){ch = '"' ;} else if(baudot == B10100){ch = '#' ;} else if(baudot == B11010){ch = '&' ;} else if(baudot == B11110){ch = ';' ;} else if(baudot == B00101){ } //BELL } } else if(usFig == 0) //"TONO THETA-5000E" COMPATIBLE { ch = '\0'; if(baudot == B11111){fig = 0; } //LETTERS else if(baudot == B11011){fig = 1; } //FIGURES else if(baudot == B01000){ } //CR else if(baudot == B00010){ch = ' ';} //LF else if(baudot == B00100){ch = ' ';} //SPACE if(fig == 0) { if(baudot == B00011){ch = 'A';} else if(baudot == B11001){ch = 'B';} else if(baudot == B01110){ch = 'C';} else if(baudot == B01001){ch = 'D';} else if(baudot == B00001){ch = 'E';} else if(baudot == B01101){ch = 'F';} else if(baudot == B11010){ch = 'G';} else if(baudot == B10100){ch = 'H';} else if(baudot == B00110){ch = 'I';} else if(baudot == B01011){ch = 'J';} else if(baudot == B01111){ch = 'K';} else if(baudot == B10010){ch = 'L';} else if(baudot == B11100){ch = 'M';} else if(baudot == B01100){ch = 'N';} else if(baudot == B11000){ch = 'O';} else if(baudot == B10110){ch = 'P';} else if(baudot == B10111){ch = 'Q';} else if(baudot == B01010){ch = 'R';} else if(baudot == B00101){ch = 'S';} else if(baudot == B10000){ch = 'T';} else if(baudot == B00111){ch = 'U';} else if(baudot == B11110){ch = 'V';} else if(baudot == B10011){ch = 'W';} else if(baudot == B11101){ch = 'X';} else if(baudot == B10101){ch = 'Y';} else if(baudot == B10001){ch = 'Z';} } if(fig == 1) { if(baudot == B10110){ch = '0' ;} else if(baudot == B10111){ch = '1' ;} else if(baudot == B10011){ch = '2' ;} else if(baudot == B00001){ch = '3' ;} else if(baudot == B01010){ch = '4' ;} else if(baudot == B10000){ch = '5' ;} else if(baudot == B10101){ch = '6' ;} else if(baudot == B00111){ch = '7' ;} else if(baudot == B00110){ch = '8' ;} else if(baudot == B11000){ch = '9' ;} else if(baudot == B00011){ch = '-' ;} else if(baudot == B11001){ch = '?' ;} else if(baudot == B01110){ch = ':' ;} else if(baudot == B01111){ch = '(' ;} else if(baudot == B10010){ch = ')' ;} else if(baudot == B11100){ch = '.' ;} else if(baudot == B01100){ch = ',' ;} else if(baudot == B11101){ch = '/' ;} //"TONO THETA-5000E" COMPATIBLE else if(baudot == B00101){ch = '\'';} else if(baudot == B01001){ch = '$' ;} else if(baudot == B01101){ch = '!' ;} else if(baudot == B10001){ch = '+' ;} else if(baudot == B10100){ch = '#' ;} else if(baudot == B11010){ch = '&' ;} else if(baudot == B11110){ch = '=' ;} else if(baudot == B01011){ } //BELL } } } void chFlush() { while(keyboard.available()) { ch = keyboard.read(); } } void chSend1() { if(fig_1 == 0 && fig_2 == 1) //SHIFT "UP" { baudot_ = baudot; //EVACUATE baudot = B11011; //SEND FIGURE CODE FIRST shift = 1; } else if(fig_1 == 1 && fig_2 == 0) //SHIFT "DOWN" { baudot_ = baudot; //EVACUATE baudot = B11111; //SEND LETTER CODE FIRST shift = 1; } else if(space == 1 && fig_2 == 1) //FIGURE AFTER SPACE (TX_UOS) { baudot_ = baudot; //EVACUATE baudot = B11011; //SEND FIGURE CODE FIRST shift = 1; } if(shift != 1 && crLf != 1) { lcdChOut(); } if(fig_2 == 0 || fig_2 == 1) { space = 0; fig_1 = fig_2; //REGISTER LAST STATE (EXCEPT SPACE, CR&LF) } ti = 0; snd = 1; //SEND(1) } void chSend2() { if(shift == 1) //2ND BYTE AFTER SENDING SHIFT CODE { baudot = baudot_; //RESTORE lcdChOut(); shift = 0; ti = 0; snd = 1; //SEND(2) } else if(crLf == 1) //2ND BYTE AFTER SENDING "CR" { baudot = B00010; //LF lcdCrLf(); crLf = 0; ti = 0; snd = 1; //SEND(2) } } //////////////////////////////////////////////////////////////////////////////// // // -- MAIN LOOP -- // //////////////////////////////////////////////////////////////////////////////// void loop() { static boolean esc; static int msNo = -1; static byte m; static byte n; static byte o; static char mnBuf[8]; if(tRx == 0) //RX { if(dsp == 1) { chTableR(); if(ch != '\0') { if(ch == '\r') { ///// } else if(ch == '\n') { lcdCrLf(); } else { lcdChOut(); } } dsp = 0; } } else if(tRx == 1) //RX to TX { digitalWrite(15, 1); Timer1.attachInterrupt(timer1_interrupt, MARK); delay(350); chFlush(); fig_1 = 0; snd = 0; tRx = 2; ch = '\r'; chTableT(); chSend1(); } else if(tRx == 2) //TX { if(snd == 0) { if(shift == 1 || crLf == 1) //TOP PRIORITY (WHEN 2ND BYTE IS NEEDED) { chSend2(); } else if(esc == 1 && msNo >= 0) //HANDLES FIXED MESSAGES (MAIN) { if(digitalRead(18) == 1) //CHECK SW { msNo = -1; n = 0; goto exitTx; } ch = ms[msNo][m]; //READ OUT if(ch == '\0') //END OF SENTENCE { msNo = -1; if(n == 0) //NO MESSAGE-NUMBER IS STORED FROM THE FIRST, EXIT { esc = 0; digitalWrite(14, 0); } } while(keyboard.available()) //ALWAYS CHECK KEYBOARD { char ch2 = keyboard.read(); if(ch2 == PS2_ESC) //WHEN [Esc] IS TYPED, STOP IMMEDIATELY, AND EXIT { msNo = -1; n = 0; esc = 0; digitalWrite(14, 0); } else if(ch2 >= 48 && ch2 <= 57) //'0'-'9' { if(n < 7) { mnBuf[n] = ch2; //REGISTER ADDITIONAL MESSAGE-NUMBERS, 7 NUMBERS AT MAXIMUM n++; } } } if(msNo >= 0) //-----SEND FIXED MESSAGE----- { chTableT(); chSend1(); m++; } } else if(esc == 1 && n > 0) //COMPLETED SENDING FIXED MESSAGE, AND OTHERS STILL REMAIN { ch = mnBuf[o]; //READ OUT if(ch >= 48 && ch <= 57) //'0'-'9' { msNo = ch - 48; //SPECIFY THE NEXT m = 0; o++; } else if(ch == '\0') //THE END OF THE MESSAGE-NUMBERS, EXIT { n = 0; esc = 0; digitalWrite(14, 0); } } else if (keyboard.available()) //COMPLETED SENDING FIXED MESSAGES, AND KEYBOARD IS TYPED { if(digitalRead(18) == 1) //CHECK SW { goto exitTx; } ch = keyboard.read(); chConvt(); if(ch != '\0') { chTableT(); if(ch == PS2_ESC) //HANDLES [Esc] KEY { esc = esc ^ 1; digitalWrite(14, esc); } else { if(esc == 1) { if(ch >= 48 && ch <= 57) //'0'-'9' { msNo = ch - 48; //WHEN esc=1 AND A MESSAGE KEY IS TYPED, START SENDING A NEW ONE //--Ini m = 0; o = 0; for(int i = 0; i < 7; i++) { mnBuf[i] = '\0'; } //-- } } if(esc == 0) //-----SEND FROM KEYBOARD----- { chSend1(); } } } } else { if(digitalRead(18) == 1) //CHECK SW { exitTx: //-LABEL- delay(700); //LONG TONE digitalWrite(15, 0); //CARRIER OFF Timer1.detachInterrupt(); lcdCrLf(); esc = 0; digitalWrite(14, 0); chFlush(); rSq = 0; fig = 0; dsp = 0; tRx = 0; } else //NOTHING TO PROCESS, DIDDLE { if(ddl == 1 && ddCnt > ddItv) { baudot = B11111; //LTR(DIDDLE) fig_1 = 0; ti = 0; snd = 1; } } } } } delay(5); }