Menu

OneOf directive issue

Help
2015-05-22
2015-05-22
  • Jacques Nilo

    Jacques Nilo - 2015-05-22

    Hello all
    I am trying to define constants according to different type of chip that are being used
    the following code works ok

    #ifdef ChipNameStr "16F1509"
    print "ok"
    #endif
    

    The following code compiles ok but does not work:

    #ifdef ChipNameStr oneof("16F1509","16F690")
    print "ok"
    #endif
    

    I have a pretty long list of chips for which I have 3 parameters to set and would like to avoid replicating n times the first example
    Any idea or suggestions ?
    Jacques

     
  • Hugh Considine

    Hugh Considine - 2015-05-22

    OneOf works a bit differently to that. All of its parameters must be the names of constants, and if any of those constants have been defined then it will return true. One option if you had a single chip, or only a few chips, would be something like this:

    #if ChipName = 16F1509 Or ChipName = 16F690
    Print "ok"
    #endif
    

    If you have more chips, then maybe it is better to use the Chip_ constants that the compiler creates. It will always create a constant called Chip_ and then the name of the microcontroller used. Here, you can use OneOf. An example:

    #ifdef OneOf(Chip_16F1509, Chip_16F690)
    Print "ok"
    #endif
    

    Another thing to consider - filtering by chip name may not be the easiest option. If you do this, you need to deal with things like LF chips, or chips that are almost identical (16F818/16F819, for example). Could you use something else? Maybe look for a system register, or use the ChipPins constant to get the pin count. If there is anything else in the chip data file that you'd like to access as a constant, let us know and maybe we can implement that.

     
  • Jacques Nilo

    Jacques Nilo - 2015-05-22

    Thanks Hugh for your feedback I'll try that. I am currently working on a library that could allow the use of High Extended Flash memory for those new chips that do not have EEPROM. In fact a transcription in GCBASIC of the library proposed in AN1673. This is nearly done. Unfortunately HEF memory is the poorest documented part of Microchip datasheets... and I have not found a better way to assign my const variables than checking for the chip name...

     

    Last edit: Jacques Nilo 2015-05-22

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.