Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== PIC Development ====== Tested on %%FreeBSD%% 13.0 ===== Prerequisites ===== [[http://sdcc.sourceforge.net/|sdcc]] is a C compiler used for microprocessors. It states that PIC microprocessors are unmaintained, but I've found it to be pretty reliable so far (take this with a grain of salt, I'm no expert). The port can be found under: | lang/sdcc | Page 75 of the [[http://sdcc.sourceforge.net/doc/sdccman.pdf|sdcc user manual]] lists the supported PIC devices. Header files can be found under ''%%/usr/local/share/sdcc%%'' For programming the MCU, I've found ''%%pk2cmd%%'' to work well with the Microchip PICKit2 programmer (or Chinese clones), but there's no port for %%FreeBSD%% anymore. The Makefile won't install files properly, so we have some extra work to do afterwards: <code> $ git clone https://github.com/psmay/pk2cmd.git $ cd pk2cmd/pk2cmd # gmake freebsd install clean # mv /usr/share/pk2/PK2DeviceFile.dat /usr/local/bin # rm -rf /usr/share/pk2 </code> Supported devices for ''%%pk2cmd%%'' are listed [[https://github.com/psmay/pk2cmd/blob/master/pk2cmd/ReadmeForPK2CMDLinux2-6.txt|here]]. ===== Detecting and programming the MCU ===== :!: AUTO-DETECT WARNING: Always select the device family BEFORE connecting the chip to limit the maximum VPP that the PICkit 2 applies to the chip. Otherwise you risk damaging the chip and spending an inordinate amount of time trying to resolve issues with what is now a damaged chip. To avoid damage to chips by VPP voltage levels above that rated for the chip the recommended method for auto detection is: 1) Get and cache a list of supported devices and families with -?P 2) Get and cache a list of auto detectable families and IDs with -PF 3) Use 1 and 2 to determine the family ID for a given part. Auto detect the chip using -PFn where n is the family ID. The //better option// is to avoid auto-detect altogether and specify the chip part number (eg PIC16F877A). Assuming you've wired the MCU and the programmer correctly, hook up the programmer to your computer and check the chip is blank. If not erase the chip. If any of the following ''%%pk2cmd%%'' commands fail, make sure everything really is wired properly: <code> $ pk2cmd -P PIC16F877A -C Device is blank Operation Succeeded </code> Compile your source code. The target executable is the ''%%.hex%%'' file ''%%sdcc%%'' will output. Replace ''%%pic14%%'' and ''%%16f877a%%'' with the appropriate names for your device: <code> $ sdcc --use-non-free -mpic14 -p16f877a main.c </code> Erase the PIC (if the blank check failed) and flash the new code. Again, use the appropriate names: <code> $ pk2cmd -P PIC16F877A -E $ pk2cmd -P PIC16F877A -X -M -F main.hex </code> If all went well, you should get an output similar to this: <code> PICkit 2 Program Report 23-1-2022, 21:01:29 Device Type: PIC16F877A Program Succeeded. Operation Succeeded </code> ---- {{tag>HowTo}} microcontrollers/pic.txt Last modified: 2022/01/23 22:55by TrevorRoydhouse