电子技术
当前位置 :首页光电技术电子技术

4位LED共阳数码动态显示的C51源程序

来源: 作者: 时间:2010-05-16 点击:

/* 4位LED共阳数码动态显示的C51源程序,未整理,但编译后的HEX代码可在WS803上直接运行。*/
#include<reg51.h>
#include<intrins.h>
#include<stdio.h>
#include<string.h>

#define UN  unsigned char
UN read_1byte();
void  write_1byte(unsigned char x);
void WriteToChip(UN a,b);
void read(UN h,l,d);
void JiaMi51();
void JiaMi53();
void ck(UN x);
void csf();
UN  d10[4];
void del05s();

UN btl_bz;
UN icxh;


unsigned int AllByte;//需读出的字节数不16位


sbit    lsledcs =P3^7;

 

void delay();
UN zh_adh8252r(UN x);
UN zh_adh8252w(UN x);
sfr16 DPTR=0x82;

sbit    ACC0=ACC^0;
sbit    ACC1=ACC^1;
sbit    ACC2=ACC^2;
sbit    ACC3=ACC^3;
sbit    ACC4=ACC^4;
sbit    ACC5=ACC^5;
sbit    ACC6=ACC^6;
sbit    ACC7=ACC^7;

unsigned char bdata bm;
sbit  bm0=bm^0;
sbit  bm1=bm^1;
sbit  bm2=bm^2;
sbit  bm3=bm^3;
sbit  bm4=bm^4;
sbit  bm5=bm^5;
sbit  bm6=bm^6;
sbit  bm7=bm^7;
UN data rmem[6]={0xff,0xff,0xff,0xff,0xff,0xff};
UN code ledcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,//0-9
                   0x88,0x83,0xa7,0xa1,0x86,0x8e};
void main()

{   unsigned int i,j;

 csf();
  while(1)
       {


         P0=0xff;
         lsledcs=1;
      j=0;
      while(j!=30)
      {
         i=0;
         do{
         P0=ledcode[0];
         P1=0xfe;
         delay();
         P0=ledcode[1];
         P1=0xfd;
         delay();
         P0=ledcode[2];
         P1=0xfb;
         delay();
         P0=ledcode[3];
         P1=0xf7;
         delay();
          i++;}
          while(i!=10);
        j++;
       }

       P1=0xff;
       del05s();
         ///////////////////
        
   j=0;
      while(j!=30)
      {
         i=0;
         do{
         P0=ledcode[4];
         P1=0xfe;
         delay();
         P0=ledcode[5];
         P1=0xfd;
         delay();
         P0=ledcode[6];
         P1=0xfb;
         delay();
         P0=ledcode[7];
         P1=0xf7;
         delay();
          i++;}
          while(i!=10);
         j++;
       }

       P1=0xff;
       del05s();
         ///////////////////
       j=0;
      while(j!=30)
      {
          i=0;
         do{
         P0=ledcode[8];
         P1=0xfe;
         delay();
         P0=ledcode[9];
         P1=0xfd;
         delay();
         P0=ledcode[10];
         P1=0xfb;
         delay();
         P0=ledcode[11];
         P1=0xf7;
         delay();
          i++;}
          while(i!=10);
       j++;
       }

      P1=0xff;
       del05s();[
        j=0;
      while(j!=30)
      {
         i=0;
         do{
         P0=ledcode[12];
         P1=0xfe;
         delay();
         P0=ledcode[13];
         P1=0xfd;
         delay();
         P0=ledcode[14];
         P1=0xfb;
         delay();
         P0=ledcode[15];
         P1=0xf7;
         delay();
          i++;}
          while(i!=10);
       j++;
       }

       P1=0xff;
       del05s();
         P0=0x00;
         P1=0xff;lsledcs=0;
         del05s();del05s();
         lsledcs=1;
         del05s();
        }

}

void csf()
{

         TMOD=0x20;TH1=0xfd;TL1=0xfd;SCON=0x50;PCON|=0x80;TR1=1;

         EA=1;
         delay();
         ES=0;
    SBUF=0xf0;while(TI==0){;}TI=0;
    SBUF=0x01;while(TI==0){;}TI=0;
    SBUF=0x02;while(TI==0){;}TI=0;
    SBUF=0x03;while(TI==0){;}TI=0;ES=1;
 }


/*################################串口*/
  void surt() interrupt 4
   {UN surti; unsigned int cc1;
        surti=0;
        RI=0;

        d10[surti]=SBUF;
       do
        {cc1=0xffff;
         surti++;
         while(RI==0){cc1--;if(cc1==0){goto surtint;}}
         RI=0;d10[surti]=SBUF;}
       while(surti!=3);

  surtint:;ES=1;

}

void delay()
{unsigned int kk=0xff;
    do{_nop_();kk--;}
    while(kk!=0);
}
void del05s()
{unsigned int kk=0xefff;
    do{_nop_();kk--;}
    while(kk!=0);
}

 

最新评论共有 位网友发表了评论
发表评论
用户名: 密码: 游客发言不需要密码