Programming the Finite State Machine with 8-Bit PICs in Assembly and C

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Andrew Pratt provides a detailed introduction to programming PIC microcontrollers, as well as a thorough overview of the Finite State Machine (FSM) approach to programming. Most of the book uses assembly programming, but do not be deterred. The FSM gives a structure to a program, making it easy to plan, write, and modify. The last two chapters introduce programming in C, so you can make a direct comparison between the two techniques. The book references the relevant parts of the Microchip datasheet as familiarity with it is the best way to discover detailed information. This book is aimed at Microsoft Windows and Linux users. To keep your costs to a minimum and to simplify the toolchain, specific applications are provided as a free download to enable you to use an FTDI serial lead as the programmer. The assembler used is the open-source "gpasm". All programming can be done in a text editor. There are detailed instructions on how to perform the necessary installations on Windows, Linux Debian, and derivatives such as Ubuntu and Fedora. For programming in C, Microchip's XC8 compiler is used from the command line. In addition to the programming applications, two serial read and serial write applications can be used for communicating with the PICs from a computer. A voltmeter project including practical instructions on building a circuit board from scratch is included. All theory is covered beforehand, including how to do integer arithmetic in assembly. Two PICs are covered: the PIC12F1822 and the PIC16F1823. Both can run at 32 MHz with an internal oscillator. You do not need to buy a factory-made development board and programmer. With relatively inexpensive parts including a serial lead, microcontroller, a few resistors, and LEDs, you can get started exploring embedded programming.

Author(s): Andrew Pratt
Publisher: Elektor Publication
Year: 2023

Language: English
Pages: 188

Programming the Finite State Machine
Table of Contents
Preface
Chapter 1 • Getting Started
1.1 • Introduction
1.2 • Practical Implementation
1.3 • Some Fundamentals
1.4 • Program Memory
1.5 • Hello World
Chapter 2 • The Assembly Program as a Finite State Machine
2.1 • Introduction
2.2 • A State Machine Framework for Assembly Language
2.3 • Timer0
2.4 • Interrupts
2.5 • A More Complicated LED Flasher
2.6 • Running More Than One Machine in a Program
2.7 • Driving a Seven Segment LED Display
2.8 • The Differences Between the PIC 12F1822 and the 16F1823
2.9 • Interrupts and State Diagrams
Chapter 3 • Macros, Subroutines and Bank Switching
3.1 • Introduction
3.2 • Create Your Own Instruction
3.3 • Subroutines
3.4 • Bank Switching
Chapter 4 • Inputs and Outputs
4.1 • Introduction
4.2 • Serial Output to a Computer
4.3 • Serial Input from a Computer
4.4 • Analog Inputs
4.5 ● Pulse with modulated outputs
4.6 ● Digital Inputs
Chapter 5 • Project Hardware Construction
5.1 • Introduction
5.2 • Overview of the Suggested Method
5.3 • Cutting and Drilling the board
5.4 • Populating and Wiring the Board
5.5 • The Circuit Board Test Program
Chapter 6 • Binary Arithmetic
6.1 • Introduction
6.2 • Binary Addition of Unsigned Numbers
6.3 • Binary Subtraction of unsigned integers
6.4 • Binary Subtraction with Negative Results
6.5 • Negative numbers in binary
6.6 • Binary Multiplication
6.7 • Binary Division
Chapter 7 • Digital Voltmeter Project
7.1 • Introduction
7.2 • The State Diagrams
7.3 • Scaling the Raw Analog Value
7.4 • Extracting the individual figures for the display
7.5 • Detecting No Input Voltage
7.6 • Recalibration
Chapter 8 • Troubleshooting and Planning
8.1 • Introduction
8.2 • Have an Overview of the Project
8.3 • Break Big Problems Down Into Smaller Ones
8.4 • Read Through Your Code in Detail and Add Comments
8.5 • Debugging a Running Program
8.6 • Traffic Lights
8.7 • Using Debug Macro on the Voltmeter Programmable
8.8 • A List of Things to Remember
Chapter 9 • A Comparison with C
9.1 • Introduction
9.2 • The Microchip XC8 Compiler
9.3 • Introduction to C
9.4 • Serial Communication
Chapter 10 • Further C
10.1 • Introduction
10.2 • Data Types
10.3 • More on Functions
10.4 • Integer Arithmetic
10.5 • The Voltmeter in C
10.6 • Summary of Assembly, C, and Finite State Machines
Index