intTypePromotion=1

Ứng dụng vi xử lý

Chia sẻ: Thuan Ga Thuan | Ngày: | Loại File: DOC | Số trang:43

0
331
lượt xem
60
download

Ứng dụng vi xử lý

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Đơn vị xử lý trung tâm CPU: CPU có cấu tạo gồm có đơn vị xử lý số học và lôgic (ALU), các thanh ghi, các khối lôgic và các mạch giao tiếp. Chức năng của CPU là tiến hành các thao tác tính toán xử lý, đưa ra các tín hiệu địa chỉ, dữ liệu và điều khiển nhằm thực hiện một nhiệm vụ nào đó do người lập trình đưa ra thông qua các lệnh (Instructions).

Chủ đề:
Lưu

Nội dung Text: Ứng dụng vi xử lý

  1. ---------- Ứng dụng vi xử lý
  2. CAC BAI TAP UNG DUNG VI SU LY $include(reg52.inc) bai tap ve di chuyen du lieu bµi1 start: mov r0,#30h ;r0=30h mov @r0,#40h mov a,@r0 ;a=40h mov p1,a ;p1=40h mov r1,a ;r1=40 mov @r1,#10h ;@r1=10h mov b,@r1 ;b=10h mov p3,b ;p3=10h mov @r1,#0cch ;@r1=0cch jmp start bµi2 start: mov p2,#0c5h ;p2=0c5h mov p1,#35h ;p1=35h mov c,p1.2 ;c=1 mov p1.3,c ;p1=3d mov c,p2.3 ;c=0 mov p1.2,c ;p1=39h jmp start end bµi3 start: mov r0,#11h mov a,#55h movx @r0,A ;@r0=55h mov 80h,#55h movx a,@r0 ;a=55h mov r1,#23h movx @r1,a jmp start end bµi4 start: mov sp,#05h mov dptr,#1123h push dpl mov p0,dpl push dph mov p1,dph jmp start end bµi5 start: mov sp,#32h pop dph;dph=12h,sp=31
  3. pop dpl ;dpl=11h,sp=30h,dptr=1211h jmp start bµi6 tart: mov a,#0ffh;a=0ffh mov r1,#30h mov @r1,#0fh;@R1=0fh xch a,@r1;a=0fh,@r1=0ffh mov p1,a mov p3,@r1 jmp start end bµi7 start: mov a,#10001100b;a=8ch mov r1,#20h mov @r1,#11100001b;@r1=ech xchd a,@r1 mov p0,a;a81h mov p2,@r1; p2=ech jmp start bµi8 start:mov 0b0h,#0f0h mov r0,#3fh mov @r0,0b0h mov p1,@r0 jmp start end bai start:mov a,#0c3h mov r1,#0aah add a,r1 mov p0,a mov p1,r1 jmp start wait:mov r0,#4 w1:djnz r0,w1 ret end bai start:mov a,#0c3h
  4. mov r1,#0aah addc a,r1 mov p0,a mov p1,r1 jmp start wait:mov r0,#4 w1:djnz r0,w1 ret end bai start:mov a,#0c9h mov r2,#054h subb a,r2 mov p0,a mov p1,r2 jmp start wait:mov r0,#4 w1:djnz r0,w1 ret end bai start:mov r0,#7eh mov @r0,#0ffh inc @r0 inc r0 mov @r0,#40h inc @r0 jmp start wait:mov r0,#4 w1:djnz r0,w1 ret end bai start:mov dptr,#12feh inc dptr inc dptr inc dptr mov 90h,dph mov 80h,dpl jmp start end bai start:mov a,#50h mov b,#0a0h mul ab jmp start end
  5. bai start:mov a,#0fbh mov b,#12h mov p1,a mov p2,b div ab mov p1,a mov p2,b call wait jmp start wait:mov r0,#5 W1:djnz r0,w1 ret end PHAN LO GIC start:mov a,#0c3h mov r0,#55h anl a,r0;a=41 jmp start wait:mov r0,#5 W1:djnz r0,w1 ret end start: mov a,#0c3h mov r0,#55h orl a,r0;a=D7h jmp start end start:mov c,p1.0 mov acc.7,c anl c,acc.7 jmp start end PhÇn bµI t©p logic (a)=0c3h,(r0)=055h Sau khi thùc hiÖn lÖnh anl a,r0;(a)=?
  6. Bµi1 start:mov a,#0c3h mov r0,#55h anl a,r0;a=41 jmp start wait:mov r0,#5 W1:djnz r0,w1 ret end P1.0=1,acc.7=1 ThiÕt lËp carry b»ng lÖnh anl bµi2 start:mov p1,#01h mov a,#01h mov c,p1.0 anl c,p1.0 jmp start end =0c3h,r0=55h u khi thùc hiÖn lÖnh orl a,r0;(a)=? bµi3 start: mov a,#0c3h mov r0,#55h orl a,r0;a=D7h jmp start end P1.0=1,acc.7=1,ov=0 ThiÕt lËp carry lÖnh b»ng orl Bµi4 start:mov p1,#01h mov a,#01h orl c,p1.0;c=1 jmp start end (a)=0c3h,(r0)=0aah Sau khi thùc hiÖn lÖnh xrl a,r0; (a)=?
  7. bµi5 start:mov a,#0c3h mov r0,#0aah xrl a,r0;a=69h jmp start end (A)=0C5H Sau khi thùc hiÖn lÖnh sau rl a; (a)=? bµi6 start: mov a,#0c5h rl a;a=8bh jmp start end (a)=0c5h,(c)=0 Sau khi thùc hiÖn lÖnh sau rlc a; a=?, c=? Bµi7 start:mov a,#0c5h clr c;c=0 rlc a;a=8ah,c=1 jmp start end (a)=0c5h X¸c ®Þnh a=? sau khi thùc hiªn lÖnh sau rr a bµI8 start:mov a,#0c5h rr a;a=e2h jmp start end (a)=0c5h,c=0 X¸c dÞnh a=?, c=? sau khi thùc hiÖn lªnh sau rrc a bµi9
  8. start:mov a,#0c5h clr c;c=0 rrc a;a=62h,c=1 jmp start end (a)=0c5h X¸c ®inh a=? sau khi thùc hiÖn lÖnh sau swap bµi10 start:mov a,#0c5h swap a;a=5ch thùc hiÖn ®¶o 4 bÝt thÊp thµnh 4bÝt cao jmp start end $include(reg52.inc) start: mov r0,#8h wait: cpl p1.7 djnz r0,wait jmp start end start: clr p2.7 nop nop nop nop setb p2.7 jmp start end start:mov p1,#5dh clr p1.2 jmp start start:mov p1,#34h mov c,p1.0 setb p1.0 setb c jmp start end start:mov p1,#5bh cpl p1.2
  9. cpl p1.1 jmp start end start:mov a,#5ch cpl a mov p1,a jmp start end có dùng bảng dữ liệu start: label1: db 0feh,0fch,0f8h,0f0h,0e0h,0c0h,080h,00h,0ffh mov dptr,#label1 mov r0,#9h label2:mov a,#0h movc a,@a+dptr mov p1,a inc dptr djnz r0,label2 wait:mov r1,#10 W1:djnz r1,w1 ret jmp start end label1: db 0feh,0fch,0f8h,0f0h,0e0h,0c0h,080h,00h,0ffh start:mov dptr,#label1 label2:mov a,#0h movc a,@a+dptr mov p1,a call wait inc dptr cjne a,#0ffh,label2 wait:mov r1,#10 mov r0,#0ffh mov r2,#0ffh W1:djnz r1,w1 w0:djnz r0,w0 w2:djnz r2,w2 ret jmp start end ®Õm tiÕn start:mov dptr,#nhan1 nhan2:mov a,#0h movc a,@a+dptr mov p1,a call wait
  10. inc dptr cjne a,#08eh,nhan2 jmp start wait:mov r0,#5 mov r1,#0ffh mov r2,#0ffh w1:djnz r1,w1 w2:djnz r2,w2 w3:djnz r0,w3 ret nhan1:db 0c0h,0f9h,0a4h,0b0h db 099h,092h,082h,0f8h db 080h,090h,088h,083h db 0c6h,0a1h,084h,08eh end dem tien dem luikhi co tac dong ngat ngoai start: jb p3.3,nhan mov p1,#0ffh jmp start nhan: mov a,p3 cjne a,#0fbh,nhan1 mov dptr,#table2 d1: mov a,#0h movc a,@a+dptr mov p1,a inc dptr cjne a,#0c0h,d1 jmp start nhan1:mov dptr,#table1 dt1:mov a,#0h movc a,@a+dptr mov p1,a inc dptr cjne a,#8eh,dt1 jmp start table1:db 0c0h,0f9h,0a4h,0b0h db 099h,092h,082h,0f8h db 080h,090h,088h,083h db 0c6h,0a1h,086h,08eh table2:db 08eh,086h,0a1h,0c6h db 083h,088h,090h,080h db 0f8h,082h,092h,099h db 0b0h,0a4h,0f9h,0c0h end đếm theo sơ đồ
  11. start: call demtien call demlui jmp start demtien:mov dptr,#nhan1 dt1:mov a,#0h movc a,@a+dptr mov p1,a call wait inc dptr cjne a,#8eh,dt1 ret demlui:mov dptr,#nhan2 dl1:mov a,#0h movc a,@a+dptr mov p1,a call wait inc dptr cjne a,#0c0h,dl1 ret wait:mov r0,#5 mov r1,#0ffh mov r2,#0ffh ;w1:djnz r1,w1 ;w2:djnz r2,w2 w3:djnz r0,w3 ret nhan1:db 0c0h,0f9h,0a4h,0b0h db 099h,092h,082h,0f8h db 080h,090h,088h,083h db 0c6h,0a1h,086h,08eh nhan2:db 086h,0a1h,0c6h db 083h,088h,090h,080h db 0f8h,082h,092h,099h db 0b0h,0a4h,0f9h,0c0h end bai tap hien thi so1va so 0 neu int0=0 thi so 0 neu int0=1 thi so 1 start: jb p3.2,nhan1 mov p1,#0c0h jmp start
  12. nhan1:mov p1,#0f9h end cách 2: start: mov a,#0ffh cjne a,p3,nhan1 mov p1,#0f9h jmp start nhan1:mov p1,#0c0h end hiÓn thÞ sè 0 vµ 1 cã ng¾t ngoµi INT0 start: mov a,p3 cjne a,#0fbh,nhan1 mov p1,#0c0h jmp start nhan1:mov p1,#0f9h end hiÓn thÞ sè 0 vµ 1 cã ng¾t ngoµi nt0 vµ int1 start: jb p3.3,nhan mov p1,#0ffh jmp start nhan: mov a,p3 cjne a,#0fbh,nhan1 mov p1,#0c0h jmp start nhan1:mov p1,#0f9h end hiÓn thÞ sè 0 vµ 1 nhng nhÊp nh¸y start: jb p3.3,nhan mov p1,#0ffh jmp start nhan: mov a,p3 cjne a,#0fbh,nhan1 mov p1,#0c0h mov p1,#0ffh jmp start nhan1:mov p1,#0f9h mov p1,#0ffh end ®Õm tiÕn ®Õm lïi c¸ch2
  13. start: jb p3.3,nhan mov p1,#0ffh jmp start nhan: jb p3.2,dt1 mov dptr,#table2 call ctcon ctcon: d1: mov a,#0h movc a,@a+dptr mov p1,a inc dptr cjne a,#0ffh,d1 ret jmp start dt1:mov dptr,#table1 call ctcon table1:db 0c0h,0f9h,0a4h,0b0h db 099h,092h,082h,0f8h db 080h,090h,088h,083h db 0c6h,0a1h,086h,08eh,0ffh table2:db 08eh,086h,0a1h,0c6h db 083h,088h,090h,080h db 0f8h,082h,092h,099h db 0b0h,0a4h,0f9h,0c0h,0ffh end ®Õm cã dõng start: jb p3.3,nhan jmp start nhan: jb p3.2,dt1 mov dptr,#table2 call ctcon ctcon: d1: mov a,#0h movc a,@a+dptr mov p1,a inc dptr jnb p3.3, start cjne a,#0ffh,d1 ret jmp start dt1:mov dptr,#table1 call ctcon table1:db 0c0h,0f9h,0a4h,0b0h db 099h,092h,082h,0f8h db 080h,090h,088h,083h
  14. db 0c6h,0a1h,086h,08eh,0ffh table2:db 08eh,086h,0a1h,0c6h db 083h,088h,090h,080h db 0f8h,082h,092h,099h db 0b0h,0a4h,0f9h,0c0h,0ffh end đếm từ 1 đến 255 start:mov r0,#0 mov r1,#0 mov r2,#0 hangnghin:mov dptr,#label mov a,r0 movc a,@a+dptr mov p0,a hangtram:mov dptr,#label mov a,r1 movc a,@a+dptr mov p1,a hangchuc: mov dptr,#label mov a,r2 movc a,@a+dptr mov p2,a mov dptr,#label nhan:mov a,#0 movc a,@a+dptr mov p3,a inc dptr cjne a,#90h,nhan inc r2 cjne r2,#6,hangchuc mov r2,#0 inc r1 cjne r1,#0ah,hangtram mov r1,#0 inc r0 cjne r0,#6,hangnghin jmp start label: db 0c0h,0f9h,0a4h,0b0h,099h,092h,082h,0f8h db 80h,90h end BAI TAP: Xác định thời gian của chương trình.
  15. $include(reg52.inc) start: wait:mov R0,#1 w1 :mov R1,#248 w2 :mov R2,#247 loop:djnz R2,loop djnz R1,w2 djnz R1,w1 ret end wait:mov R0,#10 ;2us w1: mov R1,#248 ;2us loop: djnz R1,loop ;248*2 djnz R0,w1 ;2us ret ;2us end ; 2+(2+2+248*2)*10+2=5004 wait: mov R0,#249;2us loop: nop ;1us nop ;1us djnz R0,loop ;2us ret ;2us end ; 2+(1+1+2)*249+2 =1000us=1ms BAI2: $include(reg52.inc) start: mov r0,#0 mov r1,#0 mov r2,#0 lap4: mov dptr,# nhan mov a,r2 movc a,@a+dptr mov p0,a lap3:mov dptr,#nhan mov a,r1 movc a,@a+dptr mov p1,a lap2:mov dptr,#nhan mov a,r0 movc a,@a+dptr mov p2,a lap1:mov a,#0 movc a,@a+dptr mov p3,a inc dptr cjne a,#90h,lap1 inc r0 cjne r0,#6,lap2 mov r0,#0
  16. inc r1 cjne r1,#0ah,lap3 mov r1,#0 inc r2 cjne r0,#6,lap4 jmp start nhan:db 0C0h,0F9h,0A4h,0B0h,99h,92h db 82h, 0F8h,80h,90h end mov R0,#00h chuc:mov DPTR,#tabel mov A,R0 movc A,@A+DPTR mov P1,A mov DPTR,#tabel donvi: clr A movc A,@A+DPTR mov P3,A inc DPTR cjne A,#90h,donvi inc R0 cjne R0,#0Ah,chuc jmp start wait:mov R0,#10 w1 :mov R1,#200 w2 :mov R2,#248 w3 :djnz R2,w3 djnz R1,w2 djnz R0,w1 ret tabel: db 0C0h,0F9h,0A4h,0B0h,99h,92h,82h db 0F8h,80h,90h end wait:mov R0,#10 ;2us w1: mov R1,#248 ;2us loop: djnz R1,loop ;248*2 djnz R0,w1 ;2us ret ;2us end ; 2+(2+2+248*2)*10+2=5004 wait: mov R0,#249;2us loop: nop ;1us nop ;1us djnz R0,loop ;2us ret ;2us end ; 2+(1+1+2)*249+2 =1000us=1ms
  17. $nomod51 $include(AT898252.inc) org 4000h start: mov R0,#249 cpl p1.7 loop: nop djnz R0,loop ret end $nomod51 $include(AT898252.inc) org 4000h start: mov R0,#249 cpl p1.7 call wait jmp start wait: nop djnz R0,wait ret end $nomod51 $include(AT898252.inc) org 4000h start: wait:mov r0 ,#10 w1:mov r1,247 cpl p1.7 loop:nop w2:djnz r1,w2 djnz r0,loop ret end $nomod51 $include(AT898252.inc) org 4000h start: lim2:mov r2,#20 ;20*250*1ms lim1:mov r1,#250 cpl p1.0 lim3:mov r0,#249 ;250*4=1000us dec r0 ;1us mov a,r0 ;2us jnz lim1 djnz r1,lim2 djnz r2,lim3
  18. jmp 8000h end $nomod51 $include(AT898252.inc) org 4000h start: setb p1.1 dec r1 mov a,r1 w: nop dec A jnz w clr p1.1 call wait jmp start wait: mov r4,#6 w1: mov r5,#0ffh w2: mov r6,#0ffh w3: djnz r4,w3 djnz r5,w2 djnz r6,w1 ret end ;viet chuong trinh dieu khien den giao thong o nga ;tu duong pho start:mov p1,#0ffh mov p1,#0f6h call wait25 setb p1.3 clr p1.4 call wait5 mov p1,#0dbh call wait25 setb p1.2 clr p1.1 call wait5 jmp start wait5: mov r0,#64h w1: mov r1,#64h W2: mov r2,#0f8h w3: djnz r2,w3 djnz r1,w2 djnz r0,w1 ret wait25:mov r3,#0fah w4:mov r4,#0c8h w5:mov r5,#0f8h w6:djnz r5,w6
  19. djnz r4,w5 djnz r3,w4 ret end org 4000h LCD_KD: mov a,#00111000b call LCD_DK mov a,#00001110b call LCD_DK call LCD_xoa ret LCD_xoa: mov a,#00000001b call LCD_DK call cho1700 ret LCD_DK: mov r0,#8000h movx @r0,a call cho40 ret LCD_DL: mov r0,#8002h movx @r0,a call cho40 ret cho40: mov a,#12 c40: dec a jnz c40 ret cho1700: mov a,#242 c1700: dec a nop nop nop nop jnz c1700 ret end
  20. $nomod51 $include (at898252.inc) org 4000h start: call lcd_kd mov a,#86h call lcd_dk mov a,#54h call lcd_dl jmp start LCD_KD: mov a,#00111000b call LCD_DK mov a,#00001110b call LCD_DK call LCD_xoa ret LCD_xoa: mov a,#00000001b call LCD_DK call cho1700 ret LCD_DK: mov r0,#8000h movx @r0,a call cho40 ret LCD_DL: mov r0,#8002h movx @r0,a call cho40 ret cho40: mov a,#12 c40: dec a jnz c40 ret cho1700: mov a,#242 c1700: dec a nop nop nop nop
ADSENSE
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2