-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv1.c
125 lines (101 loc) · 2.01 KB
/
v1.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
118
119
120
121
122
123
124
125
#include<LPC17xx.h>
#include<stdio.h>
unsigned int flag1 = 0;
unsigned int flag2 = 0;
#define RS_CTRL 0x08000000
#define EN_CTRL 0x10000000
#define DT_CTRL 0x07800000
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;
int main()
{
SystemInit();
SystemCoreClockUpdate();
LPC_GPIO0->FIODIR = 0x00000FF0;
LPC_GPIO0->FIODIR |= DT_CTRL | RS_CTRL | EN_CTRL;
flag1L=0;
for (i=0;i<9;i++){
temp1=init_command[i];
lcd_write();
}
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;
}
flag1L=0;
temp1=0X80;
lcd_write();
flag1L=1;
sprintf(msg,"%d",count);
i=0;
while(msg[i]!='\0')
{
temp1=msg[i++];
lcd_write();
}
}
}
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(flag1L==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++);
return;
}