Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $regfile = "m8def.dat"
- $crystal = 8000000
- $hwstack = 64
- $swstack = 64
- $framesize = 64
- $eepromhex
- '$sim
- Dim Ka , Kb As Bit
- Dim X , Y , Z , L1 , L2 , L_t , N As Byte
- Dim Tab_u(50) , Tab_i(50) , Tab_t(50) As Word
- Dim Tab_l(3) As Byte
- Dim K_u , K_i , K_t As Word
- Dim S_u , S_t , S_i As Word
- Dim Wnt , T As Single
- '===============================================================================
- Declare Sub Cyfry(wartosc As Word , Byval Korr As Word , Byval Mult As Byte)
- '===============================================================================
- Config Portb = 255
- Portb = 255
- Config Portc = 44
- Portc = 108
- Config Portd = 252
- Portd = 255
- Config Timer2 = Pwm , Prescale = 256 , Compare Pwm = Clear Up
- Config Timer1 = Timer , Prescale = 8 , Clear Timer = 1 , Compare A = Disconnect , Compare B = Disconnect
- Config Adc = Single , Prescaler = Auto , Reference = Off
- '===============================================================================
- Pwm2 = 255 : Kb = 1 : Z = 1 : X = 1
- '===============================================================================
- Readeeprom K_u , 1
- Readeeprom K_i , 3
- Readeeprom K_t , 5
- Waitms 200
- Enable Interrupts
- Enable Compare1a
- Compare1a = 5000
- On Compare1a Pomiar
- Start Adc
- L1 = 7 : Z = 0
- Waitms 200
- '===============================================================================
- Do
- If Pind.0 = 0 Then
- Waitms 50
- If Pind.0 = 0 Then
- Waitms 50
- If Pind.0 = 0 Then
- Ka = 1
- If Ka = 1 And Kb = 0 Then
- Incr Z
- If Z > 2 Then
- Z = 0
- End If
- End If
- Kb = 1
- End If
- End If
- Else
- Ka = 0 : Kb = 0
- End If
- If T >= 60 Then
- Do
- Portb.0 = 0
- Pwm2 = 0
- Loop Until T <= 50
- Portb.0 = 1
- End If
- Loop
- End
- '===============================================================================
- Pomiar:
- Incr X
- If X > 50 Then
- X = 1
- End If
- S_u = 0 : S_i = 0 : S_t = 0
- Tab_u(x) = Getadc(0)
- Tab_i(x) = Getadc(1)
- Tab_t(x) = Getadc(4)
- For Y = 1 To 50
- S_u = S_u + Tab_u(y)
- S_i = S_i + Tab_i(y)
- S_t = S_t + Tab_t(y)
- Next Y
- T = S_t / K_t
- Wnt = T * -18
- Wnt = Wnt + 900
- Select Case Wnt
- Case Is > 180
- Wnt = 255
- Case Is < 0
- Wnt = 0
- End Select
- Pwm2 = Round(wnt)
- If Pinb.0 = 0 Then
- Call Cyfry(s_t , K_t , 10)
- Incr N
- If N = 100 Then
- Portd = Portd Or 223
- Portd.2 = 0
- Toggle Portd.5
- N = 1
- End If
- Else
- Select Case Z
- Case 0
- Call Cyfry(s_u , K_u , 10)
- Portd = Portd Or 255
- Portd = Portd And 123
- Case 1
- Call Cyfry(s_i , K_i , 100)
- Portd = Portd Or 255
- Portd = Portd And 183
- Case 2
- Call Cyfry(s_t , K_t , 10)
- Portd = Portd Or 255
- Portd = Portd And 219
- End Select
- End If
- Incr L1
- If L1 > 3 Then
- L1 = 1
- End If
- L_t = L1 + 4
- L2 = Lookup(tab_l(l1) , Kody)
- Portb = Portb Or 224
- Shiftout Portc.2 , Portc.3 , L2 , 0
- Portb.l_t = 0
- Return
- '===============================================================================
- Sub Cyfry:
- Local Tmp As Single , Cyfra , Temp As Word , N As Byte
- Tmp = Wartosc / Korr
- Tmp = Tmp * Mult
- Cyfra = Round(tmp)
- For N = 1 To 3
- Temp = Cyfra Mod 10
- Tab_l(n) = Temp
- Cyfra = Cyfra / 10
- Next N
- End Sub
- '===============================================================================
- Kody:
- Data 160 , 249 , 196 , 200 , 153 , 138 , 130 , 248 , 128 , 136
- '===============================================================================
- $eeprom
- Data 0 , 3500% , 2000% , 500%
- $data