- #1
Altairs
- 127
- 0
This is example 7-14 from "The 8051 Microcontroller and Embedded Systems" by Mazidis and McKinlay.
A door sensor is connected to P1.1 pin, and a buzzer is connected to P1.7. Write an 8051 C program to monitor the door sensor, and when it opens, sound the buzzer.
My question is that we are initializing DSensor to 1 to make it input. But in the condition while (Dsensor == 1) checks that as long as that pin remain input the buzzer should sound. How will this condidtion ever become false? As far as I can see it will always remain true.
A door sensor is connected to P1.1 pin, and a buzzer is connected to P1.7. Write an 8051 C program to monitor the door sensor, and when it opens, sound the buzzer.
Code:
#include <reg51.h>
void MSDelay(unsigned int);
sbit Dsensor = P1^1;
sbit Buzzer = P1^7;
void main(void)
{
Dsensor = 1;
while (Dsensor ==1)
{
buzzer=0;
MSDelay(250);
buzzer=1;
MSDelay(250);
}
}
void MSDelay(...
My question is that we are initializing DSensor to 1 to make it input. But in the condition while (Dsensor == 1) checks that as long as that pin remain input the buzzer should sound. How will this condidtion ever become false? As far as I can see it will always remain true.