$regfile = "m1284pdef.dat"
$crystal = 16000000 'extern
$hwstack = 128
$swstack = 128
$framesize = 128
$baud = 38400 'extern
'(
----------------------------
-------AVR44MDL-Modul-------
----------------------------
RxD >-------------o--PD0/RxD | SCK/PB7--o
Txd <-------------o--PD1/TxD | MISO/PB6--o
o--PD2/Int0 | MOSI/Pb5--o
o--PD3/INT1 | PB4--o
o--PD4 | PB3--o
o--PD5 | PB2--o
LED <-------------o--PD6 | PB1--o
o--PD7 | PB0--o
SCL <>------------o--SCL/PC0---|--------PA0--o
SDA <>------------o--SDA/PC1 | PA1--o
o--PC2 | PA2--o
o--PC3 | PA3--o
o--PC4 | PA4--o
o--PC5 | PA5--o
o--PC6 --16MHz-- PA6--o
>----------o--PC7 Resonator PA7--o
o--Vcc | ARef--o
o--GND | GND--o
----------------------------
')
' ==============================================================================
' Bestimme die Ein und Ausgänge
Ddra = &B_000_01000 '1 ist Ausgang 0 ist Eingang
Porta = &B111_10111 'auf Hi oder Low setzen
'Ddrb = &B_00000000 '1 ist Ausgang 0 ist Eingang
'Portb = &B11111111 'auf Hi oder Low setzen
Ddrc = &B_0000_0000 '1 ist Ausgang 0 ist Eingang
Portc = &B1111_1111 'auf Hi oder Low setzen
Ddrd = &B_0111_0010 '1 ist Ausgang 0 ist Eingang
Portd = &B1000_1101 'auf Hi oder Low setzen
' ==============================================================================
' I2C-Config
$lib "i2c_twi.lbx"
Config Twi = 400000 'BUS-Takt, max. 400k
' #############################################################################
Const 16kw = &HA0 '16k EEPROM write-Adresse
Dim 16k_w As Byte 'EEPROM-Adresse mit Nr. der Speicherbank
' #############################################################################
Led Alias Portd.6 'Kontroll-LED
' #############################################################################
Dim Wert(17) As Byte 'Byte-Array
Dim Bz As Byte 'ByteanZahl
Dim Block As Byte 'Speicherbank/Speicherblock
Dim I1 As Byte 'Index-Variable
' #############################################################################
' #############################################################################
Do
I2cstart
I2cwbyte 16kw 'auf Karte prüfen
I2cstop
If Err = 1 Then
Led = 1
Print "Keine Chipkarte erkannt!"
Wait 1
Return
Else
Led = 0
Print ""
Print "Bitte waehlen:"
Print "0 = 16K-Karte lesen"
Print "3 = 16K-Karte schreiben"
Print "5 = 16K-Speicher-Block nummerieren (1-255)"
Print "7 = 16K-Speicher-Block komplett loeschen (&HFF)"
Print "9 = 16K-Speicher-Block anzeigen"
Print ""
Input "Eingabe= " , I1
End If
Select Case I1
Case 0 : Gosub 16k_read
Case 3 : Gosub 16k_write
Case 5 : Gosub 16k_fuellen
Case 7 : Gosub 16k_loeschen
Case 9 : Gosub 16k_anzeige
End Select
Loop
End 'end program
' #############################################################################
16k_read:
Print ""
Print ""
Print "EEPROM auslesen..."
Print ""
Gosub Block_adresse
Input "Speicher-Start-Byte angeben: " , Wert(1)
Input "Wieviele Bytes lesen? (max.16) = " , Bz
I2creceive 16k_w , Wert(1) , 1 , Bz
Print ""
Print ""
Print "Ergebnis:"
For I1 = 1 To Bz
Print I1 ; ". empfangenes Byte= " ; Wert(i1)
Next I1
Print ""
Print ""
Wait 1
Return
' #############################################################################
16k_write:
Print ""
Print ""
Print ""
Print "EEPROM beschreiben..."
Print ""
Gosub Block_adresse
Input "Speicher-Start-Byte angeben: " , Wert(1)
Input "Wieviele Bytes schreiben? (max.16) = " , Bz
Incr Bz
For I1 = 2 To Bz
Input "Byte-Wert eingeben= " , Wert(i1)
Next I1
I2csend 16k_w , Wert(1) , Bz
Print ""
Print ""
Print "Erledigt !"
Print ""
Print ""
Wait 1
Return
' #############################################################################
16k_fuellen:
Print ""
Print "EEPROM-Speicherbereich nummerieren (max. 255)..."
Print ""
Gosub Block_adresse
Input "Speicher-Startadresse= " , Wert(1)
Input "...bis Speicherzelle= " , Wert(17)
For Wert(2) = 0 To Wert(17)
I2csend 16k_w , Wert(1) , 2
Waitms 5
Incr Wert(1)
Next Wert(2)
Print ""
Print "Eledigt !"
Print ""
Wait 1
Return
' #############################################################################
16k_loeschen:
Print ""
Print ""
Print ""
Print "Gesamter EEPROM-BLOCK-Speicher wird geloescht (&HFF)!!!"
Print "7= Ja oder 0= NEIN"
Print ""
Input "Eingabe= " , I1
Select Case I1
Case 7
For I1 = 2 To 17
Wert(i1) = &HFF
Next I1
Gosub Block_adresse
Wert(1) = &H00
For I1 = 1 To 16
I2csend 16k_w , Wert(1) , 17
Wert(1) = Wert(1) + 16
Waitms 5
Next I1
Print ""
Print "Speicher geloescht!"
Print ""
Waitms 250
Case Else
Print ""
Print "Vorgang abgebrochen!"
Print ""
Print ""
Waitms 500
End Select
Return
' #############################################################################
16k_anzeige:
Print ""
Print "Speicherbereich anzeigen..."
Print ""
Gosub Block_adresse
Input "Speicher-Start= " , Wert(16)
Input "Speicher-Ende= " , Wert(17)
Waitms 250
For Wert(15) = Wert(16)to Wert(17)
Wert(1) = Wert(15)
I2creceive 16k_w , Wert(1) , 1 , 1
If Wert(1) < 255 Then
Print Spc(3) ; "Speicherzelle " ; Wert(15) ; " hat den Wert= " ; Wert(1)
Else
End If
Next Wert(15)
Print ""
Print "ENDE"
Print ""
Print ""
Wait 1
Return
' #############################################################################
Block_adresse:
Input "Block angeben: " , Block
If Block > 7 Then
Print "Eingabe fehlerhaft!"
Print "Nur 0-7 erlaubt!"
Print "Abbruch..."
Waitms 500
Print ""
Print ""
Return
Else
Shift Block , Left , 1
16k_w = 16kw + Block
End If
Return