Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert these C++ codes into assembly language using Atmel Studio 7 const int flowSensor = 2; // Flow rate sensor pin const int oneB =

Convert these C++ codes into assembly language using Atmel Studio 7
const int flowSensor = 2; // Flow rate sensor pin
const int oneB = 7; // OR-Gate IC pins
const int oneA = 8;
const int oneY = 9;
const int tempSensor = A3; // Temperature sensor pin
volatile int flowFrequency = 0; // Flow pulse
unsigned int flowRate = 0; // Variable for flow rate (L/Hour)
unsigned int flowThreshold = 191; // Maximum safe flow rate
unsigned long currentTime = 0; // Time since UNO is ON
unsigned long cloopTime = 0;
bool type = true; // true = Temperature, false = Flow
bool output = false; // Output variable for OR-Gate IC
int tempVoltage = 0; // Output variable for temperature sensor
double tempCelcius = 0; // Variable for temperature (degC)
double tempThreshold = 28.70; // Maximum safe temperature
void flow() {flowFrequency++;} // Interrupt function
void temperature() {
tempVoltage = analogRead(tempSensor);
tempCelcius = tempVoltage * 5; // 5V
tempCelcius = tempCelcius / 1024; // 1024 bits
tempCelcius = tempCelcius - 0.5; // Offset
tempCelcius = tempCelcius * 100; // Temperature value (degC)
Serial.print(tempCelcius);
Serial.println(" degC");
}
void waterFlow() {
currentTime = millis();
if (currentTime >= (cloopTime + 1000)) {
cloopTime = currentTime; // Update cloopTime
// Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min. (Results in +/- 3% range)
// (Pulse frequency x 60 min) / 7.5Q = flow rate in L/hour
flowRate = ((flowFrequency * 60) / 7.5);
flowFrequency = 0; // Reset pulse counter
Serial.print(flowRate, DEC);
Serial.println(" L/hour");
}
}
void setup() {
pinMode(tempSensor, INPUT);
pinMode(flowSensor, INPUT);
pinMode(oneA, OUTPUT);
pinMode(oneB, OUTPUT);
Serial.begin(9600); // Begin serial monitor
attachInterrupt(0, flow, RISING); // Setup interrupt
sei(); // Enable interrupt (Set I bit)
currentTime = millis(); // Input time since UNO is ON
cloopTime = currentTime;
}
// Parameter check function for temperature and flow rate
// Check type: true = temperature, false = flow rate
void parameterCheck(bool type, double data, double threshold) {
// Compares the current parameter data with its corresponding threshold
bool parameterExceed = (data >= threshold);
if (parameterExceed) {
if (type) { // Temperature exceeded
digitalWrite(oneB, HIGH);
Serial.println("TEMPERATURE: HIGH");
} else { // Flow rate exceeded
digitalWrite(oneA, HIGH);
Serial.println("FLOW : HIGH");
}
} else {
if (type) { // Normal temperature
digitalWrite(oneB, LOW);
Serial.println("TEMPERATURE: LOW");
} else { // Normal flow rate
digitalWrite(oneA, LOW);
Serial.println("FLOW : LOW");
}
}
}
void loop() {
temperature(); // Input and calculate temperature
waterFlow(); // Input and calculate flow rate
parameterCheck(true, tempCelcius, tempThreshold); // Check temperature
parameterCheck(false, flowRate, flowThreshold); // Check flow rate
output = digitalRead(oneY); // Warning data
if (output) Serial.println("WARNING"); // (Temperature OR flow rate) = HIGH
else Serial.println("NORMAL"); // (Temperature OR flow rate) = LOW
Serial.println(" "); // Print a blank line
delay(5000); // Next-batch-input delay time
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions