ESD Lab6 DARK 22ESD

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

QUAID-E-AWAM UNIVERSITY OF ENGINEERING, SCIENCE & TECHNOLOGY,

NAWABSHAH
DEPARTMENT OF ELECTRONIC ENGINEERING
SUBJECT: EMBEDDED SYSTEM DESIGN
LAB NO: 06

Name: ________________________________________ Roll Number: ____________________


Signature of Teacher: ____________________________ Score: ___________________________

Equipment Equipment Equipment Procedural Response (4) Observation’s Safety Group Score
Identification Use (4) Handling (4) Skills (4) Use (4) Adherence work (32)
(4) (4) (4)

Practice the few PIC18F instructions with the default access bank

Learning outcomes
After completion of the lab, students shall,
➢ Describe the WREG register, data RAM or File Register
➢ Practice to use the default access bank in PIC18F
➢ Follow the instructions to use PIC18F458 simple instructions with the default access bank

Lab Requirements
➢ PC with Windows Operating System
➢ MPLAB IDE v8.91
➢ MicroChip C18 Tool suite

The PIC18F Memory Registers


CPUs use many registers to store data temporarily. To program in assembly language, an
understanding of the registers and architecture of a given microcontroller is necessary. In PIC, the most
commonly used special function register is WREG. It is discussed in the next section.

The WREG Register in the PIC


In PIC the vast majority of registers are 8-bit registers. In the PIC, there is only one data type i-e 8-bits
(1-byte). The WREG is also an 8-bit register. It is given in Table 1.
Table 1: 8-bit PIC WREG registers.

Where D7 is the most significant bit (MSB) and D0 is the least significant bit (LSB) of the WREG
register. The WREG stands for Working REGister, as there is only one. One can compare the use of
the WREG register with the accumulator in other microcontrollers. It is used for all arithmetic and
logic instructions.

1
The PIC File Register or Data RAM
The PIC file register or data RAM is a read/write (static RAM) memory. It is also referred to as data
memory space to distinguish it from program code memory (ROM). The file register is used by the
CPU for data storage, scratch pad and registers for internal use and functions. As with WREG,
arithmetic and logical operations can be performed on many locations of the file register data RAM.
The size of the file register ranges from 32 bytes to several thousand bytes depending uponthe chip. It
must be noted that the file registers data RAM has a byte-size width. The file register in PIC is divided
into two sections.
1. Special Function Registers (SFRs)
2. General Purpose Registers (GPRs)

SFRs (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 microcontroller or peripherals.

GPRs (General Purpose Register)


The general purpose registers are a group of RAM locations in the file register that is used for data
storage temporarily. Each location is 8-bit wide. In the PIC controllers, the space that is not allocated
to the SFRs typically is used for general-purpose registers. The size of file registers for different chips
is given in Table 2.

Access Bank in the PIC18


The PIC18 family has a file register of 4096 (4K) bytes. The file register is divided into 256-byte
banks. Therefore PIC18 microcontrollers can have a maximum of 16 banks. It is shown in Figure 1.

Figure 1: File register allocation in PIC18

2
Different PIC18 microcontrollers have different sizes of file registers, however, every PIC18 has at
least one bank for the file register. This bank is called the access bank and is the default bank when
powering up the PIC18 chip.
The default access bank (256 bytes) is divided into two equal portions of 128 bytes. These 128-byte
sections are given to the general purpose registers and special function registers. The 128 bytes from
location 00H to 7FH are set aside for general-purpose registers and the other 128 bytes of the access
bank are set aside for SFRs. It has addresses of F80H to FFFH. It is shown in Figure 2.

Figure 2: Access Bank.

Using Instruction with Default Access Bank


In this section, some simple instructions that use general-purpose registers and special-purpose
registers will be discussed. In addition to WREG, the PIC allows direct access to other locations in the
file register for ALU and other operations. The following instructions will show the use of WREG and
other file registers in the PIC microcontroller.

I. The MOVLW Instruction


This instruction moves 8-bit data into the WREG register. The format of this instruction is shown
below.
MOVLW K ; move literal value K into WREG
Where K is an 8-bit value that can range from 0-255 in decimal or 00H to FFH in hex.

II. The ADDLW Instruction


The ADD instruction tells the CPU to add the literal value K to register WREG and put the result back
into the WREG. The format of this instruction is shown below.
ADDLW K; add literal value K to WREG

III. The MOVWF Instruction


In instruction MOVWF the letter ‘F‘ stands for file register and it represents the location in the file
register. The MOVWF tells the CPU to move the source register of WREG to a destination in the file
register (F). After execution of this instruction, 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 SFRs or a location in the general
purpose registers.
The format of this instruction is given as MOVWF fileReg, where fileReg is the file register location
address.

3
IV. The ADDWF Instruction
The ADDWF adds together the contents of WREG and a file register location. The locationin the file
register can be one of the SFRs or a location in the general purpose registers. The format of this
instruction is given as
ADDWF fileReg, D
Where D indicated the destination bit. It can be either 0 or 1. If D=0, then it indicates that the result
will be stored in the WREG register or if D=1 then it puts the result in the file register. However, the
PIC assembler allows us to use the letters W or F instead of 0 or 1 to indicate the destination.

V. The COMF Instruction


This instruction will complement (invert) the contents of the file register and place the result in
WREG or fileReg. The format is given as
COMF FileReg, D

VI. The DECF Instruction


Format: DECF FileReg, D
It decrements the contents of the fileReg and places the result in WREG or FileReg. This type of
instruction is mostly used in making loops.

VII. The MOVF Instruction


Format: MOVF fileReg, D
If D=0, it copies the content of fileReg to WREG and if D=1, it copies the content of fileReg to itself.
It is typically used to bring the data into the WREG from the I/O pins.

VIII. The MOVFF Instruction


It copies the data from one location in fileREeg to another location in fileReg. The fileReg location
for the source and destination can be any of the 4096 locations in the data RAM space of the PIC18.
It allows the programmer to move data within 4K space of data RAM without going through the
WREG register.
Format: MOVFF source fileReg, destination fileReg

REVIEW QUESTIONS:

1. Describe data RAM allocation in PIC.

2. Define the role of special function registers and general purpose registers.

4
3. Define the importance and role of the WREG register in PIC microcontrollers.

4. Describe the access bank in the PIC microcontroller. What is the maximum number
of banks a PIC18 microcontroller can have?

5. Write a code to move value 09H into the WREG register. Then add 05H into it. The
result should be stored in location 25H of the file register.

6. Write a code to store your roll number in location 01H. Then copy the contents of
the 01H location to the 02H location of the file register without involving the WREG
register.

7. Write a code to send FFH to the data RAM location 25H and complement its bits
continuously forever.

8. Write a code to send a 20H value in the fileReg 01H and then add a value o f
10H to it.Store the result in the WREG register.

NOTE: Verify your code in MPLAB and attach the result of each program along with the
handout.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy