SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
Copyright Politeknik Kota Bharu Page 1
CHAPTER 2 – MICROCONTROLLER ARCHITECTURE & ASSEMBLY LANGUAGE PROGRAMMING
PIC18 Microcontroller families
 PIC is a family of modified Harvard architecture microcontrollers made by Microchip
Technology, derived from the PIC1650 originally developed by General Instrument's
Microelectronics Division. The name PIC initially referred to "Peripheral Interface
Controller".
 1989 – Microchip Technology Corporation introduced it’s first 8-bit microcontroller
PIC18 Architecture
 PIC microcontrollers are based on advanced RISC architecture.
 RISC stands for Reduced Instruction Set Computing. In this architecture, the instruction
set of hardware gets reduced which increases the execution rate (speed) of system.
 CPUs use many register to store data temporarily.
 To program in Assembly Language, we must understand the register and architecture
 PIC microcontrollers follow Harvard architecture for internal data transfer
 PIC microcontrollers are designed using the Harvard Architecture which includes:
 Microprocessor unit (MPU)
 Program memory for instructions
 Data memory for data
 I/O ports
 Support devices such as timers
Copyright Politeknik Kota Bharu Page 2
Copyright Politeknik Kota Bharu Page 3
The data RAM file Register
 CPUs use many registers to store data temporarily.
 To program in assembly language, we must understand the registers and architecture of
given CPU and the role they play in processing data.
WREG register
 Registers are used to store information temporarily
 The information could be a byte of data to be processed, or and address pointing to the
data to be fetched
 The WREG is the most widely used register in PIC microcontroller
Copyright Politeknik Kota Bharu Page 4
 The 8-bit WREG register is the most widely used register in the PIC micro controller.
 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 the WREG register, we will show it in the context of two simple instructions:
MOVLW and ADDWL.
MOVLW Instruction
Notice that 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 following
instruction loads the WREG register with a literal value of 25H (i.e., 25 in hex).
o MOVLW 25H ; move value 25H into WREG
o MOVLW 87H ; load 87H into WREG
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
MOVLW 25H ; load 25H into WREG
ADDLW 34H ; add value 34 to WREG
W = W + 34H Executing the above lines results in WREG = 59H (25H + 34H = 59H)
File register (SFRs and GPR)
 File Register (data RAM) is read/write memory used by CPU for data storage, scratch
pad and register for internal use and function
 Divided into two sections:
o SFRs – Special Function Registers
o GPR – General-Purpose Register
Copyright Politeknik Kota Bharu Page 5
Special Function Register (SFRs)
 Special-Function registers are RAM memory locations, their purpose is
predetermined during manufacturing process and cannot be changed.
 Dedicated to specific functions – ALU status, timers, serial communication, I/O ports
ADC etc.
 Fixed by CPU designer at the time of design
 8 bits register
Copyright Politeknik Kota Bharu Page 6
General Purpose Register (GPR)
 8-bit registers
 are a group of RAM locations in the file register that are used for data storage and
scratch pad.
 the space that is not allocated to the SFRs typically used for general-purpose registers
MOVWF Instruction
Notice that in MOVWF, the letter F stands for a location in the file register, while W
means WREG. The MOVWF instructions tells the CPU to move (in reality, copy) the
source register of WREG to a destination in the file register (F)
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)
Copyright Politeknik Kota Bharu Page 7
MOVF Instruction
The MOVF mnemonic is intended to perform MOVFW. It move the contents of file
register into WREG or to itself
MOVF PORTB,W ; move from file register of Port B to WREG
MOVF PORTB,0 ; move content of file register into WREG
MOVF PORTB,1 ; move content of file register into itself
Review Question
1. State five example of SFR
2. What is GPR
3. Write an instruction to move value of 58H into WREG
4. Write an instruction to move value of 58H into PORTB
5. What is the difference between the MOVWF and MOVF instruction
6. Explain each instruction below:
a. MOVLW 55H
b. MOVF PORTB,W
Status Register
 One of the most important register in PIC. Most of PIC has this register.
 8-Bit register. Sometime referred as flag register.
 Only 5 bits of it are used by the PIC18.
o called conditional flags
 The three unused bits are unimplemented and read as 0.
Copyright Politeknik Kota Bharu Page 8
 C (Carry/Borrow Flag) set when an addition generates a carry and a subtraction
generates a borrow.
 DC(Digit Carry Flag):also called Half Carry flag;set when carry generated from Bit3 to
Bit4 an arithmetic operatio.n
 Z(Zero Flag):set when result of an operation is zero.
 OV(Overflow Flag):set when result of an operation of signed numbers goes beyond
seven bits-if the results fall outside 127(0x7F)and -128(0x80).
 N(Negative Flag):set when bit B7 is one of the result of an arithmetic/logic operation.
Example
1. Show the status of the C, DC and Z flag after the addition of 38H and 2FH.
Solution:
38H 00111000
+ 2FH + 00101111
67H 01100111
C = 0 ; DC = 1; Z = 0
Copyright Politeknik Kota Bharu Page 9
2. Show the status of the C, DC and Z flags after the addition of 9CH and 64H in the
following instructions:
MOVLW 9CH
ADDLW 64H
3. Write the instruction for addition operation of 88H and 93H and show the status of the
C, DC and Z flags.
Solution:
MOVLW 88H
ADDLW 93H
Review Question
1. Determine the state of status register after the instruction below:
a. MOVLW 0F5H
ADDLW 0BH
b. MOVLW 9FH
ADDLW 61H
Copyright Politeknik Kota Bharu Page 10
2. Show the status of the C, DC and Z flags after the addition of 9CH and 64H in the
following instructions:
a. MOVLW 9CH
ADDLW 64H
b. MOVLW 67H
ADDLW 99H
c. MOVLW 87H
ADDLW 22H
Data format and directives
 PIC data type has only one data type. 8-bits. Size of register also 8-bits ( 00-FF, or 0-255)
 Data format representation.
o Hex,
o Binary,
o Decimal,
o ASCII
HEX number
 Use h, or H right after the number. Example MOVLW 12H
 Put 0x. Example MOVLW 0x12;
 Put nothing. Eg. MOVLW 12
 Put h in front of number. MOVLW h’12’
Binary number
 Only one way to represent binary numbers,
Example: MOVLW B’00010010’
1 2 in hex
Decimal number
 Two ways to represent. MOVLW D’12’ , (in hex 0x0C)
 Or MOVLW .12
Copyright Politeknik Kota Bharu Page 11
ASCII code
To represent ASCII data in PIC assemble we use the letter A as follows
MOVLW A’2’ ; WREG = 00110010 or 32 in hex ( see ASCII chart)
MOVLW A’c’ ; WREG = 01100011 or 63 in hex (see ASCII chart)
MOVLW ‘9’ ; WREG = 39H another way for ASCII
Copyright Politeknik Kota Bharu Page 12
ASSEMBLER Directive
 Directive give direction to he assembler..
 Example EQU, ORG, END, #INCLUDE, LIST, _CONFIG
EQU (equate)
 Used to define constant value or fixed address.
 Associates a constant number / address label
 Eg. COUNT EQU 0x25
MOVLW COUNT ; WREG = 25
ORG (Origin)
 Indicate the beginning of the address.
 Example ORG 0x00
END
 Important to indicate End of code, last line
LIST
 Indicates to the assembler the specific PIC chip for which the program should be
assembled. Eg. LIST P=18F458
#INLCUDE
 Tell the assembler to use the libraries associated with the specific chip
_CONFIG
 To configure bits for the targeted PIC. Read during the power-up, wrong configuration
makes PIC unusable.
Copyright Politeknik Kota Bharu Page 13
Example code
Instruction set of PIC18
 PIC18F2455/2550/4455/4550 devices incorporate the standard set of 75 PIC18 core
instructions.
 The instruction set is highly orthogonal and is grouped into four basic categories:
o Byte-oriented operations
o Bit-oriented operations
o Literal operations
o Control operations
Copyright Politeknik Kota Bharu Page 14
Copyright Politeknik Kota Bharu Page 15
Arithmetic Instruction and Operation
a. Addition and subtraction
MOVLW 0xF5 ; WREG = F5
ADDLW 0x0B ; WREG = F5 + 0B = 00 and C = 1
MOVLW 0x23 ; WREG = 23H
SUBLW 0x3F ; WREG = 3F - WREG
Copyright Politeknik Kota Bharu Page 16
b. Multiplication
The PIC supports byte-by-byte multiplication only. The byte is assumed to be unsigned
data. The syntax is as follows. After multiplication, the result is in the special function
registers PRODH and PRODL; the lower byte is in PRODL, and the upper byte is in
PRODH.
MULLW K ; W x K 16 bit is result in PRODH:PRODL
Copyright Politeknik Kota Bharu Page 17
c. Addition of BCD data
 BCD stands for binary coded decimal. BCD is needed because in everyday life we use
the digits 0 to 9 for number, not binary or hex number
 Binary representation of 0 to 9 is called BCD . In computer literature, one encounters
two terms for BCD numbers: (i) unpacked BCD, and (ii) packed BCD.
 In unpacked BCD, the lower 4 bits of the number represent the BCD number, and
the rest of the bits are O. Example: "0000 100 I" and "0000 0101" are unpacked BCD
for 9 and 5, respectively. Unpacked BCD requires I byte of memory, or an S-bit
register, to contain it.
 In packed BCD, a single byte has two BCD numbers in it: one in the lower 4 bits, and
one in the upper 4 bits. For example, "0101 1001" is packed BCD for 59H. Only I byte
of memory is needed to store the packed BCD operands. One reason to use packed
BCD is that it is twice as efficient in storing data.
 There is a problem with adding BCD numbers, which must be corrected. The
problem is that after adding packed BCD numbers, the result is no longerBCD. Look
at the following.
MOVLW 0x17
ADDLW 0x28
 Adding these two numbers gives 0011 IIII B (3FH), which is not BCD. A BCD number
can only have digits from 0000 to 1001 (or 0 to 9).
 The result above should have been 17 + 28 = 45 (01000101). To correct this problem,
the programmer must add 6 (0 II 0) to the low digit: 3F + 06 = 45H.
 The same problem could have happened in the upper digit (for example, in 52H +
87H = D9H). Again, 6 must be added to the upper digit (D9H + 60H = 139H) to ensure
that the result is BCD (52 + 87 = 139).
 This problem is so pervasive that most microprocessors such as the PIC 18 have an
instruction to deal with it. In the PIC 18 instruction "DAW" is designed to correct the
BCD addition problem.
 The DAW (decimal adjust WREG) instruction in the PIC 18 is provided to correct the
aforementioned problem associated with BCD addition.
 The mnemonic "DAW" works only with an operand in the WREG register. The DAW
instruction will add 6 to the lower nibble or higher nibble if needed; otherwise, it will
leave the result alone. The following example will clarify these points

Copyright Politeknik Kota Bharu Page 18
Logic Instruction and Bit Manipulation
 Apart from I/O and arithmetic instructions, logic instructions are some of most widely
used instructions.
 Boolean logic instructions such as AND, OR, Exclusive-OR (XOR), and complement.
 Logical operations are useful for looking for array elements with certain properties (e.g.,
divisible by power of 2) and manipulating I/O pin values (e.g., set certain pins to high,
clear a few pins, toggle a few signals, and so on).
 The logical instruction allow user to perform AND, OR, exclusive-OR and complementing
on 8-bit numbers.
AND
ANDLW K ; WREG = WREG AND K
Example : Show the result of the following
MOVLW 0x35h
ANDLW 0x0Fh
Copyright Politeknik Kota Bharu Page 19
OR
IORLW K ; WREG = WREG OR K
Example : Show the result of the following
MOVLW 0x04h
IORLW 0x30h
EX-OR
XORLW K ; WREG = WREG XOR K
Example : Show the result of the following
MOVLW 0x54h
XORLW 0x78h
Copyright Politeknik Kota Bharu Page 20
COMF (Compliment file register)
This instruction complements the contents of a file register. The complement action changes
the 0s to 1s and the 1s to 0s. This is also called 1’s complement
Bit Manipulation
 BCF – Bit Clear File register (set the bit: bit = 1)
 BSF – Bit Set File register (clear the bit: bit = 0)
 BTG – Bit Toggle File register (complement the bit)
 BTFSC – Bit Test File register, skip if clear (skip next instruction if bit = 0)
 BTFSS– Bit Test File register, skip if set (skip next instruction if bit = 1)
 RRNCF – Rotate right f (no carry)
 RLNCF – Rotate left f (no carry)
 RRCF – Rotate right f through carry
 RLCF – Rotate left f through carry
Example
Copyright Politeknik Kota Bharu Page 21
Review Question
1. Explain each of the register below:
a. WREG Register
b. File Register
c. Status Register
2. Include directive is used to ……………
3. EQU is used to ………………………………
4. Illustrate the result after the following code is executed

Contenu connexe

Tendances

PART -1 TRAFFIC LIGHT CONTROL USING 8085
PART -1 TRAFFIC LIGHT CONTROL USING 8085PART -1 TRAFFIC LIGHT CONTROL USING 8085
PART -1 TRAFFIC LIGHT CONTROL USING 8085Subash Sambath Kumar
 
report on embedded system
 report on embedded system report on embedded system
report on embedded systemseema kumawat
 
1347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 80511347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 8051techbed
 
“Microcontroller Based Substation Monitoring system with gsm modem”.
“Microcontroller Based Substation Monitoring system with gsm modem”.“Microcontroller Based Substation Monitoring system with gsm modem”.
“Microcontroller Based Substation Monitoring system with gsm modem”.Priya Rachakonda
 
Embedded system (Chapter 2) part A
Embedded system (Chapter 2) part AEmbedded system (Chapter 2) part A
Embedded system (Chapter 2) part AIkhwan_Fakrudin
 
Lab 4 Three-Bit Binary Adder
Lab 4 Three-Bit Binary AdderLab 4 Three-Bit Binary Adder
Lab 4 Three-Bit Binary AdderKatrina Little
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller Gaurav Verma
 
8086 microprocessor
8086 microprocessor8086 microprocessor
8086 microprocessorsavitamhaske
 
VLSI Lab manual PDF
VLSI Lab manual PDFVLSI Lab manual PDF
VLSI Lab manual PDFUR11EC098
 
Speed control of IM using Space Vector Modulation
Speed control of IM using Space Vector ModulationSpeed control of IM using Space Vector Modulation
Speed control of IM using Space Vector ModulationAsif Jamadar
 
Verilog coding of demux 8 x1
Verilog coding of demux  8 x1Verilog coding of demux  8 x1
Verilog coding of demux 8 x1Rakesh kumar jha
 

Tendances (20)

PART -1 TRAFFIC LIGHT CONTROL USING 8085
PART -1 TRAFFIC LIGHT CONTROL USING 8085PART -1 TRAFFIC LIGHT CONTROL USING 8085
PART -1 TRAFFIC LIGHT CONTROL USING 8085
 
report on embedded system
 report on embedded system report on embedded system
report on embedded system
 
8051
80518051
8051
 
Half adder layout design
Half adder layout designHalf adder layout design
Half adder layout design
 
1347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 80511347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 8051
 
“Microcontroller Based Substation Monitoring system with gsm modem”.
“Microcontroller Based Substation Monitoring system with gsm modem”.“Microcontroller Based Substation Monitoring system with gsm modem”.
“Microcontroller Based Substation Monitoring system with gsm modem”.
 
ARM Architecture Subroutine and Flags
ARM Architecture Subroutine and FlagsARM Architecture Subroutine and Flags
ARM Architecture Subroutine and Flags
 
Embedded system (Chapter 2) part A
Embedded system (Chapter 2) part AEmbedded system (Chapter 2) part A
Embedded system (Chapter 2) part A
 
Lab 4 Three-Bit Binary Adder
Lab 4 Three-Bit Binary AdderLab 4 Three-Bit Binary Adder
Lab 4 Three-Bit Binary Adder
 
Omron ladder programming
Omron ladder programmingOmron ladder programming
Omron ladder programming
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
 
8086 microprocessor
8086 microprocessor8086 microprocessor
8086 microprocessor
 
List of 8085 programs
List of 8085 programsList of 8085 programs
List of 8085 programs
 
8051 serial communication-UART
8051 serial communication-UART8051 serial communication-UART
8051 serial communication-UART
 
8085 alp programs
8085 alp programs8085 alp programs
8085 alp programs
 
8086 microprocessor
8086 microprocessor8086 microprocessor
8086 microprocessor
 
VLSI Lab manual PDF
VLSI Lab manual PDFVLSI Lab manual PDF
VLSI Lab manual PDF
 
Lecture 03 basics of pic
Lecture 03 basics of picLecture 03 basics of pic
Lecture 03 basics of pic
 
Speed control of IM using Space Vector Modulation
Speed control of IM using Space Vector ModulationSpeed control of IM using Space Vector Modulation
Speed control of IM using Space Vector Modulation
 
Verilog coding of demux 8 x1
Verilog coding of demux  8 x1Verilog coding of demux  8 x1
Verilog coding of demux 8 x1
 

En vedette

Lab 1 microcontroller
Lab 1 microcontrollerLab 1 microcontroller
Lab 1 microcontrollermkazree
 
3 organization of intel 8086
3 organization of intel 80863 organization of intel 8086
3 organization of intel 8086ELIMENG
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic   copyChp6 assembly language programming for pic   copy
Chp6 assembly language programming for pic copymkazree
 
Management of Learner Support Centres in Open and Distance Education
Management of Learner Support Centres in Open and Distance EducationManagement of Learner Support Centres in Open and Distance Education
Management of Learner Support Centres in Open and Distance EducationRamesh C. Sharma
 
Introduction of microcontroller
Introduction of microcontrollerIntroduction of microcontroller
Introduction of microcontrollerEngineer Maze
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructionsRavi Anand
 
Chp5 pic microcontroller instruction set copy
Chp5 pic microcontroller instruction set   copyChp5 pic microcontroller instruction set   copy
Chp5 pic microcontroller instruction set copymkazree
 
PIC microcontroller review
PIC microcontroller reviewPIC microcontroller review
PIC microcontroller reviewMohsen Sarakbi
 
Microcontroleur Pic16 F84
Microcontroleur Pic16 F84Microcontroleur Pic16 F84
Microcontroleur Pic16 F84guest1e7b02
 
Embedded system (Chapter 1)
Embedded system (Chapter 1)Embedded system (Chapter 1)
Embedded system (Chapter 1)Ikhwan_Fakrudin
 
Chp4 introduction to the pic microcontroller copy
Chp4 introduction to the pic microcontroller   copyChp4 introduction to the pic microcontroller   copy
Chp4 introduction to the pic microcontroller copymkazree
 
Architecture of 80286 microprocessor
Architecture of 80286 microprocessorArchitecture of 80286 microprocessor
Architecture of 80286 microprocessorSyed Ahmed Zaki
 
Programming with PIC microcontroller
Programming with PIC microcontroller Programming with PIC microcontroller
Programming with PIC microcontroller Raghav Shetty
 
PIC-MICROCONTROLLER TUTORIALS FOR BEGINNERS
PIC-MICROCONTROLLER TUTORIALS FOR BEGINNERSPIC-MICROCONTROLLER TUTORIALS FOR BEGINNERS
PIC-MICROCONTROLLER TUTORIALS FOR BEGINNERSVISHNU KP
 
Latest Digital Electronic Projects
Latest Digital Electronic ProjectsLatest Digital Electronic Projects
Latest Digital Electronic Projectselprocus
 
Embedded system (Chapter )
Embedded system (Chapter )Embedded system (Chapter )
Embedded system (Chapter )Ikhwan_Fakrudin
 

En vedette (19)

Lab 1 microcontroller
Lab 1 microcontrollerLab 1 microcontroller
Lab 1 microcontroller
 
3 organization of intel 8086
3 organization of intel 80863 organization of intel 8086
3 organization of intel 8086
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic   copyChp6 assembly language programming for pic   copy
Chp6 assembly language programming for pic copy
 
Management of Learner Support Centres in Open and Distance Education
Management of Learner Support Centres in Open and Distance EducationManagement of Learner Support Centres in Open and Distance Education
Management of Learner Support Centres in Open and Distance Education
 
Introduction of microcontroller
Introduction of microcontrollerIntroduction of microcontroller
Introduction of microcontroller
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructions
 
Chp5 pic microcontroller instruction set copy
Chp5 pic microcontroller instruction set   copyChp5 pic microcontroller instruction set   copy
Chp5 pic microcontroller instruction set copy
 
PIC microcontroller review
PIC microcontroller reviewPIC microcontroller review
PIC microcontroller review
 
Microcontroleur Pic16 F84
Microcontroleur Pic16 F84Microcontroleur Pic16 F84
Microcontroleur Pic16 F84
 
Embedded system (Chapter 1)
Embedded system (Chapter 1)Embedded system (Chapter 1)
Embedded system (Chapter 1)
 
Pic microcontroller step by step your complete guide
Pic microcontroller step by step your complete guidePic microcontroller step by step your complete guide
Pic microcontroller step by step your complete guide
 
Chp4 introduction to the pic microcontroller copy
Chp4 introduction to the pic microcontroller   copyChp4 introduction to the pic microcontroller   copy
Chp4 introduction to the pic microcontroller copy
 
Architecture of 80286 microprocessor
Architecture of 80286 microprocessorArchitecture of 80286 microprocessor
Architecture of 80286 microprocessor
 
Programming with PIC microcontroller
Programming with PIC microcontroller Programming with PIC microcontroller
Programming with PIC microcontroller
 
PIC-MICROCONTROLLER TUTORIALS FOR BEGINNERS
PIC-MICROCONTROLLER TUTORIALS FOR BEGINNERSPIC-MICROCONTROLLER TUTORIALS FOR BEGINNERS
PIC-MICROCONTROLLER TUTORIALS FOR BEGINNERS
 
Digital modulation
Digital modulationDigital modulation
Digital modulation
 
Digital electronics
Digital electronicsDigital electronics
Digital electronics
 
Latest Digital Electronic Projects
Latest Digital Electronic ProjectsLatest Digital Electronic Projects
Latest Digital Electronic Projects
 
Embedded system (Chapter )
Embedded system (Chapter )Embedded system (Chapter )
Embedded system (Chapter )
 

Similaire à Ch2 microcontroller architecture

Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Ikhwan_Fakrudin
 
Xcs 234 microprocessors
Xcs 234 microprocessorsXcs 234 microprocessors
Xcs 234 microprocessorssweta suman
 
My seminar new 28
My seminar new 28My seminar new 28
My seminar new 28rajeshkvdn
 
Computer architecture 3
Computer architecture 3Computer architecture 3
Computer architecture 3Dr.Umadevi V
 
ECET 330 Massive Success--snaptutorial.com
ECET 330 Massive Success--snaptutorial.comECET 330 Massive Success--snaptutorial.com
ECET 330 Massive Success--snaptutorial.comsantricksapiens71
 
Ecet 330 Success Begins / snaptutorial.com
Ecet 330 Success Begins / snaptutorial.comEcet 330 Success Begins / snaptutorial.com
Ecet 330 Success Begins / snaptutorial.comWilliamsTaylorzm
 
Ecet 330 Enthusiastic Study / snaptutorial.com
Ecet 330 Enthusiastic Study / snaptutorial.comEcet 330 Enthusiastic Study / snaptutorial.com
Ecet 330 Enthusiastic Study / snaptutorial.comStephenson033
 
ECET 330 Technology levels--snaptutorial.com
ECET 330 Technology levels--snaptutorial.comECET 330 Technology levels--snaptutorial.com
ECET 330 Technology levels--snaptutorial.comsholingarjosh102
 
15CS44 MP & MC Module 1
15CS44 MP & MC Module 115CS44 MP & MC Module 1
15CS44 MP & MC Module 1RLJIT
 
Design of an Embedded Micro controller
Design of an Embedded Micro controllerDesign of an Embedded Micro controller
Design of an Embedded Micro controllerDaniel Gomez-Prado
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set ArchitectureDilum Bandara
 
PIC introduction + mapping
PIC introduction + mappingPIC introduction + mapping
PIC introduction + mappingOsaMa Hasan
 
Unit 2 Instruction set.pdf
Unit 2 Instruction set.pdfUnit 2 Instruction set.pdf
Unit 2 Instruction set.pdfHimanshuPant41
 
Microcontroller pic 16f877 addressing modes instructions and programming
Microcontroller pic 16f877 addressing modes instructions and programmingMicrocontroller pic 16f877 addressing modes instructions and programming
Microcontroller pic 16f877 addressing modes instructions and programmingNilesh Bhaskarrao Bahadure
 
8085 microprocessor(1)
8085 microprocessor(1)8085 microprocessor(1)
8085 microprocessor(1)Reevu Pal
 
PIC16F877A C Programming.ppt
PIC16F877A C Programming.pptPIC16F877A C Programming.ppt
PIC16F877A C Programming.pptIlaiyarajaS1
 
Basic programming of 8085
Basic programming of 8085 Basic programming of 8085
Basic programming of 8085 vijaydeepakg
 

Similaire à Ch2 microcontroller architecture (20)

Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2
 
Xcs 234 microprocessors
Xcs 234 microprocessorsXcs 234 microprocessors
Xcs 234 microprocessors
 
My seminar new 28
My seminar new 28My seminar new 28
My seminar new 28
 
Picmico
PicmicoPicmico
Picmico
 
Computer architecture 3
Computer architecture 3Computer architecture 3
Computer architecture 3
 
Qb microprocessors
Qb microprocessorsQb microprocessors
Qb microprocessors
 
ECET 330 Massive Success--snaptutorial.com
ECET 330 Massive Success--snaptutorial.comECET 330 Massive Success--snaptutorial.com
ECET 330 Massive Success--snaptutorial.com
 
Ecet 330 Success Begins / snaptutorial.com
Ecet 330 Success Begins / snaptutorial.comEcet 330 Success Begins / snaptutorial.com
Ecet 330 Success Begins / snaptutorial.com
 
Ecet 330 Enthusiastic Study / snaptutorial.com
Ecet 330 Enthusiastic Study / snaptutorial.comEcet 330 Enthusiastic Study / snaptutorial.com
Ecet 330 Enthusiastic Study / snaptutorial.com
 
ECET 330 Technology levels--snaptutorial.com
ECET 330 Technology levels--snaptutorial.comECET 330 Technology levels--snaptutorial.com
ECET 330 Technology levels--snaptutorial.com
 
15CS44 MP & MC Module 1
15CS44 MP & MC Module 115CS44 MP & MC Module 1
15CS44 MP & MC Module 1
 
Design of an Embedded Micro controller
Design of an Embedded Micro controllerDesign of an Embedded Micro controller
Design of an Embedded Micro controller
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set Architecture
 
PIC introduction + mapping
PIC introduction + mappingPIC introduction + mapping
PIC introduction + mapping
 
Unit 2 Instruction set.pdf
Unit 2 Instruction set.pdfUnit 2 Instruction set.pdf
Unit 2 Instruction set.pdf
 
Microcontroller pic 16f877 addressing modes instructions and programming
Microcontroller pic 16f877 addressing modes instructions and programmingMicrocontroller pic 16f877 addressing modes instructions and programming
Microcontroller pic 16f877 addressing modes instructions and programming
 
Highridge ISA
Highridge ISAHighridge ISA
Highridge ISA
 
8085 microprocessor(1)
8085 microprocessor(1)8085 microprocessor(1)
8085 microprocessor(1)
 
PIC16F877A C Programming.ppt
PIC16F877A C Programming.pptPIC16F877A C Programming.ppt
PIC16F877A C Programming.ppt
 
Basic programming of 8085
Basic programming of 8085 Basic programming of 8085
Basic programming of 8085
 

Dernier

"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086anil_gaur
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxnuruddin69
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...Health
 

Dernier (20)

"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 

Ch2 microcontroller architecture

  • 1. Copyright Politeknik Kota Bharu Page 1 CHAPTER 2 – MICROCONTROLLER ARCHITECTURE & ASSEMBLY LANGUAGE PROGRAMMING PIC18 Microcontroller families  PIC is a family of modified Harvard architecture microcontrollers made by Microchip Technology, derived from the PIC1650 originally developed by General Instrument's Microelectronics Division. The name PIC initially referred to "Peripheral Interface Controller".  1989 – Microchip Technology Corporation introduced it’s first 8-bit microcontroller PIC18 Architecture  PIC microcontrollers are based on advanced RISC architecture.  RISC stands for Reduced Instruction Set Computing. In this architecture, the instruction set of hardware gets reduced which increases the execution rate (speed) of system.  CPUs use many register to store data temporarily.  To program in Assembly Language, we must understand the register and architecture  PIC microcontrollers follow Harvard architecture for internal data transfer  PIC microcontrollers are designed using the Harvard Architecture which includes:  Microprocessor unit (MPU)  Program memory for instructions  Data memory for data  I/O ports  Support devices such as timers
  • 3. Copyright Politeknik Kota Bharu Page 3 The data RAM file Register  CPUs use many registers to store data temporarily.  To program in assembly language, we must understand the registers and architecture of given CPU and the role they play in processing data. WREG register  Registers are used to store information temporarily  The information could be a byte of data to be processed, or and address pointing to the data to be fetched  The WREG is the most widely used register in PIC microcontroller
  • 4. Copyright Politeknik Kota Bharu Page 4  The 8-bit WREG register is the most widely used register in the PIC micro controller.  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 the WREG register, we will show it in the context of two simple instructions: MOVLW and ADDWL. MOVLW Instruction Notice that 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 following instruction loads the WREG register with a literal value of 25H (i.e., 25 in hex). o MOVLW 25H ; move value 25H into WREG o MOVLW 87H ; load 87H into WREG 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 MOVLW 25H ; load 25H into WREG ADDLW 34H ; add value 34 to WREG W = W + 34H Executing the above lines results in WREG = 59H (25H + 34H = 59H) File register (SFRs and GPR)  File Register (data RAM) is read/write memory used by CPU for data storage, scratch pad and register for internal use and function  Divided into two sections: o SFRs – Special Function Registers o GPR – General-Purpose Register
  • 5. Copyright Politeknik Kota Bharu Page 5 Special Function Register (SFRs)  Special-Function registers are RAM memory locations, their purpose is predetermined during manufacturing process and cannot be changed.  Dedicated to specific functions – ALU status, timers, serial communication, I/O ports ADC etc.  Fixed by CPU designer at the time of design  8 bits register
  • 6. Copyright Politeknik Kota Bharu Page 6 General Purpose Register (GPR)  8-bit registers  are a group of RAM locations in the file register that are used for data storage and scratch pad.  the space that is not allocated to the SFRs typically used for general-purpose registers MOVWF Instruction Notice that in MOVWF, the letter F stands for a location in the file register, while W means WREG. The MOVWF instructions tells the CPU to move (in reality, copy) the source register of WREG to a destination in the file register (F) 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)
  • 7. Copyright Politeknik Kota Bharu Page 7 MOVF Instruction The MOVF mnemonic is intended to perform MOVFW. It move the contents of file register into WREG or to itself MOVF PORTB,W ; move from file register of Port B to WREG MOVF PORTB,0 ; move content of file register into WREG MOVF PORTB,1 ; move content of file register into itself Review Question 1. State five example of SFR 2. What is GPR 3. Write an instruction to move value of 58H into WREG 4. Write an instruction to move value of 58H into PORTB 5. What is the difference between the MOVWF and MOVF instruction 6. Explain each instruction below: a. MOVLW 55H b. MOVF PORTB,W Status Register  One of the most important register in PIC. Most of PIC has this register.  8-Bit register. Sometime referred as flag register.  Only 5 bits of it are used by the PIC18. o called conditional flags  The three unused bits are unimplemented and read as 0.
  • 8. Copyright Politeknik Kota Bharu Page 8  C (Carry/Borrow Flag) set when an addition generates a carry and a subtraction generates a borrow.  DC(Digit Carry Flag):also called Half Carry flag;set when carry generated from Bit3 to Bit4 an arithmetic operatio.n  Z(Zero Flag):set when result of an operation is zero.  OV(Overflow Flag):set when result of an operation of signed numbers goes beyond seven bits-if the results fall outside 127(0x7F)and -128(0x80).  N(Negative Flag):set when bit B7 is one of the result of an arithmetic/logic operation. Example 1. Show the status of the C, DC and Z flag after the addition of 38H and 2FH. Solution: 38H 00111000 + 2FH + 00101111 67H 01100111 C = 0 ; DC = 1; Z = 0
  • 9. Copyright Politeknik Kota Bharu Page 9 2. Show the status of the C, DC and Z flags after the addition of 9CH and 64H in the following instructions: MOVLW 9CH ADDLW 64H 3. Write the instruction for addition operation of 88H and 93H and show the status of the C, DC and Z flags. Solution: MOVLW 88H ADDLW 93H Review Question 1. Determine the state of status register after the instruction below: a. MOVLW 0F5H ADDLW 0BH b. MOVLW 9FH ADDLW 61H
  • 10. Copyright Politeknik Kota Bharu Page 10 2. Show the status of the C, DC and Z flags after the addition of 9CH and 64H in the following instructions: a. MOVLW 9CH ADDLW 64H b. MOVLW 67H ADDLW 99H c. MOVLW 87H ADDLW 22H Data format and directives  PIC data type has only one data type. 8-bits. Size of register also 8-bits ( 00-FF, or 0-255)  Data format representation. o Hex, o Binary, o Decimal, o ASCII HEX number  Use h, or H right after the number. Example MOVLW 12H  Put 0x. Example MOVLW 0x12;  Put nothing. Eg. MOVLW 12  Put h in front of number. MOVLW h’12’ Binary number  Only one way to represent binary numbers, Example: MOVLW B’00010010’ 1 2 in hex Decimal number  Two ways to represent. MOVLW D’12’ , (in hex 0x0C)  Or MOVLW .12
  • 11. Copyright Politeknik Kota Bharu Page 11 ASCII code To represent ASCII data in PIC assemble we use the letter A as follows MOVLW A’2’ ; WREG = 00110010 or 32 in hex ( see ASCII chart) MOVLW A’c’ ; WREG = 01100011 or 63 in hex (see ASCII chart) MOVLW ‘9’ ; WREG = 39H another way for ASCII
  • 12. Copyright Politeknik Kota Bharu Page 12 ASSEMBLER Directive  Directive give direction to he assembler..  Example EQU, ORG, END, #INCLUDE, LIST, _CONFIG EQU (equate)  Used to define constant value or fixed address.  Associates a constant number / address label  Eg. COUNT EQU 0x25 MOVLW COUNT ; WREG = 25 ORG (Origin)  Indicate the beginning of the address.  Example ORG 0x00 END  Important to indicate End of code, last line LIST  Indicates to the assembler the specific PIC chip for which the program should be assembled. Eg. LIST P=18F458 #INLCUDE  Tell the assembler to use the libraries associated with the specific chip _CONFIG  To configure bits for the targeted PIC. Read during the power-up, wrong configuration makes PIC unusable.
  • 13. Copyright Politeknik Kota Bharu Page 13 Example code Instruction set of PIC18  PIC18F2455/2550/4455/4550 devices incorporate the standard set of 75 PIC18 core instructions.  The instruction set is highly orthogonal and is grouped into four basic categories: o Byte-oriented operations o Bit-oriented operations o Literal operations o Control operations
  • 14. Copyright Politeknik Kota Bharu Page 14
  • 15. Copyright Politeknik Kota Bharu Page 15 Arithmetic Instruction and Operation a. Addition and subtraction MOVLW 0xF5 ; WREG = F5 ADDLW 0x0B ; WREG = F5 + 0B = 00 and C = 1 MOVLW 0x23 ; WREG = 23H SUBLW 0x3F ; WREG = 3F - WREG
  • 16. Copyright Politeknik Kota Bharu Page 16 b. Multiplication The PIC supports byte-by-byte multiplication only. The byte is assumed to be unsigned data. The syntax is as follows. After multiplication, the result is in the special function registers PRODH and PRODL; the lower byte is in PRODL, and the upper byte is in PRODH. MULLW K ; W x K 16 bit is result in PRODH:PRODL
  • 17. Copyright Politeknik Kota Bharu Page 17 c. Addition of BCD data  BCD stands for binary coded decimal. BCD is needed because in everyday life we use the digits 0 to 9 for number, not binary or hex number  Binary representation of 0 to 9 is called BCD . In computer literature, one encounters two terms for BCD numbers: (i) unpacked BCD, and (ii) packed BCD.  In unpacked BCD, the lower 4 bits of the number represent the BCD number, and the rest of the bits are O. Example: "0000 100 I" and "0000 0101" are unpacked BCD for 9 and 5, respectively. Unpacked BCD requires I byte of memory, or an S-bit register, to contain it.  In packed BCD, a single byte has two BCD numbers in it: one in the lower 4 bits, and one in the upper 4 bits. For example, "0101 1001" is packed BCD for 59H. Only I byte of memory is needed to store the packed BCD operands. One reason to use packed BCD is that it is twice as efficient in storing data.  There is a problem with adding BCD numbers, which must be corrected. The problem is that after adding packed BCD numbers, the result is no longerBCD. Look at the following. MOVLW 0x17 ADDLW 0x28  Adding these two numbers gives 0011 IIII B (3FH), which is not BCD. A BCD number can only have digits from 0000 to 1001 (or 0 to 9).  The result above should have been 17 + 28 = 45 (01000101). To correct this problem, the programmer must add 6 (0 II 0) to the low digit: 3F + 06 = 45H.  The same problem could have happened in the upper digit (for example, in 52H + 87H = D9H). Again, 6 must be added to the upper digit (D9H + 60H = 139H) to ensure that the result is BCD (52 + 87 = 139).  This problem is so pervasive that most microprocessors such as the PIC 18 have an instruction to deal with it. In the PIC 18 instruction "DAW" is designed to correct the BCD addition problem.  The DAW (decimal adjust WREG) instruction in the PIC 18 is provided to correct the aforementioned problem associated with BCD addition.  The mnemonic "DAW" works only with an operand in the WREG register. The DAW instruction will add 6 to the lower nibble or higher nibble if needed; otherwise, it will leave the result alone. The following example will clarify these points 
  • 18. Copyright Politeknik Kota Bharu Page 18 Logic Instruction and Bit Manipulation  Apart from I/O and arithmetic instructions, logic instructions are some of most widely used instructions.  Boolean logic instructions such as AND, OR, Exclusive-OR (XOR), and complement.  Logical operations are useful for looking for array elements with certain properties (e.g., divisible by power of 2) and manipulating I/O pin values (e.g., set certain pins to high, clear a few pins, toggle a few signals, and so on).  The logical instruction allow user to perform AND, OR, exclusive-OR and complementing on 8-bit numbers. AND ANDLW K ; WREG = WREG AND K Example : Show the result of the following MOVLW 0x35h ANDLW 0x0Fh
  • 19. Copyright Politeknik Kota Bharu Page 19 OR IORLW K ; WREG = WREG OR K Example : Show the result of the following MOVLW 0x04h IORLW 0x30h EX-OR XORLW K ; WREG = WREG XOR K Example : Show the result of the following MOVLW 0x54h XORLW 0x78h
  • 20. Copyright Politeknik Kota Bharu Page 20 COMF (Compliment file register) This instruction complements the contents of a file register. The complement action changes the 0s to 1s and the 1s to 0s. This is also called 1’s complement Bit Manipulation  BCF – Bit Clear File register (set the bit: bit = 1)  BSF – Bit Set File register (clear the bit: bit = 0)  BTG – Bit Toggle File register (complement the bit)  BTFSC – Bit Test File register, skip if clear (skip next instruction if bit = 0)  BTFSS– Bit Test File register, skip if set (skip next instruction if bit = 1)  RRNCF – Rotate right f (no carry)  RLNCF – Rotate left f (no carry)  RRCF – Rotate right f through carry  RLCF – Rotate left f through carry Example
  • 21. Copyright Politeknik Kota Bharu Page 21 Review Question 1. Explain each of the register below: a. WREG Register b. File Register c. Status Register 2. Include directive is used to …………… 3. EQU is used to ……………………………… 4. Illustrate the result after the following code is executed