logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

[m32][BASCOM] emulacja komend rc5 jako przyciski

Ficu 09 Lis 2009 18:19 1531 12
REKLAMA
  • #1 7237250
    Ficu
    Poziom 31  
    Witam,
    od jakiegoś czasu próbuje zrobić poruszanie się po menu za pomocą nadajnika rc5. Namodziłem coś takiego, ale nie działa. Docelowo ma to działać: jeżeli układ odbierze komendę 10 to ma wejść do wyższej pozycji w menu. Czy można jakoś emulować odebrane komendy jako zwykły przycisk? Wysyłana jest komenda 10 to S1=0, wysyłana komenda 20 to S2=0 itd.
    Config Int0 = Low Level
    On Int0 Rc_5
    Enable Interrupts
    Enable Int0
    Sub Menu
    Menu = 1
    
    Do
       Disable Int0
       Call Lcdinit
       Select Case Menu
       Case Is = 1
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 1
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 2
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 1
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 3
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 1
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 4
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 1
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 5
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 1
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 6
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 1
          Lcdupdate
    
       End Select
    If Gora = 1 And Menu < 6 Then
       Incr Menu
       Reset Gora
    Waitms 222
    End If
    
    If Gora = 1 And Menu = 6 Then
       Menu = 1
       Reset Gora
    Waitms 222
    End If
    
    If Dol = 1 And Menu > 1 Then
       Decr Menu
       Reset Dol
    Waitms 222
    End If
    
    If Dol = 1 And Menu = 1 Then
       Menu = 6
       Reset Dol
    Waitms 222
    End If
    Enable Int0
    Loop
    
    Rc_5:
    Disable Int0
    Enable Interrupts
    Getrc5(address , Command)
       Command = Command And &B01111111
       Select Case Command
       Case 10 :
       Set Gora
       Case 20 :
       Set Dol
       Case 30 :
       Set Lewo
       Case 40 :
       Set Prawo
       End Select
    Return
    End Sub
  • REKLAMA
  • Pomocny post
    #2 7238129
    LED5W
    Poziom 34  
    Moim zdaniem jakoś dziwnie masz te przerwania sterowane.
    Po co w przerwaniu masz Enable Interrupts - włączasz raz na początku i nie wyłączasz.
    Disable Int0 w pętli głównej też raczej nie jest dobrym pomysłem.
    Przed Enable Int0 proponuję dopisać zerowanie flagi przerwania, a na końcu (pętli) idle - dzięki temu po przerwaniu pętla zacznie "iść" od początku.
  • REKLAMA
  • #3 7239315
    Ficu
    Poziom 31  
    Chyba lepiej jak zacznę od czegoś łatwiejszego. Jak mogę zrobić aliasy: komenda 10 to przycisk1 = 1, komenda 20 to przycisk2 = 1, komenda 255 to przycisk1 = 0, przycisk2 = 0?
  • Pomocny post
    #4 7241051
    LED5W
    Poziom 34  
    Ficu napisał:
    Jak mogę zrobić aliasy: komenda 10 to przycisk1 = 1, komenda 20 to przycisk2 = 1, komenda 255 to przycisk1 = 0, przycisk2 = 0?

    Nie możesz. :P Aliasy to tylko dodatkowa nazwa, a ty chcesz bajtem ustawiać odpowiedni bit.
    Mógłbyś tak zrobić gdyby był ustawiany konkretny bit w bajcie, np.
    Command.0 Alias przycisk1


    Moja propozycja jest taka: W przerwaniu odczytaj tylko Command. W pętli do odpowiedniej komendy przypisz odpowiednie czynności przez Select Case.
  • REKLAMA
  • #5 7241176
    Ficu
    Poziom 31  
    Program będzie miał jeszcze kilka podprogramów dlatego chciałem aliasować. Wieczorem zrobi tak jak proponujesz.
  • REKLAMA
  • #6 7245639
    Ficu
    Poziom 31  
    Nie ogarniam tego. Mógłbyś nanieść poprawki i napisać dlaczego tak?
    Config Int0 = Low Level
    On Int0 Rc_5
    Enable Interrupts
    Enable Int0
    Sub Menu
    Menu = 1
    Set Cykl
    Do
       Call Lcdinit
       Select Case Menu
       Case Is = 1
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 1
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 2
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 1
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 3
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 1
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 4
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 1
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 5
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 1
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 6
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 1
          Lcdupdate
    
       End Select
    If Gora = 1 And Menu < 6 Then
       Incr Menu
       Reset Gora
    Waitms 222
    End If
    
    If Gora = 1 And Menu = 6 Then
       Menu = 1
       Reset Gora
    Waitms 222
    End If
    
    If Dol = 1 And Menu > 1 Then
       Decr Menu
       Reset Dol
    Waitms 222
    End If
    
    If Dol = 1 And Menu = 1 Then
       Menu = 6
       Reset Dol
    Waitms 222
    End If
    Enable Int0
    Loop
    End
    
    Rc_5:
    Disable Int0
    Enable Interrupts
    Getrc5(address , Command)
       Command = Command And &B01111111
       Select Case Command
       Case 10 :
    
       If Menu = 1 Then
       Set Gora
       End If
    
       Waitms 50
       Case 20 :
       If Menu = 1 Then
       Set Dol
       End If
       Waitms 50
       Case 30 :
       Set Lewo
       Waitms 50
       Case 40 :
       Set Prawo
       Waitms 50
       End Select
    Return
    End Sub
  • Pomocny post
    #7 7246306
    mirekk36
    Poziom 42  
    Przecież tyle na elektrodzie jest przykładów jak to zgrabnie robić w Bascomie. Ale przynajmniej kolega widać że się męczy sam a nie na gotowca poluje. Więc ok, ja to robię np tak:

    Inicjalizacja obsługi RC5
    Config Rc5 = Pind.3 
    Dim Address As Byte , Command As Byte
    Dim Ir_flag As Byte
    Ir_flag = 0
    
    On Int1 Int1_rc5
    Config Int1 = Low Level
    Enable Int1



    Obsługa kodów w pętli głównej:

    Do
    
    ..... jakiś kod
    
    If Ir_flag = 1 Then
    
       If Address <> 255 Then
    
          Command = Command And &B01111111
    
          If Command = 3 Then
             ... to zrób coś tam - jakaś funkcja1
          End If
    
          If Command = 4 Then
             ... to zrób coś tam - jakaś funkcja2
          End If
    
          ..... i tak dalej - kolejne klawisze i akcje
    
         Enable Int1
         Ir_flag = 0
    End If
    
    ..... jakiś kod
    
    Loop



    Obsługa przerwania
    Int1_rc5:
          Disable Int1
          Enable Interrupts
          If Ir_flag = 0 Then
             Getrc5(address , Command)
             Ir_flag = 1
          End If
    Return
  • #8 7246799
    Ficu
    Poziom 31  
    Dzięki za wskazówki, program zmodyfikowałem, ale dalej nie działa (hmm..)
    Ir_flag = 0
    On Int0 Rc_5
    Config Int0 = Low Level
    Enable Int0
    
    Sub Menu
    Menu = 1
    Do
       Call Lcdinit
       Select Case Menu
       Case Is = 1
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 1
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 2
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 1
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 3
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 1
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 4
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 1
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 5
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 1
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 0
          Lcdupdate
       Case Is = 6
          Lcdclear
          Lcdgoxy 1 , 1
          Lcdstr "wyb. tekstu" , 1 , 0
          Lcdgoxy 1 , 2
          Lcdstr "temperatura" , 1 , 0
          Lcdgoxy 1 , 3
          Lcdstr "data i godzina" , 1 , 0
          Lcdgoxy 1 , 4
          Lcdstr "zapis pam." , 1 , 0
          Lcdgoxy 1 , 5
          Lcdstr "napiecie bat." , 1 , 0
          Lcdgoxy 1 , 6
          Lcdstr "plan lekcji" , 1 , 1
          Lcdupdate
    
       End Select
    
    If Ir_flag = 1 Then
       If Address <> 255 Then
       Command = Command And &B01111111
          If Command = 10 And Menu < 6 Then
             Incr Menu
             Waitms 222
          End If
          If Command = 10 And Menu = 6 Then
             Menu = 1
             Waitms 222
          End If
          If Command = 20 And Menu > 1 Then
             Decr Menu
             Waitms 222
          End If
          If Command = 20 And Menu = 1 Then
             Menu = 6
             Waitms 222
          End If
       End If
       Enable Int0
       Ir_flag = 0
    End If
    Loop
    End Sub
    
    
    Rc_5:
    Disable Int0
    Enable Interrupts
    If Ir_flag = 0 Then
       Getrc5(address , Command)
       Ir_flag = 1
    End If
    Return

    sprawdzałem odbiornik i nadajnik i wszystko działa w programach testujących, a tu nie chce.
  • #10 7247080
    Ficu
    Poziom 31  
    Niestety nie.
    If Ir_flag = 1 Then
       Command = Command And &B01111111
       Call Lcdinit
       Str_address = Str(address)
       Str_address = Format(str_address , "" )
       Str_command = Str(command)
       Str_command = Format(str_command , "" )
       Lcdclear
       Lcdgoxy 1 , 1
       Lcdstr Str_address , 1 , 0
       Lcdgoxy 1 , 2
       Lcdstr Str_command , 1 , 0
       Lcdupdate
       Waitms 100
       If Address <> 255 Then
          If Command = 10 And Menu < 6 Then
             Incr Menu
             Waitms 222
          End If
          If Command = 10 And Menu = 6 Then
             Menu = 1
             Waitms 222
          End If
          If Command = 20 And Menu > 1 Then
             Decr Menu
             Waitms 222
          End If
          If Command = 20 And Menu = 1 Then
             Menu = 6
             Waitms 222
          End If
       End If
       Enable Int0
       Ir_flag = 0
    End If
    Loop
    End Sub


    Dodano po 35 [sekundy]:

    Ale działa bez problemu takie coś:
    
    Do
       Disable Int0
       Enable Interrupts
       Getrc5(address , Command)
       Command = Command And &B01111111
       Call Lcdinit
       Str_address = Str(address)
       Str_address = Format(str_address , "" )
       Str_command = Str(command)
       Str_command = Format(str_command , "" )
       Lcdclear
       Lcdgoxy 1 , 1
       Lcdstr Str_address , 1 , 0
       Lcdgoxy 1 , 2
       Lcdstr Str_command , 1 , 0
       Lcdupdate
       Waitms 100
    Loop
    End
  • Pomocny post
    #11 7247707
    LED5W
    Poziom 34  
    Po co to dałeś do podprogramu? Nie ma nawet jego deklaracji.
    Na początek usuń linie z Sub i End Sub.
  • Pomocny post
    #12 7248073
    mirekk36
    Poziom 42  
    ale co ty za kombinacje odstawiasz? czy tak trudno zacząć testować od jakichś podstaw? np:

    If Ir_flag = 1 Then 
    
       If Address <> 255 Then 
    
          Command = Command And &B01111111 
          Locate 1,1
          Lcd "cmd: " ; command ; "  "
       Emdif
    
       Enable Int1 
       Ir_flag = 0 
    End If 


    i przede wszystkim zobaczysz czy prawodłowo odbiera ci poszczególne klawisze
    a dalej to już chyba sobie poradzisz?
  • #13 7248441
    Ficu
    Poziom 31  
    Na początku zapomniałem o Enable Interrupts. Teraz przyciski są dobrze odczytywane. Idąc dalej próbuje zrobić poruszanie się po menu. Aktualnie po naciśnięciu przycisku menu na wyświetlaczu mignie, ale nie przechodzi do następnej/poprzedniej pozycji.

    EDIT: Problem rozwiązany.
REKLAMA