سلام دوستان
من دوتا میکرو mega32 رو با I2C به هم وصل کردم ولی هی 255 رو میفرسته یا یه اعدادی غیر از A=125 که در برنامه send نوشته ام
برنامه میکرو فرستنده:
$regfile = "m32def.dat"
$crystal = 8000000
Config Sda = Portc.1 Config Scl = Portc.0
Config I2cdelay = 1
I2cstart
I2cinit
Const Slave = &H40
Dim A As Integer , B As Word
A = 125
Do
I2csend Slave , A
Waitms 10
Loop
برنامه میکروی گیرنده:
$regfile = "m32def.dat"
$crystal = 8000000
Config Lcdpin = Pin , Rs = Pinb.2 , E = Pinb.3 , Db4 = Pinb.4 , Db5 = Pinb.5 , Db6 = Pinb.6 , Db7 = Pinb.7
Config Lcd = 16 * 2
Cursor Off
Config I2cdelay = 1
Config Sda = Portc.1
Config Scl = Portc.0
I2cstart
I2cinit
Dim X As Word
Const Slave = &H40
Do
G:
I2creceive Slave , X
Waitms 10
If X = 255 Or X = 0 Then
Lcd " ERROR "
Waitms 25
Cls
Goto G
Else
Lcd "Recive=" ; X
Waitms 500
End If
Cls
Loop
End
من دوتا میکرو mega32 رو با I2C به هم وصل کردم ولی هی 255 رو میفرسته یا یه اعدادی غیر از A=125 که در برنامه send نوشته ام
برنامه میکرو فرستنده:
$regfile = "m32def.dat"
$crystal = 8000000
Config Sda = Portc.1 Config Scl = Portc.0
Config I2cdelay = 1
I2cstart
I2cinit
Const Slave = &H40
Dim A As Integer , B As Word
A = 125
Do
I2csend Slave , A
Waitms 10
Loop
برنامه میکروی گیرنده:
$regfile = "m32def.dat"
$crystal = 8000000
Config Lcdpin = Pin , Rs = Pinb.2 , E = Pinb.3 , Db4 = Pinb.4 , Db5 = Pinb.5 , Db6 = Pinb.6 , Db7 = Pinb.7
Config Lcd = 16 * 2
Cursor Off
Config I2cdelay = 1
Config Sda = Portc.1
Config Scl = Portc.0
I2cstart
I2cinit
Dim X As Word
Const Slave = &H40
Do
G:
I2creceive Slave , X
Waitms 10
If X = 255 Or X = 0 Then
Lcd " ERROR "
Waitms 25
Cls
Goto G
Else
Lcd "Recive=" ; X
Waitms 500
End If
Cls
Loop
End
دیدگاه