#include<reg51.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
sbit pcm_0=P1^0;
sbit pcm_1=P1^1;
uint a,an,b;
bit c=0,d=1;
uint array_data[3]={0x1547,0x1574,0x5784};
void pcm_fashe(uint array[3]);
void delay(uint n);
void main()
{
while(1)
{
delay(5000);
pcm_fashe(array_data);
delay(50000);
}
}
void pcm_fashe(uint array[3])
{
uchar i,j;
TMOD=0x02; //T0选方式2
TH0=0x83; //125us定时
TL0=0x83;
EA=1;
ET0=1;
TR0=1;
for(i=0;i<3;i++)
{
an=array[i];
for(j=0;j<16;j++)
{
a=1<<j;
b=an&a; //取第j位
while(!c); //c=0
c=0; //c=1取0
}
}
TR0=0;
ET0=0;
EA=0;
}
void fashe_t0()interrupt 1
{
if(b) //b=1
{
d=~d;
if(d)
{
pcm_1=1; //产生+1
delay(20);
pcm_1=0;
c=1;
}
else //产生-1
{
pcm_0=1;
delay(20);
pcm_0=0;
c=1;
}
}
else //b=0
c=1;
}
void delay(uint n) //延时
{
uint i;
for(i=0;i<n;i++);
} |