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

EEPROM detection

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







EEPROM detection
PostPosted: Wed Nov 20, 2002 3:48 am     Reply with quote

How can I determine if a device has internal EEPROM within the preproccessor commands. I need to do a conditional compilation dependant on internal eeprom availability
___________________________
This message was ported from CCS's old forum
Original Post ID: 9133
R.J.Hamlett
Guest







Re: EEPROM detection
PostPosted: Wed Nov 20, 2002 5:10 am     Reply with quote

:=How can I determine if a device has internal EEPROM within the preproccessor commands. I need to do a conditional compilation dependant on internal eeprom availability

Why not just use the device numbers?.
Hence:

#if __device__==673 || __device==674
#define EEPROM_PRESENT
#endif

Then in the code:
#ifdef EEPROM_PRESENT
//Here the chip has an eeprom

#endif

Obviously you'd have to pick the chipnumbers to suit, mine are for the 12C67x family.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9135
DuncanH
Guest







Re: EEPROM detection
PostPosted: Wed Nov 20, 2002 6:12 am     Reply with quote

:=:=How can I determine if a device has internal EEPROM within the preproccessor commands. I need to do a conditional compilation dependant on internal eeprom availability
:=
:=Why not just use the device numbers?.
:=Hence:
:=
:=#if __device__==673 || __device==674
:=#define EEPROM_PRESENT
:=#endif
:=
:=Then in the code:
:=#ifdef EEPROM_PRESENT
:= //Here the chip has an eeprom
:=
:=#endif
:=
:=Obviously you'd have to pick the chipnumbers to suit, mine are for the 12C67x family.
:=
:=Best Wishes


Can't do this as the 18c452 and 18f452 both have the same device number but one has eeprom and the other doesn't
___________________________
This message was ported from CCS's old forum
Original Post ID: 9136
R.J.Hamlett
Guest







Re: EEPROM detection
PostPosted: Wed Nov 20, 2002 7:04 am     Reply with quote

:=:=:=How can I determine if a device has internal EEPROM within the preproccessor commands. I need to do a conditional compilation dependant on internal eeprom availability
:=:=
:=:=Why not just use the device numbers?.
:=:=Hence:
:=:=
:=:=#if __device__==673 || __device==674
:=:=#define EEPROM_PRESENT
:=:=#endif
:=:=
:=:=Then in the code:
:=:=#ifdef EEPROM_PRESENT
:=:= //Here the chip has an eeprom
:=:=
:=:=#endif
:=:=
:=:=Obviously you'd have to pick the chipnumbers to suit, mine are for the 12C67x family.
:=:=
:=:=Best Wishes
:=
:=
:=Can't do this as the 18c452 and 18f452 both have the same device number but one has eeprom and the other doesn't

Check for the presence of the 'INT_EEPROM' variable. On these more sophisticated chips, this is defined if this interrupt exists. So:

#ifdef INT_EEPROM
//Here the chip has an EEPROM

#else
//Here the chip does not.

#endif

It is actually easier on these chips, than on the simpler ones. :-)

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9137
Woody
Guest







Re: EEPROM detection
PostPosted: Wed Nov 20, 2002 7:27 am     Reply with quote

Another possibility may be to use the built in function getenv() to retrieve the EEPROM size at compile time.

#include <16c452.h>

#define EEPROM_PRESENT (getenv("DATA_EEPROM") > 0)

void main (void)
{
if (EEPROM_PRESENT) {
;
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 9142
Felix Althaus



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

View user's profile Send private message

Re: EEPROM detection getenv?
PostPosted: Wed Nov 20, 2002 1:00 pm     Reply with quote

:=#define EEPROM_PRESENT (getenv("DATA_EEPROM") > 0)

This getenv() interests me. Are there more env variables? If yes is there a documentation? Is the getenv limited to a certain compiler version?

Thanks
Felix
___________________________
This message was ported from CCS's old forum
Original Post ID: 9167
R.J.Hamlett
Guest







Re: EEPROM detection getenv?
PostPosted: Wed Nov 20, 2002 3:22 pm     Reply with quote

:=
:=:=#define EEPROM_PRESENT (getenv("DATA_EEPROM") > 0)
:=
:=This getenv() interests me. Are there more env variables? If yes is there a documentation? Is the getenv limited to a certain compiler version?
:=
:=Thanks
Yes.
It is relatively new, and the documentation doesn't exist in the 'help' file, but in the 'readme', for the last few versions. Typically I had forgotten it in suggesting using the INT_EEPROM variable.
This is copied from the readme:


The built in function getenv() has been added. The syntax is
value = getenv(cstring);
cstring is a constant string with a recognised keyword
as follows:
FUSE_SET:fffff Returns 1 if fuse fffff is enabled
FUSE_VALID:fffff Returns 1 if fuse fffff is valid
INT:iiiii Returns 1 if the interrupt iiiii is valid
ID Returns the device ID (set by #ID)
DEVICE Returns the device name string (like "PIC16C74")
CLOCK Returns the Osc clock value (from a #USE DELAY)
VERSION Returns the compiler version as a float
VERSION_STRING Returns the compiler version as a string
PROGRAM_MEMORY Returns the size of memory for code (in words)
STACK Returns the stack size
DATA_EEPROM Returns the number of bytes of data EERPOM
READ_PROGRAM Returns a 1 if the code memory can be read
PIN:pb Returns a 1 if bit b on port p is on this part
ADC_CHANNELS Returns the number of A/D channels
ADC_RESOULTION Returns the number of bits returned from READ_ADC()
ICD Returns a 1 if this is being compiled for a ICD
SPI Returns a 1 if the device has SPI
USB Returns a 1 if the device has USB
CAN Returns a 1 if the device has CAN
I2C_SLAVE Returns a 1 if the device has I2C slave H/W
I2C_MASTER Returns a 1 if the device has I2C master H/W
PSP Returns a 1 if the device has PSP
COMP Returns a 1 if the device has a comparator
VREF Returns a 1 if the device has a voltage reference
LCD Returns a 1 if the device has direct LCD H/W
UART Returns the number of H/W UARTs
CCPx Returns a 1 if the device has CCP number x
TIMERx Returns a 1 if the device has TIMER number x
Examples:
#IF getenv("VERSION")<3.050
#ERROR Compiler version too old for this program
#ENDIF

for(i=0;i write_eeprom(i,0);

#IF getenv("FUSE_VALID:BROWNOUT")
#FUSE BROWNOUT
#ENDIF

It is very useful, since it allows conditional compilation on most chip abilities. :-)
3.074, doesn't list it, but 3.099 does. Hence it must date from somewhere between these two versions.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9177
DuncanH
Guest







Re: EEPROM detection getenv?
PostPosted: Mon Nov 25, 2002 5:19 am     Reply with quote

:=:=
:=:=:=#define EEPROM_PRESENT (getenv("DATA_EEPROM") > 0)
:=:=
:=:=This getenv() interests me. Are there more env variables? If yes is there a documentation? Is the getenv limited to a certain compiler version?
:=:=
:=:=Thanks
:=Yes.
:=It is relatively new, and the documentation doesn't exist in the 'help' file, but in the 'readme', for the last few versions. Typically I had forgotten it in suggesting using the INT_EEPROM variable.
:=This is copied from the readme:
:=
:=
:=The built in function getenv() has been added. The syntax is
:= value = getenv(cstring);
:= cstring is a constant string with a recognised keyword
:= as follows:
:= FUSE_SET:fffff Returns 1 if fuse fffff is enabled
:= FUSE_VALID:fffff Returns 1 if fuse fffff is valid
:= INT:iiiii Returns 1 if the interrupt iiiii is valid
:= ID Returns the device ID (set by #ID)
:= DEVICE Returns the device name string (like "PIC16C74")
:= CLOCK Returns the Osc clock value (from a #USE DELAY)
:= VERSION Returns the compiler version as a float
:= VERSION_STRING Returns the compiler version as a string
:= PROGRAM_MEMORY Returns the size of memory for code (in words)
:= STACK Returns the stack size
:= DATA_EEPROM Returns the number of bytes of data EERPOM
:= READ_PROGRAM Returns a 1 if the code memory can be read
:= PIN:pb Returns a 1 if bit b on port p is on this part
:= ADC_CHANNELS Returns the number of A/D channels
:= ADC_RESOULTION Returns the number of bits returned from READ_ADC()
:= ICD Returns a 1 if this is being compiled for a ICD
:= SPI Returns a 1 if the device has SPI
:= USB Returns a 1 if the device has USB
:= CAN Returns a 1 if the device has CAN
:= I2C_SLAVE Returns a 1 if the device has I2C slave H/W
:= I2C_MASTER Returns a 1 if the device has I2C master H/W
:= PSP Returns a 1 if the device has PSP
:= COMP Returns a 1 if the device has a comparator
:= VREF Returns a 1 if the device has a voltage reference
:= LCD Returns a 1 if the device has direct LCD H/W
:= UART Returns the number of H/W UARTs
:= CCPx Returns a 1 if the device has CCP number x
:= TIMERx Returns a 1 if the device has TIMER number x
:= Examples:
:= #IF getenv("VERSION")<3.050
:= #ERROR Compiler version too old for this program
:= #ENDIF
:=
:= for(i=0;i := write_eeprom(i,0);
:=
:= #IF getenv("FUSE_VALID:BROWNOUT")
:= #FUSE BROWNOUT
:= #ENDIF
:=
:=It is very useful, since it allows conditional compilation on most chip abilities. :-)
:=3.074, doesn't list it, but 3.099 does. Hence it must date from somewhere between these two versions.

Thankyou all for you help. That seems to cure the problem
___________________________
This message was ported from CCS's old forum
Original Post ID: 9379
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