18.11.2014 Views

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Successful assembly is a good sign, but it doesn’t mean that the program is error-free. As in<br />

any programming language, a line of code may contain instructions that are valid, but that<br />

do not do what you intended. It’s a good idea to at least scan the listing created by the<br />

assembler before you try to run a routine, to look for obvious errors.<br />

Different assemblers may have slightly different syntax rules. For example, some require<br />

org and end to have a leading period (.org, .end). Check your assembler’s documentation<br />

for the specifics.<br />

Uploading a Program<br />

Calling Assembly-language Routines<br />

When you’re ready to load the program into RAM, boot your 8052-BASIC system, connect<br />

the serial link to your personal computer, and run your communications software. Use the<br />

software to upload Listing B-1 or B-2, in the same way that you upload any BASIC-52<br />

program from disk.<br />

For loading Intel hex files, you can set up your host computer’s software so that it waits to<br />

receive the BASIC-52 “>” prompt (ASCII code 62) after each uploaded line. This will ensure<br />

that BASIC-52 has enough time to process each line before the next one arrives. Use this<br />

method only with Intel Hex files, not BASIC-52 programs. If a BASIC-52 program contains<br />

any “>” (greater than) operators, the software will think that these indicate the end of a<br />

program line. Intel Hex files contain no “>” characters, so there is no problem.<br />

If you want to wait for the “>” character, in Procomm Plus, from the Setup menu, select<br />

Terminal Options, then Protocol Options, ASCII Options, and set the pace character to 62.<br />

Character pacing and line pacing can be 0. In the Windows terminal, select Settings, then<br />

Text Transfers, One Line at a Time, and enter “>” under Wait for Prompt String. Other<br />

software should have similar abilities.<br />

If you wish, you can use BASIC-52’s (F)PROG command to store the program in NV<br />

memory so it’s available without having to upload each time.<br />

To use Listing B-1 or B-2, run the program and, at the prompt, use your communications<br />

software to upload your object file. <strong>The</strong> file will load into the locations specified by your<br />

source file. <strong>The</strong> program will display error messages if it has problems with the uploading.<br />

For proper calculation of the programming-pulse width in Listing B-2, set BASIC-52’s<br />

XTAL operator to match your crystal’s frequency.<br />

If the file loads successfully, you’re ready to test it. Connect a logic probe to pin 1 on the<br />

8052, or set a voltmeter to measure the voltage from pin 1 to pin 20 (ground) on the chip.<br />

To call your subroutine, enter and run this BASIC-52 program:<br />

<strong>The</strong> <strong>Microcontroller</strong> <strong>Idea</strong> <strong>Book</strong> 225

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!