| 本帖最后由 火箭客 于 2013-12-14 21:02 编辑 
 求助高手帮忙,按图编个信号发生器程序。
 
   
 可以参考下面的程序:
 
 
 
 按键发音 
 /* 名称:按键发音 说明:按下不同的按键会使喇叭发出不同频率的声音。本例使用延时函数实现不同频率的声音输出,以后也可使用定时器 */ #include<reg51.h> #define uchar unsigned char #define uint unsigned int sbit BEEP=P3^7; sbit K1=P1^4; sbit K2=P1^5; sbit K3=P1^6; sbit K4=P1^7; //延时 void DelayMS(uint x) { uchar t; while(x--) for(t=0;t<120;t++); } //按周期t发音 void Play(uchar t) { uchar i; for(i=0;i<100;i++) { BEEP=~BEEP; DelayMS(t); } BEEP=0; } void main() { P1=0xff; BEEP=0; while(1) { if(K1==0) Play(1); if(K2==0) Play(2); if(K3==0) Play(3); if(K4==0) Play(4); } } |