›XXXXXXXXXXXXXXXXXXXXXXxxxxxxxx CODE XXXXXXXXXXXXXXXXXX ;display MENU at cursor mov dx,offset menu_ms messages mov al,ds:[Offfeh] ;code to AL sget addr of the RS232 card from BIOS data a
Trang 1Chương 12: CHƯƠNG TRÌNH TRUYEN DU
LIỆU TRÊN MÁY TÍNH
'<F3> to display protocol installed',Odh,Oah
'<F4> to open file.hex and trasnmit’,Odh,Oah '<F9> to exit the TERMINAL program’',Odh,Oah 'All character typed are transmitter’ ,Odh,Oah
'All character receiver are display',Odh,Oah
Odh,Oah,'$'
Trang 2db '‘'* Installed communications
‘Baud rate:' '2400',Odh,Oah
db Par% db
db Stop%
db Word% = db
'1J= 110,0dh,0ah
2 = 150 ,0dh,0ah '3 = 300',0dh,0ah '4 = 600',0dh,0ah '5 = 1200',0dh,0ah '6 = 2400',0dh,0ah '7 = 4800',0dh,0ah '8 = 9600',0dh,0ah
'Select: $
0dh,0ah, Pariry: ,0dh,0ah 'l = odd',Odh,Oah
Trang 3db '2=none',0dh,0ah
db '3=even’',Odh,Oah
Stop_menu db Odh,Oah,'Stop bit:',Odh,Oah
db 'I= I stop bir,0dh,0ah
errl_ ms db Odh,OQah,'*** cannot transmit ***',Odh,Oah
card basedw_ 02fSh ›address of RS 232 card
innIT num db Och
setup_byte db Obbh
;Origin
O_int_seg dw 0000h ssegment
O_int_off dw O000h ‘offset
circular buffer and pointer:
circ_buf db 20 dup(OOh)
data ends
Trang 4›XXXXXXXXXXXXXXXXXXXXXXxxxxxxxx CODE XXXXXXXXXXXXXXXXXX
;display MENU at cursor
mov dx,offset menu_ms messages
mov al,ds:[Offfeh] ;code to AL
sget addr of the RS232 card from BIOS data area
;determine interrupt number:
; Obh IRQ4 all other
cmp al,Ofdh
jne set_address
mov int_num,0Obh
;ssave/install interrupt
Trang 6ax,3c00h
test_f3 set_protocol ;E2 key pressed
ax,3d00h
tes(_ 14 show_protocol ;F3 key pressed
ax,3e00h
test_f9 tran_file ;F4 key pressed
Trang 8sub al,1 sto range 0 to 7
Trang 10mov si,offset stop%
mov byte ptr[si],al
Trang 11jnc word_length
push ax
;sInput in valid range Add 6 and move input to display area
add _ al,6
mov si,offset word%
mov byte ptr[si],al
Trang 13© OE IS 2s ** x k * š % % X % k * * š % * x k * % k X % * š * * X k % X k ois * k š k* * ** k%
’
7K FS 28 2 28 26 2g ok 2 ok
;CAC CHUONG TRINH CON
comm_on proc near
chi sinterrupt off
sreset buffer pointer to start of buffer
Trang 14comm_off proc near
short $+2
comm_ off endp
show_message proc near
ax al,0dh
not_cr
al,0ah tty_one
ret
near
Trang 16out 20h,al
jmp_ short $+2 pop ds
pop di
pop dx
Trang 17pop bx
pop ax
iret
›XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXX
tran_ File:
call get name ;doc ten file
lea dx,filename ;dx chua offset cua ten file
lea dx,buffer ;tro to1 vung dem
mov bx,handle ;lay the file
call read doc file, AX = so byte doc duoc
Or ax,ax ket thuc file
J© pexit ;dung, ket thuc file
mov cx,ax ;CX chua so byte doc duoc
call display _ ;hien thi file
jmp read_loop ;lap lai
open_error:
add errcode,al
mov ah,9
int 21h shien thi thong bao loi
© OE IS 2s ** x k * š % % X % k is 2s 2s ois 2s 24s 2s 2k fs 2s 2s % * š * * is 2s 2s 2s 2s ois * k ois 2s ois ok os 2k ok ok
’
7K FS 28 2 28 26 2g ok 2 ok
Trang 18;oufput and display
;wait period timed out,display error message and exit
mov dx,offset errl_ms
lea di,buffrr tro to1 vung dem
out dx,al
jmp_ short $+2
call edelay
Trang 19inc di
loop ppl
display character
call tty
ppexit:mov bx,handle ;lay the file
lea di,filename DI tro toi ten file
mov ah,1 sham doc ki tu tu ban phim
read_name:
int 21h
je done ;dung ket thuc
done: mov al,0
stosb sluu byte 0
pop di
pop dx
Trang 20pop ax
ret
get_name endp
open proc near
mov ah,3dh sham mo file
mov al,0 ›ch1 doc
mov ah,40h sham ghi file
mov bx,1 ‘the file cho man hinh
int 21h ;dong file
Trang 21mov ah,3eh sham dong file
int 21h ;dong file
Trang 22mov [si],al
Sl XXx8
s1,buffrr dI,buffer
mov al,[di] slay byte data al,3ah ›so sanh voI ma dau ':' xxx2 ,nhay neu la dau ':
di xxx3 ;quay lai de tim dau ':'
ax,0 ;dung la het data thi lam cho AX=0000
di
Sl
xu li so byte can gol
MOV al,[di] slay so can got MSD
Trang 23cL4 al,cl
ah,al
di al,[di]
al,30h so_lon
alah
[si],al
al, 1 dl,al
;or 2 data lai thanh | byte
scatso HEX ADDR_H
sluu so byte can xu li con lai
xu li phan dia chi can gol
al,30h so_lon
cl,4 al,cl
ah,al
di al,[di]
al,30h so_lon
alah
[si],al goi_ht
slay byte ADDR_L-MSD
‘tru di 30 de thanh so hex kiem tra so ABCDEE
slay byte ADDR_L-LSD
‘tru di 30 de thanh so hex kiem tra so ABCDEE
;or 2 data lai thanh | byte
scatso HEX ADDR_H
Trang 24xu li cac byte con lai
al,30h so_lon
cL4 al,cl
ah,al
di al,[di]
al,30h so_lon
alah
[si],al goi_ht
di
di
inc di
Sl al,[di]
al,30h so_lon
cl,4 al,cl
ah,al
di al,[di]
al,30h so_lon
slay byte ADDR_H-MSD
‘tru di 30 de thanh so hex kiem tra so ABCDEE
slay byte ADDR_H-LSD
‘tru di 30 de thanh so hex kiem tra so ABCDEE
;or 2 data lai thanh | byte
;cat so byte can goI dang HEX
sbo byte 00
9
slay so byte thu nhat
‘tru di 30 de thanh so hex kiem tra so ABCDEE
;lay so byte thu 2
›ru đi 30 de thanh so hex kiem tra so ABCDEE
Trang 25dl d1,0
XXX |
di
di
di XXx3 endp
;or 2 data lai thanh | byte
;cat so byte can goI dang HEX
;quay lai v1 chua sbo byte cuoi thu nhat sbo byte thu 2
;bo ma Xuong hang
shet | hang data
;chuong trinh kiem tra ket thuc
ktra_end proc near
al,30h kt_exit
di al,[di]
al,30h kt_exit
di al,[di]
al,30h kt_exit
di al,[di]
al,30h
slay byte data skiem tra byte 0 thu nhat snhay den de thoat vi khong phai
sneu dung thi kiem tra byte 0 thu 2
slay byte data
snhay den de thoat vi khong phai
sneu dung thi kiem tra byte 0 thu 3
slay byte data
snhay den de thoat vi khong phai
sneu dung thi kiem tra byte 0 thu 4
slay byte data
Trang 26al,30h kt_exit
di al,[di]
al,30h kt_exit
di al,[di]
al,30h kt_exit
di al,[di]
al,31h
kt_exit
di al,[di]
al,46h kt_exit
ax,0
di
ax,l111h
snhay den de thoat vi khong phai
sneu dung thi kiem tra byte 0 thu 5
slay byte data
snhay den de thoat vi khong phai
sneu dung thi kiem tra byte 0 thu 6
slay byte data
snhay den de thoat vi khong phai
sneu dung thi kiem tra byte 0 thu 7
slay byte data
snhay den de thoat vi khong phai
sneu dung thi kiem tra byte | thu 8
slay byte data
snhay den de thoat vi khong phai
sneu dung thi kiem tra byte F thu 9
slay byte data
snhay den de thoat vi khong phai
sneu dung thi kiem tra byte F thu 10
slay byte data
snhay den de thoat vi khong phai
snap data sao cho khac khong la 1