在写程序时,显示部分很经常用到,所以一般都直接做成DRIVER,这样用到时调用就是了。下面是个动态扫描的驱动。
先是文件头部分
+++++++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
#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) //动态显示
{
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++);
}
}
上一篇:motorola的电子钟
下一篇:单片机的概述
推荐阅读最新更新时间:2024-03-16 13:49