1 | $regfile = "m32def.dat" ' ATMega32
|
2 | $crystal = 1000000 ' 1MHZ
|
3 | $baud = 2400 ' Baudrate
|
4 |
|
5 | $hwstack = 32 ' default use 32 for the hardware stack
|
6 |
|
7 | $swstack = 10 ' default use 10 for the SW stack
|
8 |
|
9 | $framesize = 16 ' default use 40 for the frame space
|
10 |
|
11 |
|
12 | '=====
|
13 |
|
14 | Config Scl = Portc.0 ' Porteinstellungen
|
15 | Config Sda = Portc.1
|
16 | Config I2cdelay = 10
|
17 |
|
18 | Declare Sub Write_eeprom(byval Adres As Byte , Byval Adres2 As Byte , Byval Value As Byte)
|
19 | Declare Sub Read_eeprom(byval Adres As Byte , Byval Adres2 As Byte , Value2 As Byte)
|
20 |
|
21 | Print "Startprogramm"
|
22 | Print
|
23 |
|
24 | ' 1010 E2 E1 E0 RW = 10100000 = 160
|
25 |
|
26 | Const Addressw = 160 'EEPROM SCHREIB ADRESSE
|
27 | Const Addressr = 161 'EEPROM LESE ADRESSE
|
28 |
|
29 |
|
30 | Dim Value As Byte 'Datenbyte
|
31 | Dim Value2 As Byte
|
32 | Dim Adres As Byte 'Byte der Adresse
|
33 | Dim Adres2 As Byte
|
34 | Dim Outputt As String * 1
|
35 |
|
36 | Dim A As Byte
|
37 |
|
38 |
|
39 |
|
40 | '1 Byte schreiben
|
41 | Call Write_eeprom(1 , 0 , &B01010000 ) 'schreiben
|
42 | Print "Geschrieben"
|
43 |
|
44 | Call Read_eeprom(1 , 0 , Value2 ) 'schreiben
|
45 | If Value2 = &B01010000 Then
|
46 | Print "P"
|
47 | Else
|
48 | Print "F"
|
49 | End If
|
50 |
|
51 |
|
52 |
|
53 | End
|
54 |
|
55 | 'sample of writing a byte to EEPROM 24C02
|
56 | Sub Write_eeprom(adres As Byte , Adres2 As Byte , Value As Byte)
|
57 | I2cstart 'Start
|
58 | I2cwbyte Addressw 'EEPROM Adresse Schreib
|
59 | I2cwbyte Adres 'Speicheradresse
|
60 | I2cwbyte Adres2 'Speicheradresse 'Speicheradresse
|
61 | I2cwbyte Value 'Inhalt
|
62 | I2cstop 'Stop
|
63 | Waitms 10 'Warten
|
64 | End Sub
|
65 |
|
66 |
|
67 | Sub Read_eeprom(adres As Byte , Adres2 As Byte , Value2 As Byte)
|
68 | I2cstart 'Start
|
69 | I2cwbyte Addressw 'EEPROM Adresse Schreib
|
70 | I2cwbyte Adres 'Speicheradresse 'Speicheradresse
|
71 | I2cwbyte Adres2 'Speicheradresse
|
72 | I2cstart
|
73 | I2cwbyte Addressr 'EEPROM Adresse Les
|
74 | I2crbyte Value2 , Nack 'read byte
|
75 | I2cstop 'Stop
|
76 | Waitms 10 'Warten
|
77 | End Sub
|