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

CCPR1 Register

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



Joined: 06 Nov 2011
Posts: 13

View user's profile Send private message

CCPR1 Register
PostPosted: Wed Nov 09, 2011 11:45 am     Reply with quote

Hello I need a piece of code in "C" to put a value in CCPR1 Register (16Bit).

CCPR1 correspond to

CCPR1L Capture/Compare/PWM Register 1 Low Byte (LSB)
CCPR1H Capture/Compare/PWM Register 1 High Byte (MSB)

which address is

CCPR1L 13h
CCPR1H 14h

More generally how to properly declare a 16bit register in order to use it in a program. Same question for an 8bit register. An example with the 16bit register CCPR1.

Thank you for your response.
Ttelmah



Joined: 11 Mar 2010
Posts: 19439

View user's profile Send private message

PostPosted: Wed Nov 09, 2011 4:14 pm     Reply with quote

Code:

#BYTE CCPR1L=getenv("sfr:CCPR1L")
#BYTE CCPR1H=getenv("sfr:CCPR1H")
#WORD CCPR1=CCPR1L


The 'getenv' function, returns the address of a register on the chip you are compiling for (if it exists). Makes code portable if you change chips latter....

#BYTE, locates an 8bit register (or another type - more later), at a location.
#WORD locates a 16bit register at a location.

However you can also use:
Code:

#BYTE CCPR1L=getenv("sfr:CCPR1L")
#BYTE CCPR1H=getenv("sfr:CCPR1H")
int16 CCPR1;
#BYTE CCPR1=CCPR1L


Which generates an int16 register, and then locates it at the specified location with #byte. Key thing here is that you can put any register type at a location this way (int32, float etc.....).

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 09, 2011 4:18 pm     Reply with quote

Look in the .h file for your PIC. (You didn't give your PIC).
CCS already has a definition for the 16-bit CCP register in the .h file.
You can load it with a line of code, as shown below:
Code:

#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)

//======================================
void main(void)
{

CCP_1 = 0x1234;

while(1);
}


Then to see what the compiler is doing, set the List file format to Symbolic
and re-compile. Then look at the .LST file:
Code:

.................... CCP_1 = 0x1234;
0014:  MOVLW  12
0016:  MOVWF  CCPR1H
0018:  MOVLW  34
001A:  MOVWF  CCPR1L


The definitions for the 8-bit "L" and "H" registers of the CCP are also in
the .h file for your PIC. You can see how to declare registers by looking
at these examples in the .h file.

Also, if you have the CCS IDE version of the CCS compiler, then you
can make a .h file with all the register definitions already done.
See this thread for instructions:
http://www.ccsinfo.com/forum/viewtopic.php?t=40862

Edit: I see that Ttelmah and I were typing in an answer at the same time.
He beat me, but I'll leave my post up anyway.
Ttelmah



Joined: 11 Mar 2010
Posts: 19439

View user's profile Send private message

PostPosted: Wed Nov 09, 2011 4:29 pm     Reply with quote

I forgot to point to the standard defines, so the posts complement one another rather nicely. Smile

Best Wishes
octopuss83



Joined: 06 Nov 2011
Posts: 13

View user's profile Send private message

PostPosted: Thu Nov 10, 2011 6:07 am     Reply with quote

woow , great . .... it's works fine and it's very clean code

Thanks all

Very Happy
_________________
______________________

-- Octopuss ---
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