need it in C You are asked to develop the software for a control panel of a home
ID: 2248633 • Letter: N
Question
need it in C
You are asked to develop the software for a control panel of a home automation system. You can write your software in either C or assembly. The system has 5 door/window sensors 0. Door/window signals are high if OK, and low if there is danger. There is an LED connected to pin PA6, which signifies an alarm. The LED interface is negative logic. Write the main program of the control panel that continuously checks the sensors and turns the connected warning LED if, and only if, two or more door/window s indicate there is danger. Assume the pins are initialized using the code in 1. witchesExplanation / Answer
Below is the code for sensor status reading and checking for two or more door danger status.
Lgic is that if all the doors oare OK, then PA0 to PA4 are HIGH. Therefore, the sum,
SUM = PA0 + PA1 + PA2 + PA3 + PA4 = 5;
If any two or more PAs are LOW, the sum will be less than or equal to 3.
************************************************************************************************
#define DOOR_1 PA_4
#define DOOR_2 PA_3
#define DOOR_3 PA_2
#define DOOR_4 PA_1
#define DOOR_5 PA_0
#define LED PA_6
#define TURN_ON 0
#define TURN_OFF 1
void main(void)
{
unsigned char Door_1_Val=0,Door_2_Val=0,Door_3_Val=0,Door_4_Val=0,Door_5_Val=0;
unsigned char Sum=0;
while(1)
{
Door_1_Val = DOOR_1;
Door_2_Val = DOOR_2;
Door_3_Val = DOOR_3;
Door_4_Val = DOOR_4;
Door_5_Val = DOOR_5;
Sum = Door_1_Val + Door_2_Val + Door_3_Val + Door_4_Val + Door_5_Val;
if(Sum <= 3) LED = TURN_ON;
else LED = TURN_OFF;
}
}
************************************************************************************************
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.