📜 ⬆️ ⬇️

Programming PIC16 / PIC18 microcontrollers in C. The article is introductory

Good day to you, good man.

This is an introductory article from a small cycle about programming the IC PIC16 / 18 in C.

Required minimum:
BY:
- MPLAB;
- C compiler itself;
- Proteus ISIS;
Iron:
- debug board;
- programmer.
')
MPLAB is Microchip's development environment. You can download on ofsayte. Totally free.
Contains a compiler with assembly language, allows you to spend a full development cycle including firmware (if you have the appropriate programmer).
Most C compilers have mechanisms for embedding into this environment.
We swing necessarily .

Compiler c .
Here is a little more difficult with the choice.
A list of what I advise you to pay attention to:
- CCS PICC;
- Micro-C;
- IAR C;
- HT-PICC;
- Microchip C18;



CCS PICC . Paid. It contains a good IDE. Integration with MPLAB using a plugin is possible.
There is a demo version with a limit on the size of the code and some features disabled.
You can learn about it in a very good book by Comrade Shpak “Programming in C language for AVR and PIC microcontrollers” .
Very good. Used by many. There is enough information on the net. A vaccine exists.

Micro-C . Paid. From digging mikroElektronika . It contains a very convenient IDE, a simulator and a small set of useful tools.
A wide range of supported devices.
The main plus for a beginner is a huge library of modules and examples for them. This parameter has no analogues.
There is documentation in Russian. A vaccine exists.
The best choice for a beginner, but no more.

IAR C. Paid. Very voluminous project. Support a huge number of devices and PIC18 as well.
There are probably no analogs in functionality and capabilities.
The demo version exists, with limitations naturally.
Not the best choice for a newbie . Well suited in the future, if the desire to work with the MC is not lost :-)

HT-PICC . Paid. Support many devices. There are versions for Linux and Mac.
Will be used by me in articles for programming PIC16 .
My version is 8.05PL1 .

Microchip C18 . Paid. There is a student version with full functionality for 2 months.
Will be used by me in articles about programming PIC18 .
My version is 3.33 .

go further.

Proteus ISIS . One of the components of the project Proteus from Labcent Electronics .
Simulator debugger. The best option when you do not have the necessary iron.
Information about him on the network abound.
We swing necessarily .
My version is 7.5_SP3 .

Iron
I will not advise a particular debug board or circuit for it because of the difficulties of buying / soldering / pulling for each individually.
Let me just say that I will give examples for the PIC16F628A and PIC18F4550.
With the programmer, in principle, the same thing. But I advise PICkit2 .

Now practice .
First I will talk about the PIC16 .
Well, for the introductory article, we will write and run the simplest program.

Download MPLAB. I have version 8.36 .
Download HT-PICC. My version is 8.05PL1 .
Download Proteus. My version is 7.5_SP3 .
Everything is installed - everything works.
We carry out all the recommendations for installation.
If it does not work, we solve problems.

Run MPLAB .
Go to Project -> Set Language Tool Locations . We are looking for in the list of HI-TECH PICC Toolsuite .
Open Executables . And we indicate for the compilers and the linker the installation path. Click OK.

image

Click Project -> Project Wizard . Select the PIC16F628A . Choose HI-TECH PICC Toolsuite . Select the name of the new project.
We get an empty project.
Click File -> New . Save the file in the project folder as main.c.
Click in the project manager at Source Files -> Add files and add our main.c

Write the code:

void main(void)
{
while(1);
}


Click F10.
Must see a success message.

image

A file with a .hex extension will appear in the project root.
With this file you can flash the MK and see how it does nothing :-)
In this I just wanted to help make a choice, and set up the software for further work.

In principle, I was going to highlight in a cycle questions about the basics of C for MK.
Show examples for most of the PIC16F628A and PIC18F4550 hardware modules.
Show examples of PIC18F4550 with USB.
Tell about the intricacies of C for such devices.

I would like to know if there is interest in Habré for this?

Source: https://habr.com/ru/post/75303/


All Articles