Вы находитесь на странице: 1из 4

Appendix A: It is Time for Fun - Book: PIC Microcontrollers - Program...

Products

Solutions

http://www.mikroe.com/chapters/view/18/appendix-a-it-is-time-for-fun/

Store

Distributors

Libstock

Contact Us

search here

Login | Cart (0)

Book: PIC Microcontrollers - Programming in C


TOC Chapter 1 Chapter 2 Chapter 3 Chapter 4 Appendix A

Featured Development Tools


EasyPIC v7 Development System

Appendix A: Its Time for Fun


A microcontroller is a good-natured genie in the bottle and no extra knowledge is required to use it. In order to create a device controlled by
the microcontroller, it is necessary to provide the simplest PC, program for compiling and simple device to transfer code from PC to the chip
itself. Even though this process is quite logical, there are often some queries, not because it is complicated, but for numerous variations. Lets
take a look.

A.1 LET'S BEGIN...


A.2 PROGRAM COMPILATION
A.3 IS THIS A HAPPY ENDING?
A.4 DEVELOPMENT SYSTEMS

A.1 LET'S BEGIN...


Specialized programs in the Windows environment are used for writing a program for the microcontroller. This book describes one of them
called mikroC PRO for PIC. The main advantage of this program is that it features many additional tools installed to aid in the development
process.
If you have experience with program writing then you know that the point is to write all instructions in such an order they should be executed
by the microcontroller and observe the rules of C language. In other words, the program you are writing just has to follow your idea! Thats all!

EasyPIC v7 is top selling PIC


Development Board for 250 Microchip
PIC MCUs in DIP packaging. It features
USB 2.0 programmer/debugger and over
17 essential modules necessary in
development. Board comes with
PIC18F45K22. [more info]

Featured Compilers
mikroC PRO for PIC

Popular PIC micocontrollers are loved


by hobbyists and 8-bit geeks. mikroC
helps you bring your ideas to life easy as
never before. [more info]

A.2 PROGRAM COMPILATION


The microcontroller does not understand higher programming languages as such, so that it is necessary to compile the program into machine
language. A single click on the appropriate icon within the compiler results in creating a new document with .hex. It is actually the same
program, only compiled into machine language which the microcontroller perfectly understands. Such a program is usually called a hex code
and forms a seemingly meaningless sequence of hexadecimal numbers. When compiled, the program should be loaded into the chip. And you
need appropriate hardware to make this happen. In other words, you need a programmer.

1 of 4

3/28/2014 9:29 AM

Appendix A: It is Time for Fun - Book: PIC Microcontrollers - Program...

http://www.mikroe.com/chapters/view/18/appendix-a-it-is-time-for-fun/

As mentioned, to enable a hex code to be loaded into the microcontroller it is necessary to provide a special device, called the programmer,
with appropriate software. A large number of programs and electronic circuits used for this purpose can be found on the Internet. The
procedure is basically the same for all of them and looks as follows:

Place the microcontroller in appropriate programmers socket;


Use an adequate cable to connect the programmer to a PC;
Open hex code document within the programmers software, set a few parameters and click the icon to transfer the
code. After a few seconds, a sequence of zeros and ones is to be programmed into the microcontroller.
All thats left is to install the programmed chip into the target device. If it is necessary to make some changes in the program, the previous
procedure may be repeated an unlimited number of times.

A.3 IS THIS A HAPPY ENDING?


This section briefly describes the way of using the mikroC PRO for PIC program (compiler) and PICflash programming software. Everything is
very simple...
You have already installed mikroC PRO for PIC, havent you? Start it up, open a new project and a new document with extension .c within it.

2 of 4

3/28/2014 9:29 AM

Appendix A: It is Time for Fun - Book: PIC Microcontrollers - Program...

http://www.mikroe.com/chapters/view/18/appendix-a-it-is-time-for-fun/

OK. The program has been written and tested with the simulator. It did not report any errors during the process of compiling into the hex code?
It seems that everything is under control...
Yes, the program has been successfully compiled. All thats left is to load it into the microcontroller. Now you need a programmer consisting of
software and hardware. Start up the PICFlash program.
The settings are simple and there is no need for additional explanations (the type of the microcontroller, frequency and clock oscillator etc.).

Connect the PC and programmer hardware via a USB cable;


Load the HEX code using command: File -> Load HEX; and
Click the Write button and wait...

3 of 4

3/28/2014 9:29 AM

Appendix A: It is Time for Fun - Book: PIC Microcontrollers - Program...

http://www.mikroe.com/chapters/view/18/appendix-a-it-is-time-for-fun/

Thats it! The microcontroller is programmed and everything is ready for its operation. If you are not satisfied, make some changes in the
program and repeat the procedure. Until when? Until you feel satisfied...

A.4 DEVELOPMENT SYSTEMS


A device, which in the testing program phase can simulate any device is called a development system. Apart from the programmer, the power
supply unit and the microcontrollers socket, the development system also features components for input pin activation and output pin
monitoring. The simplest version has every pin connected to one push button and one LED. A high quality version has pins connected to LED
displays, LCD displays, temperature sensors and all other components that a target device can be comprised of.

If needed, all these peripherals can be connected to the MCU via jumpers. This enables the whole program to be tested in practice even
during its development stage, because the microcontroller doesnt know or care whether its input is activated by a push button or a sensor
built in a true device.
If you have some of the development systems, the process of programming and testing a program is even simpler. Concerning that the
mikroC PRO for PIC compiler (on your PC) and the PICflash programmer hardware (on your development system) cooperate perfectly, the
process of compiling a program and programming the microcontroller is performed in a single step - by clicking the Build and Program icon
within the compiler. Now, any change in the program will immediately affect the operation of some of the development systems components.
Do you now agree with us that its time for fun?
previous chapter | table of contents

Find us on Facebook

PIC Solution

dsPIC Solution

STM32 Solution

Find us on YouTube

8051 Solution

Add-on boards

PIC Development Boards

dsPIC Development Boards

STM32 Development Boards

8051 Dev. Boards

Click Boards

PIC Compilers

dsPIC Compilers

STM32 Compilers

8051 Compilers

mikromedia shields

PIC Programmers/Debuggers

dsPIC Programmers/Debuggers

STM32 Programmers/Debuggers

8051 Programmers

Communication

PIC Kits

dsPIC Kits

STM32 Kits

8051 Books

Storage

PIC Books

dsPIC Books

8051 Kits

Real Time Clock

PIC32 Solution

Tiva C Series Solution

AVR Solution

Tiva C Development Boards

Additional Software

PIC32 Development Boards

AVR Development Boards

Tiva C Compilers

Visual TFT

PIC32 Compilers

AVR Compilers

Tiva C Programmers/Debuggers

Visual GLCD

PIC32 Programmers/Debuggers

AVR Programmers/Debuggers

Tiva C Kits

Package Manager

PIC32 Kits

AVR Kits

Measurement
Audio & Voice
Power Supply
GPS

GLCD Font Creator

GSM/GPRS

Timer Calculator

Support

Forum

mikroBUS

Lets make

Press

Legal

Archive

Display

About Us

Customization

Copyright 1998 - 2014. MikroElektronika. All rights reserved. All trade and/or services marks mentioned are the property of their respective owners.

4 of 4

3/28/2014 9:29 AM

Вам также может понравиться