Spanish Italian
17454 Users    

PICmicro

  Download PDF version of the Article

PICMICRO

PICMicro Basic
The course base on Microcontrollers, in order to understand what is a PIC with a simple and immediate language


PICMicro Advanced
We deepen the programming concepts and we use the peripherals


PICMicro Cult
The CULT course , the first one in Italy. Translate in an indefinite number of languages and versions



PICMICRO Advanced

Introduction
In order to study the PIC microcontrollers functioning we will take in consideration, at least for the moment, the PIC16F84 (or 16F84A): the most widely spread and simple for the beginners.
The main characteristics of this model are:

  • The memory: FLASH program memory with 1024 locations of 14 bit each, plus an EEPROM memory for data of 64 byte.
  • Clock: with a maximum frequency between 4 and 20Mhz, upon the model.
  • The feeding: from 4.5V to 5.5V with a maximum power consumption of 2mA (except the I/O pins).
  • The I/O ports: 13 input/output pins available, distinguished in two groups PORT A and PORT B, respective of 5 and 8 pins.
  • Instruction set: the assembly language is set up of 35 instructions, represented by mnemonic codes that we will see later.

Pin diagram

The chip is fed through the two pins VDD and VSS, connected to 5V and to ground.

The pin MCLR serves to enable the integrated (therefor in order to execute the reset) and it's usually connected to 5V with a resistance from 10Kohm in order to enable the PIC, or to ground to disable it; the same pin is connected to 12V during the phase of programming.

The clock can be generated in various ways, the most common are:

RC
It consists in a RC series, connected to OSC1, while in OSC2 is obtained the frequency divided by 4, that is the cadence with which are executed the instructions. With such method the obtained frequency is not at all precise.

Per 1Mhz -> R = 4,7K e C =
22pF

Quartz (XT)
With this member it is obtained a very precise frequency; the condensers (of 4Mhz) must be between 15 and 33pF.

To finish, there are present 13 I/O pins, configured as input and output; each one can supply or absorb 25mA, for a total, of 250mA and 300mA. It is an exception the RA4 pin that, when configured as output, is open drain, therefore it can only absorb current.

Open Drain
The pin isn't connected with Vcc, therefore it is not in a position to supply current.
If however you want to use the pin as output, is enough to connect it to Vcc with a resistance of pull-up, calculated upon the requirements.

Minimum configuration
Said like that, the minimum configuration because the PIC to be functional demands only a few components:

When programming a PIC is very useful, if not indispensable, to have in hand the relative datasheet, where we will find all the information that we need.

Inner structure

The inner architecture of the microcontrollers differs between a model and the other, but it can be outlined in a base shape, common to all the chips.


The following blocks are to be noticed:

  • The fundamental part of the uC, the CPU, in charge of executing all the instructions.
  • The memory program, that can be EPROM, CMOS EEPROM, FLASH or OTP (One Time Programmable). The chips supplied by EPROM have a little window in order to cancel the content of the memory through the ultraviolet beams, if instead they don't have this little window they are OTP because, once written, it is not possible anymore to cancel the content. In the case instead of EEPROM memories (CMOS or FLASH) it will be possible to reprogram the PIC many times over canceling it electrically.
  • The data memory is constituted from an EEPROM, where we can save data that it will not be lost once removed the feeding; it is not common for every PIC, but it is for the most of them.
  • The RAM memory contains all the temporary data, but above all, the registries; these last ones are special memory areas: they allow the qualification and the use of the peripheral, that perform another distinctive functions.
  • The Timer allows us to read the time and can be used by themselfs or as support for some peripherals; then there is a special timer, called WatchDog Timer (WDT) that, if enabled, resets the chip when this "jams".
  • At last the I/O peripheral can be various: from the simple input/output ports, until A/D converters or modules for the serial communication.


The Memory in Detail

The dimensions of the different parts that constitute the memory are changing with the PIC model; as for 16F84A, the dimensions are:



Like you have already seen, the program memory is of 1024 word of 14bit, this is because the instructions managed by the CPU are, exactly, of 14bit; the addresses available in order to access this memory are from 0 to 0x3F (1023). At every reset, the program starts always from the address 0, therefore we'll will put here the first instructions of our programs.

This memory can be divided in 4 pages of 2048 word each, because a jump instruction can address only 2048 memory locations; in order to pass between a page and the other it will be sufficient to modify the appropriate registry, in any case, it will be used very rare.

To not be confused with the RAM memory, this too divided in 4 parts (called banks), that work in a completely different way .

In both cases, the sections can be in different number, for example the PIC that we take in consideration has only one program memory page and two RAM banks.

The RAM memory

Unlike of very many other systems, for the PIC, the RAM memory t's not just a simple space where to put temporary data, but it contains the so-called Special Registers, indispensable for it's operation; every bank is therefor divided in two parts: Special Function Registers (SFR) and General Purpose Registers (GPR).

The RAM of 16F84 is organized as follows:

As you can see in the picture above, the space of effectively usable memory from the programmer is constituted by 68 byte (from 0Ch to 4Fh included), the low part is occupied by the SFR; the two banks are identical: every registry from bank 1 is a copy of the same registry in bank 0, except some special registries that are only found on one or on the other bank.

Similarly to what happens to the pages of the program memory, a single instruction can point to an address of only 7bit, that is from address 00h to 7Fh, therefore to move between a bank and the other we will use two apposite bits, placed in the STATUS registry.

The accumulator

Inside the PIC there is another very special register, the W register (also called working register or accumulator), very frequently used as temporary register in order executing some mathematical operations or in order to pass the data from a memory zone to another; in fact it is not possible to move data directly from a byte to another of the RAM, but it is necessary to pass through W.
In this lesson we will explain the most important special registers, thanks to which, together wiht some instructions, it will be possible to realize the first programs.

Status Register

The Status register is very used, in fact it contains the arithmetical state of the ALU and the bit of selection of the bank.

IRP: serves for selecting the 2 and 3 bank with the indirect address, but it isn't used by our PIC.

RP1:RP0: are selecting the RAM bank, but the RP1 bit it isn't used by 16F84 because, as you saw, it has only 2 banks.

TO': is zero after a Time Out of the WDT.

PD': is zero when the chip is in standby.

Z: is set if the operation's result is zero.

DC: shows if, during an operation, it was a carry-forward between the first and the second nibble of a byte.

C: shows that there was a carry-over.

PORTA e PORTB

These two registers allow the use of the output ports, that is the 13pin of I/O; when a port is configured as output, writing in the appropriate registry, it will come instantaneously modified the state of the correspondent pin.

For example, if it is write in the PORTB the byte 01110001b the pin RB0, RB4, RB5 and RB6 will be at 5V, while the others will be at 0V.

In the same way, if a port is configured as input, reading the relative register, you will have the state of the pin.



TRISA e TRISB

Like already pointed out previously, every single pin can be configured only as input or only as output: this is realized with the TRISA and TRISB registers. Setting the bit, the correspondent pin will be an input, otherwise it will be an output.

For example:

TRISB
bit 7 6 5 4 3 2 1 0

value

0 0 1 1 0 1 0 0

I/O

output output input input output input output output

Naturally, if a port is mixed input/output, it will not be necessary to write it or to read it all, but with appropriate single instructions we will be able to modify the bit.

LINKs

Pic by Example Il corso CULT in ITALIANO per Microcontrollers PIC, advised to all the beginners.

www.microchip.com The Microchip official site.

www.microchipc.com A good site with a lot of resources for the developers C, Bootloader and Tutorial

www.piclist.com The famous all-time site for the Source Code Library

www.phanderson.com Resources in C in particular CCS

www.electronic-engineering.ch/microchip/index.html Test Routines for the RS232 - LCD - AT Keyboard - DCF77

mikroElektronika Interesting Company with many development and compiler mikroC cards.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
2 + 8 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Who's new

  • fernand
  • Ligrock
  • paolo_0665
  • chanuei
  • JM
  • samsilva77
  • araghube
  • stoll
  • mt
  • orionkw

Who's online

There are currently 0 users and 54 guests online.