#include
#define uchar unsigned char
#define uint unsigned int
***it SCL=P2^6;
***it SDA=P2^7;
***it key1=P3^6;
***it key2=P3^7;
uint n=0;
uchar code Sinwave[]={ //正弦波波表
127, 152, 176, 198, 217, 233, 245, 252,
255, 252, 245, 233, 217, 198,176, 152,
127, 102, 78, 56, 37, 21, 9, 2,
0, 2, 9, 21, 37, 56, 78, 102
};
uchar code Triwave[] = { //三角波波表
0, 16, 32, 48, 64, 80, 96, 112,
128, 144, 160, 176, 192, 208,224, 240,
255, 240, 224, 208, 192, 176, 160, 144,
128, 112, 96, 80, 64, 48, 32, 16
};
uchar code Sawwave[] = { //锯齿波表
0, 8, 16, 24, 32, 40, 48, 56,
64,72,80, 88, 96, 104, 112,120,
128, 136, 144, 152, 160, 168, 176,184,
192, 200, 208, 216, 224,232, 240, 248,
};
uchar code Squwave[]={ //方波波表
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255
};
uint f=30;
void delay()
{ ; ; ;}
void delay10()
{ uint i,j;
for(i=0;i<10;i++)
for(j=0;j<250;j++);
}
void delay11()
{ uint i,j;
for(i=0;i
for(j=0;j<250;j++);
}
void init()
{ SCL=1;
delay();
SDA=1;
delay();
}
void start()
{ init();
SDA=0;
delay();
}
void write(uchar date)
{ uchar i,temp;
temp=date;
for(i=0;i<8;i++)
{ temp=temp<<1;
SCL=0;
delay();
SDA=CY;
delay();
SCL=1;
delay();
}
SCL=0;
delay();
SDA=1;
delay();
}
void respons()
{ uchar i;
SCL=1;
delay();
while((SDA==1)&&(i<250))
i++;
SCL=0;
delay();
}
void stop()
{
SDA=0;
delay();
SCL=1;
delay();
SDA=1;
delay();
}
void writewave(uchar xc)
{
init();
start();
write(0x90);
respons();
write(0x40);
respons();
write(xc);
respons();
stop();
}
void keyscan()
{ if(key1==0)
{
delay10();
if(key1==0)
{ f+=10;
while(!key1);
}
}
if(key2==0)
{
delay10();
if(key2==0)
{ f-=10;
if(f<=20) f=20;
while(!key2);
}
}
}
void main()
{
while(1)
{ keyscan();
for(n=0;n<32;n++)
{ writewave(Sinwave[n]);
delay11(); }
for(n=0;n<32;n++)
{ writewave(Triwave[n]);
delay11(); }
for(n=0;n<32;n++)
{ writewave(Sawwave[n]);
delay11();}
for(n=0;n<32;n++)
{ writewave(Squwave[n]);
delay11(); }
}
}
|