Microcontroller Operation:Program Operations

Program Operations

We can see in Appendix A that a machine code program consists of a list of binary codes stored in the microcontroller memory. They are decoded in sequence by the processor block, which generates control signals that set up the microcontroller to carry out the instruction. Typical operations are:

• Load a register with a given number.

• Copy data from one register to another.

• Carry out an arithmetic or logic operation on a data word.

• Carry out an arithmetic or logic operation on a pair of data words.

• Jump to an alternative point in the program.

• Test a bit or word and jump, or not, depending on the result of the test.

• Jump to a subroutine, and return later to the same point.

• Carry out a special control operation.

The machine code program must be made up only from those binary codes that the instruction decoder will recognize. These codes can be read off from the instruction set given in the data sheet. When computers were first developed, this was exactly how the program was entered, in binary, using a set of switches. This is obviously time consuming and inefficient, and it was soon realized that it would be useful to have a software tool that would generate the machine code automatically from a program written in a more user-friendly form. Assembly language programming was therefore developed, when computer hardware had moved on enough to make it practicable.

Assembly language allows the program to be written using mnemonic (memorable) codes.

Each processor has its own set of instruction codes and corresponding mnemonics. For example, a commonly used instruction mnemonic in PIC programs is ‘MOVWF’, which means move (actually copy) the contents of the working register (W) to a file register that is specified as the operand. The destination register is specified by number (file register address), such as 0Ch (the first general purpose register in the PIC 16F84A). The complete instruction is:

MOVWF 0C

This is converted by the assembler software (MPASM.EXE) to the hexadecimal code specified in the instruction set:

008C

The binary code stored in program memory is therefore

0000001 0001100

Note that the instruction is 14 bits in total, with the operand represented, in this case, by the last seven bits, and the operation code the first seven. The op-code bits are used by the

instruction decoder to select the correct source and destination registers (W and SFR 0C) prior to the operation. A following clock edge will then trigger the copy operation on the internal data bus.

There are two main types of instruction, with four identifiable subgroups within each:

PIC Microcontrollers-1132

Together, these types of operations allow inputs to be read and processed, and the results stored or output, or used to determine the subsequent program sequence.

A complete assembly language example is shown in the final section of Chapter 1. Program 1.1 is the list file KEY690.LST, whose function is to read a keypad and display the inputs. The source code mnemonics are on the right, with the machine code in column 2 and the memory location where each instruction is stored in column 1.

Leave a comment

Your email address will not be published. Required fields are marked *