-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrequencymeter.c
201 lines (185 loc) · 4.04 KB
/
frequencymeter.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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include<reg52.h>
sfr lveri = 0x90; //LCD Data Pins
sbit rs = P3^2;
sbit rw = P3^1;
sbit en = P3^0;
sbit busy = P1^7;
unsigned char Unit[4];
void MSDelay(unsigned int);
void lcdkomut(unsigned char);
void lcdveri(unsigned char);
void lcdready(void);
void lcdinit(void);
void inttoLCD(unsigned int);
void main(void)
{
unsigned int HI, LO, TOPLAM; //To keep frequency values
unsigned char l, OV, MSJ[16] = "Out of Range";
OV = 0;
T0 = 1;
TMOD = 0x05;
TL0 = 0;
TL1 = 0;
lcdinit();
while(1)// Classification is made according to the size of the frequency entered here.
{
do
{
start: TR0 = 1;
MSDelay(145);
LO = TL0;
HI = TH0;
HI = HI << 8;
TOPLAM = HI | LO;
Unit[0] = 'H';
Unit[1] = 'z';
Unit[2] = ' ';
Unit[3] = ' ';
if(OV == 1)
{
TOPLAM = TOPLAM / 1000;
TOPLAM = TOPLAM + 66;
if(TOPLAM > 100)
{
for(l=0; l<16; l++)
lcdveri(MSJ[l]);
for(l=0; l<16; l++)
lcdkomut(0x10);
goto start;
}
OV = 0;
Unit[0] = 'K';
Unit[1] = 'H';
Unit[2] = 'z';
Unit[3] = ' ';
}
inttoLCD(TOPLAM);
TL0 = 0;
TH0 = 0;
}
while(TF0 == 0);
OV = 1;
TR0 = 0;
TF0 = 0;
}
}
void lcdinit(void)
{
lcdkomut(0x38);//2 line 5x7 matrix
lcdkomut(0x0C);//Display on
lcdkomut(0x01);//Cleaning the display screen
lcdkomut(0x80);//Setting the cursor to start from the first line
lcdkomut(0x06);//Increment the cursor position by one
}
void lcdkomut(unsigned char deger)//rs and rw values have been adjusted so that operations in the lcdinit function can be performed.
{
lcdready();
lveri = deger;
rs = 0;
rw = 0;
en = 1;
MSDelay(1);
en = 0;
}
void lcdveri(unsigned char deger)
{
lcdready();
lveri = deger;//Values are loaded on pins
rs = 1;
rw = 0;
en = 1;
MSDelay(1);
en = 0;
}
void lcdready()//Reading flags and counting addresses
{
busy = 1;
rs = 0;
rw = 1;
do
{
en = 0;
MSDelay(1);
en = 1;
}
while(busy == 1);
return;
}
void inttoLCD(unsigned int deger)//Finding the format of the incoming values and their values in the ASCII table and printing them on the LCD. Adding +48 each time is the number starting after 48 in the ASCII table.
{
unsigned int x, y, z, d[5];
char l;
x = deger / 10;
d[0] = (deger % 10) + 48;
d[1] = (x % 10) + 48;
y = x / 10;
d[2] = (y % 10) + 48;
z = y / 10;
d[3] = (z % 10) + 48;
d[4] = (z / 10) + 48;
if(d[4] == 48 & d[3] == 48 & d[2] == 48 & d[1] == 48)
{
lcdveri(d[0]);
lcdveri(' ');
for(l=0; l<4; l++)
lcdveri(Unit[l]);
for(l=0 ; l<11 ; l++)
lcdveri(' ');
for(l=0 ; l<17 ; l++)
lcdkomut(0x10);
}
if(d[4] == 48 & d[3] == 48 & d[2] == 48 & d[1] != 48)
{
for(l=1; l>=0; l--)
lcdveri(d[l]);
lcdveri(' ');
for(l=0; l<4; l++)
lcdveri(Unit[l]);
for(l=0 ; l<10 ; l++)
lcdveri(' ');
for(l=0 ; l<17 ; l++)
lcdkomut(0x10);
}
if(d[4] == 48 & d[3] == 48 & d[2] != 48)
{
for(l=2; l>=0; l--)
lcdveri(d[l]);
lcdveri(' ');
for(l=0; l<4; l++)
lcdveri(Unit[l]);
for(l=0 ; l<9 ; l++)
lcdveri(' ');
for(l=0 ; l<17 ; l++)
lcdkomut(0x10);
}
if(d[4] == 48 & d[3] != 48)
{
for(l=3; l>=0; l--)
lcdveri(d[l]);
lcdveri(' ');
for(l=0; l<4; l++)
lcdveri(Unit[l]);
for(l=0 ; l<8 ; l++)
lcdveri(' ');
for(l=0 ; l<17 ; l++)
lcdkomut(0x10);
}
if(d[4] != 48)
{
for(l=4; l>=0; l--)
lcdveri(d[l]);
lcdveri(' ');
for(l=0; l<4; l++)
lcdveri(Unit[l]);
for(l=0 ; l<7 ; l++)
lcdveri(' ');
for(l=0 ; l<17 ; l++)
lcdkomut(0x10);
}
}
void MSDelay(unsigned int deger) //To set the delay
{
unsigned int x,y;
for(x = 0; x < deger; x++)
for(y = 0; y < 1275; y++);
}