The serial port hardware has several registers to cater to different functionalities. Some of the useful registers are:
Line control register LCR For configuring the serial port. (Address: comport + 3) Receiver buffer register RBR Holds the data received via the serial port. (comport + 0) Transmitter Buffer register TBR Holds the data to be transmitted.(comport + 0) Line status register LSR Holds the info regarding the line status.(comport + 5)
where comport should be replaced with your COM1 or COM2 address.
Following are some basic guidelines for programming the serial port:
- To program the serial port you must first initialize the Line Control register of your port with the required baud rate, number of data bit, desired Parity etc. The initialization value is 0x03 for a no parity, 1 stop bit and 8 data bit configuration.
- Then you must read the LSR to see if any data is received.
- If data is received then you must read the data from the RBR.
- For writing data, you must check the LSR to see if the port is ready to send data.
- Then you must write the data to the TBR to send data via the port.
This is just a very brief introduction and you need to pick up more to go into serial programming.