Electronic Circuits and Tutorials
Home > Engineering Projects > Prof. Dr. Marco Gottardo Projects > Creating the Design and Simulation
New Course in Programming PIC Microcontrollers

Creating the Design and Simulation

Author: Prof. Dr. Marco Gottardo
Email:  ad.noctis@gmail.com

Prof. Dr. Marco Gottardo

Lets Go PIC - Microcontroller Tutorial Book

Let's GO PIC!!! The book
By Marco Gottardo

Marco Gottardo collects in this volume the gist of 20 years of instruction and job in the field of electronics and automation. The text represents the first volume of a series even oriented to the self-taught, that it will supply solid slight knowledge, although basic in the programming of microcontrollers PIC. Inside the book there are numerous problems and exercises and term papers completely unrolled and totally school developed which are milestones for each industrial automation course proper.

Noteworthy chapters devoted to understanding interrupts, analog signals, and use of the LCD display. The treated language is HITECH C included on MPLAB IDE and the Hardware Platform is the Micro-GT mini and i.d.e, easily found on the net. I have also explained the LadderPIC language that will allow to program microcontrollers with PLC mode. The volume will be followed by the text "Let's Make Robots!" in distribution from December 2012. This volume gives the basis for robotics.


This page is midway between being a tutorial and a simple project "Hello World". what every novice of the PIC must have executed at least once in their life. The article is designed to be brief and concise. All that is in addition it was removed or moved to an appendix at the end of page to avoid wasting time

Setting the compiler

First, understand the basic concept that is comfortable to use tools of the official manufacturer. And I say this reluctantly because I am a convinced promoter dell'opersurce, linux, etc. But if we do not leave everyone with the same foot there will understand. 'nuff said, and then begin.

Let's all about: www.microchip.com and discharge MPLAB IDE.

The direct link is:

However you will find it easily without using this link.

The installation is quite simple, almost always suffice to say YES to every question, but be sure, one of the questions will be relevant to "add the environment variable to the path" this is important to say "yes" for not having then compilation errors.

During installation you will find that a product of another company is called and installed. This is the C compiler for PIC16, which will then be recognized as from the HITECH UNIVERSAL TOOL SUIT what skills to compile pic 12.16.10. for the moment we learn to use these.

Activating the second default

Double clicking on the icon of MPLAB that appeared on the desktop is active, the development environment. By default this is set to MPASM allows the compilation of programs written in assembly. We should change this default and enable the universal Hi-tech tool suite that has already been installed at the same MPLAB.

Inserting the elementary libraries

The first program will be extremely trivial, but highly educational. The purpose of this first lesson is not imprare the "C" but just plain to be able to move with agility in the environment.

Create a folder in your Documents folder "pic_project" and download and unpack inside this zip file.

UserFiles / ad.noctis / File / ciao_mondo.zip

Inside there are 4 files:

  • scheletro.c
  • delay.h
  • delay.c
  • ciao_mondo.mcp

The first, scheletr.c, contains a draft working program that I created for you in order to avoid unnecessary "suffering awful" the scope of this first "lecture-tutorial" in Appendix I explain how it works and what it does.

Know that until you have enough experience you will start ALL YOUR NEW PROGRAM using this skeleton. In fact, with appropriate modifications can become anything else.

Only with respect to this first test you can give up the files in the root directory of the small project, since it is assumed that first graduation since you do not there are others. Just have a little more experience, the most-project folder will contain a folder with the name of each program you want to achieve.

There I said it, but it is obvious that this test only for the file will continue to call scheletro.c but in future it will change as a first step in vostro_nome_programma.c
 

Two files have the same name but different extension. Spegherò in the lessons of "C" it means and why it is so, for the moment is more important to know where they stand and how to use them. Moreover, already named one senses that generate a delay.

Just for this first test we let the libraries folder pic_project. You'll soon discover that it will be cheaper likarle a more natural position which is the folder "includes" compiler, available from c: programmiHI-TECH Softwarepicc9.70include but this will involve a small change in the line include command in the source scheletro.h

The fourth file is the "project". It 's one thing that I added but I really do not need to go. Will serve those who just can not get out, because clicking on it ... if you link the files in the place that I have indicated, all automatically activated. This file is automatically created during the "Project Wizard" that I am going now to explain.

Departure

The adventure begins from here. Street with the stopwatch. in the 10 minutes we get there.

Click on project-> project_wizard
 

.

You will see a welcome screen that indicates this activation of the automatic process of creating the project. The term "project" means a container for all the support files that will be part of what we are about to create.

THE first step "new project assistant" asks us to select the desired controller "device" that we want to use. I recommend using the 16F877A. This is a 40 pin dual in line. Powerful, comprehensive and easy to use.

The second step is to select the compiler choir. If we fail here, there will be anomalous behavior in the later stages with the resulting non-operation. be sure to select as shown.

The third step asks you to name the project. It must be clear computer the concept of "project". This is a "folder" that a single file. In many applications to create a project means see appear a true and proper folder and see files automatically insert them inside. For the MPLAB project file with a red icon and extension of Mpalb mcp (mcrochip project). This file allows the platform to correlate MPLAB files during linkage. For this reason it is appropriate that they're all inside a folder. If you have not already created (the pic_project) do so before continuing.
 

Give the name of the project is not enough. is also essential to tell the browser (manager of the operating system folder) to put the files created and where to link them (link them) to create the hex file (the. hex) which is the single transferable in the memory of the PIC. (Similar concept to every other microcontroller).
 

As we see in the image we're going to save the project we are creating the folder pic_project we have prepared the documents folder.

At this point we are shown the path we decided to save. If it matches the expectations just plain confirm by clicking below.

The fourth step is to put the files in the project. So you'll see in the picture below. This situation appears only if you followed the previous instructions to the letter.
 

How easily we see on the left column we see the browser in which pic_project the folder and its contents. We must then add the three files by clicking on it and acting on "Add"

here is the situation after the insertion of files

Preview the project proposal is that we are going to create. If you confirm all matches with expectations.

We are close to the end. once confirmed will be opened automatically only the project tree, usually on the left, and it looks like a set of open folders whose meaning and purpose will be explained at the time. Also opens a window named output, initially empty. This window will show the output of the compilation, ie the account that is gone or less successful construction of the file. Hex other information.

By double-clicks on the file scheletro.c opens the programming editor. Here below the result.

As already said, now is not the time to start commenting the code. We must learn to use fluently the editor and in particular the compiler. So .... compile.

The build commands are those two squares red and blacks viciono the word "checksum"

If you have logged out from the subject by clicking on this button you will see from compiling with the effect shown below.
 

The display shows "Build successful!" indicates that the file was cretao. hex that will have the same project name and file. c which contains the main (inmancabile each program in c).

Let's see what was the effect of looking at the build output folder that contains the project.

Many, many files were created. All features are useful for the project, but only one is transferred to the memory of the PIC. This is "ciao_mondo.hex". to transfer the file must munisirsi of a programmer.

Stop the clock!

If you have some familiarity with the operating system should have done everything in about 10 minutes.

There is also the opportunity to work under linux, who wanted to challenge themselves scarici sdcc, but for now do not talk about because it is not topic of this article guide.

And 'possible to test the operation of the program using the program real PIC simulator.

And 'free downloadable version. contact me if you do not find that I do see where fi.

Clicking on this icon should start the simulator. Its operation is very simple.

  1. load the file ciao_mondo.hex
  2. we click and drag the red towards the center of the page, appears the LED bar
  3. we set the bar led by clicking on the first affecting assigning PORTB 0
  4. We click on the green triangle and MAGIC! If you followed my directions to letere the LED blinks

Welcome to the wonderful world of PIC programming in C.

Appendix at the end of page.

The adventure to begin the great should supply a development system and a demo board able to meet the needs at least the first educational programs. To this end I have posted on my site a number of rather well-fed electronic cards with different capabilities.
 

The latest, which is also the most powerful as well as the most complete Micro-GT is the versatile IDE (integrated Developed environment).

One sample tested and proven you see in the picture below.

The various courses of programming gilds MICROPIC I intend to propose, first, with reference to the school where I teach, students employed engineering from the University of Padua (ALSI), at various training centers, and if the public will also require free of charge / popular, grix here on, will be based on this development system.

The project, including diagrams, eagle files, gerber files constructive, demonstration exercises, equipment and software are already available on grix and on my personal website.

If someone wants to spare themselves the burden of the homebrew PCBs I can send it to him since that I have in stock a few samples. Anyone interested contact me personally.

Briefly summarize the technical characteristics of this development system.

  • 1 H-bridge up to 8 amps of power for driving the DC motor.
  • L298 1 for driving a stepping motor or two DC motors up to 2 Amps
  • 4 digit seven segment flyable type exercises for multiplexed BCD counters, clocks, thermometers, etc..
  • 8-channel analog (for processors that support them) simulated with trimmer.
  • prepared for 1 LCD 2 lines x 16 characters.
  • designed for a graphical display 128 x 64 points.
  • 14 digital outputs onboard (red LEDs) available to the board
  • 16 digital input switchable in groups of 4 as NC or NO with pullup or pulldown.
  • 1 RS232 bi-functional, programming or supervision.
  • Dual 20MHz quartz or 4Mhz for maximum compatibility with micro available.
  • all points of I / Os are accessible accessible in free access (portable field)
  • double-cross connector ICSP (in circuit serial programming) can not remove the chip.

The system recognizes the following PICs:

The following c ontroller have been tested and are fully supported:

    • PIC10F200
    • PIC12C508A, PIC12CE518
    • PIC12F629, PIC12F509, PIC12F675, PIC12F508
    • PIC16F54, PIC16F5 7
    • PIC16F84A
    • PIC16F88
    • PIC16F505, PIC16F627, PIC16F627A, PIC16F628, PIC16F628A, PIC16F630, PIC16F676, PIC16F690
    • PIC16F870, PIC16F871, PIC16F872, PIC16F873, PIC16F874
    • PIC16F785,
    • PIC16F870, PIC16F871, PIC16F872, PIC16F873A, PIC16F876, PIC16F876 A, PIC16F877, PIC16F877 A
    • PIC16F8 83
    • PIC16F627, PIC16F627A, PIC16F628, PIC16F628A
    • PIC16F648A, PIC16F630, PIC16F676
    • PIC18F 1320, PIC18F2 320, PIC18F2550, PIC18F 4320, PIC18F2 450. PIC18F2550
    • Many other unproven but compatible with earlier, also 18 series.

I can only wish all good work, and why not have fun .... 


Note: To report broken links or to submit your projects, tutorials please email to Webmaster