Welcome to the UCSD on-line course:
ECP II: Embedded C !

 

Here is a bunch of information to help you get started in ECP II. 

This is a *long* page, so please be sure to scroll down and read it ALL carefully!

 

I recommend printing this page for reference as you work through the tool installation and "Hello World" homework assignment.

************
PLEASE NOTE:
************
Information in class e-mail announcements supercedes any conflicting info you may find on this page or on the web sites!

The common web site for both live and on-line students in ECP I and II is:
        http://www.hte.com/uconline/ecp

Scroll down to the ECP II section for week by week assignments and lecture notes.  The first ECP II lecture is section 7, since it follows immediately after the sixth lecture of ECP I.

IMPORTANT:
==========
If you want to send e-mail to me regarding this course, PLEASE use the ecp2_AT_hte.com address ONLY (substitute the @ symbol for the _AT_ in the address).  That way it will be filed automatically in the correct mail folder in the instructor’s e-mail box.  Otherwise, your mail may end up in my trash folder courtesy of my spam filters, or mis-filed in the wrong folder...

Questions that may be of interest to other students should be addressed to the ECP2 discussion group ecp2group_AT_hte.com, allowing other students who answer your questions to earn extra credit (see below).  You will receive a separate welcome e-mail message when you have been added to the discussion group.

**NOTE**
========
PLEASE **DO NOT** under ANY circumstances send e-mail containing solutions to homework or tests to the group address!!  No excuses -- *YOU* are responsible for checking the TO address on your outgoing e-mails BEFORE you send them.  If you do, the consequence is that I will have to stop the process and change the assignment for the students who have not yet submitted their work.  I may also choose to penalize your score for this, so PLEASE PAY ATTENTION WHERE YOU'RE SENDING e-mail containing answers or personal information!


BOOK:
=====
We'll be using the required text book:

Pont, Michael J. (Paperback)
        "Embedded C" (With CD-ROM)
        ISBN 0  201 79523 X

The book is available used and new from a number of sources, including:
Book Emporium:
http://www.bookemporium.com/bookdetails.cfm?isbn=020179523X

Amazon:
http://www.amazon.com/gp/product/020179523X/104-9695575-1365504?v=glance&n=283155&s=books&v=glance

If the links above are stale, search the main sites with the ISBN number 020179523X


The text is also in the UCSD bookstore in the extension section.  You can go pick it up there, have it delivered to the front desk in the same building where class is held, or shipped directly to you.  See http://bookstore.ucsd.edu for more info.

You may also find the book at other bookstores.

We’ll also be using the manuals (SDCC sdccman.pdf and Keil c51.pdf and getstart.pdf on the hte.com web site above), in addition to the text.


=======
The SDK:
=======
The SDK used in this course is the same one used in ECP I, and you should be familiar with the setup and use of the SDK with your PC’s COM port, terminal emulator program on your PC, and the use of the SDK’s ROM monitor commands.  If it has been a while since you used your SDK, be sure to get the manual and follow the setup instructions on the class web site near the top of the page under the link: SDK (8051 Development Board) http://hte.com/uconline/ecp/sdkinfo.htm

 

SOFTWARE DEVELOPMENT TOOLS:
===========================
We will be using two different compilers in this course.  One is a free, unlimited open source tool chain for the most flexibility, and one is an example of a full-featured, professional embedded development package.  They are:

1) SDCC

The primary compiler we'll be using is the open source freeware SDCC compiler.  SO THIS IS THE ONE YOU WILL NEED TO BECOME MOST FAMILIAR WITH: SDCC (Sandeep Dutta's C Compiler, or Small Device C Compiler).  This is a FREE unlimited command line compiler for the 8051.  This compiler supports floating point and files of any size up to the amount of available memory, but the version at sourceforge is a command line program and does *NOT* come with an IDE, so you must use it in a DOS box in Windows.  (There is a simple but free IDE from OpCube.com called MIDE-51.  More to follow on that below.)  The command line version of SDCC will work with make and batch files and is available for both Windows and Linux.  The source for the most current version is available at http://sdcc.sourceforge.net  Go to the download page and select the link for the OS you have on your PC (e.g. SDCC-win32 for Windows, or one of the Linux versions as appropriate)

2)  Keil

We will also be using the Keil package as an example of a full commercial tool chain.  The KEIL C51 compiler, which is part of their uV2 (Micro Vision 2) IDE (Integrated Development Environment)  The free evaluation version generates 8051 object files that are limited in size, without floating point support.  The full, unlimited commercial package costs from $500 to about $3000 depending on what features you want.  Available as the C51 evaluation package at www.keil.com the current demo version NO LONGER WORKS WITH THE SDK!  Only with their software simulator, so you cannot use that version for this class.

You can get the older version which **does** work with the SDK here:
http://hte.com/uconline/ecp/ek51v612s.exe


NOTE:
If you already own a commercial 8051 compiler, feel free to use it for your work in this course, but you will still need to know how to use the SDCC and Keil tools for the final exam and homework in this course.  Later courses in the curriculum will emphasize the SDCC compiler since it is not limited and will always work with the SDKs we use.

READING ASSIGNMENT:
===================
PLEASE READ: Pont "Embedded C" through page 56 (Chapters 1 & 2), the sections in the SDCC Compiler manual titled "Installing SDCC" and "Using SDCC," and Chapter 3 in the Keil C User's Manual "c51.pdf" on the hte.com web site.  Review the Keil "Getting Started" manual (getstart.pdf) if you have trouble with the Keil compiler.  The 2002 edition of the Pont text book also includes a CD with an older version of the Keil tools that does work on the SDK.

Another book of interest for this course has gone out of print, but you may be able to get a used copy.  It is a very useful reference with lots of examples relevant to this course, if you can get your hands on a copy.  It is by the same author:
        Pont, Michael "Patterns for Time-Triggered Embedded Systems"

Homework:
=========
The first homework due at the second lecture is: download and setup the development tools, modify, download and then run the hello program in C on your SDK as we discussed in class.

Homework assignments are announced by e-mail or on the web site.  The first assignment, the C "hello world" program should be turned in by the second lecture. 

==================
The Keil compiler:
==================
As it stands, the Keil Hello project will output to the 8051's *internal* serial port, on connector P1.

So you will have to move the serial cable from connector P5 to connecter P1 after downloading and executing the code in order to see the output on your PC.

Note that the "putchar" function that's on the web site is designed to work with the Keil compiler.  The Keil printf library function expects a char return value, whereas the SDCC compiler's putchar does not return anything (void).  So the SDCC and Keil versions are not interchangeable.

The necessary files for the first homework are available at:

        http://www.hte.com/uconline/ecp

Scroll down to the ECP II section 7, and you will see links to the hello world program.

Note that the files named *.uv2 can only be opened by version 2 of the Keil tools.

You will need to download the version of the Keil software from the link above, and then follow the instructions to install the demo compiler and IDE.  Unfortunately, Keil has severely limited the demo version that's available on their web site, so we cannot use it anymore.  It is a full featured demo with all the bells and whistles, however it is limited to generating 2KBytes of code at 0x0800, and since the printf() library function uses about 1.5KB, it's not very useful except for very simple programs anyway.  The unlimited version costs hundreds to thousands of dollars, so it is not an option for most students.  The Keil C51 evaluation package in the current text book may not work with the SDK either. 

After you get the Keil version working with both serial ports, try using the SDCC compiler.

SDCC is freeware (Sandeep Dutta's Small Device C Compiler)
This is a free and unlimited compiler for the 8051 family processors.  It is a DOS/Linux command line based compiler, but there is also MIDE-51 a simple IDE that can be used with the SDCC compiler that makes it easy to use in Windoze.  It doesn't have all the cool features of the Keil package, but it does the job.

**IMPORTANT:**  When using the SDCC compiler, you must compile the code at location 0x4000 for it to load and run on the SDK!  See the MIDE/SDCC documentation for details.

==================
The SDCC compiler:
==================

The current manual is at:
        http://sdcc.sourceforge.net/doc/sdccman.pdf
        http://sdcc.sourceforge.net/doc/sdccman.html/

Start with MIDE-51, an IDE for the SDCC package, is available here:
        ftp://hte.com/uconline/library/tools/
in the file:
        ftp://hte.com/uconline/library/tools/midepack0247.exe

The original MIDE-51 came from the author's web site and the most current version can be found at:

         http://www.opcube.com

There's a version of the IDE with editor, SDCC compiler and ASEM assembler in one download package.  The most recent version also has an evaluation version of a simulator.  To get the combined version from their web site, click on the link: "download packed file"

The SDCC "home page" is on the main SDCC web site, where you can get the command line version:
         http://sdcc.sourceforge.net/

You should install both the command line SDCC and the MIDE version as you will likely need both versions.


Click the "SDCC Manual" link under "Documentation" for HTML or get the PDF file at:
         http://sdcc.sourceforge.net/doc/sdccman.pdf

*** Note that you must change the compiler options to put the code at 0x4000 for the SDK.  For MIDE, look under the menu Edit|Preference (or F12 key), click on the C-compiler tab, and add the following:

         --code-loc 0x4000

Or just use the --code option above on SDCC at the command line.


Then the code will be located at 0x4000 as required for the SDK. 

 

IMPORTANT: SDCC printf output on SDK serial connector P5

In order to make printf() output visible, you must also have a putchar function to output characters to one of the SDK's serial ports.  The putcharMonitor.c file will output to the same serial port used by the SDK monitor ROM, so you don't have to switch the cable to see the output from printf. Include the putcharmonitor.c at ftp://hte.com/uconline/ecp/sdkcode/SDCCsources/putcharMonitor.c function in your programs and printf output will be directed to the same serial port used by the monitor (connector P5) so you don’t have to move the cable to the other serial port after running the SDCC version of your program.

==========================
**ECP 2 DISCUSSION LIST:**
==========================
There is a discussion list for both live and on-line students in the ECP II course:

        ecp2group_AT_hte.com

You will receive a welcome message when you have been added to the list.  I will put everyone on the discussion list, but you may un-subscribe or add other addresses as you wish.  You will receive a separate welcome message once the list is set up. 

I STRONGLY encourage you to post questions on the ECP2 discussion list first.  You can ask and answer questions for this class there.  The group membership reflects the students enrolled in the current quarter ECP II section(s).  As it was for the ECP I list, you can access the group message archives on the group web site and subscribe to the e-mail version, with a number of options.

You can subscribe additional e-mail addresses to the list if you are not already on it.

To start sending messages to members of this group, simply send email to

        ecp2group_AT_hte.com

**PLEASE DO NOT send complete homework solutions or other answers to the list -- however, code excerpts are okay.

You CAN send complete homework solutions, working or otherwise to the auto-responder for this class and you will receive my solutions, as is described in a separate e-mail to follow later.

Questions about the homework can be sent to the discussion list, and if you don't get an answer after a day or two, send your request to ecp2_AT_hte.com

Remember to send your individual class related questions, correspondence and homework questions to ecp2_AT_hte.com 


****************************************************************
To those of you who weren't in the ECP I class that just ended :
****************************************************************

If you don't have a working SDK, contact me ASAP, as it is essential for the assignments in this course.

If you haven't already done so, or if you are unable to get the Hello program in C to work, you should hook up your SDK and do the simple Hello World program example in the SDK User's Manual to make sure everything is operating correctly.

*** PLEASE *** be sure to pay attention to the diagram showing the correct orientation of the power connector to the SDK, as it is possible to damage the board by connecting it improperly.  This is described and pictured on page 12 of the SDK manual if you have the Rev C board, and in a separate addendum page if you have the Rev D board.  The revision is written on the top edge of the board in white letters.

*** Store your SDK in the metallized plastic bag when not in use and avoid touching the board until after you have grounded yourself to dissipate any electrostatic charge you may accumulate.

The information on the SDK, and programming it in assembly and C on the ECP home page:

        http://www.hte.com/uconline/ecp/

and     ftp://ftp.hte.com/uconline/ecp

The page above has assembly and C programming examples for the SDK.  Scroll down to the ECP II part of the home web page (http://www.hte.com/uconline/ecp/) to get more info and click on the current week's info for examples of C code that runs on the SDK.

Setup videos, the manual, chip data sheets, and other info for the SDK are here:
        http://www.hte.com/uconline/ecp/sdkinfo.htm

The manual has a section, starting on page 12 that describes how to assemble, download and run a Hello World assembler program, and the ECP II link below has the Hello World program in C, in a self extracting ZIP file.
        http://www.hte.com/uconline/ecp/hello1.exe

E-mail the discussion group or call me if you have trouble getting your SDK or PC to work.

HOMEWORK info (This relates to the KEIL package)
================================================
Students often have questions regarding the Hello program, so here is some more background info I don't always go over in detail in the lecture.  This should alleviate most of the difficulties you may experience.

While you can use the simulator/debugger that's part of the Keil IDE, we did not go over that in class, and I don't expect you to use that for the Hello program.  Note that the hardware on the SDK (e.g. special memory maps and memory mapped external UART) is NOT supported by the Keil simulator.

If you download the hello.exe program, and run it as it stands, it defaults to the 8051's INTERNAL serial port unless you add the putchar.a51 file to the Hello project.  It's in the hello1.txt file comments.  The hello program, as it stands, uses the 8051's on-chip serial port for printf output, so you have to use a second serial cable or move the connector from the SDK's debug serial port (connector P5) to the internal 8051 serial port on the DB connector (P1) in order to see the output message.  After loading the unmodified program, you can start it with the GO command [g 4000] and then move the connector on the serial cable.  Then you should see the hello message displayed repeatedly.  (If you use the Execute command instead of GO, the serial data comes out at full speed so the PC's serial port may not sync up with the SDK's output depending on the instant in time that you make the connection, if the first bit it sees is not the start bit.)

There are three important files inside the hello1.exe self extracting ZIP file, which must be present in order for the program to work on the SDK: startup.a51, putchar, and hello1.uv2.

The first two files have the SDK specific code to locate the program at 0x4000 and send output to the serial port.  The default printf goes to the 8051's on-chip serial port, and the separate putchar function sends printf output to the monitor debug port (external memory mapped UART) instead of the 8051's internal serial port.  The third file has all the options for the compiler, linker and locator to allow code to run on the SDK. You **MUST** use these files rather than the ones provided by Keil.

>>>If you want to run the example without moving the cable, you need to use the putchar.a51 program on the web page.  The file must be included in the hello project file, and is at:

        http://www.hte.com/uconline/ecp/putchar.a51

Remember that you also need to add the file to the uVision 2 project folder, or the compiler won't include it even if it's in the same Windows directory or folder as the other code. 

There is a bug in the project window, such that the only way to remove a file is by clicking on it in the project window once and pushing the delete key on your keyboard. Right-clicking the file in the project window and selecting delete doesn't always work.

Note that source files downloaded form the web page might have the wrong name/type, since Internet Explorer may "help" you by appending ".txt" to the end of the file name when you download it.

Then you must open the .UV2 file and use the "Project" | "Rebuild all" menu selections (or click the corresponding icon) to force all the files to be recompiled and linked.

Once you have the homework functioning with the Keil tools, try the MIDE-51/SDCC tools.

Hopefully this will take care of most of the problems, but if not, try the group discussion list and web/ftp site for help or send an e-mail to ecp2_AT_hte.com.

The slides for ECP II lecture 2 are available on the class web site under "Section 8 - Embedded C Programming Review and Examples":

        http://www.hte.com/uconline/ecp/section8.htm

Please scan the notes and the compiler manuals prior to the second lecture, as we will be discussing them in class.

Welcome to ECP II: Embedded C !

 - Ken