Skip to Main Content
PIC Projects and Applications using C
book

PIC Projects and Applications using C

by David W Smith
December 2012
Intermediate to advanced content levelIntermediate to advanced
204 pages
3h 40m
English
Newnes
Content preview from PIC Projects and Applications using C
Chapter 4

Inputs

In order to use a digital input we need to ask the question, is the input high or low? Is it a logic 1 or 0?

If it is a 1 then we execute some code, if it is a 0 then we execute some other code. So we are asking the question, if the input is a certain value then execute the code. Let us look at the C code for this If statement.

IF Statement

The if statement looks like this:

if (condition)

{

Code

}

As an example if x is equal to 2 then make y = 6 and z = 4 would be:

if (x==2)

{

y=6;

z=4;

}

NB.  The expression x==2 means if x is equal to 2.

    The expression x=2 in C code means make x=2.

If there is only one line of code, say y = 6, then a shorthand way of writing this without the brackets {} is

if (x==2) y=6;

If–Else ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Computer Fundamentals and Programming in C (RMK)

Computer Fundamentals and Programming in C (RMK)

Anita Goel, Ajay Mittal
Jumpstarting C

Jumpstarting C

Wolfram Donat

Publisher Resources

ISBN: 9780080971513