注册 登录
编程论坛 单片机编程

RS485串口通信

zwc 发布于 2009-09-26 16:08, 1387 次点击
void Send( char *buf, int count)
{
   outportb(0x02FC,inportb(0x02FC)|0x02);    /*Raise the RTS Signal */

    while(count--)PutChar(*buf++);

    while ( ( inportb ( 0x02Fd ) & 0x40 ) == 0 );    /*wait for all data to be sended!*/

   outportb( 0x02FC,inportb(0x02FC)&0xfd);           /*Drop the RTS Signal*/
}
void PutChar ( unsigned char c )
{
    while ( ( inportb ( 0x02Fd ) & 0x20 ) == 0 );/* Wait til transmitter is ready */
                    
    outportb (0x02F8, c );                    /* then send it */
}
void revice()
{
while(1){
cc=inportb(0x2FD)&0x01;
if(cc!=0){
cm=inportb(0x2F8);
break;
}
}
发送数据正常,怎么写接收数据?谢谢

[ 本帖最后由 zwc 于 2009-9-26 16:10 编辑 ]
5 回复
#2
hlmzrdongdong2009-11-14 10:44
回复 楼主 zwc
用的是51单片机的话,需要响应串口接收中断,好像51单片机的第五个中断资源就是串口中断啊,编写这个中断的接收服务程序即可。

[ 本帖最后由 hlmzrdongdong 于 2009-11-14 10:46 编辑 ]
#3
酣放自若2010-03-22 17:03
学习
#4
酣放自若2010-03-22 17:03
学习
#5
寒风中的细雨2010-03-24 08:29
努力
#6
ltf1062012-08-24 08:55
好难啊
1