pic18f458ppt

Upload: dgkanade72

Post on 11-Oct-2015

18 views

Category:

Documents


0 download

DESCRIPTION

Introduction to PIC 18F458

TRANSCRIPT

  • Advanced MicrocontrollersEC 38105

    ByProf. Kanade D.G.

    330_02

  • What you learn?Features of PIC 18Fxx8PIC 18Fxx8 architectureAddressing ModesInstruction SetOn chip PeripheralsProgramming PIC MicrocontrollerARM 7 Processor basicsAddressing Modes & Instruction set330_02*

    330_02

  • What is PIC Microcontroller?In 1989 Microchip Technology Corp. introduced 8-bit microcontroller called PIC.PIC-Peripheral Interface Controller.8 Pin Microcontroller Small amount of RAMHundred bytes of on chip ROMOne TimerFew pins for I/O330_02*

    330_02

  • What is PIC Microcontroller?Is leading supplier of 8 bit microcontroller.PIC 8 bit microcontroller families10xxx12xxx16xxx17xxx18xxx330_02*

    330_02

  • PIC microcontroller?Not 100% upward compatible.PIC 12xxx/16xxx have 12 bit and 14 bit wide instructions and PIC 18xxx has 16 bit wide instructions.

    No 8 pin version of PIC 18xxx exists.

    330_02*

    330_02

  • PIC18F MicrocontrollersMicrocontroller Unit (MCU)Microprocessor unit (MPU)Harvard ArchitectureProgram memory for instructionsData memory for dataI/O portsSupport devices such as timers 330_02*

    330_02

  • Microcontroller Unit330_02*

    330_02

  • PIC18F MPU and Memory330_02*

    330_02

  • Microprocessor UnitIncludes Arithmetic Logic Unit (ALU), Registers, and Control UnitArithmetic Logic Unit (ALU)Instruction decoder16-bit instructionsStatus register that stores flags5-bitsWREG working register8-bit accumulator330_02*

    330_02

  • Microprocessor UnitRegistersProgram Counter (PC)21-bit register that holds the Program Memory addressBank Select Register (BSR)4-bit register used in direct addressing the Data Memory File Select Registers (FSRs)12-bit registers used as memory pointers in indirect addressing Data Memory Control unit Provides timing and control signals Read and Write operations 330_02*

    330_02

  • PIC18F - Address BusesAddress bus21-bit address bus for Program MemoryAddressing capacity: 2 MB12-bit address bus for Data MemoryAddressing capacity: 4 KB330_02*

    330_02

  • Data Bus and Control SignalsData bus16-bit instruction/data bus for Program Memory8-bit data bus for Data MemoryControl signalsRead and Write330_02*

    330_02

  • Features of 18Fxx8High-Performance RISC CPU:Linear program memory addressing up to 2 MbytesLinear data memory addressing to 4 KbytesUp to 10 MIPS operationDC 40 MHz clock input4 MHz-10 MHz oscillator/clock input with PLL active16-bit wide instructions, 8-bit wide data pathPriority levels for interrupts8 x 8 Single-Cycle Hardware Multiplier330_02*

    330_02

  • Peripheral Features:High current sink/source 25 mA/25 mAThree external interrupt pinsTimer0module: 8-bit/16-bit timer/counter with 8-bit programmable prescalerTimer1module: 16-bit timer/counterTimer2module: 8-bit timer/counter with 8-bit period register (time base for PWM)Timer3module: 16-bit timer/counterSecondary oscillator clock option Timer1/Timer3Capture/Compare/PWM (CCP) modules330_02*Features of 18Fxx8

    330_02

  • Peripheral FeaturesEnhanced CCP moduleMaster Synchronous Serial Port (MSSP) with two modes of operation:3-wire SPI (Supports all 4 SPI modes)- I2C Master and Slave mode Addressable USART moduleCAN bus Module

    330_02*Features of 18Fxx8

    330_02

  • Advanced Analog Features:10-bit, up to 8-channel Analog-to-Digital Converter module (A/D) with: Conversion available during SleepAnalog Comparator module:Programmable input and output multiplexingComparator Voltage Reference moduleProgrammable Low-Voltage Detection (LVD) module: Supports interrupt-on-Low-Voltage DetectionProgrammable Brown-out Reset (BOR)330_02*Features of 18Fxx8

    330_02

  • Special Microcontroller Features:Power-on Reset (POR), Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)Watchdog Timer (WDT) with its own on-chip RC oscillatorProgrammable code protectionPower-saving Sleep modeSelectable oscillator options, including: 4x Phase Lock Loop (PLL) of primary oscillator Secondary Oscillator (32 kHz) clock inputIn-Circuit Serial ProgrammingTM (ICSPTM) via two pins330_02*Features of 18Fxx8

    330_02

  • Flash Technology:Low-power, high-speed Enhanced Flash technologyFully static designWide operating voltage range (2.0V to 5.5V)Industrial and Extended temperature ranges330_02*Features of 18Fxx8

    330_02

  • PIC 18F458 MemoryProgram Memory: 32 K flash Address range: 000000 to 007FFFHData Memory : 1536 Bytes Address range: 000 to 5FFHData EEPROM256 BytesNot part of the data memory spaceAddressed through special function registers 330_02*

    330_02

  • PIC 18Fxx8 MemoryProgram Memory330_02*

    330_02

  • PIC 18Fxx8Data Memory330_02*

    330_02

  • Access BankThe Access Bank is comprised of theUpper 160 bytes in Bank 15 (SFRs) andLower 96 bytes in Bank 0.These two sections will be referred to as Access Bank High and Access Bank Low, respectively.Minimum bank switchingUsed to store data & parameters by programmer and c compilers

    330_02*

    330_02

  • Using Access BankMOVWF f, aIf a=0 access bank will be selectedIf a=1 BSR3:0 is used for selecting one of the 16 banks.

    330_02*

    330_02

  • Working RegisterW- working register-8 bitSimilar to accumulatorUsed in arithmetic and logical operationsMOVLW 0xffADDLW 0x56330_02*

    330_02

  • Status Register330_02*

    330_02

  • Direct Addressing Mode330_02*

    330_02

  • Direct Addressing ModeTo copy file register 0x100 to W( working register)MOVLB 0x01MOVWF 0x00330_02*

    330_02

  • Indirect Addressing330_02*

    330_02

  • Indirect AddressingThree FSR (File Select Register)-12 bit registerFSR0, FSR1, FSR2INDF0, INDF1, INDF2To copy W register to file register 0x249LFSR0,0x249MOVWFINDF0Will copy the contents of W register to Internal RAM pointed by the contents of FSR0.330_02*

    330_02

  • PIC 18FXX8 I/O PortsFive I/O portsPORT A through PORT EMost I/O pins are multiplexedGenerally have eight I/O pinsAddresses already assigned to these portsEach port is identified by its assigned SFR 330_02*

    330_02

  • I/O Ports A and B330_02*

    330_02

  • MCU Support DevicesTimersCapture, Compare and PWM (CCP Modules) Serial CommunicationsMaster Synchronous Serial Port (MSSP)Addressable USARTA/D converterParallel Slave Port (PSP)Data EEPROM330_02*

    330_02

  • MCU Support Devices330_02*

    330_02

  • PIC18F4X8 Architecture Block Diagram*

  • PIC18FXX8 Programming Model330_02*

    330_02

  • PIC18F Instructions 77 assembly language instructions Earlier PIC families have 33 or 35 instructionsPIC18F instruction setMost instructions are 16-bit word lengthFour instructions are 32-bit length330_02*

    330_02

  • Instruction SetOPCODE FIELD DESCRIPTIONS

    330_02*

    FieldOperationaRAM access bit:a = 0: RAM location in Access RAM (BSR register is ignored)a = 1: RAM bank is specified by BSR registerbbbBit address within an 8-bit file register (0 to 7).BSRBank Select Register. Used to select the current RAM bankdDestination select bit:d = 0: store result in WREGd = 1: store result in file register fdestDestination either the WREG register or the specified register file locationf8-bit register file address (0x00 to 0xFF).

    330_02

  • Instruction Set330_02*

    FieldOperationfs12-bit register file address (0x000 to 0xFFF). This is the source address.fd12-bit register file address (0x000 to 0xFFF). This is the destination address.kLiteral field, constant data or label (may be either an 8-bit, 12-bit or a 20-bit value).LabelLabel 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: No 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)nThe relative address (2s complement number) for relative branch instructions or the direct address for Call/Branch and Return instructions.

    330_02

  • Instruction Set330_02*

    FieldOperationPROHProduct of Multiply High Byte.PRODLProduct of Multiply Low Byte.sFast Call/Return mode select bit:s = 0: do not update into/from shadow registerss = 1: certain registers loaded into/from shadow registers (Fast mode)uUnused or unchangedWREGWorking register (accumulator).xDont care (0 or 1).The assembler will generate code with x = 0. It is the recommended form of use for compatibility with all Microchip software tools.TBLPTR21-bit Table Pointer (points to a program memory location).

    330_02

  • Instruction Set330_02*

    FieldOperationTABLAT8-bit Table Latch..TOSTop-of-Stack.PCProgram CounterPCLProgram Counter Low BytePCHProgram Counter High BytePCLATHProgram Counter High Byte Latch.PCLATUProgram Counter Upper Byte Latch.GIEGlobal Interrupt Enable bit.WDTWatchdog Timer.

    330_02

  • Instruction Set330_02*

    FieldOperationTOTime-out bit.PDPower-Down bit.C DC Z OV NALU status bits: Carry, Digit Carry, Zero, Overflow, Negative[ ]Optional.( )Contents.Assigned to.PCLATUProgram Counter Upper Byte Latch.< >Register bit field.In the set of.italicsUser defined term (font is courier).

    330_02

  • Instruction Set330_02*General Format For Instructions

    330_02

  • Instruction Set330_02*General Format For Instructions

    330_02

  • 330_02*Instruction SetGeneral Format For Instructions

    330_02

  • 330_02*Instruction SetGeneral Format For Instructions

    330_02

  • 330_02*Instruction SetGeneral Format For Instructions

    330_02

  • 330_02*Instruction SetGeneral Format For Instructions

    330_02

  • 330_02*Instruction SetGeneral Format For Instructions

    330_02

  • Instruction SetByte Oriented Operations

    ADDLW(all flags affected)SyntaxADDLWk0

  • Instruction SetADDWFAdd W to fSyntaxADDWFf, d, [a]0
  • Instruction Descriptions Copy (Move) 8-bit number (Literal) into W registerMnemonics: MOVLW 8-bitBinary format: 0000 1110 XXXX XXXX (any 8-bit number)Copy (Move) contents of W register into PORTC (File)Mnemonics: MOVWF PORTC, a(a indicates that PORTC is in the Access Bank)Binary format: 0110 1110 1000 0010 (82H is PORTC address)330_02*

    330_02

  • Illustrative ProgramProblem statement:Write instructions to light up alternate LEDs at PORTCHardware: PORTCBidirectional (input or output) portSetup as output port for displayLogic 1 will turn on an LED330_02*

    330_02

  • IllustrationInterfacing LEDs to PORTC330_02*

    330_02

  • IllustrationProgram (software)Logic 0 to TRISC sets up PORTC as an output portByte 55H turns on alternate LEDs

    MOVLW00;Load W register with 0MOVWFTRISC;Set up PORTC as outputMOVLW0x55;Byte 55H to turn on LEDSMOVWFPORTC;Turn on LEDsSLEEP ;Power down330_02*

    330_02

  • Illustration330_02*

    AddressHexMnemonicsComments0000000E00MOVLW 00;Load W with 0s0000026E94MOVWF TRISC;Set PORTC as output0000040E55MOVLW 0x55;Load 55 to turn on LEDs0000066E82MOVWF PORTC;Turn on LEDs0000080003SLEEP;Power Down

    330_02

  • IllustrationExecution of the instruction: MOVWF PORTC330_02*

    330_02

  • PIC18 Simulator IDE330_02*

    330_02

  • Embedded SystemMCU-based System330_02*

    330_02

    ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330*ELEC 330ELEC 330*ELEC 330*ELEC 330ELEC 330*ELEC 330*ELEC 330