Thông báo

Collapse
No announcement yet.

hiển thi led đơn có nút nhấn dùng pic 16f877a

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • hiển thi led đơn có nút nhấn dùng pic 16f877a

    e đang làm bài lab mà thấy code ko chạy dc...
    mong các anh o dien dan giup sua cho e voi...e cam on nhieu
    ;Chöông trình 4.1.8
    processor 16f877a
    include <p16f877a.inc>
    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
    ;--------------------------------------------------------------------------------------------------------------
    ;Khai baùo haèng
    ;--------------------------------------------------------------------------------------------------------------
    SW1 EQU 0
    SW2 EQU 1
    SW3 EQU 2
    SW4 EQU 3
    LED1 EQU 4
    LED2 EQU 5
    LED3 EQU 6
    LED4 EQU 7
    ;--------------------------------------------------------------------------------------------------------------
    ;Khai baùo bieán
    ;--------------------------------------------------------------------------------------------------------------
    count EQU 0x20
    count1 EQU 0x20
    counta EQU 0x21
    countb EQU 0x22
    ;--------------------------------------------------------------------------------------------------------------
    ;Caùc khai baùo khaùc
    ;--------------------------------------------------------------------------------------------------------------
    SWdel SET del150 ; gaùn SWdel vôùi label del150
    ;--------------------------------------------------------------------------------------------------------------
    ;Chöông trình
    ;--------------------------------------------------------------------------------------------------------------
    ORG 0x000
    GOTO start
    start ; vò trí baét ñaàu chöông trình chính
    BCF STATUS,RP1
    BCF STATUS,RP0 ; choïn BANK0
    CLRF PORTB
    BSF STATUS,RP0 ; choïn BANK1
    MOVLW b'00001111'
    MOVWF TRISB
    BCF STATUS,RP0 ; choïn BANK0
    loop ; voøng laëp kieåm tra coâng taùc naøo ñöôïc aán
    BTFSS PORTB,SW1 ; kieåm tra SW1
    CALL switch1 ; nhaûy tôùi chöông trình con switch1 neáu
    ; SW1 ñöôïc aán
    BTFSS PORTB,SW2 ; neáu SW1 khoâng ñöôïc aán tieáp tuïc kieåm tra
    ; SW2
    CALL switch2 ; thao taùc töông töï nhö SW1
    BTFSS PORTB,SW3
    CALL switch3
    BTFSS PORTB,SW4
    CALL switch4
    GOTO loop

    switch1
    CLRF PORTB ; xoùa PORTB
    CALL SWdel ; goïi chöông trình delay del150
    BTFSC PORTB,SW1 ; kieåm tra coâng taéc 1 coøn nhaán hay khoâng
    RETURN ; neáu khoâng coøn nhaán thì trôû veà chöông
    ; trình chính
    led1_ON
    BSF PORTB,LED1 ; baät LED1 saùng
    BTFSC PORTB,SW1 ; xaùc nhaän laïi traïng thaùi coâng taéc 1
    RETURN ; trôû veà chöông trình chính neáu coâng taéc
    ; khoâng coøn aán
    GOTO led1_ON ; tieáp tuïc giöõ LED1 saùng neáu coâng taéc coøn
    ; ñöôïc aán
    switch2 ; thao taùc töông töï vôùi caùc coâng taéc coøn laïi
    CLRF PORTB
    CALL SWdel
    BTFSC PORTB,SW2
    RETURN
    led2_ON
    BSF PORTB,LED2
    BTFSC PORTB,SW2
    RETURN
    GOTO led2_ON

    switch3
    CLRF PORTB
    CALL SWdel
    BTFSC PORTB,SW3
    RETURN
    led3_ON
    BSF PORTB,LED3
    BTFSC PORTB,SW3
    RETURN
    GOTO led3_ON

    switch4
    CLRF PORTB
    CALL SWdel
    BTFSC PORTB,SW4
    RETURN
    led4_ON
    BSF PORTB,LED4
    BTFSC PORTB,SW4
    RETURN
    GOTO led4_ON
    ;---------------------------------------------------------------------------------------------------------------
    ;Chöông trình delay caûi tieán cho pheùp nhieàu khoaûng thôøi gian delay khaùc nhau
    ;---------------------------------------------------------------------------------------------------------------
    del0
    RETURN
    del1
    MOVLW d'1'
    GOTO delay
    del5
    MOVLW d'5'
    GOTO delay
    del10
    MOVLW d'10'
    GOTO delay
    del20
    MOVLW d'20'
    GOTO delay
    del50
    MOVLW d'50'
    GOTO delay
    del100
    MOVLW d'100'
    GOTO delay
    del150
    MOVLW d'150'
    GOTO delay
    del200
    MOVLW d'200'
    GOTO delay
    delay
    MOVWF count1
    d1 ; taïo thôøi gian delay 1 mS
    MOVLW 0xC7
    MOVWF counta
    MOVLW 0x01
    MOVWF countb
    delay_0
    DECFSZ counta,1
    GOTO $+2
    DECFSZ countb,1
    GOTO delay_0
    DECFSZ count1,1
    GOTO d1
    RETURN
    END


    báo lỗi:
    Release build of project `E:\do an\do an cau truc may tinh\2132012\code\testIO.mcp' started.
    Language tool versions: MPASMWIN.exe v5.42, mplink.exe v4.40, mplib.exe v4.40
    Fri Mar 23 11:59:09 2012
    ----------------------------------------------------------------------
    Clean: Deleting intermediary and output files.
    Clean: Deleted file "E:\do an\do an cau truc may tinh\2132012\code\chay led.err".
    Clean: Deleted file "E:\do an\do an cau truc may tinh\2132012\code\chay led.lst".
    Clean: Deleted file "E:\do an\do an cau truc may tinh\2132012\code\testIO.cof".
    Clean: Deleted file "E:\do an\do an cau truc may tinh\2132012\code\testIO.hex".
    Clean: Done.
    Executing: "C:\Program Files (x86)\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F877A "toiuunhuocdiemIO.asm" /l"toiuunhuocdiemIO.lst" /e"toiuunhuocdiemIO.err" /o"toiuunhuocdiemIO.o"
    Warning[205] E:\DO AN\DO AN CAU TRUC MAY TINH\2132012\CODE\TOIUUNHUOCDIEMIO.ASM 2 : Found directive in column 1. (processor)
    Warning[205] E:\DO AN\DO AN CAU TRUC MAY TINH\2132012\CODE\TOIUUNHUOCDIEMIO.ASM 3 : Found directive in column 1. (include)
    Warning[205] E:\DO AN\DO AN CAU TRUC MAY TINH\2132012\CODE\TOIUUNHUOCDIEMIO.ASM 4 : Found directive in column 1. (__CONFIG)
    Error[151] E:\DO AN\DO AN CAU TRUC MAY TINH\2132012\CODE\TOIUUNHUOCDIEMIO.ASM 26 : Operand contains unresolvable labels or is too complex
    Message[302] E:\DO AN\DO AN CAU TRUC MAY TINH\2132012\CODE\TOIUUNHUOCDIEMIO.ASM 38 : Register in operand not in bank 0. Ensure that bank bits are correct.
    Warning[205] E:\DO AN\DO AN CAU TRUC MAY TINH\2132012\CODE\TOIUUNHUOCDIEMIO.ASM 142 : Found directive in column 1. (END)
    Halting build on first failure as requested.
    ----------------------------------------------------------------------
    Release build of project `E:\do an\do an cau truc may tinh\2132012\code\testIO.mcp' failed.
    Language tool versions: MPASMWIN.exe v5.42, mplink.exe v4.40, mplib.exe v4.40
    Fri Mar 23 11:59:13 2012
    ----------------------------------------------------------------------
    BUILD FAILED

Về tác giả

Collapse

vanhoavh Tìm hiểu thêm về vanhoavh

Bài viết mới nhất

Collapse

Đang tải...
X