69,382
社区成员
发帖
与我相关
我的任务
分享
#include <conio.h>
#include <dos.h>
#define COM1_ADDR 0x3f8
//Initial Com1
void InitCom1()
{
//disable the uart interrupt
outportb(COM1_ADDR + 1, 0x00);
//set DLAB = 1,allow to access the uart register
outportb(COM1_ADDR + 3, 0x80);
//set the bundrate:115200
outportb(COM1_ADDR + 0, 0x01);
outportb(COM1_ADDR + 1, 0x00);
//8 data bit,1 stop bit,no parity bit,DLAB = 0
outportb(COM1_ADDR + 3, 0x03);
}
char sendCom1(char data)
{
char status = inportb(COM1_ADDR + 5);//check the status of the Com1
int count = 10000;//time out counter
//wait until the send register is empty OR Time out
while(!(status & 0x20) && (count > 0))
{
count--;
status = inport(COM1_ADDR + 5);//check the status of the Com1
}
//send data
if(count > 0)//the send register is empty
{
outportb(COM1_ADDR + 0, data);//send the ONE Byte data
return 1;
}
else //the data don't send out
{
return 0;
}
}
//send file by COM1
void sendFile(FILE *pfile)
{
char ch;
while(!feof(pfile))//Send until the end of the file
{
ch = fgetc(pfile);//get the char to send
if(!sendCom1(ch))//send error
{
printf("Send Error!!\n");
}
}
}