Techtone
Newbie level 4
- Joined
- May 25, 2010
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- South East England
- Activity points
- 1,359
Hi,
I am using Microchips C18 on a P18F2455.
I am having trouble getting the Least Significant Byte and Most Significant Byte values from and Int variable.
I am trying to logical AND the Int value with 0xFF to get the LSB. For the MSB I am trying to shift right 8 bits.
I guess I would rather directly access the bytes used by C18 to store the Int variable!
I am new to C18 and have always worked in assembly language in the past.
Any suggestion would be greatly appreciated.
Here is the code that is giving me grief:
void writeIntEE(unsigned char address, int data)
{
//LSB
EEADR =(address);
EEDATA = (data && 0xFF); //LSB
//Configuration as per manual
EECON1bits.EEPGD =0;
EECON1bits.CFGS =0;
EECON1bits.WREN =1;
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1;
INTCONbits.GIE = 1;
EECON1bits.WREN = 0;
while (EECON1bits.WR)
{
}
//MSB
EEADR =(address+1);
EEDATA =(data >> 8); //MSB
//Configuration as per manual
EECON1bits.EEPGD =0;
EECON1bits.CFGS =0;
EECON1bits.WREN =1;
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1;
INTCONbits.GIE = 1;
EECON1bits.WREN = 0;
while (EECON1bits.WR)
{
}
}
Thanks
Tony
I am using Microchips C18 on a P18F2455.
I am having trouble getting the Least Significant Byte and Most Significant Byte values from and Int variable.
I am trying to logical AND the Int value with 0xFF to get the LSB. For the MSB I am trying to shift right 8 bits.
I guess I would rather directly access the bytes used by C18 to store the Int variable!
I am new to C18 and have always worked in assembly language in the past.
Any suggestion would be greatly appreciated.
Here is the code that is giving me grief:
void writeIntEE(unsigned char address, int data)
{
//LSB
EEADR =(address);
EEDATA = (data && 0xFF); //LSB
//Configuration as per manual
EECON1bits.EEPGD =0;
EECON1bits.CFGS =0;
EECON1bits.WREN =1;
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1;
INTCONbits.GIE = 1;
EECON1bits.WREN = 0;
while (EECON1bits.WR)
{
}
//MSB
EEADR =(address+1);
EEDATA =(data >> 8); //MSB
//Configuration as per manual
EECON1bits.EEPGD =0;
EECON1bits.CFGS =0;
EECON1bits.WREN =1;
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1;
INTCONbits.GIE = 1;
EECON1bits.WREN = 0;
while (EECON1bits.WR)
{
}
}
Thanks
Tony