Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Help me perform concatenation operation!

Status
Not open for further replies.

electronics_guy

Member level 2
Joined
Apr 12, 2012
Messages
49
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,655
Hi all, I am new to programming and I need some help in performing the concatenation operation in C. I am trying to write a code for ADC of PIC16F877A microcontroller. Here after the completion of the conversion, the 10 bit result is stored in two registers(ADRESL and ADRESH). I want to read and store the result in one single variable and I suppose that is possible only by concatenation operation. Plz, someone explain me the code so that I can do it or if there is some other logic, please post it.



Thanks in advance.
 

hi pic16f877a has 10 bit adc channel.u can select ADCON0,ADCON1 for operate adc result store location registers ADRESL and ADRESH.
use this
data=ADRESH;
data=data<<8; //shift to left for 8 bit
data=data|ADRESL; //10 bit result from ADC
hope this helpful
with regards
 

Thanks suvaraj and btbass. But PIC16F877A is a 8-bit microcontroller, how is it possible to store the 10 bit ADC result in to a single variable of type 'int", I mean the size of int is 8 bits, so how can I store the 10 bit result?!
plz help


Thanks in advance.
 

It doesn't matter if you have a 8bit mcu , there are several types of variables for 8,16,32, and even 64bit in some cases.
Normally a integer is a 16bit variable but you should check the manual of your compiler or sometimes there is a setting in the compiler settings, which one are you using?

Alex
 
Alex, I am using MPLab version v8.30 and HI Tech C compiler....
 

In Hi-Tech an unsigned char or char is an 8 bit type,
An unsigned int or int is a 16 bit type.
Read the compiler user guide to get the types used by the compiler.
 
It helps if you use a header file that type defines the sizes.
Then it is much easier to see what is being used.
This is the file I use with Hi-Tech compiler.
Save this file as 'PosixTypes.h' and include it in your c file.


Code:
/*--------------------------------------------------------------------
  File Name     : PosixTypes.h 
  Description   : ISO (Posix) typedef file for Pic
                : Misra Rule 6.3 (advisory)                      

  Revision      : 1.0 
  Date          : 21/08/05 
  
----------------------------------------------------------------------*/  

#ifndef POSIXTYPES_H
#define POSIXTYPES_H
            
/*--- Standard type definitions. ---*/

/* Plain char, only to be used for the storage and 
use of character values. Misra Rule 6.1 (Required) */

typedef unsigned char   uint8_t;    /* unsigned 8 bit type definition */
typedef signed char     int8_t;     /* signed 8 bit type definition */
typedef unsigned int    uint16_t;   /* unsigned 16 bit type definition */
typedef signed int      int16_t;    /* signed 16 bit type definition */
typedef unsigned long   uint32_t;   /* unsigned 32 bit type definition */
typedef signed long     int32_t;    /* signed 32 bit type definition */
typedef unsigned char   Bool;       /* Bool type definition */

/*--- Standard constant definition. ---*/

#define False ((Bool)0x00U)
#define True  ((Bool)0x01U)

#endif

/*--- End of file. ---*/


You can also get MPLAB to syntax highlight these types.

If you save the words to be highlighted in a text file, say ‘keywords.txt’

uint8_t
int8_t
uint16_t
int16_t
uint32_t
int32_t
Bool
True
False

If you right click in one of your source files in the IDE and choose ‘Properties’, or choose ‘Edit’ from the menu
and ‘Properties’ then click on the ‘Text’ tab. In the ‘Choose Colors’ there is an option for
‘User File Defined.’ Here you can select the color for your highlighting, exit that then
use the browse button to select your ‘User Defined Color File’, and click ‘Apply’
This will turn on highlighting for all the words listed in your ‘keywords.txt’ file.
 
Last edited:
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top