#include <reg51.h>typedef unsigned char byte;// 0-255 typedef unsigned char word;//0-65535static 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; }}

评论