用c读写com端口3 [英] reading and writing to com port 3 with c

查看:79
本文介绍了用c读写com端口3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





有人可以告诉我下面的代码在做什么吗?



< pre lang =c ++> outportb((* com)+ 3,inport((* com)+3)| 0x80);





我也想知道,

1-写一行代码将Word长度的大小设置为8位,用于串行通信以进行数据传输



2-在串口通信中写一行代码来设置停止位的大小等于3.



3-写一行代码打开奇偶校验位并使用偶校验。



4-在下面的代码中,使用的波特率是1200。修改它的方式使我们的波特率为2400.



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

解决方案

第一行从行控制中读取一个字节UART器件的寄存器设置最高位(DLAB =除数锁存访问位),并将结果字节写回寄存器。这样做时,您可以访问Divisior Latch寄存器。在第二个代码块中,这是通过将16位值0x0060传递给除数锁存器低位和高位字节寄存器来完成的。这将设置波特率。执行此操作后,应清除DLAB位。



通过读取适当的寄存器,设置或清除位,编写执行其他请求任务的代码将类似,将新值写回寄存器。因为可以在不设置特定访问位的情况下访问其他寄存器,所以可以使用一行代码完成。



知道端口地址(寄存器偏移)和位掩码,阅读有关UART设备的信息(例如,本页 http://retired.beyondlogic.org/serial/serial。 htm#12 [ ^ ]可能比UART数据表更容易理解。)


hi,

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

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.

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

解决方案

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).


这篇关于用c读写com端口3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆