10 ******* EELOAD.BAS 20/3/87 Version 1.0 *******1 
20 1 Written by R.Soja, Motorola East Kilbride' 
30 1 Motorola Copyright 1987' 
40 1 This program downloads S record file to the MC68HC11 through special' 
50 1 bootstrap program, designed to program either internal or external 1 
60 1 EEPROM in the 68HC11's memory map' 
70 1 The loader can also verify memory against an S record file.' 
80 1 Downloaded data is optionally echoed on terminal.' 
90 1 ================================== 
100 CR$=CHR$(13) 
110 MIN$=CHR$(32) 
120 MAX$=CHR$(127) 
130 ERM$="Can't find" 
140 LOADER$=EEPROGIX.BOO" 
150 CLRLN$=SPACE$(80) 
160 VER$=111.0": 'Version number of EELOAD' 
170 ERRTOT%=O: 'Number of errors found by verify operation' 
180 CLS 
190 PRINT   EELOAD Version ;VER$;" " 
200 PRINT   68HC11 Internal/External EEPROM loader/verifier " 
210 PRINT 
220 PRINT "==> Before continuing, ensure 68HC11 is in bootstrap mode," 
230 PRINT " RESET is off, and COM1 or COM2 is connected to the SCI" 
240 PRINT 
250 ' First make sure loader program is available' 
260 ON ERROR GOTO 880 
270 OPEN LOADER$ FOR INPUT AS #2 
280 CLOSE #2 
290 ON ERROR GOTO 0 
300 CHAN$=O" 
310 ROW=CSRLIN: 'Store current line number' 
320 WHILE CHAN$<>111" AND CHAN$<>112" 
330 GOSUB 1070 
340 LINE INPUT "Enter COM channel number (1/2):",CHAN$ 
350 WEND 
360 CM$=COM"+CHAN$ 
370 1 Now set baud rate to 1200 and load EEPROG through boot loader' 
380 1 by executing DOS MODE and COPY commands' 
390 SHELL "MODE +CM$+11:1200,N,8,1" 
400 SHELL "COPY +LOADER$+" "+CM$ 
401 GOSUB 1070 
402 FOR 1%=1 TO 4:PRINT CLRLN$;:NEXT I%:PRINT: 'Clear DOS commands from screen' 
410 ECHO$="  
420 WHILE ECHO$<>Y" AND ECHO$<>N" 
430 GOSUB 1070 
440 LINE INPUT "Do you want echo to screen (Y/N):",ECHO$ 
450 WEND 
470 ROW=CSRLIN: 'Store current line number' 
480 EEOPT$=" ": 'Initialise option char' 
490 WHILE EEOPT$<>X" AND EEOPT$<>I" AND EEOPT$<>V" 
500 GOSUB 1070 
510 LINE INPUT "Select Internal,eXternal or Verify EEPROM option (I/X/V):",EEOPT$ 
520 WEND 
530 OPT$="Verify" 
540 IF EEOPT$=I" THEN OPT$="Internal" 
550 IF EEOPT$=X" THEN OPT$="External" 
560 ROW=CSRLIN: 'Store current line position in case of file error' 
570 RXERR=O: 'Initialise number of RX errors allowed' 
580 ON ERROR GOTO 910 
590 GOSUB 1070 
600 IF OPT$="Verify" THEN INPUT "Enter filename to verify: ",F$ ELSE INPUT "Enter filename to download:",F$ 
610 CLOSE 
620 OPEN F$ FOR INPUT AS #2 
630 ON ERROR GOTO 0 
640 'COM1 or 2 connected to SCI on HC11' 
650 OPEN CM$+":9600,N,8,1" AS #1 660 'Establish contact with HC11 by sending CR char & waiting for echo' 
670 ON ERROR GOTO 860: 'Clear potential RX error' 
680 PRINT #1,CR$; 
690 GOSUB 990: 'Read char into B$' 
700 'Transmit Internal,External or Verify EEPROM option char to 68HC11' 
710 PRINT #1,EEOPT$;:GOSUB 990: 'No echo to screen' 
720 ON ERROR GOTO 930 
730 PRINT "Starting download of <";F$;"> to: ";OPT$;" Eeprom" 
732 IF ECHO$="Y" THEN E%=1 ELSE E%=O 
734 IF EEOPT$="V" THEN V%=1 ELSE V%=O 
740 WHILE NOT EOF(2) 
750 INPUT #2,S$ 
751 L%=LEN(S$) 
752 FOR 1%=1 TO L% 
760 PRINT #1,MID$(S$,I%,1);:GOSUB 990:IF E% THEN PRINT B$; 
770 IF V% THEN GOSUB 1030:IF C$<>"" THEN PRINT ":";HEX$(ASC(C$)); 
785 NEXT I% 
787 IF E% THEN PRINT 
790 WEND 
795 PRINT 
800 PRINT "Download Complete" 
810 IF V-I. THEN PRINT ERRTOT%;" error(s) found" 
820 CLOSE #2 
830 SYSTEM 
840 END 
850 --------------------, 
860 IF RXERR>5 THEN 940 ELSE RXERR=RXERR+1:RESUME 610 
870 --------------------, 
880 PRINT:PRINT ERM$;LOADER$:PRINT "Program aborted" 
890 GOTO 830 
900 --------------------, 
910 PRINT ERM$;F$;SPACE$(40) 
920 RESUME 580 
930 --------------------, 
940 PRINT:PRINT "Communication breakdown: Download aborted" 
950 GOTO 820 
960 --------------------, 
970 '--SUB waits for received character, with time limit' 
980 ,-- returns with char in B$, or aborts if time limit exceeded' 
990 TO%=0:WHILE LOC(1)=0:IF TO%>100 THEN 940 ELSE TO%=TO%+1:WEND 
1000 B$=INPUT$(1,#1):RETURN 
1010 --------------------, 
1020 '--SUB waits for received character, with time limit' 
1025 '-- returns with char in C$, or null in C$ if time limit exceeded' 
1030 TO%=O:C$="":WHILE LOC(1)=0 AND TO%<1:TO%=TO%+1:WEND 
1040 IF LOC(1)>0 THEN C$=INPUT$(1,#1):ERRTOT%=ERRTOT%+1 
1050 RETURN 
1060 --------------------, 
1070 '--SUB Clear line ' 
1080 LOCATE ROW,1,1:PRINT CLRLN$ 
1090 LOCATE ROW,1,1:RETURN 



M68HC11 Absolute Assembler Version 2.4 C:EEPROGIX.ASC 
1 A ************************************************************* 
2 A * EEPROGIX.ASC 19/3/87 Revision 1.0 * 
3 A * * 
4 A * Written by R.Soja, Motorola, East Kilbride * 
5 A * Motorola Copyright 1987. * 
6 A * * 
7 A * This program loads S records from the host to * 
8 A * either a 2864 external EEPROM on the 68HC11 external bus, * 
9 A * or to the 68HC11's internal EEPROM. It can also be used * 
10 A * verify memory contents against an S record file or just * 
11 A * load RAM located on the 68HC11's external bus. * 
12 A * Each byte loaded is echoed back to the host. * 
13 A * When programming a 2864, data polling is used to detect * 
14 A * completion of the programming cycle. * 
15 A * As the host software always waits for the echo before * 
16 A * downloading the next byte, host transmission is suspended * 
17 A * during the data polling period. * 
18 A * Because the serial communication rate (-1mS/byte) is * 
19 A * slower than the 2864 internal timer timeout rate (-300uS) * 
20 A * page write mode cannot be used. This means that data * 
21 A * polling is active on each byte written to the EEPROM, * 
22 A * after an initial delay of approx 500uS. * 
23 A * * 
24 A * When the internal EEPROM is programmed, instead of data * 
25 A * polling, each byte is verified after programming. * 
26 A * In this case, the 500uS delay is not required and is * 
27 A * bypassed. * 
28 A * If a failure occurs, the program effectively hangs up. It * 
29 A * is the responsibility of the host downloader program to * 
30 A * detect this condition and take remedial action. * 
31 A * The BASIC program EELOAD just displays a 'Communication * 
32 A * breakdown' message, and terminates the program. * 
33 A * * 
34 A * When used in the verify mode, apart from the normal echo * 
35 A * back of each character, all differences between memory * 
36 A * and S record data are also sent back to the host. * 
37 A * The host software must be capable of detecting this, and * 
38 A * perform the action required. * 
39 A * The BASIC loader program EELOAD simply displays the * 
40 A * returned erroneous byte adjacent to the expected byte, * 
41 A * separated by a colon. * 
42 A * * 
43 A * Before receiving the S records, a code byte is received * 
44 A * from the host. i.e.: * 
45 A * ASCII 'X' for external EEPROM * 
46 A * ASCII 'I' for internal EEPROM * 
47 A * ASCII 'V' for verify EEPROM * 
48 A * * 
49 A * This program is designed to be used with the BASIC EELOAD * 
50 A * program. * 
51 A * Data transfer is through the SCI, configured for 8 data * 
52 A * bits, 9600 baud. * 
53 A * * 
54 A PAGE 

M68HC11 Absolute Assembler Version 2.4 C:EEPROGIX.ASC 
55 A * Constants 
56 A 0080 TDRE EQU $80 
57 A 0020 RDRF EQU $20 
58 A 0020 MDA EQU $20 
59 A 0040 SMOD EQU $40 
60 A OD05 mS10 EQU 10000/3 			10mS delay with 8MHz xtal. 
61 A 00A6 uS500 EQU 500/3 			500uS delay. 
62 A * 
63 A * Registers 
64 A 002B BAUD EQU $2B, 
65 A 002C SCCR1 EQU $2C 
66 A 002D SCCR2 EQU $2D 
67 A 002E SCSR EQU $2E 
68 A 002F SCDR EQU $2F 
69 A 003B PPROG EQU $3B 
70 A 003C HPRIO EQU $3C 
71 A 103F CONFIG EQU $103F 
72 A * 
73 A * Variables. Note: They overwrite initialisation code! ! ! ! 
74 A 0000 ORG $0 
75 P 00000001 EEOPT RMB 1 
76 P 0001 0001 MASK RMB 1 
77 P 00020001 TEMP RMB 1 
78 P 00030001 LAST BYTE RMB 1 
79 A * 
80 A * Program 
81 A 0000 ORG $0 
82 A 0000 8EOOFF LDS #$FF 
83 A 0003 CE1000 LDX #$1000 			Offset for control registers. 
84 A 0006 6F2C CLR SCCR1,X 	Initialise SCI for 8 data bits, 9600 baud 
85 A 0008 CC300C LDD #$300C 
86 A OOOB A72B STAA BAUD,X 
87 A OOOD E72D STAB SCCR2,X 
88 A OOOF 1C3C20 BSET HPRIO,X,#MDA 		Force Special Test mode first, 
89 A *= MAINTAIN SPECIAL TEST MODE TO ALLOW B96D CONFIG REGISTER PROGRAMMING == 
90 A * BCLR HPRIO,X,#SMOD and then expanded mode. (From Bootstrap mode) 
91 A 0012 9FOO ReadOpt STS <EEOPT 		Default to internal EEPROM: EEOPT=O; MASK=$FF; 
92 A 0014 8D7C BSR READC 	Then check control byte for external or internal EEPROM selection.
93 A 0016 C149 CMPB #'1' 
94 A 00182714 BEQ LOAD 
95 A 001A C158 CMPB #'X' 			If external EEPROM requested 
96 A 001C 2609 BNE OptVerf 
97 A 001E 7COOOO INC EEOPT 			then change option to 1 
98 A 0021 8680 LDAA #$80 
99 A 00239701 STAA <MASK 			and select mask for data polling mode. 
100 A 00252007 BRA LOAD 
101 A * 
102 A 0027 C156 OptVerf CMPB #'V' 		If not verify then 
103 A 0029 26E7 BNE ReadOpt 			get next character else 
104 A 002B 7AOOOO DEC EEOPT 			make EEOPT flag negative. 
105 A * 
106 A 002E LOAD EQU * 
107 A 002E 8D62 BSR READC 
108 A 0030 C153 CMPB #'S 			Wait until S1 or S9 received, 
109 A 0032 26FA BNE LOAD 			discarding checksum of previous S1 record. 
110 A 0034 8D5C BSR READC 
111 A 0036 C131 CMPB #'1 
112 A 00382719 BEQ LOAD1 

M68HC11 Absolute Assembler Version 2.4 C:EEPROGIX.ASC 
113 A 003A C139 CMPB #'9 
114 A 003C 26FO BNE LOAD 
115 A 003E 8D5F BSR RDBYTE 			Complete reading S9 record before terminating 
116 A 004017 TBA 
117 A 0041 8002 SUBA #2 			# of bytes to read including checksum. 
118 A 0043 8D6B BSR GETADR 			Get execution address in Y 
119 A 0045 8D58 LOAD9 BSR RDBYTE 		Now discard remaining bytes, 
120 A 0047 4A DECA 				including checksum. 
121 A 0048 26FB BNE LOAD9 
122 A 004A 188COOOO CPY #0 , 			If execution address =0 then 
123 A 004E 27FE BEQ * 				hang up else 
124 A 0050 186E00 JMP ,Y 			jump to it! 
125 A * 
126 A 0053 LOAD1 EQU * 
127 A 0053 8O4A BSR RDBYTE 			Read byte count of S1 record into ACCB 
128 A 0055 17 TBA 				and store in ACCA 
129 A 00568003 SUBA #3 				Remove load address & checksum bytes from count 
130 A 00588056 BSR GETADR 			Get load address into X register. 
131 A 005A 1809 DEY 				Adjust it for first time thru' LOAD2 loop. 
132 A 005C 2017 BRA LOAD1B 
133 A * 
134 A 005E D600 LOAD1A LDAB EEOPT 		Update CC register 
135 A 0060 2B25 BMI VERIFY 			If not verifying EEPROM then 
136 A 00622705 BEQ OATAPOLL 			If programming external EEPROM 
137 A 0064 C6A6 LDAB #uS500 
138 A 0066 SA WAIT1 DECB 			then wait 500uS max. 
139 A 0067 26FD BNE WAIT1 
140 A 0069 18E600 DATAPOLL LDAB ,Y 		Now either wait for completion of programming 
141 A 006C D803 EORB <LAST BYTE 		cycle by testing MS bit of last data written to 
142 A 006E D401 ANDB <MASK 			memory or just verify internal programmed data. 
143 A 0070 26F7 BNE DATAPOLL 
144 A 0072 4A LOAD1E DECA 			When all bytes done, 
145 A 0073 27B9 BEQ LOAD 			get next S record (discarding checksum) else 
146 A 0075 8D28 LOAD1B BSR RDBYTE 		read next data byte into ACCB. 
147 A 00771808 INY 				Advance to next load address 
148 A 0079 7D0000 TST EEOPT 
149 A 007C 2B05 BMI LOAD1D 			If verifying, then don't program byte! 
150 A 007E 2743 BEQ PROG 			If internal EEPROM option selected then program 
151 A 0080 18E700 STAB ,Y 			else just store byte at address. 
152 A 0083 D703 LOAD1D STAB <LAST BYTE 	Save it for DATA POLLING operation. 
153 A 0085 20D7 BRA LOAD1A 
154 A * 
155 A 0087 18E600 VERIFY LDAB ,Y 		If programmed byte 
156 A 008A D103 CMPB <LAST BYTE 		is correct then 
157 A 008C 27E4 BEQ LOAD1E 			read next byte 
158 A 008E 8D08 BSR WRITEC 			else send bad byte back to host 
159 A 0090 20EO BRA LOAD1E 			before reading next byte. 
160 A * 
161 A 0092 READC EQU * 				ACCA, X, Y regs unchanged by this routine. 
162 A 0092 1F2E20FC BRCLR SCSR,X,#RDRF,* 
163 A 0096 E62F LDAB SCDR,X 			Read next char 
164 A 0098 1F2E80FC WRITEC BRCLR SCSR,X,#TDRE,* 
165 A 009C E72F STAB SCDR,X 			and echo it back to host. 
166 A 009E 39 RTS 				Return with char in ACCB. 
167 A * 
168 A 009F 8DF1 RDBYTE BSR READC 		1st read MS nibble 
169 A 00A1 8D17 BSR HEXBIN 			Convert to binary 
170 A 00A3 58 LSLB 				and move to upper nibble 

M68HC11 Absolute Assembler Version 2.4 C:EEPROGIX.ASC 
171 A 00A4 58 LSLB 
172 A 00A5 58 LSLB 
173 A 00A6 58 LSLB 
174 A 00A7 D702 STAB <TEMP 
175 A 00A9 8DE7 BSR READC 			Get ASCII char in ACCB 
176 A OOAB 8DOD BSR HEXBIN 
177 A OOAD DA02 ORAB <TEMP 
178 A OOAF 39 RTS 				Return with byte in ACCB 
179 A * 
180 A OOBO GETADR EQU * 
181 A OOBO 36 PSHA 				Save byte counter 
182 A 00B1 8DEC BSR RDBYTE 			Read MS byte of address 
183 A 00B3 17 TBA 				and put it in MS byte of ACCD 
184 A 00B4 8DE9 BSR RDBYTE 			Nowread LS byte of address into LS byte of ACCD 
185 A 00B6 188F XGDY 				Put load address in Y 
186 A 00B8 32 PULA 				Restore byte counter 
187 A 00B9 39 RTS 				and return. 
188 A * 
189 A OOBA HEXBIN EQU * 
190 A OOBA C139 CMPB #'9 			If ACCB>9 then assume its A-F 
191 A OOBC 2302 BLS HEXNUM 
192 A OOBE CB09 ADDB #9 
193 A OOCO C40F HEXNUM ANDB #$F 
194 A 00C2 39 RTS 
195 A * 
196 A 00C3 PROG EQU * 
197 A 00C3 36 PSHA 				Save ACCA. 
198 A 00C4 8616 LDAA #$16 			Default to byte erase mode 
199 A 00C6 188C103F CPY #CONFIG 		If byte's address is CONFIG then use 
200 A OOCA 2602 BNE PROGA 
201 A OOCC 8606 LDAA #$06 			bulk erase, to allow for A1 & A8 as well as A2. 
202 A OOCE 8D10 PROGA BSR PROGRAM 		Now erase byte, or entire memory + CONFIG. 
203 A OODO 8602 LDAA #2 
204 A 00D2 8DOC BSR PROGRAM Now program byte. 
205 A 00D4 188C103F CPY #CONFIG 		If byte was CONFIG register then 
206 A 00D8 2603 BNE PROGX 
207 A OODA 18E600 LDAB ,Y 			load ACCB with oldvalue,toprevent hangup later. 
208 A 000032 PROGX PULA 			Restore ACCA 
209 A 000E 20A3 BRA LOAD1D 			and return to main bit. 
210 A * 
211 A 00 EO PROGRAM EQU * 
212 A 00 EO A73B STAA PPROG,X 		Enable internal addr/data latches. 
213 A 00E2 18E700 STAB ,Y 			Write to required address 
214 A 00E5 6C3B INC PPROG,X 			Enable internal programming voltage 
215 A 00E7 3C PSHX 
216 A 00E8 CEOD05 LDX #ms10 			and wait 10mS 
217 A OOEB 09 WAIT2 DEX 
218 A OOEC 26FD BNE WAIT2 
219 A OOEE 38 PULX 
220 A OOEF 6A3B DEC PPROG,X 			Disable internal programming voltage 
221 A 00F1 6F3B CLR PPROG,X 			Release internal addr/data latches 
222 A 00F3 39 RTS and return 
223 A * 
224 A END 

SYMBOL TABLE: Total Entries= 41 
BAUD 002B PROGA OOCE 
CONFIG 103F PROGRAM OOEO 
DATAPOLL 0069 PROGX OODD 
EEOPT 0000 RDBYTE 009F 
GETADR OOBO RDRF 0020 
HEXBIN OOBA READC 0092 
HEXNUM OOCO ReadOpt 0012 
HPRIO 003C SCCR1 002C 
LASTBYTE 0003 SCCR2 002D 
LOAD 002E SCDR 002F 
LOAD1 0053 SCSR 002E 
LOAD1A 005E SMOD 0040 
LOAD1B 0075 TDRE 0080 
LOAD1D 0083 TEMP 0002 
LOAD1E 0072 VERIFY 0087 
LOAD9 0045 WAIT1 0066 
MASK 0001 WAIT2 OOEB 
MDA 0020 WRITEC 0098 
OptVerf 0027 mS10 OD05 
PPROG 003B uS500 00A6 
PROG 00C3
