Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $regfile = "m88pdef.dat"
- $crystal = 16000000
- $hwstack = 40
- $swstack = 16
- $framesize = 32
- 'consts ###############################################################################################################
- 'MCP4251 digital Poti
- 'n=0-256 -> 257 Positionen. Beim Lesen: Y=0=Error (bei den 6 Command Bits vorher).
- '
- 'Poti 0: W=0000_000n_nnnn_nnnn
- ' R= W:0000_11 R:Yn_nnnn_nnnn_1111_11
- 'Poti 1: W=0001_000n_nnnn_nnnn
- ' R= W:0001_11 R:Yn_nnnn_nnnn_1111_11
- Const Poti_r0 = &B0000_1100
- 'I/O ##################################################################################################################
- Ddrb = &B0000_0111
- Ddrc = &B0011_1111
- Ddrd = &B1000_1000
- Led Alias Portd.3
- Poti_cs Alias Portb.0 'chip select
- Poti_sdo Alias Portb.2 'serial data out
- Poti_clk Alias Portb.1 'clock
- Poti_sdi Alias Pind.6 'serial data in
- Poti_shdn Alias Portd.7 'shutdown
- 'vars #################################################################################################################
- Dim String3 As String * 3
- Dim Poti0 As Word
- Dim Positionpar As Word
- Dim Poti_cmd As Byte
- Dim Serialerr As Byte , Serialerr_count As Byte
- 'lcd ##################################################################################################################
- Config Lcd = 16x2
- Config Lcdpin = Pin , Db7 = Portc.0 , Db6 = Portc.1 , Db5 = Portc.2 , Db4 = Portc.3 , E = Portc.4 , Rs = Portc.5
- Cursor Off Noblink
- 'adc ##################################################################################################################
- Config Adc = Single , Prescaler = Auto , Reference = Avcc
- 'subs #################################################################################################################
- Declare Sub Setpoti0(byval Position As Word)
- 'startup ##############################################################################################################
- Poti_cs = 1 'inactive
- Poti_sdo = 0
- Poti_clk = 1 'idle high
- Poti_shdn = 1 'Poti ON
- Call Setpoti0(0)
- Cls
- 'main #################################################################################################################
- Do
- Poti0 = Getadc(6)
- Shift Poti0 , Right , 2
- If Poti0 = 255 Then
- Incr Poti0
- End If
- String3 = Str(poti0)
- Locate 1 , 1
- Lcd Format(string3 , "000")
- Call Setpoti0(poti0)
- String3 = Str(serialerr)
- Locate 2 , 1
- Lcd "ERR:" ; Format(string3 , "000")
- Waitms 100
- Loop
- End
- 'subs #################################################################################################################
- Sub Setpoti0(byval Position As Word)
- If Serialerr = 0 Then
- If Position > 256 Then
- Position = 256
- End If
- Positionpar = &HFFFF
- Serialerr_count = 0
- While Position <> Positionpar
- Poti_cs = 0
- Shiftout Poti_sdo , Poti_clk , Position , 1 , 16
- Poti_clk = 1
- If Poti_sdi = 0 Then
- Incr Serialerr_count
- Poti_cs = 1
- If Serialerr_count = 3 Then
- Serialerr.0 = 1 'cmd ungültig (write)
- Exit While
- End If
- Else
- Poti_cmd = Poti_r0
- Positionpar = 0
- Poti_cs = 1
- Poti_cs = 0
- Shiftout Poti_sdo , Poti_clk , Poti_cmd , 1 , 6
- Shiftin Poti_sdi , Poti_clk , Positionpar , 1 , 16
- Poti_clk = 1
- Poti_cs = 1
- If Positionpar.15 = 0 Then
- Incr Serialerr_count
- If Serialerr_count = 3 Then
- Serialerr.1 = 1 'cmd ungültig (read)
- Exit While
- End If
- Else
- Positionpar.15 = 0
- Shift Positionpar , Right , 6
- If Position <> Positionpar Then
- Incr Serialerr_count
- If Serialerr_count = 3 Then
- Serialerr.2 = 1 'Daten ungültig (read)
- Exit While
- End If
- End If
- End If
- End If
- Wend
- End If
- End Sub
Add Comment
Please, Sign In to add comment