-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_latches.c
119 lines (112 loc) · 2.43 KB
/
test_latches.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
/*
* test_latches.c -- Testeo de la biblioteca de cerrojos.
* Ultima modificaci'on: 23-11-2000.
* gse.
*/
#include <stdio.h>
#include "gates.h"
#include "latches.h"
#include "clock.h"
#ifdef _SR_LATCH_NOR_
int main() {
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int iter=0;
WIRE S=GND,R=GND,Q=GND,Qn=VCC;
SR_LATCH_NOR l;
CLOCK ck0(50), ck1(100);
fprintf(data,"S R Q Qn");
while(iter++<1000) {
ck0.run(iter,S);
ck1.run(iter,R);
l.run(S,R,Q,Qn);
fprintf(data_sdl,"%3d %3d %3d %3d\n",S,R,Q,Qn);
}
}
#endif
#ifdef _SR_LATCH_NAND_
int main() {
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int iter=500;
WIRE S=GND,R=GND,Q=GND,Qn=VCC;
SR_LATCH_NAND l;
CLOCK ck0(25), ck1(50);
fprintf(data,"S R Q Qn");
while(iter--) {
ck0.run(iter,S);
ck1.run(iter,R);
l.run(S,R,Q,Qn);
fprintf(data_sdl,"%3d %3d %3d %3d\n",S,R,Q,Qn);
}
}
#endif
#ifdef _D_LATCH_
int main() {
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int iter=400;
WIRE D=GND,Q=GND,Qn=VCC;
D_LATCH l;
CLOCK ck(50);
fprintf(data,"D Q Qn");
while(iter--) {
ck.run(iter,D);
l.run(D,Q,Qn);
fprintf(data_sdl,"%3d %3d %3d\n",D,Q,Qn);
}
}
#endif
#ifdef _JK_LATCH_
int main() {
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int iter=0;
WIRE J=GND,K=GND,Q=GND,Qn=VCC;
JK_LATCH l;
CLOCK ck0(50), ck1(70);
fprintf(data,"J K Q Qn");
while(iter++<1000) {
ck0.run(iter,J);
ck1.run(iter,K);
l.run(J,K,Q,Qn);
fprintf(data_sdl,"%3d %3d %3d %3d\n",J,K,Q,Qn);
}
}
#endif
#ifdef _JK_LATCH_ENABLE_
int main() {
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int iter=200;
WIRE J=GND,K=GND,E=GND,Q=GND,Qn=VCC;
JK_LATCH_ENABLE l;
CLOCK ck0(17), ck1(23), ck2(100);
fprintf(data,"J K E Q Qn");
while(iter--) {
ck0.run(iter,J);
ck1.run(iter,K);
ck2.run(iter,E);
l.run(J,K,E,Q,Qn);
fprintf(data_sdl,"%3d %3d %3d %3d %3d\n",J,K,E,Q,Qn);
}
}
#endif
#ifdef _SR_LATCH_ENABLE_
int main() {
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int iter=600;
WIRE S=GND,R=GND,E=GND,Q=GND,Qn=VCC;
SR_LATCH_ENABLE l;
CLOCK ck0(25), ck1(50), ck2(100);
fprintf(data,"S R E Q Qn");
while(iter--) {
ck0.run(iter,S);
ck1.run(iter,R);
ck2.run(iter,E);
l.run(S,R,E,Q,Qn);
fprintf(data_sdl,"%3d %3d %3d %3d %3d\n",S,R,E,Q,Qn);
}
}
#endif