Upload Hex code to Pic16F628 using Arduino Uno and Linux
The diagram comes from the Ardpicprog project which appears to be scantily documented.
Using an Arduino Uno, I want to program a PIC16F628 to blink an LED. To do this, I have built a shield; the included circuit diagram. An Arduino sketch is also available from Ardpicprog but on its own it doesn't do anything substantial.
Here are some first lines from it:
[code lang="c" line="none"]// Pin mappings for the PIC programming shield.
#define PIN_MCLR A1 // 0: MCLR is VPP voltage, 1: Reset PIC
#define PIN_ACTIVITY A5 // LED that indicates read/write activity
#define PIN_VDD 2 // Controls the power to the PIC
#define PIN_CLOCK 4 // Clock pin
#define PIN_DATA 7 // Data pin
#define MCLR_RESET HIGH // PIN_MCLR state to reset the PIC
#define MCLR_VPP LOW // PIN_MCLR state to apply 13v to MCLR/VPP pin
// All delays are in microseconds.
#define DELAY_SETTLE 50 // Delay for lines to settle for reset
#define DELAY_TPPDP 5 // Hold time after raising MCLR
#define DELAY_THLD0 5 // Hold time after raising VDD
#define DELAY_TSET1 1 // Data in setup time before lowering clock
#define DELAY_THLD1 1 // Data in hold time after lowering clock
#define DELAY_TDLY2 1 // Delay between commands or data
#define DELAY_TDLY3 1 // Delay until data bit read will be valid
#define DELAY_TPROG 4000 // Time for a program memory write to complete
#define DELAY_TDPROG 6000 // Time for a data memory write to complete
#define DELAY_TERA 6000 // Time for a word erase to complete
#define DELAY_TPROG5 1000 // Time for program write on FLASH5 systems
#define DELAY_TFULLERA 50000 // Time for a full chip erase
#define DELAY_TFULL84 20000 // Intermediate wait for PIC16F84/PIC16F84A
// Commands that may be sent to the device.
#define CMD_LOAD_CONFIG 0x00 // Load (write) to config memory
#define CMD_LOAD_PROGRAM_MEMORY 0x02 // Load to program memory
#define CMD_LOAD_DATA_MEMORY 0x03 // Load to data memory
#define CMD_INCREMENT_ADDRESS 0x06 // Increment the PC
#define CMD_READ_PROGRAM_MEMORY 0x04 // Read from program memory
#define CMD_READ_DATA_MEMORY 0x05 // Read from data memory
#define CMD_BEGIN_PROGRAM 0x08 // Begin programming with erase cycle
#define CMD_BEGIN_PROGRAM_ONLY 0x18 // Begin programming only cycle
#define CMD_END_PROGRAM_ONLY 0x17 // End programming only cycle
#define CMD_BULK_ERASE_PROGRAM 0x09 // Bulk erase program memory
#define CMD_BULK_ERASE_DATA 0x0B // Bulk erase data memory
#define CMD_CHIP_ERASE 0x1F // Erase the entire chip[/code]
Have tried the following from an Ubuntu Linux terminal (Bash): which makes the Arduino RX and TX LEDs flash:
[code line="none"]echo "Hello microcontrollers!" > /dev/ttyACM0[/code], also
[code line="none"]echo "CMD_LOAD_CONFIG 0x00" > /dev/ttyACM0" > /dev/ttyACM0[/code]
This goes to the Arduino but does it reach the Pic? Seems there's a dearth of info out there on how to use such shields. The goal is to get the Intel HEX into the Pic's PROGMEM. (The Pic should just blink an LED; if I can get it to do that, I can get it to do just about anything.) So the question is twofold: *How* to send commands to the Pic (using this sketch or another and Linux Bash commands affecting USB) and *What* to send to the Pic. Yes, there's PIC documentation but I could use some help making sense of it. Please excuse and smile about this pun:
_Any pointers will be appreciated!_
The diagram comes from the Ardpicprog project which appears to be scantily documented.
Using an Arduino Uno, I want to program a PIC16F628 to blink an LED. To do this, I have built a shield; the included circuit diagram. An Arduino sketch is also available from Ardpicprog but on its own it doesn't do anything substantial.
Here are some first lines from it:
[code lang="c" line="none"]// Pin mappings for the PIC programming shield.
#define PIN_MCLR A1 // 0: MCLR is VPP voltage, 1: Reset PIC
#define PIN_ACTIVITY A5 // LED that indicates read/write activity
#define PIN_VDD 2 // Controls the power to the PIC
#define PIN_CLOCK 4 // Clock pin
#define PIN_DATA 7 // Data pin
#define MCLR_RESET HIGH // PIN_MCLR state to reset the PIC
#define MCLR_VPP LOW // PIN_MCLR state to apply 13v to MCLR/VPP pin
// All delays are in microseconds.
#define DELAY_SETTLE 50 // Delay for lines to settle for reset
#define DELAY_TPPDP 5 // Hold time after raising MCLR
#define DELAY_THLD0 5 // Hold time after raising VDD
#define DELAY_TSET1 1 // Data in setup time before lowering clock
#define DELAY_THLD1 1 // Data in hold time after lowering clock
#define DELAY_TDLY2 1 // Delay between commands or data
#define DELAY_TDLY3 1 // Delay until data bit read will be valid
#define DELAY_TPROG 4000 // Time for a program memory write to complete
#define DELAY_TDPROG 6000 // Time for a data memory write to complete
#define DELAY_TERA 6000 // Time for a word erase to complete
#define DELAY_TPROG5 1000 // Time for program write on FLASH5 systems
#define DELAY_TFULLERA 50000 // Time for a full chip erase
#define DELAY_TFULL84 20000 // Intermediate wait for PIC16F84/PIC16F84A
// Commands that may be sent to the device.
#define CMD_LOAD_CONFIG 0x00 // Load (write) to config memory
#define CMD_LOAD_PROGRAM_MEMORY 0x02 // Load to program memory
#define CMD_LOAD_DATA_MEMORY 0x03 // Load to data memory
#define CMD_INCREMENT_ADDRESS 0x06 // Increment the PC
#define CMD_READ_PROGRAM_MEMORY 0x04 // Read from program memory
#define CMD_READ_DATA_MEMORY 0x05 // Read from data memory
#define CMD_BEGIN_PROGRAM 0x08 // Begin programming with erase cycle
#define CMD_BEGIN_PROGRAM_ONLY 0x18 // Begin programming only cycle
#define CMD_END_PROGRAM_ONLY 0x17 // End programming only cycle
#define CMD_BULK_ERASE_PROGRAM 0x09 // Bulk erase program memory
#define CMD_BULK_ERASE_DATA 0x0B // Bulk erase data memory
#define CMD_CHIP_ERASE 0x1F // Erase the entire chip[/code]
Have tried the following from an Ubuntu Linux terminal (Bash): which makes the Arduino RX and TX LEDs flash:
[code line="none"]echo "Hello microcontrollers!" > /dev/ttyACM0[/code], also
[code line="none"]echo "CMD_LOAD_CONFIG 0x00" > /dev/ttyACM0" > /dev/ttyACM0[/code]
This goes to the Arduino but does it reach the Pic? Seems there's a dearth of info out there on how to use such shields. The goal is to get the Intel HEX into the Pic's PROGMEM. (The Pic should just blink an LED; if I can get it to do that, I can get it to do just about anything.) So the question is twofold: *How* to send commands to the Pic (using this sketch or another and Linux Bash commands affecting USB) and *What* to send to the Pic. Yes, there's PIC documentation but I could use some help making sense of it. Please excuse and smile about this pun:
_Any pointers will be appreciated!_