Đây là bài em viết mỗi khi nhấn nút ở chân RB0 thì sẽ hiển thị lên led ở po rtA.
Dịch ra file he x thì ok, nhưng mô phỏng proteus lại ko dc.
Em nghĩ là do ngắt .
Code:
;=======================================================
TITLE "Mach test ngat ngoai"
PROCESSOR P16F877A
INCLUDE <P16F877A.inc>
__CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF &_HS_OSC
;chan RB0 noi voi cong tac de dem so lan nhan
;port A noi voi cac led hien de hien thi so binary
;===============================================================================
count equ 0x30
portA equ 0x05
intcon equ 0x0b
TRISB equ 0x86
trisA equ 0x85
ORG 0x0000
GOTO MAIN
org 0x0400
goto ngat
ORG 0x0005
MAIN
bsf intcon,7
bsf intcon,4
bcf intcon,1
BANKSEL TRISB ; bank select
movlw b'00000001'
movwf TRISB ; trisb = #w; rb0 = input
BANKSEL trisA
movlw 0x000
movwf trisA
movwf count
movlw portA
goto $-2
ngat
incf count,1 ;tăng giá trị lên 1 và lưu lại trong count
retfie
END
;================================================================================