PIC Microcontroller

Subroutines and Modules Part 4 (PIC Microcontroller)

Example 6.5 Write a subroutine to evaluate the square root of a 16-bit integer located in File 26:7h. The 8-bit outcome is to be returned in the Working register. Solution The crudest way of doing this is to try every possible integer k from 1 upwards, generating k2 by multiplication and checking that the outcome […]

Interrupt Handling Part 1 (PIC Microcontroller)

The subroutines discussed in topic 6 are predictable events in that they are called up whenever the program dictates. Real-time situations, defined as where the processor interacts in concert with external physical events, are not as simple as this. Very often something happens beyond the CPU which necessitates precipitate action from the processor. The vast […]

Interrupt Handling Part 2 (PIC Microcontroller)

Interrupts happen randomly as viewed by the software and thus, unless masked out, may happen at any part of the background software, including in the middle of a subroutine. An ISR foreground routine uses the internal processor registers in the same way as any other software, so conflict over such resources will exist. For example, […]

Interrupt Handling Part 3 (PIC Microcontroller)

Solution Microchip suggest two approaches to the context switching problem for cases where the ISR has to change banks and GPRs are bank specific. The first is to keep the background program in Bank0 at any point of the code where the interrupt is enabled. Access to another bank can of course be made indirectly […]

Assembly language Part 1 (PIC Microcontroller)

We have now been writing programs with gay abandon since topic 3. For clarity these listings have been written in a human-readable form. Thus instructions have been represented as a short mnemonic, such as return instead of 00000000001000b; the file registers similarly have names, such as INTCON; lines have been labelled and comments attached. Such […]

Assembly language Part 2 (PIC Microcontroller)

Assembling The assembler program will scan the source file checking for syntax errors. If there no such errors the process goes on to translate to absolute object code; which is basically machine code with information concerning the location it is to be placed in Program memory. Syntax errors include such things as referring to labels […]

Assembly language Part 3 (PIC Microcontroller)

Codepage The codepage directive is used for program code. These directives are here used to define two regions, one for the Reset and Interrupt vectors in between 000h and 004h called vec and the other called program to be used for executable code from 005 h through 3FFh. Notice the use of the prefix 0x […]

Assembly language Part 4 (PIC Microcontroller)

Once the program has been successfully been linked it may be simulated. Here the PC models the PIC’s instruction set and I/O ports and allows the user to reset the (simulated) PIC, set break points, single step or run continuously. During this process user-selected file registers or the whole of Data memory can be monitored, […]

High-Level Language Part 1 (PIC Microcontroller)

All the programs we have written in the last six topics have been in symbolic assembly language. Whilst assembly-level software is a quantum step up from pure machine-level code nevertheless there is still a one-to-one relationship between machine and assembly-level instructions. This means that the programmer is forced to think in terms of the MCU’s […]

High-Level Language Part 2 (PIC Microcontroller)

In our example the logic of the program is unaffected if the operator is pre-decrement or post-decrement. However, the compiler in the latter case adds an extra instruction to bring n down into the Working register before it is decremented in situ as it thinks that some computation involving the original value of n is […]