-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv1.1.c
117 lines (98 loc) · 2.54 KB
/
v1.1.c
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <LPC17xx.h>
#include <stdio.h> // Include stdio.h for sprintf function
unsigned int flag1 = 0;
unsigned int flag2 = 0;
#define RS_CTRL 0x08000000
#define EN_CTRL 0x10000000
#define DT_CTRL 0x07800000
LPC_GPIO0->FIODIR = 0x00000FF0;
unsigned long int temp1=0,temp2=0,i,j;
unsigned char flag1L=0,flag2L=0;
unsigned char msg[]={"No of People:"};
void lcd_write();
void port_write();
void delay_lcd(unsigned int);
unsigned long int init_command[]={0x30,0x30,0x30,0x20,0x28,0x0c,0x06,0x01,0x80};
unsigned int count = 0;
void init_GPIO(void) {
// Set GPIO directions: IR pins as inputs, LCD control pins as outputs
LPC_GPIO0->FIODIR |= (DT_CTRL | RS_CTRL | EN_CTRL);
LPC_GPIO0->FIODIR &= ~DT_CTRL; // IR pins as inputs
}
void init_LCD(void) {
for (i = 0; i < 9; i++) {
temp1 = init_command[i];
lcd_write();
}
}
void update_LCD_display(void) {
flag1L = 0;
temp1 = 0x80;
lcd_write();
flag1L = 1;
sprintf(msg, "%d", count);
i = 0;
while (msg[i] != '\0') {
temp1 = msg[i++];
lcd_write();
}
}
int main() {
SystemInit();
SystemCoreClockUpdate();
init_GPIO(); // Initialize GPIO pins
init_LCD(); // Initialize LCD
while (1) {
if (!(LPC_GPIO2->FIOPIN & (1 << 12)) && flag1 == 0) {
flag1 = 1;
}
if (!(LPC_GPIO2->FIOPIN & (1 << 13)) && flag1 == 1) {
count = count + 1;
flag2 = 1;
}
if (!(LPC_GPIO2->FIOPIN & (1 << 13)) && flag2 == 0) {
flag2 = 1;
}
if (!(LPC_GPIO2->FIOPIN & (1 << 12)) && flag2 == 1) {
count = count - 1;
flag1 = 1;
}
if (flag1 == 1 && flag2 == 1) {
flag1 = 0;
flag2 = 0;
}
if (count > 0) {
LPC_GPIO2->FIOPIN = 0x00000FF0;
} else {
LPC_GPIO2->FIOCLR = 0x00000FF0;
}
update_LCD_display();
}
}
void lcd_write(void) {
flag2 = (flag1 == 1) ? 0 : ((temp1 == 0x30) || (temp1 == 0x20)) ? 1 : 0;
temp2 = temp1 & 0xf0;
temp2 = temp2 << 19;
port_write();
if (!flag2) {
temp2 = temp1 & 0x0f;
temp2 = temp2 << 23;
port_write();
}
}
void port_write(void) {
LPC_GPIO0->FIOPIN = temp2;
if (flag1 == 0) {
LPC_GPIO0->FIOCLR = RS_CTRL;
} else {
LPC_GPIO0->FIOSET = RS_CTRL;
}
LPC_GPIO0->FIOSET = EN_CTRL;
delay_lcd(25);
LPC_GPIO0->FIOCLR = EN_CTRL;
delay_lcd(5000);
}
void delay_lcd(unsigned int r1) {
unsigned int r;
for (r = 0; r < r1; r++);
}