#include <REGX52.H>
#include "Timer0.h"
#include "MatrixKey.h" //文章最后有Timer0.h和MatrixKey.h的代码链接
#include <INTRINS.H>
unsigned char MKeyNum;
unsigned char LED_Mode=0;
unsigned int time=300;
void main()
{
P2=0xfe;
Timer0Init();
while(1)
{
MKeyNum=MatrixKey();
if(MKeyNum)
{
if(MKeyNum==1)
{
LED_Mode++; //s1 每次按下更换流水方向(左/右) 默认右移模式
if(LED_Mode>=2)LED_Mode=0;
}
if(MKeyNum==2)time=100; //s2 更改流水速度间隔100ms
if(MKeyNum==3)time=300; //s3 更改流水速度间隔300ms 默认模式
if(MKeyNum==4)time=500; //s4 更改流水速度间隔500ms
if(MKeyNum==5)time=1000;//s5 更改流水速度间隔1000ms
}
}
}
void Timer0_Routine() interrupt 1
{
static unsigned int T0Count;
TL0 = 0x66;
TH0 = 0xFC;
T0Count++;
if(T0Count>=time)
{
T0Count=0;
if(LED_Mode==0)
P2=_crol_(P2,1);
if(LED_Mode==1)
P2=_cror_(P2,1);
}
}
配置代码中用到的两个头文件:
Timer0.h:【51单片机C语言】2-4模块化定时器_北方大陸網友的博客-CSDN博客
MatrixKey.h:【51单片机C语言】2-2模块化矩阵键盘_北方大陸網友的博客-CSDN博客