Before programming your EPROM HC11 you will first have to modify your code so it will work properly in EPROM. After the necessary changes have been made to your code, you will put your EPROM HC11 into your EVBU and program it using PCBug11. Do the following:

  1. Get your program working in your BUFFALO HC11.

  2. Remove the interrupt vector code from your program. For example, if you use an Input Capture 1 interrupt service routine called tic1_isr(), remove the two lines
             TIC1_JMP = JMP_OP_CODE;
             TIC1_VEC = tic1_isr;

  3. Copy the file vectors.c into your directory. Edit the file vectors.c, adding the names of your interrupt service routines at the appropriate locations. For example, for your tic1_isr(), find the line
             0,          /* TIC1 */
    and change it to
            tic1_isr,     /* TIC1 */

    Also, near the top of the file vectors.c, just below the line

            extern void _start();   /* entry point in crt11.s */
    add lines for your interrupt service routines. For example, for your tic1_isr(), add the line
            extern void tic1_isr(void);

  4. BUFFALO will not be available for use, so you should not call any BUFFALO routines (such as OUT1BYT). You can use library functions such as printf() and putchar() to print to the terminal. If your program uses the RS-232 port (e.g., uses the printf() function), you will have to initialize the SCI because BUFFALO no longer will do this. Add the following lines to the initialization part of your program:
            BAUD = 0x30;        /* 9600 Baud */
            SCCR1 = 0x00;
            SCCR2 = 0x0c;       /* Enable SCI transmitter and receiver, with
                                   no interrupts enabled*/

  5. If you need to adjust the prescaler, do it as the first line in your C program. For example:
            TMSK2 = 0x02;       /* Set prescaler to divide by 8 */

  6. If you have variables you want to be initialized, and the variables will not change during execution, declare them to be of type const. For example, the T-Bird taillights:
        const unsigned char tbird[] =
    The const tells the compiler to put these numbers in the code section, which will be in EPROM, so they will be there permanently, but you will not be able to change them.

  7. If you have variables you want to be initialized, and the variables will change during execution, you cannot initialize the variables when you define them, but will have to do it in the program. For example, if your program has the following in it:
        int i=0;
    change it to:
        int i;
            i = 0;

  8. A function cannot use an initialized static variable. If a function has the following:
        void foo(void)
            static int i=0;
            if (i < 0)
    change the static variable to a global variable and initialize it in main(). You may have to invent a unique name for the variable so it does not conflict with another variable name. For example:
        int foo_i;
            foo_i = 0;
        void foo(void)
            if (foo_i < 0)

  9. Compile your program telling the compiler to include the file vectors.c, to put your code in EPROM at 0xd000, and to put your interrupt vectors at 0xffd6. For example, if the name of your program is prog.c, use the following line to compile it.
       icc11 -l -o prog.s19 prog.c vectors.c -btext:0xd000 -bdata:0x2000
             -binterrupt_vectors:0xffd6 -d_stack:0x9fff

  10. The computers running Windows NT in the lab do not (at this time) work with PCBug11. To program your EPROM HC11 you can follow the instructions below at home (if your computer runs Windows 3.1 or Windows 95), or take your HC11 to the programming station in Digital Lab. If you use the programming station in Digital Lab, you can use the EVBU there to do the programming, which has all its jumpers already set for programming.

  11. Make sure power is turned off to the EVBU. Remove the BUFFALO HC11 from your EVBU and put in an erased EPROM HC11.

  12. Make sure there is no jumper on J7, J14, or your Expansion Enable. Put jumpers across J3 and J4. These jumpers will put the HC11 into Special Bootstrap Mode, in which mode the HC11 will download its program over its serial port. The program PCBug11 on the PC will send the correct program to the HC11 in bootstrap mode.

  13. Connect the serial cable to your EVBU and turn on power.

  14. Start PCBug11 with the command PCBUG11 -E PORT=2 and enter the following commands:
        EPROM D000 FFFF
        VERF ERASE D000 FFFF
    The final command verifies that the EPROM is fully erased. If this command is unsuccessful, remove the EPROM HC11 and put the chip in a UV EPROM eraser from 30 minutes. Once the chip is erased start the procedure again.

  15. Apply +12.25V DC to the XIRQ pin (pin 18). Measure the voltage carefully before applying it. A voltage higher than 12.5V can destroy your EPROM HC11. A 100 Ohm resistor must be installed in series between the +12.25V supply and the XIRQ pin, and a 20 uF capacitor should be installed between the +12.25V supply and ground:

    !!! CAUTION !!!

    Do not apply the +12.25V programming voltage when the main +5V power is off. Doing so will destroy the EPROM HC11. Always turn on the +5V supply before applying the +12.25V programming voltage. Always remove the +12.25V programming voltage before turning of the +5V supply.

  16. Enter the following command to PCBug11:
    LOADS filename.s19 --
    This loads the file ``filename.s19'' into the EPROM. The file ``filename.s19''' must be an S-record format file and must be loaded into the address range 0xD000 to 0xFFFF.

  17. Remove the 12.25V programming voltage from the XIRQ pin. Give the following command to PCBug11:
    VERF filename.s19 --
    verifies that the file was loaded properly

  18. Exit PCBug11 with the command QUIT Y.

  19. Remove jumpers from J3 and J4. Reinstall the jumper on your Expansion Enable. Install a jumper on J7. Install a jumper on J14 if you are using your Real Time Clock to interrupt the HC11 over the XIRQ pin. Push the reset button, and your HC11 should execute your program out of EPROM.

  20. After you are done with the lab, turn off power and put your BUFFALO HC11 back in your board. You can erase your EPROM HC11 with a UV EPROM eraser if you want.

Bill Rison, < >
Wed Apr 22 1998

© 1998, New Mexico Tech