* Lưu đồ chương trình truyền dữ liệu. BEGIN KHỞI PHÁT: GHI TỪ CHẾ ĐỘ GHI LỆNH : DTR, TxEN ĐỌC TRẠNG THÁI: DSR, TxRDy Kiểm tra sẵn sàng :DSR= TxRDY=1 GHI SỐ LIỆU RA GHI LỆNH PHÁT: RTS END * Lưu đồ chương trình nhận dữ liệu. BEGIN KHỞI PHÁT: GHI TỪ CHẾ ĐỘ GHI L ỆNH : DTR, RxEN,RTS ĐỌC TRẠNG THÁI: DSR, RxRDy Kiểm tra sẵn sàng :DSR= RxRDY=1 ĐỌC SỐ LIỆU TỪ THANH GHI ĐỆM SỐ LIỆU END 3. CHệễNG TRèNH. a. Chửụng trỡnh khụỷi taùo 8251A. MOV DX, 0FFF2h MOV AL,00h OUT DX,AL MOV CX 2h D0 : LOOP D0 OUT DX, AL D1: MOV CX,2h LOOP D1 OUT DX, AL MOV CX,2h D2: LOOP D2 MOV AL, 40h OUT DX, AL MOV CX, 2h D3: LOOP D3 MOV AL, 11001110B OUT DX, AL MOV CX, 2h D4: LOOP D4 MOV CX, 6500h MOV AL,03h OUT 01h Chửụng trỡnh truyen dửừ lieọu. ;chuong trinh truyen du lieu org 70000h mov dx 02h ;dia chi thanh ghi dieu khien mov al,00h out dx,al ;xoa thanh ghi dieu khien call delay out dx,al call delay out dx,al call delay mov al,40h ; goi 40h vao al, gia tri cua bit RI out dx,al ;de xoa thanh ghi noi call delay mov al,0cdh ; ghi loi dieu khien che do vao out dx,al ;thanh ghi dieu khien che do call delay mov cx,6500h ; dia chi dieu khien mov al,03h ; ghi tu che do DTR(D1=1),TxEN(D0=1) out dx,al call delay x1: in al,dx and al,81h ; kiem tra trang thai cmp al,81h jnz x1 mov dx,cx mov al,m mov bl,al ; nap byte dia chi tap vao bl mov dx,00h out dx,al ;gui byte dia chi thap call delay mov al,21h ; ghi tu lenh DTS(D5),TxEN(D0) de truyen mov dx,01h out dx,21h call delay inc cx ;tang dia chi de lay byte ke tiep mov al,03h out dx,al call delay mov dx,01h x2: in al,dx and al,81h cmp al,81h jnz x2 mov dx,00h in al,dx mov dx,cx mov al,m mov bh,al ;nap dia chi cao vao bh out dx,al ;truyen byte dia chi cao call delay mov al,21h mov dx,01h out dx,al ;ra lenh truyen call delay mov dx,01h x3: in al,dx and al,81h cmp al,81h jnz x3 mov dx,cx mov al,m mov dx ooh out dx,al ;gui so byte can truyen mov ah,al x5: mov al,21h out dx,al call delay mov dx,01h x4: in al,dx and al,81h cmp al,81h jnz x4 mov dx,bx ;tuyen du lieu can truyen mov al,m mov dx,00h out dx,al inc bx dec ah mov al,21h mov dx,o1h out dx,al jnz x5 end Chöông trình nhaän döõ lieäu. ;chuong trinh con delay delay: push cx mov cx,03h y0: loop y0 pop cx ret ;chuong trinh nhan du lieu org 70000h mov dx 01h ;dia chi thanh ghi dieu khien mov al,00h out dx,al ;xoa thanh ghi dieu khien call delay out dx,al call delay out dx,al call delay mov al,40h ; goi 40h vao al, gia tri cua bit RI de xoa thanh ghi noi out dx,al call delay mov al,0cdh; ghi loi dieu khien che do vao thanh ghi dieu khien out dx,al call delay mov al,26h ; ghi tu che do RTR(D1=1),RxEN(D0=1) out dx,al call delay y1: in al,dx and al,82h; kiem tra trang thai cmp al,82h jnz y1 mov dx,00h in al,dx mov bl,al; nap byte dia chi tap vao bl mov dx,01h y2: in al,dx and al,82h cmp al,82h jnz y2 mov dx,00h in al,dx mov bh,al mov dx,01h y3: in al,dx and al,82h cmp al,82h jnz y3 mov dx ooh in dx,al ;nhan so byte truyen mov ah,al mov dx,01h ;nhan du lieu y4: in al,dx and al,82h cmp al,82h jnz y4 mov dx,00h in al,dx mov dx,bx mov m,al inc bx jnz x4 end II. CHÖÔNG TRÌNH TRUYEÀN DÖÕ LIEÄU TREÂN MAÙY TÍNH ; TERMINAL.ASM ; STACK stack segment stack db 300 dup('?') stack ends ; DATA data segment prompt db 'File name:$' filename db 30 dup(0) buffer db 512 dup(0) buffrr db 512 dup(0) handle dw ? openerr db 0dh,0ah,'OPEN ERROR - COPDE' errcode db 30h,'$' ;messages MENU_MS db ' **TERMINAL PROGRAM**',0dh,0ah db '<F1> to redisplay this MENU',0dh,0ah db '<F2> to set communications protocol',0dh,0ah db '<F3> to display protocol installed',0dh,0ah db '<F4> to open file.hex and trasnmit',0dh,0ah db '<F9> to exit the TERMINAL program',0dh,0ah db 'All character typed are transmitter',0dh,0ah db 'All character receiver are display',0dh,0ah db 0dh,0ah,'$' PROT_MS db '* Installed communications protocol',0dh,0ah db 'Baud rate:' Baud% db '2400',0dh,0ah db 'Parity:' Par% db 'Even',0dh,0ah db 'Stop bit:' Stop% db '1',0dh,0ah db 'Word length:' Word% db '8',0dh,0ah,0ah,'$' Baud$$ db '110 150 300 600 1200 2400 4800 9600' Par$$ db 'odd noneven' baud_menu db 0dh,0ah,'**New communication parameter' db 'rs input **',0dh,0ah db 'baud rate:',0dh,0ah db '1 = 110',0dh,0ah db '2 = 150',0dh,0ah db '3 = 300',0dh,0ah db '4 = 600',0dh,0ah db '5 = 1200',0dh,0ah db '6 = 2400',0dh,0ah db '7 = 4800',0dh,0ah db '8 = 9600',0dh,0ah db 'Select: $' par_menu db 0dh,0ah,'Pariry:',0dh,0ah db '1 = odd',0dh,0ah db '2 = none',0dh,0ah db '3 = even',0dh,0ah db 'Select: $' Stop_menu db 0dh,0ah,'Stop bit:',0dh,0ah db '1 = 1 stop bit',0dh,0ah db '2 = 2 stop bit',0dh,0ah db 'Select: $' Word_menu db 0dh,0ah,'Word length:',0dh,0ah db '1 = 7 bit',0dh,0ah db '2 = 8 bit',0dh,0ah db 'Select: $' err1_ms db 0dh,0ah,'*** cannot transmit ***',0dh,0ah card_base dw 02f8h ;address of RS 232 card inT_num db 0ch setup_byte db 0bbh ; ;Origin O_int_seg dw 0000h ;segment O_int_off dw 0000h ;offset ;circular buffer and pointer: circ_buf db 20 dup(00h) dw 0 data_in dw 0 ;input pointer data_out dw 0 ;output pointer data ends ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx CODE xxxxxxxxxxxxxxxxxx code segment assume CS:code start: mov ax,data mov ds,ax assume ds:data mov es,ax assume es:data ;display MENU at cursor mov dx,offset menu_ms ;messages call show_message ;hardware type push ds mov dx,0f000h mov ds,dx mov al,ds:[0fffeh] ;code to AL ;get addr of the RS232 card from BIOS data area mov dx,0 mov ds,dx mov cx,ds:0400h pop ds mov card_base,cx ;determine interrupt number: ; 0bh IRQ4 all other cmp al,0fdh jne set_address mov int_num,0bh ;save/install interrupt set_address: mov ah,53 mov al,int_num int 21h mov o_int_seg,es mov o_int_off,bx mov ah,37 mov al,int_num mov dx,offset cs:rs232_int push ds . * Lưu đồ chương trình truyền dữ liệu. . Kiểm tra sẵn sàng :DSR= TxRDY=1 GHI SỐ LIỆU RA GHI LỆNH PHÁT: RTS END * Lưu đồ chương trình nhận dữ liệu. BEGIN . dx,00h out dx,al inc bx dec ah mov al,21h mov dx,o1h out dx,al jnz x5 end Chöông trình nhaän döõ lieäu. ;chuong trinh con delay delay: push cx mov cx,03h y0: loop y0 pop