Hi everyone,
I am trying to write code to program an PIC18F4550 with my sweet Arduino using the output ports on the Arduino and the ICSP input of the PIC.
I used to write software for computers, seems Arduino needs a different approach.
I did a lot online searches always resulting in: "include library xyz".
My final goal is being able to program this kind of "instruction".
I was wondering if anyone can guide me in the right direction? Maybe a website, ebook?
To start with a more simple routine I've written (tried to ;)):
void enterProgramMode()
{
// Bail out if already in programming mode.
// if (state != STATE_IDLE)
// return;
// Switch DATA and CLOCK into outputs.
pinMode(PIN_DATA, OUTPUT);
pinMode(PIN_CLOCK, OUTPUT);
//
pinMode(PIN_VDD, OUTPUT);
// Lower MCLR, VDD, DATA, and CLOCK initially. This will put the
// PIC into the powered-off, reset state just in case.
digitalWrite(PIN_MCLR, MCLR_RESET);
digitalWrite(PIN_VDD, LOW);
digitalWrite(PIN_DATA, LOW);
digitalWrite(PIN_CLOCK, LOW);
// Wait for the lines to settle.
delayMicroseconds(DELAY_SETTLE);
// 1. Lower DATA and CLOCK
digitalWrite(PIN_DATA, LOW);
digitalWrite(PIN_CLOCK, LOW);
// 2. Raise PGM tp15>2µs
digitalWrite(PIN_MCLR, HIGH);
delayMicroseconds(DELAY_THLD0);
// 3. Raise MCLR
digitalWrite(PIN_MCLR, HIGH);
delayMicroseconds(DELAY_TPPDP);
// Wait tp12>2µs before clocking in data
// Now in program mode, starting at the first word of program memory.
//state = STATE_PROGRAM;
//pc = 0;
}
You will notice that some of the parts are based on http://rweather.github.com/ardpicprog/programpic_sketch.html which turned up in my searches too.
But what I am writing doesn't feel good... So before I proceed and producing more crap It's better to inform myself and learn I (think I) don't know the proper strategy of generating a clock and clocking in data (for ICSP). If anyone would be able to explain the general strategy of generating a clock and clocking in the data on a microcontroller with respect to the timing diagram, it would be amazingly great!!!
THANKS!