Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

FOR HCS12 dragon board : Develop an application intended to detect and control f

ID: 2249795 • Letter: F

Question

FOR HCS12 dragon board :

Develop an application intended to detect and control fire situations in buildings. The system architecture can be described as follows: Besides the HCS12 microcontroller, the Fire Detection & Control system uses PH0-PH3 of the HCS12 to interface 4 digital sensors and PB0- PB3 to interface 4 digital actuators (the sprinklers), where a bit is set if the corresponding sensor has detected a fire, and the bit is clear if no fire has been detected. The sprinklers are activated by setting the appropriate bits. The sensors are checked every 10 ms. A fire is identified when any of the sensors have been set for at least 30 ms. In this case, all the sprinklers are turned on, and remain on for a minimum of 5 seconds and until all sensors indicate no fire for 30 ms. Program using C

Explanation / Answer

#include <hidef.h> /* common defines and macros */

#include "derivative.h" /* derivative-specific definitions */

void MSDelay(unsigned int);

unsigned char array,s_on=0,s_off=0;

unsigned int a_on=1000,a_flag=0;

void main(void)

{

DDRB = 0xFF; //PORTB as output for sprinklers

DDRH = 0x00; //PORTH as input for fire sensors

while(1)

{

array = PORTH & 0x0F;

if (array!=0x00)

{

s_on = s_on+1; //variable to check sensor on for 30ms

if(s_on>3)

s_on=3;

s_off = 0;

}

else if(array == 0x00 && s_off==3)

{

s_on = 0;

}

else if(array == 0x00 && s_on==3)

{

s_off = s_off+1; //variable to check sensor off for 30ms

}

if (s_on==3 && a_flag==0)

{

PORTB=0x0F;

MSDelay(5000); //minimum 5 seconds actuator on

a_flag=1;

}

else if(s_off == 3 && a_flag==1)

{

PORTB=0x00; // actuator off when sensor off for 30ms

a_flag=0;

s_off=0;

}

MSDelay(10);

}

}

//millisecond delay for XTAL=8MHz

void MSDelay(unsigned int itime)

{

unsigned int i; unsigned int j;

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

for(j=0;j<4000;j++);   

}