Dekoder tonów na atmega 8


Witam.
mam taki oto program, który dekoduje mi tony podane na wejście AIN1 atmegi.
Sekwencja składa się z 15 tonów, najpierw wysyłane jest 7 tonów po 100ms, przerwa 200ms, 8 tonów po 100ms.
Próbuję wysłać te dane przez Uart i zamiast dostać sekwencję np 1241234 przerwa 34121242 to dostaję coś takiego

1
12
124
1241
12412
124123
1241234
3
34
3412
34121
341212
3412124
34121242

Jak sobie poradzić z tym problemem i jak zapisać te dane do tablicy 15 elementowej z której będe mógł sobie potem pobrać dane liczby i pomnożyć przez inne dowolne?

$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 40
$framesize = 40
$baud = 19200
Config Portd.2 = Output
Config Portd.3 = Output
Config Portd.4 = Output
Config Portc.2 = Output
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portd.0 , Db7 = Portd.1 , E = Portc.3 , Rs = Portc.1
Config Lcd = 16 * 1a
Cursor Off
Cls
Lcd "test"
Portd.2 = 1
Portd.3 = 1
Portd.4 = 1
Portc.2 = 0
 
Config Timer1 = Timer , Prescale = 1 , Capture Edge = Rising , Noise Cancel = 1
Config Aci = On , Compare = On , Trigger = Rising
 
On Icp1 Oncapture
Enable Icp1
 
On Int0 Ontaster
Config Int0 = Falling
Enable Int0
 
Enable Interrupts
 
Dim Licznik As Word
Dim Icr_neu As Word
Dim Icr_alt As Word
Dim Czasf As Long
Dim Czestotliwosc As Word
Dim A(16) As Word
Dim Sumaf As Word
Dim Dodaj As Integer
Dim Durchschnitt As Word
Dim Grenzeo As Word
Dim Grenzeu As Word
Dim Ton As String * 1
Dim Tonalt As String * 1
Dim Folge As String * 15
Dim Timeout As Word
 
 
 
'Portd.3 = 0
'Portd.2 = 0
Main:
 
Portd.3 = 1
 
 
Waitms 1
Czasf = 8000000 / Icr_neu
Icr_neu = 0
Czestotliwosc = Czasf
 
Incr Timeout
If Timeout > 150 Then
  Folge = ""
  Tonalt = ""
  Timeout = 0
End If
 
A(16) = A(15)
A(15) = A(14)
A(14) = A(13)
A(13) = A(12)
A(12) = A(11)
A(11) = A(10)
A(10) = A(9)
A(9) = A(8)
A(8) = A(7)
A(7) = A(6)
A(6) = A(5)
A(5) = A(4)
A(4) = A(3)
A(3) = A(2)
A(2) = A(1)
A(1) = Czestotliwosc
 
Sumaf = 0
For Dodaj = 1 To 16
  Sumaf = Sumaf + A(dodaj)
Next
 
Durchschnitt = Sumaf / 16
Grenzeo = A(1) + 10
Grenzeu = A(1) - 10
 
If Durchschnitt > Grenzeu And Durchschnitt < Grenzeo Then
 
  Select Case Durchschnitt
Case 970 To 990 : Ton = "0"
Case 1187 To 1207 : Ton = "1"
Case 1436 To 1456 : Ton = "2"
Case 1785 To 1805 : Ton = "3"
Case 2090 To 2110 : Ton = "4"
    Case Else : Goto Main
  End Select
 
Else : Goto Main
End If
 
If Ton = Tonalt Then Goto Main
Tonalt = Ton
 
Folge = Folge + Ton
Timeout = 0
 
 
If Len(folge) >1 Then
Print, Folge
Cls
Lcd Folge
 
End If
Goto Main
 
 
 
Ontaster:
Portd.3 = 1
 
 
 
Return
 
 
Oncapture:
  Licznik = Timer1
  Icr_neu = Licznik - Icr_alt
  Icr_alt = Licznik
  Portd.3 = 0
 
 
Return




Portret użytkownika kaktus

chymmm

Jakoś tu (na załączonym kodzie) nie widzę jak wysyłasz te dane, a co za tym idzie jak je odbierasz z UART.
Może jak już złapiesz wszystkie te cyferki, zrób z nich string i wyślij jednym ciągiem cały string, by na drugim końcu go złapać.

-

"Cierpliwym być musisz, by wiedzę zgłębiać tajemną, gdyż ciemna strona mocy niszczącą i silną jest.".