新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 一個(gè)好玩的C51動(dòng)態(tài)掃描小程序

一個(gè)好玩的C51動(dòng)態(tài)掃描小程序

作者: 時(shí)間:2016-11-30 來(lái)源:網(wǎng)絡(luò) 收藏
初學(xué)者上手的簡(jiǎn)單程序,把下面代碼復(fù)制進(jìn)keil代碼窗口,燒進(jìn)51hei開(kāi)發(fā)板,看看結(jié)果吧
#include#define uchar unsigned char#define uint unsigned int#define dp P0char code DuanMa[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40}; //單個(gè)數(shù)碼管顯示數(shù)char code fenjie[]={0,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f};char code WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //數(shù)碼管的位選擇:從0到7.sbit LATCH1=P2^6;	//	控制數(shù)碼管段的位sbit LATCH2=P2^7; //	控制數(shù)碼管位的位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++) //調(diào)節(jié)k的值可調(diào)節(jié)掃描時(shí)間{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);}	    }	 }	  


關(guān)鍵詞: C51動(dòng)態(tài)掃

評(píng)論


技術(shù)專(zhuān)區(qū)

關(guān)閉