數碼管動態掃描
#include<reg52.h> //包含頭文件,一般情況不需要改動,頭文件包含特殊功能寄存器的定義 void yanshi(); unsigned char code dofly[]={ 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71}; unsigned char code seg[]={0,1,2,3,4,5,6,7};//分別對應相應的數碼管點亮,即位碼 /*------------------------------------------------ 延時子程序 ------------------------------------------------*/ void main() { unsigned char i,j; while(1) { P0=dofly[i++];//取顯示數據,段碼 { if(16==i) //檢測8位掃描完全? i=0; } P2=seg[j++]; //取位碼 { if(j==8) j=0; } yanshi() ; //掃描間隙延時,時間太長會閃爍,太短會造成重影,這裏使用長時間方便了解顯示原理 } } void yanshi() { int x,y; for(x=120;x>0;x--) for(y=500;y>0;y--) ; //如果將500改為0;將if(16==i) 改為8,將靜態顯示 }
最後更新:2017-04-03 19:06:50