Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Drehgeber ###################################################################
- $regfile = "m88adef.dat"
- $crystal = 14745600
- $hwstack = 128
- $swstack = 128
- $framesize = 128
- Dim I As Dword , A As Byte , Count As Byte , I2 As Byte , Count2 As Byte
- dim count_funktion as byte
- Dim Xor_val As Byte , Old_val As Byte
- Dim Encoder_val(4) As dword, m_soll(4) as dword , m_funktion(4) as byte
- dim m_select as byte
- Dim Rx_dword As Dword , Tx_dword As Dword
- dim tx_dword_byte3 as byte at tx_dword + 3 overlay
- dim Funktion As Byte , select_m as byte
- Dim Adc_wert As Word
- Dim Ausgabe As String * 8 , Encoder_ausgabe As String * 5
- ' I/O #########################################################################
- Config Pinb.1 = Input
- Portb.1 = 1
- Config Portb.0 = Output
- Led Alias Portb.0
- Txtx Alias Portc.5
- Rxrx Alias Pinc.5
- Clk_out Alias Portc.4
- Clk_in Alias Pinc.4
- Ddrc = &B00000110
- Config Portd = Input
- Encoder_port Alias Pind
- ' LCD #########################################################################
- Config Lcdpin = Pin , Rs = Portc.2 , E = Portc.1 , Db4 = Portb.5 , _
- Db5 = Portb.4 , Db6 = Portb.3 , Db7 = Portb.2
- Config Lcd = 16x2
- Cursor Off Noblink
- Cls
- ' ADC #########################################################################
- Config Adc = Single , Prescaler = Auto , Reference = Avcc
- Start Adc
- ' startup #####################################################################
- Old_val = Encoder_port
- Led = 0
- declare sub funktion_select(byval x as byte)
- Wait 1
- ' Main ########################################################################
- Do
- Debounce Pinb.1 , 0 , Send_byte , Sub
- led = 1
- If Old_val <> Encoder_port Then
- 'Led = 1
- Xor_val = Old_val Xor Encoder_port
- Old_val = Encoder_port
- For I2 = 0 To 7 Step 1
- If Xor_val.i2 = 1 Then
- Select Case I2
- Case 0 To 1:
- Incr Encoder_val(1)
- if m_select.0 = 1 then
- call funktion_select(1)
- end if
- Case 2 To 3:
- Incr Encoder_val(2)
- if m_select.1 = 1 then
- call funktion_select(2)
- end if
- Case 4 To 5:
- Incr Encoder_val(3)
- if m_select.2 = 1 then
- call funktion_select(3)
- end if
- Case 6 To 7:
- Incr Encoder_val(4)
- if m_select.3 = 1 then
- call funktion_select(4)
- end if
- End Select
- End If
- Next
- Select Case Funktion
- case 0:
- End Select
- ' If Encoder_val(1) >= Rx_dword Then
- ' Gosub Send_byte
- ' Encoder_val(1) = 0
- ' End If
- 'Led = 0
- End If
- for count_funktion = 1 to 4 step 1
- if m_funktion(count_funktion) = 1 then
- count2 = count_funktion - 1
- tx_dword = encoder_val(count_funktion)
- tx_dword_byte3 = &b00010000
- tx_dword_byte3.count2 = 1
- gosub send_byte
- m_funktion(count_funktion) = 0
- end if
- if m_funktion(count_funktion) > 3 then
- call funktion_select(count_funktion)
- end if
- next
- If Clk_in = 0 Then
- 'led = 1
- 'Ddrc = &B00100110
- Config Txtx = Output
- Txtx = 0
- Bitwait Clk_in , Set
- Txtx = 1
- 'Ddrc = &B00000110
- Config Rxrx = Input
- For Count = 0 To 31 Step 1
- Bitwait Clk_in , Reset
- Rx_dword.count = Rxrx
- Bitwait Clk_in , Set
- Next
- For Count = 24 To 27 Step 1
- Count2 = Count - 24
- select_m.count2 = Rx_dword.count
- Rx_dword.count = 0
- Next
- For Count = 28 To 31 Step 1
- Count2 = Count - 28
- Funktion.count2 = Rx_dword.count
- Rx_dword.count = 0
- Next
- for count = 0 to 3 step 1
- if select_m.count = 1 then
- m_soll(count + 1) = rx_dword
- m_funktion(count + 1) = funktion
- m_select.count = 1
- if m_funktion(count + 1) = 0 then
- m_select.count = 0
- end if
- end if
- next
- 'led = 0
- End If
- led = 0
- Incr I
- If I = 100000 Then
- Adc_wert = Getadc(0)
- 'Tx_dword = Adc_wert
- 'Ausgabe = Str(tx_dword)
- 'Locate 1 , 1
- 'Lcd "TX: "
- 'Lcd Format(ausgabe , "000000")
- Ausgabe = Str(a)
- Locate 2 , 14
- Lcd Format(ausgabe , "000")
- 'Ausgabe = Str(rx_dword)
- 'Locate 2 , 1
- 'Lcd "RX: "
- 'Lcd Format(ausgabe , "000000")
- locate 1 , 1
- ausgabe = bin(m_funktion(1))
- lcd ausgabe
- locate 2 , 1
- ausgabe = bin(m_select)
- lcd ausgabe
- Encoder_ausgabe = Str(encoder_val(1))
- Locate 1 , 12
- Lcd Format(encoder_ausgabe , "00000")
- Incr A
- I = 0
- End If
- Loop
- End
- Send_byte:
- If Clk_in = 1 Then
- 'Ddrc = 00010110
- Config Clk_out = Output
- Clk_out = 0
- Bitwait Rxrx , Reset
- Clk_out = 1
- Bitwait Rxrx , Set
- 'Ddrc = 00110110
- Config Txtx = Output
- For Count = 0 To 31 Step 1
- Txtx = Tx_dword.count
- Clk_out = 0
- Waitus 2
- Clk_out = 1
- Next
- 'Ddrc = 00000110
- Config Rxrx = Input
- Config Clk_in = Input
- End If
- Return
- sub funktion_select(byval x as byte)
- 'led = 1
- select case m_funktion(x)
- case 2:
- if encoder_val(x) >= m_soll(x) then
- tx_dword = encoder_val(x)
- tx_dword_byte3 = &b00100000 or m_select
- gosub SEND_BYTE
- encoder_val(x) = 0
- end if
- case 3:
- end select
- 'led = 0
- end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement