70 lines
983 B
C
70 lines
983 B
C
|
#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; //ʹ<>ö<EFBFBD>ʱ<EFBFBD><CAB1>T0<54><30><EFBFBD><EFBFBD>4λȫΪ0,<2C><>4λGATE=0<><30>C/T=0<><30><EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD><C3B9><EFBFBD><EFBFBD><EFBFBD>ʽ1<CABD><31>M1=0,M1=1
|
|||
|
|
|||
|
TR0 = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>0
|
|||
|
EA = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>ܿ<EFBFBD><DCBF><EFBFBD>
|
|||
|
ET0 = 1; //<2F><EFBFBD>ʱ<EFBFBD><CAB1>0<EFBFBD>жϿ<D0B6><CFBF><EFBFBD>
|
|||
|
|
|||
|
P1 = 0X00;
|
|||
|
}
|
|||
|
|
|||
|
void pulse() interrupt 1
|
|||
|
{
|
|||
|
|
|||
|
TL0 += TL;
|
|||
|
TL0 += 19;
|
|||
|
enable = 1;
|
|||
|
count++;
|
|||
|
}
|
|||
|
|
|||
|
void ifLight()
|
|||
|
{
|
|||
|
if(enable)
|
|||
|
{
|
|||
|
int time;
|
|||
|
for(time = 1; time < 9; time++) //ʱ<><CAB1>ƥ<EFBFBD><C6A5>
|
|||
|
{
|
|||
|
|
|||
|
if(count % (20 * time) == 0) //<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
|
|||
|
int i = 1;
|
|||
|
i = i << (time - 1);
|
|||
|
var = var ^ i;
|
|||
|
P1 = var;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
enable = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
//P1 <20><>
|
|||
|
setConfig();
|
|||
|
while(1)
|
|||
|
{
|
|||
|
ifLight();
|
|||
|
}
|
|||
|
}
|