-
Notifications
You must be signed in to change notification settings - Fork 0
/
LCD initialization and printing phrases and numbers on LCD and Distance converting
87 lines (71 loc) · 2.92 KB
/
LCD initialization and printing phrases and numbers on LCD and Distance converting
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//LCD data and command function
/* That function prints and perform orders to lcd as it takes two characters parameters, char rs takes two values 0 to perform LCD commands and it is the same value of (connected to) pin 5 at port A, RS pin of LCD takes value 1 to perform LCD DATA write
, char D0toD7 is the data pins for LCD and it is the same values of (connected to) pin 5 at port A . */
void LCD(char rs, char D0toD7)
{
delay10Ns(300);
GPIO_PORTB_DATA_R = D0toD7; //sets Port B pins to D0toD7 values
delay10Ns(300); //3 millisecond
if (!(rs)) //LCD Command
{
GPIO_PORTA_DATA_R &= ~0x20; //set rs value to 0
}
else //LCD Data
{
GPIO_PORTA_DATA_R |= 0x20; //sets rs value to 1
}
delay10Ns(300); //3 millisecond
GPIO_PORTA_DATA_R |= 0x80; //set enable to logic 1
delay10Ns(300); //3 millisecond
GPIO_PORTA_DATA_R &= ~0x80; //set enable to logic 0
delay10Ns(300); //3 millisecond
}
//LCD initalize
/* LCD Commands to initalize LCD */
void initalizeLCD()
{
LCD(0, 0x3C); //Function set
LCD(0, 0x01); //Clear
LCD(0, 0x02); //Return Home
LCD(0, 0x0C); ///Display ON/control OFF(cursor off / Blinking off)
}
// display a phrase on a chosen on LCD
/* That function prints phrase on LCD that it takes it as string array (char ch[]) in a chosen line that it takes as a parameter int position */
void printOnLCD(char ch[], int position)
{
int i;
if (position == 1) //LCD clear and line 1
{
LCD(0, 0x01);
LCD(0, 0x02);
}
else if (position == 2) //LCD Data to line 2
{
LCD(0, 0xC0); //position takes value beginning of 1 for first line , 2 for beginning of second line, x for for current position
}
for (i = 0; ch[i] != '\0'; i++) LCD(1, ch[i]);
}
// display an number on LCD
/* that function prints the distance on LCDand converts it from a double value to a int as in the function definition the passed parameter is double and
the recived parameter in integer then it converts it to character and ignore zeroes at Most signfient digit and in case of printing zeroe it is printed
character zero */
void printDist(int distance) {
int i;
int tmp1 = distance;
int tmp2 = 0;
for (i = 10; i >= 0; i--)
{
int num = tmp1 / pow(10, i); //split last digit from number
tmp1 = tmp1 - num * pow(10, i);
tmp2 += num;
if (tmp2) { //ignoring zeroes at Most signfient digit
LCD(1, num + 0x30);
}
}
if (dist < 1)
{
LCD(1, '0');
}
LCD(1, 'm');
LCD(0, 0x89);
}