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 CCS Technical Support

Grouping seperate port pins

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



Joined: 07 Oct 2003
Posts: 66
Location: England

View user's profile Send private message

Grouping seperate port pins
PostPosted: Tue Nov 09, 2004 8:33 am     Reply with quote

Hi everybody

I need to group together Pic port pins to produce a combined port which I can output to in one instruction I think I need a union - could someone explain how.
Thanks for your help.

Dave
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 09, 2004 10:17 am     Reply with quote

Nope, you can't write a value to an 8 bit variable and expect it to go to multiple port pins. You can write a function that excepts an 8 bit number and then sets the port pins individually or in groups depending on what you are trying to do. PCM Programmer posted an example of something like this within the past month (I think). Give a little more detail on what you are trying to do and which ports/pins you are trying to use.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 09, 2004 10:31 am     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=18949&highlight=pins+port
davt



Joined: 07 Oct 2003
Posts: 66
Location: England

View user's profile Send private message

PostPosted: Tue Nov 09, 2004 10:38 am     Reply with quote

Thanks
I have 6pins of port a and 2 pins of port c.
Due to circumstances I do not have a complete port to drive a 7 segment display ( switched cathode type ) I thought that there was some way to combine the port pins - across ports and to access them as though they where a full port. - or is it me who is a port pin short of a full port! Laughing

Like maybe:

struct

{
port pins a0 - a5;
port pins c0 - c1;
}display;

and write to the pins display=##

I am sure there was a previous topic on this but I did a search but could not find it.

Thanks again.

Dave
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 09, 2004 11:05 am     Reply with quote

If you lay the hardware out so that
RC1 = bit7
RC0 = bit6
RA5 = bit5
RA4 = bit4
RA3 = bit3
RA2 = bit2
RA1 = bit1
RA0 = bit0

Code:
#if defined(__PCM__)
#include <16f876.h>
#device *=16
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
 
#elif defined(__PCH__)
#include <18f252.h>
#device *=16
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#endif

#case

#byte PORTA = 5
#byte PORTC = 7

void set_data(int8 data)
{
  // The lower 6 bits of data are for portA.  Note that since RA6 & RA7 do
  // not exist we don't have to worry about masking those
  PORTA = data;

  // The upper 2 bits of data are for RC1 & RC0.  Since there are only 2 lets
  // just do some bit_test/set/clear
  if (bit_test(data,7))
    bit_set(PORTC, 1);
  else
    bit_clear(PORTC, 1);
 
  if (bit_test(data,6))
    bit_set(PORTC, 0);
  else
    bit_clear(PORTC, 0);
 
}

void main(void)
{
  set_data(42);
  while(1)
  {
  }
}
davt



Joined: 07 Oct 2003
Posts: 66
Location: England

View user's profile Send private message

PostPosted: Tue Nov 09, 2004 11:24 am     Reply with quote

Thanks Mark I will try that in the morning.
Take care.

Dave
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