一个好玩的C51动态扫描小程序
2015-07-02 来源:51hei
初学者上手的简单程序,把下面代码复制进keil代码窗口,烧进51hei开发板,看看结果吧
进入单片机查看更多内容>>
#include#define uchar unsigned char #define uint unsigned int #define dp P0 char 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); } } } //闪烁8 for(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); } } }
下一篇:8位共阴极数码管动态驱动程序
相关文章