ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 15.06.2025

Просмотров: 2208

Скачиваний: 1

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

Calling Assembly-language Routines

Listing

13-7. (page 2 of 2)

;can add up to 1Fh tokens

;final token must end with 0ffh

org

vectortable

;vector table address

dw

tggp10

;label to branch to on

;TGGP10 command

dw

setp10

;label to branch to on

;SETP10 command

dw

clrp10

;label to branch to on

;CLRP10 command

tggp10

org 3000h

;use any available address

cpl

p1.0

;complement Port 1, bit 0

;(pin 1)

ret

;return to BASIC-52

setp10

org 3010h

;use any available address

setb

p1.0

;set Port 1, bit 0 (pin 1)

ret

;return to BASIC-52

clrp10

org 3020h

;use any available address

clr

p1.0

;clear Port 1, bit 0 (pin 1)

ret

;return to BASIC-52

end

The vector table consists of a list of labels corresponding to the beginning of each assembly-language routine.

In addition to the tables, you must store the assembly-language routines themselves, again using any free code/data or code memory.

To use Listing 13-7, you must assemble it and upload the resulting Intel Hex file into NV memory that will be preserved on powering down or rebooting. Reboot, and you can use the new keywords TGGP10, SETP10, and CLRP10 to control bit 0 of Port 1. (Notice that the “bit-toggle”keyword is TGGP10, rather than TOGP10, which contains the keyword TO and so won’t work.)

The Microcontroller Idea Book

235


Chapter 13

Listing 13-8. (page 1 of 2) Copies data from external memory into EPROM, EEPROM, or NV RAM.

10

PRINT “enter device type: ”

20

PRINT “EPROM 50-msec

1"

30

PRINT “EPROM Intelligent

2"

40

PRINT “EEPROM or NV RAM

3"

50

PRINT “quit

4"

60

INPUT T

70

REM set pulse width for device type

80

REM W = pulse width in milliseconds

90

IF T=1 THEN W=.05

100

IF T=2 THEN W=.001

110

IF T=3 THEN W=.0005

120

IF T=4 THEN GOTO 470

130

REM calculate and store pulse width

140

B=(65536-(W*XTAL/12)) : GOSUB 500

150

DBY(40H)=BH : DBY(41H)=BL

160

REM set up for intelligent programming or not

170

I=DBY(26H)

180

IF W=.001 THEN DBY(26H)=I.OR.8 ELSE DBY(26H)=I.AND.0F7H

190

INPUT “starting address of data to copy (source)? ”,S

200

IF S<200H OR S>0FFFFH THEN

GOTO 190

210

INPUT “ending address of data to copy (source)? ”,E

220

IF E<S OR E>0FFFFH THEN GOTO 210

230

INPUT “starting address to program (destination)? ”,P

240

IF P<MTOP OR P>0FFFFH THEN

GOTO 230

250

REM calculate and store number of bytes to program

260

B=(E-S)+1 : GOSUB 500 : DBY(1FH)=BH : DBY(1EH)=BL

270

REM store starting address of destination-1

280

B=P-1 : GOSUB 500 : DBY(1AH)=BH : DBY(18H)=BL

290

PH0. “eprom low = ”,BL

300

PH0. “eprom high = ”,BH

236

The Microcontroller Idea Book


Calling Assembly-language Routines

Listing 13-8. (page 2 of 2)

310 REM store starting address of source

320 B=S : GOSUB 500 : DBY(1BH)=BH : DBY(19H)=BL

330 PH0. “ram low = ”,BL

340 PH0. “ram high = ”,BH

350 PRINT “press ENTER to begin programming”

360 X=GET : IF X<>0DH THEN 360

370 REM program the EPROM

380 PRINT “programming in progress...”

390 PGM

400 REM check for errors

410 IF (DBY(1EH).OR.DBY(1FH))=0 THEN PRINT “programming OK”

:GOTO 470

420

REM on error, calculate address that failed to program

430

DC=DBY(19H)+256*DBY(1BH)-1

440

PH0. “ERROR: Source address

”,DC," = “,XBY(DC)

450

DP=DBY(18H)+256*DBY(1AH)

460

PH0. “

Destination address ”,DP," = “,XBY(DP)

470

END

500 REM separate B into high (BH) and low (BL) bytes 510 BL=(B.AND.0FFH)

520 BH=INT(B/256)

530 RETURN

A General-purpose EPROM Programmer

With Listing B-2, you can use an 8052-BASIC system as a general-purpose programmer for EPROM, EEPROM, or NV RAM. The program will read any file in Intel Hex format, and store it at the addresses specified in the file.

For example, you can add a socket for an 8K EPROM, EEPROM, or NV RAM addressed at A000h-BFFFh in combined code/data memory. For EEPROM or NVRAM, wire the socket exactly like U8 in Figure 4-3, except wire pin 1 of U9 to chip-select A000h (pin 10 of U6 in Figure 3-1) instead of to 8000h. For EPROM programming, also connect Figure 4-5’s circuits to pins 1 and 28 of the EPROM, for the programming voltages.

The Microcontroller Idea Book

237

Chapter 13

With these added components and Listing B-2, you can program a DS1225 NV RAM, a 28(C)64 EEPROM, or a 27(C)64 EPROM with an Intel Hex file.

One use would be to program an EPROM for a non-BASIC-52 system, where EA is tied low and on bootup, the 8052 runs a program beginning at 0 in external code memory, instead of running the BASIC-52 interpreter in internal ROM. For this use, you must add A000h to the values given in all ORG directives. For example, you would change ORG 0 to ORG A000h, and change ORG 200h to ORG A200h. You can then use Listing B-2 to copy the program into the EPROM at A000h, remove the EPROM and install it at 0 in code memory in your non-BASIC-52 system. On bootup, the 8052 will run the program in EPROM.

Another Way to Program EPROMs

Listing 13-8 is another program that you can use to copy information from external data memory into an EPROM, EEPROM, or NVRAM. To use this program, you must specify the locations to copy (the source), the locations to copy to (the destination), and the device type to copy to. The program does the rest. With this program, you can copy information directly from RAM or other memory to another device, without uploading or translating to Intel Hex format.

The program prompts you for and stores information about the programming algorithm and addresses to program and copy from. BASIC-52’s PGM instruction then uses this information to program the selected locations.

238

The Microcontroller Idea Book


Running BASIC-52 from External Memory

14

Running BASIC-52 from External Memory

Most BASIC-52 circuits use the 8052-BASIC chip with the BASIC-52 interpreter in internal ROM. This is convenient, but another option is to place BASIC-52 in external EPROM, EEPROM, or NV RAM. Two reasons for doing so are to save money and to enable you to customize BASIC-52 by modifying and reassembling BASIC-52’s source file.

For those who want to experiment with BASIC-52 in external memory, this chapter shows how to copy the BASIC-52 interpreter from ROM into NV RAM, and how to design and use a system with BASIC-52 in external memory.

Reasons

Placing BASIC-52 in external memory can save money, although as prices for the 8052BASIC chip have dropped, the savings have become minimal. Still, if you find a good deal on 8032s or 8052s and 8K EPROMs, you might find it worthwhile to build systems with these rather than using the single-chip 8052-BASIC. In your calculations, though, remember that sockets and board space add cost, not to mention the extra time involved in wiring or laying out a printed-circuit board for the added component.

The Microcontroller Idea Book

239

Chapter 14

For experienced assembly-language programmers, another reason for placing BASIC-52 in external memory is so that you can modify the source file for BASIC-52. You then can reassemble your modified source file and use the new version in your projects. In this way, you can add functions or make other changes to BASIC-52 itself. To do this, you must have a copy of BASIC-52’s source code, which has been available on Intel’s and Philips’ BBS’s, plus Intel’s ASM51 or a compatible 8051-family assembler.

Iota Systems is one vendor that has customized BASIC-52 in this way, with an expanded BASIC-52 PLUS that runs from external EPROM on Iota’s 8052-BASIC boards. BASIC-52 PLUS includes commands for uploading and downloading Intel Hex files, as well as other enhancements and bug fixes.

Copying BASIC-52

To copy BASIC-52 from ROM to NVRAM, you can use the same circuits shown in Figures 3-1 and 4-3. Use a DS1225 8K NV RAM at U8. Listing 14-1 is a program that copies the 8052-BASIC’s ROM from 0 to 1FFFh in internal code memory to U8 at 8000-9FFFh in external data or code/data memory. Boot up your system, enter or upload Listing 14-1 and run it. Then power down and remove the NV RAM at U8, which now contains a copy of BASIC-52.

If you prefer, you can use a 28(C)64 8K EEPROM instead of NV RAM at U8. Because the write-cycle time of EEPROMs is often 2 to 10 milliseconds, you may have to slow Listing

Listing 14-1. Copies the BASIC-52 interpreter program from ROM to

NVRAM.

10

PRINT “copying BASIC-52 from ROM to RAM at 8000h...”

20

FOR I=0 TO 1FFFH

30

XBY(I+8000H)=CBY(I)

40

NEXT I

50

PRINT “verifying...”

60

X=0

70

FOR I=0 TO 1FFFH

80

IF XBY(I+8000H)<>CBY(I) THEN GOSUB 120

90

NEXT I

100

IF X=0 THEN PRINT “Copy successful”

110

END

120

PH0. “Error at location ”,I

130

X=1

140

RETURN

240

The Microcontroller Idea Book