CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 18060

View user's profile Send private message

PostPosted: Tue Mar 01, 2022 7:18 am     Reply with quote

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: 214

View user's profile Send private message

PostPosted: Tue Mar 01, 2022 9:02 am     Reply with quote

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: 18060

View user's profile Send private message

PostPosted: Tue Mar 01, 2022 11:30 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 02, 2022 1:05 am     Reply with quote

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:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group