Freeware assember ASxx.EXE Ver 1.03. 0001 * ========================================================== * 0002 * Thomas C. Penick ID# 452 80 6040 Program key * 0003 * EE319K Microprocessor Programming * 0004 * Instructor: Laurence Section B * 0005 * MC6811 Program Source Code key.asm Roster# * 0006 * ========================================================== * 0007 * 0008 * This program demonstrates the use of InString and OutString. 0009 * In the SCI window the message "Type Something: " is displayed. 0010 * Up to 19 characters are accepted and can be seen in the 0011 * memory window. When the Enter key is pressed the string 0012 * is terminated and stored in the Str variable. The message 0013 * "Hit Enter" is displayed. When the Enter key is pressed, 0014 * the contents of Str are played back in the SCI window. 0015 * This program runs so slowly at the default speed, you may 0016 * want to press F8 to get it to run fast. 0017 0018 0000 org 0 Globals go in Ram 0019 0000 Str rmb 20 String variable 0020 0014 Zip rmb 2 String variable 0021 e000 org $E000 Object code goes in ROM 0022 e000 8e 00 ff Main lds #$00FF Stack grows down from $00FF 0023 e003 bd fe 00 jsr InitSCI Initialize the SCI (subroutine) 0024 0025 e006 ce e0 2b Start ldx #Greet Load register X with the address of Greet 0026 e009 bd fe 68 jsr OutString Display message in SCI window 0027 e00c ce 00 00 ldx #Str Load register X with the address of Str 0028 e00f c6 13 ldab #19 Load register B with the max size of input 0029 e011 bd fe 25 jsr InString Receive a string from the SCI window 0030 e014 ce e0 3d ldx #Enter Load register X with the address of Enter 0031 e017 bd fe 68 jsr OutString Display message "Hit Enter" in SCI window 0032 e01a ce 00 14 ldx #Zip Load register X with the address of Zip 0033 e01d c6 01 ldab #1 Load register B with the max size of input 0034 e01f bd fe 25 jsr InString Receive a string from the SCI window 0035 e022 ce 00 00 ldx #Str Load register X with the address of Str 0036 e025 bd fe 68 jsr OutString Output the previously typed string to the SCI window 0037 0038 e028 7e e0 06 jmp Start Return to the first operation 0039 0040 e02b 0d Greet fcb CR 0041 e02c 54 79 70 65 20 73 fcc /Type something: / 6f 6d 65 74 68 69 6e 67 3a 20 0042 e03c 04 fcb EOT 0043 e03d 0d Enter fcb CR 0044 e03e 48 69 74 20 45 6e fcc /Hit Enter / 74 65 72 20 0045 e048 0d fcb CR 0046 e049 04 fcb EOT 0047 fffe org $FFFE 0048 fffe e0 00 fdb Main Starting address after a RESET 0049 end 0050 ******************* SCI.ASM *************** 0051 * SCI terminal I/O routines 0052 * Jonathan W. Valvano 0053 * August 9, 1996 0054 fe00 org $FE00 end of ROM 0055 0056 *************InitSCI******************** 0057 * Initalize SCI 0058 * This RITUAL is executed once 0059 * Inputs: none Outputs: none 0060 * Registers modified: CCR 0061 fe00 36 InitSCI psha 0062 fe01 86 0c ldaa #$0c 0063 fe03 b7 10 2d staa Sccr2 enable SCI 0064 fe06 86 00 ldaa #$00 0065 fe08 b7 10 2b staa Baud baud rate=125000 0066 fe0b 32 pula 0067 fe0c 39 rts 0068 * * * * * * * End of InitSCI* * * * * * * * 0069 0070 ****************InCh*********************** 0071 * Input one character from SCI terminal 0072 * Inputs: none Outputs: RegA is ASCII character 0073 * Registers modified: CCR 0074 0020 RDRF equ $20 0075 fe0d b6 10 2e InCh ldaa Scsr Read SCSR, Gadfly loop 0076 fe10 84 20 anda #RDRF Wait for RDRF set 0077 fe12 27 f9 beq InCh RDRF=1 when a new key is available 0078 fe14 b6 10 2f ldaa Scdr ASCII character code 0079 fe17 39 rts 0080 * * * * * * * * End of InCh * * * * * * * * 0081 0082 ***************OutCh*********************** 0083 * Output one character to SCI terminal 0084 * Inputs: RegA is ASCII character Outputs: none 0085 * Registers modified: CCR 0086 0080 TDRE equ $80 0087 fe18 37 OutCh pshb 0088 fe19 f6 10 2e OutW ldab Scsr Read SCSR, Gadfly loop 0089 fe1c c4 80 andb #TDRE Set when ready for more output 0090 fe1e 27 f9 beq OutW Wait for TDRE=1 0091 fe20 b7 10 2f staa Scdr Start Output 0092 fe23 33 pulb 0093 fe24 39 rts 0094 * * * * * * * * End of OutCh * * * * * * * * 0095 0096 ***********InString********************** 0097 * Input a character string from the SCI terminal, with echo 0098 * Inputs: RegX points to an empty array, 0099 * RegB is the max string length (size of the buffer) 0100 * must be greater than 0 0101 * Outputs: RegX points to ASCII characters, terminated by EOT=$04 0102 * String is terminated by an ENTER, which is not saved 0103 * Registers modified: CCR 0104 fe25 36 InString psha Save registers 0105 fe26 3c pshx 0106 fe27 18 3c pshy 0107 fe29 18 ce 00 00 ldy #0 RegY=Character count 0108 fe2d 5a decb Need at least one place for EOT 0109 fe2e bd fe 0d ISLoop jsr InCh Input next 0110 fe31 81 08 cmpa #BS 0111 fe33 26 1b bne NotBS 0112 fe35 18 8c 00 00 cpy #0 0113 fe39 27 f3 beq ISLoop Ignore BS if at beginning of line 0114 fe3b 86 08 ldaa #BS 0115 fe3d bd fe 18 jsr OutCh 0116 fe40 86 20 ldaa #SPACE Space 0117 fe42 bd fe 18 jsr OutCh Erase old character from screen 0118 fe45 86 08 ldaa #BS 0119 fe47 bd fe 18 jsr OutCh 0120 fe4a 09 dex Erase old character from Buffer 0121 fe4b 18 09 dey 0122 fe4d 5c incb Room for more 0123 fe4e 20 de bra ISLoop 0124 fe50 81 0d NotBS cmpa #CR 0125 fe52 27 0b beq ISDone 0126 fe54 bd fe 18 jsr OutCh 0127 fe57 a7 00 staa 0,X Next ASCII character from string 0128 fe59 18 08 iny 0129 fe5b 08 inx 0130 fe5c 5a decb 0131 fe5d 26 cf bne ISLoop 0132 fe5f 86 04 ISDone ldaa #EOT 0133 fe61 a7 00 staa 0,X 0134 fe63 18 38 puly 0135 fe65 38 pulx 0136 fe66 32 pula 0137 fe67 39 rts 0138 * * * * * * * * End of InString * * * * * * 0139 0140 ***********OutString********************** 0141 * Output character string to SCI terminal 0142 * Inputs: RegX points to ASCII characters Outputs: none 0143 * String is terminated by a EOT=$04 0144 * Registers modified: CCR 0145 fe68 36 OutString psha Save registers 0146 fe69 3c pshx 0147 fe6a a6 00 OSLoop ldaa 0,X Next ASCII character from string 0148 fe6c 81 04 cmpa #EOT 0149 fe6e 27 05 beq OSDone EOT? 0150 fe70 8d a6 bsr OutCh Output next 0151 fe72 08 inx 0152 fe73 20 f5 bra OSLoop 0153 fe75 38 OSDone pulx 0154 fe76 32 pula 0155 fe77 39 rts 0156 * * * * * * * * End of OutString * * * * * * 0157 0158 ****************InHex*********************** 0159 * Input characters from SCI terminal in Hex format, with echo 0160 * and return a 16 bit unsigned number 0161 * Accepts characters until ENTER is typed 0162 * Returns V=1 if an illegal character is typed not 0-9 A-F or a-f 0163 * Returns V=0 if a valid input is accepted 0164 * space, $, tab are ignored 0165 * Inputs: none Outputs: RegD is an unsigned 16 bit 0166 * Registers modified: CCR 0167 fe78 3c InHex pshx 0168 fe79 18 3c pshy 0169 fe7b 18 ce 00 00 ldy #0 Error flag 0170 fe7f ce 00 00 ldx #0 Initial calculation of result 0171 fe82 bd fe 0d IHinput jsr InCh RegA is next char 0172 fe85 bd fe 18 jsr OutCh with echo 0173 fe88 81 20 cmpa #32 0174 fe8a 27 f6 beq IHinput 0175 fe8c 81 09 cmpa #9 0176 fe8e 27 f2 beq IHinput 0177 fe90 81 24 cmpa #'$ 0178 fe92 27 ee beq IHinput 0179 fe94 81 0d cmpa #CR ENTER? 0180 fe96 27 30 beq IHdone 0181 fe98 81 30 cmpa #'0 0182 fe9a 25 26 blo IHerr Less than ASCII 0 is error 0183 fe9c 81 39 cmpa #'9 0184 fe9e 22 04 bhi IHnotdig 0185 fea0 80 30 suba #'0 Convert ASCII 0-9 to 0-9 0186 fea2 20 0c bra IHnext 0187 fea4 84 df IHnotdig anda #$DF convert lower to uppercase 0188 fea6 81 41 cmpa #'A 0189 fea8 25 18 blo IHerr Between $3A and $41 0190 feaa 81 46 cmpa #'F 0191 feac 22 14 bhi IHerr 0192 feae 80 37 suba #'A-10 Convert ASCII A-F to $0A to $0F 0193 feb0 8f IHnext xgdx 0194 feb1 05 lsld 0195 feb2 25 0e bcs IHerr 0196 feb4 05 lsld 0197 feb5 25 0b bcs IHerr 0198 feb7 05 lsld 0199 feb8 25 08 bcs IHerr 0200 feba 05 lsld 0201 febb 25 05 bcs IHerr 0202 febd 8f xgdx 0203 febe 16 tab 0204 febf 3a abx 0205 fec0 20 c0 bra IHinput 0206 fec2 18 ce ff ff IHerr ldy #-1 error 0207 fec6 20 ba bra IHinput 0208 fec8 18 8c 00 00 IHdone cpy #0 0209 fecc 27 01 beq IHok 0210 fece 0b sev error code returned 0211 fecf 8f IHok xgdx 0212 fed0 18 38 puly 0213 fed2 38 pulx 0214 fed3 39 rts 0215 * * * * * * * * End of InHex * * * * * * * * 0216 0217 ****************OutHex*********************** 0218 * Output characters to SCI terminal in Hex format 0219 * as a 16 bit unsigned number 0220 * Inputs: RegD is an unsigned 16 bit Outputs: none 0221 * Registers modified: CCR 0222 fed4 36 OutHex psha 0223 fed5 37 pshb 0224 fed6 3c pshx 0225 fed7 18 3c pshy 0226 fed9 8f xgdx 0227 feda 86 24 ldaa #'$ 0228 fedc bd fe 18 jsr OutCh 0229 fedf 18 ce 00 04 ldy #4 Four characters 0230 fee3 8f OHloop xgdx Reg D = input 0231 fee4 ce 00 10 ldx #16 0232 fee7 02 idiv RegB is digit, RegX is rest of input 0233 fee8 37 pshb Save for later, reverse order 0234 fee9 18 09 dey 0235 feeb 26 f6 bne OHloop 0236 feed 18 ce 00 04 ldy #4 Four characters 0237 fef1 32 OHout pula next digit 0238 fef2 81 09 cmpa #9 0239 fef4 23 04 bls OH09 skip if 0 to 9 0240 fef6 8b 37 adda #'A-10 convert $0A-$0F to ASCII A-F 0241 fef8 20 02 bra OHoutch 0242 fefa 8b 30 OH09 adda #'0 convert 0-9 to ASCII 0-9 0243 fefc bd fe 18 OHoutch jsr OutCh 0244 feff 18 09 dey 0245 ff01 26 ee bne OHout 0246 ff03 18 38 puly 0247 ff05 38 pulx 0248 ff06 33 pulb 0249 ff07 32 pula 0250 ff08 39 rts 0251 * * * * * * * * End of OutHex * * * * * * * * 0252 0253 ****************InDec*********************** 0254 * Input characters from SCI terminal in Decimal format, with echo 0255 * and return a 16 bit unsigned number 0256 * Accepts characters until ENTER is typed 0257 * Returns V=1 if an illegal character is typed not 0-9 0258 * Returns V=0 if a valid input is accepted 0259 * space, ., tab are ignored 0260 * Inputs: none Outputs: RegD is an unsigned 16 bit 0261 * Registers modified: CCR 0262 0000 IDflag equ 0 Error flag initially 0 0263 0001 IDtemp equ 1 16 bit Temporary 0264 ff09 3c InDec pshx Save registers 0265 ff0a 18 3c pshy 0266 * ----------------------------------------- 0267 ff0c 3c pshx allocate 16 bit temporary without initializing 0268 ff0d 4f clra 0269 ff0e 36 psha allocate Error flag on stack 0270 * ----------------------------------------- 0271 ff0f ce 00 00 ldx #0 Initial calculation of result 0272 ff12 18 30 tsy 0,Y=error flag 1,Y=temp 0273 ff14 bd fe 0d IDinput jsr InCh RegA is next char 0274 ff17 bd fe 18 jsr OutCh with echo 0275 ff1a 81 20 cmpa #32 0276 ff1c 27 f6 beq IDinput ignore spaces 0277 ff1e 81 09 cmpa #9 0278 ff20 27 f2 beq IDinput ignore tabs 0279 ff22 81 2e cmpa #'. 0280 ff24 27 ee beq IDinput ignore '.' 0281 ff26 81 0d cmpa #CR ENTER means done 0282 ff28 27 26 beq IDdone 0283 ff2a 81 30 cmpa #'0 0284 ff2c 25 1d blo IDerr Less than ASCII 0 is error 0285 ff2e 81 39 cmpa #'9 0286 ff30 22 19 bhi IDerr 0287 ff32 80 30 suba #'0 Convert ASCII 0-9 to 0-9 0288 ff34 8f xgdx 0289 ff35 05 lsld 2*result 0290 ff36 25 13 bcs IDerr 0291 ff38 18 ed 01 std IDtemp,Y temp=2*result 0292 ff3b 05 lsld 4*result 0293 ff3c 25 0d bcs IDerr 0294 ff3e 05 lsld 0295 ff3f 25 0a bcs IDerr 8*result 0296 ff41 18 e3 01 addd IDtemp,Y (8+2)*result 0297 ff44 25 05 bcs IDerr 0298 ff46 8f xgdx 0299 ff47 16 tab RegB=new digit 0300 ff48 3a abx result=10*result+digit 0301 ff49 20 c9 bra IDinput 0302 ff4b 18 6c 00 IDerr inc IDflag,Y Set error flag 0303 ff4e 20 c4 bra IDinput 0304 ff50 18 6d 00 IDdone tst IDflag,Y 0305 ff53 27 01 beq IDok sets V=0 if OK 0306 ff55 0b sev error code returned 0307 ff56 8f IDok xgdx RegD=result 0308 * ----------------------------------------- 0309 ff57 31 ins discard local variables 0310 ff58 31 ins 0311 ff59 31 ins 0312 * ----------------------------------------- 0313 ff5a 18 38 puly Restore registers 0314 ff5c 38 pulx 0315 ff5d 39 rts 0316 * * * * * * * * End of InDec * * * * * * * * 0317 0318 ****************OutDec*********************** 0319 * Output characters to SCI terminal in decimal format 0320 * as a 16 bit unsigned number 0321 * Inputs: RegD is an unsigned 16 bit Outputs: none 0322 * Registers modified: CCR 0323 ff5e 36 OutDec psha 0324 ff5f 37 pshb 0325 ff60 3c pshx 0326 ff61 18 3c pshy 0327 ff63 18 ce 00 00 ldy #0 Number of characters 0328 ff67 ce 00 0a ODloop ldx #10 Reg D = input 0329 ff6a 02 idiv RegB is digit, RegX is rest of input 0330 ff6b 37 pshb Save for later, reverse order 0331 ff6c 18 08 iny 0332 ff6e 8f xgdx 0333 ff6f 1a 83 00 00 cpd #0 Continue until 0334 ff73 26 f2 bne ODloop 0335 ff75 32 ODout pula next digit 0336 ff76 8b 30 adda #'0 convert 0-9 to ASCII 0-9 0337 ff78 bd fe 18 jsr OutCh 0338 ff7b 18 09 dey 0339 ff7d 26 f6 bne ODout 0340 ff7f 18 38 puly 0341 ff81 38 pulx 0342 ff82 33 pulb 0343 ff83 32 pula 0344 ff84 39 rts 0345 * * * * * * * * End of OutDec * * * * * * * * 0346 0347 * *****************PAGE1.ASM****************** 0348 * Jonathan W. Valvano January 5, 1996 0349 00ff TRUE EQU $FF ;DEFINE TRUE 0350 0000 FALSE EQU $00 ;DEFINE FALSE 0351 000d CR equ 13 ;carriage return or ENTER 0352 0004 EOT equ 4 ;end of transmission 0353 0008 BS equ 8 ;backspace 0354 0020 SPACE equ 32 ;space 0355 ;**************************************************************** 0356 ;* CONTROL REGISTER ASSIGNMENTS FOR THE 68HC11 0357 ;**************************************************************** 0358 1000 base equ $1000 ;default control register address 0359 1000 Porta equ base+$00 ;I/O port a location 0360 1002 Pioc equ base+$02 ;parallel I/O control 0361 1003 Portc equ base+$03 ;I/O port c location 0362 1004 Portb equ base+$04 ;output port b 0363 1005 Portcl equ base+$05 ;alternate latched port c 0364 1007 Ddrc equ base+$07 ;data direction port c 0365 1008 Portd equ base+$08 ;I/O port d 0366 1009 Ddrd equ base+$09 ;data direction port d 0367 100a Porte equ base+$0a ;input port e 0368 100b Cforc equ base+$0b ;compare force register 0369 100c Oc1m equ base+$0c ;oc1 action mask register 0370 100d Oc1d equ base+$0d ;oc1 action data register 0371 100e Tcnt equ base+$0e ;timer counter register high byte 0372 100f Tcntl equ base+$0f ;timer counter register low byte 0373 1010 Tic1 equ base+$10 ;input capture 1 high byte 0374 1011 Tic1l equ base+$11 ;input capture 1 low byte 0375 1012 Tic2 equ base+$12 ;input capture 2 high byte 0376 1013 Tic2l equ base+$13 ;input capture 2 low byte 0377 1014 Tic3 equ base+$14 ;input capture 3 high byte 0378 1015 Tic3l equ base+$15 ;input capture 3 low byte 0379 1016 Toc1 equ base+$16 ;output compare 1 high byte 0380 1017 Toc1l equ base+$17 ;output compare 1 low byte 0381 1018 Toc2 equ base+$18 ;output compare 2 high byte 0382 1019 Toc2l equ base+$19 ;output compare 2 low byte 0383 101a Toc3 equ base+$1a ;output compare 3 high byte 0384 101b Toc3l equ base+$1b ;output compare 3 low byte 0385 101c Toc4 equ base+$1c ;output compare 4 high byte 0386 101d Toc4l equ base+$1d ;output compare 4 low byte 0387 101e Toc5 equ base+$1e ;output compare 5 high byte 0388 101f Toc5l equ base+$1f ;output compare 5 low byte 0389 1020 Tctl1 equ base+$20 ;timer control register 1 0390 1021 Tctl2 equ base+$21 ;timer control register 2 0391 1022 Tmsk1 equ base+$22 ;timer interrupt mask register 1 0392 1023 Tflg1 equ base+$23 ;timer interrupt flag register 1 0393 1024 Tmsk2 equ base+$24 ;timer interrupt mask register 2 0394 1025 Tflg2 equ base+$25 ;timer interrupt flag register 2 0395 1026 Pactl equ base+$26 ;pulse accumulator control register 0396 1027 Pacnt equ base+$27 ;pulse accumulator count register 0397 1028 Spcr equ base+$28 ;syncronous serial control register 0398 1029 Spsr equ base+$29 ;syncronous serial status register 0399 102a Sydr equ base+$2a ;syncronous serial data register 0400 102b Baud equ base+$2b ;serial baud rate control 0401 102c Sccr1 equ base+$2c ;serial control register 1 0402 102d Sccr2 equ base+$2d ;serial control register 2 0403 102e Scsr equ base+$2e ;serial status register 0404 102f Scdr equ base+$2f ;serial data register 0405 1030 Adctl equ base+$30 ;A/D control register 0406 1031 Adr1 equ base+$31 ;A/D result register 1 0407 1032 Adr2 equ base+$32 ;A/D result register 2 0408 1033 Adr3 equ base+$33 ;A/D result register 3 0409 1034 Adr4 equ base+$34 ;A/D result register 4 0410 1035 Bprot equ base+$35 ;eeprom block protect 0411 1039 Option equ base+$39 ;system config register 0412 103a Coprst equ base+$3a ;watchdog timer control register 0413 103b Pprog equ base+$3b ;eeprom programming control register 0414 103c Hprio equ base+$3c ;priority interrupt and misc. 0415 103d Map equ base+$3d ;ram and I/O mapping register 0416 103e Test1 equ base+$3e ;factory test register 0417 103f Config equ base+$3f ;cop,rom and eeprom enables Adctl 1030 Adr1 1031 Adr2 1032 Adr3 1033 Adr4 1034 BS 0008 Baud 102b Bprot 1035 CR 000d Cforc 100b Config 103f Coprst 103a Ddrc 1007 Ddrd 1009 EOT 0004 Enter e03d FALSE 0000 Greet e02b Hprio 103c IDdone ff50 IDerr ff4b IDflag 0000 IDinput ff14 IDok ff56 IDtemp 0001 IHdone fec8 IHerr fec2 IHinput fe82 IHnext feb0 IHnotdig fea4 IHok fecf ISDone fe5f ISLoop fe2e InCh fe0d InDec ff09 InHex fe78 InString fe25 InitSCI fe00 Main e000 Map 103d NotBS fe50 ODloop ff67 ODout ff75 OH09 fefa OHloop fee3 OHout fef1 OHoutch fefc OSDone fe75 OSLoop fe6a Oc1d 100d Oc1m 100c Option 1039 OutCh fe18 OutDec ff5e OutHex fed4 OutString fe68 OutW fe19 Pacnt 1027 Pactl 1026 Pioc 1002 Porta 1000 Portb 1004 Portc 1003 Portcl 1005 Portd 1008 Porte 100a Pprog 103b RDRF 0020 SPACE 0020 Sccr1 102c Sccr2 102d Scdr 102f Scsr 102e Spcr 1028 Spsr 1029 Start e006 Str 0000 Sydr 102a TDRE 0080 TRUE 00ff Tcnt 100e Tcntl 100f Tctl1 1020 Tctl2 1021 Test1 103e Tflg1 1023 Tflg2 1025 Tic1 1010 Tic1l 1011 Tic2 1012 Tic2l 1013 Tic3 1014 Tic3l 1015 Tmsk1 1022 Tmsk2 1024 Toc1 1016 Toc1l 1017 Toc2 1018 Toc2l 1019 Toc3 101a Toc3l 101b Toc4 101c Toc4l 101d Toc5 101e Toc5l 101f Zip 0014 base 1000 Number of errors 0