Searching \ for 'Setting bits with MC C18' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/index.htm?key=setting+bits+with
Search entire site for: 'Setting bits with MC C18'.

Truncated match.
PICList Thread
'Setting bits with MC C18'
2005\11\19@184145 by Lee McLaren

flavicon
face
Hi

I am trying to do a very simple thing but I can't see the probably
obvious way of doing it, I am new to C18 so this may be an easy question.

I have a 4 bit binary output I need to send to a keyboard decoding chip,
the pins are not all on one port so I am doing the following:

unsigned char KeyboardCont;
near union {
 struct {
   unsigned Bit0:1;
   unsigned Bit1:1;
   unsigned Bit2:1;
   unsigned Bit3:1;
   unsigned NotUsed4:1;
   unsigned NotUsed5:1;
   unsigned NotUsed6:1;
   unsigned NotUsed7:1;
 };
};



KeyboardCont is the register that I use to count through the 16
combinations as such:

//----------------------------------------------------------------
void ScanKeyboard(void) //step thru the kb and read
{
unsigned int i;
for (i=0; i<16; i++)
   {
   KeyboardCont = i;
   OutputKeyboard();
   }
}


So far so good, Next I want to actually update the respective ports to
reflect the count like so:
//----------------------------------------------------------------
void OutputKeyboard(void)
{
LATE.LATE0 = KeyboardCont[0];
LATE.LATE1 = KeyboardCont[1];
LATE.LATE2 = KeyboardCont[2];
LATA.LATA5 = KeyboardCont[3];
}
Notice the different ports.


This is the bit that wont work, I get the following errors:
C:\Data\PIC\PIC_C\Modbus1\main.c:432:Error [1151] struct or union object
designator expected
C:\Data\PIC\PIC_C\Modbus1\main.c:432:Error [1129] [] operator requires a
pointer and an integer as operands
C:\Data\PIC\PIC_C\Modbus1\main.c:433:Error [1151] struct or union object
designator expected
C:\Data\PIC\PIC_C\Modbus1\main.c:433:Error [1129] [] operator requires a
pointer and an integer as operands
C:\Data\PIC\PIC_C\Modbus1\main.c:434:Error [1151] struct or union object
designator expected
C:\Data\PIC\PIC_C\Modbus1\main.c:434:Error [1129] [] operator requires a
pointer and an integer as operands
C:\Data\PIC\PIC_C\Modbus1\main.c:435:Error [1151] struct or union object
designator expected
C:\Data\PIC\PIC_C\Modbus1\main.c:435:Error [1129] [] operator requires a
pointer and an integer as operands

If I try to LATE.LATE0 = 1; I also get an error, I understand that 1 is
not a bit but how do you set a bit?

I have spent a lot of time looking and I expect the answer is so easy
that its not documented :)
Is it possible to define the KeyboardCont as the pins directly so that I
don't need a working register?

thanks for reading

Lee McLaren




2005\11\19@184845 by Lee McLaren

flavicon
face
Hi

I am trying to do a very simple thing but I can't see the probably
obvious way of doing it, I am new to C18 so this may be an easy question.

I have a 4 bit binary output I need to send to a keyboard decoding chip,
the pins are not all on one port so I am doing the following:

unsigned char KeyboardCont;
near union {
 struct {
   unsigned Bit0:1;
   unsigned Bit1:1;
   unsigned Bit2:1;
   unsigned Bit3:1;
   unsigned NotUsed4:1;
   unsigned NotUsed5:1;
   unsigned NotUsed6:1;
   unsigned NotUsed7:1;
 };
};



KeyboardCont is the register that I use to count through the 16
combinations as such:

//----------------------------------------------------------------
void ScanKeyboard(void) //step thru the kb and read
{
unsigned int i;
for (i=0; i<16; i++)
   {
   KeyboardCont = i;
   OutputKeyboard();
   }
}


So far so good, Next I want to actually update the respective ports to
reflect the count like so:
//----------------------------------------------------------------
void OutputKeyboard(void)
{
LATE.LATE0 = KeyboardCont[0];
LATE.LATE1 = KeyboardCont[1];
LATE.LATE2 = KeyboardCont[2];
LATA.LATA5 = KeyboardCont[3];
}
Notice the different ports.


This is the bit that wont work, I get the following errors:
C:\Data\PIC\PIC_C\Modbus1\main.c:432:Error [1151] struct or union object
designator expected
C:\Data\PIC\PIC_C\Modbus1\main.c:432:Error [1129] [] operator requires a
pointer and an integer as operands
C:\Data\PIC\PIC_C\Modbus1\main.c:433:Error [1151] struct or union object
designator expected
C:\Data\PIC\PIC_C\Modbus1\main.c:433:Error [1129] [] operator requires a
pointer and an integer as operands
C:\Data\PIC\PIC_C\Modbus1\main.c:434:Error [1151] struct or union object
designator expected
C:\Data\PIC\PIC_C\Modbus1\main.c:434:Error [1129] [] operator requires a
pointer and an integer as operands
C:\Data\PIC\PIC_C\Modbus1\main.c:435:Error [1151] struct or union object
designator expected
C:\Data\PIC\PIC_C\Modbus1\main.c:435:Error [1129] [] operator requires a
pointer and an integer as operands

If I try to LATE.LATE0 = 1; I also get an error, I understand that 1 is
not a bit but how do you set a bit?

I have spent a lot of time looking and I expect the answer is so easy
that its not documented :)
Is it possible to define the KeyboardCont as the pins directly so that I
don't need a working register?

thanks for reading

Lee McLaren




2005\11\20@212720 by Simon Dyer

picon face
unsigned char KeyboardCont

is a single byte yet you are dereferencing an array using these
commands.

LATE.LATE0 = KeyboardCont[0];
LATE.LATE1 = KeyboardCont[1];
LATE.LATE2 = KeyboardCont[2];
LATA.LATA5 = KeyboardCont[3];

More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...