Click here to Skip to main content
15,941,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

can some one tell me what is the below code doing?

C++
outportb ((*com)+3,inport((*com)+3)|0x80);


also i want to know,
1- Write a single line of code to set the size of Word Length to 8-bits to be used in serial communication for data transmission

2- Write a single line of code to set the size of Stop bits equals 3 in serial port communication.

3- Write a single line of code to turn ON the parity bit and use Even parity.

4- In the following piece of code, the Baud rate being used is 1200. Modify it in a way such that we shall have Baud Rate of 2400.

C++
outportb ((*com)+3,inport((*com)+3)|0x80);
outportb ( (*com),0x60);
outportb( (*com) +1, 0x00);
Posted

1 solution

The first line reads a byte from the Line Control Register of an UART device, sets the highest bit (the DLAB = Divisor Latch Access Bit), and writes the resulting byte back to the register. When doing so, you can access the Divisior Latch registers. In your second code block this is done by passing the 16-bit value 0x0060 to the Divisor Latch low and high byte registers. This will set the baud rate. After doing so, the DLAB bit should be cleared.

Writing code to perform the other requested tasks will be similar by reading the appropiate registers, setting or clearing bits, and writing the new value back to the register. Because the other registers can be accessed without setting a specific access bit, this can be done using a single line of code.

To know the port adresses (register offsets) and bit masks, read about UART devices (e.g. this page http://retired.beyondlogic.org/serial/serial.htm#12[^] which may be better understable than an UART data sheet).
 
Share this answer
 
Comments
Faisalabadians 17-Jan-13 10:16am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900