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

18F4455 Timer0 read/write TMR0H

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



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

18F4455 Timer0 read/write TMR0H
PostPosted: Sat Mar 01, 2008 1:30 pm     Reply with quote

Hello everybody,
I'm trying to use the timer0 of a 18F4455.

I would like to write and read the TMR0H register.
I have read in the datasheet that to write in TMR0H, I have to put the value in TMR0H buffer and write TMR0L which will push the TMR0H buffer value into the real TMR0H regiter.
And same idea to read it.

I think it's what I'm doing with this code:
Code:
volatile int8    TMR0L;
volatile int8    TMR0H;
volatile int16    TMR0;

#pragma    locate TMR0L     = 0x0FD6 //@0x0FD6
#pragma    locate TMR0H     = 0x0FD7 //@0x0FD7
#pragma    locate TMR0    = 0x0FD6 //@0x0FD6


unsigned int16 TEST_TMR0 = 0;
unsigned int TEST_TMR0L = 0;
unsigned int TEST_TMR0H = 0;
   
T0CON.TMR0ON = 0;
T0CON.T08BIT = T08BIT_16BIT;
   
TMR0H = 0x56;
TMR0L = 0x12;

TEST_TMR0L = TMR0L;
TEST_TMR0H = TMR0H;
TEST_TMR0 = TMR0;


The results are:
TEST_TMR0L = 0x12, at least this one is good.
TEST_TMR0H = 0x00 instead of 0x56.
TEST_TMR0 = 0x0012 instead of 0x5612.

Do you have an idea about what am I doing wrong?

Thanks for any comments,
Franck.
Ttelmah
Guest







PostPosted: Sat Mar 01, 2008 4:06 pm     Reply with quote

Why not just use the #byte directive, which is designed for this?.
#locate, is 'dangerous', since it blocks the CCS C from using the location itself. It is designed for _you_ to locate values into memory that _you_ control, not to access registers that C itself may need to access.
It is not working, in a different way, to what I'd expect, but remember that #locate, is _exclusive_, and will block other variables from using the same area...

Code:

#byte TMR0L=0xFD6
#byte TMR0H=0xFD7
int16    TMR0; //The 'volatile' keyword, is pointless
#byte TMR0=0xFD6

unsigned int16 TEST_TMR0 = 0;
unsigned int TEST_TMR0L = 0;
unsigned int TEST_TMR0H = 0;
   
T0CON.TMR0ON = 0;
T0CON.T08BIT = T08BIT_16BIT;
   
TMR0H = 0x56;
TMR0L = 0x12;

TEST_TMR0L = TMR0L;
TEST_TMR0H = TMR0H;
TEST_TMR0 = TMR0;


Best Wishes
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Sun Mar 02, 2008 2:57 am     Reply with quote

Hello Ttelmah,
Thanks for the answer.

I was using #locate to keep a minimum of compatibility with other compilers.
I will try #byte tomorrow (I don't have the target during the weekend), I'm not sure it will change something for this problem, but if it's better...

In fact the volatile keyword was in another file, I forgot to remove it when I put all the code in the same file to make an example Embarassed .

Franck.
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Mon Mar 03, 2008 3:07 am     Reply with quote

Hello,
I found the problem in my code:
I made a mistake on the define of T08BIT_16BIT which configure the timer as 8 bits or 16 bits Embarassed .

T08BIT_16BIT have to be 0 to configure a 16 bits timer, which was not the case in my code.

With T0CON.T08BIT = 0 it's working fine.

Thanks for your help.
Franck.
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