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 CCS Technical Support

how to access registers?

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



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

how to access registers?
PostPosted: Tue Oct 23, 2012 12:22 am     Reply with quote

I've looked lot of examples in this forum about how to access registers directly. But couldn't find the good solution. For example, if i want to access individual bits of T0CON register, how to do that?

I'm using PIC 18f2520.

#byte T0CON = 0xD5 // timer0 address

How to access individual bits of that register?

I found by defining #bit can do this. But I want to send data as like
(example : 0b11011000). Is there any command to send data like this to register?

Can anybody help me.

Thanks in advance Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Tue Oct 23, 2012 1:23 am     Reply with quote

Er. Remember _all_ values are binary inside the chip.
Also, your address is wrong. 0xD5, is the address for T0CON, on a PIC16, _not_ a PIC18.
Let the compiler do the work for you.
Code:

#byte T0CON=("SFR:T0CON") //automatically loads the correct address
//0xFD5
#bit TMR0ON=("BIT:TMR0ON") //better way to access the bits by name

T0CON=0b11011000;
//This will directly load the binary value into the register
T0CON=216;
//Does exactly the same. The chip _works_ only with binary values.
//The compiler turns 216, into 0b11011000

//Or you can change a bit with
TMR0ON=FALSE;

bit_clear(T0CON,7);
//Both will clear the top bit without changing anything else

//However in general CCS supplies functions to do everything to registers
setup_timer_0(T0_INTERNAL | T0_8_BIT | T0_DIV_1);

//Gives what you are trying to do (T0SE, does nothing when internal is
//selected).


Best Wishes
hemnath



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

PostPosted: Tue Oct 23, 2012 10:40 am     Reply with quote

thank you Smile
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