#include "config.h"
#include "tffs/flsocket.h"
#include "tffs/pcic.h"
#include
#define COM1_PORT 0x3F8
#define inportb sysInByte
#define outportb sysOutByte
void com_send_string(unsigned char *str);
void com_send_data(unsigned char sdata);
int com1_send_data_ready(void);
int com1_recv_data_ready(void);
unsigned char com1_recv_data(void);
void com1_init(void);
void maintask(void)
{
unsigned char str[]="send success!";
char i;
/*com1_init();/*初始化串口*/
while(1)
{
if(com1_recv_data_ready())
{
i="com1"_recv_data();
com_send_data(i);
com_send_string(str);
break;
}
}
}
/***************************************/
/*发送一个字符串*/
void com_send_string(unsigned char *str)
{
int i;
i="0";
while(str[i] != '\0')
{
com_send_data(str[i]);
i++;
}
}
/*发送一个字符*/
void com_send_data(unsigned char sdata)
{
while(1)
{
if(com1_send_data_ready()) /* send data to com1 ready: 1, else 0*/
{
outportb(COM1_PORT,sdata); /* send data to com1( 查询方式?)*/
break;
}
}
}
/*发送数据是否就绪*/
int com1_send_data_ready(void) /* send data to com1 ready: 1, else 0*/
{
if(((unsigned char )inportb(COM1_PORT+5) & 0x20)!= 0)
return 1;
else return 0;
}
/*接收数据是否就绪*/
int com1_recv_data_ready(void)
{
if(((unsigned char )inportb(COM1_PORT+5) & 0x01)!= 0)
return 1;
else return 0;
}
/*接收数据*/
unsigned char com1_recv_data(void)
{
return inportb(COM1_PORT);
}
/*初始化串口*/
void com1_init(void)
{
outportb(COM1_PORT+3,0x80); /* DLAB="1", set baud*/
outportb(COM1_PORT,0x0c); /* 波特率 0x30:2400 0x18:4800 0x0c:9600*/
outportb(COM1_PORT+1,0x00);
outportb(COM1_PORT+3,0x03); /* data length: 8 , stop bits: 1*/
outportb(COM1_PORT+4,0x0b);
outportb(COM1_PORT+1,0x01); /* receive interrupt enable*/
inportb(COM1_PORT);
}
评论
发表评论