Barry Gershenfeld zmicro.com> writes: > As your morse code programs are getting smaller and smaller, they are in > danger of disappearing! This code trades efficiency for novelty. I saw > this idea at a ham club talk (in the '70's) and have been doing it this way > ever since. Since you guys use assembler more than anything else, I'll > post it that way. I do the same thing in other languages. > > ; Morse code, tree structured. > ; Example fragment assumes the basic elements have been previously defined: > > E: > call dit > goto interchar > > N: > call dah > goto E > > G: > call dah > goto N > > P: > call dit > goto G > > T: > call dah > goto interchar > > A: > call dit > goto T Or, rewritten a little bit: P: call dit G: call dah N: call dah E: call dit goto interchar O: call dah M: call dah T: call dah goto interchar A: call dit goto T ; etc But it is more interesting to analyze this for morse decoding. A binary tree approach can be used, pointing into a retlw table, with halving distances for each succesive symbol, e.g.: (Note: decoding of 'V' shown as example in comments) ;; dit half of table, to symbol count of 4 retlw 'H' retlw 'S' ; step(3); dit: A -= Y; Y=Y/2 retlw 'V' ; step(4); daw: (end) retlw 'I' ; step(2); dit: A -= Y; Y=Y/2 retlw 'F' retlw 'U' retlw m0011 ; dit dit dah dah Ddit retlw 'E' ; ex: Y=4;A=Ddit; 'V': step(1); dit: A -= Y; Y=Y/2 retlw 'L' retlw 'R' retlw m0101 retlw 'A' retlw m0110 retlw 'W' retlw 'J' ;; daw half retlw 'B' retlw 'D' retlw 'X' retlw 'N' retlw 'Y' retlw 'K' retlw 'C' Ddaw retlw 'T' retlw 'Z' retlw 'G' retlw 'Q' retlw 'M' retlw m1110 retlw 'O' retlw m1111 ; to decode morse, call a subroutine that times symbols and outputs a bit vector ; like 0001bbbb where bbbb are morse symbols, 1 for dah and 0 for dit. The 1 ; is a start symbol. If the start symbol is in bit 5 and 6,7 are 0 then it's a ; number, so treat it differently. Else use this table (bit vector is in Morse): ; (else use a different table with prosigns etc) Sdecode_morse4: movlw 4 movwf Y ; step size movlw Ddit ; 1st symbol btfsc Morse,3 ; zero: start at Ddit movlw Ddaw ; one: start at Ddaw decode_morse4: rlf Morse,f ; next bit in bit 3 btfss Morse,3 ; dit: go up subwf Y,w ; do it btfsc Morse,3 ; daw: go down addwf Y,w ; do it rrf Y,f ; Y /= 2 incf Y,f ; +1 decfsz Fcount,f ; -1, check Z goto decode_morse4 ;; check page/bank bits here movwf PC ; return with character code in W A suitable table can be found on wikipedia (scroll down to the dichotomic search table): http://en.wikipedia.org/wiki/Morse_code Peter P. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist