- 177
- 0
- 约6.53千字
- 约 8页
- 2020-09-11 发布于浙江
- 举报
基于AT89C52的16路流水灯代码
#include REG52.H
unsigned char RunMode;
/**********************************System Fuction*************************************************/
void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;icount;i++)
for(j=0;j120;j++);
}
unsigned char code LEDDisplayCode[] = { 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8, //0~7
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF};
void Display(unsigned char Value)
{
P3 = LEDDisplayCode[Value];
}
void LEDFlash(unsigned char Count)
{
unsigned char i;
bit Flag;
for(i = 0; iCount;i++)
{
Flag = !Flag;
if(Flag)
Display(RunMode);
else
Display(0x10);
Delay1ms(100);
}
Display(RunMode);
}
unsigned char GetKey(void)
{
unsigned char KeyTemp,CheckValue,Key = 0x00;
CheckValue = P20x32;
if(CheckValue==0x32)
return 0x00;
Delay1ms(10);
KeyTemp = P20x32;
if(KeyTemp==CheckValue)
return 0x00;
if(!(CheckValue0x02))
Key|=0x01;
if(!(CheckValue0x10))
Key|=0x02;
if(!(CheckValue0x20))
Key|=0x04;
return Key;
}
unsigned int TimerCount,SystemSpeed,SystemSpeedIndex;
void InitialTimer2(void)
{
T2CON = 0x00; //16 Bit Auto-Reload Mode
TH2 = RCAP2H = 0xFC; //重装值,初始值 TL2 = RCAP2L = 0x18;
ET2=1; //定时器 2 中断允许
TR2 = 1; //定时器 2 启动
EA=1;
}
unsigned int code SpeedCode[]={ 1, 2, 3, 5, 8, 10, 14, 17, 20, 30,
40, 50, 60, 70, 80, 90,100, 120, 140, 160,
180, 200, 300, 400, 500, 600, 700, 800, 900,1000};//30
void SetSpeed(unsigned char Speed)
{
SystemSpeed =SpeedCode[Speed];
}
void LEDShow(unsigned int LEDStatus)
{
P1 = ~(LEDStatus0x00FF);
P0 = ~((LEDStatus8)0x00FF);
}
void Initi
原创力文档

文档评论(0)