Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 23:21 19 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : How to CHR$ bigger then 255 decimal....

     Page 1 of 2    
Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9051
Posted: 06:45am 28 Dec 2019
Copy link to clipboard 
Print this post

Hi all.

Obviously, CHR$ only allows you an 8-bit byte to convert, cos when I try to feed it 256, MMBASIC moans that valid figures are 1-255 - fair enough.

How then, do I place data representing 256(or more) into a string?

This is the sub of code falling over:


SUB MP3_PLAYALERT
 MP3$=CHR$(&h7E)+CHR$(&hFF)+CHR$(&h06)+CHR$(&h03)+CHR$(&h00)+CHR$(&h00)+CHR$(&h100)+CHR$(&hEF)
 Print #1,MP3$;
End Sub


CHR$ is obviously not happy about my trying to push more then 8-bits into it, so how can I save 0x100(256 decimal) into the string?

The module I am sending data to, knows how to work out weather it has a single-byte command or a 'double-byte' word, based on when it receives the end-byte.(0xEF)

Basically, if the data previous to receiving an 0xEF end-byte is 8-bit, then it is a byte command, otherwise it is a 12-bit word.

EDIT: Should I be using STR$ for the 0x100 bit?  Just reading manual now....
Edited 2019-12-28 16:49 by Grogster
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5882
Posted: 07:18am 28 Dec 2019
Copy link to clipboard 
Print this post

If it really is binary data, you will need either
CHR$(&h01)+CHR$(&h00) or CHR$(&h00)+CHR$(&h01)
depending on the byte order - big endien or little endien

or you might really need HEX$() etc.

Jim
VK7JH
MMedit   MMBasic Help
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8567
Posted: 09:31am 28 Dec 2019
Copy link to clipboard 
Print this post

Which version of the MM?

New versions for MM+ and Armmites have BIN2STR$ and STR2BIN - see the MM+ manual for details
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9051
Posted: 01:56am 29 Dec 2019
Copy link to clipboard 
Print this post

Hi there.

MM2 on 170 chip.

This is the 'Engrish' page from the manual for the module, but it is hard to decipher due to the broken English.





I am trying to work out exactly what they mean here, but I THINK they mean that you need to specify two bytes for the file number if bigger then 255 - they show the example of 0x0064 for decimal 100.

I have also attached the PDF, but the rest of it is also quite hard to understand.

YX5200.zh-CN.en.pdf

In the examples I gave in the first post, THEY WORK PERFECTLY for any file number up to 255, so I am only trying to work out how to request file numbers bigger then 255, but this is where the datasheet is confusing me more then helping me due to the typically bad translation into English.
Smoke makes things work. When the smoke gets out, it stops!
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1590
Posted: 02:55am 29 Dec 2019
Copy link to clipboard 
Print this post

It looks to me that it always wants a two byte song number. I think TassyJim is correct - CHR$(&h01)+CHR$(&h00) would represent song 256 and CHR$(&h01)+CHR$(&h01) would be song 257...

Bill
Keep safe. Live long and prosper.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9051
Posted: 03:07am 29 Dec 2019
Copy link to clipboard 
Print this post

Yes, I think you are correct.  I note that in my example in the first post, I am actually giving it the high-byte 0x00 as part of the command, so I think Jim is spot on, so I will change the code slightly, and let everyone know what happens.
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9051
Posted: 03:10am 29 Dec 2019
Copy link to clipboard 
Print this post

JIM WAS CORRECT!!!!  

New code:

  Quote  SUB MP3_PLAYALERT
 MP3$=
CHR$(&h7E)+CHR$(&h10)+CHR$(&h06)+CHR$(&h03)+CHR$(&h00)+CHR$(&h01)+CHR$(&h00)+CHR$(&hEF)
 
Print #1,MP3$;
End Sub


It's alive!  ALIVE!!!!!!

This works perfectly if I ask it to play song 256 - which is reserved as the alert sound.  Now that I have it working, I can expand on this idea some more now.

Yay!  
Smoke makes things work. When the smoke gets out, it stops!
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1985
Posted: 12:49pm 29 Dec 2019
Copy link to clipboard 
Print this post

  Grogster said  ... it is hard to decipher due to the broken English.


Don't worry Grogs, I think your English has got much better during 2019  

Happy New year
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1421
Posted: 04:10pm 29 Dec 2019
Copy link to clipboard 
Print this post

  CaptainBoing said  
  Grogster said  ... it is hard to decipher due to the broken English.


Don't worry Grogs, I think your English has got much better during 2019  

Happy New year


Not to this bloke.  

Is this for an audio module?


' Open serial port

OPEN "COM1:9600" AS #1

CGMP3.SelectSD

PAUSE 500

CGMP3.Rndm

END



' Play Next song

SUB CGMP3.PlayNext

CGMP3.Cmd(&h01, &h0000)

END SUB



' Play Previous song

SUB CGMP3.PlayPrevious

CGMP3.Cmd(&h02, &h0000)

END SUB



' Play indexed song in the root directory

' sel - index to song 1-2999

SUB CGMP3.PlayRootDirSong(sel AS INTEGER)

CGMP3.Cmd(&h03, sel)

END SUB



' Increase Volume

SUB CGMP3.VolUp

CGMP3.Cmd(&h04, &h0000)

END SUB



' Decrease Volume

SUB CGMP3.VolDn

CGMP3.Cmd(&h05, &h0000)

END SUB



' Specify volume 0 to 30

SUB CGMP3.Volume(vol AS INTEGER)

CGMP3.Cmd(&h06, vol)

END SUB



' Specify EQ

' 0 - Normal

' 1 - Pop

' 2 - Rock

' 3 - Jazz

' 4 - Classical

' 5 - Bass

SUB CGMP3.EQ(eq AS INTEGER)

CGMP3.Cmd(&h07, eq)

END SUB



' Repeat specified Track

' track - index to song 1-2999

SUB CGMP3.RepeatTrack(track AS INTEGER)

CGMP3.Cmd(&h08, track)

END SUB



' Select USB for playback

SUB CGMP3.SelectUSB

CGMP3.Cmd(&h09, &h01)

END SUB



' Select SD for playback

SUB CGMP3.SelectSD

CGMP3.Cmd(&h09, &h02)

END SUB



' Reset

SUB CGMP3.Reset

CGMP3.Cmd(&h0C, &h02)

END SUB



' Play

SUB CGMP3.Play

CGMP3.Cmd(&h0D, &h02)

END SUB



' Pause

SUB CGMP3.Pause

CGMP3.Cmd(&h0E, &h02)

END SUB



' Play specified Track in Folder

' fold - index to folder 1-99

' track - index to song 1-255

SUB CGMP3.PlayFoldTrack(fold AS INTEGER, track AS INTEGER)

CGMP3.Cmd(&h0F, (fold*256)+track)

END SUB



' Stop

SUB CGMP3.Stop

CGMP3.Cmd(&h16, &h00)

END SUB



' Random Play

SUB CGMP3.Rndm

CGMP3.Cmd(&h18, &h00)

END SUB



SUB CGMP3.Cmd(commd AS INTEGER, dat AS INTEGER)

LOCAL INTEGER dath

LOCAL INTEGER datl

dath = dat >> 8

datl = dat AND &hFF

PRINT #1,CHR$(&h7E);CHR$(&hFF);CHR$(&h06);CHR$(commd);CHR$(&h00);CHR$(dath);CHR$(datl);CHR$(&hEF);

END SUB

Micromites and Maximites! - Beginning Maximite
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9051
Posted: 12:25am 30 Dec 2019
Copy link to clipboard 
Print this post

@ CaptainBoing: LOL!  Walked right into that one, didn't I! (rhetorical!)

@ CG: Yes, DFplayer Mini

They work really well, and can play pretty much anything MP3 or WAV, but the technical manual is hard to understand.

I am re-writing a correct English version of the Engrish manual, and will have it available for download from my website soon-ish.
Smoke makes things work. When the smoke gets out, it stops!
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1590
Posted: 12:49am 30 Dec 2019
Copy link to clipboard 
Print this post

AHA! That rings a bell. have you seen this ?

Bill
Keep safe. Live long and prosper.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9051
Posted: 11:38pm 30 Dec 2019
Copy link to clipboard 
Print this post

No, I had not.  I have not hovered in PICAXE circles for years now, having standardised on the Micromite through all my projects.

However, I have had a flick through that PDF(and saved it too), and it is more-or-less the same as the Engrish one I have now, but the PICAXE one is a LITTLE better translated, but it still has contextual issues when you read it.  I guess nothing is perfect.

I DO note that in the PICAXE PDF, they have correctly laid out the data-packet protocol better then in the PDF I had, where I was getting confused about the high and low bytes. (para1 and para2)

I think that the PDF I have was PROBABLY just run through Google Translate, and although that DOES help(as it is not all Chinese), Google Translate usually totally loses the context of the sentences and just translates the words.  That is bad enough in a normal Chinese document, but it becomes a real head-scratcher with a technical document!

"It is soft bubbles to the feel." kind of thing.





For more funny translations, go have a look at www.engrish.com
Smoke makes things work. When the smoke gets out, it stops!
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1590
Posted: 12:44am 31 Dec 2019
Copy link to clipboard 
Print this post

Yes, the Engrish version still needs a little translation.

I should have mentioned that Silicon Chip did one of their 'El Cheapo' articles on the DFPlayer Mini in December 2018 with a software example for the Micromite if you have access to it.

Bill
Keep safe. Live long and prosper.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9051
Posted: 03:36am 31 Dec 2019
Copy link to clipboard 
Print this post

Lovely, thanks.  I will have that issue, so I will dig it out.
Smoke makes things work. When the smoke gets out, it stops!
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 06:27am 31 Dec 2019
Copy link to clipboard 
Print this post

Please tell me what "Engrish" exactly means.

I consider the first part of the word coming from "English", but where does the "rish" come from? Short for "rubbish"?

This all reminds me of and for some extend this definitely is like "Kitchen English" ("English being spoken in the kitchen"), in Germany an artificial pseudo-english being spoken just for fun, intentionally abusing expressions for the construction of misleading meanings, especially using false friends as well as wrong pronunciation, accentuation and interpretations just to get linguistically as "bad" (funny nonsense) as possible.

For Germans among us just remember Otto as a popular example ...
https://www.youtube.com/watch?v=GFa0T0PmKxk


Andre ... such a GURU?
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1590
Posted: 06:43am 31 Dec 2019
Copy link to clipboard 
Print this post

it's just a dig at Japanese or Chinese pronunciation of some English words. If you Google it you will find a Wikipedia entry explaining it.

Bill
Edited 2019-12-31 16:48 by Turbo46
Keep safe. Live long and prosper.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9051
Posted: 08:47am 31 Dec 2019
Copy link to clipboard 
Print this post

  Poppy said  Please tell me what "Engrish" exactly means.

I consider the first part of the word coming from "English", but where does the "rish" come from? Short for "rubbish"?


CERTAINLY not.
I have nothing but respect for the Chinese, along with anyone else.

The word is picking fun at how bad the translations from Chinese to English tend to be.  By no means, does it refer to the Chinese or anyone else as a race or culture, but more picking fun at how bad the Chinese-to-English auto(Mr.G) translators tend to completely ruin the literal translation, in favour of translating the actual WORDS.
Smoke makes things work. When the smoke gets out, it stops!
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1985
Posted: 10:32am 31 Dec 2019
Copy link to clipboard 
Print this post

  Poppy said  Please tell me what "Engrish" exactly means.


It started out from a tendency for Chinese, Japanese & Korean native speakers to swap the pronunciation of "R" and "L" in certain places when speaking English (Hence the playful chain-rattle of EngRish) - and it really does happen - I talk to lots of Chinese and Japanese as part of my job and you get used to it.  The funny thing is that when native English speakers mimic Engrish, they tend to get it wrong by swapping every instance of R & L... "Proper" Engrish doesn't seem to have concrete rules like that - A friend has a Thai wife (leave it there - he has heard *all* the jokes). She cooks lots of Thai food and her "Yellow Cully" is to-die for.

It has since expanded into everything far eastern translated to English. As with most languages, the constructs of the sentences don't translate word-for-word very well, but even more-so, it appears there is more of the mindset get's missed from the language, so when you see a direct English translation it can make even less sense. A Sega game called "Zero Wing" was famous for this and has become a massive internet meme - google "All your base are belong to us" and just look at the hit count (Hint: Google gives up at 160M!). Zero Wing included such gems as "for great justice, take off every zig" and "you have no chance to survive, make your time".

It is generally very good humoured an not intended to offend, take a look at engrish.com
Edited 2019-12-31 20:36 by CaptainBoing
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 11:12am 31 Dec 2019
Copy link to clipboard 
Print this post

Thanks guys for explaining.

Of course with all respects to all others, no offense at all from me as well!
Particularly about insulting anyone I think here we are clearly talking about companies not doing their jobs professionally, so we are not getting personal at all, so there is no offense to any person or culture and a company must accept this.

Even "Kitchen English" originally humiliating those who were not able to speak english with a certain quality or in a proper way, lacking fundamental skills (those being/working in the kitchen) elevated to an autonomous art of deadpan humor now exclusively making fun of those intentionally speaking it themselves.

It is all about playing with words and by the way questioning their usage and relevance.

But coming back to "Engrich", particularly concerning manuals being translated from chinese to english language for international distribution the term I already know for is "Chinglish" therfore "Engrich" seems to be the umbrella term.


Andre ... such a GURU?
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1985
Posted: 11:28am 31 Dec 2019
Copy link to clipboard 
Print this post

  Poppy said  
Even "Kitchen English" originally humiliating those who were not able to speak English with a certain quality or in a proper way, lacking fundamental skills (those being/working in the kitchen) elevated to an autonomous art of deadpan humor now exclusively making fun of those intentionally speaking it themselves.


This is very true as an example, see this in UK - talking "street" but with a clipped Cambridge accent. The humour comes from the juxtaposition of the characters/circumstances  and the way they talk.

https://www.youtube.com/watch?v=W4pnTrjEjd0
 
     Page 1 of 2    
Print this page
© JAQ Software 2024