CAN ID receive issue in PIC18F46K80
i Am working on J1939 Project where i am getting extended ID(Length is 6 byte - for ex: 14FF4431) from CAN but where i am receiving to my controler i don't wanted first 2 bytes and last 2 bytes, i required center 4 bytes(FF44).
i am using Mikroc Library & PIC46k80 Controller.
my CAN ID is "long" in data type.
Please help me to solve
-- Expecting answer in C language/Embedded C
- Thanks in advance!
Hi,
14FF4431 ....
* if HEX, then this are 4 bytes
* if ASCII, then this us 8 bytes
I don't see 6 bytes
FF44 ... as HEX are just 2 bytes.
Klaus
Yeah, i mean its in HEX. Ya its 4 Bytes.
I want to remove first byte(14) and Last byte (31).
How its is possible ?
Please help me out.
This is working in C:
#include <stdio.h>
int main()
{
long Rx_ID = 0x14FF4431;
long Rx_ID1,Rx_ID2;
Rx_ID2 = ((Rx_ID>>8)&0xFF);
Rx_ID1 = ((Rx_ID>>16)&0xFF);
Rx_ID = (Rx_ID1<<8)|(Rx_ID2);
printf("%x",Rx_ID);
return 0;
}
Output:
FF44
But, When i am using in mikroC i am not getting correct value, see below
converting long to string, to check data at UART:
Rx_ID2 = ((Rx_ID>>8)&0xFF);
Rx_ID1 = ((Rx_ID>>16)&0xFF);
Rx_ID = (Rx_ID1<<8)|(Rx_ID2);
LongToStr(Rx_ID, Ch_Rx_ID);
UART1_Write_Text(Ch_Rx_ID);
Hi,
Pseudo code:
long Rx_ID = 0x14FF4431;
Rx_ID = ((Rx_ID AND 0x00FFFF00) >>8)
Result should be 0xFF44
Klaus