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.

Appendix B<br />

Listing B-1 (page 1 of 2). HEX2RAM.BAS loads Intel Hex files from a host<br />

computer to memory in the 8052-BASIC system. Reprinted with permission from<br />

Systronix.<br />

10 STRING 82, 80 : DIM HI (70) : DIM LOW (70)<br />

15 FOR I=48 TO 57 : HI(I) = (I - 48) * 16 : LOW(I) = I - 48<br />

: NEXT<br />

25 FOR I=65 TO 70 : HI(I) = (I - 55) * 16 : LOW(I) = I - 55<br />

: NEXT<br />

35 PRINT TAB(19),"INTEL HEX FILE TO RAM LOADING PROGRAM V1.1"<br />

45 PRINT TAB(14), “Copyright 1991 Systronix Inc. All rights<br />

reserved.” : PRINT<br />

55 PRINT TAB(8),"This program accepts as input an Intel hex<br />

file and stores"<br />

65 PRINT TAB(8),"it in external RAM at the addresses specified<br />

in the HEX file.":PRINT<br />

75 PRINT TAB(8),"Ready to receive the input file one line at<br />

a time. Set your"<br />

85 PRINT TAB(8),"communication software to send a line when<br />

when it receives"<br />

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

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

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

REM Get the byte count and save it in the variable COUNT<br />

115 I = 2 : GOSUB 700 : COUNT = CH<br />

REM Get the starting address for this record’s data<br />

125 FOR I = 4 TO 7 STEP 2 : GOSUB 700 : ADDR = (ADDR * 256)<br />

+ CH : NEXT<br />

REM Get the record type (we only understand types 0 and 1)<br />

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

510<br />

145 RECORD = CH<br />

REM <strong>The</strong> initial checksum calculation<br />

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

REM Get the individual bytes, accumulate them in the check<br />

sum and store<br />

REM them in memory at the appropriate destination<br />

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

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