em có cái code asm như thế này sao cho chạy thử nó nhảy lung tung ko đếm chính xác được, các bác xem giúp em code này có gì ko ổn ko ạ!
dataport equ p2 ; xuat du lieu ra p2
ctrl equ p1 ; p1 la port dieu khien de quet led
led2 equ 1 ; led 2 la p1.1
led3 equ 2 ; led 3 la p1.2
a_ equ 11111110b
b_ equ 11111101b
c_ equ 11111011b
d equ 11110111b
e equ 11101111b
f equ 11011111b
g equ 10111111b
dp equ 01111111b
dseg at 30h
dv : ds 1
ch : ds 1
delay0: ds 1
delay1: ds 1
cseg at 00h
ljmp begin
;-----------------------------
;Khai bao ngat ngoai 1
cseg at 13h
ljmp ext1_isr
begin:
; cau hinh ngat ngoai 1
setb IT1
setb EX1
setb EA
mov ctrl,#0FFh ;lenh dieu khien p1
mov dptr,#ma7doan
mov dv,#0
mov ch,#0
l:
lcall hienthi
ljmp l
; khai bao ngat ngoai 1
ext1_isr:
;moi khi co ngat say ra thi se goi chuong trinh dem tang(count_up)
lcall count_up
reti
; dem tang tu 000-999
count_up:
inc dv
mov r0,dv
cjne r0,#10,count_exit
mov dv,#0
inc ch
mov r0,ch
cjne r0,#10,count_exit
mov ch,#0
count_exit:
ret
; quet led 7 doan
hienthi:
mov dptr,#ma7doan
mov a,dv
movc a,@a+dptr
mov dataport,a
setb ctrl.led3
lcall delay_2ms
clr ctrl.led3
mov dptr,#ma7doan
mov a,ch
movc a,@a+dptr
mov dataport,a
setb ctrl.led2
lcall delay_2ms
clr ctrl.led2
ret
; thoi gian delay 2mms
delay_2ms:
mov delay0,#2
loop_0:
mov delay1,#250
loop_1:
nop
nop
djnz delay1,loop_1
djnz delay0,loop_0
ret
; Bang ma led 7 doan
ma7doan:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,080H,090H
end
dataport equ p2 ; xuat du lieu ra p2
ctrl equ p1 ; p1 la port dieu khien de quet led
led2 equ 1 ; led 2 la p1.1
led3 equ 2 ; led 3 la p1.2
a_ equ 11111110b
b_ equ 11111101b
c_ equ 11111011b
d equ 11110111b
e equ 11101111b
f equ 11011111b
g equ 10111111b
dp equ 01111111b
dseg at 30h
dv : ds 1
ch : ds 1
delay0: ds 1
delay1: ds 1
cseg at 00h
ljmp begin
;-----------------------------
;Khai bao ngat ngoai 1
cseg at 13h
ljmp ext1_isr
begin:
; cau hinh ngat ngoai 1
setb IT1
setb EX1
setb EA
mov ctrl,#0FFh ;lenh dieu khien p1
mov dptr,#ma7doan
mov dv,#0
mov ch,#0
l:
lcall hienthi
ljmp l
; khai bao ngat ngoai 1
ext1_isr:
;moi khi co ngat say ra thi se goi chuong trinh dem tang(count_up)
lcall count_up
reti
; dem tang tu 000-999
count_up:
inc dv
mov r0,dv
cjne r0,#10,count_exit
mov dv,#0
inc ch
mov r0,ch
cjne r0,#10,count_exit
mov ch,#0
count_exit:
ret
; quet led 7 doan
hienthi:
mov dptr,#ma7doan
mov a,dv
movc a,@a+dptr
mov dataport,a
setb ctrl.led3
lcall delay_2ms
clr ctrl.led3
mov dptr,#ma7doan
mov a,ch
movc a,@a+dptr
mov dataport,a
setb ctrl.led2
lcall delay_2ms
clr ctrl.led2
ret
; thoi gian delay 2mms
delay_2ms:
mov delay0,#2
loop_0:
mov delay1,#250
loop_1:
nop
nop
djnz delay1,loop_1
djnz delay0,loop_0
ret
; Bang ma led 7 doan
ma7doan:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,080H,090H
end