CCS does not monitor this forum on a regular basis. Please do not post bug Reports on this forum. Send them to support@ccsinfo.com
 Pic to pic UART data Transfer Goto page Previous  1, 2
Author Message
Ttelmah

Joined: 11 Mar 2010
Posts: 18225

Posted: Tue Mar 01, 2022 7:18 am

Combining nibbles into bytes is easy:
 Code: int8 A;    int8 B;    int8 combined;    A=something;    B=something_else;    combined = (A*0xF) &((B &0xF) << 4);    //Then to extract values    A=combined & 0xF;    B=(combined>>4) & 0xF;

As written, this combines two numbers and extracts these back, also making
sure any 'extra' bits are thrown away.
gaugeguy

Joined: 05 Apr 2011
Posts: 216

 Posted: Tue Mar 01, 2022 9:02 am Shouldn't that be : combined = (A*0xF) | ((B &0xF) << 4); It seems that 0x0F & 0xF0 would result in 0 but I might be missing something.
Ttelmah

Joined: 11 Mar 2010
Posts: 18225

 Posted: Tue Mar 01, 2022 11:30 am No. It should be: combined = (A & 0xF) | ((B & 0xF) << 4); Two typing errors, you only spotted one.... A & 0xF gives the low 4 bits of A. Then B & 0F gives the low 4 bits of B These are then rotated left 4 times. On the PIC 16 & 18, you can actually use: combined = (A&0xF) | swap(B &0xF); This uses the internal swap instruction that swaps the high and low nibbles in a single instruction, while the rotation takes four instructions. This doesn't exist on the DsPIC's.
CaptainOnedin

Joined: 27 Feb 2022
Posts: 7
Location: All over the world

 Posted: Wed Mar 02, 2022 1:05 am Thanks alot you guys all! Finally i figured out it. There is only one thing waiting to solve. Why IOC doesn't trigger with UART signal? I'll try all pins for it when i free. I'm grateful to you guys.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT - 6 HoursGoto page Previous  1, 2 Page 2 of 2

 Jump to: Select a forum Software----------------General CCS C DiscussionCode LibraryEZ App LynxBest OfKnown Issues Hardware----------------CCS ICD / Mach X / Load-n-Go
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