Board logo

标题: 谁能给我一份DOS下串口编程的资料或者源代码?谢谢! [打印本页]

作者: wwm_820924     时间: 2005-2-22 00:00    标题: 谁能给我一份DOS下串口编程的资料或者源代码?谢谢!
刚开始学习DOS下串口编程,谁能给我一份DOS下串口编程的资料或者源代码?谢谢!

作者: wwm_820924     时间: 2005-2-23 00:00
对拉,我的邮箱是wwm_820924@sohu.com或wwm_820924@163.com

作者: stamp     时间: 2005-2-25 00:00    标题: serial
我以前写的一个串口程序,看看对你有没有帮助,我比较懒,没有注释,你研究串口,根据具体的名称应该可以明白他们的含义

打开附件

作者: wwm_820924     时间: 2005-2-25 00:00    标题: [原创]
打开附件

首先感谢stamp。
在此我找了一份龚建平伟的源码,一起给大家共享,有需要的下载

作者: rocchapter     时间: 2005-11-29 14:30
我在学校时用过一个代码是电力系统模拟控制程序,其精髓就是RS232的通信编程,不知道还在不在

作者: Neat     时间: 2005-12-17 22:15
我也想要一份看看

作者: syking117     时间: 2006-3-28 15:10
不知道还有没有人理这贴,我也想要一个,能不能给我传一个(sykings@peoplemail.com.cn),谢谢

作者: cliffwb     时间: 2006-6-21 00:07
附件都下不了啊,wbin_mail@sohu.com

现已修正(管理员注 2009-4-22)

作者: mengy     时间: 2006-6-29 11:14    标题: 来看看这个吧
还是转来的,对基本原理已经讲的比较清除,自己修改一下就可以了。
附件 1: dos串口通讯原码.c (2006-6-29 11:14, 5.12 KiB, 下载附件所需积分 1点 ,下载次数: 284)

作者: lisa888     时间: 2006-10-7 09:10
谢谢!

作者: chanjoh     时间: 2007-8-23 20:37
下了谢谢!先看看合用不

作者: nokor     时间: 2007-8-27 22:49
这里人好热心啊!!谢谢了

作者: agang220     时间: 2007-9-11 16:52
非常感谢

作者: BA_WANG_MAO     时间: 2007-9-12 15:52
MS-DOS 6.22 下如何编程控制RS232串口详细资料及源程序

http://www.cn-dos.net/forum/viewthread.php?tid=33505

作者: junzhangsh     时间: 2007-11-18 03:10
太好了呀

作者: shim     时间: 2007-11-21 10:49
谢谢分享!

作者: jojand     时间: 2007-11-22 11:08
A机的发送端(TX)与B机的接收端(RX)相连,A机的接收端(RX)与B机的发送端(TX)相连,两机的地线(GND)相连;

发送:
OPEN "COM1:1200,N,8,1,RS,CS,DS" AS #1
PRINT #1,"OK"
CLOSE #1

接收:
OPEN "COM1:1200,N,8,1,RS,CS,DS" AS #1
INPUT #1,A$
CLOSE #1

作者: maclover815     时间: 2007-12-13 22:46    标题: nice
good

作者: shlinno     时间: 2007-12-19 15:49
不错啊,我也需要一个

作者: gaoxy2008     时间: 2008-4-11 10:25
非常感谢

作者: dragon123321     时间: 2008-4-11 17:30
呵呵。。串口并口编程,我的代码
http://hi.baidu.com/大伦子

作者: dragon123321     时间: 2008-4-11 17:31
转载时请留言哦。。我只是想认识几个朋友罢了,交流交流编程罢了,呵呵

作者: netwinxp     时间: 2008-4-17 09:06
Originally posted by jojand at 2007-11-22 11:08:
A机的发送端(TX)与B机的接收端(RX)相连,A机的接收端(RX)与B机的发送端(TX)相连,两机的地线(GND)相连;

发送:
OPEN "COM1:1200 ...

对,居于com设备句柄的操作更省事。
另:单片机方面可以用232芯片(如max232)来实现电平匹配从而降低对电源的要求,以前的电流环在设计中比较容易出现意外。

作者: danieldy     时间: 2008-5-15 12:42
我想下载,可是积分不够

作者: Pauly     时间: 2008-5-15 13:53
下来学习下

作者: ycjyh007     时间: 2008-5-16 16:15
非常感谢~学习中

作者: yhoyo     时间: 2008-5-16 17:03
看看...学习

作者: saliwen302     时间: 2008-5-21 11:43
ding qi !!

作者: lqhlqg123     时间: 2008-5-21 18:48
下载了,谢谢

作者: saliwen302     时间: 2008-5-22 14:50    标题: 贴一段phoenix 的int 14h的code吧
先是注释:
;----------------------------------------------------------------------------
;
; I N T E R R U P T 1 4
;
; coreBiosSerialInterface - The BIOS serial interface supports the
; Intel 8250 Serial chip.
; Functions available are init, send, receive, and status.
;
;
; AH = 00 - Initialize Communications Port
; Entry: DX - COM adapter to initialize (0-3)
; AL - Initialization values
;
; 7 6 5 4 3 2 1 0
; Baud rate Parity stop bits Word length
; ---------------------------------------
; 000-110 00-None 0-1 10-7 Bits
; 001-150 01-Odd 1-2 11-8 Bits
; 010-300 10-None
; 011-600 11-Even
; 100-1200
; 101-2400
; 110-4800
; 111-9600
; Exit: AH - Line status
;
;
; AH = 01 - Send Character
; Entry: DX - Communication adapter number (0-3)
; AL - Character to send
; Exit: AH - Line Status
;
;
; AH = 02 - Receive Character
; Entry: DX - Communcation adapter number (0-3)
; Exit: AL - Character received
; AH - Line Status
;
;
; AH = 03 - Return Communication Status
; Entry: DX - Communication adapter number (0-3)
; Exit: AL - Modem status
; Bit 0 - Delta clear to send
; Bit 1 - Delta data set ready
; Bit 2 - Trailing edge ring indicator
; Bit 3 - Delta (RLSD)
; Bit 4 - Clear to send
; Bit 5 - Data set ready
; Bit 6 - Ring indicator
; Bit 7 - Received line signal detect
;
; AH - Line status
; Bit 0 - Data ready
; Bit 1 - Overrun error
; Bit 2 - Parity Error
; Bit 3 - Framing Error
; Bit 4 - Break detect
; Bit 5 - Trans holding register empty
; Bit 6 - Trans shift register empty
; Bit 7 - Time out error
;
; AH = 04 - Extended Initialize (PS2 compatibility)
; Entry: DX - Communication adapter number (0-3)
; AL - Break
; 00H - No Break
; 01H - Break
; BH - Parity
; 00H - None
; 01H - Odd
; 02H - Even
; 03H - Stick parity odd
; 04H - Stick parity even
; BL - Stop Bit
; 00H - One
; 01H - Two if 6,7, or 8 bit word length
; One and one-half if 5 bit word length
; CH - Word Length
; 00H - 5 bits
; 01H - 6 bits
; 02H - 7 bits
; 03H - 8 bits
; CL - Baud Rates
; 00H - 110 baud
; 01H - 150 baud
; 02H - 300 baud
; 03H - 600 baud
; 04H - 1200 baud
; 05H - 2400 baud
; 06H - 4000 baud
; 07H - 9600 baud
; 08H - 19200 baud
;
; Exit: AL - Modem status
; Bit 0 - Delta clear to send
; Bit 1 - Delta data set ready
; Bit 2 - Trailing edge ring indicator
; Bit 3 - Delta (RLSD)
; Bit 4 - Clear to send
; Bit 5 - Data set ready
; Bit 6 - Ring indicator
; Bit 7 - Received line signal detect
;
; AH - Line status
; Bit 0 - Data ready
; Bit 1 - Overrun error
; Bit 2 - Parity Error
; Bit 3 - Framing Error
; Bit 4 - Break detect
; Bit 5 - Trans holding register empty
; Bit 6 - Trans shift register empty
; Bit 7 - Time out error
;
; AH = 05 - Extended Communications Port Control (PS2 compatibility)
; Entry: AL = 0 Read modem control register
; DX - Communication adapter number (0-3)
; Exit BL = Modem control register
;
; Entry AL = 01 Write modem control register
; DX - Communication adapter number (0-3)
; BL - Modem Control Register
;
; Exit: AL - Modem status
; Bit 0 - Delta clear to send
; Bit 1 - Delta data set ready
; Bit 2 - Trailing edge ring indicator
; Bit 3 - Delta (RLSD)
; Bit 4 - Clear to send
; Bit 5 - Data set ready
; Bit 6 - Ring indicator
; Bit 7 - Received line signal detect
;
; AH - Line status
; Bit 0 - Data ready
; Bit 1 - Overrun error
; Bit 2 - Parity Error
; Bit 3 - Framing Error
; Bit 4 - Break detect
; Bit 5 - Trans holding register empty
; Bit 6 - Trans shift register empty
; Bit 7 - Time out error
;
;============================================================================

作者: saliwen302     时间: 2008-5-22 14:52    标题: 贴一段phoenix 的int 14h的code吧 2
这个是int 14h的入口函数,用来dispatch任务

;============================================================================
;
; DECLARE SERIAL COMMAND TABLE
;
PUBLIC coreSerialCmdTable
coreSerialCmdTable LABEL WORD
DW coreSerialInit
DW coreSerialSend
DW coreSerialReceive
DW coreSerialStatus
DW coreExtendedSerialInit
DW coreExtendedPortControl


coreBiosSerialInterface PROC FAR
sti
PUSH_REG_STACK ; Save regs, set BP
cmp ah, 05 ; Command out of range?
ja serialExit ; Yes - Don't do anything
cmp dx, 3 ; Requesting > COM4?
ja serialExit ; Yes - Don't do anything
mov ds, SegAddressBDA ; Access BIOS data area
mov bx, dx ; Get COM channel number
mov cl, bdaRS232TimeOut[bx] ; Get timeout value
shl bx, 1 ; Double for Base address
mov dx, bdaRS232Table[bx] ; Read base address for COM
or dx, dx ; Test for COM not available
jz serialExit ; Yes-Dont do anything
movzx bx, ah ; Save command number in BX
mov ah, cl ; Keep timeut in AH
shl bx, 1 ; Double for table offset
add dx, 04 ; Advance DX to MCR

call cs:coreSerialCmdTable[bx] ; Go perform command

serialExit:
mov BYTE PTR [bp].regStack.axReg + 1, ah ; Save line status in AH
POP_REG_STACK ; Restore callers registers
iret
coreBiosSerialInterface ENDP

作者: saliwen302     时间: 2008-5-22 14:54    标题: 贴一段phoenix 的int 14h的code吧 3
两个macro,帮助理解程序:

;;---------------------------------------------------------------------------
;;
;; PUSH_REG_STACK - set up register stack
;;
;; Processing:
;; pushes all regs associated with register stack structure
;; copies SP to BP
;;
;; Usage:
;; PUSH_REG_STACK - to set up register stack
;; [bp].regStack.axReg - to reference AX register on regStack
;;
PUSH_REG_STACK MACRO
pusha
push es
push ds
mov bp, sp
ENDM

;;---------------------------------------------------------------------------
;;
;; POP_REG_STACK - restore regs from register stack
;;
;; Usage:
;; POP_REG_STACK - to restore regs from register stack
;;
POP_REG_STACK MACRO
pop ds
pop es
popa
ENDM

作者: saliwen302     时间: 2008-5-22 14:55    标题: 贴一段phoenix 的int 14h的code吧 3
Init COM的代码,分为legacy init和extend mode init

;+---------------------------------------------------------------------------
;
; coreSerialInit - Initialize the specified RS232 channel.
;
; Entry:
;
; Exit:
;
; Modifies:
;
; Processing:
; Initialization consists of programming the line control registers,
; the baud rate divisor, and clearing the interrupt enable register.
;
coreSerialInit PROC NEAR PUBLIC
and al, 01Fh ; Clear Baud bits from init
mov ch, al ; Save to restore w DLAB off
or al, 080h ; Set the DLAB bit on
dec dx ; Decrement to LCR (xFBH)
out dx, al ; Keep Stick and Set Break low
mov al, BYTE PTR [bp].regStack.axReg ; Get init byte again
mov cl, 05 ; Shift baud bits down
shr al, cl ; to bit 0 position
mov cl, al ; Save baud rate number
or al, al ; Are we setting 110 baud ?
mov ax, 417h ; Handle 110 baud special
jz setBaudRate ; Yes-Use value in AX
mov ax, 0600h ; Compute divisor based
shr ax, cl ; on baud rate number

setBaudRate:
xchg al, ah ; Get high divisor into AL
dec dx ; Move back to high divisor
dec dx ; located at xF9H.
out dx, al ; Write MSB of divisor
IODELAY
dec dx ; Move back to LSB of divisor
mov al, ah ; Get LSB divisor byte
out dx, al ; Write at xF8H.
add dx, 03 ; Advance to LCR
mov al, ch ; Get LCR value w/o DLAB set
out dx, al ; Write LCR (xFBH)
sub dx, 02 ; Go back to interrupt
mov al, 00 ; Dont allow any 8250
out dx, al ; interrupts occur
add dx, 03h ; Move to (LSR-1) (xFCH)
jmp coreSerialStatus ; Go return Line & Modem status
coreSerialInit ENDP


;+---------------------------------------------------------------------------
; coreExtendedSerialInit - For PS/2 Compatibility
; Extended communications port initialization.
;
; Entry:
; DX points to MCR
;
; Exit:
;
; Modified:
;
coreExtendedSerialInit PROC NEAR PUBLIC
mov cx, [bp].regStack.cxReg
cmp cl, 8
ja extendedSerialInitEx
xor ch, ch ; Retrieve the baud rate divisor
shl cx, 1 ; and set the baud rate.
mov di, cx
mov bx, baudDivisorTable[di]
dec dx ; Reference the line control register.
push ax
call setBd
pop ax
and al, 00000001b ; Use only the break/no break.
shl al, 6 ; Build the line control word. AL is
mov bx, [bp].regStack.bxReg
shl bl, 2 ; Break/no break, BL is stops,
or al, bl ; Doesn't match the control register's
mov cx, [bp].regStack.cxReg
or al, ch
mov bl, bh
and bx, 00000111b
or al, BYTE PTR BHTranslate[BX]
out dx, al ; Set LCR
IODELAY
sub dx, 02 ; Go back to interrupt
mov al, 00 ; Dont allow any 8250
out dx, al ; interrupts occur
add dx, 03h ; Move to MCR

ExtendedSerialInitEx:
jmp coreSerialStatus ; Go return Line & Modem status
coreExtendedSerialInit ENDP

作者: saliwen302     时间: 2008-5-22 14:56    标题: 贴一段phoenix 的int 14h的code吧 4
然后是发送和接受


;+---------------------------------------------------------------------------
;
; coreSerialSend - Send specified character to 8250 Serial Device.
;
; Entry:
;
; Exit:
;
; Modifies:
;
; Processing:
; Before the data is sent, CTS and DTR must be set and the tranmitter
; holding register must be empty.
;
coreSerialSend PROC NEAR PUBLIC
movzx cx, ah ; Set timeout in CX
mov al, 03h ; Set DTR and RTS
out dx, al ; Write to MCR (xFCH)
inc dx ; Advance to Modem status
inc dx ; register (MSR at xFEH)

sendWaitLoop:
push cx ; Save Timeout count
mov bx, 3030h ; Mask for CTS and DSR
mov cx, 8235h ; Wait for 1 sec

call coreIOstatus30us ; Wait for CTS and DSR
jz lsrTranReg
pop cx ; Restore count
loop sendWaitLoop ; Loop again if I/O timeout
jmp coreSerialTimeout

lsrTranReg:
pop cx
dec dx ; Else-Move back to LSR

transmitWait:
push cx ; Save timeout
mov bx, 2020h ; Wait for Transmit Reg empty
mov cx, 8235h
call coreIOstatus30us
pop cx ; Restore timeout
loopne transmitWait ; Go wait if not ready and time left
jnz coreserialTimeout ; Exit if error

serialTransmit:
sub dx, 05 ; Move back to Data reg (xF8H)
mov al, BYTE PTR [bp].regStack.axReg ; Get byte to send
out dx, al ; Send it to 8250
add dx, 05 ; Advance to LSR
jmp coreserialStatus1 ; Go return Line Status

coreSerialTimeout::
mov ah, 080h ; Return timeout error
ret
coreSerialSend ENDP

;+---------------------------------------------------------------------------
;
; coreSerialReceive - Receive a character from the 8250.
;
; Entry:
;
; Exit:
;
; Modifies:
;
; Processing:
; In order for a character to be received, DSR must be set in
; the modem status register and em status register and data ready must be set in the
; line status register. If the break key is pressed during the
; timeout period, then a premature timeout will occur.
;
coreSerialReceive PROC NEAR PUBLIC
movzx cx, ah ; Set timeout in CX
mov al, 01 ; Set DTR in MCR
out dx, al ; Write to Modem Control reg
inc dx ; Advance to modem status
inc dx ; register (MSR at xFEH)

dsrWaitLoop:
push cx ; Save timeout count
mov bx, 2020h ; Mask for DSR
mov cx, 8235h ; Wait for 1 sec
call coreIOstatus30us ; Wait for DSR - All registers
; are preserved across call
pop cx ; Restore count
jz checkLsrDataRdy
loop dsrWaitLoop ; Loop again if I/O timeout
jmp coreSerialTimeout ; Exit if error

checkLsrDataRdy:
dec dx ; Else-Decrement to LSR
in al, dx ; Read LSR
mov ah, al ; Save line status
and ah, 1Eh ; Isolate error bits

receiveWait:
push cx ; Save timeout
mov bx, 0101h ; Mask for Data Ready
mov cx, 8235h ; 1 sec wait
call coreIOstatus30us ; Wait for Data Ready - All registers
; are preserved across call
pop cx ; Restore timeout
loopne receiveWait ; Go wait if not ready and time left
jnz coreSerialTimeout ; Exit if error

coreDataReady:
sub dx, 05 ; Move back to data register
in al, dx ; Read character from line
mov BYTE PTR [bp].regStack.axReg, al ; Save character in AL
ret ; Return to caller
coreSerialReceive ENDP

作者: saliwen302     时间: 2008-5-22 14:58    标题: 贴一段phoenix 的int 14h的code吧 5
取得当前COM状态的函数

;+---------------------------------------------------------------------------
;
; coreSerialStatus - Return the status of the line status register
; and the modem status register.
;
; Entry:
;
; Exit:
;
coreSerialStatus PROC NEAR PUBLIC
inc dx ; Advance to LSR
call coreSerialStatus1 ; Read status of registers
mov BYTE PTR [bp].regStack.axReg, al ; Save the Modem status in AL
ret
coreSerialStatus ENDP

;+---------------------------------------------------------------------------
;
; coreSerialStatus1 - Return the status of the line status register
; and the modem status register.
;
; Entry:
;
; Exit:
;
coreSerialStatus1 PROC NEAR PUBLIC
in al, dx ; Read Line Status register
mov ah, al ; Save line status in AH
inc dx ; Advance to Modem status reg
in al, dx ; Read modem status register
ret
coreSerialStatus1 ENDP

作者: saliwen302     时间: 2008-5-22 14:59
最后一个函数,如果是用 ah=05 int 14h的话,就会到以下这个函数执行。


;+---------------------------------------------------------------------------
;
; coreExtendedPortControl - For PS/2 compatability
;
; Entry:
; DX points to MCR
;
; Exit:
;
coreExtendedPortControl PROC NEAR PUBLIC
cmp al, 1 ; Check function in range
je ecpcWrite ; If AL == 1, then WRITE requested.
jb ecpcRead ; If AL == 0, then READ requested.
ret

; the READ returns the contents of the Modem Control Port, of the Line Status
; Register, and of the Modem Status Register.

ecpcRead:
in al, dx ; Read it and
mov BYTE PTR [bp].regStack.bxReg, al
jmp ecpcExit

; the WRITE sets the contents of the Modem Control Register, and then returns
; the contents of the Modem Status Register and of the Line Status Register.

ecpcWrite:
mov al, BYTE PTR [bp].regStack.bxReg ; Get original bx
and al, 01Fh
out dx, al ; Set modem control

ecpcExit:
IODELAY
jmp coreSerialStatus
coreExtendedPortControl ENDP

作者: saliwen302     时间: 2008-5-22 15:04    标题: 贴一段phoenix 的int 14h的code吧 6
以下这个函数是在发送和接受的时候会用到的。这个是一个通用的函数,不得不佩服Phoenix的功力。

至于里面调用的coreDelayMin15us的实现是通过读取acpi timer来实现的。这个就要看具体的南桥的spec了。就不贴了。

;+---------------------------------------------------------------------------
;
; coreIOStatus30us - Wait a specified time for an IO port status
;
; Entry:
; BH - Mask
; BL - Match
; CX - Time in 30us
; DX - IO Address
;
; Exit:
; ZF = 0 - Timed out waiting for desired status
; = 1 - Data value matched
;
; Modifies:
; Minor flags
;
; Process:
; This routine waits until either the specified port matches
; the desired state or for the specified time to expire.
;
coreIOStatus30us PROC NEAR PUBLIC
push ax
push ecx

movzx ecx, cx ; Convert to 15uS intervals
shl ecx, 1
jmp IOS30CheckEntry

IOS30Check:
push cx

mov cx, 1 ; Delay at least 15us
call coreDelayMin15us

pop cx

IOS30CheckEntry:
in al, dx ; AL := Current value of target port
and al, bh ; Eliminate don't care bits
cmp al, bl ; Remaining bits = expected pattern?
je IOS30GotStatus ; Yes-Exit check loop
loopd IOS30Check ; No -Repeat until timer expires

IOS30GotStatus:
pop ecx
pop ax
ret
coreIOStatus30us ENDP

作者: biqiang     时间: 2008-5-23 15:07
学习一下吧,现在想弄一下DOS下Modem通讯

作者: yanchunyun     时间: 2008-7-16 11:53
一直都沒上論壇,積分居然為 0,丟人啊!

作者: cmangel     时间: 2008-8-28 23:17
谢谢,没想到这里有我想找的东东,好好学习一下,太感谢了。

作者: 112223333     时间: 2009-2-15 17:35
xiexie

作者: zhanglitao422     时间: 2009-2-23 12:29
关注中,看看。。

作者: weiguohua     时间: 2009-3-16 00:03    标题: 2008
这年头搞这个的人不多见了.

作者: chali     时间: 2009-4-9 23:30
ding

作者: lonegoer     时间: 2009-4-21 12:41
有没有具体点的关于rts,dtr握手处理相关的串口c源码啊?

作者: saline     时间: 2009-4-27 10:40
看看哦

作者: djxxt     时间: 2009-11-29 19:47
多谢。我也学习学习

作者: bausrpgf888     时间: 2009-12-6 10:11
学习了,谢谢资料.

作者: wangwei86117     时间: 2009-12-9 09:56
很好

作者: cir2633     时间: 2010-1-7 15:03
mark

作者: czweb     时间: 2010-6-6 12:09
楼上发的附件怎么才能变成可以执行文件,如bat,exe

作者: 人类     时间: 2010-6-16 01:07
DOS下编程可以用BC++3.1啊,很经典

作者: blue007     时间: 2010-8-10 18:20
谢谢

作者: yysn     时间: 2010-9-19 01:51
我也想要

作者: netreg     时间: 2010-10-9 10:13
很好,牛人……

作者: hxfcm1234     时间: 2010-10-9 23:14

作者: wangz     时间: 2010-10-13 23:25
串口通讯比较方便谢谢提供资料!

作者: luoshiwan     时间: 2015-11-3 22:02
谢谢