PICdown
PICdown
PIC is an abbreviation of Peripheral Interface Controller. It is the smallest microcontroller and are
programmed to execute large number of operations.
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
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.
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.
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:
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.
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:
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 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:
The following diagram shows the literal value and WREG being fed to the PIC ALU.
Program2:
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 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
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:
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
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.