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.
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...
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.
Without using the graphics module, write a program to simulate an archery score tracker. Your program...
Without using the graphics module, write a program to simulate an archery score tracker. Your program should use a Tkinter canvas to draw a target. Your program should allow the user to click the target to mark where their arrow landed on the target (or off). When the user clicks the target, the program should draw a dot at that location and compute the score. Scores for each ring are as follows: yellow 5, red 4, blue 3, black 2,...
write C++ program using functions (separate function for each bottom) Write a program to find if...
write C++ program using functions (separate function for each bottom) Write a program to find if a number is large word for two given bottom base - bottom1 and bottom2. You can predict that a number, when converted to any given base shall not exceed 10 digits. . the program should ask from user to enter a number that it should ask to enter the base ranging from 2 to 16 after that it should check if the number is...
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...
Problem Write a movie management system using object-oriented design principles. The program will read from the...
Problem Write a movie management system using object-oriented design principles. The program will read from the supplied data file into a single array list. The data file (movies.txt) contains information about the movies. Each movie record has the following attributes: - Duration (in minutes) - Title - Year of release Each record in the movies.txt file is formatted as follows: - Duration,Title,Year - e.g.: 91,Gravity,2013 Specifically, you have to create an interactive menu driven application that gives the user the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT