在寫程序時,顯示部分很經(jīng)常用到,所以一般都直接做成DRIVER,這樣用到時調用就是了。下面是個動態(tài)掃描的驅動。
先是文件頭部分
+++++++LEDDRIVER.H++++++++
#ifndef _LedDriver_H_ //防止重復引用該文擋,如果沒定義過符號
//_LedDriver_H_, 則編譯下程序
#define _ledDriver_H_
void LedPrint(unsigned char Dat);
void LedWork(void);
void Delay(unsigned char count);
#endif
++++++LEDDRIVER.C++++
#include <REGX52.H>
#include "LedDriver.h"
code unsigned char LedCode[]=
{
//0 1 2 3 4 5 6 7 8 9
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
//A B C D E F - H L P O
0x77,0x7c,0x39,0x5e,0x79,0x71,0x40,0x76,0x38,0x73,0x5c
};
unsigned char DisBuf[4];
void LedPrint (unsigned char Dat) //顯示值的緩存
{
DisBuf[0] = DisBuf[1];
DisBuf[1] = DisBuf[2];
DisBuf[2] = DisBuf[3];
DisBuf[3] = Dat;
}
void LedWork(void) //動態(tài)顯示
{
static unsigned char i=0;
int m;
P2 =0x0f;
P0=LedCode[DisBuf[i]];
switch (i)
{
case 0: P2_0=0; break;
case 1: P2_1=0; break;
case 2: P2_2=0; break;
case 3: P2_3=0; break;
}
if(++i>=4) i=0;
}
void Delay(unsigned char count)
{
unsigned char j;
while(count-- != 0)
{
for(j=0;j<72;j++);
}
}