2.12 蜂鸣器发出声音BO...BO..
1 //--------------------------------------------------------------------------
2 //来源: http://hi.baidu.com/mculove/home
3 //程序名称: 蜂鸣器发出声音BO...BO..
4 //晶振: 11.0592MHz;
5 //MCU型号: STC89C52RC;
6 //电路板型号: EBV-MV(51实验板);
7 //--------------------------------------------------------------------------
8
9
10
11
12 //--------------------------------------------------------------------------
13 //硬件连接:(格式说明:端口名表示"板名-{模片名}-器件名-[端口名]",连接表示"->")
14 //EBVn-[VCC] -> MVn-[--VCC--]
15 //EBVn-[GND] -> MVn-[//GND//]
16 //EBVn-[P10] -> MVn-{EX5}-[OUT]
17 // -> MVn-{EX5}-(VCC)
18 //--------------------------------------------------------------------------
19
20
21
22
23 //--------------------------------------------------------------------------
24 //实验结果:
25 //蜂鸣器发出声音BO...BO..
26 //--------------------------------------------------------------------------
27
28
29
30
31 //------------------------------------------------------
32 //头文件;
33 #include <AT89X52.H>
34
35
36 //------------------------------------------------------
37 //延时程序;
38 void delay(void)
39 {
40 unsigned char i,j; //定义变量i,j;
41 for(i=0;i<250;i++) //延时程序;
42 for(j=0;j<250;j++);
43 }
44
45
46 //------------------------------------------------------
47 //程序入口;
48 void main(void)
49 {
50 while(1)
51 {
52 P1_0 = 1; //单片机端口P10输出高电平
53 delay(); //调用延时程序;
54 P1_0 = 0; //单片机端口P10输出低电平
55 delay();
56 }
57 }