Code von unserem Servotestprg.
Hi,
hier ist unser Code:
Code:
'###################################################
'Servotest Prg
'###################################################
$regfile = "m32def.dat"
Declare Sub Rnb_servob(byval Servonummer As Byte , Byval Position As Integer)
'i2c-Test
Const Writepowerport_adr = &H7E 'I2C Adr PCF 2
Const Readpowerport_adr = &H7F 'I2C Adr PCF 2
Dim I2cdaten As Byte 'Datenbyte aus PCF8574
Dim T As Byte , Senddata As Byte
Dim X As Integer
Dim Y As Integer
X = 128
Y = 128
Senddata = 23
Config Scl = Portc.0 'Ports fuer IIC-Bus
Config Sda = Portc.1
'i2c-Test ENDE
Dim I As Byte
Dim J As Byte
Dim Con As Byte
J = 1
Dim Pos As Byte
$crystal = 8000000 'Quarzfrequenz
$baud = 9600
I2cinit
I2cstart
I2cwbyte &H74 'Schreibbefehl an PCF3 schicken
' Led´s ein ,Motorendstufen ein, Port-Peripherie ein, RBN-Bus Sleep Modus aus (also Peripherie aktiv)
I2cwbyte &B00000010 'Datenbyte an PCF3
I2cstop
Wiederhole:
Waitms 100
I2creceive Readpowerport_adr , Con
I2csend Writepowerport_adr , 0
If Con = 0 Then
X = X
Y = Y
End If
If Con = 1 Then
X = X - 50
If X <= 0 Then
X = 0
End If
End If
If Con = 2 Then
X = X - 10
If X <= 0 Then
X = 0
End If
End If
If Con = 3 Then
X = X - 1
If X <= 0 Then
X = 0
End If
End If
If Con = 10 Then
X = 128
End If
If Con = 13 Then
X = X + 50
If X >= 255 Then
X = 255
End If
End If
If Con = 12 Then
X = X + 10
If X >= 255 Then
X = 255
End If
End If
If Con = 11 Then
X = X + 1
If X >= 255 Then
X = 255
End If
End If
If Con = 200 Then
Y = Y + 10
If Y >= 255 Then
Y = 255
End If
End If
If Con = 210 Then
Y = Y - 10
If Y <= 0 Then
Y = 0
End If
End If
If Con = 220 Then
Y = 128
End If
If Con = 230 Then
Y = 80
End If
If Con = 100 Then
Call Rnb_servob(2 , 255)
Waitms 1000
Call Rnb_servob(2 , 128)
Waitms 1500
Call Rnb_servob(2 , 1)
Waitms 1000
End If
Call Rnb_servob(1 , X)
Call Rnb_servob(2 , Y)
'I2csend &H74 , 10100010
'I2csend Readpowerport_adr , 12
'I2cstart 'generate start
'I2cwbyte Writepowerport_adr 'send slave address
'I2cwbyte 1 'send address of EEPROM
'I2cwbyte 3 'send a value
'I2cstop
'Print "I2c gelesen, Wert1:" 'generate stop
'Print X
'I2creceive &H74 , X
Print "X ="
Print X
'I2csend &H74 , &B11000010
'Waitms 10000
'I2creceive &H74 , X
Print "Con ="
Print Con
Print "Y ="
Print Y
'Con = 0
'I2csend &H74 , 01000010 'wait 10 mS because that is the time that the chip needs to write the data
'Print "1000ms gewartet"
'
'
'I2cstart
'I2cwbyte Writepowerport_adr
'I2cwbyte 1
'I2cstart
'I2cwbyte Readpowerport_adr 'generate repeated start
'I2crbyte X , Nack
'I2cstop
'Print "I2c gelesen, Wert2:"
'Print X
'If X = 12 Then Goto Test
'I2creceive Readpowerport_adr , X
'Print "I2c READPORT gelesen, Wert:"
'Print X
Goto Wiederhole
Sub Rnb_servob(byval Servonummer As Byte , Byval Position As Integer)
Open "comd.7:9600,8,n,1" For Output As #2
Print #2 , "#s" ; Chr(servonummer) ; Chr(position)
Close #2
End Sub
End