diegoherranz / sdcc-examples

Code examples for microcontrollers ready to compile with SDCC
GNU General Public License v2.0
71 stars 17 forks source link

Explanation & Assumptions #2

Open andrewcharnley opened 8 years ago

andrewcharnley commented 8 years ago

Hi

re: https://github.com/diegoherranz/sdcc-examples/blob/master/pic14/1.blink_led/blink_led.c

I'm new to the game and have my env setup. The include file you use doesn't exist, and sdcc has include/pic14/pic12f629.h (or 675) instead?

Andrew

andrewcharnley commented 8 years ago

Ok, there is a one but it's pic14/pic16regs.h and this pulls the relevant file in via the -p command line (i.e -p12f629). Your generic loading of the pic16regs.h wont work.

diegoherranz commented 8 years ago

Hi,

It works for me so it might be related to a different SDCC version?

In the blink_led.c, modifying the Makefile to use PROC=12f629:

#include <pic14regs.h> loads sdcc/non-free/include/pic14/pic14regs.h which loads sdcc/non-free/include/pic14/pic12f629.h. OK.

If I modify blink_led.c to #include <pic16regs.h> instead, it works as well:

#include <pic16regs.h> loads sdcc/include/pic14/pic16regs.h which loads sdcc/non-free/include/pic14/pic12f629.h. OK.

I didn't know about pic16regs.h, I had always used pic14regs.h. I'll try to understand the difference but both work for me.

Can you indicate which SDCC version you're using?

axs-gentoo commented 7 years ago

Something of particular interest here is that pic16regs.h is not located within the non-free section -- I expect that using this header allows for using free support when it exists and falls back to non-free if it doesn't (or errors more usefully if non-free isn't available, maybe??)

The pic14regs.h is a rather interesting dynamic hack that essentially uses the preprocessor to "build itself" based on all of the files that are in the pic14/ directory. So although it may not look like it works, it does work. That said, having it spelled out in pic16regs.h looks to be safer and/or easier to follow, though I can't comment as to why it's called pic16regs.h given it is all pic14 chips, unless the overarching idea here is to make building 14bit and 16bit hex possible from the same C code?