Developing a Home Security System with Digital I/O in C

School
Brigham Young University, Idaho**We aren't endorsed by this school
Course
ECEN 390
Subject
Electrical Engineering
Date
Dec 12, 2024
Pages
7
Uploaded by ProfessorOpossumMaster1110
This lab report was created from a template by a student in ECEN 260 during the Winter 2024 semester. Use of this report by students in other semesters is not allowed and is academic dishonesty. ECEN 260 Lab ReportLab #5: Digital Input & Output in ‘C’Name: Leaton Jenkins Lab Partner: Hunter and Case Date: May 22, 2024 Instructor: ____________________ Semester: ______Winter 2024____
Background image
This lab report was created from a template by a student in ECEN 260 during the Winter 2024 semester. Use of this report by students in other semesters is not allowed and is academic dishonesty. Lab Overview In this lab, we focused on developing a simple home security system using the C programming language. The system utilizes digital inputs from buttons and reed switch sensors and outputs to status and alarm LEDs. The primary objective was to learn how to configure and manipulate GPIO (General-Purpose Input/Output) ports on a microcontroller to read inputs and control outputs effectively. By the end of this lab, we aimed to have a functional security system that could arm and disarm based on button inputs and trigger alarms if any sensor detected an intrusion while the system was armed. This exercise helped reinforce our understanding of digital I/O operations, GPIO configuration, and bitwise manipulation in embedded systems programming.Test Plan and Results Fill out the table below with your test plan.The test plan should include several tests, each with precise steps to complete the test. The set of tests should include common cases as well as edge cases / error cases as appropriate. Each test should also accurately indicate specificexpected results. Then, the actual results should be recorded after completing each test. Delete this paragraph. (i.e., Don’t leavethe template instructions in your report.)# Test Scenario Expected Result Observed Result 1 Press Arm Button (PC13) System arms, ArmStatus LED (PA5) turns on System arms, ArmStatus LED turns on 2 Press Disarm Button (PA4) System disarms, ArmStatus LED turns off, all Alarm LEDs turn off System disarms, ArmStatus LED and all Alarm LEDs turn off 3 Arm system, trigger Front Sensor (PA8) FrontAlarm LED (PA9) turns on FrontAlarm LED turns on 4 Arm system, trigger Back Sensor (PA6) BackAlarm LED (PA10) turns on BackAlarm LED turns on 5 Arm system, trigger Window Sensor (PA7) WindowAlarm LED (PA11) turns onWindowAlarm LED turns on 6 Disarm system after any sensor is triggered All Alarm LEDs turn off All Alarm LEDs turn off 7 Arm system, no sensor is triggered No Alarm LEDs turn on No Alarm LEDs turn on 8 Continuous arm/disarm cycling System should reliably arm and disarm with appropriate LED changes System reliably arms and disarms with appropriate LED changes Table 1: Test plan with expected and observed results. Code /* This program uses inputs from buttons and reed switch sensors * and outputs to status and alarm LEDs to create an home * security system. */
Background image
This lab report was created from a template by a student in ECEN 260 during the Winter 2024 semester. Use of this report by students in other semesters is not allowed and is academic dishonesty. // INSTRUCTIONS FOR 2-PERSON TEAM: // Person A needs to type parts 1, 3, and 5. // Person B needs to type parts 2, 4, and 6. // INSTRUCTIONS FOR 3-PERSON TEAM: // Person A needs to type parts 1 and 4. // Person B needs to type parts 2 and 5. // Person C needs to type parts 3 and 6. // GPIO Port struct typedef struct{ unsigned int MODER; // offset: 0x00 unsigned int OTYPER; // offset: 0x04 unsigned int OSPEEDR; // offset: 0x08 unsigned int PUPDR; // offset: 0x0C unsigned int IDR; // offset: 0x10 unsigned int ODR; // offset: 0x14 } Port; // Address of the Advanced High-performance Bus 2 Enable Register unsigned int* AHB2ENR = (unsigned int*) 0x4002104c; // Base addresses of the GPIO Port control registers (SFRs) Port* GPIOA = (Port*) 0x48000000; // base address of GPIOA Port* GPIOB = (Port*) 0x48000400; // base address of GPIOB Port* GPIOC = (Port*) 0x48000800; // base address of GPIOC /* Part 1. Typed by Leaton Jenkins. */ // input pins #defineArmButtonPin 13 // PC13
Background image
This lab report was created from a template by a student in ECEN 260 during the Winter 2024 semester. Use of this report by students in other semesters is not allowed and is academic dishonesty. #defineDisarmButtonPin 4 // PA4 #defineFrontSensorPin 8 // PA8 #defineBackSensorPin 6 // PA6 #defineWindowSensorPin 7 // PA7 // output pins #defineArmStatusPin 5 // PA5 #defineFrontAlarmPin 9 // PA9 #defineBackAlarmPin 10 // PA10 #defineWindowAlarmPin 11 // PA11 int main(void) { // Turn on GPIO clocks (Ports A, B, and C) *AHB2ENR |= 0b111; /* Part 2. Typed by Hunter Pecheos. */ // Configure button pin as inputs GPIOC->MODER &= ~(0b11 << (ArmButtonPin*2)); // configure ArmButtonPin as input GPIOA->MODER &= ~(0b11 << (DisarmButtonPin*2)); // configure DisarmButtonPin as input // Configure reed switch pins as inputs GPIOA->MODER &= ~(0b11 << (FrontAlarmPin*2)); // configure ArmButtonPin as input GPIOA->MODER &= ~(0b11 << (BackAlarmPin*2)); // configure DisarmButtonPin as input GPIOA->MODER &= ~(0b11 << (WindowSensorPin*2)); // configure ArmButtonPin as input
Background image
This lab report was created from a template by a student in ECEN 260 during the Winter 2024 semester. Use of this report by students in other semesters is not allowed and is academic dishonesty. /* Part 3. Typed by Case M. */ // Enable pull resistors GPIOA->PUPDR |= (0b01 << (DisarmButtonPin*2)); GPIOA->PUPDR |= (0b01 << (FrontSensorPin*2)); GPIOA->PUPDR |= (0b01 << (BackSensorPin*2)); GPIOA->PUPDR |= (0b01 << (WindowSensorPin*2)); /* Part 4. Typed by Leaton Jenkins. */ // Configure LED pins as outputs GPIOA->MODER = ~(0b01 << ArmStatusPin); GPIOA->MODER = ~(0b01 << FrontAlarmPin); GPIOA->MODER = ~(0b01 << BackAlarmPin); GPIOA->MODER = ~(0b01 << WindowAlarmPin); // Initialize Alarm Status (turn off all LEDs) GPIOA->ODR |= ~(0b01 << ArmStatusPin); GPIOA->ODR |= ~(0b01 << FrontAlarmPin); GPIOA->ODR |= ~(0b01 << BackAlarmPin); GPIOA->ODR |= ~(0b01 << WindowAlarmPin); // armed state (initialize to disarm) int armed = 0; // infinite loop while(1){ /* Part 5. Typed by Hunter Pecheos. */ // check if ArmButton is pressed if (ArmButtonPin==0){
Background image
This lab report was created from a template by a student in ECEN 260 during the Winter 2024 semester. Use of this report by students in other semesters is not allowed and is academic dishonesty. // a system armed = 1; // set arm state GPIOA->ODR |= (1 << ArmStatusPin); // turn on ArmStatus LED } // check if DisarmButton is pressed if (DisarmButtonPin==0){ // disarm system GPIOA->ODR &= ~(0 << ArmStatusPin); // reset arm state GPIOA->ODR &= ~(1 << ArmStatusPin); // turn off ArmStatus LED GPIOA->ODR &= ~(1 << FrontAlarmPin); // turn off FrontAlarm LED GPIOA->ODR &= ~(1 << BackAlarmPin); // turn off BackAlarm LED GPIOA->ODR &= ~(1 << WindowAlarmPin); // turn off WindowAlarm LED } /* Part 6. Typed by Case M. */ // if system is armed, check sensors if (armed){ // check the FrontSensor if ((GPIOA->IDR &(1 << FrontAlarmPin)) ){ // system armed & front door is open: GPIOA->ODR |= (1 << FrontAlarmPin); // turn on FrontAlarm LED } // check the BackSensor if ((GPIOA->IDR &(1 << BackAlarmPin)) ){ // system armed & front door is open: GPIOA->ODR |=(1 << BackAlarmPin); // turn on BackAlarm LED
Background image
This lab report was created from a template by a student in ECEN 260 during the Winter 2024 semester. Use of this report by students in other semesters is not allowed and is academic dishonesty. } // check the WindowSensor if ((GPIOA->IDR &(1 << WindowAlarmPin))){ // system armed & front door is open: GPIOA->ODR |=(1 << WindowAlarmPin); // turn on WindowAlarm LED } } } } Conclusion In summary, this lab enabled us to build and test a basic home security system using digital I/O operations in C. We successfully configured GPIO ports for both input (buttons and sensors) and output (LEDs) and implemented the logic to control the system’s armed and disarmed states. Through this exercise, we solidified our understanding of bitwise operations, GPIO configuration, and the importance of precise timing and state management in embedded systems. Connecting this lab to our coursework, the principles of digital logic and microcontroller programming were put into practice. The lab built on previous experiences with basic I/O operations, advancing our skills in managing multiple inputs and outputs in a coordinated manner. Looking ahead, the knowledge gained here will be crucial for more complex projects involving sensor integration, real-time processing, and interrupt handling in embedded systems.
Background image