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

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
 
Microcontrollers 80 Marks Sample Question Paper
Microcontrollers   80 Marks Sample Question PaperMicrocontrollers   80 Marks Sample Question Paper
Microcontrollers 80 Marks Sample Question Paperprathik
 
Interrupts for PIC18
Interrupts for PIC18Interrupts for PIC18
Interrupts for PIC18raosandy11
 
register file structure of PIC controller
register file structure of PIC controllerregister file structure of PIC controller
register file structure of PIC controllerNirbhay Singh
 
Fsm sequence detector
Fsm sequence detector Fsm sequence detector
Fsm sequence detector lpvasam
 
Interfacing keypad
Interfacing keypadInterfacing keypad
Interfacing keypadPRADEEP
 
Summer Internship Report For PLC Programming of Traffic light through Ladder ...
Summer Internship Report For PLC Programming of Traffic light through Ladder ...Summer Internship Report For PLC Programming of Traffic light through Ladder ...
Summer Internship Report For PLC Programming of Traffic light through Ladder ...Aman Gupta
 
Verilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and EncoderVerilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and EncoderBharti Airtel Ltd.
 
Serial communication in LPC2148
Serial communication in LPC2148Serial communication in LPC2148
Serial communication in LPC2148sravannunna24
 
Microchip's PIC Micro Controller
Microchip's PIC Micro ControllerMicrochip's PIC Micro Controller
Microchip's PIC Micro ControllerMidhu S V Unnithan
 
Fpga(field programmable gate array)
Fpga(field programmable gate array) Fpga(field programmable gate array)
Fpga(field programmable gate array) Iffat Anjum
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Aarav Soni
 
PIC MICROCONTROLLERS -CLASS NOTES
PIC MICROCONTROLLERS -CLASS NOTESPIC MICROCONTROLLERS -CLASS NOTES
PIC MICROCONTROLLERS -CLASS NOTESDr.YNM
 
Clk-to-q delay, library setup and hold time
Clk-to-q delay, library setup and hold timeClk-to-q delay, library setup and hold time
Clk-to-q delay, library setup and hold timeVLSI SYSTEM Design
 
Semi Custom Integrated Circuit Design
 Semi Custom Integrated Circuit Design Semi Custom Integrated Circuit Design
Semi Custom Integrated Circuit DesignDr.YNM
 

Tendances (20)

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
 
CPLDs
CPLDsCPLDs
CPLDs
 
PIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC InterfacingPIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC Interfacing
 
Important questions
Important questionsImportant questions
Important questions
 
Microcontrollers 80 Marks Sample Question Paper
Microcontrollers   80 Marks Sample Question PaperMicrocontrollers   80 Marks Sample Question Paper
Microcontrollers 80 Marks Sample Question Paper
 
Interrupts for PIC18
Interrupts for PIC18Interrupts for PIC18
Interrupts for PIC18
 
register file structure of PIC controller
register file structure of PIC controllerregister file structure of PIC controller
register file structure of PIC controller
 
Fsm sequence detector
Fsm sequence detector Fsm sequence detector
Fsm sequence detector
 
Interfacing keypad
Interfacing keypadInterfacing keypad
Interfacing keypad
 
2-bit comparator
2-bit comparator2-bit comparator
2-bit comparator
 
Summer Internship Report For PLC Programming of Traffic light through Ladder ...
Summer Internship Report For PLC Programming of Traffic light through Ladder ...Summer Internship Report For PLC Programming of Traffic light through Ladder ...
Summer Internship Report For PLC Programming of Traffic light through Ladder ...
 
Verilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and EncoderVerilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and Encoder
 
Serial communication in LPC2148
Serial communication in LPC2148Serial communication in LPC2148
Serial communication in LPC2148
 
Microchip's PIC Micro Controller
Microchip's PIC Micro ControllerMicrochip's PIC Micro Controller
Microchip's PIC Micro Controller
 
Fpga(field programmable gate array)
Fpga(field programmable gate array) Fpga(field programmable gate array)
Fpga(field programmable gate array)
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction set
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
PIC MICROCONTROLLERS -CLASS NOTES
PIC MICROCONTROLLERS -CLASS NOTESPIC MICROCONTROLLERS -CLASS NOTES
PIC MICROCONTROLLERS -CLASS NOTES
 
Clk-to-q delay, library setup and hold time
Clk-to-q delay, library setup and hold timeClk-to-q delay, library setup and hold time
Clk-to-q delay, library setup and hold time
 
Semi Custom Integrated Circuit Design
 Semi Custom Integrated Circuit Design Semi Custom Integrated Circuit Design
Semi Custom Integrated Circuit Design
 

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
 
Embedded system (Chapter 2) part A
Embedded system (Chapter 2) part AEmbedded system (Chapter 2) part A
Embedded system (Chapter 2) part AIkhwan_Fakrudin
 
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 (20)

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
 
Embedded system (Chapter 2) part A
Embedded system (Chapter 2) part AEmbedded system (Chapter 2) part A
Embedded system (Chapter 2) part A
 
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 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
 
Ecet 330 Success Begins / snaptutorial.com
Ecet 330 Success Begins / snaptutorial.comEcet 330 Success Begins / snaptutorial.com
Ecet 330 Success Begins / snaptutorial.comWilliamsTaylorzm
 
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
 
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
 
Microprocessor lab manual
Microprocessor lab manualMicroprocessor lab manual
Microprocessor lab manualDhaval Shukla
 

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 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
 
Ecet 330 Success Begins / snaptutorial.com
Ecet 330 Success Begins / snaptutorial.comEcet 330 Success Begins / snaptutorial.com
Ecet 330 Success Begins / 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
 
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
 
Microprocessor lab manual
Microprocessor lab manualMicroprocessor lab manual
Microprocessor lab manual
 

Dernier

ASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderjuancarlos286641
 
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....santhyamuthu1
 
Modelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovationsModelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovationsYusuf Yıldız
 
Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...Apollo Techno Industries Pvt Ltd
 
SUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docx
SUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docxSUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docx
SUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docxNaveenVerma126
 
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS Bahzad5
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabusViolet Violet
 
Phase noise transfer functions.pptx
Phase noise transfer      functions.pptxPhase noise transfer      functions.pptx
Phase noise transfer functions.pptxSaiGouthamSunkara
 
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Amil baba
 
UNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptxUNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptxrealme6igamerr
 
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...amrabdallah9
 
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdfSummer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdfNaveenVerma126
 
Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical SensorTanvir Moin
 
Mohs Scale of Hardness, Hardness Scale.pptx
Mohs Scale of Hardness, Hardness Scale.pptxMohs Scale of Hardness, Hardness Scale.pptx
Mohs Scale of Hardness, Hardness Scale.pptxKISHAN KUMAR
 
Clutches and brkesSelect any 3 position random motion out of real world and d...
Clutches and brkesSelect any 3 position random motion out of real world and d...Clutches and brkesSelect any 3 position random motion out of real world and d...
Clutches and brkesSelect any 3 position random motion out of real world and d...sahb78428
 
Multicomponent Spiral Wound Membrane Separation Model.pdf
Multicomponent Spiral Wound Membrane Separation Model.pdfMulticomponent Spiral Wound Membrane Separation Model.pdf
Multicomponent Spiral Wound Membrane Separation Model.pdfGiovanaGhasary1
 
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratoryدليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide LaboratoryBahzad5
 

Dernier (20)

ASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entender
 
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
 
Modelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovationsModelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovations
 
Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...
 
SUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docx
SUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docxSUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docx
SUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docx
 
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabus
 
Phase noise transfer functions.pptx
Phase noise transfer      functions.pptxPhase noise transfer      functions.pptx
Phase noise transfer functions.pptx
 
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
 
UNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptxUNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptx
 
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
 
Litature Review: Research Paper work for Engineering
Litature Review: Research Paper work for EngineeringLitature Review: Research Paper work for Engineering
Litature Review: Research Paper work for Engineering
 
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdfSummer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
 
Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical Sensor
 
Mohs Scale of Hardness, Hardness Scale.pptx
Mohs Scale of Hardness, Hardness Scale.pptxMohs Scale of Hardness, Hardness Scale.pptx
Mohs Scale of Hardness, Hardness Scale.pptx
 
Lecture 2 .pptx
Lecture 2                            .pptxLecture 2                            .pptx
Lecture 2 .pptx
 
Clutches and brkesSelect any 3 position random motion out of real world and d...
Clutches and brkesSelect any 3 position random motion out of real world and d...Clutches and brkesSelect any 3 position random motion out of real world and d...
Clutches and brkesSelect any 3 position random motion out of real world and d...
 
Lecture 4 .pdf
Lecture 4                              .pdfLecture 4                              .pdf
Lecture 4 .pdf
 
Multicomponent Spiral Wound Membrane Separation Model.pdf
Multicomponent Spiral Wound Membrane Separation Model.pdfMulticomponent Spiral Wound Membrane Separation Model.pdf
Multicomponent Spiral Wound Membrane Separation Model.pdf
 
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratoryدليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
 

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