Chapter#1 - THE PIC MICRO-CONTROLLERS HISTORY

Chapter 1 - THE PIC MICRO-CONTROLLERS HISTORY:

Upon Completion of this Chapter, You will be able to:

  • Compare and contrast microprocessors and micro-controllers.
  • Describe the advantages of micro-controllers for some applications.
  • Explain the concept of Embedded systems.
  • Discuss criteria for considering a micro-controllers.
  • Explain the variations of speed, packaging, memory and cost per unit.
  • Compare and contrast the various members of the PIC family.
  • Compare the PIC with micro-controllers offered by other manufacturers.

SECTION  I - MICRO-CONTROLLERS AND EMBEDDED PROCESSORS

  • SECTION  I-1: Micro-controllers Versus General Purpose Microprocessor
  • SECTION  I-2: Micro-controllers for Embedded Systems
  • SECTION  I-3: x86 PC Embedded Applications
  • SECTION  I-4: Criteria for Choosing a Micro-controllers
  • SECTION  I-5: Mechatronics and Micro-controllers

SECTION  2 - OVERVIEW OF THE PIC18 FAMILY

  • SECTION  II-1: A brief history of the PIC micro-controller
  • SECTION  II-2: PIC18 Features
  • SECTION  II-3: PIC micro-controller Program ROM, with UV-EPROM and Flash
  • SECTION  II-4: PIC micro-controller data RAM and EEPROM
  • SECTION  II-5: PIC micro-controller I/O Pins, Peripherals, trainer & other micro-controllers

This chapter begins with a discussion of the role and importance of micro-controllers in every day life. Also discuss criteria to consider in choosing a micro-controller, as well as the use of micro-controllers in the embedded market, Also covers various members of the PIC18 family and their features. Also provide a brief discussion of alternatives to the PIC chip such as the 8051, AVR, and 68HC11 micro-controllers.

In this chapter We will discuss the role and importance of micro-controllers in everyday life. Microprocessors and micro-controller will be contrasted and compared. We will discuss the use of micro-controllers in the embedded market. We will also discuss criteria to consider on choosing a micro-controller such as speed, memory, I/O, Packaging, and cost per unit. the second section we will describe about various families of the PIC, such as the PIC18 and PIC16 and their features. We will discuss various members of the PIC18 family such as the PIC18F252 and PIC18F458.

SECTION I-1: Microcontrollers Versus General Purpose Microprocessor

SECTION  I-1: Micro-controllers Versus General Purpose Microprocessor

Need for micro-controllers  and contrast them with general-purpose microprocessors such as the Pentium and other x86 microprocessors. Looking at the role of micro-controllers in the embedded market plus providing some criteria on how to choose a micro-controllers.

What is the difference between a microprocessor and micro-controller?

Microprocessor  is meant the general-purpose microprocessors such as Intel's x86 family (8086m 80286, 80386, 80486, and the Pentium) or Motorola's Power PC family. These microprocessors contain no RAM, no ROM, and no I/O ports on the chip itself. For this reason, they are commonly referred to as general-purpose microprocessors.

microprocessor-versus-microcontroller.jpg

A system designer using a general-purpose microprocessor such as the Pentium or the power PC must add RAM, ROM, I/O ports, and timers externally to make them functional. Although the addition of external RAM, ROM, and I/O ports makes these systems bulkier and much more expensive, they have the advantage of versatility, enabling the designer to decide on the amount of RAM, ROM, and I/O ports needed to fit the task at hand. This is not the case with micro-controllers. A micro-controllers has a CPU in addition to a fixed amount of RAM, ROM, I/O ports, and timer are all embedded together on one chip; therefore, the designer cannot add any external memory, I/O ports in micro-controllers makes them ideal for many applications in which cost and space are critical, In many applications, a TV remote control, there is no need for the computing power of a 486 or even an 8086 microprocessor. In many applications, the space used, the power consumed, and the price per unit are much more critical considerations than the computing power. These applications most often require some I/O operations to read signals and turn on and off certain bits. Some call these processors IBP, "itty-bitty processors". It is interesting to note that some micro-controllers manufacturers have gone as far as integrating an ADC, analog to digital converter, and other peripherals into the micro-controllers.

SECTION I-2: Micro-controllers for Embedded Systems

SECTION  I-2: Micro-controllers for Embedded Systems

Microprocessors and micro-controllers  are widely used in embedded system products. An embedded product is controlled by its own internal microprocessor or micro-controllers, as opposed to an external controller. In an embedded system, the micro-controllers ROM is burned with a purpose for specific functions needed for the system. A printer is an example of an embedded system because the processor inside it performs one task only; getting the data and printing it. Contrast this with a Pentium based PC or any x86 IBM compatible PC, which can be used for any number of applications such as work processor, print-server, bank teller terminal, video game player, network server, or internet terminal. A PC can also load and run software for a variety of applications. A PC can perform myriad tasks is that it has RAM memory and an operating system that loads the application software into RAM and lets the CPU run it. In an embedded system, only one application software is burned into ROM. An x86 PC contains or is connected to various embedded products such as the keyboard, printer, modem, disk controller, sound cards, CD-ROM driver, mouse etc. Each one of these peripherals has a micro-controller inside it that performs only one task of finding the mouse's position and sending it to the PC.

HOME OFFICE AUTO
Appliances Telephones Trip computer
Intercom Computers Engine control
Telephones Security Systems Air bag
Security systems Fax machines ABS
Garage door openers Microwave Instrumentation
Answering machines Copier Security system
Fax machines Laser Printer Transmission control
Home computers Color printer Entertainment
TVs Paging Climate control
Camcorder   Cellular phone
Remote controls   Keyless entry
Video games    
Cellular phones    
Musical instruments    
Sewing machines    
Lighting control    
Paging    
Camera    
Pinball machines    
Toys    
Exercise equipment    

 

SECTION I-3: x86 PC Embedded Applications

SECTION  I-3: x86 PC Embedded Applications

Micro-controllers are the preferred choice for many embedded systems. Micro-controllers some times inadequate for the task. Many manufacturers of general-purpose microprocessors such as Intel, Free scale semiconductor, Motorola, and AMD advanced Micro Devices, Inc. have targeted their microprocessor for the high end of the embedded market. Intel and AMD push their x86 processors for both the embedded and microprocessors 604, 603, 620, etc in place of the 680x0 for the Machintosh. The power PC microprocessors is a joint venture between IBM and Motorola, and is targeted for the high end of the embedded ,market as well as the PC market. When a company targets a general-purpose microprocessor for the embedded market it optimizes the processor used for embedded systems. The processors are often called high-end embedded processors. Another chip widely used in the high end of the embedded system design is the ARM microprocessor. The terms embedded processors and micro-controllers are used interchangeably.

One of the most critical needs of an embedded system is to decrease power consumption and space. This can be achieved by integrating more functions into the CPU chip, All the embedded processors based on the x86 and Power PC 6xx have low power consumption in addition to some forms of I/O, COM port, and ROM, all on a single chip. In high-performance embedded processors, the trend is to integrate more and more functions on the CPU chip and let the designer decide which features to use. This trend is invading PC system design a well. In designing, the PC motherboard we need a CPU plus a chipset containing I/O, a cache controller, a flash ROM containing BIOS, and finally a secondary cache memory. New designs are emerging in industry, like many companies have a chip that contains the entire CPU and all the supporting logic and memory, except for DRAM. In other words, we have the entire computer on a single chip.

Linux, MS-DOS and windows standardization, many embedded systems use x86 PC's. Using x86 PC's for the high-end embedded applications not only saves memory but also shortens development time because a vast library of software already exists for the Linux, DOS, and windows platforms. The fact that windows and Linux are widely used and well-understood platforms means that developing a windows-based or Linux-based embedded product reduces the cost and shortens the development time considerably.

 

SECTION I-4: Criteria for Choosing a Micro-controllers

SECTION  I-4: Criteria for Choosing a Micro-controllers

There are 5 major 8-bit micro-controllers. They are...

  • Free scale Semiconductors formerly Motorola 68HC08/68HC11
  • Intel's 8051
  • Atmel's AVR, Zilog's Z8
  • PIC Microchip

The Above micro-controllers has a unique instruction set and register set. They are not compatible with each other. Programs written for one will not run on the others. there are also 16-bit and 32-bit micro-controllers.

What criteria do designers consider in Choosing one?

  1. Meeting the computing needs of the task at hand efficiently and cost effectively.
  2. Availability of software and hardware development tools such as compilers, assemblers, debuggers, and emulators.
  3. Wide availability and reliable sources of the micro-controllers.

1) Meeting the computing needs of the task at hand efficiently and cost effectively:

The first and foremost criterion in choosing a micro-controllers is that it must meet the task at hand efficiently and cost effectively. In analyzing the needs of a micro-controller-based project, we must first see whether an 8-bit, 16-bit, or 32-bit micro-controller can best handle the computing needs of the task most effectively. Other considerations in this category are:

  • Speed: What is the highest speed that the micro-controller supports?
  • Packaging: Does it come in a 40-pin DIP, dual inline package or QFP quad flat package, or some other packaging format. This is important in terms of space, assembling, and prototyping the end product.
  • Power consumption: This is especially critical for battery-powered products.
  • RAM/ROM: The amount of RAM and ROM on the chip.
  • I/O Pins: The number of I/O pins and the timer on the chip.
  • Upgrade: Ease of upgrade to higher-performance or lower-power-consumption versions.
  • Cost per unit: Important in terms of the final cost of the product in which a micro-controller is used. Some micro-controllers cost 50 cents per unit when purchased 100,000 units at a time.

2) Availability of software and hardware development tools such as compilers, assemblers, debuggers, and emulators.

It is how easy to to develop micro-controller products around it. Including the availability of an assembler, debugger, a code-efficient C language compiler, emulator, technical support, and both in-house and outside expertise. The third party vendors, a supplier other than manufacturer, support for the chip is as good as, if not better than, support from the chip manufacturer.

3) Wide availability and reliable sources of the micro-controllers.

Its ready availability in needed quantities both now and in the future. For some designers this is even more important than the first two criteria. Currently, of the leading 8-bit micro-controllers, the 8051 family has the largest number of diversified suppliers. In the case of 8051, which was originated by Intel, several companies also currently produce the 8051. The Free scale or Motorola, Atmel, Zilog, and Microchip technology have all dedicated massive resources to ensure wide and timely availability of their products because their products are stable, mature, and single sourced. In recent years, companies have begun to sell Field-programmable Gate Array FPGA and Application-Specific Integrated Circuit ASIC libraries for the different micro-controllers.

SECTION I-5: Mechatronics and Micro-controllers

SECTION  I-5: Mechatronics and Micro-controllers

The micro-controllers is playing a major role in an emerging field called mechatronics.

Many technical processes and products in the area of mechanical and electrical engineering show an increasing integration of mechanics with electronics and information processing. This integration is between the components hardware and the information-driven functions software, resulting in integrated systems called mechatronic systems.

The development of mechatronic systems involves finding an optimal balance between the basic mechanical structure, sensor and actuator implementation, automatic digital information processing and overall control, and this synergy results in innovative solutions. The practice of mechatronics requires multidisciplinary, expertise across a range of disciplines, such as mechanical engineering, electronics, information technology, and decision making theories.

 

SECTION II-1: A brief history of the PIC Micro-controller

SECTION  II-1: A brief history of the PIC micro-controller

In 1989, Microchip technology Corporation introduced an 8-bit micro-controller called the PIC, which stands for Peripheral Interface Controller. This micro-controller had small amounts of data RAM, a few Hundreds bytes of on-chip ROM for the program, one timer, and a few pins for I/O ports, all on a single chip with only 8 pins. A company that began with such a humble product became one of the leading suppliers of 8-bit micro-controllers in less than a decade. Microchip is the number one supplier of 8-bit  micro-controllers in the world. The introduction of the PIC16xxx, they have introduced an array of 8-bit micro-controllers too numerous to list here. They include the PIC families of 10xxx, 12xxx, 14xxx, 16xxx, 17xxx, and 18xxx. They are all 8-bit processors, meaning that the CPU can work on only 8-bits of data at a time. Data larger than 8-bits has to be broken into 8-bits pieces to be processed by the CPU. The PIC family not all 100% upwardly compatible in terms of software when going from one family to another family. e.g; The 12xxx/16xxx have 12-bit and 14-bit wide instructions, the PIC18xxx instructions is 16 bits wide with many new instructions.

To run program written for the PIC12xxx on a PIC18, we must recompile the program and possibly change some register locations before loading it into the PIC18.  The PIC18xxx family has the highest performance of all the families of 8-bit PIC  micro-controllers. The PIC18xxx is available in 18 to 80 pins packages makes it an ideal choice for new designs because it allows an easy migration to more powerful versions of the chip without losing software availability. At this time, no 8-pin version of the PIC18xxx exists, and that is the main reason to choose other family members of the 10xxx-16xxx if your design calls for a small package.

SECTION II-2: PIC18 Features

SECTION  II-2: PIC18 Features

The PIC18 has a RISC architecture that comes with some standard features such as on-chip program (code) ROM, data RAM, data EEPROM, timers, ADC, and USART and I/O ports.

The size of the program ROM, data RAM, data EEPROM, and I/O ports varies among the family members, they all have peripherals such as timers, ADC, and USART

pic16-block-diagram.jpg

pic18-block-diagram.jpg

Due to the importance of these peripherals, the details of the RAM/ROM memory and I/O features of the PIC18 will be discussed in the next few chapters.

SECTION II-3: PIC micro-controller Program ROM, with UV-EPROM and Flash

SECTION  II-3: PIC micro-controller Program ROM, with UV-EPROM and Flash

PIC Micro-controller Program ROM:

In micro-controllers, the ROM is used to store programs. It is called program or code ROM. The PIC18 has 2MB of program code ROM space. Not all family members come with that much ROM installed. The program ROM size can vary from 4K to 128K at the time of this writing, depending on the family member. The PIC18 program ROM is available in different memory types, such as flash, One time programmable OTP, and masked, all of which have different part numbers. Different flavors of the PIC18 exist in terms of speed and amount of on-chip RAM/ROM, they are all compatible with each other as far as the instructions are concerned. This means that if you write your program for one, it will run on any of them regardless of the chip number.

PIC Micro-controller with UV-EPROM:

Some of the PIC micro-controllers use UV-EPROM, for on-chip program ROM. These kinds of chips for development requires access to a PROM burner, as well as a UV-EPROM eraser ro erase the contents of 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. At this time, flash is replacing the UV-EPROM altogether.

Some Members of the PIC18 Family

members-of-pic-family.jpg

PIC18Fxxx with Flash:

Many PIC18 chips have on-chip program ROM in the form of flash memory. The flash version used the letter F in the part number to indicate that the on -chip ROM is flash. PIC18F458 is an example of PIC18 with flash ROM. The flash version is ideal for fast development because flash memory can be erased in seconds compared to 20 minutes or more needed for the UV-EPROM version. The PIC 18F has been used in place of the UV-EPROM to eliminate the waiting time needed to erase the chip, thereby speeding up the development time. To use the PIC18F to develop a micro-controller based system requires a ROM burner that supports flash memory. A ROM eraser is not needed because flash is an EEPROM, electrically erasable PROM. In flash memory, you must erase the entire contents of ROM programmer itself, and so a separate eraser is not needed. You can also program the PIC18F via the PICkit 2 from MicroChip using the USB port of an IBM PC.

One Time Programmable OTP Version of PIC:

OTP versions of the PIC are also available from Microchip. PIC16C432 chip uses OTP for program ROM. Contrast the PIC16C432 and PIC18F252. The letter 'C' indicates the OTP ROM, while the letter 'F' is for flash. The flash version is typically 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 in terms of price per unit. The problem with the OTP is that you cannot reprogram it if you want to modify your program.

Masked Version of PIC:

Microchip Corporation provides a service in which you can send in your program and they will burn the program into the PIC chip during the fabrication process of the chip. This chip is commonly referred to as masked PIC, which is one of the stages of IC fabrication. Masked PIC is the cheapest of all types, if the unit number are high enough. This is because there is a minimum order for the masked version of the PIC micro-controllers.

 

SECTION II-4: PIC micro-controller data RAM and EEPROM

SECTION  II-4: PIC micro-controller data RAM and EEPROM

ROM is used to store program code. The RAM space is for data storage. The PIC18 has a maximum of 4096 bytes (4K) of data RAM space. Not all of the family members come with that much RAM. The data RAM size for the PIC18 varies from 256 bytes to 4096 bytes. The data RAM space has two components: General-purpose RAM (GPR) and Special Function registers (SFRs). SFRs are fixed and every micro-controller must have them. It is the GPR's size that varies from chip to chip. The Microchip website gives only the GPR size. 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 PIC18 is always a multiple of 256 bytes. In some of the PIC family members, we also have a small amount of EEPROM to store critical data that does not need to be changes very often. Every PIC18 muct have some data RAM for scratch pad, the EEPROM is optional, not all versions of the PIC18 some with EEPROM. EEPROM is used mainly for storage of critical data.

SECTION II-5: PIC micro-controller I/O Pins, Peripherals, trainer & other microcontrollers

SECTION  II-5: PIC micro-controller I/O Pins, Peripherals, trainer & other Micro-controllers

PIC Micro-controller I/O Pins:

The PIC18 can have from 16 to 72 pins dedicated for I/O. The number of I/O pins depends on the number of pins in the package itself. the number of pins for the PIC18 packages goes from 18 to 80 at this time. In the case of the 18-pin PIC18F1220, we have 16 pins for I/O, in case of the 80-pin PIC18F8722, we can use up to 72 pins for I/O.

PIC Micro-controllers Peripherals:

All the numbers of the PIC18 family come with ADC analog to digital converter, timers, and USART (Universal Asynchronous Receiver Transmitter) as standard peripherals. 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 PIC18 can have up to 4 timers besides the watchdog timer. The USART peripheral allows us to connect the PIC18 based system to serial ports such as the COM port of the IBM PC. Many of the PIC18 family members come with the I2C and CAN bus as well.

PIC Trainer:

We will discuss the design of the PIC18F458 trainer extensively. This trainer programmed using the PICkit2. The MDEPIC trainer is also compatible with other 40-pin devices from Microchip.

Other Micro-controllers:

There are many popular 8-bit micro-controllers besides the PIC chip. Among then are the 8051, 68HC11, AVR, and Z8. Besides Intel, a number of other companies make the 8051 family. The AVR is made by Atmel Corp. Free scale (Motorola) makes the 68HC11 and many of its variations. Zilog produces the Z8 micro-controllers.

comparison-8051-pic-8-bit-websites.jpg

Chapter#2 - INTRODUCTION TO COMPUTING

Upon Completion of this chapter, You will be able to:

  • Convert any number from base 22, base 10m or base 16 to any of the other two bases
  • Add and subtract hex numbers
  • Add Binary numbers
  • Represent any binary number in 2's complement
  • Represent an alphanumeric string in ASCII code
  • Describe the logical operations AND, OR, NOT, XOR, NAND, and NOR
  • Use logic gates to diagram simple circuits
  • Explain the difference between a bit, a nibble, a byte, and a word
  • Mathematical definitions of the terms kilobyte, megabyte, gigabyte, and terabytes
  • Explain the difference between RAM and ROM and describe their use
  • Describe the purpose of the major components of a computer system
  • List the 3 types of buses found in computer systems
  • List the major components of the CPU and describe the purpose of each

SECTION  I - NUMBERING AND CODING SYSTEMS

  • SECTION  I-1: Decimal and Binary Number System
  • SECTION  I-2: Converting from Decimal to binary
  • SECTION  I-3: Converting from Binary to Decimal
  • SECTION  I-4: Hexadecimal Number System
  • SECTION  I-5: Converting Between Binary and Hex
  • SECTION  I-6: Converting from Decimal to Hex
  • SECTION  I-7: Converting from Hex to Decimal
  • SECTION  I-8: Counting in Bases 10, 2, and 16
  • SECTION  I-9: Addition of Binary and Hex Numbers
  • SECTION  I-10: 2's Complement
  • SECTION  I-11: Addition and Subtraction of Hex Numbers
  • SECTION  I-12: ASCII Code

SECTION  II - DIGITAL SYSTEM

  • SECTION  II-1: Binary Logic and Logic Gates
  • SECTION  II-2: Logic Design Using Gates
  • SECTION  II-3: Decoders and Flip-Flop Application of Logic gates

SECTION  III: Inside the Computer 

  • SECTION  III-1: K, mega, giga, byte, ROM, RAM
  • SECTION  III-2: Internal Organization of Computers
  • SECTION  III-3: Data Bus and Address Bus in Computers
  • SECTION  III-4: CPU, RAM and ROM in Computers
  • SECTION  III-5: Inside Central Processing Units
  • SECTION  III-6: Internal Working of Computers

Basic Introduction of Chapter # 2

In this chapter, we will cover the Binary number system represents all numbers with a combination of the two binary digits, 0 and 1. The use of binary systems is necessary in digital computers because only two states can be represented: ON or OFF. Any binary number can be coded directly into its hexadecimal equivalent for the convenience of humans. Converting from binary/hex to decimal, and vice versa, is a straight forward process that becomes easy with practice. The ASCII code is a binary code used to represent alphanumeric data internally in the computer. It is frequently used in peripheral devices for input and output.

The Logic gates AND, OR, and inverter are the basic building blocks of simple circuits. NAND, NOR and XOR gates are also used to implement circuit design. Half-adders and Full-adders were given as examples of the use of logic gates for circuit design. Decoders are used to detect certain addresses. Flip-flops are used to latch its data until other circuits are ready for it.

The major components of any computer system are the CPU, memory, and I/O devices. "Memory" refers to temporary or permanent storage of data. In most systems, memory can be accessed as bytes of words. The terms kilobyte, megabyte, gigabyte, and terabytes are used to refer to large numbers of bytes. There are two main types of memory in computer systems. RAM (Random Access Memory) and ROM Read Only Memory. RAM is used for temporary storage of programs and data. ROM is used for permanent storage of programs and data. All components of the computer system are under the control of the CPU. Peripheral devices such as I/O (input / Output) devices allow the CPU to communicate with humans or other computer systems.

There are 3 types of buses in computers: Address, Control and Data. Control buses are used by the CPU to direct other devices. The address bus is used by the CPU to locate a device or a memory location. Data buses are used to send information back and forth between the CPU and other devices.

Now we will go though each section of this chapter # 2 one by one in details...

SECTION I-1: Decimal and Binary Number System

Human begins use bae 10 (decimal) arithmetic. Computers use base 2 (binary) system. Although there has been speculation that the origin of the base 10 system is the fact that human beings have 10 fingers, there is no speculation about the reason behind the use of the binary system in computers. The binary system is used in computers because  1 and 0 represent the two voltage levels of ON and OFF. In base 10 there are 10 different distinct symbols 0,1,2,3,4,5,6,7,8,9 and in base 2 there are only two 0, and 1, with which to generate numbers. Base 10 contains digits 0 through 9; binary contains digits 0 and 1 only. There two binary digits, 0 and 1, are commonly referred to as bits.

SECTION I-2: Converting from Decimal to Binary

One method of converting from decimal to binary is to divide the decimal number by 2 repeatedly, keeping track of the remainders, This process continues until the quotient becomes zero. The remainders are then written in reverse order to obtain the binary number. This is demonstrated below.

Convert 2510 to Binary
    Quotient Remainder  
25/2 = 12 1 LSB (Least Significant Bit)
12/2 = 6 0  
6/2 = 3 0  
3/2 = 1 1  
1/2 = 0 1 MSB (Most Significant Bit)
Therefore, 2510 = 110012

 

SECTION I-3: Converting from Binary to Decimal

To convert from Binary to Decimal, it is important to understand the concept of weight associated with each digit position. Recall the weight of numbers in the Base 10 system. Each digit position of a number in Base 2 has a weight associated with it.

74068310
3X100 = 3
8X101 = 80
6X102 = 600
0X103 = 0000
4X104 = 40000
7X105 = 700000
TOTAL 740683
1101012 Decimal Binary
1X20 = 1X1 = 1 1
0X21 = 0X2 = 0 00
1X22 = 1X4 = 4 100
0X23 = 0X8 = 0 0000
1X24 = 1X16 = 16 10000
1X25 = 1X32 = 32 110101
TOTAL 53 110101
Convert 110012
Weight   16     8     4     2     1  
Digits 1 1 0 0 1
Total 16+ 8+ 0+ 0+ 1
= 2510

Knowing the weight associated with each binary bit position allows one to convert a decimal number to binary directly instead of going through the process of repeated division. This is demonstrated below.

Convert 3910 to Binary
Weight 32 16 8 4 2 1
Digits 1 0 0 1 1 1
Total 32+ 0+ 0+ 1+ 1+ 1
= 3910 Therefore, 3910 = 1001112

 

 

 

 

 

SECTION I-4: Hexadecimal Number System

Base 16, or the Hexadecimal system is used as a convenient representation of binary numbers. It is much easier for a human being to represent a string of 0s and 1s such as 100010010110 as its Hexadecimal equivalent of 896H. The binary system has two digits 0 and 1. The base 10 system has 10 digits, 0 through 9. The Hexadecimal, base 16, system has 16 digits. In base 16, the first 10 digits 0 to 9, are the same as in decimal, and for the remaining 6 digits, the letters A, B, C, D, E, and F are used. The Hexadecimal number system is demonstrated below.

Decimal Binary Hex
0 0000 0
1 0001 1
2 0100 2
3 0011 3
4 0010 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F

 

SECTION I-5: Converting Between Binary and Hex Number System

To represent a Binary Number as its equivalent Hexadecimal number, start from the right and group 4 bits at a time, replacing each 4-bit binary number with its Hex equivalent. To convert from Hex to Binary, each Hex digits is replaced with its 4-bit binary equivalent. This is demonstrated below in Examples.

Represent Binary 100111110101 in Hex
First the number is grouped into sets of 4 bits : 1001 1111 0101
Then each group of 4 bits is replaced with its hex equivalent:
1001 1111 0101
9 F 5
Therefore, 100111110101= 9F5 Hexadecimal
Convert Hex 29B to Binary
2 9 B
0010 1001 1011
Dropping the leading zeros gives 1010011011

 

SECTION I-6: Converting from Decimal to Hex Number System

Converting from Decimal to Hex can be approached in two ways:

  1. Converting to Binary first and then convert to Hex. This method is demonstrated below.
  2. Convert directly from Decimal to Hex by repeated division, keep tracking of the remainders
Convert 4510 to Hex
32/1 16/0 8/1 4/1 2/0 1/1

First Convert to Binary

32+8+4+1 = 4510

45= 0010 11012 = 2D
Convert 62910 to Hex
512 256 128 64 32 16 8 4 2 1
1 0 0 1 1 1 0 1 0 1
62910 - (512+64=32+16+4+1) = 0010 0111 01012 = 275 Hex
Convert 171410 to Hex
1024 512 256 128 64 32 16 8 4 2 1
1 1 0 1 0 1 1 0 0 1 0
171410  - (1024+512+128+32+16+2) = 0110 1011 00102 = 6B2 Hex

 

SECTION I-7: Converting from Hex to Decimal

Converting from Hex to to decimal can also be approached in two ways:

  1. Convert from Hex to Binary and then to Decimal Example is demonstrated below.
  2. Convert directly from Hex to Decimal by summing the weight of all digits.

 

Convert Hexadecimal number  6B216  to Decimal
6B216 = 6 = 0110, B = 1011, 2 = 0010 So 6B216 = 0110 1011 00102
210 29 28 27 26 25 24 23 22 21 20
1024 512 256 128 64 32 16 8 4 2 1
1 1 0 1 0 1 1 0 0 1 0
1024 + 512 + 128 + 32 + 16 + 2 = 171410

 

Convert Hexadecimal number 9F2D16 to Decimal Base 10
9F2D16 = 1001 1111 0010 11012
9 = 1001,     F = 1111,    2 = 0010,    D = 1101
1x215 0x214 0x213 1x212 1x211 1x210 1x29 1x28 0x27 0x26 1x25 0x24 1x23 1x22 0x21 1x20
1x32768 0x16384 0x8192 1x4096 1x2048 1x1024 1x512 1x256 0x128 0x64 1x32 0x16 1x8 1x4 0x2 1x1
32768 0 0 4096 2048 1024 512 245 0 0 32 0 8 4 0 1
32768 + 4096 + 2048 + 1024 + 512 + 256 + 32 + 8 + 4 + 1 = 40,74910

 

SECTION I-8: Counting in Bases 10, 2, and 16

Table Below demonstrated the relationship between all three Bases. Showed the sequence of numbers from 0 to 31 in decimal, along with the equivalent Binary and Hex numbers. In each base that when one more is added to the the highest digit, that digit becomes zero and a 1 is carried to the next-highest digit position. In decimal, 9 + 1 = 0 with a carry to the next-highest position. In Binary, 1 + 1 = 0 with a carry; similarly, in Hex, F + 1 = 0 with a carry.

Decimal Binary Hex
0 00000 0
1 00001 1
2 00010 2
3 00011 3
4 00100 4
5 00101 5
6 00110 6
7 00111 7
8 01000 8
9 01001 9
10 01010 A
11 01011 B
12 01100 C
13 01101 D
14 01110 E
15 01111 F
16 10000 10
17 10001 11
18 10010 12
19 10011 13
20 10100 14
21 10101 15
22 10110 16
23 10111 17
24 11000 18
25 11001 19
26 11010 1A
27 11011 1B
28 11100 1C
29 11101 1D
30 11110 1E
31 11111 1F

 

SECTION I-9: Addition of Binary and Hex Numbers

The Addition of Binary is a very straightforward process as demonstrated below showing the addition of two bits.

Binary Addition
A + B Carry Sum
0 + 0 0 0
0 + 1 0 1
1 + 0 0 1
1 + 1 1 0

 

The discussion of subtraction of binary numbers is bypassed since all computers use the addition process to implement subtraction. Although computers have adder circuitry, there is no separate circuitry subtracters. Instead, adders are used in conjunction with 2's complement circuitry to perform subtraction. To implement " x - y " , the computer takes the 2's complement of 'y' and adds it to ''x'. Below example demonstrated the addition of Binary numbers.

 

Add Binary numbers 1101 and 1001. Check against their decimal equivalents
Binary Decimal
    1101 13
+  1001 9
  10110 22

 

SECTION I-10: 2's Complement of Binary Number

To get the 2's complement of a Binary number, invert all the bits and then add 1 to the result. Inverting the bits is simply a matter of changing all 0's to 1's and 1's to 0's. This is called the 1's complement. Example is demonstrated below.

 

Take the 2's complement of 10011101
10011101 Binary Number
01100010 1's Complement
+          1  
01100011 2's Complement

 

SECTION I-11: Addition and Subtraction of Hex Numbers

By studying issues related to software and hardware of computers, it is often necessary to add or subtract hex numbers. Hex addition and subtraction is explained and demonstrated below.

Addition of Hex Numbers:

Starting with the least significant digits, the digits are added together. If the result is less than 16, write that digit as the sum for that position. If it is greater than 16, subtract 16 from it to get the digit and carry 1 to the next digit. This is shown in example below.

 

Perform Hex Addition : 23D9 + 94BE  
     23D9 D = 1410 LSD: 9 + 14 = 23 23 - 16 = 7 with a carry
+   94BE E = 1310, B = 1110 1 + 13 + 11 = 25 25 - 16 = 9 with a carry
    B897   1 + 3 + 4 = 8  
  B = 1110 MSD: 2 + 9 = B  

 

Subtraction of Hex Numbers:

In subtracting two Hex numbers, if the second digit is greater than the first, borrow 16 from the preceding digit. This is demonstrated in example below.

 

Perform Hex Subtraction: 59F - 2B8
  59F F = 1510 LSD: 15 - 8 = 7
- 2B8 B = 1110 (9+16=25) ,  25 - 11 = 14 (E)
  2E7 E = 1410 (5 - 1 = 4) , 4 - 2 = 2

 

 

 

SECTION I-12: ASCII - American Standard Code for Information Interchange

All information in the computer must be represented by 0's and 1's, binary patterns must be assigned to letters and other characters. In the 1960's a standard representation called ASCII was established. The ASCII code assigns Binary patterns for numbers 0 to 9, all the letters of the English alphabet, both upper-case capital and lower case, and many control codes and punctuation marks. The advantage of this system i s that it is used by most computers, so that information can be shared among computers. The ACSII system uses a total of 7 bits to represent each code. Example 100 0001 is assigned to the upper-case letter "A" and 110 0001 is for the lower-case letter "a". A zero is placed in the most significant bit position to make it an 8-bit code. A completed list of ASCII codes is demonstrated below.

ascii-codes-list.jpg

The use of ASCII is not only standard for keyboards used in United States but also many other countries to provides a standard for printing and displaying characters by output devices such as printers and monitors. The pattern of ASCII codes was designed to allow for easy manipulation of ASCII data. Digits 0 to 9 are represented by ASCII codes 30 through 39. This enables a program to easily convert ASCII to decimal by masking off the "3" in the upper nibble. Also notice that there is a relationship between the uppercase and lowercase letters. The uppercase letters are represented by ACSII codes 41 through 5A and lowercase letters are represented by codes 61 through 7A. The only bit that is different between the uppercase "A" and lowercase "a" is bit 5. Therefore, conversion between uppercase and lowercase is as simple as changing bit 5 of the ASCII code.

 

 

SECTION II-1: DIGITAL SYSTEM - Binary Logic and Logic Gates

Binary Logic:

Computers use the binary number system because the two voltage levels can be represented as the two digits 0 and 1. Signals in digital electronics have two distinct voltage levels. A system may define 0V as logic '0' and +5V as logic '1'. Picture below demonstrated this system with built-in tolerances for variations in the voltage.

Binary Signals:

binary-signals.jpg

Logic Gates:

Binary logic gates are simple circuits that take one or more input signals and send out one output signal. Several of these are demonstrated below.

AND Gate:-

The AND gate takes two or more inputs and performs a logic AND on them. If both inputs to the AND gate are 1, the output will be 1. Any other combination of inputs will give a 0 output. The example shows two inputs, x and y. Multiple outputs are also possible for logic gates. In the case of AND, if all inputs are 1, the output is 1. If any input is 0, the output is 0.

 

Logical AND Function
Inputs Output
X Y X AND Y
00 0
01 0
10 0
11 1

and-logic-gate.jpg

 

OR Gate:-

The OR logic function will output a 1 if one or more inputs is 1. If all inputs are 0, then and only then will the output be 0.

 

Logical OR Function
Inputs Output
X Y X OR Y
00 0
01 1
10 1
11 1

or-logic-gate.jpg

 

Tri-State Buffer:-

A buffer gate does not change the logic level of the input. It is used to isolate or amplify the signal.

tri-state-buffer.jpg

 

Inverter:-

The inverter, also called NOT gate, outputs the value opposite to that input to the gate. A 1 input will give a 0 output, while a 0 input will give a 1 output.

 

Logical Inverter
Input Output
X NOT X
0 1
1 0

not-logic-gate.jpg

 

XOR Gate:-

The XOR gate performs an exclusive-OR operation on the inputs. Exclusive-OR produces a 1 output if one, but only one, input is 1. If both operands are 0, the output is 0. If both operands are 1, the output is also 0. In below truth table whenever are two inputs are the same, the output is 0. This function can be used to compare two bits to see if they are the same.

 

Logical XOR Function
Inputs Output
X Y X XOR Y
00 0
01 1
10 1
11 0

xor-logic-gate.jpg

 

NAND Gate:-

The NAND gate functions like an AND gate with an inverter on the output. It produces a 0 output when all the inputs are 1. Otherwise it produces a 1 output when all the inputs are 0. NAND gate are used extensively in digital design because they are easy and inexpensive to fabricate. Any circuit that can be designed with AND, OR, XOR and INVERTER gates can be implemented using only NAND and NOR gates

 

Logical NAND Function
Inputs Output
X Y X NAND Y
00 1
01 1
10 1
11 0

nand-logic-gate.jpg

 

NOR Gate:-

The NOR gate functions like an OR gate with an inverter on the output. It produces a 1 output when all the inputs are 0. Otherwise it produces a 0 output when all the inputs are 1. NOR gate are used extensively in digital design because they are easy and inexpensive to fabricate. Any circuit that can be designed with AND, OR, XOR and INVERTER gates can be implemented using only NAND and NOR gates

 

Logical NOR Function
Inputs Output
X Y X NOR Y
00 1
01 0
10 0
11 0

nor-logic-gate.jpg

 

 

SECTION II-2: Logic Design Using Gates

If we add two binary digits there are four possible outcomes:

A simple Logic design to add two Binary digits
  Carry Sum
0 + 0 = 0 0
0 + 1 = 0 1
1 + 0 = 0 1
1 + 1 = 1 0

 

When we add 1 + 1 we get 0 with a carry to the next higher place. We will need to determine the sum and the carry for this design. The sum column above matches the output for the XOR function, and that the carry column matches the output for the AND function. Below demonstrated a simple adder implemented with XOR and AND gates, and demonstrated the same logic circuit implemented with AND and OR gates and inverters.

 

Two Implementations of a Half-Adder
Half-Adder Using XOR and AND Half-Adder Using AND, OR, Inverters
half-adder-using-xor-and.jpg half-adder-using-xor-and-inverters.jpg

Block Diagram of a Half-Adder:-

Demonstrated a block diagram of a half-adder. Two half-adders can be combines to form an adder that can add three input digits. This is called a full-adder.

 

Block Diagram of a Half-Adder
block-diagram-of-half-adder.jpg

 

Full-Adder Built From a Half-Adder:-

Demonstrated below the logic diagram of a full-adder, along with a block diagram that masks the details of the circuit.

 

Full-Adder Built From a Half-Adder:-
full-adder-built-from-half-adder.jpg full-adder-built-from-half-adder-block.jpg

 

Three Bit Adder Using Three Full-Adders:-

 

3 Bit Adder using three Full-adders
3-bit-adders-using-three-full-adders.jpg

 

SECTION II-3: Decoders and Flip-Flop Application of Logic Gates

Decoders:-

Decoders are widely used for address decoding in computer design. Demonstrated below decoders for 9 (1001 binary) and 5 (0101) using inverters and AND gates.

 

Address Decoders
address-decoder-for-9.jpg address-decoder-for-5.jpg

Address decoder for 9 (Binary 1001) The Output of the AND gate will be 1 if and only if input is Binary 1001

Address decoder for 5 (Binary 0101). The output of the AND gate will be 1 if and only if the input is Binary 0101

 

Flip-Flops:-

A widely used component in digital systems is the Flip-flop. Flip-flops are used to store data. Below diagram demonstrated the logic diagram, block diagram and the truth table for a Flip-flop.

The D Flip-flop is widely used to latch data. Notice from the truth table that a D type Flip flops grabs the data at the input as the clock is activated. A D type Flip-flop holds the data as long as the power is ON.

 

D Flip-Flops
d-flip-flops-circuit-diagram.jpg d-flip-flops-block-diagram.jpg d-flip-flops-truth-table.jpg
D Flip-flop Circuit Diagram D Flip-flop Block Diagram D Flip-flop Truth Table

 

SECTION III-1: INSIDE THE COMPUTER - K, mega, giga, byte, ROM, RAM

 

The concept that will be discussed, applicable to all computers, including the IBM PC, PS/2, and compatibles. One of the most important features of a computer is how much memory is has. Bit is a binary digit that can have the value 0 or 1. A Byte is defined as 8 bits. A nibble is a half byte, or 4 bits. A word is two bytes, or 16 bits. The display is intended to show the relative size of these units, they could all be composed of any combination is zeros and ones.

 

Bit       0
Nibble       0000
Byte     0000 0000
Word 0000 0000 0000 0000

 

A Kilobyte is 210 bytes, which is 1024 bytes. The abbreviation K is often used to represent kilobytes. e.g; some Floppy disks hold 356K of data. A megabyte, it 220 bytes, which is over 1 million bytes; it is exactly 1,048,576 bytes. A gigabytes is 230 bytes, which is over 1 billion bytes, and terabytes is 240, which is over 1 trillion bytes.

How these some on terms are used in computers, suppose that a given computer has 16 megabytes of memory. That would be 16 X 2020, or 24 X 220, which is 224. Therefore 16 megabytes is 224 bytes.

Two types of memory commonly used in microcomputers are RAM, which stands for "random access memory", sometimes called Read/Write memory. ROM stands for "read only memory", RAM is used by the computer for temporary storage of programs that it is running. That data is lost when the computer is turned OFF. RAM is sometimes called volatile memory. ROM contains programs and information essential to operation of the computer. The information in ROM is permanent, cannot be changes by the user, and is not lost when the power is turned OFF. Therefore, it is called nonvolatile memory.

 

 

SECTION III-2: Internal Organization of Computers

The internal working of every computer can be broken down into three parts:

  • CPU (Central Processing Unit)
  • Menory
  • I/O (Input / Output) devices

 

Inside the Computer
inside-the-computer.jpg

 

The function is the CPU is to execute and process information stores in memory. The function of the I/O devices such as the keyboard and video monitor is to provide a means of communicating with the CPU. the CPU is connected to memory and I/O through strips of wire called a bus. The bus inside a computer carries information from place to place just as a street bus carried people from place to place. In every computer, there are three types of buses:

  1. Address Bus
  2. Data Bus
  3. Control Bus

 

For a device, memory or I/O to be recognized by the CPU, it must be assigned an address. The address assigned to a given device must be unique; no two devices are allowed to have the same address. The CPU puts the address in binary, on the address bus, and the decoding circuitry finds the device. Then the CPU uses the data bus either to get data from that device or to send data to it. The control buses are used to provide read or write signals to the device to indicate if the CPU is asking for information or sending information. Of the three buses, the address bus and data bus determine the capability of a given CPU.

 

 

SECTION III-3: Data Bus and Address Bus in Computers

The address bus is used to identify the devices and memory connected to the CPU, the more address buses available, the larger the number of devices that can be addressed. The number of address buses for a CPU determines the number of locations with which it can communicate. The number of locations is always equal to 2x, where x is the number of address lines, regardless of the size of the data bus. A CPU with 16 address lines can provide a total of 65,536 (216) or 64K of addressable memory. Each location can have a maximum if 1 byte of data. This is because all general-purpose microprocessor CPU's are what is called byte addressable. The IBM PC AT uses a CPU are what is called byte addressable. The total accessible memory is 16 megabytes,  224 = 16 megabytes. There would be 224 locations, as each location is 1 byte, there would be 16 megabytes of memory. The address bus is a unidirectional bus, which means that the CPU uses the address bus only to send out addresses. To summarize, the total number of memory locations addressable by a given CPU is always equal to 2x, where x is the number of address bits, regardless of the size of the data bus.

Data Bus, Address Bus and Control Bus Inside Internal Organization of Computers
internal-organization-of-computer.jpg

 

SECTION III-4: CPU, RAM and ROM in Computers

For the CPU to process information, the data must be stored in RAM or ROM. The function of ROM in computers is to provide information that is fixed and permanent. This is information such as tables for characters patterns to be displayed on the video monitor, or programs that are essential to the working of the computer, such as programs for testing and finding the total amount of RAM installed on the system, or for displaying information that can change with time, such as various versions of the operating system and application packages such as work processing or tax calculation packages. These programs are loaded from the hard device into RAM to be processed by the CPU. The CPU cannot get the information from the disk directly because the disk is too slow. The CPU first seeks the information to be processed from RAM or ROM. Only if the data is not there does the CPU seek it from a mass storage device such as disk, and then it transfers the information to RAM. For this reason, RAM and ROM are sometimes referred to as primary memory and disks are called secondary memory.

 

Block Diagram of the Internal Organization of the Computers

 

 

 

SECTION III-5: Inside Central Processing Units

A program stored in memory provides instructions to the CPU to perform an action. The action can simply be adding data such as payroll data or controlling a machine such as a robot. The function of the CPU is to fetch these instructions from memory and execute them. To perform the actions of fetch and execute, all CPU's are equipped with resources such as the following:

  1. Foremost among the resources at the disposal of the CPU are a number of registers. The CPU used registers to store information temporarily. The information could be two values to be processed, or the address of the value needed to be fetched from memory. Registers inside the CPU can be 8-bit, 16-bit, 32-bit or even 64-bit registers, depending on the CPU. In general, the more and bigger the registers, the better the CPU. The disadvantage of more and bigger registers is the increased cost of such a CPU.
  2. The CPU also has what is called ALU (Arithmetic Logic Unit). The ALU section of the CPU is responsible for performing arithmetic functions such as Addition, Subtract, Multiply and Divide, and logic functions such as AND, OR, and NOT.
  3. Every CPU has what is called a program counter. The function of the program counter is to point to the address of the next instruction to be executed. As each instruction is executed, the program counter is incremented to point to the address of the next instruction to executed. The contents of the program counter are placed on the address bus to find and fetch the desired instruction. In the IBM PC, the program counter is a register called IP, or the instruction pointer.
  4. The function of the instruction decoder is to interpret the instruction fetched into the CPU. One can think of the instruction decoder as a kind of dictionary, storing the meaning of each instruction and what steps the CPU should take upon receiving a given instruction. Just as a dictionary requires more pages, the more words it defines, a CPU capable of understanding more instructions required more transistors to design.

 

 

 

SECTION III-6: Internal Working of Computers

A step-by-step analysis of the process a CPU would go through to add three numbers is demonstrated below. Assume an imaginary CPU has registers called A, B. C, and D. It has an 8 bit of data bus and a 16 bit of address bus. Therefore, the CPU can access memory from addresses 0000 to FFFFH (for a total of 10000H locations). The action to be performed by the CPU is to put hexadecimal value 21 into register A, and then add to register A values 42H and 12H. Assume that the code for the CPU to move a value to register A is 1011 0000 (B0H) and the code for adding a value to register A is 0000 0100 (04H). The  steps to perform them are demonstrated below.

 

Action Code Data
Move value 21H into register A B0H 21H
Ass value 42H to register A 04H 42H
Add value 12H to register A 04H 12H

 

If the program to perform the actions listed above is stored in memory locations starting at 1400H, the following would represent the contents for each memory address location.

 

Memory Address Contents of Memory Address
1400 (B0) Code for moving a value to register A
1401 (21) Value to be moved
1402 (04) Code for adding a value to register A
1403 (42) Value to be added
1404 (04) Code for adding a value to register A
1405 (12) Value to be added
1406 (F4) Code for halt

 

The actions performed by the CPU to run the program above explained below:

  1.  The CPU's program counter can have a value between 0000 and FFFFH. The program counter must be set to the value 1400H, indicating the address of the first instruction code to be executed. After the program counter has been loaded with the address of the first instruction, the CPU is ready to execute.
  2. The CPU puts 1400H on the address bus and sends it out. The memory circuitry finds the location while the CPU activates the READ signal, indicating to memory that it wants the byte at location 1400H. This causes the contents of memory location 1400H, which is B0, to be put on the data bus and brought into the CPU.
  3. The CPU decodes the instruction B0 with the help of its instruction decoder dictionary. When it finds the definition for that instruction it knows it must bring into register A of the CPU the byte in the next memory location. It commands its controller circuitry to do exactly that. When it brings in value 21H from memory location 1401, it makes sure tha the doors of all registers are closed except register A. Therefore, when value 21H comes into the CPU it will go directly into register A. After completing one instruction, the program counter points to the address of the next instruction to be executed, which in this case is 1402H. Address 1402 is send our on the address bus to fetch the next instruction.
  4. From memory location 1402H the CPU fetches code 04H. After decoding, the CPU knows that it must add the byte sitting at the next address (1403) to the contents of register A. After the CPU brings the value, 42H, into register A, it provides the contents of register A along with this value to the ALU to perform the addition. It then takes the result of the addition from the ALU's output and puts it in register A. Meanwhile the program counter becomes 1404H , the address of the next instruction.
  5. Address 1404H is put on the address bus and the code is fetched into the CPU, decoded, and executed. This code again is adding a value to register A. The program counter and fetching instructions.

Now suppose that address 1403H contained value 04 instead of 42H. How would the CPU distinguish between data 04 to be added and code 04?. Code 04 for this CPU means "move the next value into register A". Therefore, the CPU will not try to decode the next value. It simple moves the contents of the following memory location into register A, regardless of its value.

Chapter#3 - THE PIC ASSEMBLY LANGUAGE PROGRAMMING AND ARCHITECTURE

Upon Completion of this chapter, You will be able to:

  • Examine the data RAM file register of the PIC micro-controller
  • Manipulate data using the WREG and MOV instruction
  • Perform simple operations such as DD and MOVE using the file register and access bank in the PIC micro-controller
  • Explain the purpose of the status register
  • Discuss data RAM memory space allocation in the PIC micro-controller
  • List Special function registers of the PIC micro-controller
  • Code simple PIC Assembly Language instructions
  • Describe PIC data types and directives
  • Assemble and run a PIC program using MPLAB
  • Describe the sequence of events that occur upon PIC power-up
  • Examine programs in PIC ROM code
  • Explain the PIC ROM memory map
  • Detail the execution of PIC Assembly language instruction
  • Understand the RISC and Harvard architectures of the PIC micro-controller
  • Examine the PIC's registers and data RAM using the MPLAB simulator

 

SECTION  I - THE WREG , MOVLW, ADDLW IN THE PIC

  • SECTION  I-1: The WREG Register in the PIC micro-controller
  • SECTION  I-2: The MOVLW instruction in the PIC micro-controller
  • SECTION  I-3: The ADDLW instruction in the PIC micro-controller

SECTION  II - FILE REGISTER IN THE PIC MICRO-CONTROLLER

  • SECTION  II-1: File register (Data RAM) Space Allocation in PIC micro-controller
  • SECTION  II-2: Special Function Registers SFR's in PIC micro-controller
  • SECTION  II-3: General-Purpose Registers or RAM in PIC micro-controller
  • SECTION  II-4: General Purpose Registers RAM Vs EEPROM in PIC micro-controller
  • SECTION  II-5: File Register and Access bank in the PIC18

SECTION  III: INSTRUCTION WITH THE DEFAULT ACCESS BANK

  • SECTION  III-1: MOVWF Instruction in the PIC micro-controller
  • SECTION  III-2: Instructions involving the WREG and the Access Bank
  • SECTION  III-3: ALU Instructions Using Both WREG and FileReg
  • SECTION  III-4: File Register Instructions Using FileReg or WREG and Destination
  • SECTION  III-5: The COMF Instruction in the PIC micro-controller
  • SECTION  III-6: DECF Instruction in the PIC micro-controller
  • SECTION  III-7: MOVF Instruction in the PIC micro-controller
  • SECTION  III-8: MOVFF Instruction in the PIC micro-controller

SECTION  IV: THE STATUS REGISTER IN PIC MICRO-CONTROLLER

  • SECTION  IV-1: Bits of PIC Status Resister
  • SECTION  IV-2: ADDLW Instruction and the Status Register
  • SECTION  IV-3: Instructions That Affect Flag Bits
  • SECTION  IV-4: Flag Bits and Decision Making

SECTION  V: PIC DATA FORMAT AND DIRECTIVES

  • SECTION  V-1: Data Format Representation Hex Numbers
  • SECTION  V-2: Data Format Representation Binary Numbers
  • SECTION  V-3: Data Format Representation Decimal Numbers
  • SECTION  V-4: Data Format Representation ASCII Character
  • SECTION  V-5: Assembler Directives EQU - Equate
  • SECTION  V-6: Assembler Directives SET
  • SECTION  V-7: Using EQU for Fixed Data Assignment
  • SECTION  V-8: Using EQU for SFR Address Assignment
  • SECTION  V-9: Using EQU for RAM Address Assignment
  • SECTION  V-10: ORG - Origin, END, LIST, #include, _config, radix Directives
  • SECTION  V-11: Rules for Labels in Assembly Language
  • SECTION  V-12: Using EQU for RAM Address Assignment

SECTION  VI: INTRODUCTION TO PIC ASSEMBLY PROGRAMMING

 

  • SECTION  VI-1: Introduction to PIC Assembly Programming
  • SECTION  VI-2: Structure of Assembly Language
  • SECTION  VI-3: Assembling and Linking a PIC Program
  • SECTION  VI-4: asm, err, and Object Files in PIC
  • SECTION  VI-5: "lst" and "map" Files in PIC
  • SECTION  VI-6: The Program Counter and Program ROM Space in PIC
  • SECTION  VI-7: ROM Memory map in the PIC18 Family
  • SECTION  VI-8: Where the PIC Wakes Up when it is Powered Up
  • SECTION  VI-9: Placing Code in Program ROM
  • SECTION  VI-10: Executing a Program Byte by Byte
  • SECTION  VI-11: ROM Width in the PIC18
  • SECTION  VI-12: Harvard Architecture in the PIC
  • SECTION  VI-13: Instruction Size of the PIC18 MOVLW Instruction Formation
  • SECTION  VI-14: Instruction Size of the PIC18 ADDLW Instruction Formation
  • SECTION  VI-15: Instruction Size of the PIC18 MOVWF Instruction Formation
  • SECTION  VI-16: Instruction Size of the PIC18 MOVFF Instruction Formation
  • SECTION  VI-17: Instruction Size of the PIC18 GOTO Instruction Formation
  • SECTION  VI-18: Coming from other microprocessors to the PIC18
  • SECTION  VI-19: The RISC Architecture in the PIC
  • SECTION  VI-20: Features of RISC Architecture in the PIC
  • SECTION  VI-21: Viewing Register and Memory With MPLAB Simulator

       

      Basic Introduction of Chapter # 3

      This Chapter will began with an exploration of the major registers of the PIC, including WREG, SFR's, and general-purpose data RAM, and the program counter. The use of these registers will be demonstrated in thr context of programming examples. The process of creating an assembly language program will be described from writing the source files, to assembling it, linking, and executing the program. The program counter register always points to the next instruction to be executed. The way the PIC uses program ROM space will be explored. PIC assembly language programmers must be aware of where programs are placed in ROM, and how much memory is available.

      An assembly language program is composed of a series of statements that are either instructions or pseudo-instructions, also called directives. Instructions are translated by the assembler into machine code. Pseudo instructions are not translated into machine code. They direct the assembler in how to translate instructions into machine code. Some pseudo instructions, called data directives, are used to define data. Data is allocated in byte size increments. The data can be in a binary, hex, decimal, or ASCII formats.

      Flags are useful to programmers because they indicate certain conditions, such as carry or zero, that result from execution of instructions. The concepts of RISC and Harvard architectures were also explored.

      The RISC architecture allows the design of much more powerful micro controllers. It has a simple instruction set and uses of a large number of registers. Harvard architecture allows us to bring more code and data to the CPU faster. The use of a wider data in the PIC18 allows us to fetch an instruction every every cycle because the PIC instructions are typically 2 bytes.

       

      SECTION I-1: The WREG Register in the PIC micro-controller

      CPUs use many registers to store data temporarily. PIC micro-controllers have many registers for arithmetic and logic operations.

      WREG Register:-

      In the CPU, registers are used to store information temporarily. That information could be a byte of data to be processed, or an address pointing to the data to be fetched. The vast majority of PIC registers are 8-bit registers. In the PIC there is only one data type: 8-bit as shown 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 chunks before it is processed.

       

      wreg-register.jpg

       

      The 8 bit WREG register is the most widely used register in the PIC micro-controllers. WREG stands for working register, as there is only one. The WREG register is the same as the accumulator in other microprocessors. The WREG register is used for all arithmetic and logic instructions. To understand the use of WREG register, we will show it in the context of two simple instructions: MOVE and ADD in the next sections.

      SECTION I-2: The MOVLW Instruction in the PIC micro-controller

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

      MOVLW k ;move literal value K into WREG

       

      K is an 8 bit value that can range from 0-255 in decimal, or 00-FF in hex. The 'L' stands for literal, a number must be used. In other words, if we see the word literal in any instruction, we are dealing with an actual value that must be provided right there with the instruction. This is similar to the immediate value we see in other microprocessors. In MOVLW, the letter L (literal) comes first and then the letter W (WREG), which means "move a literal value to WREG" the destination.

      The folowing instruction loads the WREG register with a literal value of 25H i.e, 25 in hex.

      MOVLW 25H ;move value 25H unto WREG (WREG = 25H)

       

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

      MOVLW 87H ;load 87H into WREG (WREG = 87H

       

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

      MOVLW 15H ;load 15H into WREG (WREG = 15H)

       

      SECTION I-3: The ADDLW instruction in the PIC micro-controller

      The ADDLW instruction has the following format:

      ADDLW K ;ADD literal value

       

      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. To add two numbers such as 25H and 34H, one can do the following.

      MOVLW 25H ;load 25H into WREG
      ADDLW 34H ;add value 34 to W (W = W + 34)

       

      PIC WREG and ALU Using Literal Value
      pic-wreg-alu-using-literal-value.jpg

      Execute the above lines results in WREG = 59H (25H + 34H = 59H)

      The following program will add 12H, 16H, 11H, and 43H:

      MOVLW 12H ;load value 12H into WREG (WREG = 12H)
      ADDLW 16H ;add 16 to WREG = 28H)
      ADDLW 11H ;add 11 to WREG (WREG = 39H)
      ADDLW 43H ;add 43 to WREG (WREG = 7CH)

       

      When programming the WREG register of the PIC micro-controller 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 micro-controllers.
      2. If values 0 to F are moved into an 8 bit register such as WREG, the rest of the bits are assumed to be all zeros. For example, in "MOVLW 5H" the result will be WREG = 05H; i.e. 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 .err file.

       

      MOVLW 7F2H ;Illegal 7F2H > 8 bits (FFH), becomes F2H
      MOVLW 456H ;Illegal 456H > FFH, becomes 56H
      MOVLW 60A5H ;Illegal but becomes A5H

       

      SECTION II-1: File register (Data RAM) Space Allocation in PIC micro-controller

      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.

      File Register (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. As with WREG, we can perform arithmetic and logic operations on many locations of the file register data RAM. The PIC micro-controllers file register size ranges from 32 bytes to several thousand bytes depending on the chip. Even within the same family, the size of the file register data RAM varies from chip to chip. The file register data RAM has a byte-size width, just like WREG. The file register data RAM in PIC is divided into two sections:

      1. Special Function Registers (SFR)
      2. General-Purpose Registers (GPR) or General Purpose RAM (GP RAM)

       

      SECTION II-2: Special Function Registers in PIC micro-controller

      The Special Function Register (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 micro-controller or peripheral. The PIC SFRs are 8 bit registers. The number of locations in the file register set aside for SFR depends on the pin numbers and peripheral functions supported by that chip. That number can vary from chip to chip even among members of the same family. Some have a few as 7 (8 pin PIC12C508 with no on-chip analog to digital converter). The more timers we have in a chip, the more SFR registers we will have.

       

      SECTION II-3: General-Purpose Registers or RAM in PIC micro-controller

      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 data we want as long as it is 8 bit. Again, the number of RAM locations in the file register that are set aside for general purpose registers can vary from chip to chip, even among members of the same family. In the PIC micro-controllers, the space that is not allocated to the special function registers is used for general purpose registers. That means in a PIC chip with a thousand-byte file register, no more than 100 bytes are used for special function registers are the rest are used for general purpose registers. A larger GPR size means more difficulties in managing these registers if you use assembly language programming. In today's high performance micro-controllers, with a over of thousand bytes of GPR, the job of managing them is handled by the C compilers. Indeed, the C compilers are the very reason we need a large GPR since it makes it easier for C compilers to store parameters and perform their jobs much faster.

       

      File Register Size for PIC Chips
      file-register-size-pic-chips.jpg

       

      File Register of PIC12, PIC16 and PIC18
      file-registers-pic12-pic16-pic18.jpg

       

      SECTION II-4: General Purpose Registers RAM Vs EEPROM in PIC micro-controller

      There are two RAM columns in the chip information section of the Microchip website. One refers to the general purpose registers GP RAM size, and the other is the EEPROM size. GP RAM, which constitutes most of the file register, must not be confused with the EEPROM data memory. The GPRs are 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. Many PIC chips have zero bytes of EEPROM data, it is impossible for a micro-controller to have zero size for the file register. The microchip website provides tha data RAM size, which is the same as GPR size.

      SECTION II-5: File Register and Access bank in the PIC18

      The file register of the PIC18 family can have a maximum of 4096 (4K) bytes. With 4096 bytes, the file register has addresses of 000-FFFH. The file register in the PIC18 is divided into 256 byte banks. We can have up to a maximum of 16 banks (16 X 256 = 4096). Although not all members of the PIC18 family have that many banks, every PIC18 family member has at least one bank for the file register. This bank is called the access bank and is the default bank when we power up the PIC18 chip.

       

      File Register for PIC18 Family
      file-register-pic18-family.jpg

       

      We concentrate on the PIC18 series with their large file register, although the insight gained in the process can be applied to the PIC16 and PIC12 series.

      Examine the access bank for the PIC18 in figure below. The 256 byte access bank is divided into two equal sections of 128 bytes. These 128 bytes 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 what is normally called scratch pad. These 128 locations of RAM are widely used for storing data and parameters by PIC18 programmers and C compilers. Each location of this 128 byte RAM of general purpose registers can be accessed directly by its address. We will use these locations in future chapters to store data brought into the CPU via I / O and serial ports. Will also use then to define counters for time delay. The other 128 bytes of the access bank is used for special function registers. It has addresses of F80H to FFFH. Why 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 GPRs by various members of the PIC18 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 PIC18 family members that have more than the minimum access bank. PIC18 members with a file register of more than 256 bytes will be discussed, when we discuss bank switching.

      The I / O port SFRs, PORTA, PORTB, PORTC, PORTD, and associated registers are among the most widely used special function registers in PIC.

      SECTION III-1: MOVWF Instruction in the PIC micro-controller

      The PIC allows direct access to other locations in the file register for ALU and other operations. In this section we show the instructions using various locations of the file register.

      MOVWF Instruction:-

      The access bank of the file register is the default bank upon powering up the PIC18. The term file register must be emphasized because the instructions have the letter F in their mnemonics. In instructions such as MOVWF, the F stands for a location in the file register, while W means WREG. The MOVWF instruction tells the CPU to move, in reality copy, the source register of WREG to a destination in the file register (F). After this instruction is executed, the location in the file register will have the same value as register WREG. The location in the file register can be one of the special function registers SFRs or a location in the general purpose register region. For example: The "MOVWF PORTA" instruction will move the contents of WREG into the SFR register called PORTA.

      The following program first loads the WREG register with value 55H, then moves this value around to various SFRs of PORT B, C and D.

       

      MOVLW 55H ;WREG = 55H
      MOVWF PORTB ;copy WREG to PORT B (Port B = 55H)
      MOVWF PORTC ;copy WREG to PORT C (Port C = 55H)
      MOVWF PORTD ;copy WREG to PORT D (Port D = 55H

       

      PORTB, PORTC, and PORTD are part of the special function registers in the file register as shown in figure below. They can be connected to the I / O pins of the PIC micro-controller.

       

      Special Function Registers of the PIC18 Family
      special-function-registers-pic18-family.jpg

       

      We can also move (copy) the contents of WREG into any location in the general purpose registers (RAM) region of the file registers. The following program will put 99H into locations 0 - 4 of the general purpose register GPR region in the file register:

       

      MOVLW 99H ;WREG = 99H
      MOVWF 0H ;move (copy) WREG contents to location 0h
      MOVWF 1H ;move (copy) WREG contents to location 1h
      MOVWF 2H ;move (copy) WREG contents to location 2h
      MOVWF 3H ;move (copy) WREG contents to location 3h
      MOVWF 3H ;move (copy) WREG contents to location 4h

       

      The chart indicates the contents of addresses 0 - 4 after execution of the code

       

      Address Data
      000 99
      001 99
      002 99
      003 99
      004 99

       

      State the contents of file register RAM locations after the following program
      MOVLW 99H ;load WREG with value 99H
      MOVWF 12H  
      MOVLW 85H ;load WREG with value 85H
      MOVWF 13H  
      MOVLW 3FH ;load WREG with value 3FH
      MOVWF 14H  
      MOVLW 63H ;load WREG with value 63H
      MOVWF 15H  
      MOVLW 12H ;load WREG with value 12H
      MOVWF 16H  
      After the execution of MOVWF 12H filereg RAM location 12H has value 99H
      After the execution of MOVWF 13H filereg RAM location 13H has value 85H
      After the execution of MOVWF 14H filereg RAM location 14H has value 3FH
      After the execution of MOVWF 15H filereg RAM location 15H has value 63H
      After the execution of MOVWF 12H filereg RAM location 16H has value 12H

       

      As shown in the chart below:

      Address Data
      012 99
      013 85
      014 3F
      015 63
      016 12

       

      SECTION III-2: Instructions involving the WREG and the Access Bank

      You cannot move literal (immediate) values directly into the general purpose RAM locations in the PIC18. They must be moved there via WREG.

      There is a group of logic and arithmetic instructions that involve both the WREG and a location in the file register. The ADDWF instruction is one of them. The ADDWF instruction adds together the contents of WREG and a file register location. The file register location can be one of the special function registers SFRs or a general purpose register GPR. The destination for the result can be the WREG or the file register. The following format indicates the destination.

       

      ADDWF fileReg, D

       

      Where fileReg is the file register location and D indicates the destination bit. The D bit can be 0 or 1. If D = 0, it means that the destination is WREG. If D = 1, then the result will be placed in the file register.

       

      The following will first put value 22H into GP RAM locations 5, 6 and 7, then add them together and put the result in WREG
      MOVLW 22H ;WREG = 22H
      MOVWF 5H ;move (copy) WREG contents to location 5H
      MOVWF 6H ;move (copy) WREG contents to location 6H
      MOVWF 7H ;move (copy) WREG contents to location 7H
      ADDWF 5H, 0 ;add w and location 5, result in WREG (WREG = 22H + 22H  = 44H
      ADDWF 6H, 0 ;add w and location 6, result in WREG (WREG = 44H + 22H  = 66H
      ADDWF 7H, 0 ;add w and location 7, result in WREG (WREG = 66H + 22H  = 88H

       

      Address Data
      005 22
      006 22
      007 22
      GPR after the execution upto "MOVWF 7H"  WREG = 22H

       

      Address Data
      005 22
      006 22
      007 22
      GPR after the execution upto "ADDWF 7H, 0"  WREG = 88H

       

       

      Look at the same program where the result is put into file register location 7:
      MOVLW 22H ;WREG = 22H
      MOVWF 5H ;move (copy) WREG contents to location 5H
      MOVWF 6H ;move (copy) WREG contents to location 6H
      MOVWF 7H ;move (copy) WREG contents to location 7H
      ADDWF 5H, 0 ;add w and location 5, result in WREG (WREG = 22H + 22H  = 44H
      ADDWF 6H, 0 ;add w and location 6, result in WREG (WREG = 44H + 22H  = 66H
      ADDWF 7H, 1

      ;add w and location 7, result in lacation 7H

      ;now location 7 has 88H and WREG = 66H

       

       

      Address Data
      005 22
      006 22
      007 22
      GPR after the execution upto "MOVWF 7H"  WREG = 22H

       

      Address Data
      005 22
      006 22
      007 22
      GPR after the execution upto "ADDWF 7H, 1"  WREG = 66H

       

      To make things less confusing as far as the D bit is concerned, the PIC assembler allows us to use the letters W or F instead of 0 or 1 to indicate the destination.

       

      ADDWF fileReg, w ;add WREG and fileRef. WREG = the result
      ADDWF fileReg, f ;add WREG and fileReg ;fileReg = the result

       

      This format is much easier  and will help us to avoid confusion about the destination. Look at the rewrite of the last program with the new format for the ADDWF instruction.

       

      Look at the same program where the result is put into file register location 7:
      MOVLW 22H ;WREG = 22H
      MOVWF 5H ;move (copy) WREG contents to location 5H
      MOVWF 6H ;move (copy) WREG contents to location 6H
      MOVWF 7H ;move (copy) WREG contents to location 7H
      ADDWF 5H, W ;add w and location 5, result in WREG (WREG = 22H + 22H  = 44H
      ADDWF 6H, W ;add w and location 6, result in WREG (WREG = 44H + 22H  = 66H
      ADDWF 7H, F

      ;add w and location 7, result in lacation 7H

      ;now location 7 has 88H and WREG = 66H

       

      The above concept is important and must be understood since there are a large number of instructions with this format.

       

      State the contents of file register RAM locations 12H and WREG after the following program
      MOVLW 0 ;move 0 WREG to clear it (WREG = 0)
      MOVWF 12H ;move WREG to location 12 to clear it
      MOVLW 22H ;load WREG with value 22H
      ADDWF 12H, F

      ;add WREG to location 12H, location 12H = 22+0 = 22

      ;location 12 = sum

      ADDWF 12H, F

      ;add WREG to location 12H, location 12H = 22+22 = 44

      ;location 12 = sum

      ADDWF 12H, F

      ;add WREG to location 12H, location 12H = 22H+44 = 66

      ;location 12 = sum

      ADDWF 12H, F

      ;add WREG to location 12H, location 12H = 22H+66 = 88

      ;location 12 = sum

       

      The program clears above both the WREG and RAM location 12H in the file register. Then it loads WREG with value 22H. Then it adds the WREG register and location 12 together and saves the result in location 12H. It does that four times. At the end, location 12H of GP RAM has the value of 88H (4 X 22H = 88H) and WREG = 22H

      After each "ADDWF 12, F" instruction

      Address Data
      011  
      012 22
      013  
      WREG = 22H
      Address Data
      011  
      012 44
      013  
      WREG = 22H
      Address Data
      011  
      012 66
      013  
      WREG = 22H
       
      Address Data
      011  
      012 88
      013  
      WREG = 22H

       

      Rewrite the above example to place the sum in WREG as you add the file register locations and the WREG register
      MOVLW 0 ;move 0 WREG to clear it (WREG = 0)
      MOVWF 12H ;move WREG to location 12 to clear it
      MOVLW 22H ;load WREG with value 22H
      ADDWF 12H, W

      ;add WREG to location 12H, WREG = 22+0 = 22

      ;WREG = sum

      ADDWF 12H, W

      ;add WREG to location 12H, WREG = 22+22 = 44

      ;WREG = sum

      ADDWF 12H, W

      ;add WREG to location 12H, location 12H = 44H+22 = 66

      ;location 12 = sum

      ADDWF 12H, W

      ;add WREG to location 12H, location 12H = 66H+22 = 88

      ;location 12 = sum

       

      The program adds WREG and location 12H together and saves the result in WREG each time. At the end, location 12H has a value of 22H amd WREG = 88H

      After each 'ADDWF 12, W" instruction:

       

      Address Data
      011  
      012 22
      013  
      WREG = 22H
      Address Data
      011  
      012 22
      013  
      WREG = 44H
      Address Data
      011  
      012 22
      013  
      WREG = 66H
      Address Data
      011  
      012 22
      013  
      WREG = 88H

       

      SECTION III-3: ALU Instructions Using Both WREG and FileReg

       

      WREG, FileReg and ALU in PIC18
      wreg-filereg-alu-pic18.jpg

       

      The instructions in table below operate on both WREG and a file register location and then give you the option of placing the result in WREG or a file register location. 

       

      ALU Instructions Using Both WREG and fileReg
      alu-instructions-wreg-filereg.jpg

       

      The d bit selects the destination for the operation. If d = w; the result is stored in WREG (d = 0). If d = F; the result is stored in the fileReg (d = 1). The default is F. That means "ADDWF myfile" is the same as "ADDWF myfile, F"

      SECTION III-4: File Register Instructions Using FileReg or WREG as Destination

      Table below operate on the file register only and then give you the option of placing the result in WREG or a file register location.

       

      File Register Instructions Using FileReg or WREG as Destination
      file-register-instructions-filereg-wreg.jpg

       

      The d bit selects the destination for the operation. If d = w; the result is stored in the WREG (d = 0). If d = F; the result is stored in the fileReg (d = 1). The default is F. That means "DECF myfile" i s the same as "DECF myfile, F."