Information Technology Reference
In-Depth Information
} while (ch!=4);
return(0);
}
void setup_serial(void)
{
_outp( LCR, 0x80);
/* set up bit 7 to a 1 to set Register address bit */
_outp(TXDATA,0x0C);
_outp(TXDATA+1,0x00);
/* load TxRegister with 12, crystal frequency is 1.8432MHz
*/
_outp(LCR, 0x0A);
/* Bit pattern loaded is 00001010b, from msb to lsb these are: */
/* Access TD/RD buffer, normal output, no stick bit */
/* even parity, parity on, 1 stop bit, 7 data bits */
}
void send_character(int ch)
{
char status;
do
{
status = _inp(LSR) & 0x40;
} while (status!=0x40);
/*repeat until Tx buffer empty ie bit 6 set*/
_outp(TXDATA,(char) ch);
}
Program 13.4
/* receive.c
*/
#define TXDATA 0x3F8
#define LSR 0x3FD
#define LCR 0x3FB
#include <stdio.h>
#include <conio.h> /* included for getch */
#include <dos.h>
void setup_serial(void);
int get_character(void);
int main(void)
{
int inchar;
setup_serial();
do
{
inchar=get_character();
putchar(inchar);
} while (inchar!=4);
return(0);
}
void setup_serial(void)
{
_outp( LCR, 0x80);
/* set up bit 7 to a 1 to set Register address bit
*/
_outp(TXDATA,0x0C);
_outp(TXDATA+1,0x00);
/* load TxRegister with 12, crystal frequency is 1.8432MHz
*/
_outp(LCR, 0x0A);
/* Bit pattern loaded is 00001010b, from msb to lsb these are: */
/* Access TD/RD buffer, normal output, no stick bit
*/
/* even parity, parity on, 1 stop bit, 7 data bits */
}
Search WWH ::




Custom Search