PICmicro. PICMICRO basic
§1. What is a microcontroller?
The very first question is: what a microcontroller is and what is this useful for?
The microcontroller is an integrated circuit with 8 pins (The one that we examine here is 18 pins) that actually it's like a small computer, with it's own RAM memory, EPROM memory, FLASH or ROM. In one of the last three types of memory a software is written (that is a program, that it's called firmware), through an appropriate device called “programmer”. The circuit will run the program sequentially, instruction after instruction, putting the pins on a high or low level (if are programmed as output) or reading the level of the input pins. Saying this way it doesn't seem to be very useful, but you will notice that in very many cases it turns out the to be the “winning card” for many applications, the microcontroller, in fact, can be destined to the most disparate uses, and actually now it is used from the baby toys until the professional applications of control and calculation.
There are different types of microcontrollers, that vary upon the memory available, of the available pin number, of the number of the instructions that these are containing and of other properties as well.
Let's begin now with the examination of the microcontroller from this handbook.
This device comes sold in different types of container, each one with its characteristics:
|
Image |
Name |
N.ro pin |
Note |
|
|
PDIP (Plastic Dual In Line Package) |
18 |
This plastic container, adapted for traditional assembly (Through Hole), we'll cover in this manual is the most widely-used among electronics enthusiasts as well as education institutions. |
|
|
SOIC (Small Outline Integrated Circuit) |
18 |
Un A plastic container adapted for SMD assembly. |
|
|
SSOP (Shrink small outline package) |
20 |
Un Another plastic container adapted for SMD assembly. |
|
|
QFN (Quad Flat package No leads) |
28 |
Still a container for the SMD assembly, has the characteristic that the pins are not visible. |
§4. The program memory (FLASH)

Figure 2: Programming memory
As you can see in the picture above the memory has a size of 1kbyte and starts from 00 (hexadecimal) until 3FF (hexadecimal). Any location allows the insertion of an instruction, for a total of 1024 instructions. The device has a stack (we'll see later what is this about) of 8 positions and a program counter (PC) at 13 bit. The memory from 400 (hexadecimal) to 1FFF (hexadecimal) is not physically implemented and a writing in this area it means the overwriting of the existent memory in a cyclic way, that means if writing in 400 (hexadecimal) in truth is written in 000 (hexadecimal).
The location 000 (hexadecimal) is the RESET vector, from where starts the execution of a program as a result of a power-on or a reset.
The location 004 (hexadecimal) is the INTERRUPT vector, practically the program jumps immediately to this location when it receives an external or internal interrupt signal, executes the routine that starts from that point and, as a result of the instruction RETFIE, returns to the execution of the next instruction to the one where the signal was generated.
Let's see now what the stack is.
The stack is a specific memory area where the microcontroller inserts the address memory of the instruction that follows the one where the subroutine has been called or however when it is necessary to memorize the address of the next location of the program in order to resume the execution afterwards. Being at 8 levels it is possible to memorize up to 8 locations, the insertion of the memory location comes automatically from the part of the device and is resumed in an automatic way.
The stack is LIFO (Last In First Out) that means that the last inserted location is the first to be recovered. Without getting further, let's say however that we cannot directly manage in any way this area.
The Program Counter is a memory area where the device memorizes the address of the memory location next to the one that is currently in execution, that means it is a kind of index of the next instruction to be executed. It is initialized at 000 (hexadecimal) as a result of a reset or a power-on, at 004 (hexadecimal) as a result of an interrupt signal and the stack value is copied at the return of a subroutine, all these operations are executed automatically by the integrated, but in this area it is necessary to intervene in particular cases, as for example, for the data tables (we'll see later).
§7. The data memory

Figure 3: Data memory
We'll examine now the data restricted memory (RAM). This is divided in two parts:
- SFR (Special Function Register) These are areas that determine the functionality of the device's special circuits or return the results.
- GPR (General Purpose Register) are free areas that can be used for memorizing variables of the program.
The picture above shows both types of areas.
We will examine in detail the SFR in the description of different services.
You can notice that the memory is divided in 4 banks of 128 byte each with some SFR (the most used) in common through the different banks. Before accessing any location it will be necessary to accept the right memory bank, the bank access can be made in two different ways, we'll see how it can be done in the STATUS registry description.
In this case also, accessing the non implemented memory areas will happen an overwriting of the existing memory areas, for example in the 1st bank, the areas from C0h to FFh will cause an overwriting of the areas from 40h to 7F of the bank 0.
The areas 00h, 80h, 100h and 180h are not directly usable, but are used for a particular type of addressing, the Indirect Addressing.
The areas marked in gray are not implementable, therefore these don't have to be EVER used.
§8. The EEPROM memory

Figure 4: EEProm memory
This type of memory is available for the memorization of the data that doesn't have to be canceled in case of power lack (for example user settings, data calculated by the program itself, etc...). The use of this memory demands a particular technical programming in order to guarantee the integrity of the data that will be explained further in this manual. This memory counts of 128 byte of memory.
§9. STATUS REGISTER : Bank 0 (03h); 1 (83h); 2(103h); 3 (183h)

We are beginning the explanation of the SFR (see paragraph 08) with the registry that contains all the informations relative to the unit that runs the operations (ALU = Arithmetic Logic Unit), that contains the bit for the change of the memory bank and the state of the reset of the device, and that is the same for all memory banks.
Is a 8 bit registry, here is the significance for every bit starting with the most significant one (bit 7) until the last significant one (bit 0).
ATTENTION! The writing on this register could not return the expected result, because 2 bit are only for reading and the last 3 bit respects however the state of the ALU apart from what it is written!
- Ionela's blog
- 853 reads









Post new comment