用一个三极管放大一下电流。。。 单片机输出的电流很小 用一个三级管,不管是9012,还是9013 都可以。
具体原理就是利用三极管的放大作用。
这是一首歌 猜出有奖哦。。。呵呵。
P10 接蜂鸣器
下面贴出代码
-
- #include
- ***it fmq=P1^0;
- void delayms(unsigned char ms);
- unsigned int data j;
- unsigned char code song[636]={
- 0xFF,0xFF,4,0xFd,0x08,2,0xFd,0x08,2,0xFd,0x08,2,0xFd,0x08,2,0xFd,0x08,2,0xfd,0x08,2, //21
- 0xFD,0x5B,4,0xFD,0x08,2,0xFC,0xAB,2,0xFC,0x0B,2,0xFC,0x0B,2,0xff,0xff,2,0xFc,0x0B,2, //21
- 0xFC,0xAB,2,0xFC,0xAB,2,0xFC,0xAB,2,0xFC,0xAB,2,0xFC,0xAB,4,0xFC,0xAB,2,0xFC,0xAB,2, //21
- 0xFB,0x8F,2,0xFC,0x0B,2,0xFC,0x0B,4,0xff,0xff,8, //12
- 0xff,0xff,2,0xFD,0x08,2,0xFD,0x08,2,0xFD,0x08,2,0xFD,0x08,4,0xFD,0x08,2,0xFD,0x08,2, //21
- 0xFD,0x5B,4,0xFD,0x08,2,0xFC,0xAB,4,0xFD,0x08,6, //12
- 0xff,0xff,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x03,2,0xFA,0x14,2, //24
- 0xFC,0xAB,4,0xFC,0xAB,2,0xFC,0xAB,2,0xFC,0xAB,2,0xFC,0x0B,2,0xFC,0x0B,4, //18
- 0xFF,0xFF,4,0xFD,0x08,2,0xFD,0x08,2,0xFD,0x08,2,0xFD,0x08,2,0xFD,0x08,2,0xFD,0x08,2, //21
- 0xFD,0x5B,4,0xFD,0x08,2,0xFC,0xAB,4,0xFD,0x08,6, //12,183
- 0xFF,0xFF,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x03,2,0xFA,0x14,2, //24
- 0x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x14,2,0xfa,0x14,4, //18
- 0xff,0xff,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x03,2,0xFA,0x14,2, //24
- 0xfb,0x03,2,0xfb,0x03,2,0xfb,0x03,2,0xfa,0x14,2,0xfa,0x14,1,0xf9,0x5b,1,0xf8,0x2a,2,0xf8,0x2a,4, //24
- 0xff,0xff,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x03,2,0xFA,0x14,2, //24
- 0xfb,0x8f,2,0xfc,0x08,2,0xfc,0x08,2,0xfc,0x08,10, //12
- 0xff,0xff,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x03,2,0xFA,0x14,2, //24
- 0xfb,0x03,2,0xfb,0x03,2,0xfb,0x03,2,0xfa,0x14,2,0xfa,0x14,1,0xf9,0x5b,1,0xf8,0x2a,2,0xf8,0x2a,4, //24,207
- 0xff,0xff,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x8F,2,0xFB,0x03,2,0xFA,0x14,2, //24
- 0xfc,0xab,2,0xfd,0x08,2,0xfd,0x08,2,0xfd,0x08,2,0xff,0xff,4,0xff,0xff,4}; //18,42,636
- void main()
- { TMOD = 0x01;
- IE = 0x82;
- while(1)
- { j=0;
- while (j<636)
- { TR0=1;
- if ((song[j]==0xff)&&(song[j+1]==0xff)) TR0=0;
- delayms(song[j+2]);
- j=j+3;
- }
- }
- }
- void timer0() interrupt 1 using 1
- { TH0=song[j];
- TL0=song[j+1];
- fmq = !fmq;
- }
- void delayms(unsigned char ms)
- { unsigned int i;
- while(ms--)
- {
- for(i = 0; i < 20300; i++);
- }
- TR0=0;
-
- }
复制代码
0
|
|
|
|