' {$STAMP BS2} ' {$PBASIC 2.5} ' ' Morse Generator by OZ1BXM Lars Petersen eeprom VAR Byte ' EEPROM address morse VAR Byte ' morse character to send bitToSend VAR morse.BIT7 ' bit 7 (MSB) in the morse character Pitch CON 1000 ' hertz Dot CON 75 ' milliseconds KeyOn CON 1 ' key on is high (+5 volts) KeyOff CON 0 Space CON 32 Spkr PIN 7 ' Speaker is connected to P7 (pin 12) Key PIN 8 ' Key pin is P8 (pin 13) Init: OUTPUT Key ' Make the key pin an output Key = KeyOff ' Set key pin low ' Morse characters: ' 0 1 2 3 4 ' %11111100, %01111100, %00111100, %00011100, %00001100 ' 5 6 7 8 9 ' %00000100, %10000100, %11000100, %11100100, %11110100 ' a b c d e ' %01100000, %10001000, %10101000, %10010000, %01000000 ' f g h i j ' %00101000, %11010000, %00001000, %00100000, %01111000 ' k l m n o ' %10110000, %01001000, %11100000, %10100000, %11110000 ' p q r s t ' %01101000, %11011000, %01010000, %00010000, %11000000 ' u v w x y ' %00110000, %00011000, %01110000, %10011000, %10111000 ' z ? ' %11001000, %00110010 ' Write to EEPROM: ' c q c q WRITE 48, %10101000, %11011000, Space, %10101000, %11011000, Space ' c q d e WRITE 54, %10101000, %11011000, Space, %10010000, %01000000, Space ' o z 1 e u o WRITE 60, %11110000, %11001000, %01111100, %01000000, %00110000, %11110000, Space ' o z 1 e u o WRITE 67, %11110000, %11001000, %01111100, %01000000, %00110000, %11110000, Space ' o z 1 e u o k WRITE 74, %11110000, %11001000, %01111100, %01000000, %00110000, %11110000, Space, %10110000 Main: FOR eeprom = 48 TO 81 READ eeprom, morse ' Copy contents of EEPROM memory (at address eeprom) into morse GOSUB Send_morse_char ' Send the morse character NEXT PAUSE 1000 ' Delay 1000 ms GOTO Main ' Start over again END Send_morse_char: IF morse = Space THEN ' If Space then wait and return PAUSE (4 * Dot) ' Word spacing is 7 dots; 3 dots elapsed already RETURN ENDIF DO ' Send one bit at the time in morse character IF bitToSend = 1 THEN GOSUB Send_dash ELSE GOSUB Send_dot ENDIF morse = morse << 1 ' shift left 1 bit, fill in zeros from the right LOOP UNTIL (morse = %10000000) ' the stop pattern is found, break out of loop PAUSE 2 * Dot ' add 2 x dot spacing (the 3rd spacing was in Send_dot/Send_dash) RETURN Send_dot: Key = KeyOn FREQOUT Spkr, Dot, Pitch Key = KeyOff PAUSE Dot RETURN Send_dash: Key = KeyOn FREQOUT Spkr, 3 * Dot, Pitch Key = KeyOff PAUSE Dot RETURN