[PIC16C773] Toolchain help - Page 1
Forum section: electronics / general

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: November 23, 2023, 01:16:12 pm
content: Hello everybody!I have to make some very minor changes to the firmware of a 20 year old product. Issue is that i have no idea of how to compile the code....The only thing i have to go of is that its a PIC16C773 and the code is dated September 2003, there is only one filemain.cand it references<pic.h>(presumably abstraction from the IDE).I do know that MPLAB IDE 8.50 is used to program the processor so i've tried to compile it using that version of the IDE but just get ~100 errors aboutIllegal character (X),Illegal opcode (X)and that it is unable to open"pic.h". I assume that this is the source for a lot of errors but wouldn't it be a part of the IDE/toolchain? This error number 36 so quite a few other complaint before missing library files.Maybe another compiler/library was used but i have no idea, there is zero documentation of this.Does anybody have any idea on how to compile this?I've never used PIC nor any toolchain from this time, other than gcc and make.I appreciate any help

author: Ian.M
author_rank: Super Contributor
timestamp: November 23, 2023, 01:30:37 pm
content: "Illegal Opcode" 'smells' like you are attempting to use the Microchip MPASM assembler toolchain for C sourcecode!IIRC 20 years ago Microchip didn't have their own PIC16 C compiler though there were a couple of third party ones.You'd need to post enough of the source file for us to identify the compiler, which we do by recognising the names of system functions, how the CONFIG word is set, device or compiler specific includes, and various data types. Then you'd need to find a copy of that compiler and install it as MPLAB 8 didn't come with compilers (though you could optionally install demo versions of several with limited device support or program size restrictions). Then you have the problem of obtaining a valid licence key for a legacy compiler as without it, most will drop back to demo mode, and even if the demo mode supports your chip, either code size restrictions or lack of optimization will bite your ass.

author: JPortici
author_rank: Super Contributor
timestamp: November 23, 2023, 02:09:01 pm
content: Luckily the .mcs file is a text file, and should have enough information to identify the toolchain

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: November 23, 2023, 02:53:50 pm
content: Quote from: Ian.M on November 23, 2023, 01:30:37 pmHaha you're probably right, looking through the different configurations of MPLAB suggests that....Thought i was using the built in PIC-C C-compiler but it doesn't seem to exist, falling back to the MPASM suit :/I have hower tried to compile it with the MPLAB X IDE with a C-compiler and it does not work. Im however able to create a project for the old processor in this modern IDE.There are two flags/defines and such that aren't defined in the C-file or referenced in the datasheet.STAT_BFFound one mention in this paperhttps://picmania.garcia-cuervo.net/recursos/ccs_picc_pic16f87x_tutorial_-_1a.pdf.Below is stated in the paper, i have no idea what PCW is, google suggests its "The Philippine Commission on Women" but i doubt the code is compiled there :/QuoteADGOCant find any mention on google regarding this.Almost all of the code seems to be handwritten/not using external functions. Other than the above mentioned "defines".

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 23, 2023, 02:58:55 pm
content: Pic.h refers to the old Hitech compiler, now XC8.Mplab is just an IDE, doesn't come with any compiler by default.Mplab 8 is ancient, but older xc8 versions will work fine.Download a v1.xx version from the archive (v2.xx works only in mplabX):https://www.microchip.com/en-us/tools-resources/archives/mplab-ecosystemI think v1.45 worked in mplab 8.92, but I recall having issues with certain deprecated functions/pragmas and reverting to v1.33. So I'd try that one first.IIRC all pic.h includes should be replaced with xc.h.

author: jpanhalt
author_rank: Super Contributor
timestamp: November 23, 2023, 03:01:23 pm
content: MPLab 8.92 shows that Microchip's(Compiler 9.60) is compatible with that chip.

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: November 23, 2023, 04:12:11 pm
content: Quote from: DavidAlfa on November 23, 2023, 02:58:55 pmThanks for the help, i downloaded the XC8 compiler v1.33. Created a test-file and im able to compile it seemingly fine with the following command.Code:PS C:\Program Files (x86)\Microchip\xc8\v1.33\bin> ./xc8.exe --chip=16C773 --outdir=C:\PIC ./test.cHowever i'm still getting compiler Errors forSTAT_BF&ADGOreferences. I can't seem to find where they come from.I'm using the commandline since MPLAB v8.92 lacks the option for adding the XC8compiler?Side note, is there really this big of a difference between the free and pro version of the compiler or just "clever" marketing?Code:(1273) Omniscient Code Generation not available in Free mode (warning)Memory Summary:Program space used 6h ( 6) of 1000h words ( 0.1%)Data space used 2h ( 2) of 100h bytes ( 0.8%)EEPROM space None availableData stack space used 0h ( 0) of 50h bytes ( 0.0%)Configuration bits used 0h ( 0) of 1h word ( 0.0%)ID Location space used 0h ( 0) of 4h bytes ( 0.0%)Running this compiler in PRO mode, with Omniscient Code Generation enabled,produces code which is typically 40% smaller than in Free mode.See http://microchip.com for more information.

author: Ian.M
author_rank: Super Contributor
timestamp: November 23, 2023, 04:43:29 pm
content: You probably need toCode:#define _LEGACY_HEADERSbefore #including xc.h to tell the compiler to use the old Hi-Tech (pre v9.81) SFR and bit names. Legacy support is in XC8 v1.45 and earlier, and also Hi-Tech PICC v9.81 upwards. I'm not sure about later versions of XC8 - check the include folder for a sub-folder called 'legacy'.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 23, 2023, 05:09:14 pm
content: Please post some code lines where those are used.Probably a deprecated thing, easily fixed with some subtitutions.Pro enables Os (Optimization for size), and yeah, it saves quite a lof of space.But it's free up to O2, which is still a decent optimization level.I have a fix somewhere to make xc8 visible in Mplab, let me search it.Edit:Open a cmd window in admin mode, execute this and reboot afterwards. XC8 should appear in mplab now.(If you're using a different/older Windows version, write the correct path to the DLL)Code:regsvr32 "C:\Program Files (x86)\Microchip\xc8\v1.33\bin\MPLABXC8.dll"

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: November 24, 2023, 07:14:39 am
content: New day, new energyThere does not seem to be a difference when using the legacy headers. I still get the same errors.Thanks, this worked!Code:regsvr32 "C:\Program Files (x86)\Microchip\xc8\v1.33\bin\MPLABXC8.dll"STAT_BFThis seems to be used as a "ready wait"/"buffer full" status flag from the SPI status registers. (SSPSTAT Bit 0).Code:CS(ON);delayx(2);SSPBUF=0x02; //command to write to eepromwhile (!STAT_BF);SSPBUF=adress>>8; //Send addrwhile (!STAT_BF);SSPBUF=(char) adress;while (!STAT_BF);SSPBUF=data;while (!STAT_BF);ADGOThis seems to be a "start ADC conversion" bit and should equal bit 2 (GO/DONE) in ADCONx.Code:ADGO=1; // start AD conversionwhile (ADGO==1); // wait for end of conversiondelayx(15); // 15 u sek delayI could simply replace them with the modern equivalent name but how would I trust that all other references are correct or that the binary compiles correctly?The only mention I could find of these "Bit names" is from this paperhttps://picmania.garcia-cuervo.net/recursos/ccs_picc_pic16f87x_tutorial_-_1a.pdfwhere they are used in the same way.It is dated January 2001 and contains a lot of coding examples that look quite similar to the code I’m trying to compile.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 24, 2023, 08:09:53 am
content: Try replacing these withSSPSTATbits.BFADCONbits.ADGO

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: November 24, 2023, 10:09:53 am
content: SSPSTATbits.BFseems to work fine.ADCONbits.ADGOdoesn't seem to work. Changed it toADCON0bits.GOseems to work?This should also be equivalent to the bitmasks?Code:ADCON0 |= 4; //Start ADCwhile (!(ADCON0 & 4)); //Wait for finishNow i have another problem, the code does not fit. And the optimize flag results in the same as non optimized. Is it possible to use the "pro" version of the compiler? I can't find a reference to it in the compilers manual?Code:PS C:\Program Files (x86)\Microchip\xc8\v1.33\bin> ./xc8.exe --chip=16C773 --outdir=C:\PIC --opt=all ./main.cMicrochip MPLAB XC8 C Compiler (Free Mode) V1.33Part Support Version: 1.33 (A)Copyright (C) 2014 Microchip Technology Inc.License type: Node Configuration(1273) Omniscient Code Generation not available in Free mode (warning)./main.c: 84: (1250) could not find space (30 bytes) for variable _outputBufSer0(908) exit status = 1(908) exit status = 1PS C:\Program Files (x86)\Microchip\xc8\v1.33\bin>EDIT:Finally got the microchip licence page to load and now im able to compile the code in pro mode!Thanks for all the help everyone

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 24, 2023, 11:08:50 am
content: Yes, ADCON0bits.GO is the same.Did you try adding ”-O2" to xc8 arguments?(O= letter, not zero)Good luck!

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: November 24, 2023, 01:23:55 pm
content: I tried the standard optimization flags but i don't think that they are supported by XC8.They seem to use the option--optfor optimization but dont have the option for code optimization type (speed/size & aggressiveness).One last question before i close this issue, is there a non OTP version of the processor or drop in replacement?Can't find one at Microchip (PIC18F2423 is similar but not exact) and don't want to waste a bunch of OTP processor for some minor code tests! The UV version does not seem to come in my IC-package...Thanks again for all the help

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 24, 2023, 02:40:47 pm
content: Just open the project in Mplab and make it there!

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 25, 2023, 06:47:02 pm
content: Did it fit already?Quote from: Sudo_apt-get_install_yum on November 24, 2023, 01:23:55 pmEnsure to check the docs:https://onlinedocs.microchip.com/pr/%20GUID-BB433107-FD4E-4D28-BB58-9D4A58955B1A-en-US-1/GUID-9BAE4452-0B5D-4D7D-8812-644FA917ECAC.htmlMaybe older XC8 used a different options.

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: November 27, 2023, 09:00:35 am
content: Yeah the binary size in "pro mode" and full optimization results in a program usage of 57% and 81% data-space usage, everything fits!The docs i posted in my previous post are the correct one, the compiler does not recognize "-O2, -Os etc".Now i'm just waiting for new processors from Digikey to test the changes. I only have programmed processors and they are OTP....

author: mikerj
author_rank: Super Contributor
timestamp: November 27, 2023, 05:32:22 pm
content: If you need the DIP package then you could get a windowed SSOP part and mount it on an standard SSOP-20 to DIP-20 adapter PCB (cheap versions available from eBay).

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 28, 2023, 11:11:26 pm
content: Porting the code to the newer pic shouldn't be too hard!