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

Błąd konfiguracji Timer1 i Timer0 w wykrywaczu metali na ATMega8+Bascom

heyka 27 Lut 2012 11:13 4701 4
  • #1 10605245
    heyka
    Poziom 17  
    Witam

    Znalazłem na elektrodzie poniższy kod:
    
    $regfile = "m8def.DAT"
    Config Lcd = 16 * 2
    Config Lcdpin = Pin , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 , E = Portc.4 , Rs = Portc.5
    Config Portd.0 = Input
    Config Portd.1 = Input
    Config Portd.2 = Input
    Config Portd.3 = Input
    Config Portd.5 = Input
    Config Portb.4 = Output
    Cursor Off
    Config Timer1 = Timer , Gate = External , Mode = 1          'tu mi  wywala bład w bascomie
    Config Timer0 = Counter , Gate = Internal , Mode = 1        'tu mi  wywala bład w bascomie
    Dim Temp As Byte
    Dim R As Byte
    Dim Freq_compare As Word
    Dim Metal_type As Bit
    Dim Freq As Word
    Dim Dif As Word
    Dim Temp2 As Byte
    Dim Prescale As Byte
    Dim Flag1 As Bit
    Dim X As Word
    Declare Sub Loop1
    Dim Display_type_flag As Bit
    Dim Counts As Byte
    S1 Alias Portd.1
    S5 Alias Portd.0
    S3 Alias Portd.2
    S4 Alias Portd.5
    S6 Alias Portd.3
    Pipek Alias Portb.4
    On Timer1 Frequency
    
    Deflcdchar 0 , 4 , 14 , 31 , 31 , 31 , 31 , 31 , 31         ' replace ? with number (0-7)
    Cls
    Deflcdchar 1 , 31 , 31 , 31 , 31 , 31 , 31 , 14 , 4         ' replace ? with number (0-7)
    Cls
    Lcd " AVT - 5025"
    Wait 1
    Cls
    
    Lcd " METAL DETECTOR"
    Wait 1
    Enable Interrupts
    Enable Timer0
    Enable Timer1
    Start Timer0
    Start Timer1
    Prescale = 1
    Display_type_flag = 1
    Loop1
    Counts = 7
    Sub Loop1
    Freq_compare = Freq
    
    Dif = 0
    Do
    
    Loop
    End Sub
    
    
    
    Frequency:
    Flag1 = 1
    
    Counter1 = 4150
    Start Timer1
    Incr Temp
    If Temp = Counts Then
    Temp = 0
    
    Stop Timer0
    Stop Timer1
    Freq = Counter0
    Counter0 = 0
    Set S1
    If S1 = 0 Then
    Cls
    Lcd "RESET"
    Waitms 255
    Freq_compare = Freq
    Dif = 0
    Flag1 = 0
    Display_type_flag = 1
    End If
    Set S4
    
    If S4 = 0 Then
    Prescale = 10
    Cls
    Lcd "SENSITIVITY LOW"
    Counts = 7
    Flag1 = 0
    Display_type_flag = 1
    Waitms 255
    Cls
    End If
    
    Set S5
    If S5 = 0 Then
    Prescale = 5
    Cls
    Lcd "SENSITIVITY MID"
    Counts = 7
    Display_type_flag = 1
    Waitms 255
    
    Cls
    End If
    
    Set S6
    If S6 = 0 Then
    Prescale = 1
    Cls
    Lcd "SENSITIVITY HIGH"
    Counts = 7
    Display_type_flag = 1
    Waitms 255
    Cls
    End If
    
    Set S3
    If S3 = 0 Then
    Display_type_flag = 0
    Cls
    Lcd "  FREQUENCY"
    Counts = 15
    Waitms 255
    
    End If
    If Display_type_flag = 1 Then
    If Freq_compare > Freq Then
    Dif = Freq_compare - Freq
    Metal_type = 1
    End If
    
    If Freq_compare < Freq Then
    Dif = Freq - Freq_compare
    Metal_type = 0
    End If
    Temp2 = Dif / Prescale
    If Temp2 > 16 Then Temp2 = 16
    
    If Dif > 1 And Flag1 = 1 Then
    Cls
    For R = 1 To Temp2
    If Metal_type = 1 Then Lcd Chr(0);
    If Metal_type = 0 Then Lcd Chr(1);
    Sound P1.0 , 100 , 100
    Next Temp2
    Else
    Cls
    Lcd "    NO METAL!"
    End If
    Else
    Cls
    Locate 1 , 4
    Lcd Freq ; " Hz"
    End If
    Start Timer1
    Start Timer0
    End If
    
    Return
    
    


    Kod dotyczy wykrywacza metalu wg zestawu AVT-2025, został on przerobiony na ATMega8. Bascom w linijce konfiguracji Timer-ów wyrzuca błędy.

    Mam pytanie czy ktoś próbował uruchomić wykrywacz z wykorzystaniem powyższego kodu?
  • #2 10608101
    jacekk232
    Poziom 17  
    Witam.

    W tych dwóch liniach kompilator zgłasza ci błędy bo to nie są polecenia z Bascom AVR tylko z Bascom 8051. Dlatego Bascom AVR ich nie rozpoznaje.
  • #3 10610716
    heyka
    Poziom 17  
    Nigdy nie miałem do czynienia z Bascomem 5051, możesz mi podpowiedzieć co to za polecenia i jakie są adekwatne polecenia w Bascom AVR?
  • #4 10610902
    SylwekK
    Poziom 32  
    Gate i Mode w konfiguracji timera nie występuje w bascomie na AVR. Prawdopodobnie może to być sposób wyzwalania/ zliczania timera (wewnętrzne lub zewnętrzne) plus jakieś inne tryby pracy.
  • #5 11754088
    lumpus
    Poziom 14  
    Witam

    Ten program został napisany na MCU - AT89C2051 !
    A nie na AVR Atmega8, dlatego Bascom avr ma problem.
    Aby go skompilować Musisz to zrobić w Bascom 8051.
    Ps. przymierzam się do zrobienia tego detektora od
    roku, ale jakoś czasu nie mam...
REKLAMA