Hallo Leute!
Ich bin neu hier und auch auf dem Gebiet der µC!
Ich habe mir als erstes ein kleines Projekt überlgt, bei dem die über eine Tastatur eingegebenen Werte gespeichert werden und wenn benötigt wieder ausgegeben werden! Ohne Sinn
So, zum Speichern verwende ich einen AT24C64 von Atmel, den ich über den I2C ansteuern möchte!( Atmega8 )
Die Hardware ist soweit in Ordnung!
Aber ich glaub in meinem Prog. ist der wurm
Max 232, sowie Tastatur input funktionieren, nur irgendwie das Speichern auf dem EEPROM nicht!
Kann einer helfen !?!
Code:
$regfile = "m8def.dat"
$crystal = 4000000

Config Keyboard = Pind.3 , Data = Pind.2 , Keydata = Keydata
Config Portd.6 = Output
Config Pinb.0 = Input
Config Pinb.1 = Input
Config Pinb.2 = Input

Lesen_start Alias Pinb.0
Senden_start Alias Pinb.1
Led Alias Portd.6
Led = 1
'-------------------------------------------------------------------------------
Config Sda = Portc.4
Config Scl = Portc.5
'-------------------------------------------------------------------------------
Declare Sub Write_eeprom(byval Adres As Byte , Byval Daten As Byte)
Declare Sub Read_eeprom(byval Adres As Byte , Daten As Byte)

Const Addressw = 160                                        'slave write address
Const Addressr = 161                                        'slave read address
'-------------------------------------------------------------------------------


Dim Z As Byte
Dim B As Byte
Dim Adres As Byte
Dim Daten As Byte
Adres = 0

Do

   If Lesen_start = 0 And Senden_start = 1 Then
      Z = Getatkbd()
      If Z > 0 Then
         Daten = Z
         Led = 0
         Waitms 10
         Led = 1
      End If

   Adres = Adres + 1
   Call Write_eeprom(adres , Daten)
      Else
      Led = 0
   End If


   If Lesen_start = 1 And Senden_start = 0 Then
      For B = 1 To Adres
      Call Read_eeprom(b , Daten)
      Next B
         Else
         Led = 0
   End If
Loop
End






Keydata:
' Shift-Taste nicht gedrückt
Data 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , &H5E , 0
Data 0 , 0 , 0 , 0 , 0 , 113 , 49 , 0 , 0 , 0 , 122 , 115 , 97 , 119 , 50 , 0
Data 0 , 99 , 120 , 100 , 101 , 52 , 51 , 0 , 0 , 32 , 118 , 102 , 116 , 114 , 53 , 0
Data 0 , 110 , 98 , 104 , 103 , 121 , 54 , 7 , 8 , 44 , 109 , 106 , 117 , 55 , 56 , 0
Data 0 , 44 , 107 , 105 , 111 , 48 , 57 , 0 , 0 , 46 , 45 , 108 , 48 , 112 , 43 , 0
Data 0 , 0 , 0 , 0 , 0 , 92 , 0 , 0 , 0 , 0 , 13 , 0 , 0 , 92 , 0 , 0
Data 0 , 60 , 0 , 0 , 0 , 0 , 8 , 0 , 0 , 49 , 0 , 52 , 55 , 0 , 0 , 0
Data 48 , 44 , 50 , 53 , 54 , 56 , 0 , 0 , 0 , 43 , 51 , 45 , 42 , 57 , 0 , 0

' Shift-Taste gedrückt
Data 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
Data 0 , 0 , 0 , 0 , 0 , 81 , 33 , 0 , 0 , 0 , 90 , 83 , 65 , 87 , 34 , 0
Data 0 , 67 , 88 , 68 , 69 , 0 , 35 , 0 , 0 , 32 , 86 , 70 , 84 , 82 , 37 , 0
Data 0 , 78 , 66 , 72 , 71 , 89 , 38 , 0 , 0 , 76 , 77 , 74 , 85 , 47 , 40 , 0
Data 0 , 59 , 75 , 73 , 79 , 61 , 41 , 0 , 0 , 58 , 95 , 76 , 48 , 80 , 63 , 0
Data 0 , 0 , 0 , 0 , 0 , 96 , 0 , 0 , 0 , 0 , 13 , 94 , 0 , 42 , 0 , 0
Data 0 , 62 , 0 , 0 , 0 , 8 , 0 , 0 , 49 , 0 , 52 , 55 , 0 , 0 , 0 , 0
Data 48 , 44 , 50 , 53 , 54 , 56 , 0 , 0 , 0 , 43 , 51 , 45 , 42 , 57 , 0 , 0

Sub Write_eeprom(byval Adres As Byte , Byval Daten As Byte)

I2cstart                                                    'start condition
I2cwbyte Addressw                                           'slave address
I2cwbyte Adres                                              'asdress of EEPROM
I2cwbyte Daten                                              'value to write
I2cstop                                                     'stop condition

Waitms 10                                                   'wait for 10 milliseconds
End Sub



Sub Read_eeprom(byval Adres As Byte , Daten As Byte)

I2cstart                                                    'generate start
I2cwbyte Addressw                                           'slave adsress
I2cwbyte Adres                                              'address of EEPROM
I2cstart                                                    'repeated start
I2cwbyte Addressr                                           'slave address (read)
I2crbyte Daten , Nack                                       'read byte
I2cstop                                                     'generate stop

End Sub
Ich danke euch