The campus bus uses an embedded system that tracks the number of passengers gett
ID: 1846800 • Letter: T
Question
The campus bus uses an embedded system that tracks the number of passengers getting in and those getting out of the bus. Two circuits with laser photodiodes, connected to RB0 (getting in) and RB1 (getting out), are used to track these numbers. At any time, the total number of passengers is equal to the total passengers entering in minus the total of those getting out of the bus. Whenever the total number of passengers in the bus reaches its maximum capacity (assumed equal to 30), the system turns on a red LED (connected to RD1). If the number is under 30, the system turns a green LED (connected to RD0).
a) Write an algorithm for the program (10 points)
b) Translate the algorithm to a C program (10 points)
Explanation / Answer
algorithm
let
RB0= Passenger is in
RB1= Passenger is out
RD0= show bus is under capacity
RD1= show bus full
laser diode used with photo diode.
//logic of main code. library will define according your microprosser.
#inculde <xxxxx>
int i=0; //initiate counter
while(i<=30) //loop start
{
if (RB0==0) //if any passenger is in so RB0 pin getting '0'(no voltage) by photo diode
{
in=0 //counter start how many passanger in
in=in++;
}
elseif(RB1==0) //if any passenger is out so RB1 pin getting '0'(no voltage) by photo diode
{
out=0 //counter start how many passanger out
out=out++;
}
else //condition tell us how much is in the bus
{
in-out<=i //if in-out less than or equal to value of i its mean it is under 30.
RD0==0; // so led greed will on by generating pulse low. (where anode of led connected +5V with resitance)
i=i++; //main loop counter
}
RD1==0; //if counter not work, its mean bus has 30 pass. so loop exit and turn on led red.
return(0) // return to initial.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.