Send hex to 8 pins
gregfox
Posts: 68
in Propeller 1
Hi all,
I'm trying to send a hex code to 8 pins of a parallax propeller in c.
Send hex 38 to pins 27,26,25,24,23,22,21,20 which is 00111000 in binary, so that;
0 goes to pin27
0 goes to pin26
1 goes to pin25
1 goes to pin24
1 goes to pin23
0 goes to pin22
0 goes to pin21
0 goes to pin20
In stead of sending a binary to each pin I want to send a single hex code.
Thanks
I'm trying to send a hex code to 8 pins of a parallax propeller in c.
Send hex 38 to pins 27,26,25,24,23,22,21,20 which is 00111000 in binary, so that;
0 goes to pin27
0 goes to pin26
1 goes to pin25
1 goes to pin24
1 goes to pin23
0 goes to pin22
0 goes to pin21
0 goes to pin20
In stead of sending a binary to each pin I want to send a single hex code.
Thanks
Comments
This is my guess as well.
As Peter points out, 'Hex" is a way of displaying numbers for us humans. All numbers are stored in binary inside the Propeller. Sometime us humans don't mind reading numbers in binary but we also like numbers displayed in other ways depending on the application. Hexadecimal is a convenient way of displaying a single byte as two digits.
I'll add, Sapphire's code:
Could also be written other ways with the exact some results.
(I left off the leading zeros in the binary and quaternary notation.)
All the above numbers are stored inside the Propeller with the same pattern of ones and zeros.
Andy
This is just a poorly worded question, are you saying you want to send "hex code" to each pin?
If I write $FA to P0..P7 then it is possible to feed P0..P3 into a "binary" to 7-segment decoder driving a 7-segment display to display "hex" and the same for the other 4 bits. But your question comes across as just pure nonsense.
Sorry about that. Good thing Ariba was around.
I want to send a hex code(38) to 8 pins so that the first pin gets a 0 , and the next pin gets a 0 and the next pin gets a 1 , etc. This would be easier then
Low(27);
Low(26);
High(25);
I hope that’s clear, sorry for my poorly worded post.
By the way this is C not spin.
Thank you
sending a binary code to each pin.
I hope that’s clear, sorry for my poorly worded post.
By the way this is for C code. The code I'm using so far, that works by using binary is:
//int port[] = {27,26,25,24,23,22,21,20};
int i = 8;
while(i >0)
{ //while start
--i;
low(27);
low(26);
high(25);
high(24);
high(23);
low(22);
low(21);
low(20);
}
What I want to do is send a single hex code (38) to pins 20 to 27.
Thank you
P.S. come to think of it, I get in trouble with my wife all the time for this type of thing!
I'm not a C programmer, but I understand the Propeller well enough to know that outputs require manipulation of the dira and outa registers. After installing SimpleIDE I poked around for a few minutes and found a function that I could adapt to your pin set.
Edit: I just saw in the other thread that Andy provided a solution; this one is a little more generic so you can change the values on the pins with the function call.
In your case you would do something like this:
The above will set pins 16-23 to output
then pins 20-23 will go high.
Thanks again.
Hiding behind German heritage is no excuse for bellicose, pejorative, lilliputian behavior.
Just so you know, I solved the problem with my own agog with the below code:
set_directions (23, 16, 0xFF); //instead of 0b11111111 0xFF can be used
set_outputs (23, 16, 0XF0); //set pin 20-23 high
In any case I hold no umbrage.
I don't suppose we could get these threads merged?
As has been said multiple times, you're not sending "hex", you're sending a number. Hex is one way to display the number.
I"m trying.
Full documentation on the SimplePort can be found here: http://david.zemon.name/PropWare/classPropWare_1_1SimplePort.xhtml
/code
/*
Blank Simple Project.c
http://learn.parallax.com/propeller-c-tutorials
*/
#include "simpletools.h" // Include simple tools
//DataPins "20 21 22 23 24 25 26 27"
#define RS 17 //Register Select
#define EN 18 // Enable (Starts data read/write.)After E allows R/W it must then be turned off.
#define RW 19 //Read/write
#define DATA {27 26 25 24 23 22 21 20}
void inst(void);
void data(void);
void latch(void);
void Initialize(void);
void setout(void);
void setin(void);
void wr8bits(int val);
int main()
{ //main start
initialize(); //initialize LCD display (low(RS), low(RW), high(EN)
inst(); //Send Instruction Function Select routine (low(RS), low(RW))
//DATA Send Data 0X38 (set 8 bit mode) Send This instruction on LCD databus
set_outputs (27, 20, 0x38); //set 8 bit mode, 2-lines Font 5x7
pause(2);
latch();
//DATA Send 0X0f Second Instruction on LCD databus
inst();
set_outputs (27, 20, 0x0F); //Display on, Cursor on, Cursor blink
latch();
inst(); //(low(RS), low(RW))
set_directions (27, 20, 0xFF); //instead of 0b11111111 0xFF can be used (outputs)
set_outputs (27, 20, 0x1); //CLEAR display 0b00000001
latch();
pause(2000);
set_directions (27, 20, 0xFF); //instead of 0b11111111 0xFF can be used (outputs)
data(); //Change the input type to Data.(before it was instruction input)
set_outputs (27, 20, 0x47); //Send G send 47 HEX (G) to pins 20 to 27
latch();
set_outputs (27, 20, 0x52); //Send R
latch();
set_outputs (27, 20, 0x45); //Send E
latch();
set_outputs (27, 20, 0x47); //Send G
latch();
return(0);
inst();
set_outputs (27, 20, 0xC0); //Cusor on line 2
latch();
void inst(void) //Instruction select routine
{
low(RS); //RS low
low(RW); //RW low
}
void data(void) // //Change the input type to Data.(before it was instruction input)
{
high(RS); //RS high
low(RW); //RW low
}
void latch(void) //->EN<- Latch the above instruction once.
{
high(EN); //EN high
pause(2); //wait 30mS
low(EN); //EN low
pause(2); //wait 30 mS
high(EN); //EN high
// p ause(50); //wait 50mS
}
void initialize(void)
{
low(RS);
low(RW);
high(EN);
pause(2); //some LCDs takes time to initialize at startup
}
void setout(void)
{
set_directions (27, 20, 0xFF); //instead of 0b11111111 0xFF can be used (outputs)
}
void setin(void)
{
set_directions (27, 20, 0x0); //instead of 0b00000000 0xFF can be used (inputs)
}
void wr8bits(int val)
{
DIRA |= 0xff << 20;
OUTA = (OUTA & ~(0xff << 20)) | (val << 20);
}
code/
As can be seen (in red), I'm sending one character at a time to the LCD, I've been working on a way to sent a string, instead of one character at a time. Any help?
//code
code//
BTW, is this the proper way to display code?
[ code ]
And
[ /code ]
But without the spaces.