This is another 8250-centric section. If your port isn't a regular PC port but something else, feel free to skip to the next section.
On PCs, the baud rate, B, is set as a divisor, actually 1843200/(16*B); or equivalently, 115200/B. The divisor is an integer, so not all baud-rates are available, only the 115200/N. The following table shows baud-rates for some interesting divisors N:
N | Baud-rate | N | Baud-rate | N | Baud-rate |
1 | 115200 | 11 | 10472 | 192 | 600 |
2 | 57600 | 12 | 9600 | 384 | 300 |
3 | 38400 | 16 | 7200 | 768 | 150 |
4 | 28800 | 18 | 6400 | 1047 | 110 |
5 | 23040 | 23 | 5008 | 1152 | 100 |
6 | 19200 | 24 | 4800 | 1920 | 60 |
7 | 16457 | 32 | 3600 | 2304 | 50 |
8 | 14400 | 48 | 2400 | 11520 | 10 |
9 | 12800 | 64 | 1800 | 23040 | 5 |
10 | 11520 | 96 | 1200 | 115200 | 1 |
These divisors are set on ports 0 (LSB) and 1 (MSB) when port 3 bit 7 is 1. The following C (DOS, Turbo C) function shows how these can be set:
void setbaudrate(int portbase, /* This should be 0x378, 0x278 or whatever as appropriate. */ long baudrate) { int divnumber, dh, dl; /* If we want to limit or quantize the baudrate here we could. */ if(baudrate == 0) return; /* Avoid this stupid mistake at least.... */ divnumber = 115200L / baudrate; dl = divnumber & 0x0FF; dh = (divnumber >> 8) & 0xFF outportb(portbase+3, inportb(portbase+3) | 0x80); outportb(portbase+0, dl); outportb(portbase+1, dh); outportb(portbase+3, inportb(portbase+3) & 0x7F); }
I have noticed that under the unix systems, only certain baud rates may be set. Usually this is done via ioctl(TCSETA) or similar, with settings for Baud Rate, data bits, stop bits, parity, "raw"/"cooked" modes and so on. The actual possibilities beyond standard rates are very dependent on the actual hardware.
To 5. Where do you find the ports?
To 7. Programming on DOS, including DOS boxes under Windows.