PIC18F252 Programming

28 September, 2002
Alan Judson
vk3jaj@bigpond.com

1. Introduction

This investigation was started after I ordered the free sample kit for the Circuit Cellar contest, called Mad Dash for Flash Cash. There seems to be many ways to program the device. Here I have investigated two ways of programming the PIC18F252.

2. In-Circuit Serial Programming™

The Microchip document Programming the PIC18FXX2/FXX8, describes programming either the high or the low voltage In-Circuit Serial Programming™ (ICSP™). This document, 39576a.pdf, is available from the Microchip web site.

Figure 1. High Voltage In-Circuit Serial Programming™
Data is clocked with a 10MHz clock maximum, into the PIC, in multiple 20 bit instructions, made up of 4 bits of command, and 16 bits of operand. Between each command and operand is a gap of 20ns and between each block of 20 bits is a gap of 20ns. The operand can contain the word of data payload to be programmed. This might mean the PIC18F252 could be programmed in about 33ms, but it is doubtful that a parallel port on a PC could support that throughput.

3. Serial Port Bootloader

Further investigation into the contents of a "blank", as shipped, PIC18F252 revealed a program residing from 0000 - 01BF. This code is a serial port bootloader and if allowance for this code is made, then the device can be programmed via a COM port on a PC. The listing for the code is here. I disassembled the object code after reading the PIC18F252 with my PICstart®Plus development system, and comparing the code with that shown in AN851, A FLASH Bootloader for the PIC16 & PIC18. To handle the PIC18F252, the PICstart®Plus needed to be upgraded from 1v5 to 3v0 firmware after obtaining a PIC17C44 from the local supplier.

Figure 2. Serial Port Bootloader Schematic
This circuit uses the MAX232A from Maxim Integrated Products. This is required for level shifting from unipolar to bipolar levels, and data inversion.

Figure 3. Functional Block Diagram of MAX232
Data is framed on a standard asynchronous octet that has its baud rate determined on the first character sent to the firmware after a reset to the PIC18F252. The recommended baud rate from AN851, the application note titled, A FLASH Bootloader for the PIC16 and PIC18 devices, 000851a.pdf, on page 4, is 9600 baud. This might mean the device could take about 34 seconds to program. The application note is available from the Microchip web site.

3. References

Doc # File name Size Date Framing Title
AN589 00589a.pdf 111,027 2 Jun 97 ICSP™ A PC-Based Development Programmer for the PIC16C84
AN732 00732a.pdf 327,437 12 Mar 02 USART Implementing a bootloader for the PIC16F87x
AN819 00819a.pdf 268,661 15 Oct 01 USART Implementing Bootloader firmware for the PIC18C601/801 ROMless Microcontrollers
AN851 00851a.pdf USART A FLASH Bootloader for PIC16 and PIC18 Devices
DS39564A 39564a.pdf 5,893,198 29 Jun 01 PIC18FXX2 28/40-pin High Performance, Enhanced FLASH Microcontrollers with 10-Bit A/D
DS39576A 39576a.pdf 447,893 22 Aug 01 ICSP™ Programming for PIC18FXX2/FXX8 FLASH MCUs
TB016 91016b.pdf 300,236 14 Feb 02 ICSP™ How to Implement ICSP Using PIC16F8X FLASH MCUs
TB024 91024a.pdf 56,229 12 Oct 99 Hex Downloading HEX files to External FLASH Memory Using PIC17CXXX PICmicro
TB025 91025a.pdf 54,246 12 Oct 98 Hex Downloading HEX files to PICF87X PICmicro
Table 1. Reference Documents from Microchip

Copyright © 2002 Alan Judson. All Rights Reserved.
www.users.bigpond.com/vk3jaj/p18f252/ PIC18F252 Programming Issue 1, 29 September, 2002
index.html Draft Page 1 of 1