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.

how to get capture result into a single variable..

Status
Not open for further replies.

sarathsnairpoonjar

Member level 2
Joined
Nov 12, 2012
Messages
50
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Cochin,Kerala,India
Activity points
1,560
i am using below equation to combine CCP result registers
var=(CCPR1H<<8)+CCPR1L

But the value in var is not always correct,let me say..
i am viewing CCPR1H , CCPR1Land var separately in an Lcd ...
when
CCPR1H=1 and CCPR1L=205 var contains 205
when
CCPR1H=2 and CCPR1L=57 var contains 569
in the second case above equation seems to be fine ,then why it is not working when the msb is 1,
anybody have a solution?, please help me...
 

I have no idea why it works in one case and not the other but if CCPR1H is an 8bit value then you should typecast it to 16bit before you shift it

Code:
var=((unsigned int)CCPR1H<<8)+CCPR1L

Or (since var is a 16bit type)
Code:
var=CCPR1H;
var=(var<<8)+CCPR1L;
 

The second case gives correct value, so the first one should too. It seems in the first case CCPR1H is actually 0 instead of 1.

Try breaking it into steps:
Code:
unsigned int varH;
unsigned char varL;
varH = CCPR1H;
varL = CCPR1L;
varH = varH << 8;
var = varH | varL;
//or:    var = varH + varL;

If you still face a problem, please upload your code.

Hope this helps.
Tahmid.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top