因仑“3+1”工程特种兵精英论坛

标题: PC与串口通信、双机通信(MAX232)甲 [打印本页]

作者: 张衍波    时间: 2015-4-18 21:38
标题: PC与串口通信、双机通信(MAX232)甲


程序说明:
  甲机将代码段发送给乙,乙接收用数码管显示
*********************************************************************/
#include<reg52.h>                 //库文件
#define uchar unsigned char//宏定义无符号字符型
#define uint unsigned int  //宏定义无符号整型

code uchar seg7code[10]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //显示段码 数码管字跟

uchar i;
/********************************************************************
                            延时函数
*********************************************************************/

void delayms(uchar n)
{
uchar m,s;
for(m=n;m>0;m--)
for(n=20;n>0;n--)
for(s=248;s>0;s--);
}

/********************************************************************
                功能:串口初始化,波特率9600,方式1
*********************************************************************/

void Init_Com(void)
{
TMOD = 0x20;
PCON = 0x00;
SCON = 0x50;
TH1 = 0xFd;
TL1 = 0xFd;
TR1 = 1;
}
/********************************************************************
                            主函数
*********************************************************************/
void main()
{
Init_Com();         //初始化
delayms(40); //延时等待

for(i=0;i<=9;i++)
{
  SBUF=        seg7code;
  while(!TI);
  TI=0;
}

}
       
/********************************************************************
                              结束
*********************************************************************/
[attach]2350[/attach]








欢迎光临 因仑“3+1”工程特种兵精英论坛 (http://bbs.enlern.com/) Powered by Discuz! X3.4