Author Topic: [PIC16C773] Toolchain help  (Read 1722 times)

0 Members and 1 Guest are viewing this topic.

Offline Sudo_apt-get_install_yumTopic starter

  • Regular Contributor
  • *
  • Posts: 161
  • Country: se
[PIC16C773] Toolchain help
« on: November 23, 2023, 01:16:12 pm »
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 file main.c and 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 about Illegal 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 :)
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12862
Re: [PIC16C773] Toolchain help
« Reply #1 on: November 23, 2023, 01:30:37 pm »
"Illegal Opcode" 'smells' like you are attempting to use the Microchip MPASM assembler toolchain for C sourcecode!  |O

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.
« Last Edit: November 23, 2023, 01:34:43 pm by Ian.M »
 
The following users thanked this post: Sudo_apt-get_install_yum

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: [PIC16C773] Toolchain help
« Reply #2 on: November 23, 2023, 02:09:01 pm »
Luckily the .mcs file is a text file, and should have enough information to identify the toolchain
 

Offline Sudo_apt-get_install_yumTopic starter

  • Regular Contributor
  • *
  • Posts: 161
  • Country: se
Re: [PIC16C773] Toolchain help
« Reply #3 on: November 23, 2023, 02:53:50 pm »
"Illegal Opcode" 'smells' like you are attempting to use the Microchip MPASM assembler toolchain for C sourcecode!  |O

Haha 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_BF
    Found one mention in this paper https://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 :/
    Quote
    Program UNION_1.C compiles under PCW. However, when compiling in MPLAB, MPLAB hangs. I saw this
    problem at a recent workshop and also a posting on the PICLIST describing the same problem.
  • ADGO
    Cant 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".
« Last Edit: November 23, 2023, 02:58:08 pm by Sudo_apt-get_install_yum »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: [PIC16C773] Toolchain help
« Reply #4 on: November 23, 2023, 02:58:55 pm »
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-ecosystem

I 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.
« Last Edit: November 23, 2023, 03:13:56 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: Sudo_apt-get_install_yum

Offline jpanhalt

  • Super Contributor
  • ***
  • Posts: 3479
  • Country: us
Re: [PIC16C773] Toolchain help
« Reply #5 on: November 23, 2023, 03:01:23 pm »
MPLab 8.92 shows that Microchip's(Compiler 9.60) is compatible with that chip.
 

Offline Sudo_apt-get_install_yumTopic starter

  • Regular Contributor
  • *
  • Posts: 161
  • Country: se
Re: [PIC16C773] Toolchain help
« Reply #6 on: November 23, 2023, 04:12:11 pm »
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-ecosystem

I 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.

Thanks 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: [Select]
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 for STAT_BF & ADGO references. 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 XC8 compiler?


Side note, is there really this big of a difference between the free and pro version of the compiler or just "clever" marketing?
Code: [Select]
(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 available
    Data 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.

« Last Edit: November 23, 2023, 04:16:43 pm by Sudo_apt-get_install_yum »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12862
Re: [PIC16C773] Toolchain help
« Reply #7 on: November 23, 2023, 04:43:29 pm »
You probably need to
Code: [Select]
#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'.
 
The following users thanked this post: Sudo_apt-get_install_yum

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: [PIC16C773] Toolchain help
« Reply #8 on: November 23, 2023, 05:09:14 pm »
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: [Select]
regsvr32 "C:\Program Files (x86)\Microchip\xc8\v1.33\bin\MPLABXC8.dll"
« Last Edit: November 23, 2023, 05:20:00 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: Sudo_apt-get_install_yum

Offline Sudo_apt-get_install_yumTopic starter

  • Regular Contributor
  • *
  • Posts: 161
  • Country: se
Re: [PIC16C773] Toolchain help
« Reply #9 on: November 24, 2023, 07:14:39 am »
New day, new energy  ;D

There does not seem to be a difference when using the legacy headers. I still get the same errors.

Thanks, this worked!
Code: [Select]
regsvr32 "C:\Program Files (x86)\Microchip\xc8\v1.33\bin\MPLABXC8.dll"
STAT_BF
This seems to be used as a "ready wait"/"buffer full" status flag from the SPI status registers. (SSPSTAT Bit 0).
Code: [Select]
CS(ON);
delayx(2);
SSPBUF=0x02;                    //command to write to eeprom
while (!STAT_BF);

SSPBUF=adress>>8;               //Send addr
while (!STAT_BF);
SSPBUF=(char) adress;
while (!STAT_BF);

SSPBUF=data;
while (!STAT_BF);

ADGO
This seems to be a "start ADC conversion" bit and should equal bit 2 (GO/DONE) in ADCONx.
Code: [Select]
ADGO=1;                         // start AD conversion
while (ADGO==1);                // wait for end of conversion
delayx(15);                     // 15 u sek delay

I 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 paper https://picmania.garcia-cuervo.net/recursos/ccs_picc_pic16f87x_tutorial_-_1a.pdf where 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.

 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: [PIC16C773] Toolchain help
« Reply #10 on: November 24, 2023, 08:09:53 am »
Try replacing these with

SSPSTATbits.BF
ADCONbits.ADGO
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline Sudo_apt-get_install_yumTopic starter

  • Regular Contributor
  • *
  • Posts: 161
  • Country: se
Re: [PIC16C773] Toolchain help
« Reply #11 on: November 24, 2023, 10:09:53 am »
SSPSTATbits.BF seems to work fine.

ADCONbits.ADGO doesn't seem to work. Changed it to ADCON0bits.GO seems to work?
This should also be equivalent to the bitmasks?
Code: [Select]
ADCON0 |= 4; //Start ADC
while (!(ADCON0 & 4));  //Wait for finish

Now 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: [Select]
PS C:\Program Files (x86)\Microchip\xc8\v1.33\bin> ./xc8.exe --chip=16C773 --outdir=C:\PIC --opt=all ./main.c
Microchip MPLAB XC8 C Compiler (Free Mode) V1.33
Part 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 = 1
PS 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  ;D
« Last Edit: November 24, 2023, 10:50:30 am by Sudo_apt-get_install_yum »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: [PIC16C773] Toolchain help
« Reply #12 on: November 24, 2023, 11:08:50 am »
Yes, ADCON0bits.GO is the same.
Did you try adding ”-O2" to xc8 arguments?
(O= letter, not zero)
Good luck!
« Last Edit: November 24, 2023, 11:11:01 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline Sudo_apt-get_install_yumTopic starter

  • Regular Contributor
  • *
  • Posts: 161
  • Country: se
Re: [PIC16C773] Toolchain help
« Reply #13 on: November 24, 2023, 01:23:55 pm »
I tried the standard optimization flags but i don't think that they are supported by XC8.
They seem to use the option --opt for 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  ;D
« Last Edit: November 24, 2023, 01:41:44 pm by Sudo_apt-get_install_yum »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: [PIC16C773] Toolchain help
« Reply #14 on: November 24, 2023, 02:40:47 pm »
Just open the project in Mplab and make it there!
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: [PIC16C773] Toolchain help
« Reply #15 on: November 25, 2023, 06:47:02 pm »
Did it fit already?

I tried the standard optimization flags but i don't think that they are supported by XC8.
They seem to use the option --opt for optimization but dont have the option for code  optimization type (speed/size & aggressiveness).
Ensure to check the docs:
https://onlinedocs.microchip.com/pr/%20GUID-BB433107-FD4E-4D28-BB58-9D4A58955B1A-en-US-1/GUID-9BAE4452-0B5D-4D7D-8812-644FA917ECAC.html

Maybe older XC8 used a different options.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline Sudo_apt-get_install_yumTopic starter

  • Regular Contributor
  • *
  • Posts: 161
  • Country: se
Re: [PIC16C773] Toolchain help
« Reply #16 on: November 27, 2023, 09:00:35 am »
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....  :-\
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3240
  • Country: gb
Re: [PIC16C773] Toolchain help
« Reply #17 on: November 27, 2023, 05:32:22 pm »
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).
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: [PIC16C773] Toolchain help
« Reply #18 on: November 28, 2023, 11:11:26 pm »
Porting the code to the newer pic shouldn't be too hard!
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf