-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_file.c
More file actions
179 lines (169 loc) · 3.18 KB
/
code_file.c
File metadata and controls
179 lines (169 loc) · 3.18 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <reg51.h>
sbit sw1= P0^0;
sbit sw2= P0^1;
sbit rs=P2^0;
sbit rw=P2^1;
sbit e=P2^2;
sbit reset = P0^3;
sbit pause = P0^2;
void WriteCommandToLCD(unsigned char);
void WriteStringToLCD(unsigned char ch[]);
void WriteDataToLCD(unsigned char);
void WriteData1ToLCD(unsigned char);
void delay(unsigned int);
void main()
{
unsigned int num1 = 0, num2 = 0, total = 0, i = 0, sum = 0;
bit paused = 0;
WriteCommandToLCD(0x38);
WriteCommandToLCD(0x01);
WriteCommandToLCD(0x0C);
WriteCommandToLCD(0x80);
WriteCommandToLCD(0x06);
WriteStringToLCD("WELCOME TO ");
WriteCommandToLCD(0xc0);
WriteStringToLCD("ELECTIONS");
delay(20);
P3=0x00;
sw1=0;
sw2=0;
total=P3;
delay(10);
WriteCommandToLCD(0x01);
WriteCommandToLCD(0x80);
WriteStringToLCD("total voters = ");
WriteCommandToLCD(0xc0);
WriteDataToLCD((total / 100) + 48);
WriteDataToLCD(((total / 10) % 10) + 48);
WriteDataToLCD((total % 10) + 48);
delay(40);
while(1)
{
if(pause == 1)
{
paused = !paused; // Toggle pause state
delay(200); // Debounce
}
if(paused)
{
WriteCommandToLCD(0x01);
WriteCommandToLCD(0x80);
WriteStringToLCD("ELECTION PAUSED");
delay(50);
continue; // Skip rest of the loop
}
if(reset == 1)
{
// Reset all variables
num1 = 0;
num2 = 0;
sum = 0;
paused = 0;
WriteCommandToLCD(0x01);
WriteCommandToLCD(0x80);
WriteStringToLCD("RESETTING...");
delay(50);
// Restart voting intro
WriteCommandToLCD(0x01);
WriteCommandToLCD(0x80);
WriteStringToLCD("WELCOME TO ");
WriteCommandToLCD(0xC0);
WriteStringToLCD("ELECTIONS");
delay(40);
continue;
}
P3=0x00;
total=P3;
delay(10);
if(sw1==1 && sw2==0)
{
num1=num1+1;
delay(20);
}
else if(sw1==0 && sw2==1)
{
num2=num2+1;
delay(20);
}
else if(sw1==1 && sw2==1)
{
num1=num1+1;
delay(20);
num2=num2+1;
delay(20);
}
WriteCommandToLCD(0x01);
WriteCommandToLCD(0x80);
WriteCommandToLCD(0x06);
WriteStringToLCD("stud1 vote = ");
WriteData1ToLCD((num1 / 100) + 48);
WriteData1ToLCD(((num1 / 10) % 10) + 48);
WriteData1ToLCD((num1 % 10) + 48);
WriteCommandToLCD(0xc0);
WriteStringToLCD("stud2 vote = ");
WriteData1ToLCD((num2 / 100) + 48);
WriteData1ToLCD(((num2 / 10) % 10) + 48);
WriteData1ToLCD((num2 % 10) + 48);
sum=num1+num2;
if(sum>=total)
{
WriteCommandToLCD(0x01);
WriteCommandToLCD(0x80);
WriteCommandToLCD(0x06);
WriteStringToLCD("RESULT");
if(num1>num2){
WriteCommandToLCD(0xc0);
WriteStringToLCD("WINNER->>stud1");
}else{
WriteCommandToLCD(0xc0);
WriteStringToLCD("WINNER->>stud2");
}
delay(40);
break;
}
// delay(20);
}
while(1);
//}
}
void delay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<1275;j++);
}
void WriteCommandToLCD(unsigned char ch)
{
e=1;
rs=0;
rw=0;
P1=ch;
e=0;
delay(5);
}
void WriteDataToLCD(unsigned char ch)
{
e=1;
rs=1;
rw=0;
P1=ch;
e=0;
delay(20);
}
void WriteData1ToLCD(unsigned char ch)
{
e=1;
rs=1;
rw=0;
P1=ch;
e=0;
delay(50);
}
void WriteStringToLCD(unsigned char ch[])
{
int i;
for(i=0;ch[i]!='\0';i++)
{
WriteDataToLCD(ch[i]);
}
}