-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
41 lines (33 loc) · 731 Bytes
/
Copy pathmain.c
File metadata and controls
41 lines (33 loc) · 731 Bytes
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
#include "HAL/LCD/lcd.h"
#include "HAL/Sensors/HC-SR04-Ultrasonic/hc-sr04_ultrasonic.h"
#include <util/delay.h>
#include <avr/interrupt.h>
int main(){
uint16 distance;
/*enable global interrupt flag*/
sei();
/*Initialize devices*/
LCD_init();
Ultrasonic_init();
LCD_displayString("Distance = ");
while(1){
/*read the distance*/
distance = Ultrasonic_readDistance();
/*Display the distance*/
LCD_moveCursor(0, 11);
LCD_intgerToString(distance);
/*Units correction*/
if(distance<10){
LCD_moveCursor(0, 12);
LCD_displayString(" cm ");
}
/*Tenth correction*/
else if(distance<100){
LCD_moveCursor(0, 13);
LCD_displayString(" cm ");
}
else{
LCD_displayString("cm");
}
}
}