Starting your PIC Engine
Start Line - Before You Write Your First Code of PIC 16F877
Now you're in the class and gotta be ready for a small or big project using PIC16F877. Lecture notes are everywhere and some example codes you attained and stashed inside your USB memory stick. Before you take that code out from the stick, you have to stand, and get-set, at the start line. I mean that you have to have a minimum hardware for PIC16F877 application. The minimum hardware configuration, which you can build from scratch either on your breadboard or project board, can be found in Chapter 4 of my book, Embedded Computing with PIC16F877-Assembly Language Approach.
PIC16F877 and PIC16F887A
In the configuration, you need a PIC16F877 or PIC16F877A. The 16F877A is a brother (I would say a twin brother, delivered much later though than its elder brother) of 16F877. I noticed that 16F877A is slightly cheaper and, so far, I found only one difference in the pin assignment. That's very minor. I used to use 16F877 chips only, of course. Since late last year, I see only 16F877A from the students who visit my office for bootloader download to the chip. Whether you choose 16F877 or 877A, I recommend you choose the chip properly according to my guideline: package type must be DIP (Dual-in line) so that it goes through the holes in your breadboard or project board, and the clock speed of 20MHz (Even though PIC16F877/877A supports 4 or 8 MHz also, but do we not utilize the maximum speed the chip promises, 20MHz. I always use 20MHz speed, and all the source codes in my book are based on 20MHZ clocking.
The only other chip you need is MAX232, RS-232 level converter. RS-232 is a regulation for the voltage level for binary numbers. Something like -15V for "1" and 20V for "0". Sorry I do not remember the exact value of the voltage levels for the binary values. But the message is clear. In RS-232 rule, binary expression is done in two very different levels of voltage. Long time ago, data transmission is done by something called tele-type, signal attenuation over the long distance is significant. At least that's what they say. So increasing the voltage level would increase the performance of the communication. Even though we're in all digital age, somehow we still use RS-232 regulation. In desktop PCs, most notably. At the back of your PC, find a 9-pin connector designated for serial communication port. Out of the pins are the voltage levels determined by binary values. In other words, everything inside your PC is done digitally (1/0 logic or +5V/0V logic). When a byte of data comes out of your PC through the DB-9 connector, they are converted to the RS-232 logic. Therefore, MAX232 (or any equivalent 232 chip) is to covert binary logic system to RS-232 logic system. Now you rightly guess why we need a MAX232 chip. It is to convert the digital logic in 16F877 to RS-232 level, so that this RS-232 logic can be transmitted via RS-232 logic DB-9 connector to your PC. Or a byte data from PC in digital logic is converted to RS-232 logic via MAX232 (or equivalent chip) inside PC is entered in to your PIC board, first through your MAX232 chip, reversed to digital logic, then to your 16F877 in binary logic. In MAX232 chip, you will need four 1-micro Farad electrolyte capacitors. See Chapter 4 of my book, Embedded Computing with PIC16F877-Assembly Language Approach.
Laptop without DB-9 but with USB only
Nowadays, manufacturers of laptop PC do not bother to include DB-9 connectors. Instead they install only USB slots. This will give you pain when you have MAX-232 and DB-9 male/female connector ready for DB-9 connector in your laptop. One option is to buy a Serial-to-USB converter. This thing has two types of connectors. DB-9 at one end and USB at the other end.
Or you can buy a PIC board from Olimex ( which has everything including USB connector. This board comes with PIC16F877A. Or if they changed their product or policy, you may have to buy a 16F877A chip along with the board. The board must be a 40-pin board, with built-in 20MHz crystal and all the necessary accessories. The olimex board with USB is the product number PIC-40B-USB. The PIC board from Olimex with DB-9 connector with power supplying circuit is PIC-40B. The PIC-40B-USB does not have power supply circuit since USB connection can draw power from your PC or laptop. When you purchase PIC-USB-40B, you have to install a USB serial communication driver and you need to know how to find the COM port number of your USB-ed PIC board to your PC.
Bootloader for PIC16F877 and 877A
Once you have your PIC board with PIC16F877 or 16F877A, you have to have a bootloader burned into your PIC chip. A bootloader is a small size code which opens up communication between the PIC chip and host PC (your desktop PC or your laptop) via a serial communication program, most notably HyperTerminal in Windows operating system, or a specific PIC downloader (available here or try this website). What bootloader does is to allow you to download your hex code (assembled using any PIC assembler, for example, MPLAB or MPASM) inside the PIC chip and burn the flash memory of the PIC chip. Once you burn your bootloader (itself a hex code) in the flash memory of your PIC chip, you're now free from any hassle. You just connect your USB or serial communication to your PC or laptop, and use the PIC downloader to download your hex code. The bootloader remains unchanged no matter what. OK. Now where can you find the bootloader for PIC 16F877 and 16F877A? Of course free ones. The best place I know is the microchip web site. Go visit and select the following link and down load. Inside this zip file you will see many different versions of bootloader. 16F87x 4MHz 19200bps, 16F87xA 20MHz 56000bps etc. Source codes and hex codes altogether. Somebody did a real good job. Anyway, the first one is apparently the chip, and the second tells you your crystal speed, and the third one is the serial communication bps (bit per second). This bps must be the same as the bps you will select in the PIC downloader. OK. I think now you have (1) the necessary bootloader hex code and (2) PIC downloader.
PIC Burner (or PIC programmer)
A PIC burner is a physical PIC programmer. A "physical: programmer is not a person who is a programmer. A physical programmer is a small board which burns your bootloader hex code into you PIC chip so that, later, you can download your own code to your PIC chip using the PIC downloader. There are many types of PIC burners with different functions and of course price tags. The one I use is very simple and cheap. It's from Olimex and the product number is PIC-PG2C. This slick board with 40-pin IC socket does not need external power supply. All you need is a serial cable. And the burn software is available from the Olimex web site and its name is ICPROG.EXE. The speed selection in ICprog window must be HS (high speed) since we use the maximum oscillation of 20MHZ. Other selections you can leave as default.
Now you have everything. PIC board with PIC chip. PIC Downloader. PIC Burner. PIC bootloader. The source codes I developed originally for PIC16F877 perfectly works with PIC16F877A. In your code section at the first line, you don't even have to declare as 16F877A. You can leave as it is with PIC16F877. But in your PIC burner, you have to select PIC16F877A and corresponding bootloader. Now ladies and gentlemen, start your engine!
You need help?
If you meet any problem in the start line, after a long search and tries, please write to me at


Return to Book Page