-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.c
More file actions
42 lines (34 loc) · 1.13 KB
/
application.c
File metadata and controls
42 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
=============================================================================
* Name :application.c
* Author :Menna Saeed
* Description :A system to measure the distance using ultrasonic sensor HC-SR04
* Created on :March 1, 2022
==============================================================================
*/
#include "lcd.h"
#include "ultrasonic.h"
#include "avr/io.h" /* To use the SREG register */
#include "avr/delay.h" /*To use the delay functions*/
/*==========================================================================*/
int main()
{
SREG|=(1<<7); /* Enable Global Interrupt I-Bit */
/* Initialize both the LCD and Ultrasonic driver */
LCD_init();
Ultrasonic_init();
LCD_displayString("Distance= cm ");
uint16 distance=0; /*Distance to be measured and displayed on LCD*/
while (1)
{
distance=Ultrasonic_readDistance();
LCD_moveCursor(0, 10);
LCD_intgerToString(distance);
if(distance<100)
{
/* In case the digital value is two or one digits print space in the next digit place */
LCD_displayCharacter(' ');
}
_delay_ms(100);
}
}