New Chapter 3 Programming C
New Chapter 3 Programming C
CHAPTER 3
PIC PROGRAMMING IN C
INTRODUCTION
An embedded system is a combination of computer hardware and software designed for a
specific function.
Real-time operating
Software and firmware. system.
Software for embedded systems Real-time operating system.
can vary in complexity. These are not always included
Embedded system programming Hardware in embedded systems,
is computer software, which is especially smaller-scale
The hardware of
used to control devices by systems. RTOSes define how
embedded systems is
providing a set of instructions. the system works by
based around
firmware various devices with supervising the software and
microprocessors and
various functionalities can be setting rules during program
microcontrollers.
programmed using embedded execution.
software, by maintaining design
constraints and storing the final
data in memory (RAM/ ROM).
The following are some of major reason for writing programs in C instead of Assembly:
It is easier and
less time consuming.
C is easier to
modify and update. You can use code
. available in function
libraries.
C code is portable to
other microcontrollers
with little or no
modification
Compile the
Write a program
The following are the steps of program to convert
(example, using it to machine
programming an embedded C language). language
system: (in binary/hex).
01 .
04 02
03
Finally placed the
microcontroller chip on the The program will be burned
control circuit of into a microcontroller chip
the real application for using a special circuit called
example robot arm. programmer/burner.
Example of a simple
program written in C
language:
Example of program
structure in C language
for PIC microcontroller.
FUNCTION
• The main idea is to divide a program into several parts using these functions in
order to solve the actual problem easier.
STRUCTURE
• Every function must be properly declared so as to be properly interpreted during
the process of compilation.
• Declaration contains the following elements:
Function name
Function body
List of parameters
Declaration of parameters
Type of function result
.
COMMENT
• Comments are part of the program used to clarify the operation of the program or
provide more information about it.
• Comments are ignored and not compiled into executable code by the compiler.
• The compiler can recognize special characters used to designate where comments
start and terminate and completely ignores the text in between during compilation.
C Data Types
DELAY FUNCTION IN C
• A time delay is something that is very important when working with
embedded applications, because there are times you want a delay before
something is begun.
• Time delays can also be used for breaks between processes. For example,
a time delay in between an LED can make the LED blink on and off, on and off,
repeatedly. So time delays can be very useful and important for embedded
applications.
• A __delay_ms() is not a real function, it is a macro which will expand into in-line
assembly instructions or a nested loop of instructions which will consume the sp
ecified number of time.
EXAMPLE 1
This C program exits in ten seconds, after the printf function is executed the program waits
for 10000 milliseconds or 10 seconds and then it terminates.
EXAMPLE 2
If you don't wish to use delay function then you can use loops to produce delay in a C program.
Thank you
SEE YOU ON END OF CHAPTER 1