-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount fact.c
More file actions
215 lines (166 loc) · 2.69 KB
/
count fact.c
File metadata and controls
215 lines (166 loc) · 2.69 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
Write a program to implement an n-bit counter where is ‘n’ is given by the user input on 8051.
REQUIREMENTS:
1. Keil μVision IDE
2. Flash Magic
3. p89v51rx2.h header file
SOURCE CODE:
#include<P89V51Rx2.h>
sbit switch_pin1 = P3^2;
sbit switch_pin2 = P3^3;
sbit switch_pin3 = P3^4;
sbit switch_pin4 = P3^5;
void delay(unsigned int delay){
unsigned int i,j;
for(i=0; i<=100; i++)
for(j=0;j<delay;j++);
}
void main(void){
switch_pin1 = 1;
switch_pin2 = 1;
switch_pin3 = 1;
switch_pin4 = 1;
while(1){
if(switch_pin4 == 0){
int i;
for(i=0; i!=16; i++){
int j=i;
unsigned int a=1,b=1,c=1,d=1;
int mask = 1;
if(j&mask){
a=0;
}
j>>=1;
if(j&mask){
b=0;
}
j>>=1;
if(j&mask){
c=0;
}
j>>=1;
if(j&mask){
d=0;
}
RxD = a;
TxD = b;
WR = c;
RD = d;
delay(500);
}
}
//----------------------------
else if(switch_pin3 == 0){
int i;
for(i=0; i!=8; i++){
int j=i;
unsigned int a=1,b=1,c=1,d=1;
int mask = 1;
if(j&mask){
a=0;
}
j>>=1;
if(j&mask){
b=0;
}
j>>=1;
if(j&mask){
c=0;
}
RxD = a;
TxD = b;
WR = c;
RD = d;
delay(500);
}
}
else if(switch_pin2 == 0){
int i;
for(i=0; i!=4; i++){
int j=i;
unsigned int a=1,b=1,c=1,d=1;
int mask = 1;
if(j&mask){
a=0;
}
j>>=1;
if(j&mask){
b=0;
}
RxD = a;
TxD = b;
WR = c;
RD = d;
delay(500);
}
}
else if(switch_pin1 == 0){
int i;
for(i=0; i!=2; i++){
int j=i;
unsigned int a=1,b=1,c=1,d=1;
int mask = 1;
if(j&mask){
a=0;
}
RxD = a;
TxD = b;
WR = c;
RD = d;
delay(500);
}
}
}
}
Write a program to find the factorial of a number on 8051.
REQUIREMENTS:
1. Keil μVision IDE
2. Flash Magic
3. p89v51rx2.h header file
4. LCD.h header file
SOURCE CODE:
#include<P89V52RX2.h>
#include<lcd.h>
int a,b,c, sum, fac;
char ans[4];
void main(void){
LCD_INIT();
while(1){
INT0 = 1; //Sw1
INT1 = 1; //Sw2
T0 = 1; // Sw3
T1 = 1; //Sw4
RxD = 1; //D1
TxD = 1; //D2
WR = 1; //D3
RD = 1; //D4
a=0;b=0;c=0;
while(T1 !=0){
if(INT0 == 0)
a = 1;
if(INT1 == 0)
b = 1;
if(T0 == 0)
c = 1;
}
if(a==1)
RxD = 0;
if(b == 1)
TxD = 0;
if(c==1)
WR = 0;
sum=1;
sum = a*4 + b*2 + c*1 ;
fac=1;
for(i = 1; i<=sum ; i++)
fac = fac*i;
ans[0] = fac/1000+'0';
fac=fac%1000;
ans[1] = fac/100+'0';
fac=fac%100;
ans[2] = fac/10+'0';
fac=fac%10;
ans[3] = fac+'0';
LCD_CMD(LCD_CLEAR);
LCD_WRITE(ans);
}
}