Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Morse note?
Author | Message | ||||
Herry Senior Member Joined: 31/05/2014 Location: AustraliaPosts: 261 |
In the absence of any sound, beep or tone command I am wondering if there is a simple way of generating a given note to be output to a small speaker or similar. I've seen a couple of rather complex offerings. I only want to generate one note but I will be placing this in routines that generate a) dots, b)dashes and c) a continuous note. Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 911 |
Herry, not sure if I am reading your question right but PWM is your default sound producer. GM |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1141 |
Hi Herry, this could be interesting for you: Micromite Musical Box. There is also a Morse program for MAXIMITES. You should be able to convert this for your Micromite. Regards Michael |
||||
Herry Senior Member Joined: 31/05/2014 Location: AustraliaPosts: 261 |
OK, PWM it is. I shall work on that. I suppose I can pass parameters (arguments) with subroutines or functions? Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
viscomjim Guru Joined: 08/01/2014 Location: United StatesPosts: 925 |
Hi Herry, I remembered a piece of code from a few years back on the GreatCow Basic forum that read a ps2 keyboard and did the morse code. This is a good starting point where you would have to make the obvious changes for the uMite, I just thought it was cool the way the dot and bar subs were used. Take a look and let us know how you make out on your project. 'Morse Code demonstration for Great Cow BASIC
'(c) Hugh Considine 2006-2008 'A program to accept messages from a standard PS/2 keyboard, then play 'them as morse code using a speaker. 'User Settings #define CodeFrequency 750 'Hz #define DotLength 5 '* 10 ms #define DotSpace 250 ' ms #define BarLength 25 '* 10 ms #define BarSpace 50 ' ms 'Hardware settings #chip 16F877A, 20 'LCD connection settings #define LCD_IO 8 #define LCD_DATA_PORT PORTC #define LCD_RS PORTD.0 #define LCD_RW PORTD.1 #define LCD_Enable PORTD.2 'PS/2 keyboard connection settings #define PS2Clock PORTB.1 #define PS2Data PORTB.2 'Tone output pin #define SoundOut PORTD.3 'Set port directions DIR PS2Clock IN DIR PS2Data IN DIR SoundOut OUT 'Clear key buffer DIM KeyLog(32) DataCount = 0 KeyLog(1) = 32 'Space character 'Show opening message PRINT "GCBASIC Morse" locate 1,0 PRINT "Code Transmitter" 'Main routine Main: 'Get a keypress KeyIn = INKEY if KeyIn = 0 then goto Main 'Allow time for key to be released wait 150 ms 'if ENTER is pressed, then send message if KeyIn = 13 then MorseSend goto Main end if 'Escape - clear message buffer if KeyIn = 27 then DataCount = 0 for DataPos = 1 to 32 KeyLog(DataPos) = 32 next goto DisplayData end if 'Backspace - delete last character if KeyIn = 8 then if DataCount = 0 then goto Main KeyLog(DataCount) = 32 DataCount = DataCount - 1 goto DisplayData end if 'Otherwise, add the character to the buffer DataCount = DataCount + 1 KeyLog(DataCount) = KeyIn DisplayData: 'Display key log CLS for DataPos = 1 to DataCount if DataPos = 17 then locate 1,0 LCDWriteChar KeyLog(DataPos) next goto Main sub MorseSend for SendLetter = 1 to DataCount Letter = KeyLog(SendLetter) 'Numbers if Letter = 48 then Bar: Bar: Bar: Bar: Bar '0 if Letter = 49 then Dot: Bar: Bar: Bar: Bar '1 if Letter = 50 then Dot: Dot: Bar: Bar: Bar '2 if Letter = 51 then Dot: Dot: Dot: Bar: Bar '3 if Letter = 52 then Dot: Dot: Dot: Dot: Bar '4 if Letter = 53 then Dot: Dot: Dot: Dot: Dot '5 if Letter = 54 then Bar: Dot: Dot: Dot: Dot '6 if Letter = 55 then Bar: Bar: Dot: Dot: Dot '7 if Letter = 56 then Bar: Bar: Bar: Dot: Dot '8 if Letter = 57 then Bar: Bar: Bar: Bar: Dot '9 'Letters if Letter >= 97 and Letter <= 122 then Letter -= 32 'Convert to upper case if Letter = 65 then Dot: Bar if Letter = 66 then Bar: Dot: Dot: Dot if Letter = 67 then Bar: Dot: Bar: Dot if Letter = 68 then Bar: Dot: Dot if Letter = 69 then Dot if Letter = 70 then Dot: Dot: Bar: Dot if Letter = 71 then Bar: Bar: Dot if Letter = 72 then Dot: Dot: Dot: Dot if Letter = 73 then Dot: Dot 'I if Letter = 74 then Dot: Bar: Bar: Bar 'J if Letter = 75 then Bar: Dot: Bar 'K if Letter = 76 then Dot: Bar: Dot: Dot 'L if Letter = 77 then Bar: Bar 'M if Letter = 78 then Bar: Dot 'N if Letter = 79 then Bar: Bar: Bar 'O if Letter = 80 then Dot: Bar: Bar: Dot 'P if Letter = 81 then Bar: Bar: Dot: Bar 'Q if Letter = 82 then Dot: Bar: Dot 'R if Letter = 83 then Dot: Dot: Dot 'S if Letter = 84 then Bar 'T if Letter = 85 then Dot: Dot: Bar 'U if Letter = 86 then Dot: Dot: Dot: Bar 'V if Letter = 87 then Dot: Bar: Bar 'W if Letter = 88 then Bar: Dot: Dot: Bar 'X if Letter = 89 then Bar: Dot: Bar: Bar 'Y if Letter = 90 then Bar: Bar: Dot: Dot 'Z 'Misc if Letter = 32 then wait 300 ms 'Space next end sub sub Dot Tone CodeFrequency, DotLength wait DotSpace ms end sub sub Bar Tone CodeFrequency, BarLength wait BarSpace ms end sub |
||||
HankR Senior Member Joined: 02/01/2015 Location: United StatesPosts: 209 |
This is an amazingly simple way to interface to a PS2 keyboard. High fives to the compiler designer for that feature and implementation. Sometimes GREAT COW can be so limited in many important ways, but that part is a winner. Thanks, Jim. Hank |
||||
HankR Senior Member Joined: 02/01/2015 Location: United StatesPosts: 209 |
Jim, If you like that, you should see the various bit saving schemes that are employed for coding the dits and dahs (dots and dashes for civilians) using assembler or C. Fun to figure out how it's done. Every Morse symbol takes up only 1 byte. I've done this kind of minimalist encoding for ham radio balloon borne transmitters using early PIC microcontrollers. Hank |
||||
CircuitGizmos Guru Joined: 08/09/2011 Location: United StatesPosts: 1421 |
The scheme I worked out is to encode dit as 0, dah as 1. Also leading 0 is ignored, 1 is ignored and a start bit. Example: S is . . . Encoded: 00001000 Decode bit by bit from MSB 0 ignore 0 ignore 0 ignore 0 ignore 1 ignore and 'start' (next bits are real) 0 dit 0 dit 0 dit Example: O is _ _ _ Encoded: 00001111 Decode bit by bit from MSB 0 ignore 0 ignore 0 ignore 0 ignore 1 ignore and 'start' (next bits are real) 1 dah 1 dah 1 dah Example: 2 is . . _ _ _ Encoded: 00100111 Decode bit by bit from MSB 0 ignore 0 ignore 1 ignore and 'start' (next bits are real) 0 dit 0 dit 1 dah 1 dah 1 dah Actually, though, I encoded from LSB, so it all was backward from what is here, but it is easier to see the morse code and the encoding "forward" rather than backward. Micromites and Maximites! - Beginning Maximite |
||||
Herry Senior Member Joined: 31/05/2014 Location: AustraliaPosts: 261 |
All good. It turns out to be amazingly trivial for my application. As advised it is simply eg PWM 2, 400, 50 and a loudspeaker via an electrolytic on pin 26, with of course PWM 2, STOP after the required delay! Thanks to all who replied. Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
Print this page |