PIC18F2550 Pinguino

From Pinguino-Wiki

Jump to: navigation, search
Language: English  • EspaƱol


Contents

Diagram

Image:PIC18F2550 diagram.png

Features

This version of the Pinguino board is built with a Microchip PIC18F2550 chip. It works with a 20 MHz crystal and is USB 2.0 compatible.

The characteristics of this board are:

  • 18 digital input/output with 5 shared analog inputs,
  • UART for serial communications,
  • 2 fast PWM outputs ( 3000 Hz ),
  • 5 analog inputs.

There is one switch to reset the board. When reset is held, the board is in bootloader mode waiting for an upload from the development computer for 5 seconds. After 5 seconds, the current program is run.

This board can be powered by the USB connector subject to computer power limitations. It can be powered by an external power supply from 4.2Vcc to 5.5Vcc. You can add an onboard regulator to provide 5V Vcc for the microcontroller chip (using a 7805 voltage regulator for example).

Schematics and PCB of the board can be found here: [1]

This is an inkscape version of the PCB: [2]

PIC18F2550 Features: Reference PIC18F2550 features not, or not yet, supported by Pinguino.

Pins

Pin name Digital I/O Analog input Other Pin on Chip Microchip name
0 Yes nohw I2C I/O - SPI SDI 21 RB0/AN12/INT0/FLT0/SDI/SDA
1 Yes nohw I2C SCL - SPI SCK 22 RB1/AN10/INT1/SCK/SCL
2 Yes nohw - 23 RB2/AN8/INT2/VMO
3 Yes nohw - 24 RB3/AN9/CCP2/VPO
4 Yes nohw - 25 RB4/AN11/KBI0
5 Yes - - 26 RB5/KBI1/PGM
6 Yes - ICSP PGC 27 RB6/KBI2/PGC
7 Yes - ICSP PGD 28 RB7/KBI3/PGD
8 Yes - Serial Tx 17 RC6/TX/CK
9 Yes - Serial Rx - SPI SDO 18 RC7/RX/DT/SDO
10 Yes - - 11 RC0/T1OSO/T13CK
11 Yes - PWM 12 RC1/T1OSI/CCP2/UOE
12 Yes - PWM 13 RC2/CCP1
13 Yes Yesall - 2 RA0/AN0
14 Yes Yesall - 3 RA1/AN1
15 Yes Yesall - 4 RA2/AN2/VREF-/CVREF
16 Yes Yesall - 5 RA3/AN3/VREF+
17 Yes Yesall - 7 RA5/AN4/SS/HLVDIN/C2OU
Run Output only - Run Ledrun 6 RA4/T0CKI/C1OUT/RCV
USB+ - - USB 16 RC5/D+/VP
USB- - - USB 15 RC4/D-/VM
Vusb - - USB 14 VUSB
Reset - - Reset switch 1 MCLR/VPP/RE3
Vdd (5V) - - - 20 Vdd
Vss (GND) - - - 8 Vss
Vss (GND) - - - 19 Vss
OSC1 - - Quartz 9 OSC1/CLKI
OSC2 - - Quartz 10 OSC2/CLKO/RA6
  • Note hw: Analog input hardware available, but no software support
  • Note all: If one pin between 13 and 17 is used as analog input, all those pins are configured as analog inputs.
  • Note run: With bootloader v1, you must also connect a run switch and can not use digital Output

Pinguino Self-replication

Self-replication is any process by which a thing will make a copy of itself

Self-replicating Pinguino on a Breadboard

This code allows you to copy the bootloader of your Pinguino into a new blank (or not) chip. This has been successfully tried with a PIC18F2550. It should work also with a PIC18F4550 but it has not been tested.

Programming Hardware and Schematic

What do you need ?

  • 3 transistors
  • 2 LEDs
  • 5 resistors
  • an external 12V power supply. (12V from the computer is OK)

Schematic

Programming Source Code

// This is a tool to program the pinguino bootloader in a new chip
// with your Pinguino, the self replicating machine !!
// Jean-Pierre MANDON 2010
// Fixed bug 02/07/2011 PGM pin is no longer used
 
#define PGC 1           // connected to the PGC pin of the blank chip
#define PGD 2           // connected to the PGD pin of the blank chip
#define VPP 3           // connected to the VPP pin of the blank chip
#define VCC 6           // connected to the power on transistor
#define redled   5
 
uchar bulkerase[48] ={0x00,0x3C,0x0E,0x00,0xF8,0x6E,0x00,0x00,0x0E,0x00,0xF7,0x6E,0x00,0x05,0x0E,0x00,
                      0xF6,0x6E,0x0C,0x3F,0x3F,0x00,0x3C,0x0E,0x00,0xF8,0x6E,0x00,0x00,0x0E,0x00,0xF7,
                              0x6E,0x00,0x04,0x0E,0x00,0xF6,0x6E,0x0C,0x8F,0x8F,0x00,0x00,0x00,0x00,0x00,0x00};
 
uchar startwrite[24]={0x00,0xA6,0x8E,0x00,0xA6,0x9C,0x00,0x00,0x0E,0x00,0xF8,0x6E,0x00,0x00,0x0E,0x00,
                                          0xF7,0x6E,0x00,0x00,0x0E,0x00,0xF6,0x6E};
 
uchar startwrid[24] ={0x00,0xA6,0x8E,0x00,0xA6,0x8C,0x00,0x30,0x0E,0x00,0xF8,0x6E,0x00,0x00,0x0E,0x00,
                                          0xF7,0x6E,0x00,0x00,0x0E,0x00,0xF6,0x6E};
uchar checkmem[32];
uint address=0;
 
#define pic_on()  digitalWrite(VCC,LOW)
#define pic_off() digitalWrite(VCC,HIGH)
 
// begin programming mode
// power is on ( VCC and Programing voltage )
 
void start_pgm()
{
        digitalWrite(VPP,HIGH);
        delayMicroseconds(4);
}
 
// end programming mode
// power is on ( VCC and Programing voltage )
 
void stop_pgm()
{
        digitalWrite(PGD,LOW);
        digitalWrite(PGC,LOW);
        digitalWrite(VPP,LOW);
}
 
// send a command to the chip
// SPI soft
 
void send_command(uchar command,uchar lowbyte,uchar highbyte)
{
        unsigned char i;
        for (i=0;i<4;i++)
                {
                digitalWrite(PGC,HIGH);
                if ((command&1)==1) digitalWrite(PGD,HIGH);
                else digitalWrite(PGD,LOW);
                digitalWrite(PGC,LOW);
                command=command>>1;
                }
        for (i=0;i<8;i++)
                {
                digitalWrite(PGC,HIGH);
                if ((lowbyte&1)==1) digitalWrite(PGD,HIGH);
                else digitalWrite(PGD,LOW);
                digitalWrite(PGC,LOW);
                lowbyte=lowbyte>>1;
                }
        for (i=0;i<8;i++)
                {
                digitalWrite(PGC,HIGH);
                if ((highbyte&1)==1) digitalWrite(PGD,HIGH);
                else digitalWrite(PGD,LOW);
                digitalWrite(PGC,LOW);
                highbyte=highbyte>>1;
                }
digitalWrite(PGC,LOW);
digitalWrite(PGD,LOW);
}
 
// special end of command write
// DS39622K Page 20 figure 3.5 (Flash Microcontroller Programming Specification)
 
void end_writecmd()
{
unsigned char i;
digitalWrite(PGD,LOW);
for (i=0;i<3;i++)
        {
        digitalWrite(PGC,HIGH);
        digitalWrite(PGC,LOW);
        }
digitalWrite(PGC,HIGH);
delay(6);
digitalWrite(PGC,LOW);
delayMicroseconds(500);
for (i=0;i<8;i++)
        {
        digitalWrite(PGC,HIGH);
        digitalWrite(PGC,LOW);
        }
for (i=0;i<8;i++)
        {
        digitalWrite(PGC,HIGH);
        digitalWrite(PGC,LOW);
        }
}       
 
// Read Flash memory
// Pinguino examples Flash folder
 
uint ReadFlash(uint address)
{
uchar high8,low8;
TBLPTRU=0;
TBLPTRH=address>>8;
TBLPTRL=address;
__asm tblrd*+ __endasm;
low8=TABLAT;
__asm tblrd*+ __endasm;
high8=TABLAT;
return((high8<<8)+low8);
}
 
//-----------------------------------------------------------
// begining of the main loop
//-----------------------------------------------------------
 
void setup()
{
pinMode(PGC,OUTPUT);
digitalWrite(PGC,LOW);
pinMode(PGD,OUTPUT);
digitalWrite(PGD,LOW);
pinMode(VPP,OUTPUT);
digitalWrite(VPP,LOW);
pinMode(redled,OUTPUT);
digitalWrite(redled,LOW);
pinMode(VCC,OUTPUT);
digitalWrite(VCC,HIGH);
}
 
void loop()
{
int i;
 
// erase chip
pic_on();
delay(20);
start_pgm();
digitalWrite(redled,HIGH);
delay(10);
for (i=0;i<48;i+=3) send_command(bulkerase[i],bulkerase[i+1],bulkerase[i+2]);
delay(100);
stop_pgm();
delay(20);
pic_off();
delay(1000);
 
// read bootloader and write it
 
pic_on();
delay(1000);
start_pgm();
delay(10);
for (i=0;i<24;i+=3) send_command(startwrite[i],startwrite[i+1],startwrite[i+2]);
while (address<0x1FDF)
        {
        for (i=0;i<32;i++) checkmem[i]=ReadFlash(address+i);
        for (i=0;i<30;i+=2) send_command(0b00001101,checkmem[i],checkmem[i+1]);
        send_command(0b00001110,checkmem[30],checkmem[31]);
        end_writecmd();
        address+=32;
        digitalWrite(redled,digitalRead(redled)^1);
        delay(4);
        }
digitalWrite(redled,HIGH);      
for (i=0;i<32;i++) checkmem[i]=ReadFlash(address+i);
for (i=0;i<48;i+=3) send_command(startwrite[i],startwrite[i+1],startwrite[i+2]);
for (i=0;i<30;i+=2) send_command(0b00001101,checkmem[i],checkmem[i+1]);
send_command(0b00001111,checkmem[30],checkmem[31]);
end_writecmd();
 
// ---------- end copying bootloader
 
// programing configuration bits
 
for (i=0;i<24;i+=3) send_command(startwrid[i],startwrid[i+1],startwrid[i+2]);
send_command(0b00001111,0x24,0x24);
end_writecmd();
send_command(0,0x01,0x0E);
send_command(0,0xF6,0x6E);
send_command(0b00001111,0x0E,0x0E);
end_writecmd();
send_command(0,0x02,0x0E);
send_command(0,0xF6,0x6E);
send_command(0b00001111,0x3F,0x3F);
end_writecmd();
send_command(0,0x03,0x0E);
send_command(0,0xF6,0x6E);
send_command(0b00001111,0x1E,0x1E);
end_writecmd();
send_command(0,0x05,0x0E);
send_command(0,0xF6,0x6E);
send_command(0b00001111,0x81,0x81);
end_writecmd();
send_command(0,0x06,0x0E);
send_command(0,0xF6,0x6E);
send_command(0b00001111,0x81,0x81);
end_writecmd();
send_command(0,0x08,0x0E);
send_command(0,0xF6,0x6E);
send_command(0b00001111,0x0F,0x0F);
end_writecmd();
send_command(0,0x09,0x0E);
send_command(0,0xF6,0x6E);
send_command(0b00001111,0xC0,0xC0);
end_writecmd();
send_command(0,0x0A,0x0E);
send_command(0,0xF6,0x6E);
send_command(0b00001111,0x0F,0x0F);
end_writecmd();
send_command(0,0x0B,0x0E);
send_command(0,0xF6,0x6E);
send_command(0b00001111,0xA0,0xA0);
end_writecmd();
send_command(0,0x0C,0x0E);
send_command(0,0xF6,0x6E);
send_command(0b00001111,0x0F,0x0F);
end_writecmd();
send_command(0,0x0D,0x0E);
send_command(0,0xF6,0x6E);
send_command(0b00001111,0x40,0x40);
end_writecmd();
 
// ---------- end configuration bits
 
stop_pgm();
pic_off();
 
digitalWrite(redled,LOW);
 
while(1);
}
Personal tools