Pilot IR NEC
: 12 sty 2018, 11:19
Witam, tak bawię się pilotem z aliexpress na kodzie zaczerpniętym ze strony kaktusa i o ile odczytywanie działa prawidłowo to mam problem ze sterowaniem portami.
W tym układzie jak nacisnę przycisk pilota to "set led_0" powoduje załączenie diody na stałe ,a "toggle" działa bardzo losowo.
Możesz zerknąć aby to zadziałało na zasadzie naciskam przycisk to led świeci, puszczam to gaśnie oraz jedno naciśnięcie zaświeci a kolejne wygasi.
W tym układzie jak nacisnę przycisk pilota to "set led_0" powoduje załączenie diody na stałe ,a "toggle" działa bardzo losowo.
Możesz zerknąć aby to zadziałało na zasadzie naciskam przycisk to led świeci, puszczam to gaśnie oraz jedno naciśnięcie zaświeci a kolejne wygasi.
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- [/'Tester pilotów NEC - dziala
- 'LCD: RS-PB.3 , ENA-PB.2 , D4-PB.6 , D5-PB.5 , D6-PB.7 , D7-PB.4
- 'WYJŚCIA: LED_G-PD.6 , LED_R-PD.4 , LED_B-PD.3 , LED_Y-PD.5 , LED_G-PD.1 , LED_R-PD.0
- 'ODBIORNIK IR-PD.2 (INT0)
- 'ODBIORNIK IR NEC-PD.3 (INT1)
- 'CKDIW 8 - wylaczone
- 'PORTA.0/PORTA.1 - kwarc ,PORTA.2 - reset
- 'Adres:0 , 1 – com: 162 , 2 – com: 98 , 3 – com: 226 , 4 – com: 34 , 5 – com: 2 , 6 – com: 194
- '7 – com: 224 , 8 – com: 168 , 9 – com: 144 , 0 – com: 152 , * - com: 104 , # - com: 176
- 'Góra - com: 24 , Dół – com: 74 , Lewo – com: 16 , Prawo – com: 90 , OK – com: 56
- '1 - com:34 ,
- $regfile = "attiny2313.dat"
- $crystal = 8000000
- $hwstack = 36
- $swstack = 36
- $framesize = 40
- Config Porta = &B11111100 : Porta = &B11111111
- Config Portb = &B11111100 : Portb = &B11111111
- Config Portd = &B11110011 : Portd = &B00001100
- Config Lcdpin = Pin , Db4 = PortB.6 , Db5 = Portb.5 , Db6 = Portb.7 , Db7 = Portb.4 , E = Portb.2 , Rs = Portb.3
- Config Lcd = 16 * 2
- Cursor Off
- Cls
- Config Timer0 = Timer , Prescale = 256 '8000000/256=31250 Hz
- Config Int1 = Falling 'Interruption on Falling
- Stop Timer0
- Enable Timer0
- Enable Int1
- Enable Interrupts
- On Timer0 Tikers 'work on timer
- On Int1 Infrared
- Locate 1 , 1
- Lcd "NEC DEC."
- Locate 2 , 1
- Lcd "Marekszy"
- 'Wait 1
- led_0 alias portd.0
- led_1 alias portd.1
- led_4 alias portd.4
- led_5 alias portd.5
- led_6 alias portd.6
- 'work on interruption
- Dim Got As Bit
- Dim Tik As Word 'counter of teaks of timer
- Dim Byt As Byte 'counter accepted bit
- Dim Repeat_flag As Bit 'flag of repetition
- Dim Start_flag As Bit 'flag of start condition
- Dim Address_1 As Byte 'direct byte of address
- Dim Command_1 As Byte 'direct byte of command
- Dim Address_0 As Byte 'indirect byte of address
- Dim Command_0 As Byte 'indirect byte of command
- Dim Summa As Word
- Dim Address_nec As Byte , Command_nec As Byte
- Cursor Off 'Switch Off cursor
- '################################################################################################################
- Do 'Main cycle
- If Got = 1 Then
- Cls
- Locate 1 , 1
- Lcd "Adr:" ; Address_nec
- Locate 2 , 1
- Lcd "Com:" ; Command_nec 'Lcd ADDRESS and COMMAND
- Reset Got
- End If
- 'Waitms 10 'Delay 10 en
- If Address_nec <> 255 Then 'jeśli Wpisać "If Address=0 Then"
- 'to zawęzimy tylko do telewizorów
- Select Case Command_nec
- Case 162: 'przycisk pilota - 1
- set Led_0
- Case 98: 'przycisk pilota - 2
- toggle Led_1
- case 226: 'przycisk pilota - 3
- set led_5
- case 34: 'przycisk pilota - 4
- set led_4
- case 2: 'przycisk pilota - 5
- set led_6
- case 176: 'przycisk pilota - #
- reset led_0
- reset led_1
- reset led_4
- reset led_5
- reset led_6
- End Select
- End If
- Loop
- End 'End of main cycle
- '################################################################################################################
- Tikers: 'work on timer
- Timer0 = 253 '31250/(256-253)=10416,66 Hz (96 een)
- Incr Tik
- If Tik >= 1200 Then 'if 1200 teaks, have thrown all in source condition
- Tik = 0
- Repeat_flag = 0
- Start_flag = 0
- Address_1 = 255
- Command_1 = 255
- Address_0 = 0
- Command_0 = 0
- Address_nec = 255
- Command_nec = 255
- Stop Timer0
- End If
- Return
- '################################################################################################################
- Infrared: 'work on interruption
- Start Timer0
- If Tik >= 139 And Tik < 150 Then 'if has happenned from 139 before 150 teaks - "START"
- Address_nec = 1
- Repeat_flag = 0
- Start_flag = 1
- Address_1 = 255
- Command_1 = 255
- Address_0 = 0
- Command_0 = 0
- End If
- If Tik >= 116 And Tik < 139 Then 'if has happenned from 116 before 138 teaks - "REPETITION"
- Address_nec = 0
- Repeat_flag = 1
- Start_flag = 0
- End If
- If Tik >= 22 And Tik < 116 And Start_flag = 1 Then 'if has happenned from 22 before 115 teaks - have taken "1"
- Incr Byt
- If Byt < 9 Then
- Shift Address_1 , Left
- Address_1 = Address_1 + 1
- End If
- If Byt >= 9 And Byt < 17 Then
- Shift Address_0 , Left
- Address_0 = Address_0 + 1
- End If
- If Byt >= 17 And Byt < 25 Then
- Shift Command_1 , Left
- Command_1 = Command_1 + 1
- End If
- If Byt >= 25 Then
- Shift Command_0 , Left
- Command_0 = Command_0 + 1
- End If
- End If
- If Tik >= 10 And Tik < 22 And Start_flag = 1 Then 'if has happenned from 10 before 21 teaks - have taken "0"
- Incr Byt
- If Byt < 9 Then
- Shift Address_1 , Left
- End If
- If Byt >= 9 And Byt < 17 Then
- Shift Address_0 , Left
- End If
- If Byt >= 17 And Byt < 25 Then
- Shift Command_1 , Left
- End If
- If Byt >= 25 Then
- Shift Command_0 , Left
- End If
- End If
- Tik = 0
- If Byt = 32 Then
- Address_nec = Address_1
- Command_nec = Command_1
- Set Got
- Address_1 = 255
- Command_1 = 255
- Byt = 0
- Repeat_flag = 0
- Start_flag = 0
- Stop Timer0
- End If
- ReturnCodebox]