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.

• BASIC-52’s ON EX1 instruction will also respond to external interrupt 1, but the<br />

response time will be much slower. ON EX1 has priority, however, and Listing 13-6<br />

will not execute if an ON EX1 statement has executed in BASIC-52.<br />

• When BASIC-52 jumps to an assembly-language interrupt routine, it automatically<br />

pushes psw on the stack. But popping psw on returning from the interrupt routine is not<br />

automatic, so the interrupt routine must include an instruction to do so.<br />

• Unlike other subroutines, which end with ret, interrupt routines must end with reti.<br />

To test Listing 13-6, upload it to RAM at 4013h, and execute these two lines of BASIC-52<br />

code, to ensure that the interrupt is enabled:<br />

IE=IE.OR.84h<br />

TCON=TCON.OR.04h<br />

Now, each time pin 13 goes low, pin 1 should toggle, as it did with Listing 13-1.<br />

Adding Custom Commands and Instructions<br />

Calling Assembly-language Routines<br />

Another feature of BASIC-52 is the ability to add up to 16 custom keywords representing<br />

commands or instructions that you define with assembly-language routines. Listing 13-7 is<br />

an example program for doing so.<br />

To add custom keywords, you must have code memory from 2000h to 2071h, because<br />

BASIC-52 looks for special information at several addresses in this area.<br />

On bootup, BASIC-52 examines the data at address 2048h. If bit 5 is set, BASIC-52 assumes<br />

that you have added custom keywords, and it looks for additional information in a token<br />

table and vector table.<br />

At 2078h, BASIC-52 expects to find the starting address of a token table, which lists your<br />

new keywords. At 2070h, it expects the starting address of a vector table, which lists the<br />

assembly-language routines that the new keywords execute.<br />

You may upload both tables to any free area of combined code/data memory. If you’re using<br />

an external EPROM programmer, you can use code-only memory in the 8052-BASIC<br />

system.<br />

In the token table, each new keyword is assigned a number, in sequence from 10h to 1Fh.<br />

<strong>The</strong> name of the keyword is surrounded by quotation marks, and a 0 indicates the end of the<br />

token. <strong>The</strong> final keyword in the list ends in 0FFh, to signify the end of the list of tokens.<br />

Listing 13-7 adds three keywords, which toggle, set, and clear bit 0 of Port 1.<br />

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

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

Saved successfully!

Ooh no, something went wrong!