Section 31. Instruction Set

Size: px
Start display at page:

Download "Section 31. Instruction Set"

Transcription

1 31 HIGHLIGHTS Section 31. Instruction Set Instruction Set This section of the manual contains the following major topics: 31.1 Introduction Data Memory Map Instruction Formats Special Function Registers as Source/Destination Fast Register Stack Q Cycle Activity Instruction Descriptions Design Tips Related Application tes Revision History Microchip Technology Inc. DS39532A-page 31-1

2 PIC18C Reference Manual 31.1 Introduction The PIC18CXXX instruction set adds many enhancements to the previous PICmicro instruction sets, while maintaining an easy migration from these PICmicro instruction sets. Most instructions are a single program memory word (16-bits), but to address customer requests, some new instructions have been added that require two program memory locations. The Instruction Set Summary, shown in Table 31-1, lists the instructions recognized by the Microchip assembler (MPASM). Table 31-2 gives the instruction description conventions. Each instruction is divided into an OPCODE that specifies the instruction type and one or more operands which further specify the of the instruction. The instruction set is highly orthogonal and is grouped into four basic categories: Byte-oriented s Bit-oriented s Literal s Control s Most byte-oriented instructions have three operands: 1. The File Register (specified by the value of f ) 2. The destination of the result (specified by the value of d ) 3. The accessed memory (specified by the value of a ) 'f' represents a File Register Designator and 'd' represents a Destination Designator. The File Register Designator specifies which File Register is to be used by the instruction. The access indicator a specifies if the BSR selects the bank or if the access bank is used. The destination designator specifies where the result of the is to be placed. If 'd' is zero, the result is placed in the WREG Register. If 'd' is one, the result is placed in the File Register specified in the instruction. All bit-oriented instructions have three operands: 1. The File Register (specified by the value of f ) 2. The bit in the File Register (specified by the value of b ) 3. The accessed memory (specified by the value of a ) 'b' represents a bit field designator that selects the number of the bit affected by the, while 'f' represents the number of the file in which the bit is located. The access indicator a specifies if the BSR selects the bank or if the access bank is used. The literal instructions may use some of the following operands: A literal value to be loaded into a File Register (specified by the value of k ) The desired FSR Register to load the literal value into (specified by the value of f ) operand required (specified by the value of ) The control instructions may use some of the following operands: A program memory address (specified by the value of n ) The mode of the CALL or RETURN instructions (specified by the value of s ) The mode of the Table Read and Table Write instructions (specified by the value of m ) operand required (specified by the value of ) All instructions are a single word except for three double word instructions. These three instructions were made double word instructions so that all the required information is available in these 32 bits. In the second word, the 4-MSb s, are 1 s. If this second word is executed as an instruction (by itself), it will execute as a NOP. All single word instructions are executed in a single instruction cycle, unless a conditional test is true or the program counter is changed as a result of the instruction. In these cases, the execution takes two instruction cycles with the additional instruction cycle(s) executed as a NOP. The double word instructions (that do not modify the PC) execute in two instruction cycles. One instruction cycle consists of four oscillator periods. Thus, for an oscillator frequency of 4 MHz, the normal instruction execution time is 1 µs. If a conditional test is true or the program counter is changed as a result of an instruction, the instruction execution time is 2 µs. Two word branch instructions (if true) would take 3 µs. DS39532A-page Microchip Technology Inc.

3 31.2 Data Memory Map Section 31. Instruction Set The Data Memory Map has 16 banks of 256 bytes. The Instruction Set and architecture allows s across all banks (such as MOVFF). A Segment of Bank 0 and a segment of Bank 15 comprise the access bank. See Section for description of the access bank. Figure 31-1: The Data Memory Map and the Access Bank BSR<3:0> = 0000b Data Memory Map Segment 0 Bank 0 00h 31 Instruction Set = 0001b Bank 1 Bank n Access Bank Segment 0 Segment 1 00h FFh Device Dependent Segment Boundary = 1110b = 1111b Bank 14 Bank 15 Segment 1 FFh When the instructions a bit = 0, The BSR is ignored and this Access Bank is used. The Segment 0 General Purpose RAM is from Bank 0. The Segment 1 Special Function Registers is from Bank 15. Whena=1, the BSR is used to specify the RAM location that the instruction uses Access Bank The access bank is an architectural enhancement that is very useful for C compiler code optimization. The techniques used by the C compiler may also be useful for programs written in assembly. This memory region can be used for Intermediate computational values Local variables of subroutine Faster context saving/switching of variables Common variables Faster evaluation/control of SFRs (no banking) The access bank is comprised of 2 segments: Segment 0 and Segment 1. Segment 0 is the RAM that is mapped in Bank 0. Segment 1 is the SFRs that are mapped in Bank 15. Each Segment can be of different sizes. The sum of RAM mapped by Segment 0 and Segment 1 is 256 bytes. When forced in the access bank (a = 0 ), the last address in Segment 0 is followed by the first address in Segment 1. Segment 1 maps the Special Function Registers so that these registers can be accessed without any software overhead. This is useful for testing status flags and modifying control bits Microchip Technology Inc. DS39532A-page 31-3

4 PIC18C Reference Manual Example 31-1 shows how registers are affected depending on the value of the access bit. Register MYREG has an 8-bit address. This address specifies the location in the specified bank to perform the. The specified bank is either the bank specified by the Bank Select Register (BSR) (when a = 1), or the access bank (when a = 0). Example 31-1:Operation of Destination and Access Bits ; ; The following symbols are defined in the Microchip supplied ; device header file: ; ; For destination bit: ; F = 1 ; Result is placed in File Register ; W = 0 ; Result is placed in WREG Register ; ; For access bit: ; B = 1 ; Register used specified by BSR Bank Register ; A = 0 ; Register used is in Access Bank ; ; MYREG is a register with an 8-bit address value between 0h and FFh. ; For this example we will assign MYREG to bank 5, though it could ; be in any (or all) banks. ; MOVLB 5 ; BSR points to RAM bank 5 ; ; Contents of ; Addr(MYREG) in ; MYREG access bank WREG ; Starting Value 0x7F 0x5A x ; DECF MYREG, F, B ; 0x7E DECF MYREG, F, A ; --- 0x ; DECF MYREG, W, B ; x7D DECF MYREG, W, A ; x58 te: If the register is specified with the full 12-bit address, the assembler will automatically force the access bit to a 0 (when the address is in the access RAM area) or a 1 (for all other addresses). DS39532A-page Microchip Technology Inc.

5 Section 31. Instruction Set The common assembler usage should be that all RAM and SFR addresses are 12-bit. This means that the assembler can determine from the address of the register, whether the access bit needs to be set or cleared. Example 31-2 shows this, as well as forcing the use of the access bank. Example 31-2:Code ; ; The following symbols are defined in the Microchip supplied ; device header file: ; ; For destination bit: ; F = 1 ; Result is placed in File Register ; W = 0 ; Result is placed in WREG Register ; ; For access bit: ; B = 1 ; Register used specified by BSR Bank Register ; A = 0 ; Register used is in Access Bank ; ; Register Name Address ; Loop_CNTR 0x000 ; MYREG 0x524 ; SFR1 0xA9F ; MOVLB 5 ; BSR points to RAM bank 5 ; Addr 24 ; a-bit MYREG Loop_CNTR SFR1 WREG Bank0 ; Starting Value --- 0x7F 0x7F 0x7F x 0xA9 ; DECF Loop_CNTR, F ; x7E DECF MYREG, F ; 1 0x7E DECF SFR1, F ; x7E ; ; DECF Loop_CNTR, W ; x7D --- DECF MYREG, W ; x7D --- DECF SFR1, W ; x7D Instruction Set INCF MYREG, F, A ; xAA INCF MYREG, W, A ; x7F Microchip Technology Inc. DS39532A-page 31-5

6 PIC18C Reference Manual Table 31-1: PIC18CXXX Instruction Set Summary Mnemonic, Operands Description BYTE-ORIENTED FILE REGISTER OPERATIONS ADDWF ADDWFC ANDWF CLRF COMF CPFSEQ CPFSGT CPFSLT DECF DECFSZ DCFSNZ INCF INCFSZ INFSNZ IORWF MOVF MOVFF MOVWF MULWF NEGF RLCF RLNCF RRCF RRNCF SETF SUBFWB SUBWF SUBWFB SWAPF TSTFSZ XORWF f, d, a f, d, a f, d, a f, a f, d, a f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f s,f d f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a Add WREG and f Add WREG and Carry bit to f AND WREG with f Clear f Complement f Compare f with WREG, skip = Compare f with WREG, skip > Compare f with WREG, skip < Decrement f Decrement f, Skip if 0 Decrement f, Skip if t 0 Increment f Increment f, Skip if 0 Increment f, Skip if t 0 Inclusive OR WREG with f Move f Move f s (source) to 1st word f d (destination) 2nd word Move WREG to f Multiply WREG with f Negate f Rotate Left f through Carry Rotate Left f ( Carry) Rotate Right f through Carry Rotate Right f ( Carry) Set f Subtract f from WREG with borrow Subtract WREG from f Subtract WREG from f with borrow Swap nibbles in f Test f, skip if 0 ExclusiveORWREGwithf BIT-ORIENTED FILE REGISTER OPERATIONS BCF BSF BTFSC BTFSS BTG f, b, a f, b, a f, b, a f, b, a f, d, a Bit Clear f Bit Set f BitTestf,SkipifClear BitTestf,SkipifSet Bit Toggle f Cycles (2or3) 1(2or3) 1(2or3) 1 1(2or3) 1(2or3) 1 1(2or3) 1(2or3) (2or3) (2or3) 1(2or3) 1 16-Bit Instruction Word MSb da 00da 01da 101a 11da 001a 010a 000a 01da 11da 11da 10da 11da 10da 00da 00da 111a 001a 110a 01da 01da 00da 00da 100a 01da 11da 10da 10da 011a 10da bbba bbba bbba bbba bbba LSb Status Affected C,DC,Z,OV,N C,DC,Z,OV,N Z, N Z Z, N ne ne ne C,DC,Z,OV,N ne ne C,DC,Z,OV,N ne ne Z, N Z, N ne ne ne C,DC,Z,OV,N C, Z, N Z, N C, Z, N Z, N ne C,DC,Z,OV,N C,DC,Z,OV,N C,DC,Z,OV,N ne ne Z, N ne ne ne ne ne tes 1, 2, 3 1, 2, 3 1,2, 3 2, 3 1, 2, , 2, 3, 4 1, 2, 3, 4 1, 2 1, 2, 3, 4 1, 2, 4 1, 2 1, 2 1, , 2 1, 2 1, 2 1, 2 1, 2 2 1, 2 1, 2 1, 2 1, 2, 4 2 te 1: When a PORT Register is modified as a function of itself (e.g., MOVF PORTB, 1, 0), the value used will be that value present on the pins themselves. For example, if the latch is '1' for a pin configured as input and is driven low by an external device, the will be written back with a '0'. 2: If this instruction is executed on the TMR0 Register (and, where applicable, d = 1), the prescaler will be cleared if assigned. 3: If Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is executed as a NOP. 4: Some instructions are 2 word instructions. The second word of these instructions will be executed as a NOP, unless the first word of the instruction retrieves the information embedded in these 16-bits. This ensures that all program memory locations have a valid instruction. 5: If the table write starts the write cycle to internal program memory, the write continues until terminated. 1, 2 1, 2 3, 4 3, 4 1, 2 DS39532A-page Microchip Technology Inc.

7 Table 31-1: Mnemonic, Operands CONTROL OPERATIONS BC BN BNC BNN BNOV BNZ BOV BRA BZ CALL CLRWDT DAW GOTO NOP NOP POP PUSH RCALL RESET RETFIE RETLW RETURN SLEEP n n n n n n n n n n, s n n s k s Branch if Carry Branch if Negative Branch if t Carry Branch if t Negative Branch if t Overflow Branch if t Zero Branch if Overflow Branch Unconditionally Branch if Zero Call subroutine 1st word 2nd word Clear Watchdog Timer Decimal Adjust WREG Go to address 1st word 2nd word Operation Operation Pop top of return stack (TOS) Push top of return stack (TOS) Relative Call Software device RESET Return from interrupt enable Section 31. Instruction Set PIC18CXXX Instruction Set Summary (Continued) Description Return with literal in WREG Return from Subroutine Go into standby mode 1(2) 1(2) 1(2) 1(2) 1(2) 1(2) 1(2) 2 1(2) Cycles 16-Bit Instruction Word nnn s kkkk kkkk 0000 xxxx nnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk kkkk kkkk 0000 xxxx nnnn kkkk nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk kkkk kkkk 0000 xxxx nnnn s kkkk 001s 0011 ne ne ne ne ne ne ne ne ne ne Status Affected TO, PD C ne ne ne ne ne ne All GIE/GIEH, PEIE/GIEL ne ne TO, PD 4 tes te 1: When a PORT Register is modified as a function of itself (e.g., MOVF PORTB, 1, 0), the value used will be that value present on the pins themselves. For example, if the latch is '1' for a pin configured as input and is driven low by an external device, the will be written back with a '0'. 2: If this instruction is executed on the TMR0 Register (and, where applicable, d = 1), the prescaler will be cleared if assigned. 3: If Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is executed as a NOP. 4: Some instructions are 2 word instructions. The second word of these instructions will be executed as a NOP, unless the first word of the instruction retrieves the information embedded in these 16-bits. This ensures that all program memory locations have a valid instruction. 5: If the table write starts the write cycle to internal program memory, the write continues until terminated. MSb LSb 31 Instruction Set 2000 Microchip Technology Inc. DS39532A-page 31-7

8 PIC18C Reference Manual Table 31-1: PIC18CXXX Instruction Set Summary (Continued) Mnemonic, Operands LITERAL OPERATIONS ADDLW ANDLW IORLW LFSR MOVLB MOVLW MULLW RETLW SUBLW XORLW k k k f, k k k k k k k Add literal and WREG AND literal with WREG Inclusive OR literal with WREG Move literal (12-bit) 1st word to FSRx 2nd word Move literal to BSR<3:0> Move literal to WREG Multiply literal with WREG Return with literal in WREG Subtract WREG from literal Exclusive OR literal with WREG DATA MEMORY PROGRAM MEMORY OPERATIONS TBLRD* TBLRD*+ TBLRD*- TBLRD+* TBLWT* TBLWT*+ TBLWT*- TBLWT+* Description Table Read Table Read with post-increment Table Read with post-decrement Table Read with pre-increment Table Write Table Write with post-increment Table Write with post-decrement Table Write with pre-increment Cycles (5) 2 (5) 2 (5) 2 (5) 16-Bit Instruction Word kkkk kkkk kkkk 00ff kkkk 0000 kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk C,DC,Z,OV,N Z, N Z, N ne ne ne ne ne C,DC,Z,OV,N Z, N ne ne ne ne ne ne ne ne Status Affected tes te 1: When a PORT Register is modified as a function of itself (e.g., MOVF PORTB, 1, 0), the value used will be that value present on the pins themselves. For example, if the latch is '1' for a pin configured as input and is driven low by an external device, the will be written back with a '0'. 2: If this instruction is executed on the TMR0 Register (and, where applicable, d = 1), the prescaler will be cleared if assigned. 3: If Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is executed as a NOP. 4: Some instructions are 2 word instructions. The second word of these instructions will be executed as a NOP, unless the first word of the instruction retrieves the information embedded in these 16-bits. This ensures that all program memory locations have a valid instruction. 5: If the table write starts the write cycle to internal program memory, the write continues until terminated. MSb LSb DS39532A-page Microchip Technology Inc.

9 31.3 Instruction Formats Section 31. Instruction Set Figure 31-2 shows the three general formats that the instructions can have. As can be seen from the general format of the instructions, the opcode portion of the instruction word varies from 3-bits to 6-bits of information. This is what allows the Enhanced Instruction Set to have 75 instructions. te: Any unused opcode is Reserved. Use of any reserved opcode may cause unexpected. All instruction examples use the following format to represent a hexadecimal number: 0xhh where h signifies a hexadecimal digit. To represent a binary number: b where b is a binary string identifier. Figure 31-2: General Format for Instructions Byte-oriented File Register s OPCODE d a f (FILE #) d=0forresultdestinationtobewregregister d=1forresultdestinationtobefileregister(f) a = 0 to force Access Bank a=1forbsrtoselectbank f = 8-bit File Register address Example Instruction ADDWF MYREG, W, B 31 Instruction Set Byte to Byte move s (2-word) OPCODE f (Source FILE #) f (Destination FILE #) MOVFF MYREG1, MYREG2 f = 12-bit File Register address Bit-oriented File Register s OPCODE b (BIT #) a f (FILE #) BSF MYREG, bit, B b = 3-bit position of bit in File Register (f) a=0toforceaccessbank a=1forbsrtoselectbank f = 8-bit File Register address Literal s OPCODE k (literal) k = 8-bit immediate value MOVLW 0x7F Control s CALL, GOTO, and Branch s OPCODE n<7:0> (literal) n<19:8> (literal) GOTO label n = 20-bit immediate value 2000 Microchip Technology Inc. DS39532A-page 31-9

10 PIC18C Reference Manual Table 31-2: Instruction Description Conventions Field a Description RAM access bit a = 0: RAM location in access bank (BSR Register is ignored) a = 1: RAM bank is specified by BSR Register bbb Bit address within an 8-bit File Register (0 to 7) BSR Bank Select Register. Used to select the current RAM bank. d Destination select bit; d = 0: store result in WREG, d = 1: store result in File Register f. dest Destination either the WREG Register or the specified register file location f 8-bit Register file address (0x00 to 0xFF) fs 12-bit Register file address (0x000 to 0xFFF). This is the source address. fd 12-bit Register file address (0x000 to 0xFFF). This is the destination address. k Literal field, constant or label (may be either an 8-bit, 12-bit or a 20-bit value) label Label name mm The mode of the TBLPTR Register for the Table Read and Table Write instructions Only used with Table Read and Table Write instructions: * Change to Register (such as TBLPTR with Table reads and writes) *+ Post-Increment Register (such as TBLPTR with Table reads and writes) *- Post-Decrement Register (such as TBLPTR with Table reads and writes) +* Pre-Increment Register (such as TBLPTR with Table reads and writes) n The relative address (2 s complement number) for relative branch instructions, or the direct address for Call/Branch and Return instructions PRODH Product of Multiply high byte PRODL Product of Multiply low byte s Fast Call / Return mode select bit. s = 0: do not update into/from Shadow Registers s = 1: certain registers loaded into/from Shadow Registers u Unused or Unchanged WREG Working Register (accumulator) x Don'tcare(0or1) The assembler will generate code with x = 0. It is the recommended form of use for compatibility with all Microchip software tools. TBLPTR 21-bit Table Pointer (points to a Program Memory location) TABLAT 8-bit Table Latch TOS Top of Stack INDF Any one of the indirect addressing registers, such as INDF0, INDF1, or INDF2 FSR Any one of the file select register pairs, such as FSR0H:FSR0L, FSR1H:FSR1L, or FSR2H:FSR2L DS39532A-page Microchip Technology Inc.

11 Table 31-2: Field Section 31. Instruction Set PC Program Counter PCL Program Counter Low Byte PCH Program Counter High Byte PCLATH Program Counter High Byte Latch PCLATU Program Counter Upper Byte Latch GIE Global Interrupt Enable bit WDT Watchdog Timer TO Time-out bit PD Power-down bit C,DC, ALU status bits Carry, Digit Carry, Zero, Overflow, Negative Z,OV,N [ ] Optional ( ) Contents of Assigned to < > Register bit field In the set of italics Instruction Description Conventions (Continued) User defined term (font is courier) Description 31 Instruction Set Table 31-3: Field *FSRn *FSRn++ *FSRn-- *(++FSRn) *(FSRn+W) Indirect Addressing Symbols Description Selects INDFn Register Selects POSTINCn Register Selects POSTDECn Register Selects PREINCn Register Selects PLUSWn Register 2000 Microchip Technology Inc. DS39532A-page 31-11

12 PIC18C Reference Manual 31.4 Special Function Registers as Source/Destination The Section 31. Instruction Set s Orthogonal Instruction Set allows read and write of all File Registers, including Special Function Registers. The user should be aware of some special situations which are explained in the following subsections STATUS Register as Destination Bit Manipulation If an instruction writes to the STATUS Register, the Z, C, DC, OV, and N bits may be set or cleared as a result of the instruction and overwrite the original bits. For example, executing CLRF STATUS will clear Register STATUS, and then set the Z bit leaving b in the register. All bit manipulation instructions will first read the entire register, operate on the selected bit and then write the result back to (read-modify-write (R-M-W)) the specified register. The user should keep this in mind when operating on some Special Function Registers, such as the Port Pin Register. te: PCL as Source or Destination Status bits that are manipulated by the device (including the interrupt flag bits) are set or cleared in the Q1 cycle, so there is no issue with executing R-M-W instructions on registers that contain these bits. Read, write or read-modify-write (R-M-W) on PCL may have the following results: Read PCL: PCL destination ; Reading PCL causes the following PCH PCLATH PCU PCLATU Write PCL: 8-bit destination value PCL ; Writing PCL causes the following PCLATH PCH PCLATU PCU Read-Modify-Write: PCL ALU operand ; R-M-W of PCL causes the following PCH PCLATH PCU PCLATU ; PCL is modified 8-bit result PCL ; result is written back to PCL PCLATH PCH PCLATU PCU Where PCH = program counter high byte (not an addressable register), PCLATH = Program counter high holding latch, PCU = program counter upper byte (not an addressable register), PCLATU = Program counter upper holding latch, destination = Register file f. DS39532A-page Microchip Technology Inc.

13 31.5 Fast Register Stack Section 31. Instruction Set At times it is desirable to be able to quickly access and return from a function. This function may be called as a subroutine, or an interrupt routine of the device. To reduce the overhead for accessing/returning from these functions, the architecture has the ability to save three key registers in a one deep Register Stack. These registers are: WREG Register BSR (Bank Select Register) Register STATUS Register The two events that cause these registers to be loaded onto the Fast Register Stack are: Afastcall(CALL K, fast)(where the fast bit is set ( 1 )) Any interrupt occurs These Fast Stack Registers are not accessible for reading or writing. When doing the return from these subroutine, the values can be restored into their registers executing the fast return: RETFIE fast (where the fast bit is set ( 1 )) RETURN fast (where the fast bit is set ( 1 )) When s (fast) = 0, the Fast Register Stack is not used, when s (fast) = 1, the Fast Register Stack is used Q Cycle Activity Each instruction cycle (Tcy) is comprised of four Q clocks (also called Q cycles). These are referred to as Q1, Q2, Q3, or Q4. The Q cycles provide the timing/designation for the Decode, Read, Data, Write etc., of each instruction cycle. The Figure 31-3 shows the relationship of the Q cycles to the instruction cycle. The four Q cycles that make up an instruction cycle (Tcy) can be generalized as: Q1: Instruction Decode Cycle or forced Operation Q2: Instruction Read Cycle or Operation Q3: the Data Q4: Instruction Write Cycle or Operation Some actions occur on the edge between the end of one Q cycle and the start of the next Q cycle. An example would be a Q2-Q3 action. This action occurs on the clock edge between the end of Q2 cycle and the beginning of the Q3 cycle. The clock source for the Q cycle is normally the device oscillator clock (TOSC). But the clock source is software selectable. So the Q cycle may be independent of the device oscillator cycle (TOSC). In the full description of each instruction, the detailed Q cycle for the instruction will be shown. Figure 31-3: Q Cycle Activity 31 Instruction Set TOSC Tcy1 Tcy2 Tcy Microchip Technology Inc. DS39532A-page 31-13

14 PIC18C Reference Manual 31.7 Instruction Descriptions ADDLW Add Literal to WREG Syntax: [ label ] ADDLW k Operands: 0 k 255 Operation: (WREG) + k WREG Status Affected: C, DC, Z, OV, N Encoding: kkkk kkkk Description: The eight bit literal k is added to the contents of the WREG and the result is placed in the WREG. Words: 1 Cycles: 1 Q Cycle Activity: Decode Read literal 'k' Write to WREG Register Example1 ADDLW 0x19 ; Add 19h to value in WREG WREG = 0x18 C,DC,Z,OV,N =x WREG = 0x31 C = 0 DC = 1 OV = 0 N = 0 Example 2 ADDLW MYREG ; Add the value of the ; address for MYREG Register ; to WREG WREG = 0x60 Address of MYREG =0x37 MYREG is a symbol for a memory location C, DC, Z, OV, N = x WREG = 0x97 C = 0 DC = 0 OV = 1 N = 1 DS39532A-page Microchip Technology Inc.

15 Section 31. Instruction Set 31 Example 3 ADDLW HIGH (LU_TABLE) ; Add high byte of address ; LU_TABLE to WREG WREG = 0x10 Address of LU_TABLE = 0x9375 LU_TABLE is a label for an address in program memory C, DC, Z, OV, N = x WREG = 0xA3 C = 0 DC = 0 OV = 0 N = 1 Instruction Set Example 4 ADDLW PCL ; Add value of the address ; of Program Counter Low ; byte (PCL) to WREG WREG = 0x02 Address of PCL = 0xFF8 (only low 8-bits are used) PCL is the symbol for the Program Counter low byte location C, DC, Z, OV, N = x WREG = 0xFA C = 0 DC = 0 OV = 0 N = 0 Example 5 ADDLW Offset ; Add the value of symbol ; Offset to WREG WREG = 0x10 Offset = 0x02 C, DC, Z, OV, N = x WREG = 0x12 Offset = 0x02 C = 0 DC = 0 OV = 0 N = Microchip Technology Inc. DS39532A-page 31-15

16 PIC18C Reference Manual ADDWF Add WREG and f Syntax: [ label ]ADDWF f,d,a Operands: 0 f 255 d [0,1] a [0,1] Operation: (WREG) + (f) destination Status Affected: C, DC, Z, OV, N Encoding: da Description: Add the contents of the WREG Register to the contents of Register 'f'. The d bit selects the destination for the. If 'd' is 1; the result is stored back in the File Register 'f'. If 'd' is 0; the result is stored in the WREG Register. The a bit selects which bank is accessed for the. If a is 1; the bank specified by the BSR Register is used. If a is 0; the access bank is used. Words: 1 Cycles: 1 Q Cycle Activity: Decode Read Register 'f' Write to destination Example 1 ADDWF FSR0L, 1, 1 ; Add value in WREG to ; value in the ; FSR0H:FSR0L Register Case 1: WREG = 0x17 FSR0H:FSR0L = 0x2C2 C,DC,Z,OV,N = x WREG = 0x17 FSR0H:FSR0L = 0x2D9 C = 0 DC = 0 OV = 0 N = 1 Case 2: WREG = 0x17 FSR0H:FSR0L = 0x2FF C,DC,Z,OV,N = x WREG = 0x17 FSR0H:FSR0L = 0x316 C = 0 DC = 0 OV = 0 N = 0 DS39532A-page Microchip Technology Inc.

17 Section 31. Instruction Set 31 Example 2 ADDWF INDF0, 1, 1 ; Add value in WREG to ; value in the register ; pointed to (addressed) ; by the FSR0H:FSR0L ; Register WREG = 0x17 FSR0H:FSR0L = 0x6C2 Contents of Address (FSR0) = 0x20 C,DC,Z,OV,N = x WREG = 0x17 FSR0H:FSR0L = 0x6C2 Contents of Address (FSR0) = 0x37 C = 0 DC = 0 OV = 0 N = 0 Instruction Set Example 3 ADDWF INDF0, 1, 0 ; Add value in WREG to ; value in the register ; pointed to (addressed) ; by the FSR0H:FSR0L ; Register WREG = 0x17 FSR0H:FSR0L = 0x0C2 Contents of Address (FSR0) = 0x20 C,DC,Z,OV,N = x WREG = 0x17 FSR0H:FSR0L = 0x0C2 Contents of Address (FSR0) = 0x37 C = 0 DC = 0 OV = 0 N = Microchip Technology Inc. DS39532A-page 31-17

18 PIC18C Reference Manual Example 4 ADDWF PCL, 1, 1 ; Add the value in WREG to ; the current value in the ; low byte of the program ; counter (PCL) Case 1: WREG = 0x10 PCL = 0x37 C,DC,Z,OV,N = x WREG = 0x10 PCL = 0x47 C = 0 DC = 0 OV = 0 N = 0 Case 2: WREG = 0x10 PCL = 0xF7 PCH = 0x08 C,DC,Z,OV,N = x WREG = 0x10 PCL = 0x07 PCH = 0x08 C = 1 DC = 0 OV = 0 N = 0 DS39532A-page Microchip Technology Inc.

19 Section 31. Instruction Set 31 Example 5 ADDWF MYREG, 1 ; Add the value in WREG to ; the current value in ; MYREG ; (assembler determines ; that MYREG requires ; access bit to be set) Case 1: BSR = 0x01 WREG = 0x10 MYREG = 0x37 ; In Bank 1 C,DC,Z,OV,N = x BSR = 0x01 WREG = 0x10 MYREG = 0x47 ; In Bank 1 C = 0 DC = 0 OV = 0 N = 0 Case 2: BSR = 0x01 WREG = 0x10 MYREG = 0xF7 C,DC,Z,OV,N = x BSR = 0x01 WREG = 0x10 MYREG = 0x07 C = 1 DC = 0 OV = 0 N = 0 ; In Bank 1 ; In Bank 1 Instruction Set 2000 Microchip Technology Inc. DS39532A-page 31-19

20 PIC18C Reference Manual ADDWFC Add WREG and Carry bit to f Syntax: [ label ]ADDWF f,d,a Operands: 0 f 255 d [0,1] a [0,1] Operation: (WREG) + (f) + (C) destination Status Affected: C, DC, Z, OV, N Encoding: da Description: Add the contents of the WREG Register and the Carry bit to the contents of Register 'f'. The d bit selects the destination for the. If 'd' is 1; the result is stored back in the File Register 'f'. If 'd' is 0; the result is stored in the WREG Register. The a bit selects which bank is accessed for the. If a is 1; the bank specified by the BSR Register is used. If a is 0; the access bank is used. Words: 1 Cycles: 1 Q Cycle Activity: Decode Read Register 'f' Write to destination Example 1 ADDWFC FSR0L, 0, 1 ; Add WREG, C bit, and FSR0L ; value (Destination WREG) Case 1: WREG = 0x17 FSR0H:FSR0L = 0x9C2 C = 0 DC,Z,OV,N = x WREG = 0xD9 FSR0H:FSR0L = 0x9C2 C = 0 DC = 0 OV = 0 N = 1 Case 2: WREG = 0x17 FSR0H:FSR0L = 0x7C2 C = 1 DC,Z,OV,N = x WREG = 0xDA FSR0H:FSR0L = 0x7C2 C = 0 DC = 0 OV = 0 N = 1 DS39532A-page Microchip Technology Inc.

21 Section 31. Instruction Set 31 Example 2 ADDWFC INDF0, 1, 1 ; Add WREG and the Carry ; bit to the value pointed ; to by the FSR0H:FSR0L ; (Destination: File ; Register) WREG = 0x17 FSR0H:FSR0L = 0x0C2 Contents of Address (FSR0H:FSR0L) = 0x20 C = 0 DC, Z, OV, N = x WREG = 0x17 FSR0H:FSR0L = 0x0C2 Contents of Address (FSR0H:FSR0L) = 0x37 C = 0 DC = 0 OV = 0 N = 0 Instruction Set Example 3 ADDWFC PCL, 1, 1 ; Add WREG and the Carry ; bit to the PCL Register Case 1: WREG = 0x10 PCL = 0x38 C = 0 DC,Z,OV,N = x WREG = 0x10 PCL = 0x48 C = 0 DC = 0 OV = 0 N = 0 Case 2: WREG = 0x10 PCL = 0xF8 PCH = 0x08 C = 0 DC,Z,OV,N = x WREG = 0x10 PCL = 0x08 PCH = 0x08 C = 1 DC = 0 OV = 0 N = Microchip Technology Inc. DS39532A-page 31-21

22 PIC18C Reference Manual ANDLW AND Literal with WREG Syntax: [ label ] ANDLW k Operands: 0 k 255 Operation: (WREG).AND. (k) W Status Affected: Z, N Encoding: kkkk kkkk Description: The contents of WREG Register are AND d with the eight bit literal 'k'. The result is placed in the WREG Register. Words: 1 Cycles: 1 Q Cycle Activity: Decode Read literal 'k' Write to WREG Register Example 1 ANDLW 0x5F ; And constant to WREG WREG = 0xA3 Z, N = x WREG = 0x03 N = 0 ; (0x5F) ; (0xA3) ; ; (0x03) Example 2 ANDLW MYREG ; And address of MYREG ; to WREG WREG = 0xA3 Address of MYREG =0x37 Z, N = x MYREG is a symbol for a memory location WREG = 0x23 N = 0 ; (0x37) ; (0xA3) ; ; (0x23) DS39532A-page Microchip Technology Inc.

23 Section 31. Instruction Set 31 Example 3 ANDLW HIGH (LU_TABLE) WREG = 0xA3 Address of LU_TABLE = 0x9375 Z, N = x LU_TABLE is a label for an address in program memory WREG = 0x83 N = 1 ; And the high byte of ; address LU_TABLE ; with WREG ; (0xA3) ; (0x93) ; ; (0x83) Instruction Set Example 4 ANDLW LOW (LU_TABLE); And the low byte of ; address LU_TABLE ; with WREG WREG = 0xA3 ; (0xA3) Address of LU_TABLE = 0x9375 Z, N = x LU_TABLE is a label for an address in program memory WREG = 0x21 N = 0 ; (0x75) ; ; (0x21) 2000 Microchip Technology Inc. DS39532A-page 31-23

24 PIC18C Reference Manual ANDWF AND WREG with f Syntax: [ label ]ANDWF f,d,a Operands: 0 f 255 d [0,1] a [0,1] Operation: (WREG).AND. (f) destination Status Affected: Z, N Encoding: da Description: The contents of the WREG Register are AND d with the contents of Register 'f'. The d bit selects the destination for the. If 'd' is 1; the result is stored back in the File Register 'f'. If 'd' is 0; the result is stored in the WREG Register. The a bit selects which bank is accessed for the. If a is 1; the bank specified by the BSR Register is used. If a is 0; the access bank is used. Words: 1 Cycles: 1 Q Cycle Activity: Decode Read Register 'f' Write to destination Example 1 ANDWF REG1, 1, 1 ; And WREG with REG1 WREG = 0x17 REG1 = 0xC2 Z, N = x WREG = 0x17 REG1 = 0x02 N = 0 ; (0x17) ; (0xC2) ; ; (0x02) Example 2 ANDWF REG1, 0, 1 ; And WREG with REG1 ; (destination WREG) WREG = 0x17 REG1 = 0xC2 Z, N = x WREG = 0x02 REG1 = 0xC2 N = 0 ; (0x17) ; (0xC2) ; ; (0x02) DS39532A-page Microchip Technology Inc.

25 Section 31. Instruction Set 31 Example 3 ANDWF INDF0, 1, 1 ; And WREG with value pointed ; by FSR0H:FSR0L (FSR0) Case 1: Case 2: WREG = 0x17 FSR0H:FSR0L = 0xFC2 Contents of Address (FSR0) = 0x5A Z, N = x WREG = 0x17 FSR0H:FSR0L = 0xFC2 Contents of Address (FSR0) = 0x12 N = 0 WREG = 0x00 FSR0H:FSR0L = 0x4C2 Contents of Address (FSR0) = 0x5A Z, N = x WREG = 0x00 FSR0H:FSR0L = 0x4C2 Contents of Address (FSR0) = 0x00 Z = 1 N = 0 ; (0x17) ; (0x5A) ; ; (0x12) ; (0x00) ; (0x5A) ; ; (0x00) Instruction Set 2000 Microchip Technology Inc. DS39532A-page 31-25

26 PIC18C Reference Manual BC Branch if Carry Syntax: [ label ] BC n Operands: -128 f 127 Operation: If carry bit is 1 (PC + 2) + 2n PC Status Affected: ne Encoding: nnnn nnnn Description: If the Carry bit is 1, then the program will branch. The 2 s complement number 2n (the offset) is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be (PC+2)+2n. This instruction is then a two-cycle instruction. Words: 1 Cycles: 1 (2) Q Cycle Activity: If Branch Decode Read literal 'n' Write to PC If Branch Decode Read literal 'n' Example 1 Case 1: Case 2: HERE NOT_C C_CODE BC GOTO C_CODE MORE_CODE C = 0 PC = address NOT_C C = 1 PC = address C_CODE ; ; If C bit is not set ; execute this code. ; ; else if C bit is set ; this code will execute DS39532A-page Microchip Technology Inc.

27 Section 31. Instruction Set 31 Example 2 Case 1: Case 2: HERE NO_C PLUS0 PLUS1 PLUS2 PLUS3 PLUS4 PLUS5 PLUS6 BC GOTO $ + OFFSET PROCESS_CODE C = 0 PC = address NO_C C = 1 + OFFSET ; If carry bit is set, ; branch to HERE+OFFSET Instruction Set Example 3 Case 1: Case 2: MIN6 MIN5 MIN4 MIN3 MIN2 MIN1 MIN0 HERE NO_C BC GOTO $ - OFFSET PROCESS_CODE C = 0 PC = address NO_C C = 1 - OFFSET ; If carry bit is set, ; branch to HERE-OFFSET te: Assembler will convert the specified address label into the offset to be used Microchip Technology Inc. DS39532A-page 31-27

28 PIC18C Reference Manual BCF Bit Clear f Syntax: [ label ]BCF f,b,a Operands: 0 f b 7 a [0,1] Operation: 0 f<b> Status Affected: ne Encoding: 1001 bbba Description: Bit 'b' in Register 'f' of the specified bank is cleared. The a bit selects which bank is accessed for the. If a is 1; the bank specified by the BSR Register is used. If a is 0; the access bank is used. Words: 1 Cycles: 1 Q Cycle Activity: Decode Read Register 'f' Write Register 'f' Example 1 BCF MYREG, 7, 1 ; Clear bit 7 in Register ; MYREG MYREG = 0xC7 MYREG = 0x47 ; ; DS39532A-page Microchip Technology Inc.

29 Section 31. Instruction Set 31 Example 2 BCF INDF0, 3, 0 ; Clear bit 7 in the register ; pointed to by the FSR0 ; (FSR0H:FSR0L) Register FSR0 = 0x3C2 Contents of Address (FSR0) = 0x2F ; FSR0 = 0x3C2 Contents of Address (FSR0) = 0x27 ; Instruction Set 2000 Microchip Technology Inc. DS39532A-page 31-29

30 PIC18C Reference Manual BN Branch if Negative Syntax: [ label ] BN n Operands: -128 f 127 Operation: If negative bit is 1 (PC + 2) + 2n PC Status Affected: ne Encoding: nnnn nnnn Description: If the Negative bit is 1, then the program will branch. The 2 s complement number 2n (the offset) is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be (PC+2)+2n. This instruction is then a two-cycle instruction. Words: 1 Cycles: 1 (2) Q Cycle Activity: If Branch Decode Read literal 'n' Write to PC If Branch Decode Read literal 'n' Example 1 Case 1: Case 2: HERE NOT_N N_CODE BN GOTO N_CODE MORE_CODE N = 0 PC = address NOT_N N = 1 PC = address N_CODE ; If N bit is not set ; execute this code. ; ; ; else if N bit is set ; this code will execute DS39532A-page Microchip Technology Inc.

31 Section 31. Instruction Set 31 Example 2 Case 1: Case 2: HERE NOT_N PLUS0 PLUS1 PLUS2 PLUS3 PLUS4 PLUS5 PLUS6 BN GOTO $ + OFFSET PROCESS_CODE N = 0 PC = address NOT_N N = 1 + OFFSET ; If negative bit is set, ; branch to HERE + OFFSET Instruction Set Example 3 Case 1: Case 2: MIN6 MIN5 MIN4 MIN3 MIN2 MIN1 MIN0 HERE NO_N BN GOTO $ - OFFSET PROCESS_CODE N = 0 PC = address NO_N N = 1 - OFFSET ; If negative bit is set, ; branch to HERE - OFFSET te: Assembler will convert the specified address label into the offset to be used Microchip Technology Inc. DS39532A-page 31-31

32 PIC18C Reference Manual BNC Branch if t Carry Syntax: [ label ] BNC n Operands: -128 f 127 Operation: If carry bit is 0 (PC + 2) + 2n PC Status Affected: ne Encoding: nnnn nnnn Description: If the Carry bit is 0, then the program will branch. The 2 s complement number 2n (the offset) is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be (PC+2)+2n. This instruction is then a two-cycle instruction. Words: 1 Cycles: 1 (2) Q Cycle Activity: If Branch Decode Read literal 'n' Write to PC If Branch Decode Read literal 'n' Example 1 Case 1: Case 2: HERE CARRY NC_CODE BNC GOTO NC_CODE MORE_CODE C = 0 PC = address NC_CODE C = 1 PC = address CARRY ; If C bit is set ; execute this code. ; ; ; else if C bit is clear ; this code will execute DS39532A-page Microchip Technology Inc.

33 Section 31. Instruction Set 31 Example 2 Case 1: Case 2: HERE CARRY PLUS0 PLUS1 PLUS2 PLUS3 PLUS4 PLUS5 PLUS6 BNC GOTO $ + OFFSET PROCESS_CODE C = 0 + OFFSET C = 1 PC = address CARRY ; If carry bit is clear, ; branch to HERE + OFFSET Instruction Set Example 3 Case 1: Case 2: MIN6 MIN5 MIN4 MIN3 MIN2 MIN1 MIN0 HERE CARRY BNC GOTO $ - OFFSET PROCESS_CODE C = 0 - OFFSET C = 1 PC = address CARRY ; If carry bit is clear, ; branch to HERE - OFFSET te: Assembler will convert the specified address label into the offset to be used Microchip Technology Inc. DS39532A-page 31-33

34 PIC18C Reference Manual BNN Branch if t Negative Syntax: [ label ] BNN n Operands: -128 f 127 Operation: If negative bit is 0 (PC + 2) + 2n PC Status Affected: ne Encoding: nnnn nnnn Description: If the Negative bit is 0, then the program will branch. The 2 s complement number 2n (the offset) is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be (PC+2)+2n. This instruction is then a two-cycle instruction. Words: 1 Cycles: 1 (2) Q Cycle Activity: If Branch Decode Read literal 'n' Write to PC If Branch Decode Read literal 'n' Example 1 Case 1: Case 2: HERE BNN NEG GOTO POS_CODE POS_CODE MORE_CODE N = 0 PC = address POS_CODE N = 1 PC = address NEG ; If N bit is set ; execute this code. ; ; ; else if N bit is clear ; this code will execute DS39532A-page Microchip Technology Inc.

35 Section 31. Instruction Set 31 Example 2 Case 1: Case 2: HERE NEG PLUS0 PLUS1 PLUS2 PLUS3 PLUS4 PLUS5 PLUS6 BNN GOTO $ + OFFSET PROCESS_CODE N = 0 + OFFSET N = 1 PC = address NEG ; If negative bit is clear, ; branch to HERE + OFFSET Instruction Set Example 3 Case 1: Case 2: MIN6 MIN5 MIN4 MIN3 MIN2 MIN1 MIN0 HERE NEG BNN GOTO $ - OFFSET PROCESS_CODE N = 0 - OFFSET N = 1 PC = address NEG ; If negative bit is clear, ; branch to HERE - OFFSET te: Assembler will convert the specified address label into the offset to be used Microchip Technology Inc. DS39532A-page 31-35

36 PIC18C Reference Manual BNOV Branch if t Overflow Syntax: [ label ] BNOV n Operands: -128 f 127 Operation: If overflow bit is 0 (PC + 2) + 2n PC Status Affected: ne Encoding: nnnn nnnn Description: If the Overflow bit is 0, then the program will branch. The 2 s complement number 2n (the offset) is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be (PC+2)+2n. This instruction is then a two-cycle instruction. Words: 1 Cycles: 1 (2) Q Cycle Activity: If Branch Decode Read literal 'n' Write to PC If Branch Decode Read literal 'n' Example 1 Case 1: Case 2: HERE BNOV OVFL GOTO NOV_CODE NOV_CODE MORE_CODE OV = 0 PC = address NOV_CODE OV = 1 PC = address OVFL ; If overflow bit is set ; execute this code. ; ; ; else if overflow bit is ; clear this code will ; execute DS39532A-page Microchip Technology Inc.

37 Section 31. Instruction Set 31 Example 2 Case 1: Case 2: HERE OVFL PLUS0 PLUS1 PLUS2 PLUS3 PLUS4 PLUS5 PLUS6 BNOV GOTO $ + OFFSET PROCESS_CODE OV = 0 + OFFSET OV = 1 PC = address OVFL ; If overflow bit is clear, ; branch to HERE + OFFSET Instruction Set Example 3 Case 1: Case 2: MIN6 MIN5 MIN4 MIN3 MIN2 MIN1 MIN0 HERE OVFL BNOV GOTO $ - OFFSET PROCESS_CODE OV = 0 - OFFSET OV = 1 PC = address OVFL ; If overflow bit is clear, ; branch to HERE - OFFSET te: Assembler will convert the specified address label into the offset to be used Microchip Technology Inc. DS39532A-page 31-37

38 PIC18C Reference Manual BNZ Branch if t Zero Syntax: [ label ] BNZ n Operands: -128 f 127 Operation: If zero bit is 0 (PC + 2) + 2n PC Status Affected: ne Encoding: nnnn nnnn Description: If the Zero bit is 0, then the program will branch. The 2 s complement number 2n (the offset) is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be (PC+2)+2n. This instruction is then a two-cycle instruction. Words: 1 Cycles: 1 (2) Q Cycle Activity: If Branch Decode Read literal 'n' Write to PC If Branch Decode Read literal 'n' Example 1 Case 1: Case 2: HERE ZERO Z_CODE BNZ GOTO Z_CODE MORE_CODE PC = address Z_CODE Z = 1 PC = address ZERO ; If Z bit is set ; execute this code. ; ; ; else if Z bit is clear ; this code will execute DS39532A-page Microchip Technology Inc.

39 Section 31. Instruction Set 31 Example 2 Case 1: Case 2: HERE ZERO PLUS0 PLUS1 PLUS2 PLUS3 PLUS4 PLUS5 PLUS6 BNZ GOTO $ + OFFSET PROCESS_CODE + OFFSET Z = 1 PC = address ZERO ; If zero bit is clear, ; branch to HERE + OFFSET Instruction Set Example 3 Case 1: Case 2: MIN6 MIN5 MIN4 MIN3 MIN2 MIN1 MIN0 HERE ZERO BNZ GOTO $ - OFFSET PROCESS_CODE - OFFSET Z = 1 PC = address ZERO ; If zero bit is clear, ; branch to HERE - OFFSET te: Assembler will convert the specified address label into the offset to be used Microchip Technology Inc. DS39532A-page 31-39

40 PIC18C Reference Manual BOV Branch if Overflow Syntax: [ label ] BOV n Operands: -128 f 127 Operation: If overflow bit is 1 (PC + 2) + 2n PC Status Affected: ne Encoding: nnnn nnnn Description: If the Overflow bit is 1, then the program will branch. The 2 s complement number 2n (the offset) is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be (PC+2)+2n. This instruction is then a two-cycle instruction. Words: 1 Cycles: 1 (2) Q Cycle Activity: If Branch Decode Read literal 'n' Write to PC If Branch Decode Read literal 'n' Example 1 Case 1: Case 2: HERE OVFL OV_CODE BOV GOTO OV_CODE MORE_CODE OV = 0 PC = address OVFL OV = 1 PC = address OV_CODE ; If OV bit is clear ; execute this code. ; ; ; else if OV bit is set ; this code will execute DS39532A-page Microchip Technology Inc.

41 Section 31. Instruction Set 31 Example 2 Case 1: Case 2: HERE OVFL PLUS0 PLUS1 PLUS2 PLUS3 PLUS4 PLUS5 PLUS6 BOV GOTO $ + OFFSET PROCESS_CODE OV = 0 PC = address OVFL OV = 1 + OFFSET ; If overflow bit is set, ; branch to HERE + OFFSET Instruction Set Example 3 Case 1: Case 2: MIN6 MIN5 MIN4 MIN3 MIN2 MIN1 MIN0 HERE OVFL BOV GOTO $ - OFFSET PROCESS_CODE OV = 0 PC = address OVFL OV = 1 - OFFSET ; If OV bit is set, ; branch to HERE - OFFSET te: Assembler will convert the specified address label into the offset to be used Microchip Technology Inc. DS39532A-page 31-41

42 PIC18C Reference Manual BRA Branch Unconditional Syntax: [ label ] BRA n Operands: f 1023 Operation: (PC + 2) + 2n PC Status Affected: ne Encoding: nnn nnnn nnnn Description: The 2 s complement number 2n (the offset) is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be (PC+2)+2n. This instruction is a two-cycle instruction. Words: 1 Cycles: 2 Q Cycle Activity: If Branch Decode Read literal 'n' Write to PC If Branch Decode Read literal 'n' Example 1 HERE THERE BRA THERE PC = address THERE ; Branch to a program memory ; location (THERE) ; this location must be ; < 1023 locations forward DS39532A-page Microchip Technology Inc.

43 Section 31. Instruction Set 31 Example 2 THERE HERE BRA THERE PC = address THERE ; Branch to a program memory ; location (THERE) ; this location must be ; < 1024 locations backward Instruction Set Example 3 HERE BRA $ ; Branch to program memory ; location (HERE). ; Infinite Loop te: Assembler will convert the specified address label into the offset to be used Microchip Technology Inc. DS39532A-page 31-43

44 PIC18C Reference Manual BSF Bit Set f Syntax: [ label ] BSF f, b, a Operands: 0 f b 7 a [0,1] Operation: 1 f<b> Status Affected: ne Encoding: 1000 bbba Description: Bit 'b' in Register 'f' is set. The a bit selects which bank is accessed for the. If a is 1; the bank specified by the BSR Register is used. If a is 0; the access bank is used. Words: 1 Cycles: 1 Q Cycle Activity: Decode Read Register 'f' Write Register 'f' Example 1 BSF FLAG_REG, 7 ; Set bit 7 in Register ; FLAG_REG ; (assembler determines ; that FLAG_REG requires ; access bit to be set) FLAG_REG = 0x0A ; FLAG_REG = 0x8A ; Example 2 BSF INDF0, 3, 0 ; Set bit 3 in the register ; pointed to by the FSR0 ; (FSR0H:FSR0L) Register WREG = 0x17 FSR0 = 0x0C2 Contents of Address ; (FSR0)= 0x20 WREG = 0x17 FSR0 = 0x0C2 Contents of Address ; (FSR0) = 0x28 DS39532A-page Microchip Technology Inc.

45 Section 31. Instruction Set 31 BTFSC Bit Test File, Skip if Clear Syntax: [ label ]BTFSC f,b,a Operands: 0 f b 7 a [0,1] Operation: Skip if (f<b>) = 0 Status Affected: ne Encoding: 1011 bbba Description: If bit 'b' in Register 'f' is '0' then the next instruction is skipped. If bit 'b' is '0' then the next instruction (fetched during the current instruction execution) is discarded, and a NOP is executed instead, making this a 2-cycle instruction. Instruction Set The a bit selects which bank is accessed for the. If a is 1; the bank specified by the BSR Register is used. If a is 0; the access bank is used. Words: 1 Cycles: 1 (2 or 3) Q Cycle Activity: Decode Read Register 'f' If skip (2nd cycle): Ifskipandfollowedbyatwowordinstruction: Example 1 Case 1: Case 2: HERE FALSE TRUE BTFSC GOTO FLAG, 4, 1 PROCESS_CODE FLAG = xxx0 xxxx Since FLAG<4> = 0 PC = address TRUE FLAG = xxx1 xxxx Since FLAG<4> = 1 PC = address FALSE ; Test bit 4 of Register ; FLAG, and skip if ; clear 2000 Microchip Technology Inc. DS39532A-page 31-45

46 PIC18C Reference Manual BTFSS Bit Test File, Skip if Set Syntax: [ label ]BTFSS f,b,a Operands: 0 f b<7 a [0,1] Operation: Skip if (f<b>) = 1 Status Affected: ne Encoding: 1010 bbba Description: If bit 'b' in Register 'f' is '1' then the next instruction is skipped. If bit 'b' is '1', then the next instruction (fetched during the current instruction execution) is discarded and a NOP is executed instead, making this a 2-cycle instruction. The a bit selects which bank is accessed for the. If a is 1; the bank specified by the BSR Register is used. If a is 0; the access bank is used. Words: 1 Cycles: 1 (2 or 3) Q Cycle Activity: Decode Read Register 'f' If skip (2nd cycle): Ifskipandfollowedbyatwowordinstruction: Example 1 Case 1: Case 2: HERE FALSE TRUE BTFSS GOTO FLAG, 4, 0 PROCESS_CODE FLAG = xxx0 xxxx Since FLAG<4> = 0 PC = address FALSE FLAG = xxx1 xxxx Since FLAG<4> = 1 PC = address TRUE ; Test bit 4 of Register ; FLAG, and skip if set DS39532A-page Microchip Technology Inc.

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS PIC6F87X 3.0 INSTRUCTION SET SUMMARY Each PIC6F87X instruction is a 4bit word, divided into an OPCODE which specifies the instruction type and one or more operands which further specify the operation of

More information

Assembly Language Instructions

Assembly Language Instructions Assembly Language Instructions Content: Assembly language instructions of PIC16F887. Programming by assembly language. Prepared By- Mohammed Abdul kader Assistant Professor, EEE, IIUC Assembly Language

More information

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar Starting to Program Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar Outline Introduction Program Development Process The PIC 16F84A Instruction Set Examples The PIC 16F84A Instruction Encoding Assembler Details

More information

ECE Test #1: Name

ECE Test #1: Name ECE 376 - Test #1: Name Closed Book, Closed Notes. Calculators Permitted. September 23, 2016 20 15 10 5 0

More information

Instuction set

Instuction set Instuction set http://www.piclist.com/images/www/hobby_elec/e_pic3_1.htm#1 In PIC16 series, RISC(Reduced Instruction Set Computer) is adopted and the number of the instructions to use is 35 kinds. When

More information

PIC16F84A 7.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

PIC16F84A 7.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS PI6F84A 7.0 INSTRUTION SET SUMMARY Each PI6XX instruction is a 4bit word, divided into an OPODE which specifies the instruction type and one or more operands which further specify the operation of the

More information

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design Year: IV DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING EE6008 Microcontroller based system design Semester : VII UNIT I Introduction to PIC Microcontroller

More information

Arithmetic,logic Instruction and Programs

Arithmetic,logic Instruction and Programs Arithmetic,logic Instruction and Programs 1 Define the range of numbers possible in PIC unsigned data Code addition and subtraction instructions for unsigned data Perform addition of BCD Code PIC unsigned

More information

Lecture (04) PIC16F84A (3)

Lecture (04) PIC16F84A (3) Lecture (04) PIC16F84A (3) By: Dr. Ahmed ElShafee ١ Central Processing Unit Central processing unit (CPU) is the brain of a microcontroller responsible for finding and fetching the right instruction which

More information

Arithmetic and Logic Instructions. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Arithmetic and Logic Instructions. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan Arithmetic and Logic Instructions Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan chanhl@mail.cgu.edu.tw Find the sum of the values from 40H to 43H. Put the sum in filereg locations

More information

4.5.1) The Label Field ) The Mnemonic Field. 4.5) Assembly Language Program Structure A PIC18 ALP consists of 3 type of statements:

4.5.1) The Label Field ) The Mnemonic Field. 4.5) Assembly Language Program Structure A PIC18 ALP consists of 3 type of statements: 4.5) Assembly Language Program Structure A PIC18 ALP consists of 3 type of statements: 1) Assembler Directives To control the assembler: its input, output, and data allocation. Must be terminated with

More information

EEE111A/B Microprocessors

EEE111A/B Microprocessors EEE111A/B Microprocessors Revision Notes Lecture 1: What s it all About? Covers the basic principles of digital signals. The intelligence of virtually all communications, control and electronic devices

More information

PIC 16F84A programming (II)

PIC 16F84A programming (II) Lecture (05) PIC 16F84A programming (II) Dr. Ahmed M. ElShafee ١ Introduction to 16F84 ٣ PIC16F84 belongs to a class of 8-bit microcontrollers of RISC architecture. Program memory (FLASH) EEPROM RAM PORTA

More information

SOLUTIONS!! DO NOT DISTRIBUTE!!

SOLUTIONS!! DO NOT DISTRIBUTE!! THE UNIVERSITY OF THE WEST INDIES EXAMINATIONS OF FEBRUARY MID-TERM 2005 Code and Name of Course: EE25M Introduction to Microprocessors Paper: Date and Time: Duration: One Hour INSTRUCTIONS TO CANDIDATES:

More information

TOPIC 3 INTRODUCTION TO PIC ASSEMBLY LANGUAGE. E4160 Microprocessor & Microcontroller System. Prepared by : Puziah Yahaya JKE, POLISAS / DEC 2010

TOPIC 3 INTRODUCTION TO PIC ASSEMBLY LANGUAGE. E4160 Microprocessor & Microcontroller System. Prepared by : Puziah Yahaya JKE, POLISAS / DEC 2010 TOPIC 3 INTRODUCTION TO PIC ASSEMBLY LANGUAGE Prepared by : Puziah Yahaya JKE, POLISAS / DEC 2010 E4160 Microprocessor & Microcontroller System Learning Outcomes 2 At the end of this topic, students should

More information

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2006 Recitation 01 21.02.2006 CEng336 1 OUTLINE LAB & Recitation Program PIC Architecture Overview PIC Instruction Set PIC Assembly Code Structure 21.02.2006

More information

Chapter 13. PIC Family Microcontroller

Chapter 13. PIC Family Microcontroller Chapter 13 PIC Family Microcontroller Lesson 15 Instruction Set Most instructions execution Time One instruction cycle If XTAL frequency = 20 MHz, then instruction cycle time is 0.2 s or 200 ns (= 4/20

More information

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002. Semester 2. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J2. Time allowed: 3 Hours

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002. Semester 2. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J2. Time allowed: 3 Hours UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 Semester 2 Year 2 MICROCONTROLLER SYSTEMS Module Code: EEE305J2 Time allowed: 3 Hours Answer as many questions as you can. Not more than TWO questions

More information

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27) Lesson 14 Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27) Name and affiliation of the author: N W K Jayatissa Department of Physics,

More information

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 RESIT. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J1. Time allowed: 3 Hours

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 RESIT. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J1. Time allowed: 3 Hours UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 RESIT Year 2 MICROCONTROLLER SYSTEMS Module Code: EEE305J1 Time allowed: 3 Hours Answer as many questions as you can. Not more than TWO questions

More information

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work LAB WORK 1 We are studying with PIC16F84A Microcontroller. We are responsible for writing assembly codes for the microcontroller. For the code, we are using MPLAB IDE software. After opening the software,

More information

PIC16C63A/65B/73B/74B

PIC16C63A/65B/73B/74B PI663A/65B/73B/74B 4.0 MEMORY ORGANIATION 4. Program Memory Organization The PI663A/65B/73B/74B has a 3bit program counter capable of addressing an 8K x 4 program memory space. All devices covered by this

More information

Architecture. Harvard Architecture. PIC18 Review. Architecture, Instruction Set, and Assembly Language Programming

Architecture. Harvard Architecture. PIC18 Review. Architecture, Instruction Set, and Assembly Language Programming PIC18 Review Architecture, Istructio Set, ad Assembly Laguage Programmig 25 Microchip Techology Icorporated. All Rights Reserved. Slide 1 Architecture The high performace of the PICmicro microcotroller

More information

Mod-5: PIC 18 Introduction 1. Module 5

Mod-5: PIC 18 Introduction 1. Module 5 Mod-5: PIC 18 Introduction 1 Module 5 Contents: Overview of PIC 18, memory organisation, CPU, registers, pipelining, instruction format, addressing modes, instruction set, interrupts, interrupt operation,

More information

The University of Texas at Arlington Lecture 7

The University of Texas at Arlington Lecture 7 The University of Texas at Arlington Lecture 7 CSE 3442/5442 Agenda HW 2 due today Begin Chapter 5 In class assignment. Reading Assignment for Tuesday, Continue Reading Chapter 6. Assignment 3 and 4 due

More information

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan Bank Switching, Table, Macros & Modules Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan chanhl@mail.cgu.edu.twcgu PIC18 memory access up to 2 MB of program memory Inside the

More information

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution 16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution 1. (20 points, 5 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

PIC Discussion. By Eng. Tamar Jomaa

PIC Discussion. By Eng. Tamar Jomaa PIC Discussion By Eng. Tamar Jomaa Chapter#2 Programming Microcontroller Using Assembly Language Quiz#1 : Time: 10 minutes Marks: 10 Fill in spaces: 1) PIC is abbreviation for 2) Microcontroller with..architecture

More information

16.317: Microprocessor-Based Systems I Spring 2012

16.317: Microprocessor-Based Systems I Spring 2012 16.317: Microprocessor-Based Systems I Spring 2012 Exam 3 Solution 1. (20 points, 5 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

16.317: Microprocessor-Based Systems I Summer 2012

16.317: Microprocessor-Based Systems I Summer 2012 16.317: Microprocessor-Based Systems I Summer 2012 Exam 3 Solution 1. (20 points, 5 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

CHAPTER 0: INTRODUCTION TO COMPUTING SECTION 0.1: NUMBERING AND CODING SYSTEMS 1. (a) 1210 = 11002 (b) 12310 = 0111 10112 (c) 6310 = 0011 11112 (d) 12810 = 1000 00002 (e) 100010 = 0011 1110 10002 2. (a)

More information

MPASM and MPLINK PICmicro QUICK REFERENCE GUIDE

MPASM and MPLINK PICmicro QUICK REFERENCE GUIDE MPASM and MPLINK PICmicro QUICK REFERENCE GUIDE The Embedded Control Solutions Company MPASM Quick Reference Guide This Quick Reference Guide gives all the instructions, directives, and command line options

More information

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester Embedded Systems PIC16F84A Sample Programs Eng. Anis Nazer First Semester 2017-2018 Development cycle (1) Write code (2) Assemble / compile (3) Simulate (4) Download to MCU (5) Test Inputs / Outputs PIC16F84A

More information

Fortune. Semiconductor Corporation 富晶半導體股份有限公司. 8-bit MCU with 1k program ROM, 64-byte RAM, 1 R2F module and 3 13 LCD driver. TD Rev. 1.

Fortune. Semiconductor Corporation 富晶半導體股份有限公司. 8-bit MCU with 1k program ROM, 64-byte RAM, 1 R2F module and 3 13 LCD driver. TD Rev. 1. Fortune 1 R2F module and 3 13 LCD driver. Data Sheet TD-0410001 Rev. 1.2 This manual contains new product information. Fortune reserves the rights to modify the product specification without further notice.

More information

PTK8756B 8 Bit Micro-controller Data Sheet

PTK8756B 8 Bit Micro-controller Data Sheet PTK8756B 8 Bit Micro-controller DEC 15, 2008 Ver1.1 普泰半導體股份有限公司 PORTEK Technology Corporation 公司地址 : 臺北縣新店市寶橋路 235 巷 120 號 4 樓 聯絡電話 : 886-2-89121055 傳真號碼 : 886-2-89121473 公司網址 : www.portek.com.tw Page1

More information

Week1. EEE305 Microcontroller Key Points

Week1. EEE305 Microcontroller Key Points Week1 Harvard Architecture Fig. 3.2 Separate Program store and Data (File) stores with separate Data and Address buses. Program store Has a 14-bit Data bus and 13-bit Address bus. Thus up to 2 13 (8K)

More information

Chapter 5 Sections 1 6 Dr. Iyad Jafar

Chapter 5 Sections 1 6 Dr. Iyad Jafar Building Assembler Programs Chapter 5 Sections 1 6 Dr. Iyad Jafar Outline Building Structured Programs Conditional Branching Subroutines Generating Time Delays Dealing with Data Example Programs 2 Building

More information

Section 4. Architecture

Section 4. Architecture M Section 4. Architecture HIGHLIGHTS This section of the manual contains the following major topics: 4. Introduction...4-2 4.2 Clocking Scheme/Instruction Cycle...4-5 4.3 Instruction Flow/Pipelining...4-6

More information

Micro II and Embedded Systems

Micro II and Embedded Systems 16.480/552 Micro II and Embedded Systems Introduction to PIC Microcontroller Revised based on slides from WPI ECE2801 Moving Towards Embedded Hardware Typical components of a PC: x86 family microprocessor

More information

Section 11. Timer0. Timer0 HIGHLIGHTS. This section of the manual contains the following major topics:

Section 11. Timer0. Timer0 HIGHLIGHTS. This section of the manual contains the following major topics: M 11 Section 11. HIGHLIGHTS This section of the manual contains the following major topics: 11.1 Introduction...11-2 11.2 Control Register...11-3 11.3 Operation...11-4 11.4 TMR0 Interrupt...11-5 11.5 Using

More information

Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code.

Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code. Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code. 1S. Prior to execution of the following code segment,

More information

TM57PA20/ TM57PA40. 8 Bit Microcontroller. User Manual. Tenx reserves the right to change or discontinue this product without notice.

TM57PA20/ TM57PA40. 8 Bit Microcontroller. User Manual. Tenx reserves the right to change or discontinue this product without notice. Advance Information TM57PA20/ TM57PA40 User Manual Tenx reserves the right to change or discontinue this product without notice. tenx technology inc. tenx technology, inc. CONTENTS FEATURES... 3 BLOCK

More information

Hitchhiker s Guide to FlashForth on PIC18 Microcontrollers

Hitchhiker s Guide to FlashForth on PIC18 Microcontrollers Hitchhiker s Guide to FlashForth on PIC18 Microcontrollers Interpreter The outer interpreter looks for words and numbers delimited by whitespace. Everything is interpreted as a word or a number. Numbers

More information

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 5 Solution

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 5 Solution For each of the following complex operations, write a sequence of PIC 16F1829 instructions that performs an equivalent operation. Assume that X, Y, and Z are 16-bit values split into individual bytes as

More information

DERTS Design Requirements (1): Microcontroller Architecture & Programming

DERTS Design Requirements (1): Microcontroller Architecture & Programming Lecture (5) DERTS Design Requirements (1): Microcontroller Architecture & Programming Prof. Kasim M. Al-Aubidy Philadelphia University 1 Lecture Outline: Features of microcomputers and microcontrollers.

More information

NH-67, TRICHY MAIN ROAD, PULIYUR, C.F , KARUR DT. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING COURSE MATERIAL

NH-67, TRICHY MAIN ROAD, PULIYUR, C.F , KARUR DT. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING COURSE MATERIAL NH-67, TRICHY MAIN ROAD, PULIYUR, C.F. 639 114, KARUR DT. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING COURSE MATERIAL Subject Name : Embedded System Class/Sem : BE (ECE) / VII Subject Code

More information

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory 0907334 6 Experiment 6:Timers Objectives To become familiar with hardware timing

More information

Chapter 3 BRANCH, CALL, AND TIME DELAY LOOP

Chapter 3 BRANCH, CALL, AND TIME DELAY LOOP Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 3022: Embedded Systems Discussion Chapter 3 BRANCH, CALL, AND TIME DELAY LOOP Eng. Eman R. Habib February, 2014 2 Embedded

More information

PIC16C84. 8-bit CMOS EEPROM Microcontroller PIC16C84. Pin Diagram. High Performance RISC CPU Features: CMOS Technology: Peripheral Features:

PIC16C84. 8-bit CMOS EEPROM Microcontroller PIC16C84. Pin Diagram. High Performance RISC CPU Features: CMOS Technology: Peripheral Features: 8-bit CMOS EEPROM Microcontroller High Performance RISC CPU Features: Only 35 single word instructions to learn All instructions single cycle (400 ns @ 10 MHz) except for program branches which are two-cycle

More information

Section 13. Timer0 HIGHLIGHTS. Timer0. This section of the manual contains the following major topics:

Section 13. Timer0 HIGHLIGHTS. Timer0. This section of the manual contains the following major topics: Section 13. Timer0 HIGHLIGHTS This section of the manual contains the following major topics: 13.1 Introduction... 13-2 13.2 Control Register... 13-3 13.3 Operation... 13-4 13.4 Timer0 Interrupt... 13-5

More information

Introduction to the PIC18 Microcontroller 1.1 Objectives

Introduction to the PIC18 Microcontroller 1.1 Objectives 1 Introduction to the PIC18 Microcontroller 1.1 Objectives After completing this chapter, you should be able to: Define or explain the following terms: computer, processor, microprocessor, microcontroller,

More information

Embedded System Design

Embedded System Design ĐẠI HỌC QUỐC GIA TP.HỒ CHÍ MINH TRƯỜNG ĐẠI HỌC BÁCH KHOA KHOA ĐIỆN-ĐIỆN TỬ BỘ MÔN KỸ THUẬT ĐIỆN TỬ Embedded System Design : Microcontroller 1. Introduction to PIC microcontroller 2. PIC16F84 3. PIC16F877

More information

16.317: Microprocessor Systems Design I Fall 2015

16.317: Microprocessor Systems Design I Fall 2015 16.317: Microprocessor Systems Design I Fall 2015 Exam 2 Solution 1. (16 points, 4 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

PIC Architecture & Assembly Language Programming. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

PIC Architecture & Assembly Language Programming. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan PIC Architecture & Assembly Language Programming Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan chanhl@mail.cgu.edu.tw ALU with working register (WREG) and literal value 2 MOVLW

More information

Microcontroller. Instruction set of 8051

Microcontroller. Instruction set of 8051 UNIT 2: Addressing Modes and Operations: Introduction, Addressing modes, External data Moves, Code Memory, Read Only Data Moves / Indexed Addressing mode, PUSH and POP Opcodes, Data exchanges, Example

More information

Directives & Memory Spaces. Dr. Farid Farahmand Updated: 2/18/2019

Directives & Memory Spaces. Dr. Farid Farahmand Updated: 2/18/2019 Directives & Memory Spaces Dr. Farid Farahmand Updated: 2/18/2019 Memory Types Program Memory Data Memory Stack Interna PIC18 Architecture Data Memory I/O Ports 8 wires 31 x 21 Stack Memory Timers 21 wires

More information

More (up a level)... Connecting the Nokia 3510i LCD to a Microchip PIC16F84 microcontroller

More (up a level)... Connecting the Nokia 3510i LCD to a Microchip PIC16F84 microcontroller 1 von 8 24.02.2010 21:53 More (up a level)... Connecting the Nokia 3510i LCD to a Microchip PIC16F84 microcontroller As with the FPGA board previously, the connections are made by soldering standard IDC

More information

PIN DESCRIPTION Name I/O Description VDD P VSS P 5V Power from USB cable Ground RC6M O X1 I Test/OTP mode clock in Internal clock output (6MHz) VPP I

PIN DESCRIPTION Name I/O Description VDD P VSS P 5V Power from USB cable Ground RC6M O X1 I Test/OTP mode clock in Internal clock output (6MHz) VPP I GENERAL DESCRIPTION The IN6005 is an 8-bit microprocessor embedded device tailored to the USB genernal purpose application. It includes an 8-bit RISC CPU core, 192-byte SRAM, Low Speed USB Interface and

More information

ALU and Arithmetic Operations

ALU and Arithmetic Operations EE25M Introduction to microprocessors original author: Feisal Mohammed updated: 6th February 2002 CLR Part IV ALU and Arithmetic Operations There are several issues connected with the use of arithmetic

More information

A Better Mouse Trap. Consumer Appliance, Widget, Gadget APPLICATION OPERATION: Ontario, Canada

A Better Mouse Trap. Consumer Appliance, Widget, Gadget APPLICATION OPERATION: Ontario, Canada A Better Mouse Trap Author: APPLICATION OPERATION: My application uses a PIC12C508 to produce realistic sounding mouse-like coos that all mice are sure to find seductive. The entire circuit should be imbedded

More information

Chapter 3: Further Microcontrollers

Chapter 3: Further Microcontrollers Chapter 3: Further Microcontrollers Learning Objectives: At the end of this topic you will be able to: recall and describe the structure of microcontrollers as programmable assemblies of: memory; input

More information

/ 40 Q3: Writing PIC / 40 assembly language TOTAL SCORE / 100 EXTRA CREDIT / 10

/ 40 Q3: Writing PIC / 40 assembly language TOTAL SCORE / 100 EXTRA CREDIT / 10 16.317: Microprocessor-Based Systems I Summer 2012 Exam 3 August 13, 2012 Name: ID #: Section: For this exam, you may use a calculator and one 8.5 x 11 double-sided page of notes. All other electronic

More information

movwf prevcod ; a new button is pressed - rcnt=3 movwf (mtx_buffer+1) movlw 3 movwf rcnt

movwf prevcod ; a new button is pressed - rcnt=3 movwf (mtx_buffer+1) movlw 3 movwf rcnt movlw 0x20 #endif call scan movlw 0xfd tris PORTB ; select colb (RB1) #ifdef MODE_CH8 movlw 0x04 #endif #ifdef MODE_CH4 movlw 0x30 #endif call scan movf cod, W bz loop2 ; if no buton is pressed, skip subwf

More information

16.317: Microprocessor Systems Design I Spring 2015

16.317: Microprocessor Systems Design I Spring 2015 16.317: Microprocessor Systems Design I Spring 2015 Exam 2 Solution 1. (16 points, 4 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by

More information

ABOV SEMICONDUCTOR 8-BIT SINGLE-CHIP MICROCONTROLLERS MC71PD506. USER S MANUAL (Ver. 1.0)

ABOV SEMICONDUCTOR 8-BIT SINGLE-CHIP MICROCONTROLLERS MC71PD506. USER S MANUAL (Ver. 1.0) ABOV SEMICONDUCTOR 8-BIT SINGLE-CHIP MICROCONTROLLERS MC71PD506 USER S MANUAL (Ver. 1.0) TABLE OF CONTENTS 1. PRODUCT OVERVIEW... 1 2. MEMORY ORGANIZATION... 12 3. INTERRUPT... 26 4. INSTRUCTIONS SET...

More information

Chapter 6. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code.

Chapter 6. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code. Chapter 6. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code. 1S. Write an assembly code equivalent for the following

More information

AN587. Interfacing to an LCD Module. Interfacing to an LCD Module INTRODUCTION OPERATION CONTROL SIGNAL FUNCTIONS TABLE 2: CONDITIONAL ASSEMBLY FLAGS

AN587. Interfacing to an LCD Module. Interfacing to an LCD Module INTRODUCTION OPERATION CONTROL SIGNAL FUNCTIONS TABLE 2: CONDITIONAL ASSEMBLY FLAGS Interfacing to an LCD Module AN587 INTRODUCTION TABLE 1: CONTROL SIGNAL FUNCTIONS This application note interfaces a PIC16CXX device to the Hitachi LM02L LCD character display module. This module is a

More information

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan Interrupts and Resets Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan chanhl@mail.cgu.edu.twcgu Interrupts An event that will cause the CPU to stop the normal program execution

More information

/ 28 HLL assembly Q4: Conditional instructions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

/ 28 HLL assembly Q4: Conditional instructions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10 16.317: Microprocessor Systems Design I Fall 2014 Exam 2 November 5, 2014 Name: ID #: For this exam, you may use a calculator and one 8.5 x 11 double-sided page of notes. All other electronic devices (e.g.,

More information

Embedded Systems Design (630470) Lecture 4. Memory Organization. Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

Embedded Systems Design (630470) Lecture 4. Memory Organization. Prof. Kasim M. Al-Aubidy Computer Eng. Dept. Embedded Systems Design (630470) Lecture 4 Memory Organization Prof. Kasim M. Al-Aubidy Computer Eng. Dept. Memory Organization: PIC16F84 has two separate memory blocks, for data and for program. EEPROM

More information

DR bit RISC Microcontroller. Instructions set details ver 3.10

DR bit RISC Microcontroller. Instructions set details ver 3.10 DR80390 8-bit RISC Microcontroller Instructions set details ver 3.10 DR80390 Instructions set details - 2 - Contents 1. Overview 7 1.1. Document structure. 7 2. Instructions set brief 7 2.1. Instruction

More information

These 3 registers contain enable, priority,

These 3 registers contain enable, priority, 8.3.2) Registers Related to Interrupts These registers enable/disable the interrupts, set the priority of the interrupts, and record the status of each interrupt source. RCON INTCON, INTCON2, and INTCON3

More information

M PIC16F84A. 18-pinEnhanced FLASH/EEPROM 8-Bit Microcontroller. High Performance RISC CPU Features: Pin Diagrams. Peripheral Features:

M PIC16F84A. 18-pinEnhanced FLASH/EEPROM 8-Bit Microcontroller. High Performance RISC CPU Features: Pin Diagrams. Peripheral Features: M PIC6F84A 8-pinEnhanced FLASH/EEPROM 8-Bit Microcontroller High Performance RISC CPU Features: Pin Diagrams Only 35 single word instructions to learn All instructions single-cycle except for program branches

More information

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!! THE UNIVERSITY OF THE WEST INDIES EXAMINATIONS OF APRIL MID-TERM 2005 Code and Name of Course: EE25M Introduction to Microprocessors Paper: MidTerm Date and Time: Thursday April 14th 2005 8AM Duration:

More information

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

EE6008-Microcontroller Based System Design Department Of EEE/ DCE UNIT- II INTERRUPTS AND TIMERS PART A 1. What are the interrupts available in PIC? (Jan 14) Interrupt Source Enabled by Completion Status External interrupt from INT INTE = 1 INTF = 1 TMR0 interrupt T0IE

More information

PIC16F8X. 8-Bit CMOS Flash/EEPROM Microcontrollers PIC16F8X PIC16CR8X. Pin Diagram. Devices Included in this Data Sheet:

PIC16F8X. 8-Bit CMOS Flash/EEPROM Microcontrollers PIC16F8X PIC16CR8X. Pin Diagram. Devices Included in this Data Sheet: This document was created with FrameMaker 404 PIC16F8X 8-Bit CMOS Flash/EEPROM Microcontrollers Devices Included in this Data Sheet: PIC16F83 PIC16CR83 PIC16F84 PIC16CR84 Extended voltage range devices

More information

PIC10F200/202/204/206 Data Sheet

PIC10F200/202/204/206 Data Sheet Data Sheet 6-Pin, 8-Bit Flash Microcontrollers DS4239A 6-Pin, 8-Bit Flash Microcontrollers Devices Included In ThisData Sheet: PIC0F200 PIC0F202 PIC0F204 PIC0F206 High-Performance RISC CPU: Only 33 single-word

More information

Microcontroller systems Lec 2 PIC18LF8722 Microcontroller s s core

Microcontroller systems Lec 2 PIC18LF8722 Microcontroller s s core TKT-3500 Microcontroller systems Lec 2 PIC18LF8722 Microcontroller s s core Erno Salminen Copyright notice Some figures by Robert Reese, from supplementary CD of the course book from PIC18F8722 Family

More information

PIC16F8X 18-pin Flash/EEPROM 8-Bit Microcontrollers

PIC16F8X 18-pin Flash/EEPROM 8-Bit Microcontrollers 18-pin Flash/EEPROM 8-Bit Microcontrollers Devices Included in this Data Sheet: PIC16F83 PIC16F84 PIC16CR83 PIC16CR84 Extended voltage range devices available (PIC16LF8X, PIC16LCR8X) High Performance RISC

More information

Contents 8051 Instruction Set BY D. BALAKRISHNA, Research Assistant, IIIT-H Chapter I : Control Transfer Instructions Lesson (a): Loop Lesson (b): Jump (i) Conditional Lesson (c): Lesson (d): Lesson (e):

More information

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University PIC ming in C and Assembly Outlines Microprocessor vs. MicroController PIC in depth PIC ming Assembly ming Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University Embedded C

More information

TKT-3500 Microcontroller systems

TKT-3500 Microcontroller systems TKT-3500 Microcontroller systems Lec 2 PIC18LF8722 Microcontroller s core Teemu Laukkarinen Department of Computer Systems Tampere University of Technology Fall 2011 Copyright Tampere University of Technology

More information

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed EE25M Introduction to microprocessors original author: Feisal Mohammed updated: 18th February 2002 CLR Part V Hardware Interfacing There are several features of computers/microcontrollers which have not

More information

8051 Overview and Instruction Set

8051 Overview and Instruction Set 8051 Overview and Instruction Set Curtis A. Nelson Engr 355 1 Microprocessors vs. Microcontrollers Microprocessors are single-chip CPUs used in microcomputers Microcontrollers and microprocessors are different

More information

S w e d i s h c r. w e e b l y. c o m j a l i l a h m e l i v e. c o m Page 1

S w e d i s h c r. w e e b l y. c o m j a l i l a h m e l i v e. c o m Page 1 ********************************************************************** This file is a basic code template for assembly code generation * on the PICmicro PIC12C508. This file contains the basic code * building

More information

Microcontroller Intel [Instruction Set]

Microcontroller Intel [Instruction Set] Microcontroller Intel 8051 [Instruction Set] Structure of Assembly Language [ label: ] mnemonic [operands] [ ;comment ] Example: MOV R1, #25H ; load data 25H into R1 2 8051 Assembly Language Registers

More information

Outline. Micriprocessor vs Microcontroller Introduction to PIC MCU PIC16F877 Hardware:

Outline. Micriprocessor vs Microcontroller Introduction to PIC MCU PIC16F877 Hardware: HCMIU - DEE Subject: ERTS RISC MCU Architecture PIC16F877 Hardware 1 Outline Micriprocessor vs Microcontroller Introduction to PIC MCU PIC16F877 Hardware: Program Memory Data memory organization: banks,

More information

16.317: Microprocessor Systems Design I Fall 2014

16.317: Microprocessor Systems Design I Fall 2014 16.317: Microprocessor Systems Design I Fall 2014 Exam 2 Solution 1. (16 points, 4 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

PIC16C432 OTP 8-Bit CMOS MCU with LIN bus Transceiver

PIC16C432 OTP 8-Bit CMOS MCU with LIN bus Transceiver OTP 8-Bit CMOS MCU with LIN bus Transceiver Devices included in this Data Sheet: High Performance RISC CPU: Only 35 instructions to learn All single cycle instructions (200 ns), except for program branches

More information

Controller Provides Display of Monitored Process Deviation

Controller Provides Display of Monitored Process Deviation Controller Provides Display of Monitored Process Deviation The gadget, shown in Figure 1.0, is implemented with a controller based process which continuously monitors two, discrete, momentary switch inputs

More information

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017 Philadelphia University Faculty of Engineering Course Title: Embedded Systems (630414) Instructor: Eng. Anis Nazer Dept. of Computer Engineering Final Exam, First Semester: 2016/2017 Student Name: Student

More information

SN8F5000 Family Instruction Set

SN8F5000 Family Instruction Set SONiX Technology Co., Ltd. 8051-based Microcontroller 1 Overview SN8F5000 is 8051 Flash Type microcontroller supports comprehensive assembly instructions and which are fully compatible with standard 8051.

More information

D:\PICstuff\PartCounter\PartCounter.asm

D:\PICstuff\PartCounter\PartCounter.asm 1 ;********************************************************************** 2 ; This file is a basic code template for assembly code generation * 3 ; on the PICmicro PIC16F84A. This file contains the basic

More information

PIC10F200/202/204/206

PIC10F200/202/204/206 6-Pin, 8-Bit Flash Microcontrollers Devices Included In This Data Sheet: PIC0F200 PIC0F202 PIC0F204 PIC0F206 High-Performance RISC CPU: Only 33 Single-Word Instructions to Learn All Single-Cycle Instructions

More information

CONNECT TO THE PIC. A Simple Development Board

CONNECT TO THE PIC. A Simple Development Board CONNECT TO THE PIC A Simple Development Board Ok, so you have now got your programmer, and you have a PIC or two. It is all very well knowing how to program the PIC in theory, but the real learning comes

More information

PIC12C5XX. 8-Pin, 8-Bit CMOS Microcontroller. CMOS Technology: Devices included in this Data Sheet: High-Performance RISC CPU: Pin Diagram

PIC12C5XX. 8-Pin, 8-Bit CMOS Microcontroller. CMOS Technology: Devices included in this Data Sheet: High-Performance RISC CPU: Pin Diagram This document was created with FrameMaker 404 8-Pin, 8-Bit CMOS Microcontroller PIC12C5XX Devices included in this Data Sheet: PIC12C508 and PIC12C509 are 8-bit microcontrollers packaged in 8-lead packages.

More information

EE 367 Introduction to Microprocessors Homework 6

EE 367 Introduction to Microprocessors Homework 6 EE 367 Introduction to Microprocessors Homework 6 Due Wednesday, March 13, 2019 Announcements: Midterm on March 27 th The exam will cover through Lecture notes, Part 6; Lab 3, Homework 6, and readings

More information

Chapter 7 Central Processor Unit (S08CPUV2)

Chapter 7 Central Processor Unit (S08CPUV2) Chapter 7 Central Processor Unit (S08CPUV2) 7.1 Introduction This section provides summary information about the registers, addressing modes, and instruction set of the CPU of the HCS08 Family. For a more

More information

An Introduction & Guide to JALV2

An Introduction & Guide to JALV2 An Introduction & Guide to JALV2 An Introduction & Guide to JALV2 JAL is a high level language designed to hide the general nuisance of programming a MicroChip PIC processor. It is derived from the original

More information

Discrete Logic Replacement Message Dispatch Engine

Discrete Logic Replacement Message Dispatch Engine Message Dispatch Engine Author: OVERVIEW As we all know, the 8-pin PICmicro has limited resources. A nice way of using interrupts is for queuing events, prioritizing them, or even buffering them. This

More information