Elektroda.pl
Elektroda.pl
X
Proszę, dodaj wyjątek www.elektroda.pl do Adblock.
Dzięki temu, że oglądasz reklamy, wspierasz portal i użytkowników.

Problem z programem do sterownika.

bobhead 19 Lip 2006 10:34 1245 4
  • #1 19 Lip 2006 10:34
    bobhead
    Poziom 10  

    Witam!
    Przepisałem z "NE" program do sterownika akariowego,niestety podczas sprawdzania błędów,Bascom wyrzuca mi kilka.Bardzo proszę,gdyby ktos zechciał zerknąć jaka jest tego przyczyna.Z góry dziękuję za pomoc.

    '##############################################################################
    'Sterownik do akwarium
    'Wersja Kompilatora Bascom-AVR V.1.11.7.4
    'Programator Bascom-AVR Demo V.1.11.7.4
    'stk200 \ Stk300
    'Generator Zewnętrzny 8mhz(external)
    'FusebitA9871110 : 1110external Osc
    'Reset Wewnetrzny : Fusebit Kl 10
    '6ck64mS Delay
    '##############################################################################
    $regfile = "m8def.dat"
    $crystal = 8000000

    Config Timer1 = Timer , Prescale = 8
    Config Adc = Single , Prescaler = 16 , Reference = Avcc
    Config Lcd = 16 * 2
    Config Lcdpin = Pin , Db4 = Portb.5 , Db5 = Portb.4 , Db6 = Portb.3 , Db7 = Portb.2 , E = Portc.2 , Rs = Portc.4
    '_______________________________________________________________________
    Config Pinb.0 = Output
    Config Pinb.1 = Input
    Portb.1 = 1

    Config Pinb.2 = Output
    Config Pinb.3 = Output
    Config Pinb.4 = Output
    Config Pinb.5 = Output
    Config Pinb.6 = Output
    Config Pinb.7 = Output
    '______________________________________________________________________________
    Config Pinc.0 = Output

    Config Pinc.1 = Input
    Portc.1 = 1

    Config Pinc.2 = Output
    Config Pinb.3 = Input
    Portc.3 = 0
    Config Pinc.4 = Output
    Config Pinb.5 = Input
    Portc.5 = 1
    Config Pinc.6 = Input
    '______________________________________________________________________________
    Config Pind.0 = Input
    Config Pind.1 = Input
    Config Pind.2 = Input

    Config Pind.3 = Output
    Config Pind.4 = Output

    Config Pind.7 = Input
    Portd.7 = 1
    Config Pind.6 = Input
    Portd.6 = 1
    Config Pind.5 = Input
    Portd.5 = 1

    '------------------------------------------------------------------------
    'PIN/PORT
    #if_sim = 0
    '____________________________________________________________________________
    'przyciski
    S1 Alias Pind.7
    S2 Alias Pind.6
    S3 Alias Pind.5
    S4 Alias Pind.1
    '__________________________________________________________________________
    #else
    '_______________________________________________________________________
    'przyciski
    S1 Alias Portd.7
    S2 Alias Portd.6
    S3 Alias Portd.5
    S4 Alias Portd.1
    '________________________________________________________________________
    #endif
    '_______________________________________________________________
    Clock Alias Portc.0
    Pk1 Alias Portd.3
    Pk2 Alias Portd.4
    Pk3 Alias Portb.0

    Const Skok = 4883

    Dim Adc_reg As Word
    Dim Adc_buf As Word

    Dim Temper As Byte

    Dim Licznik As Byte

    Dim Sekundy As Long





    Dim Temp_time As Long
    Dim Temp_degs As Long
    Dim Temp As Long
    Dim Degs As Integer

    Dim W_on As Long
    Dim W_off As Long
    Dim P_on As Long
    Dim P_off As Long

    Dim Coun_time As Byte


    Dim Fuse As Word
    Dim Fuse_hi As Byte
    Dim Fuse_lo As Byte

    Dim S_s As Byte
    Dim M_m As Byte
    Dim H_h As Byte

    Dim W_h_on As Byte
    Dim W_m_on As Byte

    Dim W_h_off As Byte
    Dim W_m_off As Byte

    Dim P_h_on As Byte
    Dim P_m_on As Byte

    Dim P_h_off As Byte
    Dim P_m_off As Byte

    Dim Flags As Byte

    X1 Alias Flags.0
    Xpk1 Alias Flags.1
    Xpk2 Alias Flags.2
    Xpk3 Alias Flags.2
    Auto1 Alias Flags.4
    Ls_edit Alias Flags.7

    Dim Menu As Byte

    'procedury pozycjonowania i wyswietlania
    Declare Sub Lcd_temper()

    Declare Sub Lcd_w_h_on()
    Declare Sub Lcd_w_m_on()

    Declare Sub Lcd_w_h_off()
    Declare Sub Lcd_w_m_off()

    Declare Sub Lcd_p_h_on()
    Declare Sub Lcd_p_m_on()

    Declare Sub Lcd_p_h_off()
    Declare Sub Lcd_p_m_off()

    Declare Sub Lcd_t_h()
    Declare Sub Lcd_t_m()

    Declare Sub Count_time()

    Declare Sub Readkey()
    Dim Key As Byte


    Start Adc

    On Timer1 Timer_1_sub
    Enable Interrupts
    Disable Int0
    Disable Int1
    Disable Timer0
    Enable Timer1
    Stop Timer0
    Stop Timer1
    '##################################################################
    '#####POCZĄTEK PROGRAMU############################################
    '##################################################################
    Cursor Off

    Cls
    Lcd "NOWY ELEKTRONIK"
    Locate 2 , 1
    Lcd "AQUARIUM DRIVER"
    Wait 2

    Cls
    '#################################################################
    '#######POCZĄTEK PĘTLI GŁÓWNEJ####################################
    '#################################################################
    Readeeprom Temper , 10
    Readeeprom W_h_on , 11
    Readeeprom W_m_on , 12
    Readeeprom W_h_off , 13
    Readeeprom W_m_off , 14
    Readeeprom P_h_on , 15
    Readeeprom P_m_on , 16
    Readeeprom P_h_off , 17
    Readeeprom P_m_off , 18

    If Temper < 10 Or Temper > 50 Then Temper = 30
    If W_h_on > 23 Then W_h_on = 12
    If W_m_on > 59 Then W_m_on = 30

    If W_h_off > 23 Then W_h_off = 12
    If W_m_off > 59 Then W_m_off = 30

    If P_h_on > 23 Then P_h_on = 12
    If P_m_on > 59 Then P_m_on = 30

    If P_h_off > 23 Then P_h_off = 12
    If P_m_off > 59 Then P_m_off = 30

    Call Count_time()

    Xpk1 = 0
    Xpk2 = 0
    Xpk3 = 0

    Auto1 = 1
    Sekundy = 43200

    Fuse = 17221
    Fuse_hi = 256 - High(fuse)
    Fuse_lo = 256 - Low(fuse)

    Count_time = 16
    Tcnt1h = Fuse_hi
    Tcnt1l = Fuse_lo
    Start Timer1
    '##################################################
    '#a w przerwach między przerwaniami można sobie coś porobić#
    '###################################################
    Do
    '###################################################
    'odczyt sekund i zamiana na hh:mm:ss
    Locate 1 , 2
    Temp_degs = Sekundy
    Temp_time = Temp_degs
    Temp = Temp_degs Mod 60
    S_s = Temp
    Temp = Temp_degs / 60
    Temp_degs = Temp / 60
    H_h = Temp_degs
    Temp_degs = Temp Mod 60
    M_m = Temp_degs
    'wyswietlanie czasu
    If H_h < 10 Then Lcd "0";
    Lcd H_h ; ":";
    If M_m < 10 Then Lcd "0";
    Lcd M_m ; ":";
    If S_s < 10 Then Lcd "0";
    Lcd S_s ; ""

    '#######################################################
    'sprawdzanie czasów
    If Temp_time = W_on Then Xpk2 = 1
    If Temp_time = W_off Then Xpk2 = 0
    If Temp_time = P_on Then Xpk3 = 1
    If Temp_time = P_off Then Xpk3 = 0
    '################################################################
    'odczyt ADC - 50 razy na cykl
    Adc_buf = 0
    For Licznik = 1 To 50
    Adc_reg = Getadc(3)
    Adc_buf = Adc_buf + Adc_reg
    Next Licznik

    'przeliczanie napięcia na temp
    Adc_reg = Adc_buf / 50
    Temp_degs = Adc_reg * Skok
    Temp_degs = Temp_degs / 10
    Temp_degs = Temp_degs / 10
    Temp_degs = Temp_degs / 10
    Temp_degs = Temp_degs / 10
    Degs = Temp_degs - 273
    'wyświetlanie temperatury
    Locate 1 , 12
    Lcd "T=" ; Degs ; ""
    '################################################################
    'sprawdzanie temperatury
    If Degs < Temper Then
    Xpk1 = 1
    Elseif Degs > Temper Then
    Xpk1 = 0
    End If

    'warunek dla przycisku s1
    If Auto1 = 0 Then
    Xpk1 = 0
    End If

    'aktywacja przekaźników
    Pk1 = Xpk1
    Pk2 = Xpk2
    Pk3 = Xpk3

    'wyświetlanie stanu przekaźników
    Locate 2 , 1
    Lcd "R1=" ; Xpk1 ; "R2=" ; Xpk2 ; "R3=" ; Xpk3
    '###################################################################
    'obsługa klawiatury
    If S1 = 0 Or S2 = 0 Or S3 = 0 Or S4 = 0 Then
    Call Readkey()
    Ls_edit = 0
    Select Case Key
    Case 1:
    Toggle Auto1

    Case 2:
    Toggle Xpk2

    Case 3:
    Toggle Xpk3

    Case 4:
    Menu = 0
    Cls
    Lcd "Settings"
    Pk1 = 0
    Pk2 = 0
    Pk3 = 0
    Do
    Call Readkey()
    Select Case Key
    Case 1:
    Incr Menu
    If Menu > 7 Then Menu = 1
    Cls
    Select Case Menu
    Case 1 : Lcd "TempON R1"
    Call Lcd_temper()
    Case 2:
    Lcd "TimeON R2:"
    Call Lcd_w_h_on()
    Call Lcd_w_m_on()
    Locate 1 , 13
    X1 = 0
    Cursor On
    Case 3:
    Lcd "TimeOFF R2:"
    Call Lcd_w_h_off()
    Call Lcd_w_m_off()
    Locate 1 , 13
    X1 = 0
    Case 4:
    Lcd "TimeON R3:"
    Call Lcd_p_h_on()
    Call Lcd_p_m_on()
    Locate 1 , 13
    X1 = 0
    Case 5:
    Lcd "TimeOFF R3:"
    Call Lcd_p_h_off()
    Call Lcd_p_m_off()
    Locate 1 , 13
    X1 = 0
    Case 6:
    Lcd "CLOCK TIME:"
    Call Lcd_t_h()
    Call Lcd_t_m()
    Locate 1 , 13
    X1 = 0
    Case 7:
    Lcd "<EXIT>"
    Cursor Off
    End Select
    Case 2:
    Select Case Menu
    Case 2 To 6
    If X1 = 0 Then
    X1 = 1
    Locate 1 , 16
    Elseif X1 = 1 Then
    X1 = 0
    Locate 1 , 13
    End If
    Case 7 : Menu = 100
    End Select
    Case 3:
    Select Case Menu
    Case 1:
    Incr Temper
    If Temper > 50 Then Temper = 10
    Call Lcd_temper()
    Case 2:
    If X1 = 0 Then
    Incr W_h_on
    If W_h_on > 23 Then W_h_on = 0
    Call Lcd_w_h_on()
    Elseif X1 = 1 Then
    Incr W_m_on
    If W_m_on > 59 Then W_m_on = 0
    Call Lcd_w_m_on()
    End If
    Case 3:
    If X1 = 0 Then
    Incr W_h_off
    If W_h_off > 23 Then W_h_off = 0
    Call Lcd_w_h_off()
    Elseif X1 = 1 Then
    Incr W_m_off
    If W_m_off > 59 Then W_m_off = 0
    Call Lcd_w_m_off()
    End If
    Case 4:
    If X1 = 0 Then
    Incr P_h_on
    If P_h_on > 23 Then P_h_on = 0
    Call Lcd_p_h_on()
    Elseif X1 = 1 Then
    Incr P_m_on
    If P_m_on > 59 Then P_m_on = 0
    Call Lcd_p_m_on()
    End If
    Case 5:

    Incr P_h_off
    If P_h_off > 23 Then P_h_off = 0
    Call Lcd_p_h_off()
    Elseif X1 = 1 Then
    Incr P_m_off
    If P_m_off > 59 Then P_m_off = 0
    Call Lcd_p_m_off()
    End If
    Case 6:
    Ls_edit = 1
    If X1 = 0 Then
    Incr H_h
    If H_h > 23 Then H_h = 0
    Call Lcd_t_h()
    Elseif X1 = 1 Then
    Incr M_m
    If M_m > 59 Then M_m = 0
    Call Lcd_t_m()
    End If
    Case 7 : Menu = 100
    End Select
    Case 4:
    Select Case Menu
    Case 1:
    Decr Temper
    If Temper < 10 Then Temper = 50
    Call Lcd_temper()

    Case 2:
    If X1 = 0 Then
    Decr W_h_on
    If W_h_on > 23 Then W_h_on = 23
    Call Lcd_w_h_on()
    Elseif X1 = 1 Then
    Decr W_m_on
    If W_m_on > 59 Then W_m_on = 59
    Call Lcd_w_m_on()
    End If
    Case 3:
    If X1 = 0 Then
    Decr W_h_off
    If W_h_off > 23 Then W_h_off = 23
    Call Lcd_w_h_off()
    Elseif X1 = 1 Then
    Decr W_m_off
    If W_m_off > 59 Then W_m_off = 59
    Call Lcd_w_m_off()
    End If
    Case 4:
    If X1 = 0 Then
    Decr P_h_on
    If P_h_on > 23 Then P_h_on = 23
    Call Lcd_p_h_on()
    Elseif X1 = 1 Then
    Decr P_m_on
    If P_m_on > 59 Then P_m_on = 59
    Call Lcd_p_m_on()
    End If
    Case 5:
    Decr P_h_off
    If P_h_off > 23 Then P_h_off = 23
    Call Lcd_p_h_off()
    Elseif X1 = 1 Then
    Decr P_m_off
    If P_m_off > 59 Then P_m_off = 59
    Call Lcd_p_m_off()
    End If
    Case 6:
    Ls_edit = 1
    If X1 = 0 Then
    Decr H_h
    If H_h > 23 Then H_h = 23
    Call Lcd_t_h()
    Elseif X1 = 1 Then
    Decr M_m
    If M_m > 59 Then M_m = 59
    Call Lcd_t_m()
    End If
    Case 7 : Menu = 100
    End Select
    End Select
    Loop Until Menu = 100

    Cls
    If Ls_edit = 1 Then
    Temp_degs = H_h * 60
    Temp_degs = Temp_degs + M_m
    Temp_degs = Temp_degs * 60
    Stop Timer1
    Count_time = 16
    Tcnt1h = Fuse_hi
    Tcnt1l = Fuse_lo
    Sekundy = Temp_degs
    Start Timer1
    End If

    Writeeeprom Temper , 10
    Writeeeprom W_h_on , 11
    Writeeeprom W_m_on , 12
    Writeeeprom W_h_off , 13
    Writeeeprom W_m_off , 14
    Writeeeprom P_h_on , 15
    Writeeeprom P_m_on , 16
    Writeeeprom P_h_off , 17
    Writeeeprom P_m_off , 18
    Call Count_time()
    Loop
    '#################################################################
    'koniec pętli głównej################
    '#################################################################

    Sub Lcd_temper()
    Locate 1 , 14
    If Temper < 10 Then Lcd "0"
    Lcd Temper
    End Sub
    '#############################################
    Sub Lcd_w_h_on()
    Locate 1 , 12
    If W_h_on < 10 Then Lcd "0"
    Lcd W_h_on
    Locate 1 , 13
    End Sub
    '############################################
    Sub Lcd_w_m_on()
    Locate 1 , 15
    If W_m_on < 10 Then Lcd "0"
    Lcd W_m_on
    Locate 1 , 16
    End Sub
    '############################################
    Sub Lcd_w_h_off()
    Locate 1 , 12
    If W_h_off < 10 Then Lcd "0"
    Lcd W_h_off
    Locate 1 , 13
    End Sub
    '############################################
    Sub Lcd_w_m_off()
    Locate 1 , 15
    If W_m_off < 10 Then Lcd "0"
    Lcd W_m_off
    Locate 1 , 16
    End Sub
    '############################################
    Sub Lcd_p_h_on()
    Locate 1 , 12
    If P_h_on < 10 Then Lcd "0"
    Lcd P_h_on
    Locate 1 , 13
    End Sub
    '############################################
    Sub Lcd_p_m_on()
    Locate 1 , 15
    If P_m_on < 10 Then Lcd "0"
    Lcd P_m_on
    Locate 1 , 16
    End Sub
    '############################################
    Sub Lcd_p_h_off()
    Locate 1 , 12
    If P_h_off < 10 Then Lcd "0"
    Lcd P_h_off
    Locate 1 , 13
    End Sub
    '############################################
    Sub Lcd_p_m_off()
    Locate 1 , 15
    If P_m_off < 10 Then Lcd "0"
    Lcd P_m_off
    Locate 1 , 16
    End Sub
    '############################################
    Sub Lcd_t_h()
    Locate 1 , 12
    If H_h < 10 Then Lcd "0"
    Lcd H_h
    Locate 1 , 13
    End Sub
    '############################################
    Sub Lcd_t_m()
    Locate 1 , 15
    If M_m < 10 Then Lcd "0"
    Lcd M_m
    Locate 1 , 16
    End Sub
    '############################################
    Sub Count_time()
    W_on = W_h_on * 60
    W_on = W_on + W_m_on
    W_on = W_on * 60

    W_off = W_h_off * 60
    W_off = W_off + W_m_off
    W_off = W_off * 60
    P_on = P_h_on * 60
    P_on = P_on + P_m_on
    P_on = P_on * 60
    P_off = P_h_off * 60
    P_off = P_off + P_m_off
    P_off = P_off * 60
    End Sub
    '#############################################
    Sub Readkey()
    Do
    Key = 0
    If S1 = 0 Then
    Waitms 40
    Do
    Loop Until S1 = 1
    Key = 1
    Elseif S2 = 0 Then
    Waitms 40
    Do
    Loop Until S2 = 1
    Key = 2
    Elseif S3 = 0 Then
    Waitms 40
    Do
    Loop Until S3 = 1
    Key = 3
    Elseif S4 = 0 Then
    Waitms 40
    Do
    Loop Until S4 = 1
    Key = 4
    End If
    Loop Until Key > 0
    End Sub
    '####################################################3
    Timer_1_sub:
    Decr Count_time
    If Count_time > 0 Then Goto No_1sek
    Count_time = 16
    Tcnt1h = Fuse_hi
    Tcnt1l = Fuse_lo
    Toggle Clock
    Incr Sekundy

    If Sekundy > 86399 Then
    Sekundy = 0
    End If
    No_1sek:
    Return
    '####################################################
    End

    0 4
  • #2 19 Lip 2006 12:19
    crazy_phisic
    VIP Zasłużony dla elektroda

    W funkcji:

    Code:

    Timer_1_sub:
    Decr Count_time
    If Count_time > 0 Then Goto No_1sek
    Count_time = 16
    Tcnt1h = Fuse_hi
    Tcnt1l = Fuse_lo
    Toggle Clock
    Incr Sekundy


    Odwołujesz się do nieistniejącej zmiennej, "Count_time" to funkcja a zmienna to "Coun_time". Poza tym zgubiłeś gdzieś End Select

    0
  • #3 19 Lip 2006 13:46
    bobhead
    Poziom 10  

    Ok,dziękuję za zainteresowanie tematem.Zatem co powinienem w tym kodzie poprawić?Dopiero zaczynam zabawę z mikrokontrolerami i nie za bardzo wiem jak to ugryźć.dzięki z góry za odpowiedź.

    0
  • #4 19 Lip 2006 17:44
    bogdan_p
    Poziom 39  

    bobhead nie chcę Cię zniechęcać , ale podobnych tematów jest kilka na forum odnośnie przepisanych programów z NE , sam nawet siedziałem dość długo chcąc pomóc na forum w podobnej sprawie i okazało się że nawet po poprawieniu błędów , prawidłowej kompilacji załadowaniu do uC program nie działał , nie wiem czy nie lepiej poszukać innego sterownika z pewnym programem

    0
  • #5 19 Lip 2006 20:57
    bobhead
    Poziom 10  

    Bogdan_p masz chyba rację,po prostu byłem ciekaw czy to moja wina czy ich celowe działanie.Także słyszałem opinię że kody "NE" nie działają.
    W każdym razie dziękuję za pomoc.Temat zamknięty.

    0
  Szukaj w 5mln produktów