S2DP_PIC12F509 is a simple serial data programmer which runs on PIC12F509. It controls four system signals, DATA, CLOCK, WP_, and RESET_, on boot-time using GIPO as follows: *1
- Set direction of the GPIO into INPUT
- Wait RESET_ turn into HIGH (disabled)
- Set direction of the GPIO into OUTPUT
- Set RESET_ into LOW (enabled) and WP_ into HIGH (unprotected)
- Write data one bit by one bit using DATA and CLOCK
- Set direction of the GPIO into INPUT again
- Sleep
*1 Expect that DATA, CLOCK, and WP_ are pull-downed and RESET_ is pull-upped
- 1 VDD
- 2 GP5: DATA
- Should be pull-downed
- 3 GP4: WP_
- Should be pull-downed
- 4 GP3: Unused (INPUT)
- 5 GP2: RESET_
- Should be pull-upped
- 6 GP1: CLOCK
- Should be pull-downed
- 7 GP0: Unused (OUTPUT with LOW)
- 8 VSS
Download and install MPLAB X IDE.
https://www.microchip.com/mplab/mplab-x-ide
Download and install MPLAB XC8 Compiler.
https://www.microchip.com/mplab/compilers
Startup MPLAB X IDE.
Select New Project...
from File
menu.
Select Microchip Embedded
from Categories:
and Standalone Project
from Projects:
.
Select PIC12F509
as Device:
.
Do nothing. Just press Next >
.
Select using PIC writer if you have. If you use universal programmer such as TL866CS, select
PICKit3
or something.
Select XC8
as a compiler.
Enter project name, e.g, S2DP, in Project Name:
Project S2DP has been created.
Download main.c from GitHub repository.
Import main.c into the project. Right click Source Files
of the project tree of S2DP, select Add Existing Item...
and select downloaded main.c file.
If main.c is imported successfully, it would appear in Source Files
.
Double click main.c and show it in the right area.
Press the hammer icon to test the compiler.
If compiled successfully, the following message is shown in the right bottom area
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/yourname/MPLABXProjects/S2DP.X'
make -f nbproject/Makefile-default.mk dist/default/production/S2DP.X.production.hex
make[2]: Entering directory 'C:/Users/yourname/MPLABXProjects/S2DP.X'
....
BUILD SUCCESSFUL (total time: 2s)
Loading code from C:/Users/yourname/MPLABXProjects/S2DP.X/dist/default/production/S2DP.X.production.hex...
Loading completed
C:/Users/yourname/MPLABXProjects/S2DP.X/dist/default/production/S2DP.X.production.hex is a file to be programmed to PIC device.
Focus on main.c. Replace both DATALEN and DATA macro with an appropriate value what you want to program.
Before:
#define DATALEN 16
#define DATA {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}
After (example with 12Byte data):
#define DATALEN 12
#define DATA {0x48,0x65,0x6C,0x6C,0x6F,0x20,0x57,0x6F,0x72,0x6C,0x64,0x00}
Build again. Press the hammer icon.
If successfully built, a hex file is appeared in the output directory after the following message is shown.
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/yourname/MPLABXProjects/S2DP.X'
make -f nbproject/Makefile-default.mk dist/default/production/S2DP.X.production.hex
make[2]: Entering directory 'C:/Users/yourname/MPLABXProjects/S2DP.X'
....
BUILD SUCCESSFUL (total time: 2s)
Loading code from C:/Users/yourname/MPLABXProjects/S2DP.X/dist/default/production/S2DP.X.production.hex...
Loading completed
This document shows the way to write compiled program to PIC device with TL866CS as an example. If you are using another PIC writer, please follow its usage.
Startup MiniPro Programmer.
Select Search and Select IC
from Select IC
menu.
Select PIC12F509
as device.
Open hex file. Select Open
from File
menu.
Open S2DP.X.production.hex file generated by MPLAB Toolchain.
File load Options
window is shown. Just press OK
button.
Select Program
from Device
menu.
Chip Program
window is shown. Set PIC12F509 device on TL866CS and press Program
button.
If successfully programmed, Programming Successful!
message is shown.