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

Easiest way to recombine a 16 bit binary value

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lsudigitalguy
Guest







Easiest way to recombine a 16 bit binary value
PostPosted: Wed Oct 01, 2008 3:34 pm     Reply with quote

Hello,

I am using a PIC16C65. I have a 16 bit binary value coming into the chip through two 8 bit ports. I was wondering on the easiest way to recombine the two 8 bit values into a 16 bit value.


EX: value = A55Ah

port 1 = A5h;
port 2 = 5Ah;

variable = A55Ah
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Oct 01, 2008 3:50 pm     Reply with quote

Use make16(), a union or shift/AND operations.

Make16 example:
Code:
int16 MyVar;

MyVar = make16( input_A(), input_B() );


For a description of the difference between the three methods and a union example see Ttelmah's post in http://www.ccsinfo.com/forum/viewtopic.php?t=30416
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Oct 01, 2008 4:53 pm     Reply with quote

or you may not have to do anything, if there on consecutive ports and in the right order.
Code:
#define FIRM_MAJOR 'C'
#define FIRM_MINOR  05
#define HARD_MAJOR  3
#define HARD_MINOR  03
#include <18F4525.h>
#use delay(clock=10000000, restart_wdt)
#fuses hs,nowdt,noprotect,nolvp,put
#use rs232(baud=19200,xmit=PIN_C0,invert,stream=DEBUG) // stderr(same as debug)
#use rs232(baud=19200,enable=PIN_C5,xmit=PIN_C6,rcv=PIN_C7,stream=CIM)  // rs485 is the default
#case
#zero_ram

int16 my_int16;
#byte my_int16  = 0xF80 //note: no semicolin    0xF80= port A0 on a 18F4525
//                        sencond byte comes from 0xF81 which is port B on a 18F4525

//=== MAIN ===//
void main(void)
{
  setup_adc_ports(NO_ANALOGS);
  setup_adc(ADC_OFF);
  set_tris_a(0xFF);set_tris_e(0xFF);set_tris_c(0xFF);
  set_tris_b(0xFF);set_tris_d(0xFF);port_b_pullups(TRUE);

  fprintf(DEBUG,"%lu\n\r",my_int16);

  while(1)
  {
  }
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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