Jean-Marie ON4CBS wrote: > > hello > > i want to make a morsecode trainer with a pic(16f84) > > the random codes must be visual on a lcd display > speed and space must be variable > > is there anybody who worked already on this matter? > > 73 jean-marie on4cbs I haven't done it in PIC but here's a programme in PASCAL that runs on a PC and bleeps the morse thru the internal speaker. It's variable speed but only does one sentence which you type in. Hopefully it'll be good for some ideas? Regards - Ian ;**************************************** PROGRAM SendMors; { DATE : 26.12.99; AUTHOR : Ian Hynes PURPOSE : To test the Morse_Tx procedure. } TYPE String255 = STRING [255]; String80 = STRING [80]; VAR Message : String255; Flag : char; SpeedSwitch : boolean; CodeRate, TestFreq : integer; {$I ..\PASCAL\LIBPRC\Morse_Tx.PRC} BEGIN ClrScr; { Best CodeRate = 15, TestFreq = 1000. } CodeRate := 10; TestFreq := 1000; writeln ('*** This is MORSE CODE #1 ***'); writeln; write ('Do you want to send (F)ast, (S)low or (R)eal Slow ? '); readln (Flag); Flag := UpCase (Flag); IF Flag IN ['F', 'S', 'R'] THEN CASE Flag OF 'F' : CodeRate := 20; 'S' : CodeRate := 10; 'R' : CodeRate := 5 END { ... of CASE. } ELSE BEGIN writeln ('A bad entry ! Setting Code Rate to FAST'); CodeRate := 15 END; writeln; Flag := ' '; FillChar (Message, 255, Flag); Message := 'Numbered, numbered, weighed and divided.'; writeln ('Enter your message ... '); writeln; readln (Message); writeln; writeln ('Hit any key to terminate transmission ... '); REPEAT Morse_Tx (Message, TestFreq, CodeRate); UNTIL KeyPressed; writeln (' ... OK. Transmission is ended. '); END. ;************************** PROCEDURE Morse_Tx (PlainText : String255; ToneFrequency : integer; CodeSpeed : integer); { DATE : 23.x.99; REF : Duntemann, pg. 52 PURPOSE : To convert a text string into audible morse. GLOBALS : TYPE String255 = STRING [255]; String80 = STRING [80]; } VAR I, ToneLength, DitLength : integer; CodeChar : String80; BlendNextTwo : boolean; {...................................................} PROCEDURE Morse (CodeChar : String80); VAR I : integer; BEGIN { Of Morse ... } FOR I := 1 TO Length (CodeChar) DO BEGIN IF CodeChar [1] IN [ '.', '-'] THEN BEGIN IF CodeChar [I] = '.' THEN ToneLength := DitLength ELSE ToneLength := DitLength * 3; Sound (ToneFrequency); Delay (ToneLength); NoSound; Delay (DitLength) END END END; { ... of Morse. } {...................................................} BEGIN { Of Morse_Tx ... } BlendNextTwo := FALSE; IF CodeSpeed = 0 THEN EXIT; { Catch duff entry ... } DitLength := ROUND ((1.2 / CodeSpeed) * 1000); FOR I := 1 TO Length (PlainText) DO IF PlainText [I] = '*' THEN BlendNextTwo := TRUE ELSE BEGIN { Of Case-Loop ... } PlainText [I] := UpCase (PlainText [I]); Case PlainText [I] OF 'A' : CodeChar := '.-'; 'B' : CodeChar := '-...'; 'C' : CodeChar := '-.-.'; 'D' : CodeChar := '-..'; 'E' : CodeChar := '.'; 'F' : CodeChar := '..-.'; 'G' : CodeChar := '--.'; 'H' : CodeChar := '....'; 'I' : CodeChar := '..'; 'J' : CodeChar := '.---'; 'K' : CodeChar := '-.-'; 'L' : CodeChar := '.-..'; 'M' : CodeChar := '--'; 'N' : CodeChar := '-.'; 'O' : CodeChar := '---'; 'P' : CodeChar := '.--.'; 'Q' : CodeChar := '--.-'; 'R' : CodeChar := '.-.'; 'S' : CodeChar := '...'; 'T' : CodeChar := '-'; 'U' : CodeChar := '..-'; 'V' : CodeChar := '...-'; 'W' : CodeChar := '.--'; 'X' : CodeChar := '-..-'; 'Y' : CodeChar := '-.--'; 'Z' : CodeChar := '--..'; '1' : CodeChar := '.----'; '2' : CodeChar := '..---'; '3' : CodeChar := '...--'; '4' : CodeChar := '....'; '5' : CodeChar := '.....'; '6' : CodeChar := '-....'; '7' : CodeChar := '--...'; '8' : CodeChar := '---..'; '9' : CodeChar := '----.'; '0' : CodeChar := '-----'; '?' : CodeChar := '..--..'; '.' : CodeChar := '.-.-.-'; ',' : CodeChar := '--..--'; '/' : CodeChar := '-..-.'; '\' : CodeChar := '.-..-'; '$' : Codechar := '...-..-'; '-' : CodeChar := '-....-' ELSE CodeChar := '' END; { .. of Case. } Morse (CodeChar); IF NOT BlendNextTwo THEN Delay (DitLength * 2); BlendNextTwo := FALSE; IF KeyPressed THEN EXIT END { ... of Case-Loop. } END; { ... of Morse_Tx. } > -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.