'************* Konfiguracja uC ***************** '*********************************************** $regfile = "m162def.dat" $crystal = 16000000 Config Porta = &B11111111 : Porta = &B00000000 Config Portb = &B11100001 : Portb = &B00011111 Config Portc = &B11111111 : Portc = &B11111111 Config Portd = &B11111011 : Portd = &B11111111 Config Porte = &B11111111 : Porte = &B11111111 'Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0 'mirley UPT M162 'Config Lcd = 16 * 2 'Cls 'Cursor Off Noblink Config Timer1 = Timer , Prescale = 8 Enable Timer1 : On Timer1 Prztimer1 On Int0 Przzew0 Nosave Config Int0 = Low Level Enable Int0 Config Rc5 = Pind.2 , Wait = 2000 S_port Alias Porta Aura_port Alias Portb.6 Spec_port Alias Portb.5 Ir_led Alias Portb.7 Stb_led Alias Portb.0 Sw_port Alias Pinb H1_port Alias Portd H2_port Alias Portc Enable Interrupts '********** Konfiguracja uC Koniec ************ '****************** Zmienne ******************* '*********************************************** Dim Komenda As Byte , Adres As Byte Dim Odebrano As Bit Dim Stan_sw As Byte , Sw As Byte , Last_sw As Byte , Licznik_sw As Byte Dim Dziel As Word , Dziel2 As Byte , Dziel3 As Byte , Flag As Bit , Flag2 As Bit , Flag3 As Bit Dim Licznik As Byte Dim Stars(8) As Byte , Stars_i(8) As Byte , Stars_set(8) As Byte , Stars_p As Byte 'stany swiecenia gwiazd LED Dim Star_state As Byte , Star_licz As Byte Dim Aura As Byte , Aura_i As Byte , Aura_set As Byte Dim Special As Byte , Special_i As Byte , Special_set As Byte Dim H_on As Byte , H1_licz As Byte , H2_licz As Byte Dim I As Byte Dim Hb As Byte Dim Hb2 As Byte Dim Hbb As Bit Dim X As Word 'params Dim Mn As Byte , Mx As Byte '************* Zmienne Koniec **************** '************ Warunki Poczatkowe *************** '*********************************************** Stan_sw = Sw_port And &B00011110 Shift Stan_sw , Right , 1 Aura_set = 0 Special_set = 0 Star_state = 0 H_on = 0 If Aura_set = 0 And Special_set = 0 And Star_state = 0 And H_on = 0 Then Stb_led = 1 Else Stb_led = 0 'parametry Mn = 3 Mx = 50 'Lcd "test sufit" '******* Warunki Poczatkowe Koniec *********** Config Watchdog = 2048 Start Watchdog '************** Petla glowna ****************** '*********************************************** Do '****** Rc5 pilot ************** If Odebrano = 1 Then If Adres = 0 Then 'halogeny If Komenda = 16 Then Toggle H_on.0 If Komenda = 17 Then Toggle H_on.1 'specjalny kanał If Komenda = 6 Then Special_set = 0 If Komenda = 3 Then Special_set = 50 'aura If Komenda = 4 Then If Aura_set > 5 Then Decr Aura_set If Komenda = 1 Then If Aura_set < 50 Then Incr Aura_set If Aura_set < 5 Then Aura_set = 5 End If If Komenda = 7 Then Aura_set = 0 If Komenda = 13 Then Aura_set = 50 'gwiazdy If Komenda = 2 Then Star_state = 1 If Komenda = 5 Then Star_state = 2 If Komenda = 8 Then Star_state = 3 If Komenda = 0 Then Star_state = 4 If Komenda = 15 Then Star_state = 0 'inne If Komenda = 12 Then Aura_set = 0 Special_set = 0 Star_state = 0 H_on = 0 End If Set Ir_led 'Cls 'Lcd Komenda Waitms 20 Reset Ir_led End If Odebrano = 0 Enable Int0 End If '******************************** If Flag = 1 Then Flag = 0 Reset Watchdog 'fade all diodes For I = 1 To 8 If Stars_i(i) > Stars_set(i) Then Decr Stars_i(i) If Stars_i(i) < Stars_set(i) Then Incr Stars_i(i) X = Stars_i(i) * Stars_i(i) X = X / 25 Stars(i) = X Next I If Aura_i > Aura_set Then Decr Aura_i If Aura_i < Aura_set Then Incr Aura_i X = Aura_i * Aura_i X = X / 25 Aura = X If Special_i > Special_set Then Decr Special_i If Special_i < Special_set Then Incr Special_i X = Special_i * Special_i X = X / 25 Special = X 'switches Sw = Sw_port And &B00011110 Shift Sw , Right , 1 If Sw <> Stan_sw And Last_sw = Sw Then Incr Licznik_sw If Licznik_sw = 4 Then If Sw.0 <> Stan_sw.0 Then 'SW4 If Star_state = 0 Then Star_state = 1 Else Star_state = 0 End If If Sw.1 <> Stan_sw.1 Then 'SW3 If Aura_set = 0 Then Aura_set = 50 Else Aura_set = 0 End If If Sw.2 <> Stan_sw.2 Then 'SW2 Toggle H_on.0 End If If Sw.3 <> Stan_sw.3 Then 'SW1 Toggle H_on.1 End If Stan_sw = Sw Set Ir_led Waitms 20 Reset Ir_led End If Else Last_sw = Sw Licznik_sw = 0 End If End If '******************************** If Flag2 = 1 Then Flag2 = 0 'halogeny If H_on.0 = 1 Then If H1_licz < 6 Then Incr H1_licz Else If H1_licz > 0 Then Decr H1_licz End If If H_on.1 = 1 Then If H2_licz < 6 Then Incr H2_licz Else If H2_licz > 0 Then Decr H2_licz End If Hb = Lookup(h1_licz , H1_data) Hb2 = H1_port And &B00001111 H1_port = Hb Or Hb2 Hb = Lookup(h1_licz , H1_datab) Hb2 = Lookup(h2_licz , H2_data) H2_port = Hb Or Hb2 '******************************** End If If Flag3 = 1 Then Flag3 = 0 If Aura_set = 0 And Special_set = 0 And Star_state = 0 And H_on = 0 Then Stb_led = 1 Else Stb_led = 0 'sekwencyjny gaszenie wszystkich gwiazd, po kliknieciu przelacznika lub na pilocie If Star_state = 0 Then Incr Star_licz If Star_licz = 9 Then Star_licz = 1 Stars_set(star_licz) = 0 End If If Star_state = 1 Then ' Cls Incr Star_licz If Star_licz = 9 Then Star_licz = 1 If Stars_set(star_licz) <> Mx Then Stars_set(star_licz) = Mx Else Stars_set(star_licz) = Mn 'Lcd Stars_set(star_licz) ; " " End If If Star_state = 2 Then 'Cls Incr Star_licz If Star_licz = 9 Then Star_licz = 1 Hb = Mx - Mn Hb = Rnd(hb) Hb = Hb + Mn Stars_set(star_licz) = Hb 'Lcd Stars_set(star_licz) ; " " End If If Star_state = 3 Then 'Cls Hb = Rnd(250) Star_licz = Hb Mod 8 Hb = Hb / 8 Hb = Hb Mod 3 If Hb = 0 Then Stars_set(star_licz + 1) = 0 If Hb = 1 Then Stars_set(star_licz + 1) = 25 If Hb = 2 Then Stars_set(star_licz + 1) = 50 'Lcd Star_licz ; " " ; Hb ; " " ; Stars_set(star_licz) ; " " End If If Star_state = 4 Then Incr Star_licz If Star_licz = 9 Then Star_licz = 1 Stars_set(star_licz) = 50 End If 'Lowerline 'Lcd Star_state End If '******************************** Loop End '************ Petla glowna Koniec ************** '********** Przerwanie Zewnetrzne ************** '*********************************************** Przzew0: Disable Int0 Enable Interrupts Getrc5(adres , Komenda) Komenda = Komenda And &B01111111 Odebrano = 1 Return '****** Przerwanie zewnetrzne koniec ********** '************ Przerwanie timer 0 *************** '*********************************************** Prztimer1: Timer1 = 65286 Incr Licznik If Licznik = 100 Then Licznik = 0 If Licznik < Stars(1) Then Set Stars_p.0 Else Reset Stars_p.0 If Licznik < Stars(2) Then Set Stars_p.1 Else Reset Stars_p.1 If Licznik < Stars(3) Then Set Stars_p.2 Else Reset Stars_p.2 If Licznik < Stars(4) Then Set Stars_p.3 Else Reset Stars_p.3 If Licznik < Stars(5) Then Set Stars_p.4 Else Reset Stars_p.4 If Licznik < Stars(6) Then Set Stars_p.5 Else Reset Stars_p.5 If Licznik < Stars(7) Then Set Stars_p.6 Else Reset Stars_p.6 If Licznik < Stars(8) Then Set Stars_p.7 Else Reset Stars_p.7 If Licznik < Aura Then Set Aura_port Else Reset Aura_port If Licznik < Special Then Set Spec_port Else Reset Spec_port S_port = Stars_p Incr Dziel If Dziel = 400 Then Dziel = 0 Set Flag Incr Dziel2 If Dziel2 = 2 Then Dziel2 = 0 Set Flag2 Incr Dziel3 If Dziel3 = 5 Then Dziel3 = 0 Set Flag3 End If End If End If Return '******** Przerwanie timer 0 Koniec ************ ' 0 1 2 3 4 5 6 H1_data: Data &B11110000 , &B01110000 , &B00110000 , &B00010000 , &B00000000 , &B00000000 , &B00000000 H1_datab: Data &B00000011 , &B00000011 , &B00000011 , &B00000011 , &B00000011 , &B00000010 , &B00000000 H2_data: Data &B11111100 , &B11111000 , &B11110000 , &B11100000 , &B11000000 , &B10000000 , &B00000000