hacker
09.04.2007, 18:49
hi,
es gab ja doch ab und zu mal ein paar Fragen nach der Ansteuerung für den ADNS2610 mit BASCOM.
Ich hab mich die Tage mal dran gemacht und das realisiert.
Anschluss ist der übliche, steht auch im DB des Chips.
Code:
$regfile = "m8def.dat"
$crystal = 16000000
$baud = 19200
Ddr_sck Alias Ddrd.6
Ddr_sdio Alias Ddrd.7
Port_sck Alias Portd.6
Port_sdio Alias Portd.7
Pin_sdio Alias Pind.7
Declare Sub Adns2610_init()
Declare Sub Adns2610_write_byte(byval Write_byte As Byte)
Declare Function Adns2610_read_byte() As Byte
Declare Sub Adns2610_write_operation(byval Address_byte As Byte , Byval Data_byte As Byte)
Declare Function Adns2610_read_operation(byval Address_byte As Byte) As Byte
Call Adns2610_init()
Dim X As Integer
Dim Y As Integer
X = 0
Y = 0
Dim X_cm As Single
Dim Y_cm As Single
Dim Read_data As Byte
Read_data = 0
Dim Tmp As Byte
Tmp = 0
Do
Read_data = Adns2610_read_operation(&H03)
If Read_data > &H7F Then
Tmp = &HFF - Read_data
Incr Tmp
X = X - Tmp
Else
X = X + Read_data
End If
X_cm = X * 0.00635
Print " X: " ; X_cm;
Read_data = Adns2610_read_operation(&H02)
If Read_data > &H7F Then
Tmp = &HFF - Read_data
Incr Tmp
Y = Y - Tmp
Else
Y = Y + Read_data
End If
Y_cm = Y * 0.00635
Print " Y: " ; Y_cm;
Waitms 500
Loop
End
Sub Adns2610_init:
Ddr_sck = 1
Ddr_sdio = 1
Port_sck = 1
Port_sdio = 1
Call Adns2610_write_operation(&H00 , &H80)
Call Adns2610_write_operation(&H00 , &H01)
End Sub
Sub Adns2610_write_byte(byval Write_byte As Byte)
Local I As Byte
Ddr_sdio = 1
For I = 7 To 0 Step -1
Port_sck = 0
Port_sdio = Write_byte.i
Waitus 1
Port_sck = 1
Waitus 1
Next I
Ddr_sdio = 0
Port_sdio = 0
End Sub
Function Adns2610_read_byte() As Byte
Local I As Byte
Local Data_byte As Byte
Waitus 250
For I = 7 To 0 Step -1
Port_sck = 0
Waitus 1
Port_sck = 1
Data_byte.i = Pin_sdio
Next I
Adns2610_read_byte = Data_byte
End Function
Sub Adns2610_write_operation(byval Address_byte As Byte , Byval Data_byte As Byte)
Address_byte = Address_byte Or &B10000000
Call Adns2610_write_byte(address_byte)
Call Adns2610_write_byte(data_byte)
End Sub
Function Adns2610_read_operation(byval Address_byte As Byte) As Byte
Call Adns2610_write_byte(address_byte)
Adns2610_read_operation = Adns2610_read_byte()
End Function
Vllt. kann der ein oder andere damit was anfangen. Ich stell ihn auch noch gleich ins Wiki dazu. zu dem PAN Bsp in C.
/Edit Ich seh grad, dass man da angemeldet sein muss....Ich muss jetzt los. Das mit dem Wiki schau ich mir die Tage an, oder einer von euch ist so nett, und machts da rein.
Gruß Hacker
es gab ja doch ab und zu mal ein paar Fragen nach der Ansteuerung für den ADNS2610 mit BASCOM.
Ich hab mich die Tage mal dran gemacht und das realisiert.
Anschluss ist der übliche, steht auch im DB des Chips.
Code:
$regfile = "m8def.dat"
$crystal = 16000000
$baud = 19200
Ddr_sck Alias Ddrd.6
Ddr_sdio Alias Ddrd.7
Port_sck Alias Portd.6
Port_sdio Alias Portd.7
Pin_sdio Alias Pind.7
Declare Sub Adns2610_init()
Declare Sub Adns2610_write_byte(byval Write_byte As Byte)
Declare Function Adns2610_read_byte() As Byte
Declare Sub Adns2610_write_operation(byval Address_byte As Byte , Byval Data_byte As Byte)
Declare Function Adns2610_read_operation(byval Address_byte As Byte) As Byte
Call Adns2610_init()
Dim X As Integer
Dim Y As Integer
X = 0
Y = 0
Dim X_cm As Single
Dim Y_cm As Single
Dim Read_data As Byte
Read_data = 0
Dim Tmp As Byte
Tmp = 0
Do
Read_data = Adns2610_read_operation(&H03)
If Read_data > &H7F Then
Tmp = &HFF - Read_data
Incr Tmp
X = X - Tmp
Else
X = X + Read_data
End If
X_cm = X * 0.00635
Print " X: " ; X_cm;
Read_data = Adns2610_read_operation(&H02)
If Read_data > &H7F Then
Tmp = &HFF - Read_data
Incr Tmp
Y = Y - Tmp
Else
Y = Y + Read_data
End If
Y_cm = Y * 0.00635
Print " Y: " ; Y_cm;
Waitms 500
Loop
End
Sub Adns2610_init:
Ddr_sck = 1
Ddr_sdio = 1
Port_sck = 1
Port_sdio = 1
Call Adns2610_write_operation(&H00 , &H80)
Call Adns2610_write_operation(&H00 , &H01)
End Sub
Sub Adns2610_write_byte(byval Write_byte As Byte)
Local I As Byte
Ddr_sdio = 1
For I = 7 To 0 Step -1
Port_sck = 0
Port_sdio = Write_byte.i
Waitus 1
Port_sck = 1
Waitus 1
Next I
Ddr_sdio = 0
Port_sdio = 0
End Sub
Function Adns2610_read_byte() As Byte
Local I As Byte
Local Data_byte As Byte
Waitus 250
For I = 7 To 0 Step -1
Port_sck = 0
Waitus 1
Port_sck = 1
Data_byte.i = Pin_sdio
Next I
Adns2610_read_byte = Data_byte
End Function
Sub Adns2610_write_operation(byval Address_byte As Byte , Byval Data_byte As Byte)
Address_byte = Address_byte Or &B10000000
Call Adns2610_write_byte(address_byte)
Call Adns2610_write_byte(data_byte)
End Sub
Function Adns2610_read_operation(byval Address_byte As Byte) As Byte
Call Adns2610_write_byte(address_byte)
Adns2610_read_operation = Adns2610_read_byte()
End Function
Vllt. kann der ein oder andere damit was anfangen. Ich stell ihn auch noch gleich ins Wiki dazu. zu dem PAN Bsp in C.
/Edit Ich seh grad, dass man da angemeldet sein muss....Ich muss jetzt los. Das mit dem Wiki schau ich mir die Tage an, oder einer von euch ist so nett, und machts da rein.
Gruß Hacker