100% found this document useful (2 votes)
22 views11 pages

PICdown

Uploaded by

jayanthisnj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (2 votes)
22 views11 pages

PICdown

Uploaded by

jayanthisnj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 11

PIC Microcontrollers

PIC is an abbreviation of Peripheral Interface Controller. It is the smallest microcontroller and are
programmed to execute large number of operations.

Salient features of PIC 18:

 It has RISC Architecture


 It contains ROM of size 2 Megabytes
 It has on chip program(Code) ROM in the form of flash memory
 It contains RAM between 256 bytes to 4096 bytes
 It has data EEPROM
 It include timers
 It has ADC
 It includes USART Protocol for PC communication
 It contains I/O port between 16 to 72 pins

Simplified View of a PIC MicrocontroIIer is as shown below

The details of the RAM/ ROM memory and I/O features of the PIC 18 are given below.

Program ROM
In microcontrollers, the ROM is used to store programs and hence it is called Program or code ROM.
Although the PICl8 has 2M (megabytes) of program (code) ROM space, not all family of PIC 18 has the
same size. The program ROM size can vary from 4K to 128K. The different types of memory of PICl8
Program ROM are discussed below

Types of Program ROM:

Some of the types of Program ROM are –

 UV-EPROM
 Flash memory
 OTP ROM
 Mask ROM

UV-EPROM :
Some of the PIC rnicrocontrollers use UV-EPROM, for on-chip program ROM. To use these kinds
of chips for development requires access to a PROM burner, as well as a UV-EPROM eraser to erase the
contents of ROM. The window on the UV-EPROM chip allows the UV light to erase the ROM. The
problem with the UV-EPROM is that it takes around 20 minutes to erase the chip before it can be
programmed again. This has led Microchip to introduce a flash version of the PIC family.

PIC18Fxxx with flash


PIC l8 chips have on-chip program ROM in the form of flash memory. (The flash version uses the
letter F in the part number to indicate that the on chip ROM is flash. Example: PIC18F458). As the data
stored in flash memory can be erased in a very short time, thereby speeding up the development time it has
been used in place of UV-EPROM. In flash memory, the entire contents of ROM is erased in order to
program it again. This erasing of flash is done by the ROM programmer itself, and so a separate eraser is not
needed.

OTP version of the PIC


The flash version is used for product development. When a product is designed and absolutely
finalized, the OTP version of the PIC is used for mass production because it is cheaper than flash. The
problem with the OTP is that you cannot reprogram it if you want to modify your program. OTP (one-time-
programmable) versions of the PIC are available from Microchip. PIC 16C432 chip uses OTP for program
ROM.. The letter C indicates the OTP ROM.

Masked version of PIC


Mask ROM refers to the kind of ROM whose contents are programmed by the IC manufacturer. i.e., it is
not a user programmable ROM. Masked PIC is the cheapest of all types, if the unit numbers are high
enough. This is because there is a minimum order for the masked version of the PIC microcontrollers.
What is Mask ROM?
Ans: Mask ROM is a type of ROM where the data is permanently programmed during the manufacturing
process using a photolithographic process.

What is EPROM?
Ans: EPROM stands for Erasable Programmable Read-Only Memory. It is a type of ROM that can be
erased and reprogrammed using ultraviolet light.

What is flash memory?


Ans: Flash memory is a type of ROM that can be electrically erased and reprogrammed in blocks instead of
byte-by-byte.

PIC microcontroller data RAM and EEPROM

While ROM is used to store program (code), the RAM space is for data storage. The PIC I8 has a
maximum of 4096 bytes (4K) of data RAM space. The data RAM size for the PIC 18 varies from 256 bytes
to 4096 bytes. The data RAM space has two components:

 General-Purpose RAM (GPR) and


 Special Function Registers (SFRs).
Because the SFRs are fixed, it is the GPR's size that varies from chip to chip. The RAM GPR space is used
for read/write, scratch pad and data manipulation and is divided into banks of 256 bytes each. The GPR size
given for the PICI8 is always a multiple of 256 bytes.

PIC microcontroller I/O pins

The PIC 18 can have 16 to 72 pins dedicated for I/O. The number of I/O pins depends on the number
of pins in the package. The number of pins for the PICI8 package goes from 18 to 80. In the case of the 18-
pin PIC 18F1220 we have 16 pins for 1/0, while in the case of the 80-pin PICI8F8722, we can use up to 72
pins for 1/0.

PIC microcontroller peripherals

The peripherals of the PICI8 microcontrollers are -

 ADC (analog-to-digital converter),


 Timers, and
 USART (Universal Synchronous Asynchronous Receiver Transmitter) .

The ADC is 10- bit and the number of ADC channels in each PIC chip varies from 5 to 16, depending on
the number of pins in the package.
The PIC 18 can have up to 4 timers besides the watchdog timer.

The USART peripheral allows us to connect the PIC 18-based system to serial ports such as the COM
port of the IBM PC.

Timers in PIC 18

A PIC18 microcontroller may have up to 5 timers: Timer0…Timer 4. – Timer 0, Timer 1 and Timer 3 are
16-bit timers whereas Timer 2 and Timer 4 are 8-bit. - When a timer rolls over, an interrupt is generated if it
is enabled.

ARCHITECTURE:

THE WREG REGISTER IN THE PIC

PIC microcontrollers have many registers and WREG register is used for arithmetic and logic operations.

WREG register

In the CPU, the registers which are 8 bit are used to store information temporarily. In the PIC there is only
one data type: 8-bit. The 8 bits of a register are shown in the diagram below. These range from the MSB
(most-significant bit) D7 to the LSB (least-significant bit) D0. With an 8-bit data type, any data larger than 8
bits must be broken into 8-bit before it is processed.

The 8-bit WREG register is the most widely used register in the PIC microcontroller. WREG stands for
WORKING REGISTER. The WREG register is the same as the accumulator in other microprocessors. The
WREG register is used for all arithmetic and logic instructions.
MOVLW instruction

The MOVLW instruction moves 8-bit data into the WREG register. It has the following format:

K is an 8-bit Hex value that can range from 00 - FF. The L stands for literal, which means, literally, a
number must be used. This is similar to the immediate value in other microprocessors. In the instruction
MOVLW, the letter L (literal) comes first and then the letter W (WREG), which means "move a literal
value to WREG," the destination. The following instruction loads the WREG register with a literal value
of 25H (i.e., 25 in hex).

The following instruction loads the WREG register with value 87H (87 in hex).

The following instruction loads the WREG register with value 15H (15 in hex and 21 in decimal).

ADDLW instruction

The ADDLW instruction has the following format:

The ADD instruction tells the CPU to add the literal value K to register WREG and put the result back in the
WREG register. Notice that in ADDLW, first comes the letter L (literal) and then the letter W (WREG),
which means "add a literal value to WREG," the destination.

Program1:

Write an ALP to add two numbers 25H and 34H:

The following diagram shows the literal value and WREG being fed to the PIC ALU.
Program2:

Write an ALP to add values 12H, 16H, 31H, and 43H

When programming the WREG register of the PIC microcontroller with a literal value, the following points
should be noted:

1. Values can be loaded directly into the WREG register. There is no need for a preceding pound sign
or dollar sign to indicate that a value is an immediate value as is the case with some other
microcontrollers.
2. If values 0 to F are moved into WREG, the rest of the bits are assumed to be all zeros.
For example, in "MOVLW 5H" the result will be WREG = 05H; that is, WREG = 00000101 in
binary.
3. Moving a value larger than 255 (FF in hex) into the WREG register will truncate the upper byte and
cause a warning in the error file.
1. Write instructions to move value 34 H into the WREG register.
2. Write instructions to add the values l6H and CDH. Place the result in the WREG register

THE PIC FILE REGISTER

The PIC microcontroller has many other registers in addition to the WREG register. They are called data
memory space to distinguish them from program (code) memory space. The data memory space in PIC is a
read/write (static RAM) memory. In the PIC microcontroller literature, the data memory is also called the
file register. The various locations of file register data RAM in the PIC and their usage with simple
instructions is discussed below

File registers (data RAM) space allocation in PIC

The file register is read/write memory used by the CPU for data storage, scratch pad, and registers for
internal use and functions. Arithmetic and logic operations can be performed on many locations of the file
register data RAM.. The width of the file register data RAM is 8 bits. It is divided into two sections:

(a) Special Function Registers (SFR), and


(b) General Purpose Registers (GPR). The general-purpose register section is also referred to as
General-Purpose RAM (GP RAM).

SFRs (Special Function Registers)


The Special Function Registers (SFRs) are dedicated to specific functions such as

 ALU status,
 Timers,
 serial communication,
 I/O ports,
 ADC and so on.
The function of each SFR is fixed by the CPU designer at the time of design because it is used for control of
the microcontroller or peripheral. The PIC SFRs are 8-bit registers. The number of locations in the file
register depends on the pin numbers and peripheral functions supported by that chip.
GPR (General-Purpose Registers or RAM)

The general-purpose registers are a group of RAM locations in the file register that are used for data storage
and scratch pad. Each location is 8 bits wide and can be used to store any eight bit data. In the PIC
controllers, the space that is not allocated to the SFRs is used for general-purpose registers. In Assembly
language programming these registers with larger GPR is difficult to manage.
GP RAM vs. EEPROM in PIC chips
The GP RAM (which constitutes most of the file register) is used by the CPU for internal data
storage, whereas the EEPROMs are considered as an add-on memory that one can also add externally to the
chip. In other words, while many PIC chips have zero bytes of EEPROM data memory, it is impossible for a
microcontroller to have zero size for the file register.

GP RAM EEPROM
The PIC 18 GP RAM is used by the CPU for internal The PIC 18 EEPROMs are considered as an add-on
data storage memory that one can also add externally to the chip.
GP RAM always exists in PIC 18 controllers PIC controllers may have zero bytes of EEPROM
data memory

File register and access bank in the PIC18

The following diagram shows the File Register for PIC18 Family
The size of the file register of the PICI8 family is 4096 (4K) bytes. With 4096 bytes, the file register
has addresses of 000-FFFH. The file register in the PICI8 is divided into 256-byte banks. Therefore,
maximum of 16 banks (16 x 256 = 4096) are available. This bank is called the access bank and is the default
bank when the PIC 18 chip is switched ON.

Let us consider a single bank. In the 256-byte access bank for the PICI8, it is divided into two equal
sections of 128 bytes. These 128-byte sections are given to the general-purpose registers and special function
registers. The 128 bytes from locations 00H to 7FH are set aside for general-purpose registers and are used
for read/write storage, or for a scratch pad. These 128 locations of RAM are widely used for storing data
and parameters by PIC 18 programmers and C compilers. Each location of this 128-byte RAM of general-
purpose registers can be accessed directly by its address.

The other 128 bytes of the access bank is used for SFRs. It has addresses of F80H to FFFH, as shown
in the above Figure. The memory space of the SFRs and GPRs in the access bank is not contiguous. The
reason is to allow the RAM space between 080H and F7FH to be used for the general-purpose registers by
various members of the PIC 18 if they implement a larger data RAM size for the file register. A file register
of more than 256 bytes will necessitate bank switching. Bank switching is a method used to access all the
banks of the file register for PIC 18 family members that have more than the minimum access bank
PIC STATUS REGISTER

The PIC has a flag register to indicate arithmetic conditions such as the carry bit. The flag register in the PIC
is called the status register
PIC18 status register
The status register is an 8-bit register. It is also referred to as the flag register. Although the status register is
8 bits wide, only 5 bits of it are used by the PIC 18. The three unused bits are unimplemented and read as 0.
The five flags are called conditional flags, that is, they indicate some conditions that result after an
instruction is executed. The bit pattern of status register is as shown below.

These five flags are


 C (carry),
 DC (digital carry),
 Z (zero),
 OV (overflow), and
 N (negative).
C, the carry flag
This flag is set whenever there is a carry out from the D7 bit. This flag bit is affected after an 8-bit addition
or subtraction. The carry flag is used to detect errors in unsigned arithmetic operations
DC, the digital carry flag
If there is a carry from D3 to D4 during an ADD or SUB operation, this bit is set; otherwise, it is cleared.
This flag bit is used by instructions that perform BCD (binary coded decimal) arithmetic. It is similar to the
AC flag (Auxiliary Carry flag) in microprocessors
Z, the zero flag
The zero flag reflects the result of an arithmetic or logic operation. If the result is zero, then Z = I. Therefore,
Z = 0 if the result is not zero..
OV, the overflow flag
This flag is set whenever the result of a signed number operation is too large, causing the high-order bit to
overflow into the sign bit. The overflow flag is used to detect errors in signed arithmetic operations.
N, the negative flag
Binary representation of signed numbers uses D7 as the sign bit. The negative flag reflects the result of an
arithmetic operation. If the D7 bit of the result is zero, then N = 0 and the result is positive. If the D7 bit is
one, then N = I and the result is negative. The negative and OV flag bits are used for the signed number
arithmetic operations
Problems:

You might also like