Menu

Multi chip code in same program

Help
2019-01-09
2019-01-12
  • Jim giordano

    Jim giordano - 2019-01-09

    I am trying to use the same program for different microprocessors. I tried the following code, but the compiler picked up the code from the second chip, even though I said to use the first block. Is there some limitation on #if I'm not understanding? I determined it was picking up the second block by looking in the asm file produced, it clearly call initpps2.

     #define chipno 1 ' 1=16F18324, 2=16F18426
    
     #if chipno=1
     #chip 16F18324,32
     #config RSTOSC=HFINT32, MCLRE=OFF
     #config FEXTOSC=OFF, CLKOUTEN=OFF, WRT=OFF, CPD=on
    
     #startup InitPPS, 85
     Sub InitPPS
        UNLOCKPPS
            SSP1CLKPPS = 0x10        ' RC0->MSSP1:SCL1
            SSP1DATPPS = 0x11        ' RC1->MSSP1:SDA1
            RC0PPS = 0x18            ' RC0->MSSP1:SCL1
            RC1PPS = 0x19            ' RC1<-MSSP1:SDA1
          LOCKPPS
     End sub
     #endif
    
     #if chipno=2
     #chip 16F18426,32
     #config RSTOSC=HFINT32, MCLRE=OFF
     #config FEXTOSC=OFF, CLKOUTEN=OFF, WRT=OFF, CPD=on
    
     #startup InitPPS2, 85
     Sub InitPPS2
        UNLOCKPPS
            SSP1CLKPPS = 0x13        ' RC0->MSSP1:SCL1
            SSP1DATPPS = 0x14        ' RC1->MSSP1:SDA1
            RC0PPS = 0x18            ' RC0->MSSP1:SCL1
            RC1PPS = 0x19            ' RC1<-MSSP1:SDA1
          LOCKPPS
     End sub
     #endif
    
     
  • Anobium

    Anobium - 2019-01-09

    I dont think you can do that the compiler looks for one #chip line. This could work as an approach but it does not as you cannot not substitute a constant on the chip line.

    Look at what is shown below but in the context that the chipname substitution does not work.

    Let me look into this.

     #define chipno 1 ' 1=16F18324, 2=16F18426
    
     #chip mychipname
     #config RSTOSC=HFINT32, MCLRE=OFF
     #config FEXTOSC=OFF, CLKOUTEN=OFF, WRT=OFF, CPD=on
    
    
      #script
          if chipno=1 then
              mychipname =16F18324
          end if
          if chipno=2 then
              mychipname =16F18426
          end if
      #endscript
    
    
     #startup InitPPS, 85
     Sub InitPPS
        UNLOCKPPS
           #if chipno=1
            SSP1CLKPPS = 0x10        ' RC0->MSSP1:SCL1
            SSP1DATPPS = 0x11        ' RC1->MSSP1:SDA1
            RC0PPS = 0x18            ' RC0->MSSP1:SCL1
            RC1PPS = 0x19            ' RC1<-MSSP1:SDA1
           #endif
           #if chipno=2
            SSP1CLKPPS = 0x13        ' RC0->MSSP1:SCL1
            SSP1DATPPS = 0x14        ' RC1->MSSP1:SDA1
            RC0PPS = 0x18            ' RC0->MSSP1:SCL1
            RC1PPS = 0x19            ' RC1<-MSSP1:SDA1
           #endif
        LOCKPPS
     End sub
    
     
  • Jim giordano

    Jim giordano - 2019-01-10

    I thought I might tackle it the opposite direction and just define the wanted chip with the correct #chip 16F18324,32 at the top and just test
    by using #if ChipNameStr="16F18324" , but the #if always fails. I guess ChipNameStr isn't available yet at that point in the compilation where #if is evaluated?

    This is not a big deal, Evan. I was just trying to clean up my code a little.

     
  • mkstevo

    mkstevo - 2019-01-12

    Not much help I'm afraid other than to say that when I was trying to do something similar I wrote two 'definition blocks' and commented one or the other out like this:

    #Define Use1459
    #Chip 16F1459, 48
    #Config OSC=INTOSC, PLLEN=On
    #Define LCD_RS              PortA.5 'A.0 and A.1 are In only on the 1459
    #Define LCD_Enable      PortA.4 'so use A.5 and A.4 which are opposite
    
    '#Define Use1829
    '#Chip 16F1829, 32
    '#Define LCD_RS                 PortA.0
    '#Define LCD_Enable         PortA.1
    

    Then within the code used stuff like this:

    #IfDef Use1459
           Wait 100 mS
           Locate 1,0
           Print  "PIC16F1459 48Mhz"
           Wait 1500 mS
    #EndIf
    
    #IfDef Use1829
           Wait 100 mS
           Locate 1,0
           Print  "PIC16F1829 32Mhz"
           Wait 1500 mS
    #EndIf
    

    Which I'm sure you have worked out for yourself anyway...

     

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.