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

Set multiple pins on single instruction

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



Joined: 19 Oct 2011
Posts: 31

View user's profile Send private message

Set multiple pins on single instruction
PostPosted: Sun Nov 04, 2012 6:25 am     Reply with quote

My brain must be asleep, this seems like an easy task but i just can't grasp it this morning.

Device PIC16F1827
Compiler 4.137

if i were to have:
Code:

char my_var = 0x55;

output_b(my_var);


Then all pins in port B would be 0x55 at the same time. But i need some of the bits in the byte to go to different pins. Here is my define:
Code:

// DEFINE PORT 'A' I/O FUNCTIONS
#define Out_3   pin_A0       // Output   - Output 3
#define Out_6   pin_A1       // Output   - Output 6
#define PinA2   pin_A2       // Output   - NC
#define PinA3   pin_A3       // Output   - NC
#define PinA4   pin_A4       // Output   - NC
#define PinA5   pin_A5       // Output  - Programming Vpp
#define PinA6   pin_A6       // Output  - NC
#define PinA7   pin_A7       // Output   - NC

// ***** PORT 'B' *****

// DEFINE PORT 'B' I/O FUNCTIONS
#define Out_1   pin_B0   // Output   - Output 1
#define Out_2   pin_B1   // Output   - Output 2
#define Serial_RX   pin_B2   // Input   - Serial Data Input
#define Out_4   pin_B3   // Output   - Output 4
#define Out_5   pin_B4   // Output   - Output 5
#define Serial_TX   pin_B5   // Output   - Serial Data Output
#define Out_7   pin_B6   // Output   - Output 7
#define Out_8   pin_B7   // Output   - Output 8


What I need is for my_var to set the Output 1-8 at the same time.

I hope I have explained my question well enough, I am sure it is elementary but what am I forgetting?

Thanks!
mtsoule



Joined: 19 Oct 2011
Posts: 31

View user's profile Send private message

I dont think its possible...
PostPosted: Sun Nov 04, 2012 7:37 am     Reply with quote

the more i think about this, i was thinking about my assembly days and how i would do this in assembly (dream sequence starting...)

and i dont think this is going to be possible in a single instruction because i am working with two different ports at the same time...

any one confirm i am thinking correctly..
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Nov 04, 2012 9:35 am     Reply with quote

No, what you want to do cannot be done in one single (assembly) instruction, but you could write a function or macro that will do the hard work.

Methods for this have been discussed many times in the past. Here are some examples:
- The CCS supplied lcd driver lcd.c
- Mark's LCD driver in the Code Library: http://www.ccsinfo.com/forum/viewtopic.php?t=20182
- http://www.ccsinfo.com/forum/viewtopic.php?p=35073
- http://www.ccsinfo.com/forum/viewtopic.php?t=18949
Ttelmah



Joined: 11 Mar 2010
Posts: 19368

View user's profile Send private message

PostPosted: Sun Nov 04, 2012 9:35 am     Reply with quote

You are correct.
You can reduce the total instructions involved though, in the case of the port B pins.
Read the port. OR with 0b11011011. Write value out to the port.
If using fast_io, takes three instructions, whereas using the bit operations takes 6.
You need to be using fast_io to do this, otherwise the output will change the TRIS on the serial port pins, which you won't want.
On port A, you can't reduce the total, since reading, setting, and writing will take one more instruction than just the two bit output instructions.

Best Wishes
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sun Nov 04, 2012 11:21 am     Reply with quote

Quote:

at the same time


SYNCHRONOUS updates are only possible with ONE port at a time.

To get a LOT of i/o lines to change synchronously otherwise,
you need to use some form of external latches or SPI latches Like the HC595 or even denser i/o combos of ganged HC595 's
or I2C expanders with 16 or more pins that can change in sync.

It was not clear if your application depends on SYNC I/O updates or if you are trying to paper over the way an existing circuit is wired to your pic.
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