Menu English Ukrainian russian Home

Free technical library for hobbyists and professionals Free technical library


ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING
Free library / Schemes of radio-electronic and electrical devices

Programming of modern PIC16, PIC12 on PonyProg. Encyclopedia of radio electronics and electrical engineering

Free technical library

Encyclopedia of radio electronics and electrical engineering / Microcontrollers

Comments on the article Comments on the article

As you know, the PonyProg programmer is designed for programming a limited number of types of Microchip PICmicro microcontrollers (PIC12C50x PIC16F8x, PIC16F87x). However, it can be used to program others, including the new microcontrollers of the PIC12, PIC16 series. How to do this is described in the article.

Many radio amateurs build their designs based on the popular PIC16F84 (PIC16F84A) PIC controller. However, time does not stand still, and the range of manufactured PICmicro microcontrollers (MC) is constantly expanding. New, more advanced MKs of the PIC16F and PIC12F series have appeared (for example, PIC12F629, PIC12F675, PIC16F628, PIC16F630, PIC16F676). They contain a comparator capable of operating with an input voltage close to zero, which is very tempting with a single supply. The 10-bit ADC included in them has an accuracy no worse than specialized microcircuits, which, along with great processing and display capabilities, allows you to create unique devices with a minimum number of external elements. The new MCUs have more memory, additional timers, a universal communication port, and other improvements. At the same time, their cost is much lower than PIC16F84, and FLASH PIC16F630 is cheaper than PIC16C505 (both in 14-pin packages). The memory organization of the PIC12Fx is the same as that of the PIC16F84 (one page), which makes it easy to adapt programs that do not require the use of an MCU in multi-pin packages.

If you decide to use new MKs in your designs, then before studying them and writing programs, think about how to program them. The acquisition of a proprietary programmer at a cost comparable to the cost of a computer system unit is almost unrealistic for radio amateurs. However, many of them have assembled the PONYPROG programmer [1]. Let's figure out how you can use it to program new MK.

All MKs are programmed over a three-wire bus. Programming requires the Upp (programming mode), CLK (clock), and DAT (data) signals.

Fans who do not have a programmer can use the simplest device assembled according to the diagram in fig. 1. It is connected to the PC COM port, a separate source with an output voltage of 5 V is used to power the MK.

Programming of modern PIC16, PIC12 on PonyProg
(click to enlarge)

In the "Hardware Settings" indicate the type of programmer - JDM API. The conclusions are connected in accordance with the table. Programming can be done directly in the finished device using its power source (it is only necessary to eliminate the shunting of the MC programming outputs by the product elements). The supply voltage during programming should be in the range of 4,5 ... 5,5 V (if necessary, select a Zener diode VD1).

The table shows that the purpose of the PIC16F84 and PIC16F628 pins used in programming is the same, so they can be programmed in the same programmer socket. For other microcircuits, you will have to install additional sockets connected to the adapter in accordance with the table. More information about PIC controllers can be found on the website [2].

Further explanations are given on the example of PIC16F628, since it does not require hardware modification of the PonyProg programmer and is more than others available in stores.

As noted, all PICmicro MKs are programmed over three wires (more precisely, over two). The programming protocol (commands) is also the same.

The program memory starts at address 0000 and ends depending on its size in a particular type of microcircuit. This means that by selecting from the PonyProg list the appropriate MK for this parameter, you can record the desired program. In our case, PIC16F871 is suitable. Please note that the bottom line of the PonyProg window indicates the amount of memory in bytes, and the technical characteristics of the MK usually give the number of words (14 bits). In other words, the programmer shows a larger volume. The PIC16F871 and PIC16F628 have 2048 words of memory. Additionally, this can be checked in the .Ikr file of the corresponding MK (located in the MPLAB installation folder) by reading it using the standard Notepad program. The program memory address is given as follows:

CODEPAGE NAME=vectors START=0x0 END=0x4 PROTECTED (conditional transfers) CODEPAGE NAME=page START=0x5 END=0x7FF (conditional transfers)

Programming of modern PIC16, PIC12 on PonyProg

At this stage, you can already try to write information to the program memory. Any HEX file no larger than 2048 words will do. After launching the utility, connect the device to the computer port, insert the MK into the appropriate socket, then turn on the power of the programmer. Select PIC16F871 from the menu, load the selected HEX file and press the "Write program memory (FLASH)" button. An error message will appear, announcing problems with the MK and containing three buttons (Fig. 2): "Abort" (interrupt), "Retry" (repeat), "Ignore" (ignore). Press the last one ("Ignore") and the programming process will begin. Upon completion, you should see a message that the recording was successful. If the programmer has issued a "Write Error", check the contents of the program memory by reading it as the appropriate command. The presence of errors indicates that the programmer may be running too fast (this happens if the computer has WINDOWS XP installed; with WINDOWS 98, the program runs slower and writes more reliably). The cause may also be interference (if the connecting wires are too long), and in rare cases, anti-virus and other background programs. If the entry is missing completely, then the hardware of the programmer is faulty or the program is incorrectly configured (in the menu).

The next, most important step is to write the configuration word. Its address can also be found in the .Ikr file of the corresponding MK. The line in the file looks like this:

CODEPAGE NAME=.config START=0x2007 END=0x2007 PROTECTED (conditional transfers).

The configuration word is located at address 0x2007. In our case, PIC16F871 and PIC16F628 have addresses 2007, i.e., they are suitable for substitution (it should be noted that the configuration word for all PIC16 and PIC12F is located exactly at this address). It is undesirable to set the configuration bits directly in the programmer, since their designation on the programmer panel for PIC16F628 and PIC16F871 is different and errors are possible, and some bits are grayed out and cannot be set directly. It is better to write down the MK configuration when compiling a program. For MPLAB these lines might look something like this:

in lude p16f628.inc> list p=16f628_config H'0242"

The value '0242' is composed according to the assignment of each bit in the configuration word and may be different in your particular case. A detailed description of all bits can be found on the site [2].

The configuration bit abbreviations are contained in the corresponding MCU's .INC file in the MPLAB installation folder. Approximate view:

BODEN ON EQU H'3FFF'

BODEN OFF EQU H'3FBF'

CP ALL EQU H'03FF'

CP 75 EQU H'17FF'

CP 50 EQU H'2BFF'

CP OFF EQU H'3FFF'

DATA CP ON EQU H'3EFF'

DATA CP OFF EQU H'3FFF'

PWRTE OFF EQU H'3FFF'

PWRTE ON EQU H'3FF7'

WDT ON EQU H'3FFF'

WDT OFF EQU H'3FFB'

LVP ON EQU H'3FFF'

LVP OFF EQU H'3F7F'

MCLRE ON EQU H'3FFF'

MCLRE OFF EQU H'3FDF'

ER OSC CLKOUT EQU H'3FFF'

ER OSC NOCLKOUT EQU H'3FFE'

INTRC OSC CLKOUT EQU H'3FFD'

INTRC OSC NOCLKOUT EQU H'3FFC

EXTCLK OSC EQU H'3FEF'

LP OSC EQU H'3FEC

XT OSC EQU H'3FED'

HS OSC EQU H'3FEE'

Using these notations, the entry string might look like this:

__config CP_ALL & WDT OFF & BODEN ON & _PWRTE_ON & _HSJ3SC &_LVP OFF ; (transfers are conditional).

This way you can write a configuration word for any MCU using its .INC file. This is convenient when adapting a finished program, for example, in the case of replacing the PIC16F627 with a cheaper PIC16F627A. When a configuration is included in the program text, it will be included in the HEX file and the shaded bits will be set. After you have entered the configuration word into the programmer by reading the HEX file of the program containing it, writing is done in the usual way by entering the appropriate command. Similarly, it can be read from MK. You can make sure that the configuration is written, either by clearing the programming panel of the programmer's configuration after writing, and then reading the configuration from the MK, or by reading the program memory from a read-protected microcircuit: before the configuration is written, it is read, and after writing it is not (if protection is installed), in this case, the configuration is also read in the protected chip.

It is not recommended to set security bits unless absolutely necessary. The fact is that some MKs have different erase commands, and you will not be able to reprogram them, since the protection bits will not be erased on PonyProg. However, when writing to an unprotected chip over the "firmware" in it, the code being written will erase the previous information and there will be no need for erasure. However, this does not apply to PIC16F627, PIC16F628, the information in them can be protected without fear.

Data is written to the EEPROM in the usual way, since the data in the PIC16F and PIC12F microcontrollers are located from the address 2100p. You can also see this in the .Ikr file. An example string:

CODEPAGE NAME=eedata START=0x2100 END=0x217F PROTECTED (conditional transfers).

Different for PIC controllers - only the end of the data area (due to different sizes): for PIC16F628 - 128, for PIC16F871 - 64 bytes, but if the amount you need for work does not exceed the size of the EEPROM of the selected replacement chip (for PIC16F871 - 64 bytes) , then you can program without switching the type of MK in the menu: the excess memory of the PIC16F628 will simply not be used. If you need to write a larger amount, then you should replace the MK type in the programmer menu with a memory size similar to PIC16F628 (in our case, it is PIC16F874 with 128 bytes EEPROM) and write in the usual way. You can change the type of MK in the menu at any stage of programming.

It should be noted that although the PIC16F874 has a program memory twice as large as the PIC16F628, you can write information to it by setting PIC16F874 and even PIC16F877 (16K) in the menu, however, when checking the record, the programmer will display an error message. The fact is that when reading a part of the memory that is not implemented in the PIC16F628, the MK will give out information recorded in the lower addresses (higher bits of the address are ignored), i.e. the program memory will be read twice (in the PIC16F877 - four times). In other words, this is not an error in the program, but a repeated reading of the memory, the program is written normally.

Literature

  1. Dolgiy A. Development and debugging of devices on the MK. - Radio, 2001, No. 6, p. 24-26: No. 7, p. 19-21.

Author: A.Sizov, Ivanovo

See other articles Section Microcontrollers.

Read and write useful comments on this article.

<< Back

Latest news of science and technology, new electronics:

Machine for thinning flowers in gardens 02.05.2024

In modern agriculture, technological progress is developing aimed at increasing the efficiency of plant care processes. The innovative Florix flower thinning machine was presented in Italy, designed to optimize the harvesting stage. This tool is equipped with mobile arms, allowing it to be easily adapted to the needs of the garden. The operator can adjust the speed of the thin wires by controlling them from the tractor cab using a joystick. This approach significantly increases the efficiency of the flower thinning process, providing the possibility of individual adjustment to the specific conditions of the garden, as well as the variety and type of fruit grown in it. After testing the Florix machine for two years on various types of fruit, the results were very encouraging. Farmers such as Filiberto Montanari, who has used a Florix machine for several years, have reported a significant reduction in the time and labor required to thin flowers. ... >>

Advanced Infrared Microscope 02.05.2024

Microscopes play an important role in scientific research, allowing scientists to delve into structures and processes invisible to the eye. However, various microscopy methods have their limitations, and among them was the limitation of resolution when using the infrared range. But the latest achievements of Japanese researchers from the University of Tokyo open up new prospects for studying the microworld. Scientists from the University of Tokyo have unveiled a new microscope that will revolutionize the capabilities of infrared microscopy. This advanced instrument allows you to see the internal structures of living bacteria with amazing clarity on the nanometer scale. Typically, mid-infrared microscopes are limited by low resolution, but the latest development from Japanese researchers overcomes these limitations. According to scientists, the developed microscope allows creating images with a resolution of up to 120 nanometers, which is 30 times higher than the resolution of traditional microscopes. ... >>

Air trap for insects 01.05.2024

Agriculture is one of the key sectors of the economy, and pest control is an integral part of this process. A team of scientists from the Indian Council of Agricultural Research-Central Potato Research Institute (ICAR-CPRI), Shimla, has come up with an innovative solution to this problem - a wind-powered insect air trap. This device addresses the shortcomings of traditional pest control methods by providing real-time insect population data. The trap is powered entirely by wind energy, making it an environmentally friendly solution that requires no power. Its unique design allows monitoring of both harmful and beneficial insects, providing a complete overview of the population in any agricultural area. “By assessing target pests at the right time, we can take necessary measures to control both pests and diseases,” says Kapil ... >>

Random news from the Archive

Silence in the operating room 10.02.2012

Observations made at the University Hospital of Bern (Switzerland) prove that there must be silence during the operation.

Surgeon Guido Beldi reviewed data from 35 patients undergoing the same abdominal surgery and compared it with the noise level during the operation recorded by the instruments. Six patients had complications due to the introduced infection. These operations differed only in that during their course the average noise level was 43,6 decibels instead of 25.

Beldi suggests that the extra noise, mainly associated with the conversations of the staff, prevented the participants in the operation from concentrating and therefore the strict antiseptic requirements were violated.

Other interesting news:

▪ Magnetoelectric effect of a symmetrical crystal

▪ Glowing fingerprints

▪ paper batteries

▪ Additional features of the touch sensor B6TS

▪ Now I understand why we need an appendix

News feed of science and technology, new electronics

 

Interesting materials of the Free Technical Library:

▪ section of the site RF power amplifiers. Article selection

▪ article Truly Russian Beginnings. Popular expression

▪ article Which shoe company gives away another pair of shoes to poor children for every pair of shoes they sell? Detailed answer

▪ Kohlrabi article. Legends, cultivation, methods of application

▪ article Convenient switch. Encyclopedia of radio electronics and electrical engineering

▪ article Switchgear with voltage up to 1 kV AC and up to 1,5 kV DC. Preface. Encyclopedia of radio electronics and electrical engineering

Leave your comment on this article:

Name:


Email (optional):


A comment:





All languages ​​of this page

Home page | Library | Articles | Website map | Site Reviews

www.diagram.com.ua

www.diagram.com.ua
2000-2024