View previous topic :: View next topic |
Author |
Message |
davt
Joined: 07 Oct 2003 Posts: 66 Location: England
|
Grouping seperate port pins |
Posted: Tue Nov 09, 2004 8:33 am |
|
|
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
|
|
Posted: Tue Nov 09, 2004 10:17 am |
|
|
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
|
|
|
davt
Joined: 07 Oct 2003 Posts: 66 Location: England
|
|
Posted: Tue Nov 09, 2004 10:38 am |
|
|
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!
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
|
|
Posted: Tue Nov 09, 2004 11:05 am |
|
|
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
|
|
Posted: Tue Nov 09, 2004 11:24 am |
|
|
Thanks Mark I will try that in the morning.
Take care.
Dave |
|
|
|