#include <reg52.h>
#include <intrins.h>
#include "delay.h"

unsigned long int count = 0;
unsigned char var = 0xFF;
#define RELOAD (65535-46080)
int TH, TL;
unsigned char enable = 0;



void setConfig()
{
  TH = RELOAD / 256;
  TL = RELOAD - (RELOAD / 256) * 256;
  TH0 = TH;
  TL0 = TL;

  TMOD = 0x01; //使用定时器T0，高4位全为0,低4位GATE=0，C/T=0，采用工作方式1，M1=0,M1=1

  TR0 = 1; //启动定时器0
  EA = 1; //打开中断总开关
  ET0 = 1; //打开定时器0中断开关

  P1 = 0X00;
}

void pulse() interrupt 1
{

  TH0 = TH;
  TL0 = TL0 + TL;
  TL0 = TL0 + 23;

  enable = 1;
  count++;
}

void ifLight()
{
  if(enable)
    {
      int time;
      for(time = 1; time < 9; time++) //时间匹配
        {

          if(count % (20 * time) == 0) //是否整数倍
            {

              int i = 1;
              i = i << (time - 1);
              var = var ^ i;
              P1 = var;
            }
        }

      enable = 0;
    }
}


int main()
{
//P1 灯
  setConfig();
  while(1)
    {
      ifLight();
    }
}
