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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13<br />

Listing 13-1. Source file for a simple program to test assembly-language<br />

interfacing with BASIC-52.<br />

org 3000h ;location where program will<br />

;load in RAM<br />

cpl p1.0 ;complement Port 1, bit 0<br />

;(pin 1)<br />

ret<br />

;return to BASIC-52<br />

end<br />

specifies 3000h. You can change the address to match whatever locations you have available<br />

in your system.<br />

<strong>The</strong> program body’s single instruction complements bit 0 of Port 1, changing it from high<br />

to low or low to high. A ret instruction then returns control to BASIC-52.<br />

To create and test the routine, do the following:<br />

Use a text editor to create a file containing Listing 13-1.<br />

Use your assembler to assemble the file. A typical command line looks like this:<br />

A51 bittog.asm -L bittog.lst -O bittog.hex<br />

<strong>The</strong> above command tells the assembler to create two files: the listing file bittog.lst (shown<br />

in Listing 13-2) and the object file bittog.hex, in Intel hex format (shown in Listing 13-3).<br />

File Formats for Assembly-language Routines<br />

This is a good time to look at Intel Hex and other file formats in greater detail. Most EPROM<br />

programmers are able to program EPROMs directly from the files created by assemblers<br />

and compilers, but the file must be in a format that the programmer recognizes. Three<br />

Listing 13-2. Listing file created by assembling the source file in Listing 13-1.<br />

3000 org 3000h ;location where program will<br />

;load in RAM<br />

3000 b2 90 cpl p1.0 ;complement Port 1, bit 0<br />

;(pin 1)<br />

3002 22 ret ;return to BASIC-52<br />

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

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

Saved successfully!

Ooh no, something went wrong!