|
单片机之简易蜂鸣器与继电器- #include "STC15F2K60S2.h"
- #include "intrins.h"
- sbit buzzer=P0^6;
- sbit relay=P0^4;
- void Delay500ms();
- void main(void)
- {
- while(1)
- {
- P2=0xa0;buzzer=1;relay=1;P2=0x1f; //打开蜂鸣器和继电器
- Delay500ms();Delay500ms(); //延时1s
- P2=0xa0;buzzer=0;relay=0;P2=0x1f; //关闭蜂鸣器和继电器
- Delay500ms();Delay500ms();
-
- }
- }
- void Delay500ms() //@11.0592MHz
- {
- unsigned char i, j, k;
- _nop_();
- _nop_();
- i = 22;
- j = 3;
- k = 227;
- do
- {
- do
- {
- while (--k);
- } while (--j);
- } while (--i);
- }
复制代码
|
|