//********************************************************************** /*   <モールス練習機V2> */ //********************************************************************** #define LED GPIO.F0 #define NON GPIO.F1 #define BEEP GPIO.F2 #define SW_MODE GPIO.F3 #define SW_KEY GPIO.F4 #define SW_SPEED GPIO.F5 #define DELAY_TIME (30 + (speed_flg * 10)) //********************************************************************** const char table[][8] = { "A.-", "B-...", "C-.-.", "D-..", "E.", "F..-.", "G--.", "H....", "I..", "J.---", "K-.-", "L.-..", "M--", "N-.", "O---", "P.--.", "Q--.-", "R.-.", "S...", "T-", "U..-", "V...-", "W.--", "X-..-", "Y-.--", "Z--..", "1.----", "2..---", "3...--", "4....-", "5.....", "6-....", "7--...", "8---..", "9----.", "0-----", /* "..-.-.-", ",--..--", ":---...", "?..--..", "'.----.", "--....-", "(-.--.", ")-.--.-", "/-..-.", "=-...-", "+.-.-.", "\".-..-.", "*-..-", "@.--.-." */ }; //********************************************************************** static short speed_flg; void Delay_ms_ex(int ms) { static int cnt; // for (cnt = 0; cnt < ms; cnt++) { Delay_us(1000); // if (SW_SPEED == 0) { while (SW_SPEED == 0) { Delay_ms(10); } if (speed_flg < 10) { speed_flg++; } else { speed_flg = 1; } } } } void short_beep() { Pwm_Start(); LED = 1; Delay_ms_ex(DELAY_TIME); LED = 0; Pwm_Stop(); Delay_ms_ex(DELAY_TIME); } void long_beep() { Pwm_Start(); LED = 1; Delay_ms_ex(DELAY_TIME * 3); LED = 0; Pwm_Stop(); Delay_ms_ex(DELAY_TIME); } void morse_chr(char chr) { static short cnt, i; // if (chr == ' ') { Delay_ms_ex(DELAY_TIME * 3); return; } // for (cnt = 0; cnt < 36; cnt++) { if (table[cnt][0] == chr) { for (i = 1; table[cnt][i] != 0x00; i++) { if (table[cnt][i] == '.') short_beep(); else long_beep(); } Delay_ms_ex(DELAY_TIME * 2); return; } } } void morse_str(char* str) { while (*str != 0x00) { morse_chr(*str); str++; } } //********************************************************************** void main() { static short cnt, i; static char buf[10]; static unsigned seed; // OSCCON = 0b01010000; // クロックは2Mhz CMCON0 = 0b00000111; // コンパレータを使用しない。 ANSEL = 0b00000000; // A/D変換は使用しない。 TRISIO = 0b00111000; //PWMの初期化(800Hz) Pwm_Init(800); Pwm_Change_Duty(PR2 / 2); Pwm_Stop(); // LED = 0; speed_flg = 5; // morse_str("CQ CQ DE JF3SFB PSE K"); Delay_ms(500); //乱数の種の設定 T1CON.TMR1ON = 1; while (SW_KEY == 1) { LED = 1; Delay_ms(50); LED = 0; Delay_ms(50); } T1CON.TMR1ON = 0; seed = TMR1H; seed = (seed < 8) | TMR1L; srand(seed); // while (1) { if (SW_MODE == 1) { for (cnt = 0; cnt < 5; cnt++) { i = rand() / 936; //i=0...35 buf[cnt] = table[i][0]; } buf[cnt] = 0x00; morse_str(buf); Delay_ms(1000); } else { if (SW_KEY == 0) Pwm_Start(); else Pwm_Stop(); } } } //**********************************************************************