C51程序
/*说明:用K1开关控制报警器,程序控制P1.0输出两种不同频率的声音,模拟很逼真的报警效果
*/
#include<reg51.h>
//#define uchar unsigned char
#define uint unsigned int
sbit motor_control_1 = P2^0;
sbit motor_control_2 = P2^1;
sbit _Forward_ = P1^5;
sbit _Reverse_ = P1^6;
sbit _Stop_ = P1^7;
sbit Switch_led = P1^0;
sbit led = P3^0;
uint i;
void init_init()//初始化函数
{
led = 1;
}
void delay_ms(int x)//延时函数 i=1时,大约延时10us
{
int i,j;
for(i=110;i>0;i--)
for(j=x;j>0;j--);
}
void motor_control()//电机控制函数
{
if( _Forward_ == 0 )
{
motor_control_1 = 1;
motor_control_2 = 0;
}
else if( _Reverse_ == 0 )
{
motor_control_1 = 0;
motor_control_2 = 1;
}
else if( _Stop_ == 0 )
{
motor_control_1 = 0;
motor_control_2 = 0;
}
}
void led_shine()//led闪烁函数
{
//if(Switch_led == 0 )
// {
for(i=0;i<20;i++)
{
led = ~led;
delay_ms(500);
}
// }
}
void main()//主函数
{
init_init();
while(1)
{
motor_control();
//led_shine();
EA = 1;
EX0 = 1;
IT0 = 1;
while(1);
}
}
void EX0_LED()interrupt 0
{
led_shine();
}
Proteus仿真电路
百度网盘链接
链接:https://pan.baidu.com/s/1KJDzPX_ANXvH9j2t-ghY6g
链接: link
提取码:2020
复制这段内容后打开百度网盘手机App,操作更方便哦