Information Technology Reference
In-Depth Information
set COM1: with the parameters of 1200 bps, 1 stop bit, no parity and 7 data bits.
void setup_serial(void)
{
int RS232_setting;
RS232_setting=BAUD1200 | STOPBIT1 | NOPARITY | DATABITS7;
bioscom(0,RS232_setting,COM1);
}
After the serial port has been initialized the interrupt service routine for the IRQ4 line is set to
point to a new 'user-defined' service routine. The primary serial port COM1: sets the IRQ4 line
active when it receives a character. The interrupt associated with IRQ4 is 0Ch (12). The get-
vect() function gets the ISR address for this interrupt, which is then stored in the variable
oldvect so that at the end of the program it can be restored. Finally, in the set_vectors()
function, the interrupt assigns a new 'user-defined' ISR (in this case it is the function
rs_interrupt() ).
void set_vectors(void)
{
oldvect = getvect(0x0C); /* store IRQ4 interrupt vector
*/
setvect(0x0C, rs_interrupt); /* set ISR to rs_interrupt()
*/
}
At the end of the program the ISR is restored with the following code.
void reset_vectors(void)
{
setvect(0x0C, oldvect); /* reset IRQ4 interrupt vector
*/
}
The COM1: port is initialized for interrupts with the code given next. The statement
ch = inportb ( MCR ) | 0x08;
resets the RS-232 port by setting bit 3 for the modem control register (MCR) to a 1. Some
RS-232 ports require this bit to be set. The interrupt enable register (IER) enables interrupts
on a port. Its address is offset by 1 from the base address of the port (that is, 0x3F9 for
COM1: ). If the least significant bit of this register is set to a 1 then interrupts are enabled, else
they are disabled.
To enable the IRQ4 line on the PIC, bit 5 of the IMR (interrupt mask register) is to be set
to a 0 (zero). The statement:
ch = inportb(IMR) & 0xEF;
achieves this as it bitwise ANDs all the bits, except for bit 4, with a 1. This is because any bit
which is ANDed with a 0 results in a 0. The bit mask 0xEF has been defined with the macro
IRQ4 .
void enable_interrupts(void)
{
int ch;
disable();
ch = inportb(MCR) | MC_INT; /* initialize rs232 port */
outportb(MCR, ch);
outportb(IER, 0x01);
ch = inportb(IMR) & IRQ4;
Search WWH ::




Custom Search