Question

Design a way of using the pushbutton to trigger an interrupt to your system. Your system,...

Design a way of using the pushbutton to trigger an interrupt to your system. Your system, upon receiving this interrupt, responds by reading and displaying the temperature in Fahrenheit degrees on the LCD display in the format of xxx.x. The system must resume displaying the digital clock. Build your circuit and include all the required information about your hardware design in your lab report. 4. Based on the hardware you designed, choose an interrupt/timer tool from mbed to update the LCD display with the digital clock HH:MM:SS every second with the correct time of second, minute and hour. You must NOT have any code for counting or displaying the clock display with hour, minute or second in the main() function other than setting the clock display to 00:00:00 at start up. This means, you should use a timing tool (interrupt or timer) to update the clock display rather than using wait(1) for waiting for 1 second. Whenever the user pushes on the push button and releases it, the system will respond to it by measuring the current temperature and displaying the temperature to the LCD for approximately 1 second. Then the system shall resume the display of the current digital time. Keep in mind, the clock should continue counting as if the temperature reading was never done instead of restarting from 00:00:00.

If you can help out with this can you please type the code so it can be easier to read. I have a temp sensor code as well as the lcd code. I am unsure of how to integrate the pushbutton as the interrupt.

#include "mbed.h"

#include "TextLCD.h"

TextLCD lcd(p15, p16, p17, p18, p19, p20);

int hours, minutes, seconds;

int main() {

hours=0; minutes=0; seconds=0;

while(1){

if(seconds==60){ seconds=0; minutes++; }

if(minutes==60){ minutes=0; hours++; }

if(hours==24){ hours=0; } lcd.locate(0, 1);

// row 1, column 0 lcd.printf("%02d:%02d:%02d", hours, minutes, seconds); //to printing the values in lcd seconds++; //second increases after one second

wait(1); //wait apply for wait one second } }

///The below is the syntax for SEN-11931 temperature sensor:

#include "mbed.h"

const unsigned int DIGIT_0 = 0xC0;

const unsigned int DIGIT_1 = 0xFC;

const unsigned int DIGIT_2 = 0xA4;

const unsigned int DIGIT_3 = 0xB0;

const unsigned int DIGIT_4 = 0x99;

const unsigned int DIGIT_5 = 0x92;

const unsigned int DIGIT_6 = 0x82;

const unsigned int DIGIT_7 = 0xF8;

const unsigned int DIGIT_8 = 0x80;

const unsigned int DIGIT_9 = 0x98;

const unsigned int DIGIT_PT = 0x7F;

const int TEMP_ADDR = 0x90; DigitalOut l3n(p21);

DigitalOut l3p(p21);

BusOut l1l2(p17, p24);

BusOut digselect(p20, p19, p15, p13);

BusOut digit(p26, p11, p25, p18, p16, p23, p12, p14);

unsigned int segDriverDigit(unsigned int digit_in);

unsigned int display5sec(float temp);

I2C tempsensor(p9, p10);

Serial pc(USBTX, USBRX);

// print temperature on console char config_t[3];

char temp_read[2];

int main() {

float temp_reading;

config_t[0] = 0x01;

config_t[1] = 0x60;

config_t[2] = 0xA0;

tempsensor.write(TEMP_ADDR, config_t, 3);

config_t[0] = 0x00;

tempsensor.write(TEMP_ADDR, config_t, 1);

while(1) {

tempsensor.read(TEMP_ADDR, temp_read, 2);

temp_reading = 0.0625 * (((temp_read[0] << 8) + temp_read[1]) >> 4)*1.8 + 32.0; display5sec(temp_reading);

}

}

unsigned int segDriverDigit(unsigned int digit_in) {

int myDigit; int retVal = 0xFF; myDigit = digit_in%10; switch (myDigit){

case 0: retVal = DIGIT_0; break;

case 1: retVal = DIGIT_1; break;

case 2: retVal = DIGIT_2; break;

case 3: retVal = DIGIT_3; break;

case 4: retVal = DIGIT_4; break;

case 5: retVal = DIGIT_5; break;

case 6: retVal = DIGIT_6; break;

case 7: retVal = DIGIT_7; break;

case 8: retVal = DIGIT_8; break;

case 9: retVal = DIGIT_9; break;

}

return retVal;

}

unsigned int display5sec(float temp) {

int s;

unsigned int tempDisplay = static_cast(temp*10);

for (s = 0; s < 250; s++) {

digselect = 0x1;

digit = segDriverDigit(tempDisplay/1000);

wait_ms(5);

digselect = 0x2;

digit = segDriverDigit(tempDisplay/100);

wait_ms(5);

digselect = 0x4;

digit = segDriverDigit(tempDisplay/10)& DIGIT_PT;

wait_ms(5);

digselect = 0x8;

digit = segDriverDigit(tempDisplay%10);

wait_ms(5);

}

return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Even a simple temperature control application, for instance, includes a number of tasks like reading the user input, displaying the data on an LCD, reading the temperature.

Interrupts must be carefully and cautiously handled, mainly because carelessly written interrupts can lead to some mysterious run-time errors.

bit flag;

#pragma interrupt_handler ISR

void ISR(void)
{
   flag=1;
}

void main()
{
   --
   --
   while(1)
   {
      --
      --
      /* Wait for the ISR to set the
      * flag; reset it before
      * taking any action. */
      if (flag)
      {
         flag = 0;
     /* Perform the required action here */
      }
   }
}

timer ISR is to be implemented in such a way that it generates timings in the order 10ms, 14ms, 19ms, and the cycle should continue. A simple way to change the period inside an ISR could be as follows:

#define PERIOD_10ms 0x01
#define PERIOD_14ms 0x02
#define PERIOD_19ms 0x03

void Timer_ISR(void)
{
   static char State = PERIOD_10ms;

   switch(State)
   {
      case PERIOD_10ms:
      {
         // Toggle pin;
         // Timer Stop;
         // Change period to 14ms;
         // Timer Start;
         break;
      }
      case PERIOD_14ms:
      {
   // Toggle pin;
   // Timer Stop;
   // Change period to 19ms;
   // Timer Start;
         break;
      }
      case PERIOD_19ms:
      {
   // Toggle pin;
   // Timer Stop;
   // Change period to 10ms;
   // Timer Start;
   break;
      }
      default:
      {
         /* Timer_ISR entered undefined state */
         // Make default period 10ms
         break;
      }
   }
}

displaying the digital clock:

#include<stdio.h>

#include<time.h>

int main()

{

   time_t ts,flag=1;

struct tm *ct;

printf(“\n\nActive Digital Clock\n”);

while(1)

{

ts=time(NULL);

ct=localtime(&ts);

if(flag || ct -> tm_min % 59 ==0)

{

If(!flag)

printf(“\b\b\b”);

printf(“%02d:%02d:%02d”,ct -> tm_hour,ct ->tm_min,ct->tm_sec);

flag=0;

printf(“\b\b”);

continue;

}

If(ct -> tm_sec %59==0)

{

printf(“\b\b\b”);

printf(“%02d:”,ct->tm_min);

}

printf(“%02d”,ct->tm_sec);

printf(“\b\b”);

}

Return 0;

}

Add a comment
Know the answer?
Add Answer to:
Design a way of using the pushbutton to trigger an interrupt to your system. Your system,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the...

    HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the second line of the display, using the HH:MM:SS format. Use the 24-hour format for the hours, in other words, have the time go from 00:00:00 to 23:59:59. #include<LiquidCrystal.h> LiquidCrystal LcdDriver(11, 9, 5, 6, 7, 8); int minutes = 27; //These global integers keep the value of the clock int sec = 10; int hr = 10; const long interval = 1000; //This interval is...

  • Write in C++ please In Chapter 10, the class clockType was designed to implement the time...

    Write in C++ please In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain applications, in addition to hours, minutes, and seconds, might require you to store the time zone. Derive the class extClockType from the class clockTypeby adding a member variable to store the time zone. Add the necessary member functions and constructors to make the class functional. Also, write the definitions of the member functions and the constructors. Finally, write...

  • Rewrite this code in Java please #include <iostream> #include <fstream> #include <cstdlib> #include <ctime> using namespace...

    Rewrite this code in Java please #include <iostream> #include <fstream> #include <cstdlib> #include <ctime> using namespace std; long length = 1000; const long max_length = 100000; int list[max_length]; void read() {     ifstream fin("random.dat", ios::binary);     for (long i = 0; i < length; i++)     {         fin.read((char*)&list[i], sizeof(int));     }     fin.close(); } void bubbleSort() {     int temp;     for(long i = 0; i < length; i++)     {         for(long j = 0; j< length-i-1; j++)...

  • Merge Sort: Time Complexity: O(n log(n)) #include "stdafx.h" #include <iostream> #include <time.h> #include <stdlib.h> using namespace...

    Merge Sort: Time Complexity: O(n log(n)) #include "stdafx.h" #include <iostream> #include <time.h> #include <stdlib.h> using namespace std; void combine(int *a, int low, int high, int mid) {        int i, j, k, c[100000];        i = low;        k = low;        j = mid + 1;        while (i <= mid && j <= high)        {               if (a[i] < a[j])               {                      c[k] = a[i];                      k++;                      i++;               }               else               {                     ...

  • Please explain to me how the following arduino code control the smart home system design below. #...

    Please explain to me how the following arduino code control the smart home system design below. #include "ESP8266.h" #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <dht.h> #define DATA_PIN 2 #define SSID       "abc" #define PASSWORD   "12345678" byte termometerLogo[8] = {     B00100,     B01010,     B01010,     B01110,     B01110,     B11111,     B11111,     B01110 }; byte humidityLogo[8] = {     B00100,     B00100,     B01010,     B01010,     B10001,     B10001,     B10001,     B01110, }; SoftwareSerial mySerial(10,11); ESP8266 wifi(mySerial); LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); dht DHT; char buffData[150]; const int...

  • Hi I need a fix in my program. The program needs to finish after serving the...

    Hi I need a fix in my program. The program needs to finish after serving the customers from the queue list. Requeriments: Headers: DynamicArray.h #ifndef DynamicArray_h #define DynamicArray_h #include using namespace std; template class DynamicArray { V* values; int cap; V dummy; public: DynamicArray(int = 2); DynamicArray(const DynamicArray&); ~DynamicArray() { delete[] values; } int capacity() const { return cap; } void capacity(int); V operator[](int) const; V& operator[](int); DynamicArray& operator=(const DynamicArray&); }; template DynamicArray::DynamicArray(int cap) { this->cap = cap; values =...

  • In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits&gt...

    In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits> #include <iostream> #include <string> // atoi #include <time.h> #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ const unsigned int DEFAULT_SIZE = 179; // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() {...

  • Time.cpp: #include "Time.h" #include <iostream> using namespace std; Time::Time(string time) {    hours = 0;   ...

    Time.cpp: #include "Time.h" #include <iostream> using namespace std; Time::Time(string time) {    hours = 0;    minutes = 0;    isAfternoon = false;    //check to make sure there are 5 characters    if (//condition to check if length of string is wrong)    {        cout << "You must enter a valid military time in the format 00:00" << endl;    }    else    {        //check to make sure the colon is in the correct...

  • Design C-1 (modulo-10 up-counter): Using the behavioral VHDL coding, create an up-counter to count upward. The...

    Design C-1 (modulo-10 up-counter): Using the behavioral VHDL coding, create an up-counter to count upward. The up counter has the following control inputs En.reset, CLK. The counting outputs are Q0, O1, Q2. and O3 reset clears the outputs of the counter to 0. En enables the counting when En-1. When En-0, the counter stops. The counter sequentially counts all the possible numbers and loops again, from 0 to 9, back to 0 and 9, etc Design C-2: Ten-second Counter with...

  • #include <iostream> #include <sstream> #include <string> using namespace std; int main() {    const int index...

    #include <iostream> #include <sstream> #include <string> using namespace std; int main() {    const int index = 5;    int head = 0;    string s[index];    int flag = 1;    int choice;    while (flag)    {        cout << "\n1. Add an Item in the Chores List.";        cout << "\n2. How many Chores are in the list.";        cout << "\n3. Show the list of Chores.";        cout << "\n4. Delete an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT