Klar kann der ATMega8 das.


Code:
$regfile = "m8def.dat"
$crystal = 16000000
$baud = 19200


Ddr_sck Alias Ddrc.4
Ddr_sdio Alias Ddrc.5

Port_sck Alias Portc.4
Port_sdio Alias Portc.5
Pin_sdio Alias Pinc.5

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

On Urxc Onrxd
Enable Urxc
Enable Interrupts

Dim Empfangsbyte As Byte
Dim Zeichen As String * 1
Dim Print_byte As Byte

Declare Sub Picture()
Declare Sub Properties()
Declare Sub Xy()

Call Adns2610_init()



Dim Read_data As Byte

Read_data = 0




Do





Loop
End

Onrxd:

  Empfangsbyte = Udr

  Zeichen = Chr(empfangsbyte)

  If Zeichen = "#" Then

      Call Picture()

  End If

  If Zeichen = "!" Then

      Call Properties()

  End If

  If Zeichen = "$" Then

      Call Xy()

  End If

Return

Sub Picture()

   Call Adns2610_write_operation(&H00 , &H01)

   Waitus 500

   Call Adns2610_write_operation(&H08 , &H00)

   Waitus 100

   Local I As Integer

   For I = 1 To 324

      Print_byte = Adns2610_read_operation(&H08)

      Print Print_byte;

      Waitms 10

   Next I

End Sub

Sub Properties()

   Print_byte = Adns2610_read_operation(&H04)

   Print Print_byte;

   Waitms 10

   Print_byte = Adns2610_read_operation(&H09)

   Print Print_byte;

   Waitms 10

   Print_byte = Adns2610_read_operation(&H0a)

   Print Print_byte;

End Sub

Sub Xy()

   Print_byte = Adns2610_read_operation(&H03)

   Print Print_byte;

   Waitms 10

   Print_byte = Adns2610_read_operation(&H02)

   Print Print_byte;

End Sub

Sub Adns2610_init()

   Ddr_sck = 1
   Ddr_sdio = 1

   Port_sck = 1
   Port_sdio = 1

   Call Adns2610_write_operation(&H00 , &H80)

   Waitus 250

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
Ich hab den jetzt aber nicht gekürzt. Aber ich denke, da sollte jeder in der Lage sein, die nötigen Subs herraus zu lesen.

Viel Erfolg damit.

Wenn noch Fragen bzgl. Maussensor sind, einfach fragen.

Gruß
Hacker