Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

The Microcontroller Idea book (Jan Akelson, 1997)

.pdf
Скачиваний:
223
Добавлен:
12.08.2013
Размер:
2.93 Mб
Скачать

 

Sources

 

Micro Future

BASIC-52 programming environment

40944 Cascado Place

 

 

Fremont, CA 94539

 

 

510-657-0264

 

 

Micromint

80C52-BASIC chip, systems, related products

4 Park Street

 

 

Vernon, CT 06066

 

 

203-871-6170

 

 

Midwest Micro-tek

8052-Basic boards

2308 E. 6th St.

 

 

Brookings, SD 57006

 

 

605-697-8521

 

 

Mitel Semiconductor

switch-matrix chips

P.O. Box 13089

 

 

Kanata, Ontario K2K 1X3

 

 

Canada

 

 

1-800-267-6244

 

 

613-592-2122

 

 

National Semiconductor Corporation

linear, digital ICs

2900 Semiconductor Drive

 

 

P.O. Box 58090

 

 

Santa Clara, CA 95052-8090

 

 

408-721-5000

 

 

1-800-272-9959

 

 

Newark Electronics

electronic components

4801 N. Ravenswood Ave.

 

 

Chicago, IL 60640-4496

 

 

312-784-5100

 

 

Omega Engineering

sensors

One Omega Drive

 

 

Box 4047

 

 

Stamford, CT 06907

 

 

1-800-826-6342

 

 

The Microcontroller Idea Book

259

Appendix A

Optek Technology

optoelectronic components

1215 West Crosby Rd.

 

Carrollton, TX 75006

 

214-323-2200

 

Philips Components/Signetics

8052 chips, data books

811 East Arques Ave.

 

P.O. Box 3409

 

Sunnyvale, CA 94088

 

408-991-2000

 

Photronics Research

high-speed BASIC-52 in Dallas DS87C520

109 Camille St.

 

Amite, LA 70422

 

504-748-7090

 

Prologic

8052-BASIC pc board, kit

P.O. Box 19026

 

Baltimore, MD 21204

 

410-661-5950

 

PseudoCorp

8051 assembler

716 Thimble Shoals Blvd., Suite E

 

Newport News, VA 23606

 

804-873-1947

 

Rigel Corporation

8051 book

P.O. Box 90040

 

Gainesville, FL 32607

 

904-373-4629

 

Sensors Magazine

Sensors Buyer’s Guide

Helmers Publishing, Inc.

 

174 Concord St.

 

P.O. Box 874

 

Peterborough, NH 03458-0874

 

603-924-9631

 

Sharp Electronics

optoelectronic components

Microelectronics Group

 

5700 NW Pacific Rim Blvd., M/S 20

 

Camas, WA 98607

 

206-834-2500

 

260

The Microcontroller Idea Book

Sources

Siemens Components

8052 chips, data books

2191 Laurelwood Rd.

 

Santa Clara, CA 95054

 

408-980-4500

 

Siemens Components

optoelectronic components

Optoelectronics Division

 

19000 Homestead Rd.

 

Cupertino, CA 95014

 

408-257-7910

 

Sil-Walker

keypad kits

880 Calle Plano, Unit #N

 

Camarillo, CA 93012

 

805-389-8100

 

FAX: 805-484-3311

 

Suncoast Technologies

8052-BASIC board

PO Box 5835

 

Spring Hill, FL 34606

 

Voice/FAX: 352-596-7599

 

Systronix

BASIC compiler, BASIC-52 programming

555 South 300 East

manual

Salt Lake City, UT 84111

 

801-534-1017

 

FAX: 801-534-1019

 

BBS 801-487-2778

 

TAB-McGraw Hill

book publisher

P.O. Box 0850

 

Blue Ridge Summit, PA 17294-0850

 

1-800-262-4729

 

Timeline, Inc.

surplus LCD modules

1490 W. Artesia Blvd.

 

Gardena, CA 90247

 

1-800-872-8878

 

Unicorn Electronics

8052-BASIC chip, electronic components

10010 Canoga Ave. Unit B-8

 

Chatsworth, CA 91311

 

1-800-824-3432

 

The Microcontroller Idea Book

261

Appendix A

Universal Cross Assemblers

8051 assembler

P.O. Box 6158

 

Saint John, NB E2L 4R6

 

Canada

 

506-847-0681

 

262

The Microcontroller Idea Book

Programs for Loading Files

Appendix B

Programs for Loading Files

This appendix contains the BASIC-52 programs HEX2RAM.BAS and HEXLOAD.BAS described in Chapter 13. Use HEX2RAM.BAS to load an Intel Hex file from your host computer to RAM, including battery-backed (NV) RAM. The HEXLOAD.BAS programdoes the same, but also allows you to load the file into EEPROM or EPROM. HEX2RAM uses XBY, while HEXLOAD uses PGM, and is slower.

The Microcontroller Idea Book

263

Appendix B

Listing B-1 (page 1 of 2). HEX2RAM.BAS loads Intel Hex files from a host computer to memory in the 8052-BASIC system. Reprinted with permission from

Systronix.

10 STRING 82, 80 : DIM HI (70) : DIM LOW (70)

15FOR I=48 TO 57 : HI(I) = (I - 48) * 16 : LOW(I) = I - 48 : NEXT

25 FOR I=65 TO 70 : HI(I) = (I - 55) * 16 : LOW(I) = I - 55 : NEXT

35 PRINT TAB(19),"INTEL HEX FILE TO RAM LOADING PROGRAM V1.1" 45 PRINT TAB(14), “Copyright 1991 Systronix Inc. All rights

reserved.” : PRINT

55PRINT TAB(8),"This program accepts as input an Intel hex file and stores"

65PRINT TAB(8),"it in external RAM at the addresses specified in the HEX file.":PRINT

75PRINT TAB(8),"Ready to receive the input file one line at a time. Set your"

85 PRINT TAB(8),"communication software to send a line when when it receives"

95 PRINT TAB(8),"the ’>’ prompt." : PRINT

100LINE=LINE+1 : INPUT “>”,$(0) : PRINT"Validating and storing...",

105 C = ASC($(0),1) : IF C<>58 THEN GOTO 500

REM Get the byte count and save it in the variable COUNT 115 I = 2 : GOSUB 700 : COUNT = CH

REM Get the starting address for this record’s data

125FOR I = 4 TO 7 STEP 2 : GOSUB 700 : ADDR = (ADDR * 256) + CH : NEXT

REM Get the record type (we only understand types 0 and 1)

135I = 8 : GOSUB 700 : IF (CH <>0 .AND. CH <>1) THEN GOTO 510

145 RECORD = CH

REM The initial checksum calculation

155 CHECK=(ADDR/256)+(ADDR.AND.0FFH)+COUNT+RECORD

REM Get the individual bytes, accumulate them in the check sum and store

REM them in memory at the appropriate destination

165 FOR I = 10 TO 10 + (COUNT * 2) STEP 2 : GOSUB 700

264

The Microcontroller Idea Book

Programs for Loading Files

Listing B-1 (page 2 of 2).

REM Here we deal with the data bytes (not executed when RECORD is type 1)

175 CHECK=CHECK+CH

185 IF RECORD = 1 THEN GOTO 210

REM Store the data in RAM 195 XBY(ADDR)=CH

205if CBY (ADDR) <>CH THEN GOTO 550 ELSE ADDR = ADDR + 1 : NEXT

210 CHECK=CHECK.AND.0FFH : IF CHECK<>0 THEN GOTO 520

215 IF RECORD = 1 THEN GOTO 640

REM Reset and continue

225 ADDR = 0 : PRINT CR : GOTO 100

REM Error messages and program termination

500PRINT CR, “Line ”, LINE, “: Character”, I, “unexpected” : GOTO 600

510PRINT CR, “Line ”, LINE, “: Unknown record type”, CH : GOTO 600

520 PRINT CR, “Line ”, LINE, “: Checksum failure. Expected”, 525 PH0. ABS (CHECK-CH) : GOTO 600

550PRINT CR, “Line”, LINE, “: Verify error at address”, : PH0. ADDR

555 PH0. “The byte at”, addr, “ is”, CBY (ADDR) 565 PH0. “The byte should be”, CH : GOTO 600

600PRINT “Stop sending input file. Type a CONTROL+C to quit.”

605 GOTO 605

REM Normal program exit point

640 PRINT CR, “Received an End record in line”,LINE : END

REM Convert the ASCII text to numbers

700 C = ASC($(0),I) : CH = HI(C) : C = ASC($(0),I + 1) : CH = CH + LOW (C)

705 RETURN

The Microcontroller Idea Book

265

Appendix B

Listing B-2 (page 1 of 4). HEXLOAD.BAS copies an Intel Hex file into RAM, EEPROM, or EPROM in an 8052-BASIC system.

1 STRING 82, 80

2 PRINT TAB(22),"HEX FILE LOADING PROGRAM 1.2"

3 PRINT TAB(14), “(C) 1990,1991 Systronix Inc. All rights reserved.” : PRINT

4 PRINT “This program accepts as input, an Intel format hex file and stores”

5 PRINT “it in RAM, EPROM, or EEPROM at the addresses specified.” : PRINT

6 PRINT : PRINT “Select the destination device type:” : PRINT

7 PRINT TAB(10), “[1] RAM” : PRINT TAB(10), “[2] Timed EEPROM”

8 PRINT TAB(10), “[3] EPROM (Intelligent algorithm)”

9 PRINT TAB(10), “[4] EPROM (50mS algorithm)”

10 PRINT TAB(10), “[5] EEPROM (RDY/BUSY type)”

11 INPUT “Select Device Type (1, 2, 3, 4, 5) >> ”, TYPE

12 IF (TYPE < 1) .OR. (TYPE 5) THEN PRINT CHR(7) : GOTO 11 20 TYPE=TYPE-1 : IF TYPE = 0 THEN GOTO 1300

21 if type = 1 then goto 22 else goto 30

22 INPUT “Delay between writes >> ”, delay : goto 1300 30 ON (TYPE) GOSUB 2100, 2100, 2110, 2120, 2100

40 IF TYPE = 2 THEN DBY(38) = DBY(38) .OR. 8 ELSE DBY(38) = DBY(38) .AND. 0f7H

rem Calculate and store pulse width

50 WAIT = 65536-WAIT*XTAL/12 : DBY(40H) = WAIT/256 : DBY(41H) = WAIT.AND.0ffH

1300 PRINT “Ready to receive the input file one line at a time. Set your”

1310 PRINT “communication software to send a line when when it receives”

1320 PRINT “the ’>’ prompt.” : PRINT

1330 SOURCE = MTOP - FREE + 1

1340 LINE = LINE + 1 : INPUT">", $(0) : PRINT “Validating input buffer ...”,

1350 I = 1 : C = ASC($(0),1) : IF C<>58 THEN GOTO 3000 : REM if not “:”

266

The Microcontroller Idea Book

Programs for Loading Files

Listing B-2 (page 2 of 4).

rem Get the byte count and save it in the variable COUNT 1360 I = 2 : GOSUB 2000 : COUNT = CH

rem Get the starting address for this record’s data 1370 FOR I = 4 TO 7 STEP 2 : GOSUB 2000 : ADDR = (ADDR *

256) + CH : NEXT

rem Get the record type (we only understand types 0 and 1) 1380 I = 8 : GOSUB 2000 : IF (CH <>0 .AND. CH <>1) THEN

GOTO 3010

1385 IF TYPE <>0 .AND. ADDR <8000H .AND. CH = 0 THEN GOTO 3040

1390 RECORD = CH

rem Get the individual bytes, accumulate them in the check sum and store

rem them in memory

1400 INDEX = SOURCE : FOR I = 10 TO 10 + (COUNT * 2) STEP 2 : GOSUB 2000

rem Here we deal with the data bytes (not executed when RECORD is type 1)

1410 CHECK=CHECK+CH

1420 IF RECORD = 1 THEN GOTO 1440

1430 XBY(INDEX)=CH : INDEX = INDEX + 1 : NEXT

rem Calculate the checksum

1440 CHECK=(CHECK+(ADDR/256)+(ADDR.AND.0FFH)+COUNT+RECORD).AND.0FFH

1450 IF CHECK<>0 THEN GOTO 3020

1460 IF RECORD = 1 THEN GOTO 3030

1470 PRINT CR, “Storing a Data record of”, COUNT, “bytes at”, : PH0. ADDR

rem Retreive the data from memory and store them in the proper addresses

1480 on type gosub 1500, 1570, 1520, 1520, 1520

rem Restore our variables and continue 1490 ADDR = 0 : CHECK=0 : GOTO 1340

The Microcontroller Idea Book

267

Appendix B

Listing B-2 (page 3 of 4).

rem Store the data in RAM

1500 FOR I=SOURCE TO SOURCE + COUNT-1 : XBY(ADDR)=XBY(I)

rem Now verify that stored data is readable as code 1505 if XBY(I) <> CBY(ADDR) THEN GOTO 3130

1508 ADDR = ADDR+1 : NEXT

1510 RETURN

rem Store the data in EPROM or RDY/BUSY EEPROM rem First load the source address registers

1520 DBY (1BH) = SOURCE/256 : DBY (19H) = SOURCE .AND. 0FFH

rem Now load the destination address registers

1530 DBY (1AH) = (ADDR-1)/256 : DBY (18H) = (ADDR - 1)

.AND. 0FFH

rem Now load the number of bytes to program

1540 DBY (1Fh) = COUNT/256 : DBY (1Eh) = COUNT .AND. 0FFh

rem Program the data into the part

1550 PGM : IF DBY (1Fh) .OR. DBY (1Eh) <>0 THEN GOTO 3060 1560 RETURN

1570 FOR I=SOURCE TO SOURCE + COUNT-1 : XBY (ADDR) = XBY

(I)

1580 time = 0 : dby (47h) = 0 : clock1 : do : until time >= delay

1590 if xby (addr) <>xby (i) goto 3100

1600 addr = addr + 1: clock0 : next : clock0 : return

rem Convert the ASCII text to numbers

2000

C = ASC($(0),I)

: IF (C<=70 .AND. C>=65) THEN C = C -

 

55 ELSE C = C -

48

 

 

 

 

 

2020

CH = C * 16 : C

= ASC($(0),I + 1)

2040

IF (C<=70 .AND. C>=65) THEN C = C - 55 ELSE C = C - 48

2050

CH = CH + C : RETURN

rem Here when we are

going to load the data into EEPROM.

2100

WAIT = 0.0005 : RETURN

rem Here for Intelligent programming

2110

WAIT = 0.001 : RETURN

268

 

 

 

The Microcontroller Idea Book