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

getenv("BIT:EN")

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



Joined: 29 Sep 2006
Posts: 115

View user's profile Send private message

getenv("BIT:EN")
PostPosted: Wed Jun 19, 2024 7:47 am     Reply with quote

Hi,

The bit-name "EN" can be found in a lot of SFR

So if I declare: #bit TMR0EN = getenv("BIT:EN") . And the complier does complie this, which "EN" has been assigned?

And there are much more of these common names. like GO, ON ...

Workaround would be:
#bit TMR0EN = getenv("SFR:T0CON0").7

But the "7" could be completely wrong for an other PIC.

What is the best option for portability?
_________________
Regards, Edwin. PCWHD v5.114
Ttelmah



Joined: 11 Mar 2010
Posts: 19326

View user's profile Send private message

PostPosted: Wed Jun 19, 2024 10:11 am     Reply with quote

I think you have already answered yourself. Using the names is the more
portable method. Also reduces chances of errors.
jeremiah



Joined: 20 Jul 2010
Posts: 1321

View user's profile Send private message

Re: getenv("BIT:EN")
PostPosted: Mon Jun 24, 2024 7:30 am     Reply with quote

Torello wrote:
Hi,

The bit-name "EN" can be found in a lot of SFR

So if I declare: #bit TMR0EN = getenv("BIT:EN") . And the complier does complie this, which "EN" has been assigned?

And there are much more of these common names. like GO, ON ...

Workaround would be:
#bit TMR0EN = getenv("SFR:T0CON0").7

But the "7" could be completely wrong for an other PIC.

What is the best option for portability?


My preferred method in this case is to use the "." within the name:
EX:
Code:

#bit U2_TXEN  = getenv("BIT:U2STA.UTXEN")


So your example would be:
Code:

#bit  TMR0EN = getenv("BIT:T0CON0.EN")

Assuming all the names are correct.

I find this the most useful way as it would give a compiler error if either the register or the bit were named wrong or if the chip database for that micro has a bad name in it.


Last edited by jeremiah on Mon Jun 24, 2024 8:01 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19326

View user's profile Send private message

PostPosted: Mon Jun 24, 2024 7:33 am     Reply with quote

Yes, and this makes it much easier to distinguish the bits on multiple
peripherals (UART1, IART2 etc..).

Much preferred.
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