Go Down

Topic: Arduino as a Pic Programmer! (Read 88744 times) previous topic - next topic

NI$HANT

"Real Men can Accomplish  Anything"

- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੁਂ!

Soranne

#31
Mar 03, 2012, 06:36 pm Last Edit: Mar 03, 2012, 06:54 pm by Soranne Reason: 1
Updated C# code and arduino code, should work with many pics (doesn't support config word yet...).

Don't forget to reset PIC before reading/writing. If the prog says "access to COMX denied", just close and re-open the prog.
My projects :
- Interfacing with Minitel : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1271350467
- Arduino PIC programmer : http://ardu

NI$HANT

Thanks! i will get back to you with the results.
"Real Men can Accomplish  Anything"

- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੁਂ!

Soranne

Ok! :)
I'm not sure about writing, but reading should work fine ;)
My projects :
- Interfacing with Minitel : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1271350467
- Arduino PIC programmer : http://ardu

NI$HANT

How can the Read software be saved?
"Real Men can Accomplish  Anything"

- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੁਂ!

Soranne

Not implemented yet but you can still copy/paste the text from the output window...
Does reading work for you?
My projects :
- Interfacing with Minitel : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1271350467
- Arduino PIC programmer : http://ardu

Hey, just wanted to give you two thumbs up for this project!
I've spent some time looking for a way to program pic through arduino and only found some (pretty arrogant) guys saying that it's not possible.. I wanted to make a PicKit2 clone, but needed something to burn hex to 16f2550, and it seems that your solution is exactly what I was looking for. It's unfortunate that I won't have time to try it soon, but keep up the good work!

sharath12

Hey Sorraine,
This is a nice project. Does this work for PIC24 (PIC24FJ256GA110) ?

Hi, Soranne !

As I said on the french topic of your project - http://arduino.cc/forum/index.php/topic,93067.0.html - I'm trying to reproduce the same kind of project with a PIC18F2550.
When i'll finish it, i'll share it on this topic, attached with a report. I expect that will help everybody else to adapt this project to their favorite microcontroller.

Cordially,

Watchi~

flz47655


Ditto... must keep an eye on this as my Pic programmer uses serial and my new PC doesn't... ;)
Keep it up Soranne, nice project...
Mike

ijager

#41
Apr 06, 2012, 01:53 pm Last Edit: Apr 30, 2012, 11:59 am by ijager Reason: 1
Hi, watchinofoye

I was also trying to build an Arduino PIC programmer for the PIC18F2550. So far without much success.

Here is my code:

Code: [Select]
/*
* Trying to build an arduino pic programmer for the PIC18F2550
* Programming specifications: http://ww1.microchip.com/downloads/en/DeviceDoc/39622L.pdf
* Author: Ingmar Jager
*/

//Pin layout
int pgc = 9;  // program clock
int pgd = 8;  // program data
int pgm = 10;  // program mode
int MCLR = 11; //Master Clear Reset / Vpp

void setup()
{
 Serial.begin(9600);
 
 pinMode(pgc, OUTPUT);
 pinMode(pgd, OUTPUT);
 pinMode(pgm, OUTPUT);
 pinMode(MCLR, OUTPUT);
 delay(500);
 
 enterProgramming();
 delay(500);
 tableRead(0x3F, 0xFF, 0xFF);
 delay(500);
 tableRead(0x3F, 0xFF, 0xFF);
 exitingProgramming();
}

/*
* @param: three bytes which form the tablepointer address
*/
void setTablePTR(int addr_upper_byte,int addr_half_byte,int addr_lower_byte)
{
 
Serial.print("Set TablePTR to: 0x");
Serial.print(addr_upper_byte, HEX);
Serial.print(addr_half_byte, HEX);
Serial.println(addr_lower_byte, HEX);

writeBits(4, 0x0); // 4 bit command
writeBits(16, 0x0E00 + addr_upper_byte); // 16 bit data payload: load address
writeBits(4, 0x0);
writeBits(16, 0x6EF8);  // set TBLPTR_U to addr_upper_byte

writeBits(4, 0x0);
writeBits(16, 0x0E00 + addr_half_byte);
writeBits(4, 0x0);
writeBits(16, 0x6EF7); //TBLPTR_H

writeBits(4, 0x0);
writeBits(16, 0x0E00 + addr_lower_byte);
writeBits(4, 0x0);
writeBits(16, 0x6EF6); //TBLPTR_L
 
}
/*
* Read byte from the given address
*/
void tableRead(int high_byte, int mid_byte, int low_byte)
{
 
 setTablePTR(high_byte,mid_byte,low_byte);
 
 writeBits(4, 0x8); //1000 = Read and no increment
 writeBits(8, 0x00);
 pinMode(pgd, INPUT);
 delayMicroseconds(5); //P6
 
 byte data = 0;
 //actual read
 Serial.print("Read bits from LSB to MSB: ");
 for (int i = 0; i < 8; i++)
 {
   digitalWrite(pgc, HIGH);
   delayMicroseconds(3); //P14
   
   if (digitalRead(pgd)==HIGH)
   {
     Serial.print("1");
     data += (1 << i);
   }
   else
   {
     Serial.print("0");
   }
     
   digitalWrite(pgc, LOW);
       delayMicroseconds(3);
 }  
 
 delayMicroseconds(5); //P5A
 pinMode(pgd, OUTPUT);
 Serial.println();
 Serial.print("Reading result: ");
 Serial.println(data);
}
 
/* Write LSB to MSB
* @param n = number of bits to write
* @param value = value to write in n bits
*/
void writeBits(int n, int value)
{
 digitalWrite(pgc, HIGH);
 for (int i = 0; i < n; i++) {
    if( (boolean) ((value >> i) & 1))
       digitalWrite(pgd,HIGH);
 }  
 delayMicroseconds(3);
 digitalWrite(pgc, LOW);
 delayMicroseconds(3);
 digitalWrite(pgd,LOW);
 delayMicroseconds(5); //P5A
}

/*
* Entering low voltage programming signals
*/
void enterProgramming()
{
  digitalWrite(pgc, LOW);
  digitalWrite(pgd, LOW);
  digitalWrite(pgm, LOW);
  digitalWrite(MCLR, LOW);
 
  delayMicroseconds(20);
 
  digitalWrite(pgm, HIGH);
  delayMicroseconds(3);//P15
  digitalWrite(MCLR, HIGH);
  delayMicroseconds(3);//P12
  Serial.println("Entered Low Voltage Programming");
}

/*
* Exiting low voltage programming signals
*/
void exitingProgramming()
{
  digitalWrite(pgc, LOW);
  digitalWrite(pgd, LOW);
  delayMicroseconds(1); //P16
  digitalWrite(MCLR, LOW);
  delayMicroseconds(1); //P18
  digitalWrite(pgm, LOW);
  Serial.println("Exiting Low Voltage Programming");
}


void loop()
{

}



I'm trying to read the deviceID on address 0x3FFFFF. According to the programming specifications the DEVID1 = 010x xxxx and DEVID2 = 0x12.
When I run my program, this is the output:
Code: [Select]
Entered Low Voltage Programming
Set TablePTR to: 0x3FFFFF
Read bits from LSB to MSB: 00000000
Reading result: 0
Set TablePTR to: 0x3FFFFF
Read bits from LSB to MSB: 00011111
Reading result: 248
Exiting Low Voltage Programming


So the first time I try to read the ID register it returns 0. However the second time the result is 00011111 (248). If I read it a third time it is 0 again. So I'm not quite sure what is happening here.

Have you got some better results?


Legot

I have been having issues with the GUI version.
When I Burn a hex to the pic, it seems to work (tx light on usb adapter flashes, etc) and the program says "Finished!" after a short time.
However, when I hit "Read from PIC" all lines (0-49) say 00000000000000

I'm using a PIC16F628A

sirbow2

ive been looking for something like this for a long time; great work!
http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

kirill578

I wrote a similar sketch for the PIC18F2550 ( a slight modification can adopt it to almost all pic18F2/4 family). the sketch and the instruction can be found over here:

https://sites.google.com/site/thehighspark/arduino-pic18f

Go Up