Program design of switch control alarm

Name: Switch-Controlled Alarm System

Description: This project uses a K1 switch to control an alarm system. The program generates two different frequencies on P1.0, creating a realistic and effective alarm sound.

/*

Author: [Your Name]

Date: [Insert Date]

*/

#include

#define uchar unsigned char

#define uint unsigned int

sbit SPK = P1^0;

sbit K1 = P1^7;

// Function to generate alarm sound

void Alarm(uchar t)

{

uchar i, j;

for (i = 0; i < 200; i++)

{

SPK = ~SPK;

for (j = 0; j < t; j++); // Adjust frequency based on parameter t

}

}

// Main function

void main()

{

SPK = 0;

while (1)

{

if (K1 == 1)

{

Alarm(90);

Alarm(120);

}

}

}

Switch-Controlled Alarm System Design

This project demonstrates how to use a simple microcontroller (like the 8051) to create an alarm system controlled by a physical switch. When the K1 switch is activated, the system triggers two different tones on a speaker connected to pin P1.0. The tone frequency is determined by the value passed into the Alarm() function, allowing for a more dynamic and realistic alarm sound. The code uses basic delay loops to control the timing of the sound pulses, making it easy to adjust and test. This kind of system can be used in various applications such as security systems, warning signals, or even educational projects for learning embedded programming. The visual diagram included shows the circuit layout, helping users understand how the hardware components are connected and operate together.

P02 Series Push Wire Connectors

Multi-pole push-in connector

Mono/dual press button for easy wiring and releasing

Compatible with earth tag and/or cable clamp

Fast Connection Wire Connector,14-20 awg Wire Connectors,4 Pole Push Wire Connector,2 Ways Push Wire Connector

Jiangmen Krealux Electrical Appliances Co.,Ltd. , https://www.krealux-online.com