{"id":589,"date":"2011-07-06T22:23:06","date_gmt":"2011-07-06T21:23:06","guid":{"rendered":"http:\/\/pinguino.walii.es\/?p=589"},"modified":"2011-07-06T22:28:08","modified_gmt":"2011-07-06T21:28:08","slug":"pinguino-grabador-de-pinguinos","status":"publish","type":"post","link":"https:\/\/pinguino.walii.es\/?p=589","title":{"rendered":"Pinguino grabador de Pinguinos"},"content":{"rendered":"

Gracias a la idea de JEAN, y tras el pedido de varias personas que dicen que no entienden el post en ingles… intentar\u00e9 poner todos los datos para que se puedan seguir y llegar a buen puerto de una forma amena y simple.<\/p>\n

lo primero que debemos tener en cuenta es que yo trabajo principalmente con el pic 18f4550… pero tiene que funcionar con el 18f2550.<\/p>\n

Teniendo en cuenta que el circuito utilizado y la identificaci\u00f3n de PINES es la siguiente.<\/p>\n

Equipo grabador, un Pinguino estandart.<\/p>\n

\"\"<\/a>el segundo es el circuito del pinguino a grabar, obviamente puede ser un zocalo de, quita y pon, as\u00ed podremos programar muchos pics.<\/p>\n

\"\"<\/a><\/p>\n

Los n\u00fameros de pines concuerdan con la imagen superior, dir\u00e1n \u00bfporque este orden? y tiene una respuesta muy simple, ya que todo el proyecto viene de mucho mas atr\u00e1s, y para una consistencia en la identificaci\u00f3n de puertas, el PIN1 es por defecto el RB0 sin importar el pin f\u00edsico donde se encuentre.<\/p>\n

El programa que utilizaremos es el siguiente, compilado en la version de IDE 9.05, no muestra indicios de errores y funciona muy bien, digo esto porque si lo compilamos en otra versi\u00f3n de IDE pueden aparecernos problemas.<\/p>\n

 <\/p>\n

[sourcecode language=\u00bbpy\u00bb]
\n\/\/ This is a tool to program the pinguino bootloader in a new chip
\n\/\/ with your Pinguino, the self replicating machine !!
\n\/\/ Jean-Pierre MANDON 2010
\n\/\/ Fixed bug 02\/07\/2011 PGM pin is no longer used<\/p>\n

#define PGC 1\t\t\/\/ connected to the PGC pin of the blank chip
\n#define PGD 2\t\t\/\/ connected to the PGD pin of the blank chip
\n#define VPP 3\t\t\/\/ connected to the VPP pin of the blank chip
\n#define VCC 6\t\t\/\/ connected to the power on transistor
\n#define redled\t 5<\/p>\n

uchar bulkerase[48] ={0x00,0x3C,0x0E,0x00,0xF8,0x6E,0x00,0x00,0x0E,0x00,0xF7,0x6E,0x00,0x05,0x0E,0x00,
\n 0xF6,0x6E,0x0C,0x3F,0x3F,0x00,0x3C,0x0E,0x00,0xF8,0x6E,0x00,0x00,0x0E,0x00,0xF7,
\n\t\t 0x6E,0x00,0x04,0x0E,0x00,0xF6,0x6E,0x0C,0x8F,0x8F,0x00,0x00,0x00,0x00,0x00,0x00};<\/p>\n

uchar startwrite[24]={0x00,0xA6,0x8E,0x00,0xA6,0x9C,0x00,0x00,0x0E,0x00,0xF8,0x6E,0x00,0x00,0x0E,0x00,
\n\t\t\t\t\t 0xF7,0x6E,0x00,0x00,0x0E,0x00,0xF6,0x6E};<\/p>\n

uchar startwrid[24] ={0x00,0xA6,0x8E,0x00,0xA6,0x8C,0x00,0x30,0x0E,0x00,0xF8,0x6E,0x00,0x00,0x0E,0x00,
\n\t\t\t\t\t 0xF7,0x6E,0x00,0x00,0x0E,0x00,0xF6,0x6E};
\nuchar checkmem[32];
\nuint address=0;<\/p>\n

#define pic_on() digitalWrite(VCC,LOW)
\n#define pic_off() digitalWrite(VCC,HIGH)<\/p>\n

\/\/ begin programming mode
\n\/\/ power is on ( VCC and Programing voltage )<\/p>\n

void start_pgm()
\n{
\n\tdigitalWrite(VPP,HIGH);
\n\tdelayMicroseconds(4);
\n}<\/p>\n

\/\/ end programming mode
\n\/\/ power is on ( VCC and Programing voltage )<\/p>\n

void stop_pgm()
\n{
\n\tdigitalWrite(PGD,LOW);
\n\tdigitalWrite(PGC,LOW);
\n\tdigitalWrite(VPP,LOW);
\n}<\/p>\n

\/\/ send a command to the chip
\n\/\/ SPI soft<\/p>\n

void send_command(uchar command,uchar lowbyte,uchar highbyte)
\n{
\n\tunsigned char i;
\n\tfor (i=0;i<4;i++)
\n\t\t{
\n\t\tdigitalWrite(PGC,HIGH);
\n\t\tif ((command&1)==1) digitalWrite(PGD,HIGH);
\n\t\telse digitalWrite(PGD,LOW);
\n\t\tdigitalWrite(PGC,LOW);
\n\t\tcommand=command>>1;
\n\t\t}
\n\tfor (i=0;i<8;i++)
\n\t\t{
\n\t\tdigitalWrite(PGC,HIGH);
\n\t\tif ((lowbyte&1)==1) digitalWrite(PGD,HIGH);
\n\t\telse digitalWrite(PGD,LOW);
\n\t\tdigitalWrite(PGC,LOW);
\n\t\tlowbyte=lowbyte>>1;
\n\t\t}
\n\tfor (i=0;i<8;i++)
\n\t\t{
\n\t\tdigitalWrite(PGC,HIGH);
\n\t\tif ((highbyte&1)==1) digitalWrite(PGD,HIGH);
\n\t\telse digitalWrite(PGD,LOW);
\n\t\tdigitalWrite(PGC,LOW);
\n\t\thighbyte=highbyte>>1;
\n\t\t}
\ndigitalWrite(PGC,LOW);
\ndigitalWrite(PGD,LOW);
\n}<\/p>\n

\/\/ special end of command write
\n\/\/ DS39622K Page 20 figure 3.5 (Flash Microcontroller Programming Specification)<\/p>\n

void end_writecmd()
\n{
\nunsigned char i;
\ndigitalWrite(PGD,LOW);
\nfor (i=0;i<3;i++)
\n\t{
\n\tdigitalWrite(PGC,HIGH);
\n\tdigitalWrite(PGC,LOW);
\n\t}
\ndigitalWrite(PGC,HIGH);
\ndelay(6);
\ndigitalWrite(PGC,LOW);
\ndelayMicroseconds(500);
\nfor (i=0;i<8;i++)
\n\t{
\n\tdigitalWrite(PGC,HIGH);
\n\tdigitalWrite(PGC,LOW);
\n\t}
\nfor (i=0;i<8;i++)
\n\t{
\n\tdigitalWrite(PGC,HIGH);
\n\tdigitalWrite(PGC,LOW);
\n\t}
\n}\t<\/p>\n

\/\/ Read Flash memory
\n\/\/ Pinguino examples Flash folder<\/p>\n

uint ReadFlash(uint address)
\n{
\nuchar high8,low8;
\nTBLPTRU=0;
\nTBLPTRH=address>>8;
\nTBLPTRL=address;
\n__asm tblrd*+ __endasm;
\nlow8=TABLAT;
\n__asm tblrd*+ __endasm;
\nhigh8=TABLAT;
\nreturn((high8<<8)+low8);
\n}<\/p>\n

\/\/———————————————————–
\n\/\/ begining of the main loop
\n\/\/———————————————————–<\/p>\n

void setup()
\n{
\npinMode(PGC,OUTPUT);
\ndigitalWrite(PGC,LOW);
\npinMode(PGD,OUTPUT);
\ndigitalWrite(PGD,LOW);
\npinMode(VPP,OUTPUT);
\ndigitalWrite(VPP,LOW);
\npinMode(redled,OUTPUT);
\ndigitalWrite(redled,LOW);
\npinMode(VCC,OUTPUT);
\ndigitalWrite(VCC,HIGH);
\n}<\/p>\n

void loop()
\n{
\nint i;<\/p>\n

\/\/ erase chip<\/p>\n

pic_on();
\ndelay(20);
\nstart_pgm();
\ndigitalWrite(redled,HIGH);
\ndelay(10);
\nfor (i=0;i<48;i+=3) send_command(bulkerase[i],bulkerase[i+1],bulkerase[i+2]);
\ndelay(100);
\nstop_pgm();
\ndelay(20);
\npic_off();
\ndelay(1000);<\/p>\n

\/\/ read bootloader and write it<\/p>\n

pic_on();
\ndelay(1000);
\nstart_pgm();
\ndelay(10);
\nfor (i=0;i<24;i+=3) send_command(startwrite[i],startwrite[i+1],startwrite[i+2]);
\nwhile (address<0x1FDF)
\n\t{
\n\tfor (i=0;i<32;i++) checkmem[i]=ReadFlash(address+i);
\n\tfor (i=0;i<30;i+=2) send_command(0b00001101,checkmem[i],checkmem[i+1]);
\n\tsend_command(0b00001110,checkmem[30],checkmem[31]);
\n\tend_writecmd();
\n\taddress+=32;
\n\tdigitalWrite(redled,digitalRead(redled)^1);
\n\tdelay(4);
\n\t}
\ndigitalWrite(redled,HIGH);
\nfor (i=0;i<32;i++) checkmem[i]=ReadFlash(address+i);
\nfor (i=0;i<48;i+=3) send_command(startwrite[i],startwrite[i+1],startwrite[i+2]);
\nfor (i=0;i<30;i+=2) send_command(0b00001101,checkmem[i],checkmem[i+1]);
\nsend_command(0b00001111,checkmem[30],checkmem[31]);
\nend_writecmd();<\/p>\n

\/\/ ———- end copying bootloader<\/p>\n

\/\/ programing configuration bits<\/p>\n

for (i=0;i<24;i+=3) send_command(startwrid[i],startwrid[i+1],startwrid[i+2]);
\nsend_command(0b00001111,0x24,0x24);
\nend_writecmd();
\nsend_command(0,0×01,0x0E);
\nsend_command(0,0xF6,0x6E);
\nsend_command(0b00001111,0x0E,0x0E);
\nend_writecmd();
\nsend_command(0,0×02,0x0E);
\nsend_command(0,0xF6,0x6E);
\nsend_command(0b00001111,0x3F,0x3F);
\nend_writecmd();
\nsend_command(0,0×03,0x0E);
\nsend_command(0,0xF6,0x6E);
\nsend_command(0b00001111,0x1E,0x1E);
\nend_writecmd();
\nsend_command(0,0×05,0x0E);
\nsend_command(0,0xF6,0x6E);
\nsend_command(0b00001111,0x81,0x81);
\nend_writecmd();
\nsend_command(0,0×06,0x0E);
\nsend_command(0,0xF6,0x6E);
\nsend_command(0b00001111,0x81,0x81);
\nend_writecmd();
\nsend_command(0,0×08,0x0E);
\nsend_command(0,0xF6,0x6E);
\nsend_command(0b00001111,0x0F,0x0F);
\nend_writecmd();
\nsend_command(0,0×09,0x0E);
\nsend_command(0,0xF6,0x6E);
\nsend_command(0b00001111,0xC0,0xC0);
\nend_writecmd();
\nsend_command(0,0x0A,0x0E);
\nsend_command(0,0xF6,0x6E);
\nsend_command(0b00001111,0x0F,0x0F);
\nend_writecmd();
\nsend_command(0,0x0B,0x0E);
\nsend_command(0,0xF6,0x6E);
\nsend_command(0b00001111,0xA0,0xA0);
\nend_writecmd();
\nsend_command(0,0x0C,0x0E);
\nsend_command(0,0xF6,0x6E);
\nsend_command(0b00001111,0x0F,0x0F);
\nend_writecmd();
\nsend_command(0,0x0D,0x0E);
\nsend_command(0,0xF6,0x6E);
\nsend_command(0b00001111,0x40,0x40);
\nend_writecmd();<\/p>\n

\/\/ ———- end configuration bits<\/p>\n

stop_pgm();
\npic_off();<\/p>\n

digitalWrite(redled,LOW);<\/p>\n

while(1);
\n}
\n[\/sourcecode]<\/p>\n

 <\/p>\n

y lo siguiente es f\u00e1cil, programaremos el PIC grabador, la imagen n\u00ba1, el chip a programar no necesita tener nada… puede ser tal cual viene de fabrica.<\/p>\n

 <\/p>\n


<\/p>\n","protected":false},"excerpt":{"rendered":"

Gracias a la idea de JEAN, y tras el pedido de varias personas que dicen que no entienden el post en ingles… intentar\u00e9 poner todos…<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[28,3,27],"tags":[],"_links":{"self":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts\/589"}],"collection":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=589"}],"version-history":[{"count":1,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts\/589\/revisions"}],"predecessor-version":[{"id":590,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts\/589\/revisions\/590"}],"wp:attachment":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}