开发者

Comunication with RS232 port in assembly

I have a circuit that have 8 input lines and a cable connected to serial port of computer. Controller of port is connected in parallel configuration. (I have no idea about what this means! students of electronic engineering said that this means "you have to use signals asynchronously, eg each signal could be on or of independent to others")

Now I should write an assembly code that reads some inputs from a file, process them, and set th开发者_JAVA技巧at data lines on or of. I can do the first 2, but don't have any idea about ports.

Could you give me a start point? for example how do I initialize a port and how to set a line of data on serial port of a PC in assembly?


I really think that you are confused - a lot. RS 232 is the protocol serial ports use. In its 9-pin version (DE-9) it does have 8 usable data lines, but only half of them are output pins and you cannot really control the data pin, short of sending actual data through it. Unless you have a device that incorporates a microcontroller with a serial interface, I doubt that it's intended to be used with an RS-232 interface.

RS-232 was, indeed, the connection used by some printers in the '80s and early '90s, usually dot-matrix printers. Unfortunately it was too slow for printing anything but ASCII text, hence the introduction of the parallel port, which, incidentally, does have 8 output lines. That port is known as "printer port" ever since the '90s. In modern computers you can even control the pins of the parallel port somewhat separately, which is why it is widely used in electronics - well, that and the fact that it usues a 5 Volt TTL interface which is far easier to handle than the 12V serial ports use.

You also don't mention which operating system your program is supposed to be for, although if you intend to access the port directly with assembly, you are probably restricted to DOS or Windows 9x/Me.

That said:

  • Assembly serial and parallel port programming for DOS. Also this and this.

  • Parallel port programming for DOS, Windows and Linux


Since you didn't specify which language or development environment, here is a sample using VB.NET:

    Private WithEvents m_comport1 As IO.Ports.SerialPort

Private Sub Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    m_comport1 = New IO.Ports.SerialPort("COM1")
    AddHandler m_comport1.DataReceived, AddressOf Comport_DataReceived
End Sub

Private Sub SendData(p_data() As Byte)

    m_comport1.Write(p_data, 0, p_data.Length)

End Sub

Private Sub SendData(p_data As String)

    m_comport1.Write(p_data)

End Sub

Private Sub Comport_DataReceived(sender As System.Object, e As System.IO.Ports.SerialDataReceivedEventArgs)
    Dim bytesAvailable = m_comport1.BytesToRead
    Dim tempData(bytesAvailable) As Byte
    m_comport1.Read(tempData, 0, bytesAvailable)

End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜