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

Jak przełączyć funkcje atmega16

henryxxl 30 Paź 2010 18:22 1310 9
  • #1 8681771
    henryxxl
    Poziom 26  
    Witam.
    Napisałem taki program
    $regfile = "m16def.dat"
    $crystal = 1000000
    
    
    
    Config Portd = Output
           Portd = &B0000000
    
    
    Do
    
        Waitms 2000
        Toggle Portd.5
        Waitms 2000
        Toggle Portd.5
    
        Waitms 1500
        Toggle Portd.5
        Waitms 1500
        Toggle Portd.5
    
    
        Waitms 1000
        Toggle Portd.5
        Waitms 1000
        Toggle Portd.5
    
    
        Waitms 0
        Toggle Portd.5
        Waitms 0
        Toggle Portd.5
    
    
    
    
    
    
     Loop
    
    End


    W moim programie po kolei załączają się rożne tryby migania diody a ja chciałbym żeby wciskając raz switcha załączał się pierwszy tryb później po wciśnięciu załączał się drugi tryb i aż tak do czwartego trybu.
    Pozdrawiam,
  • #2 8681784
    tadzik85
    Poziom 38  
    Porusz temat przerwań i liczników/timerów.
  • #3 8681859
    iryseee
    Poziom 14  
    spróbuj tak:
    
    $regfile = "m16def.dat"
    $crystal = 1000000
    
    
    
    Config Portd = Output
           Portd = &B0000000
    'config pind.7 = input
    'przycisk alias pord.7
    
    'dim as a=byte
    'set przycisk
    
    'Do
    'if przycisk=0 then
    'do 
    'loop until przycisk=1
    'a=a+1
    'end if
    
    'if a=1 a=2 a=3 then
        Waitms 2000
        Toggle Portd.5
        Waitms 2000
        Toggle Portd.5
    
        Waitms 1500
        Toggle Portd.5
        Waitms 1500
        Toggle Portd.5
    
    
        Waitms 1000
        Toggle Portd.5
        Waitms 1000
        Toggle Portd.5
    
    
        Waitms 0
        Toggle Portd.5
        Waitms 0
        Toggle Portd.5
    
    
    
    
    
    
     Loop
    
    End
    
    
    Tak mniej więcej coś w tym stylu.
  • #4 8681883
    tadzik85
    Poziom 38  
    Eh
    Ja powtórzę TIMERY, albo chociaż podziel te oczekiwania na 50ms odcinki w pętli for w której będziesz sprawdzał stan przycisków.
  • #6 8681894
    tadzik85
    Poziom 38  
    CO jest do wszystkiego jest do niczego. Jak widzę jesteś bardzo początkujący. W dodatku programujesz w bascomie, więc kup książkę do tego. A przede wszystkim lektura helpa.
  • #7 8681935
    henryxxl
    Poziom 26  
    Dziękuje za odpowiedź.
    Mam Pan rację że lepiej kupić książkę specjalnie do bascoma.
    Nie prosił bym o pomoc na forum tylko zakupiłbym książkę poczytał spróbował zrozumieć i jakoś zrobił (lepiej na tym bym wyszedł niż gotowe rozwiązanie) ale na czwartek na fizykę(3 klasa gimnazjum) muszę to zrobić więc nawet nie zdążę zarobić na książkę i do tego jeszcze ja przeczytać wiec proszę żebyście Panowie pomogli to napisać.
  • #8 8683383
    rafaloos
    Poziom 11  
                        ' ########################## USTAWIENIA ##########################
    ' ****** PODANIE IFNO O MIKROKONTROLERZE ******
    $regfile = "m128def.dat"                                    ' zdeklarowane dla Atmegi8
    $crystal = 1000000                                          ' Taktowanie wewnetrzne 8mHz
    
    ' ****** KONIEC PODAWANIA INFA ******
    
    
    
    'Ddrc = &B11111111;
    'Portc = &B11111111;
    
    'Ddrc = &B10111110;
    'Portc = &B11111111;
    
    Declare Sub Pr1()
    Declare Sub Pr2()
    Declare Sub Pr3()
    Declare Sub Pr4()
    
    Config Portd = Output
    Portd = &B11111111
    
    Config Porta = Input
    Porta = &B11111111
    
    Config Ping.0 = Output
    Portg.0 = 1
    
    Config Ping.1 = Output
    Portg.1 = 1
    
    
    Config Ping.2 = Input
    Portg.2 = 1
    
    'Config Pind.5 = Output
    'Portd.5 = 0
    
    
    'Config Portc = Output
    'Portc = &B00000000
    
    Config Pinc.7 = Output
    Portc.7 = 0
    
    'Config Ping.2 = Input
    'Portg.2 = 1
    
    Portd.2 = 0
    
    Disable Interrupts
    
    
    S1 Alias Ping.2
    S2 Alias Pina.7
    S3 Alias Pina.6
    S4 Alias Pina.5
    
    
    'Portg.2 = 1
    Porta.7 = 1
    Porta.6 = 1
    Porta.5 = 1
    'Config Lcd = 16 * 2
    'Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.4 , Db6 = Portc.5 , Db7 = Portc.6 , E = Portc.2 , Rs = Portc.0
    
    
    Cls
    
    
    Do
    
    
       Cls
       'Debounce Ping.2 , 0 , Pr1 , Call Pr1
       If S1 = 0 Then
       Waitms 25
          If S1 = 0 Then
    
             Cls
             Lcd "Switch 1"
             Toggle Portd.2
             Waitms 200
             Bitwait S1 , Set
          End If
       End If
    
       Debounce S2 , 0 , Pr2 , Call Pr2
       Debounce S3 , 0 , Pr3 , Call Pr3
       Debounce S4 , 0 , Pr4 , Call Pr4
    
    
    Loop
    End
    
    
    Sub Pr1()
    
    
    End Sub
    
    
    Sub Pr2()
       Cls
       Lcd "Switch 2"
       Toggle Portd.3
       Waitms 200
    
    End Sub
    
    
    
    Sub Pr3()
       Cls
       Lcd "Switch 3"
       Toggle Portd.4
       Waitms 200
    
    End Sub
    
    
    Sub Pr4()
       Cls
       Lcd "Switch 4"
       Toggle Portd.5
       Waitms 200
    
    End Sub



    Musisz zmienić tylko piny pod Twoje i gotowe
  • #9 8683412
    Konto nie istnieje
    Poziom 1  
  • #10 8684222
    henryxxl
    Poziom 26  
    zmieniłem porty czyli portd5 wyjście na diodę a porta jako wejście switcha
    ' ****** PODANIE IFNO O MIKROKONTROLERZE ******
    $regfile = "m16def.dat"                                     ' zdeklarowane dla Atmegi8
    $crystal = 1000000                                          ' Taktowanie wewnetrzne 8mHz
    
    ' ****** KONIEC PODAWANIA INFA ******
    
    
    
    'Ddrc = &B11111111;
    'Portc = &B11111111;
    
    'Ddrc = &B10111110;
    'Portc = &B11111111;
    
    Declare Sub Pr1()
    Declare Sub Pr2()
    Declare Sub Pr3()
    Declare Sub Pr4()
    
    Config Portd = Output
    Portd = &B11111111
    
    Config Porta = Input
    Porta = &B11111111
    
    Config Pind.0 = Output
    Portd.0 = 1
    
    Config Pind.1 = Output
    Portd.1 = 1
    
    
    Config Pina.2 = Input
    Porta.2 = 1
    
    'Config Pind.5 = Output
    'Portd.5 = 0
    
    
    'Config Portc = Output
    'Portc = &B00000000
    
    Config Pind.7 = Output
    Portd.7 = 0
    
    'Config Ping.2 = Input
    'Portg.2 = 1
    
    Portd.2 = 0
    
    Disable Interrupts
    
    
    S1 Alias Pina.2
    S2 Alias Pina.7
    S3 Alias Pina.6
    S4 Alias Pina.5
    
    
    'Portg.2 = 1
    Porta.7 = 1
    Porta.6 = 1
    Porta.5 = 1
    'Config Lcd = 16 * 2
    'Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.4 , Db6 = Portc.5 , Db7 = Portc.6 , E = Portc.2 , Rs = Portc.0
    
    
    Cls
    
    
    Do
    
    
       Cls
       'Debounce Ping.2 , 0 , Pr1 , Call Pr1
       If S1 = 0 Then
       Waitms 25
          If S1 = 0 Then
    
             Cls
             Lcd "Switch 1"
             Toggle Portd.2
             Waitms 200
             Bitwait S1 , Set
          End If
       End If
    
       Debounce S2 , 0 , Pr2 , Call Pr2
       Debounce S3 , 0 , Pr3 , Call Pr3
       Debounce S4 , 0 , Pr4 , Call Pr4
    
    
    Loop
    End
    
    
    Sub Pr1()
    
    
    End Sub
    
    
    Sub Pr2()
       Cls
       Lcd "Switch 2"
       Toggle Portd.3
       Waitms 200
    
    End Sub
    
    
    
    Sub Pr3()
       Cls
       Lcd "Switch 3"
       Toggle Portd.4
       Waitms 200
    
    End Sub
    
    
    Sub Pr4()
       Cls
       Lcd "Switch 4"
       Toggle Portd.5
       Waitms 200
    
    End Sub
    
    Jak podłącze układ do prądu to dioda świeci a gaśnie jak przytknę masę do porta 4. Co pomieszałem ze nie działa?


    Jak dobrze ustawic porty w tym programie?
    $regfile = "m16def.dat" 
    $crystal = 1000000 
    
    Dim tryb as Byte 
    
    
    Config Portd = Output 
           Portd = &B0000000 
    Config Portd.4 = Input 
    
    Do 
    
    If Pind.4 = 1 then incr tryb 
    
    If tryb = 5 then tryb = 0 
    
        If tryb = 0 then 
        Waitms 2000 
        Portd.5 = 0 
        Waitms 2000 
        End If 
    
    
    
        If tryb = 1 then 
        Waitms 2000 
        Toggle Portd.5 
        Waitms 2000 
        Toggle Portd.5 
        End If 
    
    
        If tryb = 2 then 
        Waitms 1500 
        Toggle Portd.5 
        Waitms 1500 
        Toggle Portd.5 
        End If 
    
    
        If tryb = 3 then 
        Waitms 1000 
        Toggle Portd.5 
        Waitms 1000 
        Toggle Portd.5 
        End If 
    
    
     Loop 
    
    End
REKLAMA