PIC18F4520秒表编程(MPLAB)

时间:2017-11-26 10:00:53

标签: microchip mplab pic18

我使用单个7段LED和8个按钮为PIC18F4520秒表制作代码。按钮1停止,按钮2重置。以下是我的代码。

LIST p=18F4520
#include <P18F4520.INC>
CONFIG OSC = XT
CONFIG WDT = OFF
CONFIG LVP = OFF
CBLOCK 0x000
    DELAY_H
    DELAY_L
    DELAY_U
    input
endc

ORG 0x0000
goto Main
ORG 0x0800
    BTFSC   INTCON,INT0IF
    call    INT0_ISR
    BTFSC   INTCON3,INT1IF
    call    INT1_ISR
    RETFIE

ORG 0x0100
Main
    movlw   0x0F
    movwf   ADCON1
    clrf    TRISD
    clrf    PORTD
    setf    TRISB

    BCF     INTCON,INT0IF
    BSF     INTCON,INT0IE
    BCF     INTCON2,INTEDG0
    BCF     INTCON3,INT1IF
    BSF     INTCON3,INT1IE
    BCF     INTCON2,INTEDG1
    BSF     INTCON,GIE

    movlw   0x00
    movwf   input
    call    bcd_7seg
    movwf   PORTD

count   equ 0x25
    movlw   0x0A
    movwf   count
sec     
    incf    input, F
    call    bcd_7seg
    movwf   PORTD
    call    Delay
    decf    count, F
    bnz     sec
    goto    count


bcd_table:
db 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x3F
bcd_7seg:
    movlw   low bcd_table
    movwf   TBLPTRL
    movlw   high bcd_table
    movwf   TBLPTRH
    movlw   upper bcd_table
    movwf   TBLPTRU
    movf    input, W
    addwf   TBLPTRL, F
    movlw   0
    addwfc  TBLPTRH
    addwfc  TBLPTRU
    TBLRD*
    movf    TABLAT, W
    RETURN


Delay: 
    MOVLW   d'10'
    MOVWF   DELAY_U
LOP1_0:
    MOVLW   0x80
    MOVWF   DELAY_H
LOP1_1:
    MOVLW   0xFF
    MOVWF   DELAY_L
LOP1_2:
    DECF    DELAY_L, F
    BNZ LOP1_2
    DECF    DELAY_H, F
    BNZ LOP1_1 
    DECF    DELAY_U, F
    BNZ LOP1_0
    return

INT0_ISR : ? 


INT1_ISR : ?


delay:      
    MOVLW   D'100'
    MOVWF   1
back
    MOVLW   D'0'
    MOVWF   2
here
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    decf    2, F
    BNZ     here
    decf    1, F
    BNZ     back
    return

end

即使我没有在INT0_ISR和INT1_ISR中添加任何指令,button1和button都会将LED上的数字更改为1.我应该在INT0_ISR和INT1_ISR中添加哪些指令来给出正确的结果?谢谢你的帮助!

0 个答案:

没有答案