MNM Report 2 - Merged

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

UNIVERSITY OF ENGINEERING &TECHNOLOGY

TAXILA

ELECTRONICS ENGINEERING DEPARTMENT

Microprocessor & Microcontroller


Open Ended Lab

4th Semester
Electronic Engineering Department
(B.Sc. Electronics Engineering)

Instructor: Engr.Tahir Khan


Submitted By:
Harman Ali 22-ENC-21
Ali Haider 22-ENC-11
Aftab Ahmed 22-ENC-35
Hassan Ali 22-ENC-29
Open Ended Lab

Design of a Real Time Threat Detection System

Objective:

• Write the AVR C Language Code to design of a real time threat detection
system
• Perform all simulations/hardware implementation

Introduction:
Consider a Weapons Defense System, whose job is to shoot down incoming missiles and protect
the Naval Destroyer. This Weapons Defense System consists of three subsystems: a Radar
System, a Control System and a Weapons Firing System.
The Control System (microcontroller) act as a Command and Decision System, which is a
controlling system and the Radar System and Weapons Firing System are the controlled systems.
Now we will see how this Real Time System works in a realworld scenario.
First, the Radar System continuously monitors for potential threats like incoming missiles and
measures the coordinates of the targets. It then sends these coordinates to the Control System,
which then determines the level of threat possessed by the target based on the information from
the Radar System. The Command and Decision System then calculates different parameters of
the target like speed of the missile, flight path and possible point of impact.
Based on the above parameters, the Control System then activates the Weapons Firing System,
which fires continuously until the target is destroyed.
In this example, the communication between the Command and Decision System and the
Radar system happens in real time i.e., a potential threat can occur at any time and it is
unpredictable. The second real time computing is the firing coordinates. Initially, they are
determined by the flight path of the target but are updated in real time as per the actual location
of the target.
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

// Define the memory addresses for LCD data and control ports
#define LCD_DATA_PORT PORTA
#define LCD_CONTROL_PORT PORTB
#define RS_PIN PB0
#define EN_PIN PB1
// Define the memory address for the fire pin
#define FIRE_PIN PC0

// Function to initialize the LCD


void LCD_Init() {
LCD_Command(0x38); // 2 lines, 5x7 matrix
LCD_Command(0x0C); // Display on, cursor off
LCD_Command(0x06); // Increment cursor
LCD_Command(0x01); // Clear display
LCD_Command(0x80); // Move cursor to the beginning of the first line
}

// Function to send a command to the LCD


void LCD_Command(unsigned char command) {
LCD_DATA_PORT = command;
LCD_CONTROL_PORT &= ~(1 << RS_PIN); // Select command register
LCD_CONTROL_PORT |= (1 << EN_PIN); // Enable pulse
_delay_ms(1);
LCD_CONTROL_PORT &= ~(1 << EN_PIN);
_delay_ms(3);
}

// Function to send data to the LCD


void LCD_Data(unsigned char data) {
LCD_DATA_PORT = data;
LCD_CONTROL_PORT |= (1 << RS_PIN); // Select data register
LCD_CONTROL_PORT |= (1 << EN_PIN); // Enable pulse
_delay_ms(1);
LCD_CONTROL_PORT &= ~(1 << EN_PIN);
_delay_ms(3);
}

// Function to display the calculated coordinates on the LCD


void displayCoordinates(unsigned char x, unsigned char y, unsigned char blink) {
LCD_Command(0xC0); // Move cursor to the beginning of the second line
// Convert the coordinates to ASCII characters
unsigned char x_ascii = x + 48;
unsigned char y_ascii = y + 45;
LCD_Data(X);
LCD_Data(:);
if (blink) {
LCD_Data( ); // Blink X point
} else {
LCD_Data(x_ascii);
}
LCD_Data( );
LCD_Data(Y);
LCD_Data(:);
if (blink) {
LCD_Data( ); // Blink Y point
} else {
LCD_Data(y_ascii);
}
}

int main() {
// Initialize LCD pins as output
DDRB = 0xFF;
DDRC = (1 << FIRE_PIN);
// Initialize the LCD
LCD_Init();

// Display "Firing System" on the first line with a 100ms delay for each alphabet
LCD_Command(0x80); // Move cursor to the beginning of the first line
LCD_Data(F);
_delay_ms(150);
LCD_Data(I);
_delay_ms(150);
LCD_Data(R);
_delay_ms(150);
LCD_Data(I);
_delay_ms(150);
LCD_Data(N);
_delay_ms(150);
LCD_Data(G);
_delay_ms(150);
LCD_Data( );
_delay_ms(150);
LCD_Data(S);
_delay_ms(150);
LCD_Data(Y);
_delay_ms(150);
LCD_Data(S);
_delay_ms(150);
LCD_Data(T);
_delay_ms(150);
LCD_Data(E);
_delay_ms(150);
LCD_Data(M);

// Enable interrupts
sei();

while (1) {
// Wait for valid coordinates signal
while (!(PIND & (1 << PD0)));
// Read the coordinates from the input
unsigned char coordinates = PINA;
// Extract the x and y coordinates from the input
unsigned char x = coordinates >> 4;
unsigned char y = coordinates & 0x0F;
// Blink X and Y points of coordinates for 100ms
for (unsigned char i = 0; i < 4; i++) {
displayCoordinates(x, y, 1);
_delay_ms(50);
displayCoordinates(x, y, 0);
_delay_ms(50);
}
// Activate the firing system
PORTC |= (1 << FIRE_PIN);
}

return 0;
}

Code Explanation:

• Header Inclusions:
The code includes necessary AVR library files for I/O operations and delay functions.

• Macro Definitions:
`LCD_DATA_PORT`, `LCD_CONTROL_PORT`: Define memory addresses for LCD
data and control ports.
`RS_PIN`, `EN_PIN`: Define memory addresses for control pins of the LCD.
`FIRE_PIN`: Define memory address for the pin connected to the firing mechanism.

• LCD Initialization:
`LCD_Init()`: Initializes the LCD by sending commands to set up its configuration.

• LCD Command and Data Functions:


`LCD_Command(unsigned char command)`: Sends a command to the LCD.
` `LCD_Data(unsigned char data)`: Sends data to the LCD.

• Display Coordinates Function:


`displayCoordinates(unsigned char x, unsigned char y, unsigned char blink)`: Displays
the calculated coordinates on the LCD, with an option to blink the coordinates.

• Main Function:
Initializes necessary pins as input/output.
Initializes the LCD.
Displays "Firing System" on the first line of the LCD.
Enables interrupts.
Enters an infinite loop.
Waits for a signal indicating valid coordinates (`PIND & (1 << PD0)`).
Reads the coordinates from the input (`PINA`).
Extracts the x and y coordinates.
Blinks the x and y coordinates on the LCD.
Activates the firing system by setting the `FIRE_PIN` high (`PORTC |= (1 <<
FIRE_PIN)`).
Overall, the code initializes the LCD, waits for valid coordinates, and then activates the
firing system based on those coordinates. It seems like a simple control program for a
firing system with an LCD display for feedback.

Proteus:

Conclusion:
In conclusion, the design of a real-time threat detection system represents a critical
fusion of advanced sensor technologies, machine learning algorithms, and robust data processing
architectures to swiftly identify and respond to potential security risks. By leveraging a
combination of sensors such as cameras, motion detectors, and environmental sensors, alongside
sophisticated AI algorithms capable of recognizing patterns indicative of threats, the system can
provide rapid and accurate threat detection capabilities. Moreover, the integration of real-time
data processing and analysis enables immediate response actions, ensuring the protection of
assets and individuals in dynamic environments. As technology continues to evolve, the ongoing
refinement and adaptation of such systems will be essential in addressing emerging security
challenges and safeguarding against evolving threats.

You might also like