3、g51.h>#include#defineucharunsignedchar#defineuintunsignedint//延時(shí)voidDelayMS(uintx){uchari;while(x--){for(i=0;i<120;i++);}}//主程序voidmain(){uchari;P2=0x01;while(1){for(i=0;i<7;i++){P2=_crol_(P2,1);//P2的值向左循環(huán)移動(dòng)34DelayMS(150);}for(i=0;i<7;i++){P2=_cror_(P2,1);//P2的值向右循環(huán)移動(dòng)DelayMS(150);}}}
4、04單只數(shù)碼管循環(huán)顯示0~9/*名稱:?jiǎn)沃粩?shù)碼管循環(huán)顯示0~9說明:主程序中的循環(huán)語句反復(fù)將0~9的段碼送至P0口,使數(shù)字0~9循環(huán)顯示*/#include#include#defineucharunsignedchar#defineuintunsignedintucharcodeDSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};//延時(shí)voidDelayMS(uintx){uchart;while(x--)for(t=0;t<120;t++);}//主程序v
5、oidmain(){uchari=0;P0=0x00;while(1){/*for(;i<11;i++){P0=~DSY_CODE[i];DelayMS(300);}//注:另一方案*/P0=~DSY_CODE[i];i=(i+1)%10;DelayMS(300);}}34058只數(shù)碼管滾動(dòng)顯示單個(gè)數(shù)字/*名稱:8只數(shù)碼管滾動(dòng)顯示單個(gè)數(shù)字說明:數(shù)碼管從左到右依次滾動(dòng)顯示0~7,程序通過每次僅循環(huán)選通一只數(shù)碼管*/#include#include#defineucharunsignedchar#defineuintunsignedintuchar
6、codeDSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//延時(shí)voidDelayMS(uintx){uchart;while(x--)for(t=0;t<120;t++);}//主程序voidmain(){uchari,wei=0x80;while(1){for(i=0;i<8;i++){P2=0xff;//關(guān)閉顯示wei=_crol_(wei,1);P0=DSY_CODE[i];//發(fā)送數(shù)字段碼P2=wei;//發(fā)送位碼DelayMS(300);}}}068只數(shù)碼管動(dòng)態(tài)顯示多個(gè)不同字符電路如上圖/*名稱
7、:8只數(shù)碼管動(dòng)態(tài)顯示多個(gè)不同字符說明:數(shù)碼管動(dòng)態(tài)掃描顯示0~7。*/#include34#include#defineucharunsignedchar#defineuintunsignedintucharcodeDSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//延時(shí)voidDelayMS(uintx){uchart;while(x--)