View previous topic :: View next topic |
Author |
Message |
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
how to access registers? |
Posted: Tue Oct 23, 2012 12:22 am |
|
|
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 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Tue Oct 23, 2012 1:23 am |
|
|
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
|
|
Posted: Tue Oct 23, 2012 10:40 am |
|
|
thank you |
|
|
|