{"id":296,"date":"2008-05-18T19:01:38","date_gmt":"2008-05-18T17:01:38","guid":{"rendered":"http:\/\/pa3hcm.utreg.net\/?p=296"},"modified":"2021-01-18T20:19:00","modified_gmt":"2021-01-18T19:19:00","slug":"cw-keyer-for-foxes-and-beacons","status":"publish","type":"post","link":"https:\/\/www.pa3hcm.nl\/?p=296","title":{"rendered":"CW keyer for foxes and beacons"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>Beacons and foxes have to identify themselves. Although I could sit along all day with my morse key, transmitting my call, I wanted to have some automatic keyer. Since I recently bought a PIC development kit (<a href=\"http:\/\/www.velleman.be\/nl\/en\/product\/view\/?id=350903\" target=\"_blank\" rel=\"noopener\">Velleman K8048<\/a>), I thought that it would be a nice idea to create my first PIC application by building a CW keyer.<\/p>\n\n\n\n<p>I never wrote PIC source code yet, but I have done some assembly for 68000 and x86 in the past. So it shouldn&#8217;t be to difficult to write a simple program, keying one of the outputs of a PIC. On the CD of my PIC development kit I found some sample programs, including one for a flashing LED (this appears to be the &#8220;Hello, World!&#8221; application for microcontrollers). I modified the source code and finally build the bunch of code which you can find on the bottom of this page. I&#8217;m sure that this code is not the best PIC program of the world, but it works and at least I understand how it actually works. If you have any suggestions, please feel free to send them to me!<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>The reason that I used a PIC16F627 and not the far more popular 16F84 is that the 627 comes default with the PIC development kit and the &#8220;flashing lED&#8221; code was written for that PIC too&#8230;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Schematic<\/h2>\n\n\n\n<p><a href=\"http:\/\/pa3hcm.utreg.net\/wp-content\/uploads\/2013\/12\/cwkeyer_schematic.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-122\" src=\"http:\/\/pa3hcm.utreg.net\/wp-content\/uploads\/2013\/12\/cwkeyer_schematic.png\" alt=\"cwkeyer_schematic\" width=\"600\" height=\"321\" srcset=\"https:\/\/www.pa3hcm.nl\/wp-content\/uploads\/2013\/12\/cwkeyer_schematic.png 600w, https:\/\/www.pa3hcm.nl\/wp-content\/uploads\/2013\/12\/cwkeyer_schematic-300x160.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><br>The schematic is not that difficult. Actually the software keys 2 outputs (RB0 and RB1). You can use one to create a PTT\/key output (T1, R2) and one to flash a LED (then you know it&#8217;s doing its job). R1 provides a correct initialisation of the PIC processor, and X1, C3 and C4 form a basic clock circuit. Using a crystal with another frequency wil impact the keying speed.<\/p>\n\n\n\n<p>Most beacons and foxes don&#8217;t use 5 volts for power but some higher voltage. So you may add U1, C1 and C2 to create 5V (required for the PIC).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">;*********************\n;* PA3HCM * CW KEYER *\n;*********************\n\nW                            EQU     H'0000'\nF                            EQU     H'0001'\n\n;----- Register Files------------------------------------------------------\n\nINDF                         EQU     H'0000'\nTMR0                         EQU     H'0001'\nPCL                          EQU     H'0002'\nSTATUS                       EQU     H'0003'\nFSR                          EQU     H'0004'\nPORTA                        EQU     H'0005'\nPORTB                        EQU     H'0006'\n\nINTCON                       EQU     H'000B'\nOPTION_REG                   EQU     H'0081'\nTRISA                        EQU     H'0085'\nTRISB                        EQU     H'0086'\nCMCON                        EQU     H'001F'\n\n;----- STATUS Bits --------------------------------------------------------\nIRP                          EQU     H'0007'\nRP1                          EQU     H'0006'\nRP0                          EQU     H'0005'\nNOT_TO                       EQU     H'0004'\nNOT_PD                       EQU     H'0003'\nZ                            EQU     H'0002'\nDC                           EQU     H'0001'\nC                            EQU     H'0000'\n\n;==========================================================================\n;\n;       RAM Definition\n;\n;==========================================================================\n\n    __MAXRAM H'01FF'\n    __BADRAM H'07'-H'09', H'0D', H'13'-H'14', H'1B'-H'1E'\n    __BADRAM H'87'-H'89', H'8D', H'8F'-H'91', H'93'-H'97', H'9E'\n    __BADRAM H'105', H'107'-H'109', H'10C'-H'11F', H'150'-H'16F'\n    __BADRAM H'185', H'187'-H'189', H'18C'-H'1EF'\n\n;==========================================================================\n;\n;       Configuration Bits\n;\n;==========================================================================\n\n_BODEN_ON                    EQU     H'3FFF'\n_BODEN_OFF                   EQU     H'3FBF'\n_CP_ALL                      EQU     H'03FF'\n_CP_75                       EQU     H'17FF'\n_CP_50                       EQU     H'2BFF'\n_CP_OFF                      EQU     H'3FFF'\n_DATA_CP_ON                  EQU     H'3EFF'\n_DATA_CP_OFF                 EQU     H'3FFF'\n_PWRTE_OFF                   EQU     H'3FFF'\n_PWRTE_ON                    EQU     H'3FF7'\n_WDT_ON                      EQU     H'3FFF'\n_WDT_OFF                     EQU     H'3FFB'\n_LVP_ON                      EQU     H'3FFF'\n_LVP_OFF                     EQU     H'3F7F'\n_MCLRE_ON                    EQU     H'3FFF'\n_MCLRE_OFF                   EQU     H'3FDF'\n_ER_OSC_CLKOUT               EQU     H'3FFF'\n_ER_OSC_NOCLKOUT             EQU     H'3FFE'\n_INTRC_OSC_CLKOUT            EQU     H'3FFD'\n_INTRC_OSC_NOCLKOUT          EQU     H'3FFC'\n_EXTCLK_OSC                  EQU     H'3FEF'\n_LP_OSC                      EQU     H'3FEC'\n_XT_OSC                      EQU     H'3FED'\n_HS_OSC                      EQU     H'3FEE'\n\n\t__CONFIG        _BODEN_ON &amp; _CP_OFF &amp; _DATA_CP_OFF &amp; _PWRTE_ON &amp; _WDT_OFF &amp; _LVP_OFF &amp; _MCLRE_ON &amp; _XT_OSC\n\n;==========================================================================\n;       Variable Definition\n;==========================================================================\nTIMER1\t\tEQU\tH'20'\t\t;Used in delay routine\nTIMER2\t\tEQU\tH'21'\t\t; \"\t\"\t\"\t\nPATERN\t\tEQU\tH'22'\t\t;Pattern data for effect's\n\n\t\tORG\t0\t\t;Reset vector address\n\t\tGOTO\tRESET\t\t;goto RESET routine when boot.\n\n;\t\t*********************************************\n;\t\t*  Example of a delay routine               *\n;\t\t*********************************************\n\nDELAY_ROUTINE   MOVLW   D'127'         ;54 Generate approx 10mS delay at 4Mhz CLK\n                MOVWF   TIMER2\nDEL_LOOP1       MOVLW   D'255'\t       ;60\t\n                MOVWF   TIMER1\nDEL_LOOP2       DECFSZ  TIMER1,F\n                GOTO    DEL_LOOP2\n                DECFSZ  TIMER2,F\n                GOTO    DEL_LOOP1\n\t\tRETLW   0\n\n;\t       **********************************\n;              **  RESET :  main boot routine  **\n;              **********************************\n\nRESET\t\tMOVLW\tB'00000111'\t;Disable Comparator module's\n\t\tMOVWF\tCMCON\n\t\t;\n\t\tBSF\tSTATUS,RP0\t;Switch to register bank 1\n\t\t\t\t\t;Disable pull-ups\n\t\t\t\t\t;INT on rising edge\n\t\t\t\t\t;TMR0 to CLKOUT\n\t\t\t\t\t;TMR0 Incr low2high trans.\n\t\t\t\t\t;Prescaler assign to Timer0\n\t\t\t\t\t;Prescaler rate is 1:256\n\t\tMOVLW\tB'11010111'\t;Set PIC options (See datasheet).\n\t\tMOVWF\tOPTION_REG\t;Write the OPTION register.\n\t\t;\n\t\tCLRF\tINTCON\t\t;Disable interrupts\n\t\tMOVLW\tB'11000000'\n\t\tMOVWF\tTRISB\t\t;RB7 &amp; RB6 are inputs.\n\t\t\t\t\t;RB5...RB0 are outputs.\n\t\tMOVLW\tB'11111111'\t;all RA ports are inputs\n\t\tMOVWF\tTRISA\n\t\tBCF\tSTATUS,RP0\t;Switch Back to reg. Bank 0\n\t\tCLRF\tPORTB\t\t\n\t\t;\n\nMAIN\t\tCALL\tCW_P\n\t\tCALL\tCW_A\n\t\tCALL\tCW_3\n\t\tCALL\tCW_H\n\t\tCALL\tCW_C\n\t\tCALL\tCW_M\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_R\n\t\tCALL\tCW_E\n\t\tCALL\tCW_C\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_F\n\t\tCALL\tCW_O\n\t\tCALL\tCW_X\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_A\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_KEYDOWN\n\t\tCALL\tCW_KEYUP\n\t\tCALL\tCW_PAUSE\n\t\tGOTO\tMAIN\n\nDIT\t\tMOVLW\tB'00000011'\t;Activate RB0\n\t\tMOVWF\tPORTB\n\t\tCALL\tDELAY_ROUTINE\n\t\tMOVLW\tB'00000000'\t;Activate RB0\n\t\tMOVWF\tPORTB\n\t\tCALL\tDELAY_ROUTINE\n\t\tRETLW\t0\n\nDAH\t\tMOVLW\tB'00000011'\t;Activate RB0\n\t\tMOVWF\tPORTB\n\t\tCALL\tDELAY_ROUTINE\n\t\tCALL\tDELAY_ROUTINE\n\t\tCALL\tDELAY_ROUTINE\n\t\tMOVLW\tB'00000000'\t;Activate RB0\n\t\tMOVWF\tPORTB\n\t\tCALL\tDELAY_ROUTINE\n\t\tRETLW\t0\n\nCW_5\t\tCALL\tDIT\nCW_H\t\tCALL\tDIT\nCW_S\t\tCALL\tDIT\nCW_I\t\tCALL\tDIT\nCW_E\t\tCALL\tDIT\n\t\tCALL\tDELAY_ROUTINE\n\t\tCALL\tDELAY_ROUTINE\n\t\tRETLW\t0\n\nCW_0\t\tCALL\tDAH\n\t\tCALL\tDAH\nCW_O\t\tCALL\tDAH\nCW_M\t\tCALL\tDAH\nCW_T\t\tCALL\tDAH\n\t\tCALL\tDELAY_ROUTINE\n\t\tCALL\tDELAY_ROUTINE\n\t\tRETLW\t0\n\ncW_4\t\tCALL\tDIT\ncW_V\t\tCALL\tDIT\ncW_U\t\tCALL\tDIT\nCW_A\t\tCALL\tDIT\n\t\tCALL\tDAH\n\t\tCALL\tDELAY_ROUTINE\n\t\tCALL\tDELAY_ROUTINE\n\t\tRETLW\t0\n\nCW_8\t\tCALL\tDAH\n\t\tCALL\tDAH\nCW_D\t\tCALL\tDAH\n\t\tCALL\tDIT\n\t\tCALL\tDIT\n\t\tCALL\tDELAY_ROUTINE\n\t\tCALL\tDELAY_ROUTINE\n\t\tRETLW\t0\n\nCW_7\t\tCALL\tDAH\nC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AUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tMOVLW\tB'000000000'\n\t\tMOVWF\tPORTB\n\t\tRETLW\t0\n\nCW_KEYUP\tMOVLW\tB'00000000'\n\t\tMOVWF\tPORTB\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tCALL\tCW_PAUSE\n\t\tRETLW\t0\n\n\t\tEND<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Beacons and foxes have to identify themselves. Although I could sit along all day with my morse key, transmitting my call, I wanted to have some automatic keyer. Since I recently bought a PIC development kit (Velleman K8048), I thought that it would be a nice idea to create my first PIC application by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":122,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[28,35],"class_list":["post-296","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-transmitters_and_receivers","tag-cw","tag-pic"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"_links":{"self":[{"href":"https:\/\/www.pa3hcm.nl\/index.php?rest_route=\/wp\/v2\/posts\/296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pa3hcm.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pa3hcm.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pa3hcm.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pa3hcm.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=296"}],"version-history":[{"count":4,"href":"https:\/\/www.pa3hcm.nl\/index.php?rest_route=\/wp\/v2\/posts\/296\/revisions"}],"predecessor-version":[{"id":1960,"href":"https:\/\/www.pa3hcm.nl\/index.php?rest_route=\/wp\/v2\/posts\/296\/revisions\/1960"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pa3hcm.nl\/index.php?rest_route=\/wp\/v2\/media\/122"}],"wp:attachment":[{"href":"https:\/\/www.pa3hcm.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pa3hcm.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pa3hcm.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}