This is a multi-part message in MIME format. ------=_NextPart_000_002C_01C7688F.1BEA4B20 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit On Friday, March 16, 2007 8:23 PM [GMT-3=CET], William Chops Westfield wrote: > > The start bit idea is clever! It allows a character to have > > up to 7 dits or dahs. > > Heh. The motorola "Black Widow" design contest (for their 8pin > cpus, essentially) has as one of the "steps" to finish a morse > code program. The core that they supply stores the translation > table as STRINGS: > > > > > char *convert(char c){ //Convert ASCII received switch(c){ > > > > case 'a': > > > > return ".-"; > > > > case 'b': > > > > return "-..."; > > > > case 'c': > > > > return "-.-."; > > > > > I guess that says something about changes in attention paid to > code size by "youngins" these days. And C vs ASM, perhaps. > Although since the high-end 8pin chip contains 8kbyte of flash > (more than any other 8pin uC?) I guess it doesn't matter. > > > SendMorseCharA > > RLF MorseChar,f ; shift msb into carry > > movf MorseChar,f ; test to see if we're done > > bz SendMorseCharZ ; We're done, get out > > skpc ; skip if dit > > call DoDah ; go send dah - PRESERVE CARRY! > > skpnc > > call DoDit ; go send dit > > call InterCharDelay > > goto SendMorseCharA ; go send next bit, if any > > SendMorseCharZ > > return ; we're outta here! > > Speaking of C compilers, this is a good example of the sort of > code that I think it would be really difficult for a C compiler > to generate; It's what I meant by "explicit use of carry." Does > anybody want to take a shot at C code/compiler implementation > that comes close to outputting this? > > (And on the third hand, it is perhaps also an example of optimization > that doesn't need to be done.) > > BillW Bill, This is my C approach. //************************************************* unsigned char MorseChar; unsigned char i,a,dot,dash; MorseChar= 0xED; // code + stop bit dot=dash=a=0; //testing purpose // for(i=0x80;i > 0x00;i >>= 1) //rotate a 1 used as mask { // a |= i; //preparing a mask if(MorseChar ^ (MorseChar&a)) //xoring only lsb bits. { // if((MorseChar & i)> 0) // is a one? { // dot++; //send a dot } // else // { // dash++; //send a dash } // } // else // { // break; //end of char! } // // } // //************************************************* lookup table (see attached file) The dots are represented by 1's and the dashes by 0's. A stop bit was used as Wouter pointed earlier. The table is ordered by ASCII value minus 34, since 34 is the very first character value. So the Table is only 62 bytes long!. I arbitrary used [ 11111111 91 0xFF \ 10110100 92 0xB4 to represent Error symbol (it supoused to have no errors)and the "new" symbol @. The older @ is a combination of AC. Only 7 bytes of the table are unused. The C can`t handle the error sign. So that is a particular case.:) Regards, Dennis Crawley. ------=_NextPart_000_002C_01C7688F.1BEA4B20 Content-Type: text/plain; name="morsetable.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="morsetable.txt" " 10110110 34 0xB6 # 00000000 35 0x00 $ 11101101 36 0xED % 00000000 37 0x00 & 00000000 38 0x00 ' 10000110 39 0x86 ( 01001100 40 0x4C ) 01001010 41 0x4A * 00000000 42 0x00 + 10101100 43 0xAC , 00110010 44 0x32 - 01111010 45 0x7A . 10101010 46 0xAA / 01101100 47 0x6C 0 00000100 48 0x40 1 10000100 49 0x84 2 11000100 50 0xC4 3 11100100 51 0xE4 4 11110100 52 0xF4 5 11111100 53 0xFC 6 01111100 54 0x7C 7 00111100 55 0x3C 8 00011100 56 0x1C 9 00001100 57 0xC0 : 00011110 58 0x1E ; 01010110 59 0x56 < 00000000 60 0x00 = 01110100 61 0x74 > 00000000 62 0x00 ? 11001110 63 0xCE @ 10010110 64 0x96 A 10100000 65 0xA0 B 01111000 66 0x78 C 01011000 67 0x58 D 01110000 68 0x70 E 11000000 69 0xC0 F 11011000 70 0xD8 G 00110000 71 0x30 H 11111000 72 0xF8 I 11100000 73 0xE0 J 10001000 74 0x88 K 01010000 75 0x50 L 10111000 76 0xB8 M 00100000 77 0x20 N 01100000 78 0x60 O 00010000 79 0x10 P 10011000 80 0x98 Q 00101000 81 0x28 R 10110000 82 0xB0 S 11110000 83 0xF0 T 01000000 84 0x40 U 11010000 85 0xD0 V 11101000 86 0xE8 W 10010000 87 0x90 X 01101000 88 0x68 Y 01001000 89 0x48 Z 00111000 90 0x38 [ 11111111 91 0xFF \ 10110100 92 0xB4 ] 00000000 93 0x00 ^ 00000000 94 0x00 _ 11001010 95 0xCA ------=_NextPart_000_002C_01C7688F.1BEA4B20 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist ------=_NextPart_000_002C_01C7688F.1BEA4B20--