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

[BASCOM][ATMEGA8]Program menu - sprawdzicie ?

simpson777 19 Mar 2009 11:28 1939 2
REKLAMA
  • #1 6302441
    simpson777
    Poziom 11  
    Witam

    A więc zrobiłem program menu i mam pytanie.

    Czy mógł by się przyjąć takowy program dla początkujących, którzy mają wiele pytań co do programu menu pisanego w BASCOM'ie??

    A o to program:
    
    $regfile = "m8def.dat"
    $crystal = 1000000
    
    Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.2
    Config Lcd = 16 * 2
    Config Portb = &B00001111
            Portb = &B11110000
    
    Declare Sub Przyc
    Dim A As Byte
    Dim R As Integer
    Dim G As Integer
    Dim B As Integer
    
    R=0
    G=0
    B=0
    
    Deflcdchar 0 , 16 , 17 , 18 , 20 , 24 , 16 , 31 , 32        '(Ł)
    Deflcdchar 2 , 2 , 4 , 31 , 2 , 4 , 8 , 31 , 32             '(ź)
    Deflcdchar 3 , 1 , 1 , 1 , 5 , 9 , 31 , 8 , 4               'znak powrót
    
    
    Cursor Off
    Cls
    Wait 1
    Locate 1 , 3
    Lcd Chr(0) ; "ADUJE DANE"
    Waitms 500
    Locate 2 , 6
    Lcd "*"
    Waitms 330
    Locate 2 , 7
    Lcd "*"
    Waitms 330
    Locate 2 , 8
    Lcd "*"
    Waitms 1000
    Locate 2 , 9
    Lcd "*"
    Waitms 200
    Locate 2 , 10
    Lcd "*"
    Waitms 200
    Locate 2 , 11
    Lcd "*"
    Waitms 1000
    
    Do
    Cls
    Locate 1 , 1
    Lcd "*MENU-USTAWIENIA"
    Locate 2 , 1
    Lcd "*Sprawd" ; Chr(2) ; "-  DANE "
    Waitms 20
    
       If Pinb.5 = 0 Then
          Waitms 20
          If Pinb.5 = 0 Then
          Gosub Zatw
       End If
       End If
       If Pinb.6 = 0 Then
          Waitms 20
          If Pinb.6 = 0 Then
          Gosub Zatw1
       End If
       End If
    Loop
    End
    
    Zatw:
    Do
       Cls
       Locate 1 , 3
       Lcd "zatwierdzasz"
       Locate 2 , 2
       Lcd "ok"
       Locate 2 , 14
       Lcd Chr(3)
       Waitms 20
    
       If Pinb.7 = 0 Then
          Waitms 20
          If Pinb.7 = 0 Then
          Cls
          Locate 2 , 2
          Lcd "ok"
          Wait 1
          Gosub Menu
       End If
       End If
       If Pinb.4 = 0 Then
          Waitms 20
          If Pinb.4 = 0 Then
          Cls
          Locate 2 , 14
          Lcd Chr(3)
          Wait 1
          Return
       End If
       End If
    Loop
    
    Zatw1:
    Do
       Cls
       Locate 1 , 3
       Lcd "zatwierdzasz"
       Locate 2 , 2
       Lcd "ok"
       Locate 2 , 14
       Lcd Chr(3)
       Waitms 20
    
       If Pinb.7 = 0 Then
          Waitms 20
          If Pinb.7 = 0 Then
          Cls
          Locate 2 , 2
          Lcd "ok"
          Wait 1
          gosub spraw
       End If
       End If
       If Pinb.4 = 0 Then
          Waitms 20
          If Pinb.4 = 0 Then
          Cls
          Locate 2 , 14
          Lcd Chr(3)
          Wait 1
          Return
       End If
       End If
    Loop
    
    Spraw:
    do
       Cls
       locate 1,1
       lcd "DANE:"
       locate 1,7
       lcd "G=";G
       locate 2,1
       lcd "R=";R
       locate 2,7
       lcd "B=";B
       locate 2,14
       lcd chr(3)
       Waitms 20
    
       If Pinb.4 = 0 Then
          Waitms 20
          If Pinb.4 = 0 Then
          Cls
          Locate 2 , 14
          Lcd Chr(3)
          Wait 1
          Return
       End If
       End If
    Loop
    
    Menu:
    Do
       Przyc
       if A = 1 then
          gosub GGG
       end if
    
       if A = 2 then
          gosub RRR
       end if
    
       if A = 3 then
          gosub BBB
       end if
    
       If Pinb.4 = 0 Then
          Waitms 20
          If Pinb.4 = 0 Then
          Cls
          Locate 2 , 14
          Lcd Chr(3)
          Wait 1
          Return
       End If
       End If
    Loop
    
    GGG:
    do
       cls
       locate 1,1
       lcd "Dioda zielona"
       locate 2,2
       Lcd "G=" ; G
       Locate 2 , 10
       Lcd "+ " ; "- " ; Chr(3)
       Waitms 20
    
       If Pinb.5 = 0 Then
          Waitms 20
          If Pinb.5 = 0 Then
          G = G + 1
       End If
       End If
       If Pinb.6 = 0 Then
          Waitms 20
          If Pinb.6 = 0 Then
          G = G - 1
       End If
       End If
    
       Return
    loop
    
    RRR:
    do
       cls
       locate 1,1
       lcd "Dioda czerwona"
       locate 2,2
       Lcd "R=" ; R
       Locate 2 , 10
       Lcd "+ " ; "- " ; Chr(3)
       Waitms 20
    
       If Pinb.5 = 0 Then
          Waitms 20
          If Pinb.5 = 0 Then
          R = R + 1
       End If
       End If
       If Pinb.6 = 0 Then
          Waitms 20
          If Pinb.6 = 0 Then
          R = R - 1
       End If
       End If
    
       Return
    loop
    
    BBB:
    do
       cls
       locate 1,1
       lcd "Dioda niebieska"
       locate 2,2
       Lcd "B=" ; B
       Locate 2 , 10
       Lcd "+ " ; "- " ; Chr(3)
       Waitms 20
    
       If Pinb.5 = 0 Then
          Waitms 20
          If Pinb.5 = 0 Then
          B = B + 1
       End If
       End If
       If Pinb.6 = 0 Then
          Waitms 20
          If Pinb.6 = 0 Then
          B = B - 1
       End If
       End If
    
    
       Return
    Loop
    
    Sub Przyc
    
       If Pinb.7 = 0 Then
          Waitms 20
          If Pinb.7 = 0 Then
          Incr A
          End If
       End If
    
        If A = 4 Then
          A = 0
        End If
    
    End Sub
    
  • REKLAMA
  • #2 6303024
    wader_669
    Poziom 28  
    odpowiedz na twoje pytanie nie.

    Masz pelno smieci w tym kodzie np. co chwile powtarzasz if pinb -=0 then

    zrob sprawdzanie przyciskow w jakiejs glownej petli, gdzien one by ustawialy flagi lub cos podobnego i wedlug tych flag by odpowiednio wyswietlal lcd.

    2 sprawa dlaczego dales w petli wyswietlanie na lcd totalny bezsens
  • #3 6310421
    nouki
    Poziom 25  
    Kiedyś jak się uczyłem bascoma z przymusu ktoś mi powiedział bym tak nie robił go to czy gosub a stosował suby i coll-e nie dosyć że prościej to lepiej to wygląda :)
REKLAMA