PIC Microcontroller

The PIC16F84 Microcontroller Part 1

In this topic we introduce the PIC16F84 MCU, which we will use as our baseline exemplar for the rest of the text. Here we will primarily look at internal structure, reserving external interfacing considerations for Part 3 of the topic. After reading this topic you should: • Recognize the difference between a microprocessor and microcontroller. […]

The PIC16F84 Microcontroller Part 2

Execute The execution circuitry is centered around the Arithmetic Logic Unit (ALU) – see Fig. 2.19.The ALU processes data from up to two sources. One of these is the 8-bit Working register. The other can be multiplexed either from a file in the Data store or an 8-bit literal, which is part of the instruction […]

The PIC16F84 Microcontroller Part 3

Timer Most MCUs have facilities to either measure elapsed time and/or to generate digital on/off waveforms with well defined durations. This is normally based around one or more counters that are incremented either from an external pulse or internal clock. For instance, if an automatic packing machine needs to count cans of beans going along […]

The Instruction Set Part 1 (PIC Microcontroller)

If you like to think of writing a program as analogous to preparing an elaborate meal, then for any given cooking appliance, such as a microwave oven or electric stove (the hardware) there are a range of processes. These processes – for example, steaming, frying, boiling – are analogous to the instruction set which can […]

The Instruction Set Part 2 (PIC Microcontroller)

Movement instructions Around one in three instructions move data around without alteration. With this in mind the instructions in Table 5.1 will be the most used in the repertoire. All three Move instructions can copy byte data to or from the Working register. Table 5.1: Move instructions. • movlw copies the specified 8-bit constant (or […]

The Instruction Set Part 3 (PIC Microcontroller)

The PIC 12/14-bit cores have two instructions which can shift a datum byte in a file register one place left or right. Both rlf and rrf are known as Circular or Rotate instructions. These shift left or right respectively with the incoming bit injected in from the Carry flag and outgoing bit popped out into […]

The Instruction Set Part 4 (PIC Microcontroller)

Example 5.3 Write a routine to convert a binary number of magnitude no greater than 63h (decimal 99) in File 20h to two BCD digits in File 21:2h ordered as Tens:Units. Solution A possible algorithm to implement this binary to BCD conversion is to divide by ten; this generates a quotient between 0 and 9 […]

Subroutines and Modules Part 1 (PIC Microcontroller)

Good software should be configured as a set of interacting modules rather than one large program working straight through from beginning to end. There are many advantages to modular programming, which is almost mandatory when code lengths exceed a few hundred lines or when a project is being developed by a team. What form should […]

Subroutines and Modules Part 2 (PIC Microcontroller)

As K is tested for zero after the 100 ms delay is executed7 an initial value of K = 0 will be treated as K = 256, giving a delay range of 00.125.6 s. Testing before the loop8 would give a range 0-25.5 s. Actually, the delay will be a few ^s longer than the […]

Subroutines and Modules Part 3 (PIC Microcontroller)

As an example, consider a stack-oriented version of the multiplication subroutine of Program 6.5. A view of the software stack from the perspective of this new coding is shown in Fig. 6.8. Based on this diagram, in order to call up this subroutine the following procedure has to be implemented: 1. Push the Multiplicand and […]