用C語言編程使51單片機的數(shù)碼管左移循環(huán)顯示
高手支招:請問用C語言編程使51單片機的數(shù)碼管左移循環(huán)顯示0-7的程序怎么編呀
由于我不懂得用中斷和定時,請程序里不要用那兩個函數(shù),謝謝(*^__^*) 嘻嘻……
懸賞分:0 - 解決時間:2010-7-31 18:09
問題補充:這個是我自己編的,可是運行起來就是不移動,麻煩你們幫修改一下,我沒有編左移循環(huán)部分的程序。
//==========================================================
最佳答案:
//---------------------------------------------------
#include
#define uint unsigned int
#define uchar unsigned char
uchar code DIS_SEG7[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8};
uchar code DIS_BIT[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
//---------------------------------------------------
void delay1ms(uint i)
{
uint j;
while(i--) for(j = 0; j < 125; j++);
}
//---------------------------------------------------
void main(void)
{
uchar cnt, ttt;
uchar DISP[] = {0, 1, 2, 3, 4, 5, 6, 7};
while(1) {
for(ttt = 0; ttt < 100; ttt++)
for(cnt = 0; cnt < 8; cnt++) { //點亮數(shù)碼管0-7
P2 = 0;
P0 = DIS_SEG7[DISP[cnt]];
P2 = ~DIS_BIT[cnt];
delay1ms(1);
}
//-------------------以上顯示800ms,下面更新顯示內(nèi)容
ttt = DISP[0];
DISP[0] = DISP[1];
DISP[1] = DISP[2];
DISP[2] = DISP[3];
DISP[3] = DISP[4];
DISP[4] = DISP[5];
DISP[5] = DISP[6];
DISP[6] = DISP[7];
DISP[7] = ttt;
}
}
//---------------------------------------------------
程序運行截圖如下: