Uart unter Bascom

OP #583322
Lesenswert?

Hi

ich möchte gerne mit Bascom auslesen, was am Uart eintrifft, jedoch 
kommen immer irgendwelche Fehler (bsp. weis ich net, als was ich die 
temporäre Variable dimmen soll...)

Jetzt ganz einfach habe ich mir gedacht, ob es nicht ein Beispielprog 
gibt, welches das wieder mit Print ausspuckt, was es empfangen hat.

Wenn ja, kann man mir einen Link zu Verfügung stellen? Wenn nicht, 
sollte es dich ein Wenigzeiler sein, vll. könnte jemand diesen kurz 
Posten.


Ich hoffe dass ich vier nicht totale Basics abfrage und mich zum Affen 
mache, aber es klappt mit Inkey oder Input einfach nicht :-(


Edit: Controller ist ein ATMega 32, Print klappt soweit recht gut...
Gast #583326
Lesenswert?

$regfile = "m161def.dat"                                    ' specify 
the used micro

$crystal = 4000000                                          ' used 
crystal frequency

$baud = 9600                                                ' use baud 
rate

$hwstack = 32                                               ' default 
use 32 for the hardware stack

$swstack = 10                                               ' default 
use 10 for the SW stack

$framesize = 40                                             ' default 
use 40 for the frame space
'first compile and run this program with the line below remarked

Config Serialin = Buffered , Size = 20

Dim Na As String * 10
'the enabling of interrupts is not needed for the normal serial mode

'So the line below must be remarked to for the first test

Enable Interrupts

Print "Start"

Do

   'get a char from the UART

   If Ischarwaiting() = 1 Then                              'was there a 
char?

      Input Na

      Print Na                                              'print it

   End If

   Wait 1                                                   'wait 1 
second

Loop
OP #583398
Lesenswert?

Ähnlich hab ich jetzt gelöst:
1
Do
2

3
   Dim Complete As Bit
4
   Complete = 1
5

6
   Waitms 100
7
   Do
8

9

10
      If Ischarwaiting() = 1 Then
11
         Bkey = Inkey()
12
         Ckey = Chr(bkey)
13
         Akey = Akey + Ckey
14

15
         Complete = 0
16

17
      End If
18

19
      If Ckey = "!"then
20
         Print Akey
21
         Akey = ""
22
         Ckey = "0"
23
         Complete = 1
24
      End If
25

26
   Loop Until Complete = 1
27

28
Loop

wenn das letzte Zeichen ein "!" ist, wird das ganze "geprintet", aber 
das Problem ist, dass Inkey nur ein Zeichen ist, desshalb "verpasst" der 
einige Zeichen am Anfang

Füge ich vorne
1
Config Serialin = Buffered , Size = 20

an, so kommt gar keine Antwort (und auch gar kein Print) mehr an...

Woran könnte das liegen?
Gast #583432
Lesenswert?

du must die ankommenden zeichen mit CHR() in einem string umwandeln
und dann in eine string variable  addieren.
DIM Dat As String

 Dat = ""
    Do
      Z = Inkey()
      If Z <> 0 Then Dat = Dat + Chr(z)
    Loop Until Z = 0
Gast #583473
Lesenswert?

Declare Function mpfange_daten(dat As String) As Byte


Function empfange_daten(dat As String) As Byte
Local Z As Byte

    Waitms 20
    Dat = ""
    Do                                                      n
      Z = Inkey()
      If Z <> 0 Then Dat = Dat + Chr(z)
    Loop Until Z = 0
    Rn_empfange_funkstring = 0
End Function
Gast #583478
Lesenswert?

nicht ganz, eher so:

Declare Function mpfange_daten(dat As String) As [b]String[/b]


Function empfange_daten(dat As String) As [b]String[/b]
Local Z As Byte

    Waitms 20
    Dat = ""
    Do                                                      n
      Z = Inkey()
      If Z <> 0 Then Dat = Dat + Chr(z)
    Loop Until Z = 0
    Rn_empfange_funkstring = 0
End Function

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren