Your team is asked to design a water pump control system as shown on figure 1. I
ID: 2083609 • Letter: Y
Question
Your team is asked to design a water pump control system as shown on figure 1. In this system, the power switch is connected to your embedded system via PortA pin 0 (called PA[0]), If the user turns on the system, you will read a logic "1" on PortA bit-0.
The PortA pin 1 is also connected to the water pump. If you set logic "1" on PortA[1], you will turn on the pump and fill the water into the tank.
You can directly read the user settings for the water-level value through the PortB and PortC (both are 8-bit, hence the distance range is from 0 to 255 cm).
The sensor used in the this system is an ultrasonic sensor. It is connected to the Timer0 port. You can directly read the Timer0 value, but that is not a real water level value! it is the time interval value. So you need to convert the time interval value to the distance value (cm).
The timer value is the amount of time it takes for an ultrasonic signal to travel from top of tank to the water surface. The speed of sound in the airs is 350m/sec. The timer clock frequency is 20MHz.
-------------------------------------------------------------------------------------------
THIS IS WHAT I HAVE SO FAR, BUT I KNOW IT IS WRONG
__fastcall TfMain::TfMain(TComponent* Owner)
: TForm(Owner)
{
iPortA = iPortB = iPortC = 0;
}
//---------------------------------------------------------------------------
void __fastcall TfMain::YourCodeHere()
PA[0]= 0x00;
if (PortA[0] & 0x00)PortA |= 0x01;
PortA[0] == 0x01;
if (PortA[0] & 0x01) Timer0=0x01;
while PortC[7:0]>= Timer0 >= PortB[7:0]
PortA[1]= 0x01;
if(PortA[1] & 0x01)PortC[7:0]=.0072857145;
else PortC[7:0]&= ~ .0072857145;
PortA[1]=0x01
if(PortA[1] & 0x01)PortB[7:0]=0;
else PortB[7:0]&= ~0;
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TfMain::Timer1Timer(TObject *Sender)
{
//
Timer_PreEvent();
Timer0 = 10 * 0.5;
Timer_PostEvent();
}
//---------------------------------------------------------------------------
void __fastcall TfMain::FormCreate(TObject *Sender)
{
//
Setup();
}
//---------------------------------------------------------------------------
void __fastcall TfMain::tkbPumpOffLevelChange(TObject *Sender)
{
iPortB = tkbPumpOffLevel->Min + (tkbPumpOffLevel->Max - tkbPumpOffLevel->Position);
}
//---------------------------------------------------------------------------
void __fastcall TfMain::tkbPumpOnLevelChange(TObject *Sender)
{
iPortC = tkbPumpOnLevel->Min + (tkbPumpOnLevel->Max - tkbPumpOnLevel->Position);
}
//---------------------------------------------------------------------------
void __fastcall TfMain::btOnOffClick(TObject *Sender)
{
iPortA ^= 0x01;
if (iPortA & 0x01)
spOnOffLight->Brush->Color = clLime;
else
spOnOffLight->Brush->Color = clGreen;
}
//
Explanation / Answer
#include<reg51.h>
sbit rs=P1^0;
sbit rw=P1^1;
sbit e=P1^2;
sbit quat=P3^0; // Quad water level
sbit half=P3^1; // half level of tank
sbit quat_3=P3^2; // three -fourth level of tank
sbit full=P3^3; //full level of tank
sbit motor=P3^4; //pin connected to motor
void delay(int k) //delay function
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<1275;j++);
}
void write(int j)
{
rs=1; //selecting rs pin to data mode
rw=0; //selecting rw pin to write mode
P2=j; //putting value on the pins
e=1; //high pulse
delay(1);
e=0; // low pulse
return;
}
void cmd(int j) //command function
{
P2=j; //put the data on pins
rs=0; //selecting rw pin to command mode
rw=0; //selecting to write
e=1;
delay(1);
e=0;
return;
}
void puts(char *a) // function to display string on LCD'
{
unsigned int p=0;
for(;a[p]!=0;p++)
write(a[p]);
}
void lcd_init(void) // function to initialise the LCD
{
cmd(0x38);
delay(1);
cmd(0x0c); //LCD turning on cmd
delay(1);
cmd(0x01); //clear lcd cmd
cmd(0x80); // starting point of LCD
}
void main()
{
lcd_init(); //LCD intialization
quat=half=quat_3=full=1; //configuring as input pins
quat=half=quat_3=full=0; //lowering input pins
motor = 0;
while(1)
{
if(quat==0&&half==0&&quat_3==0&&full==0) //when tank is empty
{
cmd(0x80); // to move the cursor to starting point of LCD
puts("EMPTY "); // dispalys empty on lcd
motor=1; // start motor
}
else if(quat==1&&half==0&&quat_3==0&&full==0) // when tank is quater
{
cmd(0x80);
puts("QUATER "); // dispalys Quarter on lcd
}
else if(quat==1&&half==1&&quat_3==0&&full==0) // when tank is half
{
cmd(0x80);
puts("HALF "); // dispalys half on lcd
}
else if(quat==1&&half==1&&quat_3==1&&full==0) // when tank is three-fourth
{
cmd(0x80);
puts("3/4 FULL "); // dispalys 3/4 full on lcd
}
else if(quat==1&&half==1&&quat_3==1&&full==1) // when tank is full
{
cmd(0x80);
puts("FULL "); // dispalys full on lcd
motor=0; // to stop the motor
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.