Zmieniłem częstotliwość taktowania atmegi z 10MHz na 16MHz ale przy próbie kompilacji wyskakuje błąd
- Error : 367 Line : 31 Function name not allowed [POLOHA] , in File : J:\Projekty-Bascom\AS5311-Bascom.bas
- '---
- ' (c) 2009
- '---
- 'AS5311
- $regfile = "m32def.dat"
- $crystal = 1600000
- $baud = 19200
- '$sim
- ' ****************************
- '* LCD nastavení *
- ' ****************************
- '$lib "LCD4.lbx" ' use the alternative library
- 'this is like always, define the kind of LCD
- config lcd = 16 * 4
- 'Config LCD = 16 * 2
- Config LCDpin = Pin , Rs = Portb.5 , E = Portb.4 , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3
- Config Porta = Output
- Config Portc = Input
- Config Pina.0 = Input 'DO ... data out
- Config Porta.1 = Output 'CS ... chip select
- Config Porta.2 = Output 'CLK ... clock 'data out
- Data_out Alias Pina.0 'Chip select
- Cs Alias Pina.1 'hodiny
- Clk Alias Pina.2
- Declare Sub Poloha(byref P As Integer)
- Declare Sub Determinuj_polohu(p_old As Integer , P_new As Integer , Sm As Integer , Pp As Integer)
- Declare Sub Cti_data(byref Pozice As Integer)
- Declare Sub Ssi_init
- Declare Sub Ssi_close
- Dim Pozice As Integer
- 'Dim Poloha As Long
- Dim Vzd_pom As Long
- Dim Vzdalenost As Long
- Dim Mm2 As Integer
- Dim Draha As String * 16
- Dim Pom_str As String * 16
- Dim Pom_s As Single
- Dim Pozice_old As Integer
- Dim Pozice_new As Integer
- Dim Pozice_start As Integer
- Dim Smer As Integer
- Dim Priznak As Integer
- Dim Fix_prechodu As Bit
- Dim Pocitadlo As Integer
- Dim Ocf As Byte
- Dim Cof As Byte
- Dim Lin As Byte
- Dim Mag_inc As Byte
- Dim Mag_dec As Byte
- Dim Parita As Byte
- Dim Poms As String * 16
- 'určení výchozí polohy při startu čipu-->'określenie pozycji wyjściowej na początku chipa
- Pocitadlo = 0
- Mm2 = 0
- Call Poloha(pozice_start)
- Pozice_old = Pozice_start
- 'main
- 'PINC.7 reset. tlačítko-->przycisk
- Do
- 'stisk reset tlačítka--> 'naciśnij przycisk resetowania
- Incr Pocitadlo
- If Pinc.7 = 1 Then
- 'určení výchozí pozice-->'określ pozycję wyjściową'
- Mm2 = 0
- Call Poloha(pozice_start) 'Poloha--> Pozycja
- Pozice_old = Pozice_start
- End If
- 'Waitus 10
- Call Poloha(pozice_new)
- Call Determinuj_polohu(pozice_old , Pozice_new , Smer , Priznak)
- If Smer = 0 Then 'Smer--> Kierunek
- If Priznak = 0 Then
- 'vzdálenost roste v rámci 2mm-->Odległość rośnie w ciągu 2 m
- Vzd_pom = Mm2 * 4096 : Vzd_pom = Vzd_pom - Pozice_start
- Vzdalenost = Vzd_pom + Pozice_new
- Else
- 'vzdálenost roste přes 2mm-->'Odległość rośnie ponad 2mm
- Incr Mm2
- Vzd_pom = Mm2 * 4096 : Vzd_pom = Vzd_pom - Pozice_start
- Vzdalenost = Vzd_pom + Pozice_new
- End If
- Else
- If Priznak = 0 Then
- 'vzdálenost klesá v rámci 2mm-->'Odległość spada w granicach 2mm
- Vzd_pom = Mm2 * 4096 : Vzd_pom = Vzd_pom - Pozice_start
- Vzdalenost = Vzd_pom + Pozice_new
- Else
- 'vzdálenost klesá přes 2mm-->Odległość spada ponad 2mm
- Decr Mm2
- Vzd_pom = Mm2 * 4096 : Vzd_pom = Vzd_pom - Pozice_start
- Vzdalenost = Vzd_pom + Pozice_new
- End If
- End If
- 'Waitus 10
- 'hodnota na display se zobrazí každý 20 cyklus-->wartość pojawia się na wyświetlaczu co 20 cykli
- If Pocitadlo > 50 Then
- Pocitadlo = 0
- Cls
- LCD Pozice_new
- Lowerline
- Pom_s = Vzdalenost / 2048
- LCD Fusing(pom_s , "#.###")
- End If
- Pozice_old = Pozice_new
- Loop
- End
- ' ****************************
- 'určí směr pohybu a překrocění hranice 0 /-/ 4095-->określa kierunek ruchu i przekroczenie granicy 0 / - / 4095
- ' ****************************
- Sub Determinuj_polohu(p_old As Integer , P_new As Integer , Sm As Integer , Pp As Integer)
- 'Sm ... směr
- ' 0 = vzdaluji se od reference-->Odchodzę od referencji
- ' 1 = přibližuji se-->zbliżam się
- 'Pp ... příznak přechodu přes 4095-->Pp ... przekraczanie flagi ponad 4095
- ' 0 = nepřekročil jsem 4095-->nie przekroczyłem 4095
- ' 1 = překročil jsem přes 4095-->przekroczyłem 4095
- Dim Delta As Single
- Dim Sgn_delta As Single
- Dim Abs_delta As Single
- Delta = P_new - P_old
- Abs_delta = Abs(delta)
- Sgn_delta = Sgn(delta)
- Select Case Delta
- 'delta je kladné nebo nula-->delta jest dodatnia lub zero
- Case Is >= 0
- If Abs_delta < 1000 Then
- 'vzdálenost roste a jsem v rozsahu 2 mm-->odległość rośnie i jestem w zakresie 2 mm
- Sm = 0 : Pp = 0
- Else
- 'vzdálenost klesá a překročil jsem 2 mm-->odległość maleje i przekroczyłem 2 mm
- Sm = 1 : Pp = 1
- End If
- 'delta je záporné-->delta jest ujemna
- Case Else
- If Abs_delta < 1000 Then
- 'vzdálenost klesá a jsem v rozsahu 2 mm-->odległość maleje i jestem w zakresie 2 mm
- Sm = 1 : Pp = 0
- Else
- 'vzdálenost klesá a překročil jsem 2 mm-->odległość maleje i przekroczyłem 2 mm
- Sm = 0 : Pp = 1
- End If
- End Select
- End Sub
- ' ****************************
- 'vyčte polohu z čipu-->odczytaj pozycję z chipa
- ' ****************************
- Sub Poloha(p As Integer)
- 'inicializace čipu-->inicjalizacja chipa
- Ssi_init
- 'čtení hodnoty-->wartość odczytu
- Call Cti_data(p)
- 'ukončení komunikace s čipem-->zakończenie komunikacji z chipem
- Ssi_close
- End Sub
- ' ****************************
- 'Přečte data z měřiče, bit po bitu-->Odczytuje dane z licznika, bit po bicie
- ' ****************************
- Sub Cti_data(byref Pozice As Integer)
- Dim Pom As Byte
- 'Pin 2 portu A jsou hodiny-->'Pin 2 portu A to zegar
- 'Proměnná Pozice vrací hodnotu-->Zmienna Pozice zwraca wartość
- Pozice = 0
- 'D11
- Reset Porta.2
- If Pinc.0 = 1 Then
- Pozice = Pozice + 1
- End If
- Set Porta.2
- 'D10
- Pozice = Pozice * 2
- Reset Porta.2
- If Pinc.0 = 1 Then
- Pozice = Pozice + 1
- End If
- Set Porta.2
- 'D9
- Pozice = Pozice * 2
- Reset Porta.2
- If Pinc.0 = 1 Then
- Pozice = Pozice + 1
- End If
- Set Porta.2
- 'D8
- Pozice = Pozice * 2
- Reset Porta.2
- If Pinc.0 = 1 Then
- Pozice = Pozice + 1
- End If
- Set Porta.2
- 'D7
- Pozice = Pozice * 2
- Reset Porta.2
- If Pinc.0 = 1 Then
- Pozice = Pozice + 1
- End If
- Set Porta.2
- 'D6
- Pozice = Pozice * 2
- Reset Porta.2
- If Pinc.0 = 1 Then
- Pozice = Pozice + 1
- End If
- Set Porta.2
- 'D5
- Pozice = Pozice * 2
- Reset Porta.2
- If Pinc.0 = 1 Then
- Pozice = Pozice + 1
- End If
- Set Porta.2
- 'D4
- Pozice = Pozice * 2
- Reset Porta.2
- If Pinc.0 = 1 Then
- Pozice = Pozice + 1
- End If
- Set Porta.2
- 'D3
- Pozice = Pozice * 2
- Reset Porta.2
- If Pinc.0 = 1 Then
- Pozice = Pozice + 1
- End If
- Set Porta.2
- 'D2
- Pozice = Pozice * 2
- Reset Porta.2
- If Pinc.0 = 1 Then
- Pozice = Pozice + 1
- End If
- Set Porta.2
- 'D1
- Pozice = Pozice * 2
- Reset Porta.2
- If Pinc.0 = 1 Then
- Pozice = Pozice + 1
- End If
- Set Porta.2
- 'D0
- Pozice = Pozice * 2
- Reset Porta.2
- If Pinc.0 = 1 Then
- Pozice = Pozice + 1
- End If
- Set Porta.2
- 'čtení stavových bitů-->odczytaj bity statusu
- 'OCF
- 'Waitus 10
- Reset Porta.2
- Ocf = Pinc.0
- Set Porta.2
- 'COF
- 'Waitus 10
- Reset Porta.2
- Cof = Pinc.0
- Set Porta.2
- 'LIN
- 'Waitus 10
- Reset Porta.2
- Lin = Pinc.0
- Set Porta.2
- 'Mag_INC
- 'Waitus 10
- Reset Porta.2
- Mag_inc = Pinc.0
- Set Porta.2
- 'Mag_DEC
- 'Waitus 10
- Reset Porta.2
- Mag_dec = Pinc.0
- End Sub
- ' ****************************
- ' ****************************
- Sub Ssi_init
- 'A.1 CS ¨¨¨¨¨______
- 'A.2 CLK ¨¨¨¨¨¨¨__¨¨
- ' us 2 1 1 1
- 'PortA.2 CLK ... clock
- Set Porta.2
- 'PortA.1 CS ... chip select
- Set Porta.1
- Waitus 2
- Reset Porta.1
- Waitus 1
- Reset Porta.2
- Waitus 1
- Set Porta.2
- Waitus 1
- End Sub
- ' ****************************
- ' ****************************
- Sub Ssi_close
- 'A.1 CS ___¨¨¨¨
- 'A.2 CLK _¨¨¨¨¨¨
- ' us 1 2
- 'čtu ^
- 'PortA.2 CLK ... clock
- 'PortA.1 CS ... chip select
- 'Parita
- Set Porta.2
- Parita = Pinc.0
- Waitus 1
- Set Porta.1
- Waitus 2
- End Sub
- ' ****************************
pozdrawiam Jacek.