Building a Programmable Logic Controller with a PIC16F648A Microcontroller: 1st Edition (Hardback) book cover

Building a Programmable Logic Controller with a PIC16F648A Microcontroller

1st Edition

By Murat Uzam

CRC Press

371 pages | 246 B/W Illus.

Purchasing Options:$ = USD
Paperback: 9780367379537
pub: 2019-07-31
Available for pre-order
Hardback: 9781466589858
pub: 2013-08-28
eBook (VitalSource) : 9781315215693
pub: 2017-12-19
from $28.98

FREE Standard Shipping!


Programmable logic controllers (PLCs) are extensively used in industry to perform automation tasks, with manufacturers offering a variety of PLCs that differ in functions, program memories, and the number of inputs/outputs (I/O). Not surprisingly, the design and implementation of these PLCs have long been a secret of manufacturers. Unveiling the mysteries of PLC technology, Building a Programmable Logic Controller with PIC16F648A Microcontroller explains how to design and use a PIC16F648A-microcontroller-based PLC.

The author first described a microcontroller-based implementation of a PLC in a series of articles published in Electronics World magazine between 2008 and 2010. This book is based on an improved version of the project, including:

  • Updates to the hardware configuration, with a smaller CPU board and two I/O extension boards that now support 16 inputs and 16 outputs instead of 8
  • An increased clock frequency of 20 MHz
  • Improvements to several macros
  • Flowcharts to help you understand the macros (functions)

In this book, the author provides detailed explanations of hardware and software structures. He also describes PIC Assembly macros for all basic PLC functions, which are illustrated with numerous examples and flowcharts. An accompanying CD contains source files (.ASM) and object files (.HEX) for all of the examples in the book. It also supplies printed circuit board (PCB) (Gerber and .pdf) files so that you can have the CPU board and I/O extension boards produced by a PCB manufacturer or produce your own boards.

Making PLCs more easily accessible, this unique book is written for advanced students, practicing engineers, and hobbyists who want to learn how to build their own microcontroller-based PLC. It assumes some previous knowledge of digital logic design, microcontrollers, and PLCs, as well as familiarity with the PIC16F series of microcontrollers and writing programs using PIC Assembly language within an MPLAB integrated development environment.


"Programmable logic controllers are an integral part of advanced manufacturing and industrial automation. This text allows someone who does not have all of the resources found in a mechatronics lab the possibility to use a PLC in their machine or robot design with a simplified and easily mastered programming language. … It is a well thought-out and detailed application of the PIC microcontroller to the programmable logic controller."

—Thomas Stout, Tidewater Community College, Virginia Beach, USA

Table of Contents

Hardware of the PIC16F648A-Based PLC

Basic Software

Basic Software Structure

Elimination of Contact Bouncing Problem in the PIC16F648A-Based PLC

Basic Macros of the PIC16F648A-Based PLC

An Example Program

Contact and Relay-Based Macros

The Macro ld (load)

The Macro ld _ not (load not)

The Macro not

The Macro or

The Macro or _ not

The Macro nor

The Macro and

The Macro and _ not

The Macro nand

The Macro xor

The Macro xor _ not

The Macro xnor

The Macro out

The Macro out _ not

The Macro in _ out

The Macro inv _ out

The Macro _ set

The Macro _ reset

Examples for Contact and Relay-Based Macros

Flip-Flop Macros

The Macro r _ edge (Rising Edge Detector)

The Macro f _ edge (Falling Edge Detector)

The Macro latch1 (D Latch with Active High Enable)

The Macro latch0 (D Latch with Active Low Enable)

The Macro dff _ r (Rising Edge Triggered D Flip-Flop)

The Macro dff _ f (Falling Edge Triggered D Flip-Flop)

The Macro tff _ r (Rising Edge Triggered T Flip-Flop)

The Macro tff _ f (Falling Edge Triggered T Flip-Flop)

The Macro jkff _ r (Rising Edge Triggered JK Flip-Flop)

The Macro jkff _ f (Falling Edge Triggered JK Flip-Flop)

Examples for Flip-Flop Macros

Timer Macros

The On-Delay Timer (TON)

The Macro TON _ 8 (8-Bit On-Delay Timer)

The Off-Delay Timer (TOF)

The Macro TOF _ 8 (8-Bit Off-Delay Timer)

The Pulse Timer (TP)

The Macro TP _ 8 (8-Bit Pulse Timer)

The Oscillator Timer (TOS)

The Macro TOS _ 8 (8-Bit Oscillator Timer)

An Example for Timer Macros

Counter Macros

Move and Load Macros

Counter Macros

The Up Counter (CTU)

The Macro CTU _ 8 (8-Bit Up Counter)

The Down Counter (CTD)

The Macro CTD _ 8 (8-Bit Down Counter)

The Up/Down Counter (CTUD)

The Macro CTUD _ 8 (8-Bit Up/Down Counter)

Examples for Counter Macros

Comparison Macros

The Macro R1 _ GT _ R2

The Macro R1 _ GE _ R2

The Macro R1 _ EQ _ R2

The Macro R1 _ LT _ R2

The Macro R1 _ LE _ R2

The Macro R1 _ NE _ R2

The Macro R _ GT _ K

The Macro R _ GE _ K

The Macro R _ EQ _ K

The Macro R _ LT _ K

The Macro R _ LE _ K

The Macro R _ NE _ K

Examples for Comparison Macros

Arithmetical Macros

The Macro R1addR2

The Macro RaddK

The Macro R1subR2

The Macro RsubK

The Macro incR

The Macro decR

Examples for Arithmetical Macros

Logical Macros

The Macro R1andR2

The Macro RandK

The Macro R1nandR2

The Macro RnandK

The Macro R1orR2

The Macro RorK

The Macro R1norR2

The Macro RnorK

The Macro R1xorR2

The Macro RxorK

The Macro R1xnorR2

The Macro RxnorK

The Macro invR

Example for Logical Macros

Shift and Rotate Macros

The Macro shift _ R

The Macro shift _ L

The Macro rotate _ R

The Macro rotate _ L

The Macro Swap

Examples for Shift and Rotate Macros

Multiplexer Macros

The Macro mux _ 2 _ 1

The Macro mux _ 2 _ 1 _ E

The Macro mux _ 4 _ 1

The Macro mux _ 4 _ 1 _ E

The Macro mux _ 8 _ 1

The Macro mux _ 8 _ 1 _ E

Examples for Multiplexer Macros

Demultiplexer Macros

The Macro Dmux _ 1 _ 2

The Macro Dmux _ 1 _ 2 _ E

The Macro Dmux _ 1 _ 4

The Macro Dmux _ 1 _ 4 _ E

The Macro Dmux _ 1 _ 8

The Macro Dmux _ 1 _ 8 _ E

Examples for Demultiplexer Macros

Decoder Macros

The Macro decod _ 1 _ 2

The Macro decod _ 1 _ 2 _ AL

The Macro decod _ 1 _ 2 _ E

The Macro decod _ 1 _ 2 _ E _ AL

The Macro decod _ 2 _ 4

The Macro decod _ 2 _ 4 _ AL

The Macro decod _ 2 _ 4 _ E

The Macro decod _ 2 _ 4 _ E _ AL

The Macro decod _ 3 _ 8

The Macro decod _ 3 _ 8 _ AL

The Macro decod _ 3 _ 8 _ E

The Macro decod _ 3 _ 8 _ E _ AL

Examples for Decoder Macros

Priority Encoder Macros

The Macro encod _ 4 _ 2 _ p

The Macro encod _ 4 _ 2 _ p _ E

The Macro encod _ 8 _ 3 _ p

The Macro encod _ 8 _ 3 _ p _ E

The Macro encod _ dec _ bcd _ p

The Macro encod _ dec _ bcd _ p _ E

Examples for Priority Encoder Macros

Application Example

Remotely Controlled Model Gate System

Control Scenarios for the Model Gate System

Solutions for the Control Scenarios

Solution for the First Scenario

Solution for the Second Scenario

Solution for the Third Scenario

Solution for the Fourth Scenario

Solution for the Fifth Scenario

Solution for the Sixth Scenario

Solution for the Seventh Scenario

Solution for the Eighth Scenario

About the CD-ROM



About the Author

Dr. Murat Uzam is a professor in the Department of Electrical and Electronics Engineering at Meliksah University in Kayseri, Turkey.

Subject Categories

BISAC Subject Codes/Headings:
COMPUTERS / Computer Engineering
TECHNOLOGY & ENGINEERING / Electronics / Circuits / General
TECHNOLOGY & ENGINEERING / Electronics / Microelectronics