my code to write a page in at24c08 is here:
[code:1:18135b7c73]$regfile = "m32def.dat"
$crystal = 4000000
'-------------------------------------------------------------------------------
Open "comd.6:9600,8,n,1" For Output As #1
Print #1 , "start"
'-------------------------------------------------------------------------------
Config Sda = Portd.4
Config Scl = Portd.5
Config I2cdelay = 1
Const Eeread = 161
Const Eewrite = 160
'-------------------------------------------------------------------------------
Config Portd.7 = Output
Tester Alias Portd.7
'-------------------------------------------------------------------------------
Dim Address As Word , Highaddress As Byte , Lowaddress As Byte , Highintvar As Byte , Lowintvar As Byte
Dim Intvar As Integer
Dim J As Integer
Dim I As Integer
'-------------------------------------------------------------------------------
Config Portd.2 = Output
Intr Alias Portd.2
'-------------------------------------------------------------------------------
J = -30500
For I = 0 To 50
J = J + I
'Print #1 , J
Address = I
Highaddress = High(address)
Lowaddress = Low(address)
Highintvar = High(j)
Lowintvar = Low(j)
Print #1 , J
'Print #1 , I
'Print #1 , Highintvar
'Print #1 , Lowintvar
'Print #1 , "------"
Gosub Writeeepromserial
Toggle Tester
Next I
Print #1 , "read"
For I = 0 To 50
Address = I
Highaddress = High(address)
Lowaddress = Low(address)
Gosub Readeepromserial
'Print #1 , Highintvar
'Print #1 , Lowintvar
Intvar = Makeint(lowintvar , Highintvar)
Print #1 , Intvar
'Print #1 , "------"
Next I
End
'-------------------------------------------------------------------------------
Writeeepromserial:
I2cstart
I2cwbyte Eewrite
I2cwbyte Highaddress
I2cwbyte Lowaddress
I2crbyte Highintvar
I2crbyte Lowintvar
I2cstop
Waitms 5
Return
'-------------------------------------------------------------------------------
Readeepromserial:
I2cstart
I2cwbyte Eewrite
I2cwbyte Highaddress
I2cwbyte Lowaddress
I2cstart
I2cwbyte Eeread
I2crbyte Highintvar , Nack
I2cstop
Waitms 5
I2cstart
I2cwbyte Eewrite
I2cwbyte Highaddress
I2cwbyte Lowaddress
I2cstart
I2cwbyte Eeread
I2crbyte Lowintvar , Nack
I2cstop
Waitms 5
Return
'-------------------------------------------------------------------------------
[/code:1:18135b7c73]
↧