#include <reg52.h>
/***************************************
宏定义
***************************************/
//typedef unsigned char uchar;
#define uchar unsigned char
typedef unsigned int int16;
/************************************
位端口定义
************************************/
sbit duPort = P2^6;
sbit weiPort = P2^7;
sbit ledP0 = P1^0;
sbit ledP1 = P1^1;
sbit ledP2 = P1^2;
sbit ledp3 = P1^3;
sbit ledp4 = P1^4;
sbit ledP5 = P1^5;
/**********************************
全局变量声明
**********************************/
int16 T0_COUNT;
int16 ledInt = 0Xfa;
uchar led_Type = 1;
/*********************************
函数声明
*********************************/
void Init_Time0(void);
/*************************************
函数定义
**************************************/
/**********************************
初始化定时器0
**************************************/
void Iint_Time0(void)
{
TMOD = 0X01;
TH0 = 0X4B;
TL0 = 0XFD;
TR0 = 1;
EA = 1;
ET0 = 1;
}
/***************************************
定时器0中断
****************************************/
void Time0_interrupt(void) interrupt 1
{
T0_COUNT ++;
TH0 = 0X4B;
TL0 = 0XFD;
}
/************************************
控制LED灯亮或者灭
*************************************/
void Init_Led(uchar ledLignt)
{
P1 = ledLignt;
}
/************************************
控制LED灯亮或者灭
*************************************/
void led_Control()
{
switch(led_Type)
{
case 1:
Init_Led(0xfa);
if(T0_COUNT != 100)
return;
T0_COUNT = 0;
led_Type = 2;
break;
case 2:
if(T0_COUNT%2==0)
{
Init_Led(0xee);
}
else
{
Init_Led(0xef);
}
if(T0_COUNT != 20)
return;
T0_COUNT = 0;
led_Type = 3;
break;
case 3:
Init_Led(0xf5);
if(T0_COUNT != 100)
return;
T0_COUNT = 0;
led_Type = 4;
break;
case 4:
if(T0_COUNT%2==0)
{
Init_Led(0xee);
}
else
{
Init_Led(0xef);
}
if(T0_COUNT != 20)
return;
T0_COUNT = 0;
led_Type = 1;
break;
}
}
void mian(void)
{
Iint_Time0();
while(1)
{
led_Control();
}
}
|