View previous topic :: View next topic |
Author |
Message |
Torello
Joined: 29 Sep 2006 Posts: 115
|
getenv("BIT:EN") |
Posted: Wed Jun 19, 2024 7:47 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19326
|
|
Posted: Wed Jun 19, 2024 10:11 am |
|
|
I think you have already answered yourself. Using the names is the more
portable method. Also reduces chances of errors. |
|
![](templates/subSilver/images/spacer.gif) |
jeremiah
Joined: 20 Jul 2010 Posts: 1321
|
Re: getenv("BIT:EN") |
Posted: Mon Jun 24, 2024 7:30 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19326
|
|
Posted: Mon Jun 24, 2024 7:33 am |
|
|
Yes, and this makes it much easier to distinguish the bits on multiple
peripherals (UART1, IART2 etc..).
Much preferred. |
|
![](templates/subSilver/images/spacer.gif) |
|