查看: 1001|回复: 0
打印 上一主题 下一主题

004、多个数据的发送程序

[复制链接]
跳转到指定楼层
沙发
发表于 2015-5-6 09:36:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/********************************************************************
                            汇诚科技
                                          http://www.ourhc.cn
*********************************************************************/
#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 wei[4]={0XEf,0XDf,0XBf,0X7f};  //位的控制端

code uchar dat[10]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //发送的数据
uchar shu;
/********************************************************************
                            延时函数
*********************************************************************/
void delay(uchar t)
{
  uchar i,j;
   for(i=0;i<t;i++)
   {
            for(j=13;j>0;j--);
         { ;
         }
   }
}


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--);
}

/********************************************************************
                            显示函数
*********************************************************************/        
void Led(uchar date) //显示函数
{
/*****************数据转换*****************************/
uint z,x,c,v;
  z=date/1000;                         //求千位
  x=date%1000/100;                 //求百位
  c=date%100/10;                 //求十位
  v=date%10;                         //求个位

      P2=0XFF;
          P0=seg7code[z];
          P2=wei[0];
          delay(80);
          P2=0XFF;  
      P0=seg7code[x];
          P2=wei[1];
          delay(80);
          P2=0XFF;  
             P0=seg7code[c];
          P2=wei[2];
          delay(80);
          P2=0XFF;  
      P0=seg7code[v];
          P2=wei[3];
          delay(80);
          P2=0XFF;
}
/********************************************************************
                功能:串口初始化,波特率9600,方式1
*********************************************************************/

void Init_Com(void)
{
TMOD = 0x20;
PCON = 0x00;
SCON = 0x50;
TH1 = 0xFd;
TL1 = 0xFd;
TR1 = 1;
}
/********************************************************************
                            主函数
*********************************************************************/
void main()
{
uchar a;
uint b;
Init_Com();
while(1)
{
for(a=0;a<10;a++)
{
delayms(20);
SBUF = dat[a];
shu  = dat[a];
Led(shu); //显示数据
while(TI==0);
TI=0;
}


}
}
       
/********************************************************************
                              结束
*********************************************************************/





本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?加入因仑

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入因仑

本版积分规则

快速回复 返回顶部 返回列表