Hallo,
ich fange gerade an mich mit MC Programmierung auseinander zu setzen.
Ich würde gerne ein digital Potentiometer des Typs DS1867 laden/steuern und habe mal das folgende Programm geschrieben. Da ich das betreffende Poti leider gerade noch nicht da habe, wollte ich einmal nachfragen ob es mit meinem Programm funktionieren könnte oder ob ich da etwas falsch machte bzw ob es nicht einen eleganteren Weg gibt um es zu laden.


' Digital Potentiometer Steuerung DS1867

$regfile = "m8def.dat"
$crystal = 8000000 'Quarz/Taktefrequenz

Config Portb.1 = Output 'CLK
Config Portb.2 = Output 'RST
Config Portb.3 = Output 'DQ

Config Portc.1 = Input
Config Portc.2 = Input

Declare Sub Potiladen(widerstand1 As Byte , Widerstand2 As Byte)

Dim Mybaud As Long
Dim Bitnr As Byte
Dim Ende As Byte
Dim Widerstand1 As Byte
Dim Widerstand2 As Byte

Ende = 17 '17 Bits
Widerstand1 = 127
Widerstand2 = 127

Mybaud = 19200

Do
Ende = 17

If Portc.1 = 1 Or Portc.2 = 1 Then
Portb.2 = 1

If Portc.3 = 0 Then 'Stack -Widerstand- 1
If Portc.1 = 1 Then
Incr Widerstand1
End If
If Portc.2 = 1 Then
Decr Widerstand1
End If

Call Potiladen(widerstand1 , Widerstand2)

End If 'nun sollten alle 17 Bits gesetzt sein
'Das laden aller 17 bits ist erforderlich weil sonst
'Fehler auftreten können

If Portc.3 = 1 Then 'Stack -Widerstand-2
If Portc.1 = 1 Then
Incr Widerstand2
End If
If Portc.2 = 1 Then
Decr Widerstand2
End If

Call Potiladen(widerstand1 , Widerstand2)

End If



Portb.2 = 0
End If

Loop
End

'--------------------------------------------------------------------------------------------------
Sub Potiladen(widerstand1 As Byte , Widerstand2 As Byte)

Portb.3 = 0 'Das Stack Select Bit wird gesetzt
Portb.1 = 1 ' Muß hier nun eine 1 stehen ?? !!!!!(Also bei dem SSB)
Portb.1 = 0

For Bitnr = 0 To 7
Portb.3 = Widerstand1.bitnr 'Hier sollte das MSB des Widerstandswertes1 kommen
Portb.1 = 1 ' Überprüfen ob 0 das MSB oder LSB ist !!!!
Portb.1 = 0
Next

For Bitnr = 0 To 7
Portb.3 = Widerstand2.bitnr 'Hier sollte das MSB des Widerstandswertes2 kommen
Portb.1 = 1
Portb.1 = 0
Next

End Sub
[/code]