You are on page 1of 30

USB PIC PROGRAMMER USING PIC18F2550

A Project Report Submitted in partial fulfilment of the requirements for the award of the degree Of

BACHELOR OF TECHNOLOGY
In

ELECTRONICS AND COMMUNICATION ENGINEERING


By

PRATEEK SHARMA (6EC3-70)

Department of Electronics and Communication Engineering


SADTM Campus, JNU, Jaipur, Rajasthan

PREFACE

I got the idea of this project during my study about comparators. I thought if a comparator outputs are in only 0 or 1 then it can be used to interface with microcontroller as microcontroller also needs data in 0 or 1 to work. So I decided to use this property of comparator in our project. I decided to interface comparator LM324A with microcontroller for getting output from Infrared sensors. When infrared sensor is on black line then light emitted by it is not reflected back and no input is got by the microcontroller i.e. it gets 0 input while when sensor is on the white line then the light emitted by it is reflected back to the receiver and the microcontroller gets the output i.e. 1. And according to this input microcontroller moves the motor along with the black line drawn on the white surface and vice versa. This idea was the first step for me. I hope that I would extend these ideas to a more advanced and higher level.

TABLE OF CONTENTS
1. Acknowledgement 2. Abstract 3. Circuit Diagram 4. Explanation 5. PCB Layout 6. Fabrication and assembly 7. Result 8. Program used 9. Data sheets 10. Component list and prices

TABLE OF DIAGRAMS
1. Circuit Diagram 2. PCB Layout 3. Express PCB

ACKNOWLEDGEMENT

This acknowledgement is intended to those involved in my project work directly or indirectly, when expressed in words, feeling of gratitude is partially conveyed. I gratefully acknowledge my profound indebtedness forward my mentor for his valuable guidance, excellent supervision & constant encouragement during my project work at Jaipur National University, Jaipur, for continuous interest to pursue my project work. With a sense of gratitude, I extend a sincere thanks to other faculty members of Electronics & Communication Department. I am greatly indebted to their deep perception, understanding ability, mature, excellent supervision and generous help which they rendered to my every step. Without there cooperation and guidance, it would have been inconceivable to complete my undertaken project. I am also thankful for their valuable suggestions and technical helps.

Prateek Sharma (6EC3-70) Electronics & Communication

ABSTRACT

The burner or programmer is a hardware designed specifically to program or burn hex codes into the memory of the microcontroller. This memory is the permanent memory which is there to perform as desired by the user.As we all know that PIC microcontrollers and opt by Microchip company and are developing so tremendously. So we are greatly inspired by their advancement in their products and therefore we are here to design a programmer to program them. In this project I have used the boot loader to thats itself helps the controller to run the program in it. I have interfaced this microcontroller to the PC using the universal serial port (USB). Computer will transfer the data through the USB port to the microcontrollers memory. This is one of the basic and very interesting project in the field of microcontroller and embedded systems.

CIRCUIT DIAGRAM

EXPLAINATION

It is an open source Microchip PIC programmer for the USB port. As the term open source implies, the hardware design, the software and the firmware are all available for download free of charge.

Usbpicprog is an USB in circuit programmer for Microchip PIC processors. The hardware is as simple as possible, the current version only contains one PIC18F2550, 4 mosfets, and besides the connectors a hand full of passive components. Using these passive components and this pic 18f2550 microcontroller in this programmer, we are now able to program most of the PIC ICs. it is assembled on the zero PCB, just to check out the minor mistakes which are possibly encounter in some or other way. The most impressive part of this programmer is that it can run through usb port which is generally found in every hardware. Components Usbpicprog consists of three main components :

Hardware - A PCB design which contains the necessary components to interface from the USB port to a Microchip ICSP (in circuit serial programming) header.

Firmware The software that runs on the processor on the PCB. It contains the USB framework, and high and low level functions for PIC in circuit programming.The firmware can also be divided into two parts: 8

The bootloader (Microchip Picdem bootloader) has to be loaded only once, after that this part of the firmware can be upgraded through the usbpicprog interface.

The usbpicprog part of the firmware contains the actual programming algorithms for all the implemented PIC devices.

PC software A wxWidgets based (cross platform) application to communicate with the usbpicprog hardware / firmware. This application is known to function well on Linux, Windows (XP or later) and Macosx.

The design of the hardware is open and free of charge for the people who have their own PCB production facilities, for those who are not able to build their own usbpicprog,

This programmer has got two programming headers P1 and P2. They are explained below. Programming header P1
The programming header is used to program a target board using ICSP (in circuit serial programming). The pinout of this connector (and also the second connector which is used to write the bootloader in usbpicprogs own processor) is shown in the following table: Pin# 1 2 3 4 5 Name Description Level GND Target PIC ground 0V PGC Target PIC Program Clock 0V, 3.3V, 5V PGD Target PIC Program Data 0V, 3.3V, 5V, input VDD Target PIC Supply Voltage high impedance, 5V VPP Target PIC Program voltage 0V, 5V, 12V, high impedance

Self programming header P2


The self programming header is for programming the bootloader into Usbpicprog. The pinout is the same as P1. The bootloader can be loaded with any PIC in-circuit programmer. If you dont have one and cant 9

borrow one, its easy to make one inside an RS232 connector casing. Note that an external 12V supply is needed. (If your 12V supply is stabilized well, you dont need the zener D1) In Piklab you can use this programmer as Direct programmer ==> JDM programmer with MCLR inverted. If you are running Windows, you can use Winpic800 in order to use the JDM programmer. For the macosx users: sorry, I dont have a tip for you here Once the bootloader (it uses Picdem USB) is loaded for the first time, you can update the firmware through the usbpicprog application, so you will only need to borrow a programmer once!

Status leds
Since version 0.3 of the hardware, the leds have gotten their own color, and their own functionality: Led1, Red Write Led2, Yellow Read Led3, Green Connected, blinking while in standby In Bootloader mode, with the select jumper removed, Led1 (Red) and Led2 (Yellow) Should be on.

INSTRUCTIONS FOR UPGRADING THE FIRMWARE

Put one jumper on the usbpicprog programmer, in order to start the hardware in bootloader mode (as shown in the image below)

10

Plug in usbpicprog Launch the usbpicprog application, download the latest usbpicprog firmware and open the .hex file for the firmware upgrade, now choose Actions > Program to write the firmware into the usbpicprog hardware. (make sure that the option erase before programming is on in Options > Preferences)

Unplug usbpicprog, put the second jumper as shown on the image below and plug it in again. Usbpicprog is now ready to use

PCB LAYOUT

11

FABRICATION & ASSEMBLY

First we have to design PCB layout of the circuit to be fabricated. For this we are using Express PCB software. 12

Figure: Express PCB To make any PCB layout we follow these steps:-

1. Firstly we need to select the layer at which we want to work i.e. top layer or bottom layer. 2. To place any component go to component>select "component manager...">select desired

component from the library>click on "insert component into PCB"


3. To connect the components via tracks go to side toolbar>click on the track>connect with the help

of left mouse button>to end the wire do right click from the mouse.

There are different types of tool bars in this software, these are:-

13

1. Title bar: Contains the title, file name etc. 2. Menu bar: Contains File, Edit, View, Sheet, Component, Help menus. 3. Status bar: Contains X and Y position of mouse and Snap size. 4. Side Toolbar: Contains selection, components, wire, text, arc etc. 5. Top Toolbar: Contains zoom, save, open, undo etc.

The following steps can be used as guidelines for a proper PCB design:-

1. Take a printout of PCB layout of your circuit on glossy paper by a laser-type printer that uses toner as the printing method. 2. Cut a blank copper PCB according to the size of circuit keeping some space for borders. 3. Clean the PCB thoroughly with metallic wool. The board should be extremely clean for the toner to transfer onto it effectively. 4. Place the blank PCB onto a heat resistant surface with copper-side facing up. Place the printed PCB layout facing down onto the copper and carefully align them. 5. Now run the iron over the copper to begin the PCB layout stick to the copper making sure that the PCB layout paper does not slide over the PCB. 6. Allow the board to cool with the PCB layout paper stocked to it to the room temperature before trying to peel it. 14

7. Then transfer it to a container containing water and after sometime slowly peel the paper away from the copper revealing the circuit design tracks transferred to the board. 8. Etch the PCB using a solution of Ferric Chloride. 9. Remove the PCB from the etchant and wash any residue from the board. 10. After drying, drill all of the pads present on PCB and all the terminals of each and every component using suitable drill bit. 11. Clean the PCB using Diphenyl acetone.

Now the PCB is ready and we can solder the components to their respective position to it to get our project complete.

RESULT

It was a great learning experience for me while doing this project. I faced few challenges during the completion of this project, which I overcome quite easily with the help of our colleagues and faculty. I learnt some new ideas during our work. I also learnt the use of basic PCB designing software like Express PCB and Express SCH during this work. I also learnt to design the PCB as well. I also got 15

knowledge about interfacing techniques used in microcontroller PIC16f877a and its basic architecture. I learnt to program these devices and to examine their accuracy and principle work and use. I also learnt to use the basic embedded software like usbpicprog. I am sure that this knowledge will help me in future in further research and studies in the field of microcontrollers.

PROGRAM USED
BOOT LOADER #include <p18cxxx.h> #include "typedefs.h" #include "usb.h" #include "io_cfg.h" #pragma udata 16

byte counter; byte byteTemp; byte trf_state; word big_counter;

void BootInitEP(void)

{ trf_state = WAIT_FOR_CMD; BOOT_UEP = EP_OUT_IN|HSHK_EN; // Enable 2 data pipes

/* * Do not have to init Cnt of IN pipes here. * Reason: Number of bytes to send to the host * * * * * * * */ BOOT_BD_OUT.Cnt = sizeof(dataPacket); // Set buffer size BOOT_BD_OUT.ADR = (byte*)&dataPacket; // Set buffer address BOOT_BD_OUT.Stat._byte = _USIE|_DAT0|_DTSEN;// Set status 17 varies from one transaction to another. Cnt should equal the exact number of bytes to transmit for a given IN transaction. This number of bytes will only be known right before the data is sent.

BOOT_BD_IN.ADR = (byte*)&dataPacket;

// Set buffer address

BOOT_BD_IN.Stat._byte = _UCPU|_DAT1; // Set buffer status

}//end BootInitEP

void StartWrite(void) { /* * A write command can be prematurely terminated by MCLR or WDT reset */ EECON2 = 0x55; EECON2 = 0xAA; EECON1_WR = 1; }//end StartWrite

void ReadVersion(void) //TESTED: Passed { dataPacket._byte[2] = MINOR_VERSION; dataPacket._byte[3] = MAJOR_VERSION; }//end ReadVersion // 0x00 = Bootloader Version 0 // 0x01 = Bootloader

void ReadProgMem(void) //TESTED: Passed { for (counter = 0; counter < dataPacket.len; counter++) 18

{ //2 separate inst prevents compiler from using RAM stack byteTemp = *((dataPacket.ADR.pAdr)+counter); dataPacket.data[counter] = byteTemp; }//end for

TBLPTRU = 0x00;

// forces upper byte back to 0x00

// optional fix is to set large code model }//end ReadProgMem

void WriteProgMem(void) //TESTED: Passed { /* * The write holding register for the 18F4550 family is * actually 32-byte. The code below only tries to write * 16-byte because the GUI program only sends out 16-byte * at a time. * This limitation will be fixed in the future version. */ dataPacket.ADR.low &= 0b11110000; //Force 16-byte boundary EECON1 = 0b10000100; //Setup writes: EEPGD=1,WREN=1

//LEN = # of byte to write

for (counter = 0; counter < (dataPacket.len); counter++) 19

{ *((dataPacket.ADR.pAdr)+counter) = \ dataPacket.data[counter]; if ((counter & 0b00001111) == 0b00001111) { StartWrite(); }//end if }//end for }//end WriteProgMem

void EraseProgMem(void) //TESTED: Passed { //The most significant 16 bits of the address pointer points to the block //being erased. Bits5:0 are ignored. (In hardware).

//LEN = # of 64-byte block to erase EECON1 = 0b10010100; //Setup writes: EEPGD=1,FREE=1,WREN=1

for(counter=0; counter < dataPacket.len; counter++) { *(dataPacket.ADR.pAdr+(((int)counter) << 6)); //Load TBLPTR StartWrite(); }//end for TBLPTRU = 0; // forces upper byte back to 0x00

// optional fix is to set large code model // (for USER ID 0x20 0x00 0x00) 20

}//end EraseProgMem

void ReadEE(void) //TESTED: Passed { EECON1 = 0x00; for(counter=0; counter < dataPacket.len; counter++) { EEADR = (byte)dataPacket.ADR.pAdr + counter; //EEADRH = (BYTE)(((int)dataPacket.FIELD.ADDR.POINTER + counter) >> 8); EECON1_RD = 1; dataPacket.data[counter] = EEDATA; }//end for }//end ReadEE

void WriteEE(void) //TESTED: Passed { for(counter=0; counter < dataPacket.len; counter++) { EEADR = (byte)dataPacket.ADR.pAdr + counter; //EEADRH = (BYTE)(((int)dataPacket.FIELD.ADDR.POINTER + counter) >> 8); EEDATA = dataPacket.data[counter]; EECON1 = 0b00000100; //Setup writes: EEPGD=0,WREN=1 StartWrite(); while(EECON1_WR); }//end for 21 //Wait till WR bit is clear

}//end WriteEE

//WriteConfig is different from WriteProgMem b/c it can write a byte void WriteConfig(void) //TESTED: Passed { EECON1 = 0b11000100; //Setup writes: EEPGD=1,CFGS=1,WREN=1

for (counter = 0; counter < dataPacket.len; counter++) { *((dataPacket.ADR.pAdr)+counter) = dataPacket.data[counter]; StartWrite(); }//end for

TBLPTRU = 0x00;

// forces upper byte back to 0x00

// optional fix is to set large code model }//end WriteConfig

void BootService(void) { if((usb_device_state < CONFIGURED_STATE)||(UCONbits.SUSPND==1)) return;

if(trf_state == SENDING_RESP) { if(!mBootTxIsBusy()) { BOOT_BD_OUT.Cnt = sizeof(dataPacket); 22

mUSBBufferReady(BOOT_BD_OUT); trf_state = WAIT_FOR_CMD; }//end if return; }//end if

if(!mBootRxIsBusy()) { counter = 0; switch(dataPacket.CMD) { case READ_VERSION: ReadVersion(); LED_2 = 0; counter=0x04; break;

case READ_FLASH: case READ_CONFIG: ReadProgMem(); counter+=0x05; break;

case WRITE_FLASH: WriteProgMem(); 23

counter=0x01; break;

case ERASE_FLASH: EraseProgMem(); counter=0x01; break;

case READ_EEDATA: ReadEE(); counter+=0x05; break;

case WRITE_EEDATA: WriteEE(); counter=0x01; break;

case WRITE_CONFIG: WriteConfig(); counter=0x01; break;

case RESET: //When resetting, make sure to drop the device off the bus 24

//for a period of time. Helps when the device is suspended. UCONbits.USBEN = 0; big_counter = 0; while(--big_counter);

Reset(); break;

default: break; }//end switch() trf_state = SENDING_RESP; if(counter != 0) { BOOT_BD_IN.Cnt = counter; mUSBBufferReady(BOOT_BD_IN); }//end if }//end if}//end BootService

25

26

27

28

COMPONENTS REQUIRED
Name of the Component 1. PIC18f2550 Microcontroller 2. 1N4148 3. BS170 4. BC547 5. Crystal Oscillator (8 MHz) 6. IRF4905 7. Diode (IN4007) 8. Electrolytic Capacitor (1 F/25 V) 9. Electrolytic Capacitor (10 F/50 V) 10. Two Ceramic Capacitor (33 pF) 11. One Ceramic Capacitor (0.1 F) 12. Five resistors (1k ) 13. six resistors (470 ) 14. one resistors (100 K) 15. One resistor (1Mohm) 16. three LEDs 17. USB connector 18. One Sided Copper PCB 19. Standard two pin wire (1 meter) 10 15 40 02 10 02 01 06 01 0.25 01 02 01 20 45 15 29 Price/unit (in Rs.) 300 30 25

20. Headers

10

30

You might also like