HELLO: YOUR FIRST 8051 PROGRAM

HELLO is a simple program, located in the \FSI\EXAMPLES\HELLO\  directory, that does nothing more than print “Hello World” to the serial port.  The entire program is contained in a single source file, HELLO.C, which is listed below.

YOUR FIRST 8051PROGRAM:
HELLO Project File

Editing HELLO.C

COMPILING AND LINKING HELLO FROM PROVIEW

TESTING AND DEBUGGING HELLO

LOADING WINSIM FROM PROVIEW

RUNNING WINSIM

SOURCE CODE:

/*****************************************************************************
* For information on creating a project file for this example *
* please see the “Quick Start” section in ProView help *
* *
* CREATE A PROJECT: *
* 1. Open ProView (you probably already have ProView Open) *
* 2. Select NEW from the PROJECT menu *
* 3. Name the project HELLO ( ProView will add file extension ) *
* 4. Use BROWSE to select the directory \FSI\EXAMPLES\HELLO CLICK[OK] *
* ADD SOURCE FILES TO PROJECT *
* 5. Select ADD FILE from the PROJECT menu *
* 6. Select HELLO.C from the list CLICK[OK]
* SET THE PROJECT OPTIONS *
* 7. Select PROJECT from the OPTIONS menu *
* In these dialog boxes is where you set the build options for *
* the source files in the project. HELLO uses the default options *
* MAKE THE PROJECT *
* 8. Select MAKE from the PROJECT menu *
* MAKE will Compile and Link the files in the project *
* RUN HELLO (DEBUG) *
* 9. Select START from the DEBUG menu *
* 10. Select the default VIRTUAL MACHINE (Simulator) CLICK[OK] *
* 11. Select HARDWARE from the VIEW menu *
* 12. Select UART (This will let you see the serial port output) *
* 13. Select RUN from the DEBUG menu (this will start the program) *
* “Hello World” should now appear in the UART window *
* 14. Select STOP from the DEBUG menu *
* END DEBUG SESSION *
* 15. Select TERMINATE from the DEBUG menu to return to EDIT mode *
* *
* You have just built and debugged you first project *
* *
*****************************************************************************/


#include <reg51.h> /* special function register declarations */
/* for the intended 8051 derivative */

#include <stdio.h> /* prototype declarations for I/O functions */


/****************/
/* main program */
/****************/
void main (void) { /* execution starts here after stack init */
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xf3; /* TH1: reload value for 2400 baud */
TR1 = 1; /* TR1: timer 1 run */
TI = 1; /* TI: set TI to send first char of UART */

printf ("Hello World\n"); /* the 'printf' function call */

while (1) { /* An embedded program does not stop and */
; /* ... */ /* never returns. We've used an endless */
} /* loop. You may wish to put in your own */
} /* code were we've printed the dots (...) */

This small application demonstrates how to compile, link, and debug an application using the C51 compiler, the L51 linker/locator, and the WinSim-51 debugger/simulator—all from within ProView-51.