蜂鸣器发声
#include #define uchar unsigned char
#define uint unsigned int
sbit speaker=P3^7;
uint j;
uchar m=11;
uchar flag;
uchar line;
uchar code * data song;
//
// 延时程序 //
//
void delay(uint d) //延时d微秒,最大延时65536微妙
{
while(d--);
}
void delay187ms(void)
{
uchar t;
for(t=0;t<130;t++) delay(100);
}
void main()
{
uchar i;
uchar k;
delay(100);
TMOD=0x01;
IT0=1;
EX0=1;
TR0=1;
ET0=1;
EA=1;
song=song1;
while(1)
{
switch(m)
{
case 1 :song=song1;break;
case 2 :song=song2;break;
case 3 :song=song3;break;
case 4 :song=song4;break;
case 5 :song=song5;break;
case 6 :song=song6;break;
case 7 :song=song7;break;
case 8 :song=song8;break;
case 9 :song=song9;break;
case 10 :song=song10;break;
case 11 :song=song11;break;
case 12 :song=song12;break;
default :m=1;song=song1;break;
}
j=0;
flag=1;
while(*(song+j)!=0xFF&&flag)
{
k=*(song+j)&0x0F; //取出节拍
line=*(song+j)>>4; //取出音
TH0=yin[2*line];
TL0=yin[2*line+1];
TR0=1;
if ((yin[2*line]==0xFF)&&(yin[2*line+1]==0xFF))
{
TR0=0;
}
for(i=k;i>0;--i)
{
delay187ms();
}
TR0=0;
j++;
}
for(i=0;i<20;i++)delay187ms();
m++;
}
}
void timer1() interrupt 1
{
TH0=yin[2*line];
TL0=yin[2*line+1];
speaker=!speaker;
}
void int0() interrupt 0
{
flag=0;
TR0=0;
}
TEST.C(359): error C141: syntax error near '#'
TEST.C(359): error C129: missing ';' before 'unsigned'