I2C EhBASIC source. By Lee Davison. |
When you start EhBASIC to run this program you should answer $47000 to the Memory size? prompt to protect the code from being over written by EhBASIC or it's variables.
Having said that this program doesn't make heavy use of strings so does work fine with the default memory settings.
10 REM I2C bus scan 20 REM (c) Lee Davison 2003 30 REM leeedavison@lycos.co.uk 40 REM 50 REM For V1.10 of EhBASIC68 100 ad&=$47000 : REM code address 110 a=0 : REM clear offset 120 DO 130 READ word : REM read word 140 DOKE ad&+a,word : REM put word in memory 150 INC a,a : REM next word address 160 LOOP WHILE word>=0 170 LOKE $40408,ad& : REM set USR() vector 175 REM Now use the function to scan 180 REM each I2C write address. Write 185 REM addresses are used as the I2C 190 REM write cycle is easier to end 195 REM reliably with an I2C stop. 200 FOR a=0 TO $FE STEP 2 210 IF (a AND 15)=0 THEN PRINT 220 PRINT " $";HEX$(a,2);" ";USR(a);" "; 230 NEXT 240 PRINT 250 END 1000 DATA $6122,$4EB8,$2536,$6174,$33C0,$0004,$0598,$6708 1010 DATA $33FC,$A080,$0004,$0598,$23C0,$0004,$0594,$6114 1020 DATA $4EF8,$2760,$6136,$6116,$611E,$6112,$6124,$610E 1030 DATA $6134,$600A,$611C,$6106,$610E,$6102,$611E,$2F07 1040 DATA $2E1F,$2F07,$2E1F,$4E75,$13FC,$0040,$0008,$001D 1050 DATA $4E75,$13FC,$0080,$0008,$001F,$4E75,$13FC,$0080 1060 DATA $0008,$001D,$4E75,$13FC,$0040,$0008,$001F,$4E75 1070 DATA $0839,$0004,$0008,$001B,$67F6,$60C2,$2F01,$7207 1080 DATA $0300,$6704,$61D6,$6002,$61C8,$61B2,$61BA,$61E0 1090 DATA $61D4,$61AA,$51C9,$FFEA,$61C2,$61A2,$61AA,$61D0 1100 DATA $7000,$610C,$61C0,$6196,$221F,$0840,$0000,$4E75 1110 DATA $0839,$0005,$0008,$001B,$6702,$5200,$4E75,-1The DATA statements at the end are the hex word version of the assembly code that drives the port.
When this code is run it gives an output like that shown below, any addresses that respond with an ack bit return -1, any that don't ack return zero. In this case the only active addresses are $A4 and $D4, both part of the RAMTROM FRAM & RTC chip.
Once the code has been loaded into memory and the USR() vector set you can use the routine to continuously test one address with a simple loop thus ..
DO:A=USR($C2):LOOP.. which is how the stable 'scope displays were made for these pages.
Last page update: 4th May, 2004. | e-mail me |