初学者上手的简略程序,把下面代码仿制进keil代码窗口,烧进51hei开发板,看看成果吧
#include#define uchar unsigned char#define uint unsigned int#define dp P0char code DuanMa[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40}; //单个数码管显现数char code fenjie[]={0,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f};char code WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //数码管的位挑选:从0到7.sbit LATCH1=P2^6; // 操控数码管段的位sbit LATCH2=P2^7; // 操控数码管位的位void delay(unsigned int t){while(--t);}void main(){int i,j,k;while(1){delay(5000);for(i=0;i<7;i++) //段码{ for(j=0;j<8;j++) //位码{ for(k=0;k<10;k++) //调理k的值可调理扫描时间{dp=WeiMa[j]; //取位码LATCH2=1; LATCH2=0; dp=DuanMa[i]; //取段码 LATCH1=1; LATCH1=0;delay(2500);dp=fenjie[i]; //取段码 LATCH1=1; LATCH1=0;dp=WeiMa[7]; //取位码LATCH2=1; LATCH2=0; delay(50);dp=0; //取段码 清零 减小余晖影响LATCH1=1; LATCH1=0;dp=WeiMa[j]; //取位码LATCH2=1; LATCH2=0; delay(1000); }}} //闪耀8for(k=0;k<10;k++){dp=fenjie[7]; //取段码 LATCH1=1; LATCH1=0;dp=WeiMa[7]; //取位码LATCH2=1; LATCH2=0;delay(6000);delay(6000);dp=0; //取段码 LATCH1=1; LATCH1=0;dp=WeiMa[7]; //取位码LATCH2=1; LATCH2=0;delay(6000);} } }