ΕΙΣΑΓΩΓΗ - eln. ?· Βουρβουλάκης Ιωάννης, Προγραμματισμός…

  • View
    218

  • Download
    0

Embed Size (px)

Transcript

  • 1 . MPLAB

    MPLAB, 8.0. Microchip : http :// www . microchip . com

    MPLAB Microchip PIC .

    (editor), (assembler) (simulator) . MPLAB (compiler) C, Basic .

    :

    MPLAB

    2 .

    , , . .

    http://www.microchip.com/

  • , PIC: 31, 35008, , .: 6947268005

    e-mail: jvourv@teilam.gr

    (debugging) .

    (Simulators). . .

    (Emulators). (In-Circuit). (hardware) . , .

    , . . PIC . In-Circuit Debugging ( ). ( RB6, RB7, ) .

    3 . PIC 16 F 887

    PIC16F887 . : , / .

    2

  • , PIC: 31, 35008, , .: 6947268005

    e-mail: jvourv@teilam.gr

    . , , , .

    , . . :

    PIC16F887 :

    Flash / EEPROM (SPI, I2C, USART) (A/D Converter) Capture/Compare/PWM (Analog Comparators) (Voltage Reference)

    PIC16F887 RISC (Reduced Instruction Set Computing), . , .

    2. PIC 16 F 887

    PIC16F887 : (stack)

    3

  • , PIC: 31, 35008, , .: 6947268005

    e-mail: jvourv@teilam.gr

    ) flash. . 8 (=213) 14 bit PIC16F887 . :

    Page 0 ( h0000 h1FFF) Page 1 ( h2000 h3FFF) Page 2 ( h4000 h5FFF) Page 3 ( h6000 h7FFF)

    ) PIC16F887 . SRAM EEPROM. Static RAM (Random Access Memory) . :

    Bank0 ( h00 h7F) Bank1 ( h80 hFF) Bank2 ( h100 h17F) Bank3 ( h180 h1FF)

    128 . . . PIC16F887 1.

    EEPROM (Electrically Erasable Programmable Read Only Memory) . O PIC16F887 256 bytes EEPROM.

    ) PIC16F887 8 . . .

    4

  • , PIC: 31, 35008, , .: 6947268005

    e-mail: jvourv@teilam.gr

    0 . 1 . 2 . 3 .INDF h00 INDF h80 INDF h100 INDF h180TMR0 h01 OPTION_REG h81 TMR0 h101 OPTION_REG h181PCL h02 PCL h82 PCL h102 PCL h182

    STATUS h03 STATUS h83 STATUS h103 STATUS h183FSR h04 FSR h84 FSR h104 FSR h184

    PORTA h05 TRISA h85 WDTCON h105 SRCON h185PORTB h06 TRISB h86 PORTB h106 TRISB h186PORTC h07 TRISC h87 CM1CON0 h107 BAUDCTL h187PORTD h08 TRISD h88 CM2CON0 h108 ANSEL h188PORTE h09 TRISE h89 CM2CON1 h109 ANSELH h189PCLATH h0A PCLATH h8A PCLATH h10A PCLATH h18AINTCON h0B INTCON h8B INTCON h10B INTCON h18B

    PIR1 h0C PIE1 h8C EEDAT h10C EECON1 h18CPIR2 h0D PIE2 h8D EEADR h10D EECON2 h18D

    TMR1L h0E PCON h8E EEDATH h10E

    h18E

    TMR1H h0F OSCCON h8F EEADRH h10F

    h18F

    T1CON h10 OSCTUNE h90

    16 Bytes

    h110

    16 Bytes

    h190TMR2 h11 SSPCON2 h91 h111 h191

    T2CON h12 PR2 h92 h112 h192SSPBUF h13 SSPADD h93 h113 h193SSPCON h14 SSPSTAT h94 h114 h194CCPR1L h15 WPUB h95 h115 h195CCPR1H h16 IOCB h96 h116 h196

    CCP1CON h17 VRCON h97 h117 h197RCSTA h18 TXSTA h98 h118 h198TXREG h19 SPBRG h99 h119 h199RCREG h1A SPBRGH h9A h11A h19ACCPR2L h1B PWM1CON h9B h11B h19BCCPR2H h1C ECCPAS h9C h11C h19C

    CCP2CON h1D PSTRCON h9D h11D h19DADRESH h1E ADRESL h9E h11E h19EADCON0 h1F ADCON1 h9F h11F h19F

    96 Bytes

    h20

    80 Bytes

    hA0

    80 Bytes

    h120

    80 Bytes

    h1A0

    h'EF h'16F h'1EF

    h'7F

    h'F0

    h'170

    h1F0

    hFF h17F h1FF 1. RAM PIC16F887.

    4. To PIC 16 F 887

    (instruction set) 35 2.

    A/A 1 addwf f,d w f 1 C, DC, Z2 andwf f,d AND w f 1 Z3 clrf f f 1 Z4 clrw w 1 Z

    5

  • , PIC: 31, 35008, , .: 6947268005

    e-mail: jvourv@teilam.gr

    5 comf f,d 1 f 1 Z6 decf f,d f 1 Z7 decfsz f,d f

    1 2 Z

    8 incf f,d f 1 Z9 incfsz f,d f

    1 2

    10 iorwf f,d OR f w 1 Z11 movf f,d f 112 movwf f f w 113 nop 114 rlf f,d

    f1 C

    15 rrf f,d f

    1 C

    16 subwf f,d w f 1 C, DC, Z17 swapf f,d

    bit bit f1

    18 xorwf f,d XOR w f 1 Z19 bcf f,b bit b f 120 bsf f,b 1 bit b f 121 btfsc f,b bit b f

    01 2

    22 btfss f,b bit b f 1

    1 2

    23 addlw k w k 1 C, DC, Z24 andlw k AND w k 1 Z25 call k k 226 clrwdt Watchdog Timer 1 PDTO,27 goto k

    k2

    28 iorlw k R w k 1 Z29 movlw l k w 130 retfie 231 retlw k

    w k2

    32 return 233 sleep 1 PDTO,34 sublw k w k 1 C, DC, Z35 xorlw k XOR w k 1 Z

    d=0 wd=1 f

    w f

    2. PIC16F887.

    3. PIC 16 F 887

    PIC16F887 /. :

    6

  • , PIC: 31, 35008, , .: 6947268005

    e-mail: jvourv@teilam.gr

    PORTA ( ) PORTB ( ) PORTC ( ) PORTD ( ) PORTE ( )

    1. PIC16F887.

    DIP (DualIn lineParallel) 1. .

    5. STATUS

    PIC16F887 STATUS. STATUS flag bit () (ALU) , Bank bit (Bank) bit . STATUS .

    STATUSbit 7 IRP: Bit (Bank)

    1= Bank2, Bank30= Bank0, Bank1

    bit 6-5 RP1:RP0: Bit (Bank) 11= Bank310= Bank2

    7

  • , PIC: 31, 35008, , .: 6947268005

    e-mail: jvourv@teilam.gr

    01= Bank100= Bank0

    bit 4 TO: Bit WDT1= , clrwdt sleep0= Watchdog Timer

    bit 3 PD: Bit 1= clrwdt0= sleep

    bit 2 Z: 1= 0=

    bit 1 DC: 4 bits 1= 4 bits 0= 4 bits

    bit 0 C: 1= bit 0= .: . C=0 C=1

    3. STATUS.

    8

  • , PIC: 31, 35008, , .: 6947268005

    e-mail: jvourv@teilam.gr

    PIC16F887

    1.

    PIC16F887. .

    1.

    temp1

  • , PIC: 31, 35008, , .: 6947268005

    e-mail: jvourv@teilam.gr

    1 .

    / 1 temp12 temp23 w 804 w temp15 w 5

    6 w temp1 w

    7 w temp28 w 82

    9 temp2 w w

    10 w temp1

    11 temp1, temp1

    12

    13 temp1 w

    14 AND bit w bit 254 w

    15 bit 7 temp2 1

    16 bit 0 temp1

    17 bit 7 temp2 0

    18 1 bit 0 temp119

    1. .

    2.

    ) MPLAB IDE.) Project > New (project file).) ( 2) . .

    10

  • , PIC: 31, 35008, , .: 6947268005

    e-mail: jvourv@teilam.gr

    2. Project > New

    ) Configure > Select Device 3 . PIC16F887 .) File > New ) :

    include ; assembler ; ; temp1 equ h'20' ; temp2 equ h'21' ;

    org h'0000' ; assembler ; h'0000' nop ; (no operation) clrf temp1 ; temp1 clrf temp2 ; temp2 movlw h'50' ; h'50'=d'80' w movwf temp1 ; w temp1 movlw h'05' ; h'05'=d'05' w addwf temp1,w ; w temp1 ; w movwf temp2 ; w temp2 movlw h'52' ; h'52'=d'82' w

    11

  • , PIC: 31, 35008, , .: 6947268005

    e-mail: jvourv@teilam.gr

    subwf temp2,w ; w temp2 ; w movwf temp1 ; w temp1 LABEL1 ; decfsz temp1,f ; temp1 ; goto LABEL1 ; LABEL1 comf temp1,w ; '1' temp1 ; w andlw b'11111110' ; AND w b'11111110'=d'254' rlf temp1,f ; temp1 btfss temp2,7 ; bit 7 temp2 ; '1' bcf temp1,0 ; bit 0 temp1 btfsc temp2,7 ; bit 7 temp2 ; '0' bsf temp1,0 ; '1' bit 0 temp1 goto $ ; i end ) File > Save As .asm .) Project > Add Files to Project . 4. . (workspace) 5. View > Project .

    12

  • , PIC: 31, 35008, , .: 6947268005

    e-mail: jvourv@teilam.gr

    3. . 4. .

    5. (Workspace). ) Project > Build All , , . (watch window) View > Special Function Registers View / Watch . Watch temp1 temp2 Add Symbol 6.

    13

  • , PIC: 31, 35008, , .: 6947268005

    e-mail: jvourv@teilam.gr

    6. (Watch Window).

    ) simulator MPLAB IDE, . simulator Debugger > Select Tool > MPLAB SIM .) Debugger > Step Into F7. RESET Debugger > Reset > Processor