Menu

program wont compile for 16f1826 chip

Help
Chris
2012-01-10
2013-05-30
  • Chris

    Chris - 2012-01-10

    hello, I wrote a pretty complex program and have compiled it for other chips and simulated it in proteus, and the program works perfect. when I changed to the chip that i have, which is the 16f1826 the compiler complains of a-d.set problems (as if the chip doesnt have an a-d converter which i know according to the datasheet it has a 10 channel converter) and it complains of the program being too big, which the program size of the chip is 2k words, and the other chip which i had been simulating on was also 2k words, so since it fit in that chip it should fit into the 16f1826. the chip i was simulating on was the 16f677 because it has a similar number of pins that i need. the pins i need are 3 for analog, 3 digital outputs, 3 digital inputs, and a software serial rx/tx, so a total of 11. oh and an eprom for non volitile settings to be saved inside of. i also have a 16f616 but that doesnt appear to have an eprom which i need. i dont know why great cow graphical basic complains of the program size being too big for this chip and why it acts like theres no analog. am i just overlooking something? is there a setting in the hardware settings section i should be setting, or maybe not setting? any help would be great i would love to get this working.

     
  • Chris

    Chris - 2012-01-10

    i may have found the problem with GC not accepting my chip has Analog inputs. in the 16f1826.dat file the pins show this

    17,RA0(IO)
    18,RA1(IO)
    1,RA2(IO)
    2,RA3(IO)
    3,RA4(IO)
    4,RA5(I),MCLR
    15,RA6(IO),OSC2
    16,RA7(IO),OSC1
    6,RB0(IO)
    7,RB1(IO)
    8,RB2(IO)
    9,RB3(IO)
    10,RB4(IO)
    11,RB5(IO)
    12,RB6(IO)
    13,RB7(IO)
    5,Vss
    14,Vdd

    and none of those pins say they're analog. so im gonna back up that file and try to put those values in manually and see what terrible things happen. this may be something to look into though it seems im the only one who uses this chip, which i only bought because it was cheap, had all the pins i needed and all the analog inputs i wanted and (so i thought) was fully supported by GCB. ill report my results

     
  • Chris

    Chris - 2012-01-10

    well that didnt help, im still gettings "error in library a-d.h: incorrect parameters in set, expected: set variable.bit status

     
  • Chris

    Chris - 2012-01-10

    looking through a-d.c i see theres a section that say "#IFDEF NoBit(ANS0)" and in the file 16f1826 it says ANSA0,ANSELA,0
    so maybe what the file a-d.c is missing is the letter A, but theres also ANSB1,ANSELB,1 and in the a-d.h file theres ANSELH
    so where would i put the B and where would i put the A. do I replace ANSELH with ANSELA and ANSEL with ANSELB? or am i still on the wrong track. i really dont know how to program in C so im really just guessing based on the differences in the files 16f677.dat and 16f1826.dat because if i put the contents of 16f677.dat into 16f1826.dat it doesnt complain of the AD problem.

     
  • Nobody/Anonymous

    Reading through the a-d.h include file, I saw the following warning that some PIC18's have an error in A-D chip definition. Could that be your problem?:

    'Some 18F8xxxx chips have error in chip definition
    'They claim to have PCFG4, but actually don't, can spot them by presence of ADCON2

     
  • Chris

    Chris - 2012-01-10

    well that seems to be the right track, i removed instances of pcfg from a-d.c and it doesnt give the a-d complaints, but this isnt a fix just shows where the problem is. like i said i dont know how to program in c and i dont know how to program in assembly. im more on the beginner side of pic programming. so if someone can point me in the right direction maybe i can replace the incorrect parts of the code, but i really dont know where to begin. i get a total of 6 complaints of "error in library a-d.h: incorrect parameters in set, expected: set variable.bit status" so im guessing theres a total of 6 instances of pcfg in the a-d.c library. i mean i could probably use the POT command but i think that would make my code larger (its pushing the limits as it is) and plus i dont want to waste the a/d periferals of my chip

     
  • Chris

    Chris - 2012-01-10

    ok i got that problem under control, i just downloaded the update.zip, replaced the old a-d.c file with the updated one and of course now im on a whole new course of errors, like EEDATA has not been defined which ill now be trying to troubleshoot

     
  • Nobody/Anonymous

    The 19/07/2011 version of GCBasic has a section in the a-d.h file for the 16F1826. Are you using that version?

    You may find that the program compiles to a larger size than the earlier chip as there could be more banksels needed and the A-D code compiles longer as well as the code to set the port pins to analogue is a lot bigger.

     
  • Chris

    Chris - 2012-01-10

    yes i am using the newer file with the section for my chip, i no longer get any errors related to the analog inputs, but the problems i am now running into are writing to the eeprom of the chip and all my variables are giving me errors. here is a small list of the errors i now receive
    GCASM: Symbol EEDATA has not been defined
    GCASM: Symbol LOOP_COUNTER_H has not been defined

    and it lists 3 more of my variables with _H after them (loop_counter) is one of the variables Im using, and as for the eeprom it doesnt appear in the 16f1826.dat file and it does appear in the 16f677.dat i think this is because the chip im using has the self write function and writes to the eeprom in a different way. thanks for all the help by the way i feel im getting closer to getting this program ready for the chip so i can finally start designing the hardware part

     
  • Nobody/Anonymous

    Here is a modified version of eeprom.h with a messy fix for EEDATA being renamed as EEDATL in the 1826.

    '    EEPROM routines for Great Cow BASIC
    '    Copyright (C) 2006-2007 Hugh Considine
    '    This library is free software; you can redistribute it and/or
    '    modify it under the terms of the GNU Lesser General Public
    '    License as published by the Free Software Foundation; either
    '    version 2.1 of the License, or (at your option) any later version.
    '    This library is distributed in the hope that it will be useful,
    '    but WITHOUT ANY WARRANTY; without even the implied warranty of
    '    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    '    Lesser General Public License for more details.
    '    You should have received a copy of the GNU Lesser General Public
    '    License along with this library; if not, write to the Free Software
    '    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    '********************************************************************************
    'IMPORTANT:
    'THIS FILE IS ESSENTIAL FOR SOME OF THE COMMANDS IN GCBASIC. DO NOT ALTER THIS FILE
    'UNLESS YOU KNOW WHAT YOU ARE DOING. CHANGING THIS FILE COULD RENDER SOME GCBASIC
    'COMMANDS UNUSABLE!
    '********************************************************************************
    'Updates:
    ' 3/5/2006: Program EEPROM read/write added
    ' 16/5/2006: Write mode disabled at end of EPWrite
    ' 23/5/2006: EPWrite and EPRead changed to stop use of temporary vars
    ' 19/8/2006: Program EEPROM altered to take input as word
    ' 9/2/2007: Bug fix: EEPGD bit not set if not present
    ' 5/8/2007: Altered to use alias to access address, data vars
    ' 4/9/2007: Data EEPROM code altered to support AVR
    ' 15/10/2007: Bug fix: FREE bit not set if not present, altered to use IntOn/IntOff to control interrupt
    ' 4/12/2007: Added In/Out to parameters
    ' 17/6/2008: Altered to make EPRead a system sub, to allow use in ReadTable
    ' 19/4/2009: Bugfixes for AVR, allow EEPE instead of EEWE
    sub EPWrite(In EEAddress, In EEDataValue)
    #IFDEF PIC
        'Variable alias
        #IFNDEF Var(EEADRH)
            Dim EEAddress Alias EEADR
        #ENDIF
        #IFDEF Var(EEADRH)
            Dim EEAddress As Word Alias EEADRH, EEADR
        #ENDIF
        #IFDEF Var(EEDATA)
            Dim EEDataValue Alias EEDATA
        #ENDIF
        #IFDEF Var(EEDATL)
            Dim EEDataValue Alias EEDATL
        #ENDIF
    
        'Disable interrupt
        IntOff
    
        'Select data memory
        #IFDEF Bit(EEPGD)
            SET EECON1.EEPGD OFF
        #ENDIF
        #IFDEF Bit(CFGS)
            Set EECON1.CFGS OFF
        #ENDIF
    
        'Start write
        SET EECON1.WREN ON
        EECON2 = 0x55
        EECON2 = 0xAA
        SET EECON1.WR ON
        SET EECON1.WREN OFF
    
        'Wait for write to complete
        WAIT WHILE EECON1.WR ON
        SET EECON1.WREN OFF
    
        'Restore interrupt
        IntOn
    
    #ENDIF
    #IFDEF AVR
        'Variable alias
        #IFDEF Var(EEARH)
            Dim EEAddress As Word Alias EEARH, EEARL
        #ENDIF
        #IFNDEF Var(EEARH)
            #IFDEF Var(EEAR)
                Dim EEAddress Alias EEAR
            #ENDIF
        #ENDIF
        Dim EEDataValue Alias EEDR
    
        'Enable write
        #IFDEF Bit(EEMWE)
            Set EECR.EEMWE On
        #ENDIF
        #IFNDEF Bit(EEMWE)
            #IFDEF Bit(EEMPE)
                Set EECR.EEMPE On
            #ENDIF
        #ENDIF
        'Start write, wait for it to complete
        #IFDEF Bit(EEWE)
            Set EECR.EEWE On
            Wait Until EECR.EEWE Off
        #ENDIF
        #IFNDEF Bit(EEWE)
            #IFDEF Bit(EEPE)
                Set EECR.EEPE On
                Wait Until EECR.EEPE Off
            #ENDIF
        #ENDIF
    
    #ENDIF
    
    end sub
    'EPRead made into system subroutine
    'Constant added to allow it to still be referred to as EPRead
    #define EPRead SysEPRead
    sub SysEPRead(In EEAddress, Out EEDataValue)
    
    #IFDEF PIC
        'Variable alias
        #IFNDEF Var(EEADRH)
            Dim EEAddress Alias EEADR
        #ENDIF
        #IFDEF Var(EEADRH)
            Dim EEAddress As Word Alias EEADRH, EEADR
        #ENDIF
        #IFDEF Var(EEDATA)
            Dim EEDataValue Alias EEDATA
        #ENDIF
        #IFDEF Var(EEDATL)
            Dim EEDataValue Alias EEDATL
        #ENDIF
    
        'Disable interrupt
        IntOff
    
        'Select data memory
        #IFDEF Bit(EEPGD)
            SET EECON1.EEPGD OFF
        #ENDIF
        #IFDEF Bit(CFGS)
            Set EECON1.CFGS OFF
        #ENDIF
    
        'Read
        SET EECON1.RD ON
    
        'Restore interrupt
        IntOn
    #ENDIF
    #IFDEF AVR
        'Variable alias
        #IFDEF Var(EEARH)
            Dim EEAddress As Word Alias EEARH, EEARL
        #ENDIF
        #IFNDEF Var(EEARH)
            #IFDEF Var(EEAR)
                Dim EEAddress Alias EEAR
            #ENDIF
        #ENDIF
        Dim EEDataValue Alias EEDR
    
        'Start read
        Set EECR.EERE On
    
    #ENDIF  
    end sub
    function ReadEP(EEAddress)
    #IFDEF PIC
        'Variable alias
        #IFNDEF Var(EEADRH)
            Dim EEAddress Alias EEADR
        #ENDIF
        #IFDEF Var(EEADRH)
            Dim EEAddress As Word Alias EEADRH, EEADR
        #ENDIF
        #IFDEF Var(EEDATA)
            Dim EEDataValue Alias EEDATA
        #ENDIF
        #IFDEF Var(EEDATL)
            Dim EEDataValue Alias EEDATL
        #ENDIF
    
        'Disable interrupt
        IntOff
    
        'Select data memory
        #IFDEF Bit(EEPGD)
            SET EECON1.EEPGD OFF
        #ENDIF
        #IFDEF Bit(CFGS)
            Set EECON1.CFGS OFF
        #ENDIF
    
        'Read
        SET EECON1.RD ON
        ReadEP = EEDataValue
    
        'Restore interrupt
        IntOn
    #ENDIF
    #IFDEF AVR
        'Variable alias
        #IFDEF Var(EEARH)
            Dim EEAddress As Word Alias EEARH, EEARL
        #ENDIF
        #IFNDEF Var(EEARH)
            #IFDEF Var(EEAR)
                Dim EEAddress Alias EEAR
            #ENDIF
        #ENDIF
        Dim EEDataValue Alias EEDR
    
        'Start read
        Set EECR.EERE On
    #ENDIF
    
    end function
    sub ProgramWrite(In EEAddress, In EEDataWord)
    #IFDEF PIC
        Dim EEAddress As Word Alias EEADRH, EEADR
        #IFDEF Var(EEDATA)
            Dim EEDataWord As Word Alias EEDATH, EEDATA
        #ENDIF
        #IFDEF Var(EEDATL)
            Dim EEDataWord As Word Alias EEDATH, EEDATL
        #ENDIF
    
        'Disable Interrupt
        IntOff
    
        'Select program memory
        SET EECON1.EEPGD ON
        #IFDEF Bit(CFGS)
            Set EECON1.CFGS OFF
        #ENDIF
    
        'Enable write
        SET EECON1.WREN ON
        #ifdef bit(FREE)
            SET EECON1.FREE OFF
        #endif
    
        'Write enable code
        EECON2 = 0x55
        EECON2 = 0xAA
    
        'Start write, wait for it to finish
        SET EECON1.WR ON
        NOP
        NOP
        SET EECON1.WREN OFF
    
        'Enable Interrupt
        IntOn
    #ENDIF
    end sub
    sub ProgramRead(In EEAddress, Out EEDataWord)
        Dim EEAddress As Word Alias EEADRH, EEADR
        #IFDEF Var(EEDATA)
            Dim EEDataWord As Word Alias EEDATH, EEDATA
        #ENDIF
        #IFDEF Var(EEDATL)
            Dim EEDataWord As Word Alias EEDATH, EEDATL
        #ENDIF
    
        'Disable Interrupt
        IntOff
    
        'Select program memory
        SET EECON1.EEPGD ON
        #IFDEF Bit(CFGS)
            Set EECON1.CFGS OFF
        #ENDIF
    
        'Start read, wait for it to finish
        SET EECON1.RD ON
        NOP
        NOP
    
        'Enable interrupt
        IntOn
    end sub
    sub ProgramErase(In EEAddress)
        Dim EEAddress As Word Alias EEADRH, EEADR
    
        'Disable Interrupt
        IntOff
    
        'Select program memory
        SET EECON1.EEPGD ON
        #IFDEF Bit(CFGS)
            Set EECON1.CFGS OFF
        #ENDIF
    
        SET EECON1.WREN ON
        #ifdef bit(FREE)
            SET EECON1.FREE ON
        #endif
        EECON2 = 0x55
        EECON2 = 0xAA
        SET EECON1.WR ON
        NOP
        NOP
        #ifdef bit(FREE)
            SET EECON1.FREE OFF
        #endif
        SET EECON1.WREN OFF
    
        'Enable interrupt
        IntOn
    end sub
    
     
  • Chris

    Chris - 2012-01-11

    oh wow thanks that fixed my eeprom problem, last problem is with my variables claiming to not be defined. im not sure why it puts the _H after the name of my variable in the errors

     
  • Nobody/Anonymous

    Are the variables with _H being used as indexes into tables or arrays?

     
  • Chris

    Chris - 2012-01-11

    yes, there are 3 variables i am using as indexes for an array, and it also complains about that array

     
  • Nobody/Anonymous

    There's a problem with the way GCBasic handles array indexing on the enhanced 16F chips that should probably go in the compiler problems forum. It always treats the index as a word variable even if its a byte variable which is why you are getting the _H not defined error.

    You could try 'dim'ing them as word variables if that won't break other parts of your program although the size of the code will probably balloon.

     
  • Chris

    Chris - 2012-01-11

    ok that makes sence, just before your reply i had tryed changing those variables to words because of another post i had read and that solved my problem, but did tell me my program was too large, just as you predicted. looks like ill be doing some fat trimming on my code to try to fit it all on this tiny chip. thanks so much for all your help you solved every one of my problems

     

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.