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

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: 120

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: 19520

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: 1349

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: 19520

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.
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Wed Jul 17, 2024 1:42 am     Reply with quote

Thanx both!
I like the below option! Diidn't know that is also possible.
#bit TMR0EN = getenv("BIT:T0CON0.EN")
_________________
Regards, Edwin. PCWHD v5.114
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Mon Jul 22, 2024 1:52 am     Reply with quote

Mmm, too handy to be true?
For compiler 5114:
Code:
#bit TMR0EN = getenv("BIT:T0CON0.EN")

raises a compiler error: Expecting an identifier Bad SFR name

Tried some other variartion I could think of. Like:
Code:
#bit  TMR0EN = getenv("BIT:T0CON0:EN")
#bit  TMR0EN = getenv("SFR:T0CON0.EN")
#bit  TMR0EN = getenv("SFR:T0CON0.BIT:EN")
#bit  TMR0EN = getenv("SFR:T0CON0,BIT:EN")
#bit  TMR0EN = getenv("SFR:T0CON0:BIT:EN")
#bit  TMR0EN = getenv("SFR:T0CON0 BIT:EN")

Nada..
Only one that works for 5114 is:
Code:
#bit  TMR0EN = getenv("SFR:T0CON0").7

_________________
Regards, Edwin. PCWHD v5.114
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Mon Jul 22, 2024 9:19 am     Reply with quote

Torello wrote:
Mmm, too handy to be true?
For compiler 5114:
Code:
#bit TMR0EN = getenv("BIT:T0CON0.EN")

raises a compiler error: Expecting an identifier Bad SFR name

Tried some other variartion I could think of. Like:
Code:
#bit  TMR0EN = getenv("BIT:T0CON0:EN")
#bit  TMR0EN = getenv("SFR:T0CON0.EN")
#bit  TMR0EN = getenv("SFR:T0CON0.BIT:EN")
#bit  TMR0EN = getenv("SFR:T0CON0,BIT:EN")
#bit  TMR0EN = getenv("SFR:T0CON0:BIT:EN")
#bit  TMR0EN = getenv("SFR:T0CON0 BIT:EN")

Nada..
Only one that works for 5114 is:
Code:
#bit  TMR0EN = getenv("SFR:T0CON0").7


Which chip is it? I know the format of the command works (I am looking at it in my code right now). But perhaps the chip database has a bug in it?

Sorry if you mentioned it before, but didn't see it, which micro are you using?

EDIT2: Try this:
Code:

#bit TMR1EN = getenv("BIT:T0CON0.T0EN")


I just looked up a few pic16 and pick18's and noticed they had duplicate entries for T0CON0 in their database. When they did then .EN didn't work but .T0EN did. Maybe your chip is similar.

See image at the bottom of the post.

EDIT1:
Here is an example that compiles for me in 5.113. It's a different chip, but just so you can see it for yourself.
Code:

#case

#include <24FJ1024GB610.h>

#bit TMR1EN = getenv("BIT:T1CON.TON")

void main(){
 
}


I can try your chip out if you see this in the next few hours (out for 2 weeks after that)

Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Tue Jul 23, 2024 9:11 am     Reply with quote

Yes.
The system is a bit 'odd' here. If you look a couple of lines below, it has the
EN syntax also shown. You''d rather expect it to accept this when you
access a bit in an already named register, but require the T0EN syntax
to access the bit "on it's own", but in fact it seems to work the other way
round. Does seem to be a database fault here really!.
Anyway, that is why the poster was having problems. Very Happy
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Wed Jul 31, 2024 8:07 am     Reply with quote

Hi Jeremiah, Ttlemah,

The part is PIC18F26Q83 and with the Device Table Editor indeed the bit seems to be referenced as T0EN

So
Code:
#bit TMR0EN = getenv("BIT:T0CON0.T0EN")

Now works. Thanks!

So about the Device Table Editor; I see 3 lines for T0CON0. same address, same name but different bit assingments.

Crying or Very sad <sorry, I don't get it done to add a picture.. >

I more a less understand lines 2 and 3. 2 beeing the datasheet naming and 3 the compiler.
But then what is line 1?
_________________
Regards, Edwin. PCWHD v5.114
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Aug 01, 2024 3:00 am     Reply with quote

The multiple lines are just alternative names that can be used. However
the 'bit' selection version only works on the first line in each case.
It makes sense when you look at T1CON0 instead. It only has the first
line, which avoids 'EN' existing for the second timer.
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