单片机系列(二)

来源:互联网 发布:数据库的sql语句 编辑:程序博客网 时间:2024/06/09 06:13

这是七段数码管的动态显示,写起来还真感觉吃力,尤其是犯了个低级的错误,

就是在定义那个显示的字型码的时候少写了个分号,找了半天错误,还是功底不够

牢靠,得多加练习,かんばで!

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
//       FileName: SegLed.c                       ||
//       Function: 七段数码管动态显示           ||
//       Author  : Softstone                        ||
//       Date    : 2007/04/20                      ||
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//

#include <reg51.h>
#include <intrins.h>

#define uchar unsigned char
#define SegCs  P1
#define DisTem P0

void Delay();
void Del05s(void);
void Display(void);

sbit LedCs=P3^7;

code uchar  DisBuf[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,//0-9
                     0x88,0x83,0xa7,0xa1,0x86,0x8e};    //Don't forget the ";",or you
                                         //will got the unreasonable mistake!

void main()

 LedCs=1;
 while(1){Display();}

}

//***********************************//
//     显示子程序,每次显示四个数字                       ||
//                                                                      ||
//***********************************//
void Display()
{
 uchar i,j,k,m,n;
 uchar temp;

 SegCs=0xff;
 DisTem=0xff;
 
 
 for(j=0;j<4;j++)
 { 
  k=30; 
  while(k)
  {
   temp=0xfe; 
   for(i=0;i<4;i++)
   {
   SegCs=temp;
   m=temp<<1;
   n=temp>>7;
   temp=m|n;
   DisTem=DisBuf[4*j+i];
   Delay();
   Delay();
   }
   k--;
  } 
   
   SegCs=0xff;
   Del05s();
 }
}


//********************************//
//     The delay function                               ||
//********************************//
void Delay()
{unsigned int kk=0xff;
    do{_nop_();kk--;}
    while(kk!=0);
}

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


 

原创粉丝点击