📄 leddriver.c
字号:
#include <reg52.h>
#include "LedDriver.h"
code unsigned char LedHexCode[]=
{
//0 1 2 3 4 5 6 7
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
//8 9 a b c d e f
0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71,
//- H L P o
0x40, 0x76, 0x38, 0x73, 0x5c,
};
unsigned char DisBuf[4];
unsigned int LedInterval=1;
/*
void LedPrint( unsigned char bitN, unsigned char Dat )
{ DisBuf[ bitN ] = Dat; }
*/
void LedOutput( void )
{
static unsigned char index=0;
P2 |= 0x0f;
P0 = LedHexCode[ DisBuf[index] & 0x1f ] | (DisBuf[index]&0x80);
P2 &= (1<<index)^0xff;
if( ++index == 4 ) index=0;
}
void LedSetInterval( unsigned int time ){ LedInterval = time; }
/*下面是延时函数的描述*/
void delayMs( unsigned int tc ) //tc是形参
{
while( tc != 0 ) //如果tc为0则终止延时
{
unsigned int i; //局部正整数变量 i
for(i=0; i<400; i++); //执行400次将耗时1毫秒
tc--; //tc计数减一
}
}
void LedWork( void )
{
static unsigned int delayTime=1;
delayMs( 1 );
if( --delayTime==0 )
{
delayTime = LedInterval;
LedOutput();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -