Download presentation
Presentation is loading. Please wait.
1
PIC18 CH. 4
2
PIC18F452/458 Peripherals – Data ports – PORTA 6-bit PORTB 8-bit
PORTC 8-bit PORTD 8-bit PORTE 3-bit 33 pins out of 40 pins are set aside for the 5 ports – PORTA, …
3
I/O, other functions – for each port
To use any of these ports as an input or output port – it must be programmed I/O, other functions – for each port Each port has three SFRs associated with it [see T. 4.2]. These registers r designated as PORTx - PORTA, PORTB TRISx - TRIState LATx - LATch
4
5.1 arithmetic ADDLW k ;WREG = k + WREG
ADDWF fileReg, d ; = WREG + fileReg’s byte F = F + W ADDWFC add with carry For 16-bits addition, if any carry in the lower-byte addition [ADDWF] – then this carry will be added by ADDWFC for higher-byte F = F + W + carry
5
Subtraction: SUBLW k ;WREG = k – WREG SUBWF destination = fileReg – WREG SUBWFB dest = fileReg – WREG – borrow SUBFWB dest = WREG – fileReg - borrow
6
Multiplication: byte-by-byte multiplication only – unsigned data
MULLW k W x k Result = 16-bit One of the operand must be in the WREG Another operand must be a literal value [k] Results in the special function registers PRODH (higher-byte) & PRODL (lower-byte)
7
Division of unsigned numbers
No instruction for the division of byte/byte! Perform a division by repeated subtraction Numerator is placed in a fileReg Denominator is subtracted from it repeatedly Quotient is no. of times we subtracted Remainder is in fileReg upon completion
8
Logical ANDLW k ; W = W AND k ANDWF fileReg, d
IORLW k ;inclusive-OR or logical OR IORWF f, d XORLW k ;w = w EX-OR k XORWF f, d
9
6. Addressing modes PIC18 has 4 addressing modes – by which a CPU can access data Immediate Direct Register indirect Indexed-ROM
10
6.7 MACRO Group of instructions does a task – but this gr. is used repeatedly use MACRO use user-defined function Not writing the same – again n again; to avoid errors of same code; use MACRO Meaning - 1. A single, user-defined command that is part of an application and executes a series of commands. 2. A shorthand representation for a number of lines of code.
11
---------------------------------------------------------
name MACRO variable1, v2, … … ENDM MACRO directive indicates the starting… ENDM directive signals the end ‘name’ – ইচ্ছামত but must be unique
12
Move from W to fileReg? MOVWF Move from F to F? ??
Move to WREG? MOVLW Move from W to fileReg? MOVWF Move from F to F? ?? MOVLFx MACRO k, myReg MOVLW k MOVWF myReg ENDM
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.