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.

Chapter 13<br />

Listing 13-6. This assembly-language routine is similar to Listing 13-1,<br />

except that external interrupt 1 causes the routine to run.<br />

;On external interrupt 1, Port 1, bit 0 is complemented<br />

org 4013h ;vector for external<br />

;interrupt 1<br />

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

;(pin 1)<br />

pop psw ;push psw was automatic on<br />

;interrupt,<br />

;but pop psw must be added<br />

reti<br />

end<br />

and add this to the end, before returning to BASIC-52:<br />

pop psw ;restore program status word<br />

Your routine can then write to registers R0-R7 without worrying about conflicting with<br />

BASIC.<br />

Interrupts<br />

BASIC-52 also includes a way of adding assembly-language routines that respond to<br />

interrupts. Normally, the 8052 stores its interrupt vectors (the locations where the program<br />

jumps on interrupts) from 03h to 2Bh in code memory. Since these locations are in ROM in<br />

the 8052-BASIC, your programs can’t change their contents. But built into BASIC-52 is the<br />

ability to place alternate interrupt routines from 4003h to 402Bh.<br />

To illustrate, Listing 13-6 is an assembly-language interrupt routine. <strong>The</strong> routine’s origin is<br />

4013h, which is BASIC-52’s alternate vector for external interrupt 1. <strong>The</strong> interrupt routine<br />

has the same function as Listing 13-1. It toggles bit 0 of Port 1, then returns to BASIC-52.<br />

<strong>The</strong>se are a few things of note about Listing 13-6:<br />

• You must have code memory at 4013h, since BASIC-52 specifies that this location<br />

must contain either the interrupt routine or a jump to a longer routine. If the routine is<br />

longer than 8 bytes, use a jump instruction, such as sjmp 4033h, to prevent overwriting<br />

any interrupt vectors that follow.<br />

232 <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!