View previous topic :: View next topic |
Author |
Message |
jimcbride
Joined: 05 Apr 2006 Posts: 23
|
outputing variable to pins on different ports |
Posted: Mon Jun 18, 2007 9:38 am |
|
|
Due to pin restrictions I need to output logic levels for 8 pins equal to a variable on separate ports.
Is there a way to set the all eight pins at the same time? I can easily test the bits in my variable and then set the pins to those logic levels. The problem is that I am afraid of a condiditon where the output pins get read by the attached device before all pins are set with the desired values and reads partially updated data.
Thanks... |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
jimcbride
Joined: 05 Apr 2006 Posts: 23
|
|
Posted: Mon Jun 18, 2007 10:18 am |
|
|
I am using the 18F1220 device.
I have read through that technique. I may be wrong, but it looks to me like this won't set all of the pins at the same time like setting an output port would. They will be set sequentially. It is fast though. Perhaps fast enough that a race condition occuring is improbable?
In this code snippet what is the \ (back slash) used for?
#define set_spare_bits(x) \
RA0 = x & 1; \
.... |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 18, 2007 12:52 pm |
|
|
A #define statement is terminated by the end of the line.
If you want a #define statement to consist of two or more lines, you
must put a backslash at the end of each line that is continued onto
the next line. The backslash is called the "line continuation" symbol.
I repeat -- what device are you talking to ? |
|
![](templates/subSilver/images/spacer.gif) |
jimcbride
Joined: 05 Apr 2006 Posts: 23
|
|
Posted: Mon Jun 18, 2007 3:43 pm |
|
|
hmmm. I don't see my reply posted. I will try again.
I thought I answered your question by saying I was using an 18F1220. I now realise you wanted to know what the 18f1220 is connecting to. whooops.
The setup is calorimeter node ID port -> uC -> 1-wire rs232 converter -> 1-wire multi switch -> calorimeter ID port.
The calorimeter node is an in house box that takes readings from calorimeters that are exposed to laser light. The Cal-nodes are Daisy chained and use Lontalk for communications and firmware.
Basically I have 8 pin dip switches for an ID on the Calorimeter and 8 input pins on the CAl node. But I only have two wires for communications and power. I just want to be sure that when I put data on the Cal node input pins that they are all written at once. Perhaps I can't do this. My main problem is that Porta uses the MCLR pin for reset and programming. Portb is used for the programmer/debugger and uart. The easy solution is to get rid of in circuit programming, but I would rather not.
I want to be clear that I am not trying to read pins and put those pins into a variable, I am doing the opposite. I want to receive a variable through the uart and then put that value onto the uC pins. Those pins available are not on the same port. So I have to chop up the variable and set the bits onto the pins as necessary. Setting a port to a value sets every port at the same time. Setting each bit as it is tested will be sequential. That is what I am trying to avoid.
Better? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 18, 2007 5:14 pm |
|
|
With an 8-bit microcontroller, I don't believe there is a way to write
to two i/o ports at the same time. |
|
![](templates/subSilver/images/spacer.gif) |
Pret
Joined: 18 Jul 2006 Posts: 92 Location: Iasi, Romania
|
|
Posted: Tue Jun 19, 2007 2:24 am |
|
|
Setting outputs in two different ports at the same time is imposible. You have to accept it. When you have this kind of situations, you must use an aditional bit for "Ready" confirmation. Just like PC parallel port with handshake protocol. The workflow is: set all 8 data pins accordingly, then after set the ready bit high. Most devices have that "ready to read" input bit. If not, you can add a logical AND gate for each pin. One gate pin for data and other one for Ready. Since all data are set, you can put Ready bit to hi to forward all data bits simultaneously.
Bafta! |
|
![](templates/subSilver/images/spacer.gif) |
jimcbride
Joined: 05 Apr 2006 Posts: 23
|
|
Posted: Tue Jun 19, 2007 7:22 am |
|
|
I thought this might be the case. I have thought about aditional logic in the circuit but I already am crammed for space. I think the easiest solution is to have the control system always do a double read and verify for duplicate data. Thanks for all the help. |
|
![](templates/subSilver/images/spacer.gif) |
|