You are on page 1of 10

# BÀI TẬP VỀ NHÀ VI XỬ LÝ (nguồn: Việt Hưng

)
BÀI 1: ORG 0000H MOV R0, #30h MOV R1, #10D MOV R6, #0H MOV R7, #0H MOV A, @R0 BACK: INC R0 ADD A, @R0 MOV R7, A JC OVER SJMP HERE OVER: INC R6 HERE: DJNZ R1, BACK END BÀI 2: org 0000h mov r0, #30h mov r1, #20d back:

tang con tro Ram xu ly ki tu tiep theo cjne @r0. tiep tuc so sanh voi 5Ah (ma ASCII cua Z) setb c cont: . #5ah. So sanh ((r0)) voi 41h (ma ASCII cua A) clr c here: jc next . ((r0))<=5Ah thi C=1. doc du lieu tu Ram ngoai cjne a. doi no thanh ki tu thuong mov @r0. #41h. a next: inc r0 djnz r1.cjne @r0. #2000h back: movx a. back end BÀI 3: org 0000h mov dptr. ((r0))<41h thi C=1. ((r0)>=41h thi C=0. @dptr . #32d . tang con tro Ram xu ly ki tu tiep theo jnc next convert: add a. next sjmp quit . here . neu a la ki tu '0' thi thoat luon . cont . ((r0))>5Ah thi C=0. #30h.

7 C jc port2 sjmp port1 port2: trong A la am mov p2. neu C duoc set tuc la gia tri . a here: inc dptr sjmp back quit: end BÀI 4: . khi do se xuat ra port1 org 0h ljmp main . vector ngat timer0 ljmp isr0 org 001bh .*****vector ngat******** org 000bh . acc. khi do se xuat ra port2 .******chuong trinh chinh******* . a sjmp here port1: A duong mov p1.next: mov c. luu bit cao nhat cua a vao co nho . neu C=0 tuc la gia tri trong . vector ngat timer1 ljmp isr1 .

byte cao cua -500 mov tl1.7. nap thoi gian tre mov tl0. #012h . #00ch .6 mov p1. p1.******Timer1 thay doi tan so xung******* .6.7 sjmp quit here: . #0feh .. #-100d . #08ah .6 jb p1. clr p1. byte cao cua -500 mov tl1. byte thap cua -500 mov th0. #-100d . byte thap cua -500 setb tr0 .7 setb tr1 . uu tien ngat do timer0 mov th1. #01h . timer0 che do 2 mov ie. dung timer0 mov c. cho phep ngat timer0 va 1 mov ip. #00ch . here setb p1.******Timer0 thay doi thoi gian tre***** main: mov tmod. khoi dong timer1 sjmp \$ isr0: clr tr0 . khoi dong timer0 cpl p1. c reti isr1: clr tr1 mov th1. #0feh . timer1 che do 1.6 clr p1.

clr p1.7 quit: setb tr1 reti end BÀI 5: org 0000h ljmp main org 000bh ljmp isr0 org 001bh ljmp isr1 main: mov tmod. cho phep ngat do 2 Timer setb tr0 setb tr1 setb tf0 . #0d8h . #11h . #000ch . byte thap cua -10000 mov ie. #00feh . byte cao cua -500 mov tl1. byte thap cua -500 mov th0. byte cao cua -10000 mov tl0. #8ah .Timer1 che do 1-16bit. buoc ngat do Timer0 sjmp \$ isr0: clr tr0 . #0f0h . Timer0 che do 1-16bit mov th1.

byte thap cua -10000 . bat xanh1 va do2 (25s) mov r1.0 reti end BÀI 6: . #0003d . #000ch setb tr1 cpl p1.*******XU LY DEN************ back: mov p1. byte cao cua -10000 . #01h. dung Timer0 de tao tre chinh xac 1s******* mov tmod. #0d8h mov tl0. #11011110b.che do 1 .******Thiet lap Timer0. bat vang1 va do2 (3s) mov r1. #11011101b. byte thap cua -500 org 0000h main: . #00feh mov tl1.1 reti isr1: clr tr1 mov th1. #0025d acall delay mov p1. #0f0h setb tr0 cpl p1. byte cao cua -500 .mov th0.

loop2 djnz r1. loop1 ret end BÀI 7: org 00h ljmp main . byte thap cua -50000 setb tr0 wait: jnb tf0. #11101011b. #00b0h. wait djnz r0. bat do1 va xanh2 (33s) mov r1. byte cao cua -50000 mov tl0. #003ch. #0020d loop2: clr tr0 clr tf0 mov th0. #0003d acall delay sjmp back delay: loop1: mov r0. bat do1 va vang2 (3s) mov r1. #11110011b. #0033d acall delay mov p1.acall delay mov p1.

sbuf cjne a. #90h.7 mov pcon. khoi dong Timer1 sjmp \$ sisr: jb ti. cho phep ngat do port noi tiep clr ri clr ti setb tr1. #-3d. trans. #20h.3. Timer1 che do 2 mov a. thoat neu co ti o muc cao mov a. cont1 setb P1. bat led sjmp cont2 cont1: cjne a. chon che do ca thu va phat 8 bit mov ie. #03h. a mov th1. tat led cont2: clr ri reti trans: clr ti . pcon. cont2 clr p1. chon toc do baud 19200 mov scon. #02h. vector ngat cua port noi tiep ljmp sisr main: mov tmod.org 0023h. #50h.3. nhan doi yoc do baud setb acc.

toc do baud 9600 mov ie. Timer1 che do 2 mov scon. #90h. quit mov a. #-3d. 8bit. #70h. #08fh. cont mov r0. cho phep ngat do port noi tiep mov r0. sbuf mov @r0. #080h sjmp quit cont: inc r0 clr ri reti . khoi tao con tro RAM noi setb tr1 sjmp \$ sisr: jb ti. cho phep thu mov th1. #20h. a cjne r0.reti end BÀI 8: org 00h ljmp main org 0023h ljmp sisr main: mov tmod. #50h.

quit: clr ti reti end .