Output, send Hex to port

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
Dirk-Jan
Posts: 8
Joined: Wed Oct 10, 2012 7:37 pm
Has thanked: 4 times
Contact:

Output, send Hex to port

Post by Dirk-Jan »

Hello everyone,

I am sending udp data from my pc to the E-blocks internet board.
The data that I am sending is formatted in Hexadecimal. So 01 mean 1 and ff means 255.
Now I want to output this to a E-Blocks LED board, but I don't know how to do this.
I tried to put it into a string and use this in a output block (I know that FC can output hex to a port) but it won't accept a string only a byte.
Is there maybe some easy to to achieve this or should I try to code something up in a C block?

Thank you.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Output, send Hex to port

Post by Enamul »

Hello,
I am not quite sure whether I understood your problem or not..I have attached here a program in which I have shown three possible data format for output..Binary, Hex or Decimal
Attachments
example.fcf
(5 KiB) Downloaded 585 times
Enamul
University of Nottingham
enamul4mm@gmail.com

Dirk-Jan
Posts: 8
Joined: Wed Oct 10, 2012 7:37 pm
Has thanked: 4 times
Contact:

Re: Output, send Hex to port

Post by Dirk-Jan »

Well the issue is that I am receiving something through a macro which will write it to a string variable.
Now I want to output this string variable to a port just like you did with 0xFF to port B but now it has to use the string.
And the output block's don't accept a string as a variable.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Output, send Hex to port

Post by Enamul »

Output can accept string..like..

Code: Select all

DATA[0]
it won't accept a string only a byte.
That's true byte is 8-bit so you can send to port maximum 8-bit. What is the length of your string and how you want to see them in LED? you can show byte-by-byte with some intermediate delay..although LCD is best for this..as you can see whole string at a time.
Enamul
University of Nottingham
enamul4mm@gmail.com

Dirk-Jan
Posts: 8
Joined: Wed Oct 10, 2012 7:37 pm
Has thanked: 4 times
Contact:

Re: Output, send Hex to port

Post by Dirk-Jan »

The data I have to work with is hexadecimal and goes from 01 to FF.
In total I have 8 leds and want them to switch on or off with the hex data.
So basicly if I send 01 only the first led will go on with 02 the second etc.
If I send 03 I want the first 2 leds to go on all the way until FF.

I already tried to use DATA[0] but It didn't matter what kind of value DATA had.
Only the 1, 5 and 6 led would go on. So it seems like it sended 49 in bytes.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Output, send Hex to port

Post by Enamul »

I already tried to use DATA[0] but It didn't matter what kind of value DATA had.
Only the 1, 5 and 6 led would go on. So it seems like it sended 49 in bytes.
I understand what you mean..Just clear me one thing..I might help you in designing the code. When LED 1,5 and 6 turn ON and it seems to you it sent 49..what actually you sent 1?
Enamul
University of Nottingham
enamul4mm@gmail.com

Dirk-Jan
Posts: 8
Joined: Wed Oct 10, 2012 7:37 pm
Has thanked: 4 times
Contact:

Re: Output, send Hex to port

Post by Dirk-Jan »

For that example I used test[0], I think it shouldn't be that hard though I just need to output FF or any other hex value to let the leds switch On or Off

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Output, send Hex to port

Post by Enamul »

If so, just do following..If DATA[0] is your string byte..

Code: Select all

DATA[0]=DATA[0]-'0'
In that case DATA[0]= 49-'0' = 49-48 = 1
Send that DATA[0] to PORT so only first LED will turn ON.
If you send 2 it's ASCII will be 50..DATA[0]= 50-48 = 2. So only 2nd LED will turn ON
Enamul
University of Nottingham
enamul4mm@gmail.com

Dirk-Jan
Posts: 8
Joined: Wed Oct 10, 2012 7:37 pm
Has thanked: 4 times
Contact:

Re: Output, send Hex to port

Post by Dirk-Jan »

Thanks you! I think I am able to manage it now!

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Output, send Hex to port

Post by Enamul »

Glad to know that. You are welcome :)
Enamul
University of Nottingham
enamul4mm@gmail.com

Post Reply