Chinaunix首页 | 论坛 | 博客
  • 博客访问: 399107
  • 博文数量: 105
  • 博客积分: 4100
  • 博客等级: 上校
  • 技术积分: 1040
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-27 19:57
文章存档

2012年(1)

2011年(9)

2010年(4)

2009年(25)

2008年(66)

我的朋友

分类:

2008-07-28 09:42:13

数码管动态显示

#include
typedef unsigned char byte;// 0-255
typedef unsigned char word;//0-65535
static byte arry_display[5];
byte table[10]={0x42,0xee,0x58,0x68,0xe4,0x61,0x41,0xea,0x40,0x60};//0-9
//显示函数
void display(void)
{
byte position=0xfe;
byte i,j,temp;
for(i=0;i<4;i++)//4数码管轮留导通
 {
 temp=arry_display[i];
 temp=table[temp];
 for(j=0;j<200;j++)//延时
  {
  P2=position;P0=temp;
  }
 position<<=1;
 position|=0x01;//以保证循环点亮
 
 }
//position=0xfe;
}
///将10进制转化为BCD

int cov_bcd(unsigned int n)
{
 arry_display[0]=n/1000;//千位
 arry_display[1]=(n/100)%10;//百位
 arry_display[2]=(n/10)%10;//十位
 arry_display[3]=n%10; //个位
}
void main(void)
{
unsigned int a;
a=0x00; 
 while(1)
 {
 for(;a<9999;a++)
  {
  cov_bcd(a);
  display();
  //for(j=0;j<3000;j++);
  }
    a=0x00;
 }
}

阅读(709) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~