Question

In: Electrical Engineering

Without using a Timer function, write a program to read the distance from the HC-SR04 ultrasonic...

Without using a Timer function, write a program to read the distance from the HC-SR04 ultrasonic sensor and display the distance on the C12832 lcd.

*please refer the HC-SR04 datasheet for the operation of the ultrasonic sensor, and mbed website for C12832 library and Timer function

Solutions

Expert Solution

#include <avr/io.h>
#include <MrLcd/MrLCDmega32.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdlib.h>

static volatile int pulse = 0;
static volatile int i = 0;

int main(void)
{
  int16_t count_a = 0; 
  char show_a[16];
  Initialise();
  DDRD = 0b11111011;
  _delay_ms(50);

  Initialise();

  GICR |= 1<<INT0;
  MCUCR |= 1<<ISC00;

  sei();
 
  while(1)
  { 
    PORTD |= 1<<PIND0;
    _delay_us(15);

    PORTD &= ~(1<<PIND0);
    count_a = pulse/58;

    Send_A_String("Distance Sensor");
    GoToMrLCDLocation(1,2);
    Send_A_String("Distance=");
    itoa(count_a,show_a,10);
    Send_A_String(show_a);
    Send_A_String(" ");
    GoToMrLCDLocation(13,2);
    Send_A_String("cm");
    GoToMrLCDLocation(1,1);
  }
}

ISR(INT0_vect)
{
  if(i == 0)
  {
    TCCR1B |= 1<<CS10;
    i = 1;
  }
  else
  {
    TCCR1B = 0;
    pulse = TCNT1;
    TCNT1 = 0;
    i = 0;
  }
}

Related Solutions

write a program for the msp430fr6989 Using the general purpose timer, specifically the ACLK, create a...
write a program for the msp430fr6989 Using the general purpose timer, specifically the ACLK, create a program which makes LED1 stay on for 4 seconds and off for 2 seconds and repeat indefinitely. Modify the above program to extend the timing to 20 and 10 seconds, respectively.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Using Python Write a GUI program that converts a distance in Meters to the equivalent distance...
Using Python Write a GUI program that converts a distance in Meters to the equivalent distance in Feet. The user should be able to enter a distance in Meters, click a button, and then see the equivalent distance in feet. Use the following formula to make the conversion: Meters = Feet x 0.304 For example, 1 Meter is 3.28 Feet.
PROBLEM STATEMENT: Using the list container from the STL, write a program that will read the...
PROBLEM STATEMENT: Using the list container from the STL, write a program that will read the information from a file into a list and then display the list to the screen. Add your name. Sort the list by id. Print the list again CODE: Use the provided disneyin2.txt file. Do not hard code the file name; get file name from user. Use the struct below struct student { char firstnm[20], lastnm[20]; int id, grade; }; You are to create a...
I need to write a C++ program that appends "not" into the string without using the...
I need to write a C++ program that appends "not" into the string without using the append method or any standard libraries. It should return the string if there isn't an "is" in it. Examples: is is = is not is not This is me = This is not me What is yellow? = What is not yellow? The sky is pink = The sky is not pink isis = isis What happened to you? = What happened to you?
Please write a java program to write to a text file and to read from a...
Please write a java program to write to a text file and to read from a text file.
Write a C++ program to read characters from the keyboard until a '#' character is read....
Write a C++ program to read characters from the keyboard until a '#' character is read. Then the program will find and print the number of uppercase letters read from the keyboard.
Using an arduino, breadboard,  ultrasonic sensor, buzzer, lcd and red led display distance in centimeters, If needed,...
Using an arduino, breadboard,  ultrasonic sensor, buzzer, lcd and red led display distance in centimeters, If needed, use a rotary potentiometer, male to male cable (m-m) female to male cable (f-m) or any resistor provided in the kit. display distance in centimeters to lcd. If the object is in distance, turn on Active buzzer(play sound) and turn on red led. If the object is not in range, display out of range or "Object now close'.  on the lcd, make sure the buzzer...
1-Which of the following algorithms cannot be implemented without using the timer interrupt? a. RR b....
1-Which of the following algorithms cannot be implemented without using the timer interrupt? a. RR b. SJF c. Priority d. FCFC 2-A program that performs mostly arithmetic or scientific calculations is considered as? a. CPU bound b. I/O bound 3-Operating System is: a. System processes that manages hardware resources b. System processes that provide services to the user application programs c. Interface between the hardware and user processes d. All the above e. Not of the above 4-A goal of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT