//************************************************************** // Name : QRSS_Beacon_Keyer_C.C * // Author : NAO JR6RMZ * // Notice : Copyright(c)2010 NAO JR6RMZ.All Rights Reserved * // Copyright for Language C : Rick Wakatori,7L1RLL * // Date : 2010/02/1 * // Version : 10.0202 * // Notes : VVV 7L1RLL/1 * // : Translated by 7L1RLL for CCS C (PCM). * // : Memory usage : ROM=24%,RAM=11%-42%,EEPROM=0% * // : BUILD SUCCEEDE Fri May 28 18:21:53 2010 * // Purposes: This program make AKI-PIC877A-V2 possible to * // QRSS_Beacon_Keyer. * // Usage : The program assumes additional circuit as follows;* // INPUT(Active State) OUTPUT(Active State) * // RD7: Reserved RB7: Dash-Lamp(0) * // RD6: ShortDash(0) RB6: Dash&Dot-Lamp(0) * // RD5: Speed 2^4(0) RB5: Dash-Lamp(0) * // RD4: Speed 2^2(0) RB4: +Keying(1) * // RD3: Speed 2^1(0) RB3: Not used * // RD2: MsgSW 2^4(0) RB2: Not used * // 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 constPortable[3] = "/1"; const char constSuffix[5] = "RLL"; 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"; ///// Global Variables /////// int8 dashLen=3; // dash Length <== dashLen * dotLen int32 dotLen=150; // 150ms char dat[25]=""; // messege storage to be sent ///// Declaration of Functions ////// void clear_output(); void get_messege(); void get_speed(); void send_message(); void send_cw(char cwd,int8 n); void send_dot(); void send_dash(); 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(); 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=dash,1=dot) in Hexa representaion. // The code 0x00xx means a pause. // Right Hand=codelength or number of pause. 0xBF02,0x7004,0x5004,0x6003,0x8001, // ABCDE 0xD004,0x2003,0xF004,0xC002,0x8F04, // FGHIJ 0x5F03,0xB004,0x3F02,0x4002,0x1F03, // KLMNO 0x9004,0x2F04,0xA003,0xE003,0x7F01, // PQRST 0xDF03,0xEF04,0x9F03,0x6F04,0x4F04, // UVWXY 0x3004, // Z 0x0705,0x8305,0xC705,0xE705,0xF705, // 01234 0xF805,0x7805,0x3805,0x1805,0x0805, // 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) && (k<=51) && (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_ms(dotLen*dashLen); return; case pause : putc('-'); delay_ms(dotLen*6); // 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_cw(cwd,n); break; } delay_ms(dotLen*dashLen); // pause between characters k++; for(i=0;i<=7;i++){ rotate_right(dat,25); // shift to next character } strncpy(c,dat,1); // pick a next character in the c } // while } // end of send_message() void clear_output() { const char clear = 0b11101111; // bit76543210 output_b(clear); // all outputlines to zero } // end of clear_output() void send_dot() { const char dot = 0b10111111; // bit76543210 output_b(dot); // send a dot delay_ms(dotLen); // dot length clear_output(); // end of a dot delay_ms(dotLen); // pause for a dot } // end of send_dot() void send_dash() { const char dash =0b00011111; // bit76543210 output_b(dash); // send a dash delay_ms(dashLen*dotLen); // dash length clear_output(); delay_ms(dotLen); // pause a dot } // send_dash() void send_cw(char cwd,int8 n) { int8 i; for (i=0;i<=n-1;i++){ if ((cwd==0)&&(n!=0)) delay_ms(dotLen);// pause else { if ((cwd & 0x80) != 0) send_dot(); // dot else send_dash(); // dash cwd <<=1; // shift cwd left 1 bit } } } // end of send_cw() void get_messege() { // Selection of message char callsign[7]; char portable[5]; char suffix[4]; char endMsg[6]; char VVV_DE_[8]; char VVV_[5]; char CQ_[4]; char plsTX[3]; int8 msgSW=0; strcpy(dat, ""); strcpy(callsign, constCallsign); strcpy(portable, constPortable); strcpy(suffix, constSuffix); strcpy(endMsg, constEndMsg); strcpy(VVV_DE_, constVVV_DE_); strcpy(VVV_, constVVV_); strcpy(CQ_, constCQ_); strcpy(plsTX, constPlsTX); if (input(PIN_D0)==0) msgSW+=1; // switch bit xx1 if (input(PIN_D1)==0) msgSW+=2; // switch bit x1x if (input(PIN_D2)==0) msgSW+=4; // switch bit 1xx switch (msgSW){ case 0: // Text #1 VVV DE calls 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 VVV callsign/portable strcpy(dat,VVV_); strcat(dat,callsign); strcat(dat,portable); strcat(dat,endMsg); break; case 5: // Text #6 callsign/portable strcpy(dat,callsign); strcat(dat,portable); strcat(dat,endMsg); break; case 6: // Text #7 CQ callsign strcpy(dat,CQ_); strcat(dat,callsign); strcat(dat,endMsg); break; case 7: // Text #8 CQ callsign K strcpy(dat,CQ_); strcat(dat,callsign); strcat(dat,plsTX); 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() { //--- Selection of Speed switch -------------------- int8 speedSW=0, qrss=0; int16 td=150; // 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 switch (speedSW){ case 0: qrss=0; td=150; break; // 0.1s case 1: qrss=1; td=1000; break; // 1s case 2: qrss=3; td=1000; break; // 3s case 3: qrss=10; td=1000; break; // 10s case 4: qrss=30; td=1000; break; // 30s case 5: qrss=60; td=1000; break; // 60s case 6: qrss=90; td=1000; break; // 90s case 7: qrss=120; td=1000; break; // 120s default: qrss=0; td=150; // same as case 0 } // end of speed switch selection if (qrss == 0) dotLen=td; // 150ms else dotLen=qrss*td; // from qrss1=1000 to qrss120=12000, // Getting short dash length if (input(PIN_D6)==0) dashLen=2; // short dash else dashLen=3; // long dash } // end of get_speed