using c++ with microprocessor

Upload: ferdad

Post on 07-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Using C++ With Microprocessor

    1/4

    Copyright 2000 by Barry B. Brey

    Using C++ with the 80C188EB Microprocessor

    The 80188 requires a 16-bit version of C++ like version 1.52 of Microsoft Visual C++.

    With the proper setup, this version of C++ will generate a .COM file that can beprogrammed onto EPROM or FLASH memory for use with the 80C188EC embeddedmicroprocessor.

    A few rules:

    1. You main code must be placed in an infinite while loop.

    void main(void) {while (1) {

    // code is placed here}

    }

    2. All variables must be of the integer (int), Boolean (bool), or character (char)

    types.3. Otherwise all of the C++ language features function correctly that is classes

    etc!

    Setting up MSVC version 1.52:

    Given the example program just to show you how to setup a program with a class.

    class Test {public:

    Test() {Var = 0;

    }Test(int num) {

    Var = num;}int getNum() {

    return Var;}void setNum(int num) {

    Var = num;}

    private:int Var;

    };

    void main () {int c;while (1) {

    Test a;Test b(23);a.setNum(2);c = a.getNum() * b.getNum() * 2;

    }}

  • 8/6/2019 Using C++ With Microprocessor

    2/4

    The program was compiled and generated a .COM file that was about 180 bytes inlength. The program can be placed at any location in memory because it uses only near

    jumps and calls. This means you can place it anywhere in your EPROM. For example,you already have an operating system for you 80188 in assembly language form that

    provides the basic structure of the system. This would be difficult to write in C++. The

    operating system takes less than 200 bytes. The remainder of your system EPROMmemory is available which means you could have a C++ program of up to almost 32K inlength!

    What about the variables? Since the way a compiler allocates memory is on the stack and

    since we initialized our stack memory at the top of the SRAM (32K). Our system can useup to 32K of variable space for the C++ program.

    This creates many possibilities for the 80C188EB embedded microprocessor and the

    system.

    Unfortunately, all variable data must be in integer or character form because I dont havean alternate math package to handle floating point numbers, but I am working on it and it

    will be available sometime in the future.

    In order to use MSVC to generate a .COM file that is useable, we need to set up thecompiler correctly. (These steps may be adaptable to Borland C++ as well).

    Under project options:

    Select MS-DOS COM, make sure that you check DEBUG and uncheck Use Microsoft

    Foundation Classes as shown below.

  • 8/6/2019 Using C++ With Microprocessor

    3/4

    Click on Compiler in the pervious illustration and make sure the Code Generation optionsappear as listed. Dont change the Options String directly, do it with the CPU box and so

    forth. You will need to change the Code Generation page here and the Memory Model toTINY.

    You dont need to change the Linker options because we must link from the DOS

    command line.

  • 8/6/2019 Using C++ With Microprocessor

    4/4

    When you compile your program with this set up you will get one warning as shownbelow. This is normal and you could get other warnings dependent on what your

    software does. You may not have any errors.

    Initializing...Compiling...

    Command line warning D4023 :option '/FPa' forces use of optimizing compilerc:\msvc\bin\my.cpp

    MY.CPP - 0 error(s), 1 warning(s)

    Once you have compiled your software, you will have a new file on your disk called (inthis case) my.obj plus others. The my.obj is an object file that can be linked with the

    LINK program at the command line.

    To link the object file and generate a my.com file which can be burned on an EPROMjust type:

    LINK /TINY my.obj

    Just type enter for any questions that link asks.

    You will see 2 warnings that the linker generates. This is normal for what we are doing.

    To burn the EPROM you must load two files before burning:

    Load your microprocessor project file (operating system at address 0000) then load this

    new my.com file at an address past the end of the operating system. For example, if youroperating system file is less than 200H bytes load the my.com file at 0200. You are now

    ready to burn your EPROM. Dont forget a JMP to your operating software.

    Operating System

    JMP progorg 200H

    prog: