|
#include<reg52.h>
sbit LED = P0^0;
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
void HZ_1(int* i,int* cnt)
{ *i=0;
while(1)
{
if(TF0 == 1)
{
TFO = 0;
*cnt++;
}
if(*cnt == 50)
{
*cnt = 0;
P0 = ~(0x01<<*i)
(*i)+=2;
}
if(*i >= 8)
{
*i=1;
break;
}
}
}
void HZ_2(int* i,int *cnt)
{ *i=1;
while(1)
{
if(TF0 == 1)
{
TF0 = 0;
*cnt++;
}
if(cnt == 100)
{
*cnt = 0;
P0 = ~(0x<<(*i))
(*i)+=2;
}
if(*i > 7)
{
*i = 0;
break;
}
}
}
void main()
{
int cnt = 0;
int i = 0;
ADDR0 = 0;
ADDR1 = 1;
ADDR2 = 1;
ADDR3 = 1;
ENLED = 0;
TMOD = 0x01;
TR0 = 1;
TH0 = 0xB8;
TL0 = 0x00;
while(1)
{
HZ_1(&i,&cnt);
HZ_2(&i,&cnt);
}
} |
|