Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $regfile = "m8def.dat"
- $crystal = 8000000
- Ddrb = &B00011100 : Portb = &B11100011
- Ddrc = &B00111000 : Portc = &B00000000
- Ddrd = &B11111111 : Portd = &B00000000
- Config Timer2 = Timer , Prescale = 8 , Compare = Disconnect , Clear Timer = 1
- Enable Compare2 : On Compare2 Int0_isr : Compare2 = 124
- Config Adc = Single , Prescaler = Auto , Reference = Avcc
- Start Adc
- Enable Interrupts
- '****************** Zmienne *******************
- '***********************************************
- Dim Licznik As Byte
- Dim Licz As Byte
- Dim Max_pwm As Byte
- Dim Pwm_led(17) As Byte
- Dim Speed As Word '
- Dim Scenario As Byte
- Dim Z As Word
- Dim Czas As Word
- Dim Led_nr As Byte
- Dim Bit_1 As Bit
- Dim Leds_pwm As Byte
- Dim M As Byte
- Dim Old_val As Byte
- Dim L_d As Byte
- Dim Szybkosc As Word
- Dim Odlicz As Byte
- Dim Adc_read As Word
- Dim Result As Word
- D1 Alias Portd.2 : D2 Alias Portd.3 : D3 Alias Portd.4 : D4 Alias Portd.5
- '*************** przyciski *****************
- Sw1 Alias Pinb.0
- Sw2 Alias Pinb.1
- '*************************************************
- '************** Petla glowna ******************
- Bit_1 = 0
- Szybkosc = 100
- Speed = 0
- Result = 0
- Led_nr = 1
- Do
- Adc_read = Getadc(2)
- Adc_read = Adc_read
- If Sw1 = 0 Or Sw2 = 0 And Bit_1 = 0 Then
- Bit_1 = 1
- Led_nr = 1
- Scenario = 1
- End If
- If Speed = 0 Then
- '
- Select Case Scenario
- Case 0
- '************************************************************************************
- Case 1
- ' * * * * * * * * * * * * * * * * * * * * * * * * *
- If Led_nr < 100 Then Incr Led_nr
- If Old_val <> Led_nr Then
- Old_val = Led_nr
- Speed = 127 - Led_nr
- Speed = Szybkosc
- Shift Speed , Left , 1
- M = Memcopy(led_nr , Pwm_led(1) , 17 , 2)
- End If
- If Pwm_led(4) = 100 Then
- Scenario = 2
- End If
- Case 2
- Incr Result
- Waitms 50
- If Sw1 = 0 Or Sw2 = 0 Then
- Result = 0
- End If
- If Result >= Adc_read Then
- Result = 0
- Scenario = 3
- End If
- Case 3
- If Led_nr > 0 Then Decr Led_nr
- If Old_val <> Led_nr Then
- Old_val = Led_nr
- Speed = 127 - Led_nr
- Speed = Szybkosc
- Shift Speed , Left , 1
- M = Memcopy(led_nr , Pwm_led(1) , 17 , 2 )
- End If
- Bit_1 = 0
- End Select
- End If
- Loop
- '************ Przerwanie timer 0 ***************
- '***********************************************
- Int0_isr:
- Incr Licznik
- If Licznik = 100 Then Licznik = 0
- If Licznik < Pwm_led(1) Then Set D1 Else Reset D1
- If Licznik < Pwm_led(2) Then Set D2 Else Reset D2
- If Licznik < Pwm_led(3) Then Set D3 Else Reset D3
- If Licznik < Pwm_led(4) Then Set D4 Else Reset D4
- If Speed > 0 Then Decr Speed
- Return
