1.  List all addressing modes of PIC18 uCs  Contrast and compare the addressing modes  Code PIC18 instructions to manipulate a lookup table.  Access.

Slides:



Advertisements
Similar presentations
Control structures Hot to translate high level control structures to assembler.
Advertisements

Suranaree University Of Technology มทส  2002 Anant Oonsivilai 2002/4/8 Microcomputers and Microprocessors 1 Chapter 5 Addressing Modes.
The 8051 Microcontroller and Embedded Systems
Experiment 2 PIC Program Execution & Built-In Self-Test.
By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Prof. Jorge A. Ramón Introducción a Microcontroladores.
8051 ASSEMBLY LANGUAGE PROGRAMMING
16.317: Microprocessor System Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 30: PIC data memory.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2013 Lecture 27: PIC instruction set.
Microcontroller Architecture— PIC18F Family
PIC18F Programming Model and Its Instruction Set
Chapter 4 Starting to Program – an Introduction to Assembler The aims of this chapter are to introduce: the essentials of Assembler programming; the Microchip.
9/20/6Lecture 21 -PIC Architecture1 PIC Architecture Instruction Set.
Micro controllers A self-contained system in which a processor, support, memory, and input/output (I/O) are all contained in a single package.
9/20/6Lecture 21 -PIC Architecture1 PIC Architecture Programmers Model and Instruction Set.
Building Assembler Programs Chapter Five Dr. Gheith Abandah1.
NATIONAL TAIWAN OCEAN UNIVERSITY 國立台灣海洋大學 2002/4/8 Microcomputers and Microprocessors Chapter 5 Addressing Modes.
Directives, Memory, and Stack. Directives Special commands to the assembler May or may not generate machine code Categories by their function Programming.
Microprocessor and Interfacing PIC Code Execution
The 8051 Microcontroller and Embedded Systems
Embedded System Spring, 2011 Lecture 4: The PIC Microcontrollers Eng. Wazen M. Shbair.
Embedded System Spring, 2011 Lecture 10: Arithmetic, Logic Instruction and Programs Eng. Wazen M. Shbair.
PIC18F Programming Model and Instruction Set
Lecture – 4 PIC18 Family Instruction Set 1. Outline Literal instructions. Bit-oriented instructions. Byte-oriented instructions. Program control instructions.
Embedded System Spring, 2011 Lecture 5: The PIC Microcontrollers Eng. Wazen M. Shbair.
PIC – ch. 2b. Move to GPR Move [copy] contents of WREG  GPR/RAM MOVLW99H;WREG=99H MOVWF0H ;move [copy] WREG contents to location 0h … -Cant move literal.
Embedded System Spring, 2011 Lecture 11: Bank Switching Eng. Wazen M. Shbair.
EEE237 Introduction to Microprocessors Week x. SFRs.
Eng. Husam Alzaq The Islamic Uni. Of Gaza
Architecture and instruction set. Microcontroller Core Features:  Operating speed: DC - 20 MHz clock input DC ns instruction cycle Up to 8K x.
Subroutines A subroutine is a block of code that is called from different places from within a main program or other subroutines. Saves code space in that.
PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }
Department of Electronic & Electrical Engineering Lecture 2 ● Introduction to IO ● Using a subroutine ● Driving a 7seg display.
1 EKT 225 MICROCONTROLLER I CHAPTER ASSEMBLY LANGUAGE PROGRAMMING.
Embedded System Spring, 2011 Lecture 11: Bank Switching Eng. Wazen M. Shbair.
PIC12F629/675. “Wide variety” 8-84 pin RISC core, 12/14/16bit program word USART/AUSART, I 2 C, ADC, ICSP, ICD OTP/UV EPROM/FLASH/ROM Families: PIC12,
Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ●
Dr. Iyad Jafar Introducing the PIC 16 Series and the 16F84A.
Chapter 9 PIC18 Timer Programming in Assembly
Microprocessor and Microcontroller Fundamentals
CHAPTER ADDRESSING MODES.
Microprocessor Systems Design I
Microprocessor Systems Design I
Memory Organisation Source: under
Micro-processor vs. Micro-controller
Microprocessor Systems Design I
The 8051 Microcontroller and Embedded Systems
Interrupts, Counter and Timers
Microprocessor Systems Design I
PIC – ch. 2b Md. Atiqur Rahman Ahad.
PIC 16F877.
16.317: Microprocessor System Design I
Microprocessor Systems Design I
PIC18 CH. 4.
Introduction to Micro Controllers & Embedded System Design Addressing Mode Department of Electrical & Computer Engineering Missouri University of Science.
EECE.3170 Microprocessor Systems Design I
Memory Organisation Source: under
Chapter 4 Instruction Set.
EECE.3170 Microprocessor Systems Design I
INSTRUCTION SET.
Figure 2-1. PIC WREG and ALU Using Literal Value
Figure 6-1a. MOVFF Direct Addressing Opcode
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Memory Organisation Source: under
EECE.3170 Microprocessor Systems Design I
8051 ASSEMBLY LANGUAGE PROGRAMMING
EECE.3170 Microprocessor Systems Design I
Md. Atiqur Rahman Ahad PIC18… Ch. 3.1 Md. Atiqur Rahman Ahad
Presentation transcript:

1

 List all addressing modes of PIC18 uCs  Contrast and compare the addressing modes  Code PIC18 instructions to manipulate a lookup table.  Access fixed data residing in ROM space.  Discuss how to access the entire 4kB of RAM  List address for all 16 banks of the PIC18  Discuss bank switching for the PIC18 2

 Data could be in ◦ A register ◦ In memory ◦ Provided as an immediate values  PIC18 provides 4 addressing modes ◦ Immediate ◦ Direct ◦ Register indirect ◦ Indexed-ROM 3

 In immediate addressing mode, the operands comes after the opcode ◦ MOVLW 0x25 ◦ SUBLW D’34’ ◦ ADDLW 0x86  In direct addressing mode, the operand data is in a RAM location whose address is known and given as a part of the instruction. MOVLW 0X56 MOVWF 0X40 MOVFF 0X40,50H 4

 A register is used as a pointer to the data RAM location.  Three 12-bit Registers are used (from 0 to FFFh) ◦ FSR0 ◦ FSR1 ◦ FSR2  Each register is associated with INDFx  Syntax ◦ LFSR n,data  LFSR 1,95Eh  needs 2 cycles FSR means file Select register 5

Solution A  Write a program to copy the value 55H into RAM locations 40h to 45h using A. Direct addressing mode B. Register indirect addressing mode C. A loop MOVLW 0x55 MOVWF 0x40 MOVWF 0x41 MOVWF 0x42 MOVWF 0x43 MOVWF 0x44 6

Solution B MOVLW 55H LFSR 0,0x40 MOVWF INDF0 INCF FSR0L,F MOVWF INDF0 INCF FSR0L,F MOVWF INDF0 INCF FSR0L,F MOVWF INDF0 INCF FSR0L,F MOVWF INDF0 COUNT EQU 0x10 MOVLW 0x5 MOVWF COUNT LFSR 0,0x40 MOVLW 0x55 B1 MOVWF INDF0 INCF FSR0L,F DECF COUNT,F BNZ B1 7

 Normal increment can cause problem since it increments 8-bit ◦ INC FSR0L, F  Auto increment and auto decrement solve the problem ◦ They doesn’t affect the status flag FF 03 FSR0H FSR0L 8

InstructionFunction CLRFINDFn After clearing fileReg pointed by FSRn, the FSRn stays the same CLRFPOSTINCn After clearing fileReg pointed by FSRn, the FSRn is incremented (like x++) CLRFPREINCn The FSRn is incremented, then fileReg pointed to by FSRn is cleared (like ++x) CLRFPOSTDECn After clearing fileReg pointed by FSRn, the FSRn is decremented (like x++) CLRFPLUSWn Clears fileReg pointed by FSRn + WREG, and FSRn W are unchanged 9

Solution  Write a program to clear 16 RAM location starting at location 60H using Auto increment.  Note: there are two identical mistakes in your book, pp 202. The right correction is FSR1=60H (not 40H) COUNTREG EQU 0x10 CNTVAL EQU D'16' MOVLW CNTVAL MOVWF COUNTREG LFSR 1,0x60 B3 CLRF POSTINC1 DECF COUNTREG,F BNZ B3 10

Solution  Write a program to copy a block of 5 bytes of data from location starting at 30H to RAM locations starting at 60H. COUNTREG EQU 0x10 CNTVAL EQU D'5' MOVLW CNTVAL MOVWF COUNTREG LFSR 0, 0x30 LFSR 1, 0x60 B3 MOVF POSTINC0,W MOVWF POSTINC1 DECF COUNTREG,F BNZ B3 11

Solution  Assume that RAM locations 40-43H have the following hex data. Write a program to add them together and place the result in locations 06 and 07. COUNTREG EQU 0x20 L_BYTE EQU 0x06 H_BYTE EQU 0x07 CNTVAL EQU 4 MOVLW CNTVAL MOVWF COUNTREG LFSR 0,0x40 CLRF WREG CLRF H_BYTE B5 ADDWF POSTINC0, W BNC OVER INCF H_BYTE,F OVER DECF COUNTREG,F BNZ B5 MOVWF L_BYTE AddressData 040H7D 041H EB 042H C5 043H 5B 12

Solution  Write a program to add the following multi- byte BCD numbers and save the result at location 60H COUNTREG EQU 0x20 CNTVAL EQU D'4' MOVLW CNTVAL MOVWF COUNTREG LFSR 0,0x30 LFSR 1,0x50 LFSR 2,0x60 BCF STATUS,C B3 MOVF POSTINC0,W ADDWFC POSTINC1,W DAW MOVWF POSTINC2 DECF COUNTREG,F BNZ B3 AddressData 030H77 031H H H H39 051H78 052H64 053H23 13

 Beside instructions, ROM has enough space to store fixed data  DB directive, which means Define Byte, is widely used to allocate ROM program memory in byte-sized chunks  Use single quotes (´) for a single character or double quotes (“) for a stringOrg 0x50 DATA1DB 0x39 DATA2DB`z´ DATA3DB“Hello All“  ROM address must be even 14

◦ To read the fixed data byte We need an address pointer: TBLPTR Points to data to be fetched ◦ 21 bits as the program counter!! ◦ Divided into 3 registers: TBLPTRL, TBLPTRH, TBLPTRU (all parts of SFR) ◦ Is there any instruction to load 21 bits (as LFSR)? ◦ A register to store the read byte TBLLAT: keeps the data byte once it is fetched into the CPU 15

Assume that ROM space starting at 250H contains "Embedded System“, write a program to send all characters to PORTB one byte at a time RCOUNT EQU0x20 CNTVAL EQU0x0F ORG 0000H MOVLW 0x50 MOVWF TBLPTRL MOVLW 0x02 MOVWF TBLPTRH MOVLW CNTVAL MOVWF RCOUNT CLRF TRISB B6 TBLRD* MOVFFTABLAT,PORTB INCFTBLPTRL,F DECFRCOUNT,F BNZB6 HEREGOTOHERE ORG0x250 MYDATADB "Embedded system" END 16

 You can access any bit of the status register by their name.  Examples BCF STATUS,C BTFSS STATUS, Z 17

 PIC18 has maximum of 4K of RAM ◦ Not all the space used. ◦ The fileReg is divided into 16 banks of 256B each ◦ Every PIC18 has the access bank (the first 128B of RAM + SFR ) ◦ Most PIC18 that access the data space in RAM has the ability to access any bank through setting an optional operand, called A ◦ Example: MOVWF myReg, A  If 0 it access the default bank (default)  If 1, it uses the bank selection register (BSR) to select the bank 18

19

 It is 8-bit register ◦ 4 bits are used  16 banks ◦ Banks 0 (from 00 to FF) ◦ Banks 1 (from 100 to 1FF) ◦ Banks 2 (from 200 to 2FF) ◦..... ◦ Banks F (from F00 to FFF) (includes SFR)  Upon power-on reset, BSR is equal to 0 (default value) 20

21

 Two thing must be done 1. Load BSR with desired bank 2. Make A = 1 in the instruction itself. MYREG EQU 0x40 MOVLB 0x2 MOVLW 0 MOVWF MYREG,1 INCF MYREG, F, 1 22

 Write a program to copy the value 55H into RAM locations 340h to 345h using A. Direct addressing mode B. A loop MOVLB0x3 MOVLW0x55 MOVWF0x40, 1 MOVWF0x41, 1 MOVWF0x42, 1 MOVWF0x43, 1 MOVWF0x44, 1 23

 Write a program to copy the value 55H into RAM locations 340h to 345h using A. Direct addressing mode B. A loop COUNT EQU 0x10 MOVLB0x3 MOVLW0x6 MOVWFCOUNT LFSR0,0x340 MOVLW0x55 B1 MOVWFINDF0,0 INCFFSR0L DECFCOUNT,F,0 BNZ B1 24