Using a Mega how would you send a 8 bit character value to a 8 bit port? Basically my project is taking a character from the serial bus and sending it out in parallel. This should be a simple task but I haven't found any examples of 8 bit parallel output.
Check this out
HTH
a7
As you are using a Mega then this may be of interest Arduino mega 2560 using PORTS - Programming Questions - Arduino Forum
Thanks for the replies.
Is there a way to use pinMode() and digitalWrite() with the full port or only individual pins?
It would be great if I could do the following:
pinMode(PortA, OUTPUT);
digitalWrite(PortA, 0x55);
If not, is there a easier way to set the port than 8 commands
pinMode(22, OUTPUT); thru pinMode(29, OUTPUT); ?
Look into direct port manipulation.
Yes, direct port manipulation, of course assuming you have a full port to use.
It’s not that hard, or ugly. And you can certainly bury any ugliness by writing a few functions that could mimic the look and feel of digitalRead, digitalWrite and pinMode.
a7
alto777:
Yes, direct port manipulation, of course assuming you have a full port to use.It’s not that hard, or ugly. And you can certainly bury any ugliness by writing a few functions that could mimic the look and feel of digitalRead, digitalWrite and pinMode.
a7
You might just as well write functions that actually use digitalRead, digitalWrite and pinMode
Another picture (collected from net) for the mapping of Port-pin and DPin of MEGA.
Example:
Receive the character A from the InputBox of Serial Monitor and the write its value (ASCII Code: 0100 0001) onto Port-A (PA7-PA0).
for(int i=22; i<30; i++)
{
pinMode(i, OUTPUT); //PA0 - PA7 are output pins
}
//----------------------------------------------------------
byte n = Serial.available();
if(n != 0)
{
char y = Serial.read(); //y = y7 y6 y5 y4 y3 y2 y1 y0 = 0 1 0 0 0 0 0 1
PORTA = y; //8-bit parallel output
/*
for(int i=0, j=22; i<30; i++, j++)
{
digitalWrite(j) = bitRead(y, i); //bits of A are place on Port-A
}*/
}
“ You might just as well write functions that actually use digitalRead, digitalWrite and pinMode”
Haha, yes, talk about burying ugliness. It may be, however, that the speed gained by using direct port manipulation when throwing whole bytes around at once might be advantageous.
Not to mention that all the bits will change (or be read) simultaneously.
a7
Basically my project is taking a character from the serial bus and sending it out in parallel. This should be a simple task but I haven't found any examples of 8 bit parallel output.
How hard did you look ? The obvious solution would be to use a shift register, but as we don't know the speed requirements it is impossible to provide advice in context
As to "burying ugliness", does it actually matter how ugly the solution is as long as it meets the requirement ? Personally I prefer elegant solutions, but the prime objective should be a working solution
OP: your question
“ Using a Mega how would you send a 8 bit character value to a 8 bit port? ”
was answered in the first few posts. I assumed you meant a port on the Arduino microprocessor.
So take a look where we pointed you, give it a try and ask for help if it isn’t as easy as we are making it out to be.
a7
An eight bit parallel port will typically use at least nine pins.
Hey, how about that google, look:
all libraried up for you.
a7
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.