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

combined register reading

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



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

combined register reading
PostPosted: Fri Mar 18, 2005 7:45 am     Reply with quote

In microchip, there are a lot of pairs of registers, like (TIMER1H,TIMER1L),(TIMER0H,TIMER0L), (CCPR1H,CCPR1L), we could put high byte and low byte together like the following tow methods, right?

//this is for 18f458
#BYTE timer1h 0xFD7h
#BYTE timer1l 0xFD6h
int16 time1
timer1=timer1h<<8+timer1l;

or
union timer1{int16 t1, int8 t1[2]} T1D

T1D.t1[0]=timer1l;
T1D.t1[1]=timer1h;

timer1=T1D.t1;

right?


timer1 T1
valemike
Guest







PostPosted: Fri Mar 18, 2005 8:05 am     Reply with quote

not sure about the union stuff, but i always read a Timer using CCS libraries and 'unsigned long'.

e.g.
unsigned long timer_value;
timer_value = get_timer1();
Ttelmah
Guest







PostPosted: Fri Mar 18, 2005 11:02 am     Reply with quote

You can add:

int16 timer;
#BYTE timer=0xwhatever_you_want.

Then reading/writing 'timer', will access the whole 16bit value.
'#BYTE', locates a variable at a location, and if it does not exist, creates an int8. However if the variable already exixts of a larger type, it locates the whole larger variable at the location, and subsequent addresses. It is another useful shortcut. :-)
This is what you are seeing in the libraries with the 'unsigned long'.

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Mar 18, 2005 12:44 pm     Reply with quote

use #locate instead of #byte.
Felix Althaus



Joined: 09 Sep 2003
Posts: 67
Location: Winterthur, Switzerland

View user's profile Send private message

PostPosted: Fri Mar 18, 2005 1:09 pm     Reply with quote

Hello

It's not exactly the same as orginally asked, but something similar:

What should I do, if the two bytes of a long aren't in consecutive oder. For example I want to do this:

long any_var;

any_var = counter;

counter is a long with low byte at 0xXY and high byte at 0xAB

How can I do this without #locate (I have 2.734). It seem's I can't get the trick...


Thanks
Felix
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Mar 18, 2005 8:06 pm     Reply with quote

If a variable is a long or 16bits then it must be consecutive. I said must be.
bluetooth



Joined: 08 Jan 2005
Posts: 74

View user's profile Send private message

PostPosted: Fri Mar 18, 2005 8:14 pm     Reply with quote

Without asking why the bytes wouldn't be next to each other, I suggest you take a look at the CCS function make16() - you can build it up that way with the high and low bytes any where you want them....
Ttelmah
Guest







PostPosted: Sat Mar 19, 2005 3:18 am     Reply with quote

Mark wrote:
use #locate instead of #byte.

It depends what you are doing.
#locate, prevents C from using the area. Otherwise the two functions behave identically. For an area in the main data memory, #locate would be 'choice', but I'd not want to risk what might happen if you block C from using variables in the register area. Hopefully the compiler is 'smart' enough to ignore this, but I'd really say that #byte is the 'right' command to use in this case...

Best Wishes
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