CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

outputing variable to pins on different ports

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jimcbride



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

outputing variable to pins on different ports
PostPosted: Mon Jun 18, 2007 9:38 am     Reply with quote

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...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 18, 2007 9:48 am     Reply with quote

Here is a fast way to do it:
http://www.ccsinfo.com/forum/viewtopic.php?t=18949&start=6

What's the device ?
jimcbride



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

PostPosted: Mon Jun 18, 2007 10:18 am     Reply with quote

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; \
....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 18, 2007 12:52 pm     Reply with quote

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 ?
jimcbride



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

PostPosted: Mon Jun 18, 2007 3:43 pm     Reply with quote

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?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 18, 2007 5:14 pm     Reply with quote

With an 8-bit microcontroller, I don't believe there is a way to write
to two i/o ports at the same time.
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

PostPosted: Tue Jun 19, 2007 2:24 am     Reply with quote

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!
jimcbride



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

PostPosted: Tue Jun 19, 2007 7:22 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group