//************************************************************** // Name : DFCW_Beacon_JD1QRP_C.C * // Author : NAO JR6RMZ * // Notice : Copyright(C)2010 NAO JR6RMZ.All Rights Reserved * // Copyright for Language C : Rick Wakatori,7L1RLL * // Date : 2011/10/16 * // Version : 10.0303 * // Notes : JD1QRP and 7L1RLL/1 * // : Translated by 7L1RLL for CCS C (PCM). * // : Memory usage : ROM=28%,RAM=13%-46%,EEPROM=0% * // : BUILD SUCCEEDE Sun Oct 16 10:23:40 2011 * // Purposes: This program make AKI-PIC877A-V2 possible to * // DFCW_Beacon_Keyer. * // Usage : The program assumes additional circuit as follows;* // INPUT(Active State) OUTPUT(Active State) * // RD7: DFCW_SW(0) RB7: Dash-Lamp(0) * // RD6: 2or3dot_SW(0) RB6: Dash&Dot-Lamp(0) * // RD5: Speed 2^4(0) RB5: Dash-Lamp(0) * // RD4: Speed 2^2(0) RB4: Dot Keying(1) * // RD3: Speed 2^1(0) RB3: Not used * // RD2: MsgSW 2^4(0) RB2: Dash Keying(1) * // RD1: MsgSW 2^2(0) RB1: End-Msg-Lamp(0) * // RD0: MsgSW 2^1(0) RB0: Not used * // RC7: RX(CN-C12) RC6: TX(CN-C13) * // 877-18:MCLR(CN-C-14) //***************************************************************/ #include <../Devices/16F877A.h> // depending on environment #include <../Drivers/string.h> // depending on environment #include <../Drivers/stdlib.h> // depending on environment #use delay(crystal=20MHz) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) ////// Global Constants /////// const char constCallsign[7] = "7L1RLL"; const char constCallsign2[7] = "JD1QRP"; const char constPortable[3] = "/1"; const char constSuffix[5] = "RLL"; const char constSuffix2[5] = "QRP"; const char constEndMsg[6] = "#_$*"; const char constVVV_DE_[8] = "VVV_DE_"; const char constVVV_[5] = "VVV_"; //const char constCQ_[4] = "CQ_"; //const char constPlsTX[3] = "_K"; const char constIOTA[7] = "_AS031"; const int8 constMaxData = 25; ///// Global Variables /////// int32 dashLen=3; // dash Length <== dashLen * dotLen int32 dotLen=150; // 150ms int8 dfcw =0; // false for DFCW int32 pauseLen = 150; // pause length char dat[constMaxData]=" ";// messege storage to be sent ///// Declaration of Functions ////// void clear_output(); // clear lanps and keying out void delay_s(int32 m); // delay second void get_messege(); // select a message void get_speed_mode(); // select a speed and mode void send_message(); // send a message void send_code(char cwd,int8 n);// send CW code per character void send_dot(); // send a dot element void send_dash(); // send a dash element void main(){ set_tris_d(255); //Port D are all input set_tris_b(0); //Port B are all output while(TRUE){ // endless loop clear_output(); get_messege(); get_speed_mode(); send_message(); } } // end of main() void send_message() { const char endON='#',endOFF='$', repeat='*', pause='_'; const char c_seq[43]="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?/#$*_"; const int16 Morse[43]={ // Left Hand=Morse code(0=Make,1=Open) in Hexa representaion. // The code 0x00xx means a pause. // Right Hand=codelength or number of pause. 0xBF02,0x7F04,0x5F04,0x6F03,0x8F01, // ABCDE 0xDF04,0x2F03,0xFF04,0xCF02,0x8F04, // FGHIJ 0x5F03,0xBF04,0x3F02,0x4F02,0x1F03, // KLMNO 0x9F04,0x2F04,0xAF03,0xEF03,0x7F01, // PQRST 0xDF03,0xEF04,0x9F03,0x6F04,0x4F04, // UVWXY 0x3F04, // Z 0x0705,0x8705,0xC705,0xE705,0xF705, // 01234 0xF805,0x7F05,0x3F05,0x1F05,0x0F05, // 56789 0x3306,0x6F05,0x0000,0x0000,0x0000, // ?/#$* 0x0001}; // _ int8 d=0, i=0, k=0,lengDat=0, n=0; int16 ad=0, mc=0; char cwd=0x00, c[2]=" ", seq[43]; strcpy(seq,c_seq); // convert to string lengDat=strlen(dat); strncpy(c,dat,1); // pick a character in the c while ((c[0]!=0) && (k<=constMaxData) && (k<=lengDat)) { d=*c; // get a character from the pointer if (k==lengDat){ puts(""); return; } switch (d){ case endON : output_low(PIN_B1); // on end-messege-lamp putc('#'); break; case endOff: output_high(PIN_B1); // off end-messege-lamp putc('$'); break; case repeat: puts("*"); //delay_s(dotLen*dashLen); return; case pause : putc('-'); delay_s(dotLen*dashLen); // pause break; default : putc(d); ad=strcspn(seq,c); // Collarative seq. mc=Morse[ad]; // get Morse word cwd=(0xFF00 & mc) >> 8; // Morse code n=(0x00FF & mc); // code length send_code(cwd,n); break; } delay_s(dotLen*dashLen); // pause between two characters k++; for(i=0;i<=7;i++){ rotate_right(dat,constMaxData); // shift to next character } strncpy(c,dat,1); // pick a next character in the c } // while } // end of send_message() void delay_s(int32 m) // support longer than int16 { int8 i = 0; int32 n = 0; if (m < 1000) delay_ms(m); else { n = m / 1000; for (i = 0; i < n; i++) delay_ms(1000); } } // end of delay_s void clear_output() { const char clear = 0b11101011; // bit76543210 output_b(clear); // all outputlines to zero } // end of clear_output() void send_dot() { const char dot_DFCW = 0b10111011; // bit76543210 const char dot_QRSS_CW = 0b10111111; if (dfcw == 0) // QRSS or CW output_b(dot_QRSS_CW); // send a dot for QRSS or CW else // DFCW output_b(dot_DFCW); // send a dot for DFCW delay_s(dotLen); // dot length clear_output(); // end of a dot delay_s(pauseLen); // pause } // end of send_dot() void send_dash() { const char dash = 0b00011111; // bit76543210 output_b(dash); // send a dash delay_s(dashLen*dotLen);// dash length clear_output(); delay_s(pauseLen); // pause } // send_dash() void send_code(char cwd,int8 n) { int8 i; for (i=0;i<=n-1;i++){ if ((cwd & 0x0080) != 0) send_dot(); // dot else send_dash(); // dash cwd <<= 1; // shift cwd 1 bit left } } // end of send_code() void get_messege() { // Selection of message char callsign[7]; char callsign2[7]; char portable[5]; char suffix[4]; char suffix2[4]; char endMsg[6]; char VVV_DE_[8]; char VVV_[5]; //char CQ_[4]; //char plsTX[3]; char iota[7]; int8 msgSW=0; strcpy(dat, " "); strcpy(callsign, constCallsign); strcpy(callsign2, constCallsign2); strcpy(portable, constPortable); strcpy(suffix, constSuffix); strcpy(suffix2, constSuffix2); strcpy(endMsg, constEndMsg); strcpy(VVV_DE_, constVVV_DE_); strcpy(VVV_, constVVV_); //strcpy(CQ_, constCQ_); //strcpy(plsTX, constPlsTX); strcpy(iota, constIOTA); if (input(PIN_D0)==0) msgSW+=1; // message switch bit xx1 if (input(PIN_D1)==0) msgSW+=2; // message switch bit x1x if (input(PIN_D2)==0) msgSW+=4; // message switch bit 1xx switch (msgSW){ case 0: // Text #1 VVV DE callsign strcpy(dat,VVV_DE_); strcat(dat,callsign); strcat(dat,endMsg); break; case 1: // Text #2 VVV callsign strcpy(dat,VVV_); strcat(dat,callsign); strcat(dat,endMsg); break; case 2: // Text #3 callsign strcpy(dat,callsign); strcat(dat,endMsg); break; case 3: // Text #4 suffix strcpy(dat,suffix); strcat(dat,endMsg); break; case 4: // Text #5 callsign/portable strcpy(dat,callsign); strcat(dat,portable); strcat(dat,endMsg); break; case 5: // Text #6 callsign2/IOTA strcpy(dat,callsign2); strcat(dat,iota); strcat(dat,endMsg); break; case 6: // Text #7 callsign2 strcpy(dat,callsign2); strcat(dat,endMsg); break; case 7: // Text #8 suffix2 strcpy(dat,suffix2); strcat(dat,endMsg); break; default: // "VVV" "DE" callsign strcpy(dat,VVV_DE_); strcat(dat,callsign); strcat(dat,endMsg); break; } // end of text_switch } // end get_message() void get_speed_mode() { //--- Selection of Speed switch -------------------- int8 speedSW=0; int32 td=150; // in milli second // Scan the speed swithes(Switch: on=0,off=1) if (input(PIN_D3)==0) speedSW+=1; //xx0 where zero = on if (input(PIN_D4)==0) speedSW+=2; //x0x where zero = on if (input(PIN_D5)==0) speedSW+=4; //0xx where zero = on //speedSW=4; // debug 2011-10-11 switch (speedSW){ case 0: td = 150; break; // 0.1s case 1: td = 5000; break; // 5s case 2: td = 10000; break; // 10s case 3: td = 20000; break; // 20s case 4: td = 30000; break; // 30s case 5: td = 60000; break; // 60s case 6: td = 90000; break; // 90s case 7: td = 120000; break; // 120s default: td = 150; // same as case 0 } // end of speed switch selection if (td < 1000){ // CW dotLen=td; dashLen=3; pauseLen=dotLen; dfcw=0; // 150ms } else { // QRSS or DFCW dotLen = td; // from td=1000 to td=120000 // Getting DFCW-SW if (input(PIN_D7)==0) { //DFCW SW on dfcw = -1; // DFCW ON dashLen = 1; // dash length is same as dot length for DFCW pauseLen = (dotLen / 2); } else { // QRSS dfcw = 0; if (input(PIN_D6)==0) { // 2or3dot_SW on dashLen = 3; pauseLen = dotLen; } else { dashLen = 2; // short dash for QRSS pauseLen = dotLen; } } } } // end of get_speed_mode