Serial Ports: Difference between revisions
[unchecked revision] | [unchecked revision] |
Content deleted Content added
→Port Addresses: Added I/O Access to clarify some registers which depends on it. |
m Bot: Replace main article with main template |
||
(One intermediate revision by one other user not shown) | |||
Line 388:
===Terminals===
Once you can send and receive bytes with confidence, you probably want to connect the serial port to a terminal (or more likely a terminal emulator these days). Those send specific byte sequences when a key is pressed, and can interpret codes to move the cursor on the screen and change color for example.
Line 395:
==Example Code==
===Initialization===
<
#define PORT 0x3f8 // COM1
Line 419:
return 0;
}
</syntaxhighlight>
Notice that the initialization code above writes to [PORT + 1] twice with different values. This is once to write to the Divisor register along with [PORT + 0] and once to write to the Interrupt register as detailed in the previous section. The second write to the Line Control register [PORT + 3] clears the DLAB again as well as setting various other bits.
===Receiving data===
<
int serial_received() {
return inb(PORT + 5) & 1;
Line 434:
return inb(PORT);
}
</syntaxhighlight>
===Sending data===
<
int is_transmit_empty() {
return inb(PORT + 5) & 0x20;
Line 448:
outb(PORT,a);
}
</syntaxhighlight>
==Glossary==
|