o Assignment: A door sensor is connected to the RB1 pin, and a buzzer is connect
ID: 3707079 • Letter: O
Question
o Assignment: A door sensor is connected to the RB1 pin, and a buzzer is connected to RC7. Write a C language program to monitor the door sensor, and when it opens, sound the buzzer. You can sound the buzzer by sending a square wave of a few hundred Hz frequency to it. The buzzer remains active as long as the door remains open Hints: Planning on how to write the program and make use of tlow chart Use two functions to: implement a function called "delay" to be used in generating the square wave. A function that generates a square wave called " buz"Explanation / Answer
#include <P18F458.h >
void Delay (unsigned int) ; //function prototype
#define Dsensor PORTBbits.RB1
#define buzzer PORTCbits . RC7
void main (void)
{
TRISBbits.TRISB1 = 1; //PORTB.1 as an input
TRISCbits .TRISC7 = 0; //make PORTC . 7 an output
while (Dsensor ==1)
{
buzzer = 0; //here to make square wave for buzzer output with 200ms interval
Delay (5) ;
buzzer = 1;
Delay (5) ;
}
while (1) ; //stay here forever
}
//Delay function to generate the square wave.
void Delay(unsigned int itime)
{
unsigned int i;
unsigned char j;
for(i=O;i <itime;i++ )
for (j=0;j<165;j++);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.