#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define TIME_1MS 65536-1000
long timer_ms=0;
void delay(uchar a1);
uchar a4;
void main()
{
uchar a=5,bb=0;
int aaa=0;
TMOD = 0x01; //set timer0 as mode1 (16-bit)
TL0 = TIME_1MS%256; //initial timer0 low byte
TH0 = TIME_1MS/256; //initial timer0 high byte
TR0 = 1; //timer0 start running
ET0 = 1; //enable timer0 interrupt
EA = 1;
a4=0;
while(1)
{
if(bb==0)
{
if(timer_ms==a)
{
P1=0XFF;
}
else if(timer_ms==20-a)
{
P1=0;
}
}
else
{
if(timer_ms==a)
{
P1=0;
}
else if(timer_ms==20-a)
{
P1=0xff;
}
}
if(timer_ms>=21)timer_ms=0;
aaa++;
if(aaa == 3000)
{
a++;
if(a==20)
{
bb=~bb;
a=5;
}
aaa=0;
}
}
}
void timero() interrupt 1
{
TL0 = (65536-1000)%256; //initial timer0 low byte
TH0 = (65536-1000)/256; //initial timer0 high byte
timer_ms++;
}
void delay(uchar a1)
{
char a2,a3;
for(a2=0;a2<a1;a2++)
for(a3=0;a3<250;a3++);
}
|