Welcome to the Mini Project 4 repository! This project focuses on creating a distance measurement system using an ultrasonic sensor HC-SR04 and an ATmega32 Microcontroller. Below, you'll find detailed instructions on system requirements, drivers to be used, and hardware connections for successful implementation.
- ATmega32 Microcontroller with a frequency of 8 MHz.
- Ultrasonic sensor HC-SR04.
- 4x16 LCD.
- Appropriate cables and connectors for wiring.
- Power supply for the components.
-
GPIO Driver: Implement a GPIO driver for controlling general-purpose input/output pins without referencing any specific course material.
-
ICU Driver: Create an Input Capture Unit (ICU) driver for capturing time intervals without referring to any particular course materials. Configure the ICU to work with a frequency of F_CPU/8 and to detect the rising edge as the first edge. The ICU_init and ICU_setCallBack functions should be used for setting up the ICU.
-
LCD Driver: Implement an LCD driver to control the 4x16 LCD display without referring to any specific course material. Use an 8-bit data mode. Connect the control pins and data pins as follows:
- RS → PB0
- RW → Ground
- E → PB1
- Data Bus → all PORTA pins.
-
Ultrasonic Driver: Develop a complete Ultrasonic Driver using the ICU driver. This driver should contain the following functions:
void Ultrasonic_init(void)
: Initialize the ICU driver, set up the ICU callback function, and configure the trigger pin as an output.void Ultrasonic_Trigger(void)
: Send a trigger pulse to the ultrasonic sensor.uint16_t Ultrasonic_readDistance(void)
: Send a trigger pulse, start the measurements with the ICU, and return the measured distance in centimeters.void Ultrasonic_edgeProcessing(void)
: This callback function is called by the ICU driver to calculate the high time (pulse time) generated by the ultrasonic sensor.
The project should be designed and implemented based on a layered architecture model. Ensure that the following layers are properly organized and functioning:
- GPIO Driver.
- ICU Driver.
- LCD Driver.
- Ultrasonic Driver.
For successful operation of the system, make the following hardware connections:
-
Ultrasonic Sensor HC-SR04: Connect the sensor as follows:
- VCC → 5V
- GND → Ground
- Trig → Connect to a GPIO output pin
- Echo → Connect to the ICU input pin
-
LCD: Connect the 4x16 LCD as specified in the LCD Driver Requirements section.
-
ATmega32 Microcontroller: Ensure proper power supply and connect the control pins of the Ultrasonic Driver as per the provided driver requirements.
- Clone or download this repository to your local machine.
- Set up your development environment and ensure the required tools and libraries are installed.
- Open the project in your preferred development environment.
- Implement the drivers and connect the hardware components as described above.
- Compile and upload the code to your ATmega32 Microcontroller.
- Power up the system.
- The LCD will display the measured distance in centimeters.