recitation1 (1)

Embed Size (px)

Citation preview

  • 8/6/2019 recitation1 (1)

    1/28

    CEng336

    CENG 336

    INT. TO EMBEDDED SYSTEMSDEVELOPMENT

    Spring 2011

    Recitation-1

    1/28

  • 8/6/2019 recitation1 (1)

    2/28

    Recitations and Teaching Assistants

    Introduction to PIC Lab Boards, PIC Assembly Language. (S.) PIC Assembly Language, MPLABIDE and demos. (S.) PICs I/O Ports (F.G) PICs Interrupts and timers. (F.G) Introduction to SDCC Small Device C Compiler. (F.G) Serial Communication with PICs, PICs ADC (Analog/Digital Convertor). (F.G)

    Introduction to PIC18 series microcontrollers and tools, MPLAB C Compiler forPIC18 (or FreeRTOS) . (M.G , B. )

    Introduction to PICOS18 (or FreeRTOS) . (M.G, B.)

    S. : Serdar FT (office: A402)F.G : Fatih GKE (office: A301)M.G : Murat GENTAV (office: A401)B. : Bura ZKAN (office: A401)A.K : Alper KILI (office: Security Lab)

    2/28

    Teaching Assistants

  • 8/6/2019 recitation1 (1)

    3/28

    CEng336

    Todays Outline

    Introduction to PIC Lab Boards

    Introduction to PIC arhictecture

    PIC Assembly Language (Part I)

    3/28

  • 8/6/2019 recitation1 (1)

    4/28

    CEng336

    Microcontroller:

    Very little external support hardware.

    Most RAM, ROM and peripherals on chip.

    Computer on a chip, or System on chip (SOC)

    Microprocessor:

    Requires external support hardware

    E.g., External RAM, ROM, Peripherals.

    Microcontroller vs Microprocessor

    4/28

  • 8/6/2019 recitation1 (1)

    5/28

    CEng336

    There are lots of microcontroller manufacturers

    5/28

  • 8/6/2019 recitation1 (1)

    6/28

    CEng336

    We will use

    PIC (Peripheral Interface Controller)

    PIC16F877 and PIC18F4520

    6/28

  • 8/6/2019 recitation1 (1)

    7/28

    CEng336

    PICs use the Harvard Architecture

    Used mostly in RISC CPUs Separate program bus and data

    bus: can be different widths!

    For example, PICs use:

    Data memory (RAM): asmall number of 8bit or 16bitregisters

    Program memory (ROM):

    12bit, 14bit, 16bit or 24bitwide (in EPROM, FLASH, orROM)

    PIC Architecture

    7/28

  • 8/6/2019 recitation1 (1)

    8/28

    CEng336

    14bit core - 35 instructions 200ns instruction time (Tclk = 20MHz)

    8,092 14bit FLASHprogram memory

    368 8bit data memory or registers (Fileregisters)

    256 8bit EEPROM (nonvolatile) data

    registers 8 level hardware stack

    Interrupt capability (up to 14 sources)

    33 pin I/O (for 40 pin package)

    3 Timer/Counter modules

    Timer0: 8-bit

    Timer1: 16-bit Timer2: 8-bit

    PIC16F877 Two Capture, Compare, PWM modules

    - Capture: 16-bit

    - Compare: 16-bit

    - PWM: max. resolution is 10-bit

    10-bit 8 channel Analog-to-Digital Converter

    Synchronous Serial Port (SSP) with SPI and

    I2C Universal Synchronous Asynchronous

    Receiver Transmitter (USART/SCI) with 9-bitaddress detection

    Parallel Slave Port (PSP) 8-bit

    8/28

  • 8/6/2019 recitation1 (1)

    9/28

    CEng336

    For PIC16F877: MPLAB IDE with PIC Assembler SDCC - Small Device C Compiler open sourcedevelopment tool (from command line)

    For PIC18F4520: We will use FreeRTOS or PICOS18 open sourcedevelopment tool.

    UsbPicProg (install this version 0.4.0) To program the PIC on the development boardhttp://sourceforge.net/projects/usbpicprog/files/usbpicprog-software/usbpicprog-0.4.0-software/

    Software Tools

    9/28

  • 8/6/2019 recitation1 (1)

    10/28

    CEng336

    Resources Datasheet (s) MOST IMPORTANT!!! Reference Book: Design with PIC Microcontrollers,

    John B. Peatman, Prentice Hall,1998.

    Serdar, Fatih, Murat, Bura and Alper Internet 336 news group Vendors web site

    www.microchip.com,http://forum.microchip.com Your friends (not recommended )

    10/28

  • 8/6/2019 recitation1 (1)

    11/28

    CEng336

    4 HWs (3 hws with PIC16F877, last hw with PIC18F4520)

    1st homework (7pts) and 2nd homework (8pts) will be

    coded in PIC assembler language.

    3rd homework (10pts) will be coded in SDCC (SmallDevice C Compiler).

    4th homework (15pts) will be on real time operatingsystems, FreeRTOS or PICOS18 will be used.

    HWs

    11/28

  • 8/6/2019 recitation1 (1)

    12/28

    CEng336

    PIC16F877 Program Memory Organization

    13 Bit Program Counter

    capable of addressing an 8Kx 14 program memory

    8 level stack Reset Vector: The program

    comes to this address in the firststart or after the microcontrolleris reset.

    Interrupt Vector: When an

    interrupt occurs, the programautomatically comes to thisaddress.

    12/28

  • 8/6/2019 recitation1 (1)

    13/28

    CEng336

    Program Memory Paging

    The upper 2 bits of the address areprovided by PCLATH.

    When doing a CALL or GOTO instruction,the user must ensure that the page selectbits are programmed so that the desiredprogram memory page is addressed.

    13/28

  • 8/6/2019 recitation1 (1)

    14/28

    CEng336

    PIC16F877 DATA MEMORY

    The data memory is partitionedinto multiple banks

    General Purpose Registers

    Special Function Registers Core (CPU) Registers

    STATUS

    OPTION_REG INTCON

    PIE1

    PIR1

    PIE2

    PIR2 PCON

    Peripheral Registers ex. RCSTA, PR2...

    14/28

  • 8/6/2019 recitation1 (1)

    15/28

    CEng336

    PIC16F877 DATA MEMORY Cont.

    15/28

  • 8/6/2019 recitation1 (1)

    16/28

    CEng336

    PIC INSTRUCTION SET

    16/28

  • 8/6/2019 recitation1 (1)

    17/28

    CEng336

    Some General Properties:

    Instructions are encoded in binary in ROM.

    The instructions are fixed format, each occupying 14 bits.

    Categories of instructions:

    Byte-oriented file register operations

    Bit-oriented file register operations

    Literal and Control operations

    INSTRUCTION FORMATS

    17/28

  • 8/6/2019 recitation1 (1)

    18/28

    CEng336

    Byte-oriented file register operations

    INSTRUCTION FORMATS

    18/28

  • 8/6/2019 recitation1 (1)

    19/28

    CEng336

    000 111 0 100 0111

    INSTRUCTION FORMATS

    Example

    Add W andregister

    Register number: 47hDestination is W

    W := W + Reg[47h]

    ADD W register content to 47h address

    content and save the result to W register

    19/28

  • 8/6/2019 recitation1 (1)

    20/28

    CEng336

    000 111 1 100 0111

    INSTRUCTION FORMATS

    Example

    Add W andregister

    Register number: 47hDestination isReg[47]

    Reg[47h] := W + Reg[47h]

    Only difference

    from previousinstruction

    ADD W register content to 47h address

    content and save the result to 47h address

    20/28

  • 8/6/2019 recitation1 (1)

    21/28

    CEng336

    Bit-oriented file register operations

    INSTRUCTION FORMATS

    21/28

  • 8/6/2019 recitation1 (1)

    22/28

    CEng336

    0100 101 010 1001

    INSTRUCTION FORMATS

    Example

    Clear specified bitof the register

    Register number: 29hBit 5 is to becleared

    Clear 5th bit of 29h register content

    22/28

  • 8/6/2019 recitation1 (1)

    23/28

    CEng336

    Literal operations

    INSTRUCTION FORMATS

    23/28

  • 8/6/2019 recitation1 (1)

    24/28

    CEng336

    11 1110 0001 0111

    INSTRUCTION FORMATS

    Example

    Add literal instruction Value to add: 17h

    ADD 0x17 value to W register content

    and save the result to W register

    24/28

  • 8/6/2019 recitation1 (1)

    25/28

    CEng336

    Control operations

    INSTRUCTION FORMATS

    25/28

  • 8/6/2019 recitation1 (1)

    26/28

    CEng336

    INSTRUCTION FORMATS

    Example

    101 000 0011 0010

    Binary for GOTO Binary for 32h

    GOTO 0x32

    26/28

  • 8/6/2019 recitation1 (1)

    27/28

    Next Week

    PIC Instruction Set will be continued MPLAB IDE will be introduced Demo programs and programming PIC

    27/28

  • 8/6/2019 recitation1 (1)

    28/28

    Questions???

    28/28