Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Problem with Data-Lines

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Micha

Bascom Member



Joined: 03 Oct 2006
Posts: 57

germany.gif
PostPosted: Fri Dec 24, 2021 10:05 am    Post subject: Problem with Data-Lines Reply with quote

Helo

I have written a small demo programm to show the problem

The expected Output of the program in the simulator uart window should be:

Los gehts...
ABCDEFABCDEFABCDEF
Fertig?

But the Output is following:
Los gehts...
ABCDEF)
Fertig?

The programm breaks by reading the Data lines defined with prefix '$'

Is it a Bug?

Here the Demo code:


Code:
'  Demo Datazeilen

'  Das Programm ist für den Simulator geschrieben und verdeutlicht die Problematik mit Data-Zeilen.

'  In 3 Data-Zeilen sind mit unterschiedlicher Schreibweise die Zeichen 'A' bis 'F' abgelegt.
'  Diese werden in der Hauptschleife gelesen und so sollte in der
'  UART0-Ausgabe 3x die Zeichen 'A' bis 'F' zu sehen sein.

'  Die Data-Zeilen werden im Flash extra (mit .org $100) an Adresse Word-Adresse $100 abgelegt.
'  Wenn man auf manuell programmieren geht und die Hexwerte vom Flash ansieht,
'  sind die Werte ab Byte-Adresse $200 in dem Viewer zu finden.

'  Wegen der Flash-Organisation werden 2 Zeichen immer als Word-Wert zusammen gefasst,
'  von denen das Low-Byte zuerst abgelegt wird. So sollte sich im Flash
'  3x hintereinander die Zeichenfolge 'BADCFE' finden - tatsächlich steht sie nur 2x dort.
'  Dazwischen 6 Word-Werte.

'  Die Data-Zeilen mit Prefix '$' werden als Word-Werte abgelegt anstatt als Byte-Werte.


   $Regfile = "m16def.dat"
   $HWStack = 40
   $SWStack = 40
   $Framesize = 40

   $Crystal = 8000000

   $Baud = 9600

   Config Base = 0
   Config SubMode = New

   $SIM

   Dim tmpByte as Byte

   Do
      Restore MyData_Bas

      Print "Los gehts..."

      Read tmpByte
      While tmpByte > 0
         UDR = tmpByte
         Read tmpByte
      Wend
      Print : Print "Fertig?"
   Loop


   !.org $100                                               ' Wordadresse (Flash Vorschau ab $200)

   MyData_Bas:
      Data &h41 , &h42 , &h43 , &h44 , &h45 , &h46          ' Zeichen 'A' bis 'F' / speichert Byte-weise, korrekt
      Data $41 , $42 , $43 , $44 , $45 , $46                ' Zeichen 'A' bis 'F' / speichert Word-weise, falsch im Flash abgelegt
      Data 65 , 66 , 67 , 68 , 69 , 70                      ' Zeichen 'A' bis 'F' / speichert Byte-weise, korrekt
      Data 0
 


Load the program in bascom und simulate it step by step ald watch the UART output.[/code]

(BASCOM-AVR version : 2.0.8.4 )
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Dec 24, 2021 10:16 am    Post subject: Reply with quote

Do you read the Help about "Data" statement? I suppose not.

From the Help:
Quote:
Integer and Word constants must end with the %-sign.

Long and Dword constants must end with the &-sign.

Single constants must end with the !-sign.

Double constants must end with the #-sign.



This code is a big mess. Cause you read only Byte ... real Word or Integer will become "&H0041" for example so even then somewhere you get byte equal to zero.
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Fri Dec 24, 2021 10:25 am    Post subject: Reply with quote

nice example. love that.

the $ is intended to create a string which is terminated by a 0-char by default.
for hex notation you should use &H and in the asm domain you can use $ too.

_________________
Mark
Back to top
View user's profile Visit poster's website
Micha

Bascom Member



Joined: 03 Oct 2006
Posts: 57

germany.gif
PostPosted: Fri Dec 24, 2021 12:13 pm    Post subject: Reply with quote

OK

If the sign '$' is intended to generate a String (&h41 and &h00 in Flash),
then should

Data $41

generate a String with the Char 'A' (ASCII $41) und terminated by char NULL.

Then the output in UART-Window should be

Los gehts...
A
Fertig?

But I get the Output of:

Los gehts...
)
Fertig?

Then you look in (start manual programm) Hex-Window you see generated in Flash at Adress $200 the values: &h00 and &h29. (see attachement!)

And &h29 ist not the same as &h41.

Here the changed Code to check out:


Code:
   $Regfile = "m16def.dat"
   $HWStack = 40
   $SWStack = 40
   $Framesize = 40

   $Crystal = 8000000

   $Baud = 9600

   $SIM

   Dim tmpByte as Byte

   Do
      Restore MyData_Bas

      Print "Los gehts..."

      Read tmpByte
      While tmpByte > 0
         UDR = tmpByte
         Read tmpByte
      Wend
      Print : Print "Fertig?"
   Loop


   !.org $100                                               ' Wordadresse (Flash Vorschau ab $200)

   MyData_Bas:

      Data $41
 
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Dec 24, 2021 12:29 pm    Post subject: Reply with quote

Better hit F1 in the Bascom and type "ASCII chart".
Then you realize that 41 in decimal means ")" and capital "A" uses 65 Wink
BTW. You can always use "Data "A" but there still will be zero at the end.



Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum