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|
+
#include <stdio.h>
|
| 3 |
+
#include <limits.h>
|
| 4 |
+
void knapsack(int n, int m, int profits[], int weights[])
|
| 5 |
+
{
|
| 6 |
+
int v[n+1][m+1];
|
| 7 |
+
int result[n];
|
| 8 |
+
for(int i=0; i<=m; i++)
|
| 9 |
+
v[0][i] = 0;
|
| 10 |
+
for(int i=0; i<=n; i++)
|
| 11 |
+
v[i][0] = 0;
|
| 12 |
+
for(int i=1; i<=n; i++) {
|
| 13 |
+
for(int w=1; w<=m; w++) {
|
| 14 |
+
if(w - weights[i-1] <0) {
|
| 15 |
+
v[i][w] = v[i-1][w];
|
| 16 |
+
} else {
|
| 17 |
+
int val1 = v[i-1][w];
|
| 18 |
+
int val2 = v[i-1][w-weights[i-1]] + profits[i-1];
|
| 19 |
+
v[i][w] = (val1 > val2) ? val1 : val2;
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
int k=n, j=m;
|
| 24 |
+
while (k>0 && j>0) {
|
| 25 |
+
if(v[k][j] != v[k-1][j]) {
|
| 26 |
+
result[k-1] = 1;
|
| 27 |
+
j = j-weights[k-1];
|
| 28 |
+
}
|
| 29 |
+
else {
|
| 30 |
+
result[k-1] = 0;
|
| 31 |
+
}
|
| 32 |
+
k--;
|
| 33 |
+
}
|
| 34 |
+
for(int i=0; i<n; i++)
|
| 35 |
+
printf("%d ", result[i]);
|
| 36 |
+
}
|
| 37 |
+
int main()
|
| 38 |
+
{
|
| 39 |
+
int n; //No. of objects
|
| 40 |
+
scanf("%d", &n);
|
| 41 |
+
int m; //Max capacity
|
| 42 |
+
scanf("%d", &m);
|
| 43 |
+
int profits[n], weights[n];
|
| 44 |
+
for(int i=0; i<n; i++)
|
| 45 |
+
scanf("%d", &profits[i]);
|
| 46 |
+
for(int i=0; i<n; i++)
|
| 47 |
+
scanf("%d", &weights[i]);
|
| 48 |
+
knapsack(n, m, profits, weights);
|
| 49 |
+
return 0;
|
| 50 |
+
}
|
| 51 |
+
LCS
|
| 52 |
+
#include <stdio.h>
|
| 53 |
+
#include <string.h>
|
| 54 |
+
char S1[20], S2[20];
|
| 55 |
+
int i, j, m, n, LCS_table[20][20];
|
| 56 |
+
int max(int a, int b) {
|
| 57 |
+
return (a>b) ? a: b;
|
| 58 |
+
}
|
| 59 |
+
void lcsAlgo()
|
| 60 |
+
{
|
| 61 |
+
printf("Reached\n");
|
| 62 |
+
m = strlen(S1);
|
| 63 |
+
n = strlen(S2);
|
| 64 |
+
for(i = 0; i<=m; i++)
|
| 65 |
+
LCS_table[i][0] = 0;
|
| 66 |
+
for(i=0; i<=n; i++)
|
| 67 |
+
LCS_table[0][i] = 0;
|
| 68 |
+
for(i=1; i<=m; i++) {
|
| 69 |
+
for(j=1; j<=n; j++) {
|
| 70 |
+
if(S1[i-1] == S2[j-1])
|
| 71 |
+
LCS_table[i][j] = LCS_table[i-1][j-1] + 1;
|
| 72 |
+
else
|
| 73 |
+
LCS_table[i][j] = max(LCS_table[i-1][j], LCS_table[i][j-1]);
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
int index = LCS_table[m][n];
|
| 77 |
+
char LCSAlgo[index+1];
|
| 78 |
+
LCSAlgo[index] = '\0';
|
| 79 |
+
printf("%d\n", index);
|
| 80 |
+
i=m, j=n;
|
| 81 |
+
while(i>0 && j>0)
|
| 82 |
+
{
|
| 83 |
+
if(S1[i-1] == S2[j-1]) {
|
| 84 |
+
LCSAlgo[index-1] = S1[i-1];
|
| 85 |
+
i--;
|
| 86 |
+
j--;
|
| 87 |
+
index--;
|
| 88 |
+
} else {
|
| 89 |
+
//max(LCS_table[i-1][j], LCS_table[i][j-1]);
|
| 90 |
+
if(LCS_table[i - 1][j] > LCS_table[i][j - 1])
|
| 91 |
+
i--;
|
| 92 |
+
else
|
| 93 |
+
j--;
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
printf("%d\n", index);
|
| 97 |
+
printf("The LCS is %s", LCSAlgo);
|
| 98 |
+
}
|
| 99 |
+
int main()
|
| 100 |
+
{
|
| 101 |
+
scanf("%[^\n]s", &S1);
|
| 102 |
+
scanf("%s", &S2);
|
| 103 |
+
lcsAlgo();
|
| 104 |
+
}
|
| 105 |
+
Matrix Chain
|
| 106 |
+
#include <stdio.h>
|
| 107 |
+
#include <limits.h>
|
| 108 |
+
int MatrixChainMultiplication(int arr[], int n)
|
| 109 |
+
{
|
| 110 |
+
int minMul[n][n];
|
| 111 |
+
for(int i=1; i<n; i++)
|
| 112 |
+
minMul[i][i] = 0;
|
| 113 |
+
int j, q=0;
|
| 114 |
+
for(int L=2; L<n; L++) {
|
| 115 |
+
for(int i=1; i<n-L+1; i++) {
|
| 116 |
+
j = i+L-1;
|
| 117 |
+
minMul[i][j] = INT_MAX;
|
| 118 |
+
for(int k=i; k<=j; k++) {
|
| 119 |
+
q = minMul[i][k] + minMul[k+1][j] + arr[i-1]*arr[k]*arr[j];
|
| 120 |
+
if(q<minMul[i][j])
|
| 121 |
+
minMul[i][j]=q;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
return minMul[1][n-1];
|
| 126 |
+
}
|
| 127 |
+
int main()
|
| 128 |
+
{
|
| 129 |
+
int n;
|
| 130 |
+
scanf("%d", &n);
|
| 131 |
+
int arrS[n][2];
|
| 132 |
+
int arr[n+1];
|
| 133 |
+
for(int i=0; i<n; i++) {
|
| 134 |
+
scanf("%d %d",&arrS[i][0], &arrS[i][1]);
|
| 135 |
+
}
|
| 136 |
+
arr[0] = arrS[0][0];
|
| 137 |
+
for(int i=1; i<=n; i++)
|
| 138 |
+
arr[i] = arrS[i-1][1];
|
| 139 |
+
printf("Minimum number of multiplications required for matrix
|
| 140 |
+
multiplication is %d\n", MatrixChainMultiplication(arr, n+1));
|
| 141 |
+
getchar();
|
| 142 |
+
return 0;
|
| 143 |
+
}
|
| 144 |
+
Assembly line scheduling
|
| 145 |
+
Code:
|
| 146 |
+
#include <stdio.h>
|
| 147 |
+
#include <stdlib.h>
|
| 148 |
+
#define min(a, b) ((a) < (b) ? (a) : (b))
|
| 149 |
+
int fun(int a*2+*4+, int t*2+*4+, int cl, int cs, int x1, int x2, int n);
|
| 150 |
+
int main() ,
|
| 151 |
+
int n = 4; // number of stations
|
| 152 |
+
int a*2+*4+ = , , 4, 5, 3, 2 -, , 2, 10, 1, 4 - -;
|
| 153 |
+
int t*2+*4+ = , , 0, 7, 4, 5 -, , 0, 9, 2, 8 - -;
|
| 154 |
+
int e1 = 10;
|
| 155 |
+
int e2 = 12;
|
| 156 |
+
int x1 = 18;
|
| 157 |
+
int x2 = 7;
|
| 158 |
+
// entry from 1st line
|
| 159 |
+
int x = fun(a, t, 0, 0, x1, x2, n) + e1 + a*0+*0+;
|
| 160 |
+
// entry from 2nd line
|
| 161 |
+
int y = fun(a, t, 1, 0, x1, x2, n) + e2 + a*1+*0+;
|
| 162 |
+
printf("%d\n", min(x, y));
|
| 163 |
+
|
| 164 |
+
return 0;
|
| 165 |
+
-
|
| 166 |
+
int fun(int a*2+*4+, int t*2+*4+, int cl, int cs, int x1, int x2, int n) ,
|
| 167 |
+
// base case
|
| 168 |
+
if (cs == n - 1) ,
|
| 169 |
+
if (cl == 0) , // exiting from (current) line =0
|
| 170 |
+
return x1;
|
| 171 |
+
- else , // exiting from line 2
|
| 172 |
+
return x2;
|
| 173 |
+
-
|
| 174 |
+
-
|
| 175 |
+
// continue on same line
|
| 176 |
+
int same = fun(a, t, cl, cs + 1, x1, x2, n) + a*cl+*cs + 1+;
|
| 177 |
+
// continue on different line
|
| 178 |
+
int diff = fun(a, t, !cl, cs + 1, x1, x2, n) + a*!cl+*cs + 1+ + t*cl+*cs + 1+;
|
| 179 |
+
return min(same, diff);
|
| 180 |
+
-
|
| 181 |
+
Max Sub Array Sum
|
| 182 |
+
#include <stdio.h>
|
| 183 |
+
#include <limits.h>
|
| 184 |
+
int *maxSubArraySum(int nums[], int start, int end, int *max_sum, int
|
| 185 |
+
*subarray_start, int *subarray_end)
|
| 186 |
+
{
|
| 187 |
+
if(start == end) {
|
| 188 |
+
*max_sum = nums[start];
|
| 189 |
+
*subarray_start = start;
|
| 190 |
+
*subarray_end = start;
|
| 191 |
+
return &nums[start];
|
| 192 |
+
}
|
| 193 |
+
int mid= (start+end)/2;
|
| 194 |
+
int left_subarray = maxSubArraySum(nums, start, mid, &max_sum,
|
| 195 |
+
&subarray_start, &subarray_end);
|
| 196 |
+
int right_subarray = maxSubArraySum(nums, mid+1, end, &max_sum,
|
| 197 |
+
&subarray_start, &subarray_end);
|
| 198 |
+
int left_sum=INT_MIN;
|
| 199 |
+
int curr_sum = 0;
|
| 200 |
+
int cross_start = mid;
|
| 201 |
+
for(int i=mid; i>=start; i--) {
|
| 202 |
+
curr_sum += nums[i];
|
| 203 |
+
if(curr_sum >= left_sum) {
|
| 204 |
+
left_sum = curr_sum;
|
| 205 |
+
cross_start = i;
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
int right_sum=INT_MIN;
|
| 209 |
+
curr_sum=0;
|
| 210 |
+
int cross_end = mid+1;
|
| 211 |
+
for(int i=mid+1; i<end; i++) {
|
| 212 |
+
curr_sum+=nums[i];
|
| 213 |
+
if(curr_sum>= right_sum) {
|
| 214 |
+
right_sum = curr_sum;
|
| 215 |
+
cross_end = i;
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
int main()
|
| 220 |
+
{
|
| 221 |
+
int n;
|
| 222 |
+
scanf("%d", &n);
|
| 223 |
+
int nums[n];
|
| 224 |
+
for(int i=0; i<n; i++)
|
| 225 |
+
scanf("%d ", &nums[i]);
|
| 226 |
+
int max_sum, subarray_start, subarray_end;
|
| 227 |
+
int *max_subarray =
|
| 228 |
+
maxSubArraySum(nums, 0, n-1, &max_sum, &subarray_start,
|
| 229 |
+
&subarray_end);
|
| 230 |
+
printf("The sub array [");
|
| 231 |
+
for(int i=subarray_start; i<=subarray_end; i++) {
|
| 232 |
+
if(i==subarray_end)
|
| 233 |
+
printf("%d", nums[i]);
|
| 234 |
+
else
|
| 235 |
+
printf("%d ", nums[i]);
|
| 236 |
+
}
|
| 237 |
+
printf("] has the largest sum %d", max_sum);
|
| 238 |
+
return 0;
|
| 239 |
+
}
|
| 240 |
+
KARATSUBA ALGORITHM
|
| 241 |
+
#include <stdio.h>
|
| 242 |
+
#include <string.h>
|
| 243 |
+
// Function to find the sum of larger
|
| 244 |
+
// numbers represented as a string
|
| 245 |
+
char* findSum(const char* str1, const char* str2)
|
| 246 |
+
,
|
| 247 |
+
// Before proceeding further, make
|
| 248 |
+
// sure length of str2 is larger
|
| 249 |
+
if (strlen(str1) > strlen(str2)) ,
|
| 250 |
+
const char* temp = str1;
|
| 251 |
+
str1 = str2;
|
| 252 |
+
str2 = temp;
|
| 253 |
+
-
|
| 254 |
+
// Stores the result
|
| 255 |
+
static char str*1000+;
|
| 256 |
+
// Calculate length of both strings
|
| 257 |
+
int n1 = strlen(str1);
|
| 258 |
+
int n2 = strlen(str2);
|
| 259 |
+
// Reverse both of strings
|
| 260 |
+
strrev(str1);
|
| 261 |
+
strrev(str2);
|
| 262 |
+
int carry = 0;
|
| 263 |
+
for (int i = 0; i < n1; i++) ,
|
| 264 |
+
// Find the sum of the current
|
| 265 |
+
// digits and carry
|
| 266 |
+
int sum
|
| 267 |
+
= ((str1*i+ - '0')
|
| 268 |
+
+ (str2*i+ - '0')
|
| 269 |
+
+ carry);
|
| 270 |
+
str*i+ = (sum % 10) + '0';
|
| 271 |
+
// Calculate carry for next step
|
| 272 |
+
carry = sum / 10;
|
| 273 |
+
-
|
| 274 |
+
// Add remaining digits of larger number
|
| 275 |
+
for (int i = n1; i < n2; i++) ,
|
| 276 |
+
int sum = ((str2*i+ - '0') + carry);
|
| 277 |
+
str*i+ = (sum % 10) + '0';
|
| 278 |
+
carry = sum / 10;
|
| 279 |
+
-
|
| 280 |
+
// Add remaining carry
|
| 281 |
+
if (carry)
|
| 282 |
+
str*n2+ = carry + '0';
|
| 283 |
+
else
|
| 284 |
+
str*n2+ = '\0';
|
| 285 |
+
// Reverse resultant string
|
| 286 |
+
strrev(str);
|
| 287 |
+
return str;
|
| 288 |
+
-
|
| 289 |
+
// Function to find difference of larger
|
| 290 |
+
// numbers represented as strings
|
| 291 |
+
char* findDiff(const char* str1, const char* str2)
|
| 292 |
+
,
|
| 293 |
+
// Stores the result of difference
|
| 294 |
+
static char str*1000+;
|
| 295 |
+
// Calculate length of both strings
|
| 296 |
+
int n1 = strlen(str1), n2 = strlen(str2);
|
| 297 |
+
// Reverse both of strings
|
| 298 |
+
strrev(str1);
|
| 299 |
+
strrev(str2);
|
| 300 |
+
int carry = 0;
|
| 301 |
+
// Run loop till small string length
|
| 302 |
+
// and subtract digit of str1 to str2
|
| 303 |
+
for (int i = 0; i < n2; i++) ,
|
| 304 |
+
// Compute difference of the
|
| 305 |
+
// current digits
|
| 306 |
+
int sub
|
| 307 |
+
= ((str1*i+ - '0')
|
| 308 |
+
- (str2*i+ - '0')
|
| 309 |
+
- carry);
|
| 310 |
+
// If subtraction < 0 then add 10
|
| 311 |
+
// into sub and take carry as 1
|
| 312 |
+
if (sub < 0) ,
|
| 313 |
+
sub = sub + 10;
|
| 314 |
+
carry = 1;
|
| 315 |
+
-
|
| 316 |
+
else
|
| 317 |
+
carry = 0;
|
| 318 |
+
str*i+ = sub + '0';
|
| 319 |
+
-
|
| 320 |
+
// Subtract the remaining digits of
|
| 321 |
+
// larger number
|
| 322 |
+
for (int i = n2; i < n1; i++) ,
|
| 323 |
+
int sub = ((str1*i+ - '0') - carry);
|
| 324 |
+
// If the sub value is -ve,
|
| 325 |
+
// then make it positive
|
| 326 |
+
if (sub < 0) ,
|
| 327 |
+
sub = sub + 10;
|
| 328 |
+
carry = 1;
|
| 329 |
+
-
|
| 330 |
+
else
|
| 331 |
+
carry = 0;
|
| 332 |
+
str*i+ = sub + '0';
|
| 333 |
+
-
|
| 334 |
+
// Reverse resultant string
|
| 335 |
+
strrev(str);
|
| 336 |
+
// Return answer
|
| 337 |
+
return str;
|
| 338 |
+
-
|
| 339 |
+
// Function to remove all leading 0s
|
| 340 |
+
// from a given string
|
| 341 |
+
char* removeLeadingZeros(char* str)
|
| 342 |
+
,
|
| 343 |
+
// Index to store the position of
|
| 344 |
+
// the first non-zero digit
|
| 345 |
+
int i, len = strlen(str);
|
| 346 |
+
for (i = 0; i < len - 1; i++) ,
|
| 347 |
+
if (str*i+ != '0')
|
| 348 |
+
break;
|
| 349 |
+
-
|
| 350 |
+
// Shift all non-zero digits to the
|
| 351 |
+
// beginning of the string
|
| 352 |
+
for (int j = 0; j < len - i; j++)
|
| 353 |
+
str*j+ = str*i + j+;
|
| 354 |
+
// Null terminate the string
|
| 355 |
+
str*len - i+ = '\0';
|
| 356 |
+
return str;
|
| 357 |
+
-
|
| 358 |
+
// Function to multiply two numbers
|
| 359 |
+
// using Karatsuba algorithm
|
| 360 |
+
char* multiply(const char* A, const char* B)
|
| 361 |
+
,
|
| 362 |
+
const char* str1 = A;
|
| 363 |
+
const char* str2 = B;
|
| 364 |
+
if (strlen(A) > strlen(B)) ,
|
| 365 |
+
str1 = B;
|
| 366 |
+
str2 = A;
|
| 367 |
+
-
|
| 368 |
+
// Make both numbers to have
|
| 369 |
+
// same digits
|
| 370 |
+
int n1 = strlen(str1), n2 = strlen(str2);
|
| 371 |
+
while (n2 > n1) ,
|
| 372 |
+
n1++;
|
| 373 |
+
-
|
| 374 |
+
// Base case
|
| 375 |
+
if (n1 == 1) ,
|
| 376 |
+
// If the length of strings is 1,
|
| 377 |
+
// then return their product
|
| 378 |
+
int ans = atoi(str1) * atoi(str2);
|
| 379 |
+
sprintf(str1, "%d", ans);
|
| 380 |
+
return str1;
|
| 381 |
+
-
|
| 382 |
+
// Add zeros in the beginning of
|
| 383 |
+
// the strings when length is odd
|
| 384 |
+
if (n1 % 2 == 1) ,
|
| 385 |
+
n1++;
|
| 386 |
+
char temp*1000+;
|
| 387 |
+
strcpy(temp, str1);
|
| 388 |
+
strcpy(str1, "0");
|
| 389 |
+
strcat(str1, temp);
|
| 390 |
+
strcpy(temp, str2);
|
| 391 |
+
strcpy(str2, "0");
|
| 392 |
+
strcat(str2, temp);
|
| 393 |
+
-
|
| 394 |
+
char Al*1000+, Ar*1000+, Bl*1000+, Br*1000+;
|
| 395 |
+
// Find the values of Al, Ar,
|
| 396 |
+
// Bl, and Br.
|
| 397 |
+
for (int i = 0; i < n1 / 2; ++i) ,
|
| 398 |
+
Al*i+ = str1*i+;
|
| 399 |
+
Bl*i+ = str2*i+;
|
| 400 |
+
Ar*i+ = str1*n1 / 2 + i+;
|
| 401 |
+
Br*i+ = str2*n1 / 2 + i+;
|
| 402 |
+
-
|
| 403 |
+
Al*n1 / 2+ = '\0';
|
| 404 |
+
Ar*n1 / 2+ = '\0';
|
| 405 |
+
Bl*n1 / 2+ = '\0';
|
| 406 |
+
Br*n1 / 2+ = '\0';
|
| 407 |
+
// Recursively call the function
|
| 408 |
+
// to compute smaller product
|
| 409 |
+
// Stores the value of Al * Bl
|
| 410 |
+
char* p = multiply(Al, Bl);
|
| 411 |
+
// Stores the value of Ar * Br
|
| 412 |
+
char* q = multiply(Ar, Br);
|
| 413 |
+
// Stores value of ((Al + Ar)*(Bl + Br)
|
| 414 |
+
// - Al*Bl - Ar*Br)
|
| 415 |
+
char* r = findDiff(
|
| 416 |
+
findSum(Al, Ar),
|
| 417 |
+
findSum(Bl, Br));
|
| 418 |
+
// Multiply p by 10^n
|
| 419 |
+
for (int i = 0; i < n1; ++i)
|
| 420 |
+
strcat(p, "0");
|
| 421 |
+
// Multiply s by 10^(n/2)
|
| 422 |
+
for (int i = 0; i < n1 / 2; ++i)
|
| 423 |
+
strcat(r, "0");
|
| 424 |
+
// Calculate final answer p + r + s
|
| 425 |
+
char* ans = findSum(p, findSum(q, r));
|
| 426 |
+
Subset Sum
|
| 427 |
+
#include <stdio.h>
|
| 428 |
+
#include <limits.h>
|
| 429 |
+
#include <stdbool.h>
|
| 430 |
+
bool foundSolution = false;
|
| 431 |
+
int weights[10];
|
| 432 |
+
int solution[10];
|
| 433 |
+
int n;
|
| 434 |
+
int m;
|
| 435 |
+
void subsetSum(int currentSum, int index)
|
| 436 |
+
{
|
| 437 |
+
if(index == n) {
|
| 438 |
+
if(currentSum == m) {
|
| 439 |
+
foundSolution = true;
|
| 440 |
+
for(int i=0; i<n; i++)
|
| 441 |
+
printf("%d ", solution[i]);
|
| 442 |
+
printf("\n");
|
| 443 |
+
}
|
| 444 |
+
return;
|
| 445 |
+
}
|
| 446 |
+
solution[index] = 1;
|
| 447 |
+
subsetSum(currentSum + weights[index], index+1);
|
| 448 |
+
solution[index] = 0;
|
| 449 |
+
subsetSum(currentSum, index + 1);
|
| 450 |
+
}
|
| 451 |
+
int main()
|
| 452 |
+
{
|
| 453 |
+
//int n, m;
|
| 454 |
+
scanf("%d", &n);
|
| 455 |
+
scanf("%d", &m);
|
| 456 |
+
//int weights[n];
|
| 457 |
+
for(int i=0; i<n; i++)
|
| 458 |
+
scanf("%d", &weights[i]);
|
| 459 |
+
subsetSum(0, 0);
|
| 460 |
+
if(!foundSolution)
|
| 461 |
+
printf("No solution found.\n");
|
| 462 |
+
return 0;
|
| 463 |
+
}
|
| 464 |
+
FRACTIONAL KNAPSACK GREEDY APPROACH
|
| 465 |
+
#include <stdio.h>
|
| 466 |
+
#include <stdlib.h>
|
| 467 |
+
// Structure for an item which stores weight and
|
| 468 |
+
// corresponding value of Item
|
| 469 |
+
struct Item ,
|
| 470 |
+
int profit, weight;
|
| 471 |
+
-;
|
| 472 |
+
// Comparison function to sort Item
|
| 473 |
+
// according to profit/weight ratio
|
| 474 |
+
static int cmp(const void* a, const void* b)
|
| 475 |
+
,
|
| 476 |
+
double r1 = (double)((struct Item*)b)->profit / (double)((struct Item*)b)->weight;
|
| 477 |
+
double r2 = (double)((struct Item*)a)->profit / (double)((struct Item*)a)->weight;
|
| 478 |
+
if (r1 > r2) return 1;
|
| 479 |
+
else if (r1 < r2) return -1;
|
| 480 |
+
return 0;
|
| 481 |
+
-
|
| 482 |
+
// Main greedy function to solve problem
|
| 483 |
+
double fractionalKnapsack(int W, struct Item arr*+, int N)
|
| 484 |
+
,
|
| 485 |
+
// Sorting Item on basis of ratio
|
| 486 |
+
qsort(arr, N, sizeof(struct Item), cmp);
|
| 487 |
+
double finalvalue = 0.0;
|
| 488 |
+
// Looping through all items
|
| 489 |
+
for (int i = 0; i < N; i++) ,
|
| 490 |
+
// If adding Item won't overflow,
|
| 491 |
+
// add it completely
|
| 492 |
+
if (arr*i+.weight <= W) ,
|
| 493 |
+
W -= arr*i+.weight;
|
| 494 |
+
finalvalue += arr*i+.profit;
|
| 495 |
+
-
|
| 496 |
+
// If we can't add current Item,
|
| 497 |
+
// add fractional part of it
|
| 498 |
+
else ,
|
| 499 |
+
finalvalue
|
| 500 |
+
+= arr*i+.profit
|
| 501 |
+
* ((double)W / (double)arr*i+.weight);
|
| 502 |
+
break;
|
| 503 |
+
-
|
| 504 |
+
-
|
| 505 |
+
// Returning final value
|
| 506 |
+
return finalvalue;
|
| 507 |
+
-
|
| 508 |
+
// Driver code
|
| 509 |
+
int main()
|
| 510 |
+
,
|
| 511 |
+
int W = 50;
|
| 512 |
+
struct Item arr*+ = , , 60, 10 -, , 100, 20 -, , 120, 30 - -;
|
| 513 |
+
int N = sizeof(arr) / sizeof(arr*0+);
|
| 514 |
+
// Function call
|
| 515 |
+
printf("%.2lf\n", fractionalKnapsack(W, arr, N));
|
| 516 |
+
return 0;
|
| 517 |
+
-
|
| 518 |
+
N QUENS
|
| 519 |
+
CODE :
|
| 520 |
+
// C program to solve N Queen Problem using backtracking
|
| 521 |
+
#define N 4
|
| 522 |
+
#include <stdbool.h>
|
| 523 |
+
#include <stdio.h>
|
| 524 |
+
// A utility function to print solution
|
| 525 |
+
void printSolution(int board*N+*N+)
|
| 526 |
+
,
|
| 527 |
+
for (int i = 0; i < N; i++) ,
|
| 528 |
+
for (int j = 0; j < N; j++) ,
|
| 529 |
+
if(board*i+*j+)
|
| 530 |
+
printf("Q ");
|
| 531 |
+
else
|
| 532 |
+
printf(". ");
|
| 533 |
+
-
|
| 534 |
+
printf("\n");
|
| 535 |
+
-
|
| 536 |
+
-
|
| 537 |
+
// A utility function to check if a queen can
|
| 538 |
+
// be placed on board*row+*col+. Note that this
|
| 539 |
+
// function is called when "col" queens are
|
| 540 |
+
// already placed in columns from 0 to col -1.
|
| 541 |
+
// So we need to check only left side for
|
| 542 |
+
// attacking queens
|
| 543 |
+
bool isSafe(int board*N+*N+, int row, int col)
|
| 544 |
+
,
|
| 545 |
+
int i, j;
|
| 546 |
+
// Check this row on left side
|
| 547 |
+
for (i = 0; i < col; i++)
|
| 548 |
+
if (board*row+*i+)
|
| 549 |
+
return false;
|
| 550 |
+
// Check upper diagonal on left side
|
| 551 |
+
for (i = row, j = col; i >= 0 && j >= 0; i--, j--)
|
| 552 |
+
if (board*i+*j+)
|
| 553 |
+
return false;
|
| 554 |
+
// Check lower diagonal on left side
|
| 555 |
+
for (i = row, j = col; j >= 0 && i < N; i++, j--)
|
| 556 |
+
if (board*i+*j+)
|
| 557 |
+
return false;
|
| 558 |
+
return true;
|
| 559 |
+
-
|
| 560 |
+
// A recursive utility function to solve N
|
| 561 |
+
// Queen problem
|
| 562 |
+
bool solveNQUtil(int board*N+*N+, int col)
|
| 563 |
+
,
|
| 564 |
+
// Base case: If all queens are placed
|
| 565 |
+
// then return true
|
| 566 |
+
if (col >= N)
|
| 567 |
+
return true;
|
| 568 |
+
// Consider this column and try placing
|
| 569 |
+
// this queen in all rows one by one
|
| 570 |
+
for (int i = 0; i < N; i++) ,
|
| 571 |
+
// Check if the queen can be placed on
|
| 572 |
+
// board*i+*col+
|
| 573 |
+
if (isSafe(board, i, col)) ,
|
| 574 |
+
// Place this queen in board*i+*col+
|
| 575 |
+
board*i+*col+ = 1;
|
| 576 |
+
// Recur to place rest of the queens
|
| 577 |
+
if (solveNQUtil(board, col + 1))
|
| 578 |
+
return true;
|
| 579 |
+
// If placing queen in board*i+*col+
|
| 580 |
+
// doesn't lead to a solution, then
|
| 581 |
+
// remove queen from board*i+*col+
|
| 582 |
+
board*i+*col+ = 0; // BACKTRACK
|
| 583 |
+
-
|
| 584 |
+
-
|
| 585 |
+
// If the queen cannot be placed in any row in
|
| 586 |
+
// this column col then return false
|
| 587 |
+
return false;
|
| 588 |
+
-
|
| 589 |
+
// This function solves the N Queen problem using
|
| 590 |
+
// Backtracking. It mainly uses solveNQUtil() to
|
| 591 |
+
// solve the problem. It returns false if queens
|
| 592 |
+
// cannot be placed, otherwise, return true and
|
| 593 |
+
// prints placement of queens in the form of 1s.
|
| 594 |
+
// Please note that there may be more than one
|
| 595 |
+
// solutions, this function prints one of the
|
| 596 |
+
// feasible solutions.
|
| 597 |
+
bool solveNQ()
|
| 598 |
+
,
|
| 599 |
+
int board*N+*N+ = , , 0, 0, 0, 0 -,
|
| 600 |
+
, 0, 0, 0, 0 -,
|
| 601 |
+
, 0, 0, 0, 0 -,
|
| 602 |
+
, 0, 0, 0, 0 - -;
|
| 603 |
+
if (solveNQUtil(board, 0) == false) ,
|
| 604 |
+
printf("Solution does not exist");
|
| 605 |
+
return false;
|
| 606 |
+
-
|
| 607 |
+
printSolution(board);
|
| 608 |
+
return true;
|
| 609 |
+
-
|
| 610 |
+
// Driver program to test above function
|
| 611 |
+
int main()
|
| 612 |
+
,
|
| 613 |
+
solveNQ();
|
| 614 |
+
return 0;
|
| 615 |
+
-
|
| 616 |
+
// This code is contributed by Aditya Kumar (adityakumar129)
|
| 617 |
+
RANDOMIZED QUICK SORT
|
| 618 |
+
#include <stdio.h>
|
| 619 |
+
#include <stdlib.h>
|
| 620 |
+
#include <time.h>
|
| 621 |
+
int partition(int arr*+, int low, int high)
|
| 622 |
+
,
|
| 623 |
+
int pivot = arr*low+;
|
| 624 |
+
int i = low - 1, j = high + 1;
|
| 625 |
+
while (1) ,
|
| 626 |
+
do ,
|
| 627 |
+
i++;
|
| 628 |
+
- while (arr*i+ < pivot);
|
| 629 |
+
do ,
|
| 630 |
+
j--;
|
| 631 |
+
- while (arr*j+ > pivot);
|
| 632 |
+
if (i >= j)
|
| 633 |
+
return j;
|
| 634 |
+
int temp = arr*i+;
|
| 635 |
+
arr*i+ = arr*j+;
|
| 636 |
+
arr*j+ = temp;
|
| 637 |
+
-
|
| 638 |
+
-
|
| 639 |
+
int partition_r(int arr*+, int low, int high)
|
| 640 |
+
,
|
| 641 |
+
srand(time(0));
|
| 642 |
+
int random = low + rand() % (high - low);
|
| 643 |
+
int temp = arr*random+;
|
| 644 |
+
arr*random+ = arr*low+;
|
| 645 |
+
arr*low+ = temp;
|
| 646 |
+
return partition(arr, low, high);
|
| 647 |
+
-
|
| 648 |
+
void quickSort(int arr*+, int low, int high)
|
| 649 |
+
,
|
| 650 |
+
if (low < high) ,
|
| 651 |
+
int pi = partition_r(arr, low, high);
|
| 652 |
+
quickSort(arr, low, pi);
|
| 653 |
+
quickSort(arr, pi + 1, high);
|
| 654 |
+
-
|
| 655 |
+
-
|
| 656 |
+
void printArray(int arr*+, int n)
|
| 657 |
+
,
|
| 658 |
+
for (int i = 0; i < n; i++)
|
| 659 |
+
printf("%d ", arr*i+);
|
| 660 |
+
printf("\n");
|
| 661 |
+
-
|
| 662 |
+
int main()
|
| 663 |
+
,
|
| 664 |
+
int arr*+ = , 10, 7, 8, 9, 1, 5 -;
|
| 665 |
+
int n = sizeof(arr) / sizeof(arr*0+);
|
| 666 |
+
quickSort(arr, 0, n - 1);
|
| 667 |
+
printf("Sorted array: \n");
|
| 668 |
+
printArray(arr, n);
|
| 669 |
+
return 0;
|
| 670 |
+
-
|
mpmc.txt
ADDED
|
@@ -0,0 +1,890 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CODES
|
| 2 |
+
OPERATIONS
|
| 3 |
+
org 0000h
|
| 4 |
+
//add
|
| 5 |
+
mov a,#25h
|
| 6 |
+
mov b,#12h
|
| 7 |
+
add a,b
|
| 8 |
+
mov 10h,a
|
| 9 |
+
//sub
|
| 10 |
+
mov a,#25h
|
| 11 |
+
subb a,b
|
| 12 |
+
mov 11h,a
|
| 13 |
+
//mul
|
| 14 |
+
mov a , #25h
|
| 15 |
+
mul ab
|
| 16 |
+
mov 12h,a
|
| 17 |
+
mov 13h,b
|
| 18 |
+
//div
|
| 19 |
+
mov a,#25h
|
| 20 |
+
mov b,#12h
|
| 21 |
+
div ab
|
| 22 |
+
mov 14h,a
|
| 23 |
+
mov 15h,b
|
| 24 |
+
//logical operators
|
| 25 |
+
//AND
|
| 26 |
+
mov a,#25h
|
| 27 |
+
mov b,#12h
|
| 28 |
+
anl a,b
|
| 29 |
+
mov 10h,a
|
| 30 |
+
//OR
|
| 31 |
+
mov a,#25h
|
| 32 |
+
mov b,#12h
|
| 33 |
+
orl a,b
|
| 34 |
+
mov 17h,a
|
| 35 |
+
//XOR
|
| 36 |
+
mov a,#25h
|
| 37 |
+
mov b,#12h
|
| 38 |
+
xrl a,b
|
| 39 |
+
mov 18h,a
|
| 40 |
+
//complement
|
| 41 |
+
cpl a,
|
| 42 |
+
mov 19h,a
|
| 43 |
+
//clear
|
| 44 |
+
clr a
|
| 45 |
+
mov 20h, a
|
| 46 |
+
halt:sjmp halt
|
| 47 |
+
end
|
| 48 |
+
To add following data and then use the simulator to examine the EY flag
|
| 49 |
+
org 0000h
|
| 50 |
+
mov a,#92h
|
| 51 |
+
mov r0,#23h
|
| 52 |
+
add a,r0
|
| 53 |
+
jnc l1
|
| 54 |
+
inc r7
|
| 55 |
+
l1:mov r1,#66h
|
| 56 |
+
add a,r1
|
| 57 |
+
jnc l2
|
| 58 |
+
inc r7
|
| 59 |
+
l2:mov r2,#87h
|
| 60 |
+
add a,r2
|
| 61 |
+
jnc l3
|
| 62 |
+
inc r7
|
| 63 |
+
l3:mov r3,#073h
|
| 64 |
+
add a,r3
|
| 65 |
+
jnc l4
|
| 66 |
+
jnc r7
|
| 67 |
+
l4:
|
| 68 |
+
here:sjmp here
|
| 69 |
+
end
|
| 70 |
+
TO LOAD VALUE INTO R0 R4 THEN PUSH INTO STACK THEN CLEAR AND POP THEM BACK
|
| 71 |
+
org 0000h
|
| 72 |
+
mov r0,#25h
|
| 73 |
+
mov r1,#35h
|
| 74 |
+
mov r2,#45h
|
| 75 |
+
mov r3,#55h
|
| 76 |
+
mov r4,#65h
|
| 77 |
+
push 0
|
| 78 |
+
push 1
|
| 79 |
+
push 2
|
| 80 |
+
push 3
|
| 81 |
+
push 4
|
| 82 |
+
mov r0,#00h
|
| 83 |
+
mov r1,#00h
|
| 84 |
+
mov r2,#00h
|
| 85 |
+
mov r3,#00h
|
| 86 |
+
mov r4,#00h
|
| 87 |
+
pop 0
|
| 88 |
+
pop 1
|
| 89 |
+
pop 2
|
| 90 |
+
pop 3
|
| 91 |
+
pop 4
|
| 92 |
+
end
|
| 93 |
+
CALCULATE CUBE OF A NUMBER
|
| 94 |
+
org 0000h
|
| 95 |
+
mov a,20h
|
| 96 |
+
mov b,a
|
| 97 |
+
mul ab
|
| 98 |
+
mov r0,b
|
| 99 |
+
mov b,20h
|
| 100 |
+
mul ab
|
| 101 |
+
mov 23h,a
|
| 102 |
+
mov r1,b
|
| 103 |
+
mov a,r0
|
| 104 |
+
mov b,20h
|
| 105 |
+
mul ab
|
| 106 |
+
mov 21h,b
|
| 107 |
+
mov b,r1
|
| 108 |
+
add a,b
|
| 109 |
+
mov 22h,a
|
| 110 |
+
mov a,21h
|
| 111 |
+
addc a,#0h
|
| 112 |
+
mov 21h,a
|
| 113 |
+
stop:sjmp stop
|
| 114 |
+
end
|
| 115 |
+
FACTORIAL
|
| 116 |
+
org 0000h
|
| 117 |
+
mov r1,#05h
|
| 118 |
+
mov r7,#01h
|
| 119 |
+
lcall fact
|
| 120 |
+
mov r7,a
|
| 121 |
+
fact:
|
| 122 |
+
mov a,r7
|
| 123 |
+
cjnc r1,#00,up
|
| 124 |
+
sjmp up1
|
| 125 |
+
up:
|
| 126 |
+
mov b,r1
|
| 127 |
+
mul ab
|
| 128 |
+
djnz r1,up
|
| 129 |
+
up1:
|
| 130 |
+
ret
|
| 131 |
+
end
|
| 132 |
+
LARGEST NUMBER IN THE SERIES
|
| 133 |
+
ORG 0000H
|
| 134 |
+
MOV R0,#50H
|
| 135 |
+
MOV A,@R0
|
| 136 |
+
MOV R2,A
|
| 137 |
+
DEC R2
|
| 138 |
+
INC R0
|
| 139 |
+
MOV B,@R0
|
| 140 |
+
INC RO
|
| 141 |
+
BACK:MOV A,@R0
|
| 142 |
+
CJNE A,B,LOOP
|
| 143 |
+
JMP LOOP1
|
| 144 |
+
LOOP: JC LOOP1
|
| 145 |
+
MOV B,A
|
| 146 |
+
LOOP1: INC R0
|
| 147 |
+
DJNZ R2,BACK
|
| 148 |
+
NEXT: MOV 60H,B
|
| 149 |
+
END
|
| 150 |
+
SMALLEST NUMBER
|
| 151 |
+
ORG 0000H
|
| 152 |
+
MOV R0,#50H
|
| 153 |
+
MOV A,@R0
|
| 154 |
+
MOV R2,A
|
| 155 |
+
DEC R2
|
| 156 |
+
INC R0
|
| 157 |
+
MOV B,@R0
|
| 158 |
+
INC RO
|
| 159 |
+
BACK:MOV A,@R0
|
| 160 |
+
CJNE A,B,LOOP
|
| 161 |
+
JMP LOOP1
|
| 162 |
+
LOOP: JNC LOOP1
|
| 163 |
+
MOV B,A
|
| 164 |
+
LOOP1: INC R0
|
| 165 |
+
DJNZ R2,BACK
|
| 166 |
+
NEXT: MOV 60H,B
|
| 167 |
+
END
|
| 168 |
+
VIT UNIVERSITY
|
| 169 |
+
ORG 0000H
|
| 170 |
+
MOV DPTR,#MYDATA
|
| 171 |
+
MOV R0,#40H
|
| 172 |
+
MOV R2,#13H
|
| 173 |
+
BAC:CLR A
|
| 174 |
+
MOVC A,@A+DPTR
|
| 175 |
+
MOV @R0,A
|
| 176 |
+
INC DPTR
|
| 177 |
+
INC R0
|
| 178 |
+
DJNZ R2,BACK
|
| 179 |
+
HERE:SJMP HERE
|
| 180 |
+
ORG 200H
|
| 181 |
+
MY DATA:DB "VIT UNIVERSITY"
|
| 182 |
+
END
|
| 183 |
+
TRANSFERRING STRING ADDRESS STARTING FROM 200H TO RAM LOCATIONS STARTING
|
| 184 |
+
AT 40H AND THEN MOVE TO 60H
|
| 185 |
+
ORG 0000H
|
| 186 |
+
MOV DPTR,#MYDATA
|
| 187 |
+
MOV R0,#40H
|
| 188 |
+
MOV R2,#11H
|
| 189 |
+
MOV R1,#60H
|
| 190 |
+
MOV R3,#11H
|
| 191 |
+
BAC:CLR A
|
| 192 |
+
MOVC A,@A+DPTR
|
| 193 |
+
MOV @R0,A
|
| 194 |
+
INC DPTR
|
| 195 |
+
INC R0
|
| 196 |
+
DJNZ R2,BACK
|
| 197 |
+
MOV R0,#40H
|
| 198 |
+
AGAIN:MOV A,@R0
|
| 199 |
+
MOV @R1,A
|
| 200 |
+
INC R0
|
| 201 |
+
INC R1
|
| 202 |
+
DJNZ R3,AGAIN
|
| 203 |
+
HERE:SJMP HERE
|
| 204 |
+
ORG 200H
|
| 205 |
+
MY DATA:DB "VIT UNIVERSITY"
|
| 206 |
+
END
|
| 207 |
+
CONVERSION OF DATA- TO GET A BYTE OF HEX DATA FROM P1, CONVERT IT TO DECIMAL
|
| 208 |
+
AND THEN TO ASCII. PLACE THE ASCII IN RAM LOCATIONS STARTING AT 40H
|
| 209 |
+
ORG 0000H
|
| 210 |
+
MOV P1,#0FBH
|
| 211 |
+
MOV R0, #40H
|
| 212 |
+
MOV A, P1
|
| 213 |
+
LOOP: MOV B, #10
|
| 214 |
+
DIV AB
|
| 215 |
+
XCH A,B
|
| 216 |
+
ADD A, #30H
|
| 217 |
+
MOV @R0, A
|
| 218 |
+
XCH A,B
|
| 219 |
+
INC R0
|
| 220 |
+
JNZ LOOP
|
| 221 |
+
END
|
| 222 |
+
TRANSFER CONTENT OF P1 TO P2 USING ACCUMULATOR
|
| 223 |
+
mov a, #0ffh ;a=ff hex
|
| 224 |
+
mov p1,a ; make p1 and i/p port
|
| 225 |
+
back: mov a, p1
|
| 226 |
+
mov p2, a
|
| 227 |
+
sjmp back
|
| 228 |
+
end
|
| 229 |
+
GENERATE WAVE FORM HAVING XTAL=11.0592Hz
|
| 230 |
+
ORG 000H
|
| 231 |
+
MOV TMOD,#10H
|
| 232 |
+
AGAIN:MOV TL1,#1AH
|
| 233 |
+
MOV TH1,#0FFH
|
| 234 |
+
SETB TR1
|
| 235 |
+
BACK: JNB TF1,BACK
|
| 236 |
+
CLR TR1
|
| 237 |
+
CPL P1.5
|
| 238 |
+
CLR TF1
|
| 239 |
+
SJMP AGAIN
|
| 240 |
+
END
|
| 241 |
+
TOGGLE ALL BITS OF P1 USING 200 ms WITH CRYSTAL FREQUENCY OF 11.0592Hz
|
| 242 |
+
MOV A,#55H
|
| 243 |
+
AGAIN: MOV P0,A
|
| 244 |
+
MOV P1,A
|
| 245 |
+
MOV P2,A
|
| 246 |
+
MOV P3,A
|
| 247 |
+
ACALL DELAY
|
| 248 |
+
CPL A
|
| 249 |
+
SJMP AGAIN
|
| 250 |
+
DELAY:MOV R5,#2
|
| 251 |
+
HERE1:MOV R4,#180
|
| 252 |
+
HERE2:MOV R3,#255
|
| 253 |
+
HERE3:DJNZ R3,HERE3
|
| 254 |
+
DJNZ R4, HERE2
|
| 255 |
+
DJNZ R5, HERE1
|
| 256 |
+
RET
|
| 257 |
+
TO GET 40% AND 70% DUTY CYCLE USING INTERRUPTS
|
| 258 |
+
ORG 0000H
|
| 259 |
+
BACK:
|
| 260 |
+
SETB P0.1
|
| 261 |
+
SETB P1.1
|
| 262 |
+
LCALL DELAY
|
| 263 |
+
LCALL DELAY
|
| 264 |
+
LCALL DELAY
|
| 265 |
+
LCALL DELAY
|
| 266 |
+
CPL P0.1
|
| 267 |
+
LCALL DELAY
|
| 268 |
+
LCALL DELAY
|
| 269 |
+
LCALL DELAY
|
| 270 |
+
CPL P1.1
|
| 271 |
+
LCALL DELAY
|
| 272 |
+
LCALL DELAY
|
| 273 |
+
LCALL DELAY
|
| 274 |
+
SJMP BACK
|
| 275 |
+
DELAY:
|
| 276 |
+
MOV R0,#01H
|
| 277 |
+
MOV R1,#01H
|
| 278 |
+
A1:MOV R1,A2
|
| 279 |
+
DJNZ R0,A1
|
| 280 |
+
RET
|
| 281 |
+
END
|
| 282 |
+
CREATE A PROGRAM FOR 50 ms on & 50 ms off
|
| 283 |
+
ORG 0000H
|
| 284 |
+
LJMP MAIN
|
| 285 |
+
ORG 000BH
|
| 286 |
+
DJNZ R0,TEN
|
| 287 |
+
MOV R0,#36
|
| 288 |
+
JB P1.1,ONN
|
| 289 |
+
DJNZ R2,TEN
|
| 290 |
+
MOV R2,#0
|
| 291 |
+
SET B P1.1
|
| 292 |
+
CPL P0.1
|
| 293 |
+
SJMP TEN
|
| 294 |
+
ONN: DJNZ R1,TEN
|
| 295 |
+
MOV R1,#5
|
| 296 |
+
CLR P1.1
|
| 297 |
+
CLR P0.1
|
| 298 |
+
TEN:RET I
|
| 299 |
+
ORG 0030H
|
| 300 |
+
MAIN:
|
| 301 |
+
MOV R0,#36
|
| 302 |
+
MOV R1,#5
|
| 303 |
+
MOV R2,#0
|
| 304 |
+
MOV TMOD,#2H
|
| 305 |
+
MOV TH0,#-255
|
| 306 |
+
MOV IE,#82H
|
| 307 |
+
SETB P1.1
|
| 308 |
+
SET B TR0
|
| 309 |
+
BACK:SJMP BACK
|
| 310 |
+
END
|
| 311 |
+
|
| 312 |
+
Microprocessor Codes:
|
| 313 |
+
1)CUBE OF A NUMBER
|
| 314 |
+
ORG 0000H
|
| 315 |
+
MOV A,20H
|
| 316 |
+
MOV B,A
|
| 317 |
+
MUL AB
|
| 318 |
+
MOV 21H,A
|
| 319 |
+
MOV 22H,B
|
| 320 |
+
MOV A,20H
|
| 321 |
+
MOV B,21H
|
| 322 |
+
MUL AB
|
| 323 |
+
MOV 23H,A
|
| 324 |
+
MOV 24H,B
|
| 325 |
+
MOV A,20H
|
| 326 |
+
MOV B,22H
|
| 327 |
+
MUL AB
|
| 328 |
+
MOV 25H,A
|
| 329 |
+
MOV 26H,B
|
| 330 |
+
MOV 30H,23H
|
| 331 |
+
MOV A,24H
|
| 332 |
+
MOV A,25H
|
| 333 |
+
MOV 31H,26H
|
| 334 |
+
ADDC A,#0H
|
| 335 |
+
MOV 32H,A
|
| 336 |
+
2)PUSH OR POP
|
| 337 |
+
ORG 0000H
|
| 338 |
+
MOV R0,#25H
|
| 339 |
+
MOV R1,#35H
|
| 340 |
+
MOV R2,#45H
|
| 341 |
+
MOV R3,#55H
|
| 342 |
+
MOV R4,#65H
|
| 343 |
+
PUSH 0
|
| 344 |
+
PUSH 1
|
| 345 |
+
PUSH 2
|
| 346 |
+
PUSH 3
|
| 347 |
+
PUSH 4
|
| 348 |
+
MOV R0,#00H
|
| 349 |
+
MOV R1,#00H
|
| 350 |
+
MOV R2,#00H
|
| 351 |
+
MOV R3,#00H
|
| 352 |
+
MOV R4,#00H
|
| 353 |
+
POP 4
|
| 354 |
+
POP 3
|
| 355 |
+
POP 2
|
| 356 |
+
POP 1
|
| 357 |
+
POP 0
|
| 358 |
+
END
|
| 359 |
+
3)FACTORIAL OF A NUMBER
|
| 360 |
+
ORG 0000H
|
| 361 |
+
MOV R1,#05H
|
| 362 |
+
MOV R7,#01H
|
| 363 |
+
LCALL FACT
|
| 364 |
+
MOV R7,A
|
| 365 |
+
FACT:
|
| 366 |
+
MOV A,R7
|
| 367 |
+
CJNE R1,#00,UP
|
| 368 |
+
SJMP UP1
|
| 369 |
+
UP:
|
| 370 |
+
MOV B,R1
|
| 371 |
+
MUL AB
|
| 372 |
+
DJNZ R1,UP
|
| 373 |
+
UP1:
|
| 374 |
+
RET
|
| 375 |
+
END
|
| 376 |
+
4)FIND THE LARGEST ELEMENT IN A ARRAY
|
| 377 |
+
ORG 0000H
|
| 378 |
+
MOV R0,#50H
|
| 379 |
+
MOV A,@R0
|
| 380 |
+
MOV R2,A
|
| 381 |
+
DEC R2
|
| 382 |
+
INC R0
|
| 383 |
+
MOV B,@R0
|
| 384 |
+
INC R0
|
| 385 |
+
BACK:MOV A,@R0
|
| 386 |
+
CJNE A,B,LOOP
|
| 387 |
+
JMP LOOP1
|
| 388 |
+
LOOP:JC LOOP 1
|
| 389 |
+
MOV B,A
|
| 390 |
+
LOOP1:INC R0
|
| 391 |
+
DJNZ R2,BACK
|
| 392 |
+
NEXT:MOV 60H,B
|
| 393 |
+
END
|
| 394 |
+
5)Copy string from ram 200h to ram 40h
|
| 395 |
+
ORG 0000H
|
| 396 |
+
MOV DPTR,#MYDATA
|
| 397 |
+
MOV R0,#40H
|
| 398 |
+
MOV R2,#13H
|
| 399 |
+
BACK: CLR A
|
| 400 |
+
MOVC A,@A+DPTR
|
| 401 |
+
MOV @R0,A
|
| 402 |
+
INC DPTR
|
| 403 |
+
INC R0
|
| 404 |
+
DJNZ R2,BACK
|
| 405 |
+
HERE :SJMP HERE
|
| 406 |
+
ORG 200H
|
| 407 |
+
MYDATA: DB “VITUNIVERSITY”
|
| 408 |
+
END
|
| 409 |
+
6)COPYING TO LOCATION 60H
|
| 410 |
+
ORG 0000H
|
| 411 |
+
MOV DPTR,#MYDATA
|
| 412 |
+
MOV R0,#40H
|
| 413 |
+
MOV R2,#11H
|
| 414 |
+
MOV R1,#60H
|
| 415 |
+
MOV R3,#11H
|
| 416 |
+
BACK:CLR A
|
| 417 |
+
MOVC A+@A+DPTR
|
| 418 |
+
MOV @R0,A
|
| 419 |
+
INC DPTR
|
| 420 |
+
INC R0
|
| 421 |
+
DJNZ R2,BACK
|
| 422 |
+
MOV R0,#40H
|
| 423 |
+
AGAIN: MOV A,@RO
|
| 424 |
+
MOV @R1,A
|
| 425 |
+
INC R0
|
| 426 |
+
INC R1
|
| 427 |
+
DJNZ R3,AGAIN
|
| 428 |
+
HERE: SJMP HERE
|
| 429 |
+
ORG 200H
|
| 430 |
+
MYDATA:DB “ANYA SOROHI”
|
| 431 |
+
END
|
| 432 |
+
7)EXCHANGE VALUES
|
| 433 |
+
ORG 0000H
|
| 434 |
+
MOV P1,#0FBH
|
| 435 |
+
MOV R0,#40H
|
| 436 |
+
MOV A,P1
|
| 437 |
+
LOOP:MOVB,#10
|
| 438 |
+
DIV AB
|
| 439 |
+
XCH A,B
|
| 440 |
+
ADD A,#30H
|
| 441 |
+
MOV @R0,A
|
| 442 |
+
XCH A,B
|
| 443 |
+
INC R0
|
| 444 |
+
JNZ LOOP
|
| 445 |
+
END
|
| 446 |
+
8)MOV VALUE 55H TO P1,P2,P3 SIMULTANEOUSLY
|
| 447 |
+
ORG 0000H
|
| 448 |
+
MOV A,#55H
|
| 449 |
+
AGAIN:MOV P0,A
|
| 450 |
+
MOV P1,A
|
| 451 |
+
MOV P2,A
|
| 452 |
+
MOV P3,A
|
| 453 |
+
ACALL DELAY
|
| 454 |
+
CPL A
|
| 455 |
+
SJMP AGAIN
|
| 456 |
+
DELAY:MOV R5,#2
|
| 457 |
+
HERE1:MOV R4,#180
|
| 458 |
+
HERE2:MOV R3,#255
|
| 459 |
+
HERE3:DJNZ R3,HERE3
|
| 460 |
+
DJNZ R4,HERE2
|
| 461 |
+
DJNZ R5,HERE1
|
| 462 |
+
RET
|
| 463 |
+
9)250 MICROSECS DELAY USING TIMERS
|
| 464 |
+
ORG 0000H
|
| 465 |
+
MOV TMOD,#10H
|
| 466 |
+
AGAIN: TL1,#1AH
|
| 467 |
+
MOV TH1, #0FFH
|
| 468 |
+
SETB TR1
|
| 469 |
+
BACK:JNB TF1,BACK
|
| 470 |
+
CLR TR1
|
| 471 |
+
CPL P1.5
|
| 472 |
+
CLR TF1
|
| 473 |
+
SJMP AGAIN
|
| 474 |
+
END
|
| 475 |
+
10)MOVING VALUES FROM P1 TO P2
|
| 476 |
+
ORG 0000H
|
| 477 |
+
MOV A,#0FFH
|
| 478 |
+
MOV P1,A
|
| 479 |
+
BACK: MOV A,P1
|
| 480 |
+
MOV P2,A
|
| 481 |
+
SJMP BACK
|
| 482 |
+
END
|
| 483 |
+
11)SERIAL COMMUNICATION- A
|
| 484 |
+
ORG 000H
|
| 485 |
+
SJMP MAIN
|
| 486 |
+
MAIN:MOV TMOD,#20H
|
| 487 |
+
MOV TH1,#-6
|
| 488 |
+
MOV SCON,#50H
|
| 489 |
+
SETB TR1
|
| 490 |
+
AGAIN: MOV SBUF,#”A”
|
| 491 |
+
HERE:JNB TI, HERE
|
| 492 |
+
CLR TI
|
| 493 |
+
SJMP AGAIN
|
| 494 |
+
END
|
| 495 |
+
12)VIT UNIVERSITY
|
| 496 |
+
ORG 0000H
|
| 497 |
+
SJMP MAIN
|
| 498 |
+
MAIN: MOV DPTR,#3000H
|
| 499 |
+
MOV TMOD,#20H
|
| 500 |
+
MOV RO,#0EH
|
| 501 |
+
MOV TH1,#0FDH
|
| 502 |
+
MOV SCON,#50H
|
| 503 |
+
SETB TR1
|
| 504 |
+
UP:CLR A
|
| 505 |
+
MOVC A,@A+DPTR
|
| 506 |
+
AGAIN:MOV SBUF,A
|
| 507 |
+
HERE:JNB T1, HERE
|
| 508 |
+
CLR TI
|
| 509 |
+
INC DPTR
|
| 510 |
+
DJNZ R0,UP
|
| 511 |
+
SJMP $
|
| 512 |
+
ORG 3000H
|
| 513 |
+
DB ‘VIT UNIVERSITY’
|
| 514 |
+
END
|
| 515 |
+
13)
|
| 516 |
+
ORG 0000H
|
| 517 |
+
MOV TMOD,#20H
|
| 518 |
+
MOV SCON, #50H
|
| 519 |
+
SETB TR1
|
| 520 |
+
HERE: JNB RI,HERE
|
| 521 |
+
MOV A,SBUF
|
| 522 |
+
MOV P1,A
|
| 523 |
+
CLR RI
|
| 524 |
+
SJMP HERE
|
| 525 |
+
END
|
| 526 |
+
14) PROGRAM THAT CONTINUOUSLY SENDS 8 BIT DATA FROM
|
| 527 |
+
P0 TO P1 WHILE CREATING A SQUARE WAVE OF 200US PERIOD
|
| 528 |
+
ON PIN P2.1. USE TIMER 0
|
| 529 |
+
ORG 0000H
|
| 530 |
+
LJMP MAIN
|
| 531 |
+
ORG 000BH
|
| 532 |
+
CPL P2.1
|
| 533 |
+
RETI
|
| 534 |
+
ORG 0030H
|
| 535 |
+
MAIN:MOV TMOD,#02H
|
| 536 |
+
MOV P0,#0FFH
|
| 537 |
+
MOV TH0,#-92
|
| 538 |
+
MOV IE,#82H
|
| 539 |
+
SETB TRO
|
| 540 |
+
BACK:MOV A, P0
|
| 541 |
+
MOV P1,A
|
| 542 |
+
SJMP BACK
|
| 543 |
+
END
|
| 544 |
+
15)GENERATE TWO WAVES FOR DUTY CYCLE 40% AND 70%
|
| 545 |
+
USING INTERRUPT
|
| 546 |
+
ORG 0X000
|
| 547 |
+
MOV TMOD,#01H
|
| 548 |
+
MOV TH0,#0FDH
|
| 549 |
+
MOV TH0,#0F0H
|
| 550 |
+
MOV TH1,#0C9H
|
| 551 |
+
MOV TL1,#0C7H
|
| 552 |
+
MOV TCON,#52H
|
| 553 |
+
MOV P1,#00H
|
| 554 |
+
MOV P2,#00H
|
| 555 |
+
SETB ET0
|
| 556 |
+
SETB ET1
|
| 557 |
+
SETB EA
|
| 558 |
+
MAIN: LOOP:
|
| 559 |
+
SJMP MAIN-LOOP
|
| 560 |
+
TIME Q0-ISR
|
| 561 |
+
CLR TF0
|
| 562 |
+
MOV TH0,#0FDH
|
| 563 |
+
MOV TL0,#0FDH
|
| 564 |
+
CPL P1.0
|
| 565 |
+
RETI
|
| 566 |
+
TIME Q1-ISR
|
| 567 |
+
CLR TF1
|
| 568 |
+
MOV TH1,#0C7H
|
| 569 |
+
MOV TL1,#0C7H RETE
|
| 570 |
+
CPL P2.0
|
| 571 |
+
END
|
| 572 |
+
16)WAVEFORM THAT GENERATES (ON-50MS, OFF-80MS)
|
| 573 |
+
ORG 0000H
|
| 574 |
+
LJMP MAIN
|
| 575 |
+
ORG 000BH
|
| 576 |
+
DJNZ R0,TEN
|
| 577 |
+
MOV R0,#36H
|
| 578 |
+
JB P1.1,0HN
|
| 579 |
+
DJNZ R2,TEN
|
| 580 |
+
MOV R2,#8
|
| 581 |
+
SETB P1.1
|
| 582 |
+
CPL P0.1
|
| 583 |
+
SJMP TEN
|
| 584 |
+
CONN:DJNZ R1,TEN
|
| 585 |
+
MOV R1,#5
|
| 586 |
+
CPL P1.1
|
| 587 |
+
CPL P0.1
|
| 588 |
+
TEN RETI
|
| 589 |
+
ORG 0030H
|
| 590 |
+
MAIN:
|
| 591 |
+
MOV R0,#36
|
| 592 |
+
MOV R1,#5
|
| 593 |
+
MOV R2,#8
|
| 594 |
+
MOV TMOD,#24
|
| 595 |
+
MOV THO,#-255
|
| 596 |
+
MOV IE,#82H
|
| 597 |
+
SETB P1.1
|
| 598 |
+
SETB TR0
|
| 599 |
+
BACK:SJMP BACK
|
| 600 |
+
END
|
| 601 |
+
|
| 602 |
+
Microprocessor Codes:
|
| 603 |
+
1)CUBE OF A NUMBER
|
| 604 |
+
ORG 0000H
|
| 605 |
+
MOV A,20H
|
| 606 |
+
MOV B,A
|
| 607 |
+
MUL AB
|
| 608 |
+
MOV 21H,A
|
| 609 |
+
MOV 22H,B
|
| 610 |
+
MOV A,20H
|
| 611 |
+
MOV B,21H
|
| 612 |
+
MUL AB
|
| 613 |
+
MOV 23H,A
|
| 614 |
+
MOV 24H,B
|
| 615 |
+
MOV A,20H
|
| 616 |
+
MOV B,22H
|
| 617 |
+
MUL AB
|
| 618 |
+
MOV 25H,A
|
| 619 |
+
MOV 26H,B
|
| 620 |
+
MOV 30H,23H
|
| 621 |
+
MOV A,24H
|
| 622 |
+
MOV A,25H
|
| 623 |
+
MOV 31H,26H
|
| 624 |
+
ADDC A,#0H
|
| 625 |
+
MOV 32H,A
|
| 626 |
+
2)PUSH OR POP
|
| 627 |
+
ORG 0000H
|
| 628 |
+
MOV R0,#25H
|
| 629 |
+
MOV R1,#35H
|
| 630 |
+
MOV R2,#45H
|
| 631 |
+
MOV R3,#55H
|
| 632 |
+
MOV R4,#65H
|
| 633 |
+
PUSH 0
|
| 634 |
+
PUSH 1
|
| 635 |
+
PUSH 2
|
| 636 |
+
PUSH 3
|
| 637 |
+
PUSH 4
|
| 638 |
+
MOV R0,#00H
|
| 639 |
+
MOV R1,#00H
|
| 640 |
+
MOV R2,#00H
|
| 641 |
+
MOV R3,#00H
|
| 642 |
+
MOV R4,#00H
|
| 643 |
+
POP 4
|
| 644 |
+
POP 3
|
| 645 |
+
POP 2
|
| 646 |
+
POP 1
|
| 647 |
+
POP 0
|
| 648 |
+
END
|
| 649 |
+
3)FACTORIAL OF A NUMBER
|
| 650 |
+
ORG 0000H
|
| 651 |
+
MOV R1,#05H
|
| 652 |
+
MOV R7,#01H
|
| 653 |
+
LCALL FACT
|
| 654 |
+
MOV R7,A
|
| 655 |
+
FACT:
|
| 656 |
+
MOV A,R7
|
| 657 |
+
CJNE R1,#00,UP
|
| 658 |
+
SJMP UP1
|
| 659 |
+
UP:
|
| 660 |
+
MOV B,R1
|
| 661 |
+
MUL AB
|
| 662 |
+
DJNZ R1,UP
|
| 663 |
+
UP1:
|
| 664 |
+
RET
|
| 665 |
+
END
|
| 666 |
+
4)FIND THE LARGEST ELEMENT IN A ARRAY
|
| 667 |
+
ORG 0000H
|
| 668 |
+
MOV R0,#50H
|
| 669 |
+
MOV A,@R0
|
| 670 |
+
MOV R2,A
|
| 671 |
+
DEC R2
|
| 672 |
+
INC R0
|
| 673 |
+
MOV B,@R0
|
| 674 |
+
INC R0
|
| 675 |
+
BACK:MOV A,@R0
|
| 676 |
+
CJNE A,B,LOOP
|
| 677 |
+
JMP LOOP1
|
| 678 |
+
LOOP:JC LOOP 1
|
| 679 |
+
MOV B,A
|
| 680 |
+
LOOP1:INC R0
|
| 681 |
+
DJNZ R2,BACK
|
| 682 |
+
NEXT:MOV 60H,B
|
| 683 |
+
END
|
| 684 |
+
5)Copy string from ram 200h to ram 40h
|
| 685 |
+
ORG 0000H
|
| 686 |
+
MOV DPTR,#MYDATA
|
| 687 |
+
MOV R0,#40H
|
| 688 |
+
MOV R2,#13H
|
| 689 |
+
BACK: CLR A
|
| 690 |
+
MOVC A,@A+DPTR
|
| 691 |
+
MOV @R0,A
|
| 692 |
+
INC DPTR
|
| 693 |
+
INC R0
|
| 694 |
+
DJNZ R2,BACK
|
| 695 |
+
HERE :SJMP HERE
|
| 696 |
+
ORG 200H
|
| 697 |
+
MYDATA: DB “VITUNIVERSITY”
|
| 698 |
+
END
|
| 699 |
+
6)COPYING TO LOCATION 60H
|
| 700 |
+
ORG 0000H
|
| 701 |
+
MOV DPTR,#MYDATA
|
| 702 |
+
MOV R0,#40H
|
| 703 |
+
MOV R2,#11H
|
| 704 |
+
MOV R1,#60H
|
| 705 |
+
MOV R3,#11H
|
| 706 |
+
BACK:CLR A
|
| 707 |
+
MOVC A+@A+DPTR
|
| 708 |
+
MOV @R0,A
|
| 709 |
+
INC DPTR
|
| 710 |
+
INC R0
|
| 711 |
+
DJNZ R2,BACK
|
| 712 |
+
MOV R0,#40H
|
| 713 |
+
AGAIN: MOV A,@RO
|
| 714 |
+
MOV @R1,A
|
| 715 |
+
INC R0
|
| 716 |
+
INC R1
|
| 717 |
+
DJNZ R3,AGAIN
|
| 718 |
+
HERE: SJMP HERE
|
| 719 |
+
ORG 200H
|
| 720 |
+
MYDATA:DB “ANYA SOROHI”
|
| 721 |
+
END
|
| 722 |
+
7)EXCHANGE VALUES
|
| 723 |
+
ORG 0000H
|
| 724 |
+
MOV P1,#0FBH
|
| 725 |
+
MOV R0,#40H
|
| 726 |
+
MOV A,P1
|
| 727 |
+
LOOP:MOVB,#10
|
| 728 |
+
DIV AB
|
| 729 |
+
XCH A,B
|
| 730 |
+
ADD A,#30H
|
| 731 |
+
MOV @R0,A
|
| 732 |
+
XCH A,B
|
| 733 |
+
INC R0
|
| 734 |
+
JNZ LOOP
|
| 735 |
+
END
|
| 736 |
+
8)MOV VALUE 55H TO P1,P2,P3 SIMULTANEOUSLY
|
| 737 |
+
ORG 0000H
|
| 738 |
+
MOV A,#55H
|
| 739 |
+
AGAIN:MOV P0,A
|
| 740 |
+
MOV P1,A
|
| 741 |
+
MOV P2,A
|
| 742 |
+
MOV P3,A
|
| 743 |
+
ACALL DELAY
|
| 744 |
+
CPL A
|
| 745 |
+
SJMP AGAIN
|
| 746 |
+
DELAY:MOV R5,#2
|
| 747 |
+
HERE1:MOV R4,#180
|
| 748 |
+
HERE2:MOV R3,#255
|
| 749 |
+
HERE3:DJNZ R3,HERE3
|
| 750 |
+
DJNZ R4,HERE2
|
| 751 |
+
DJNZ R5,HERE1
|
| 752 |
+
RET
|
| 753 |
+
9)250 MICROSECS DELAY USING TIMERS
|
| 754 |
+
ORG 0000H
|
| 755 |
+
MOV TMOD,#10H
|
| 756 |
+
AGAIN: TL1,#1AH
|
| 757 |
+
MOV TH1, #0FFH
|
| 758 |
+
SETB TR1
|
| 759 |
+
BACK:JNB TF1,BACK
|
| 760 |
+
CLR TR1
|
| 761 |
+
CPL P1.5
|
| 762 |
+
CLR TF1
|
| 763 |
+
SJMP AGAIN
|
| 764 |
+
END
|
| 765 |
+
10)MOVING VALUES FROM P1 TO P2
|
| 766 |
+
ORG 0000H
|
| 767 |
+
MOV A,#0FFH
|
| 768 |
+
MOV P1,A
|
| 769 |
+
BACK: MOV A,P1
|
| 770 |
+
MOV P2,A
|
| 771 |
+
SJMP BACK
|
| 772 |
+
END
|
| 773 |
+
11)SERIAL COMMUNICATION- A
|
| 774 |
+
ORG 000H
|
| 775 |
+
SJMP MAIN
|
| 776 |
+
MAIN:MOV TMOD,#20H
|
| 777 |
+
MOV TH1,#-6
|
| 778 |
+
MOV SCON,#50H
|
| 779 |
+
SETB TR1
|
| 780 |
+
AGAIN: MOV SBUF,#”A”
|
| 781 |
+
HERE:JNB TI, HERE
|
| 782 |
+
CLR TI
|
| 783 |
+
SJMP AGAIN
|
| 784 |
+
END
|
| 785 |
+
12)VIT UNIVERSITY
|
| 786 |
+
ORG 0000H
|
| 787 |
+
SJMP MAIN
|
| 788 |
+
MAIN: MOV DPTR,#3000H
|
| 789 |
+
MOV TMOD,#20H
|
| 790 |
+
MOV RO,#0EH
|
| 791 |
+
MOV TH1,#0FDH
|
| 792 |
+
MOV SCON,#50H
|
| 793 |
+
SETB TR1
|
| 794 |
+
UP:CLR A
|
| 795 |
+
MOVC A,@A+DPTR
|
| 796 |
+
AGAIN:MOV SBUF,A
|
| 797 |
+
HERE:JNB T1, HERE
|
| 798 |
+
CLR TI
|
| 799 |
+
INC DPTR
|
| 800 |
+
DJNZ R0,UP
|
| 801 |
+
SJMP $
|
| 802 |
+
ORG 3000H
|
| 803 |
+
DB ‘VIT UNIVERSITY’
|
| 804 |
+
END
|
| 805 |
+
13)
|
| 806 |
+
ORG 0000H
|
| 807 |
+
MOV TMOD,#20H
|
| 808 |
+
MOV SCON, #50H
|
| 809 |
+
SETB TR1
|
| 810 |
+
HERE: JNB RI,HERE
|
| 811 |
+
MOV A,SBUF
|
| 812 |
+
MOV P1,A
|
| 813 |
+
CLR RI
|
| 814 |
+
SJMP HERE
|
| 815 |
+
END
|
| 816 |
+
14) PROGRAM THAT CONTINUOUSLY SENDS 8 BIT DATA FROM
|
| 817 |
+
P0 TO P1 WHILE CREATING A SQUARE WAVE OF 200US PERIOD
|
| 818 |
+
ON PIN P2.1. USE TIMER 0
|
| 819 |
+
ORG 0000H
|
| 820 |
+
LJMP MAIN
|
| 821 |
+
ORG 000BH
|
| 822 |
+
CPL P2.1
|
| 823 |
+
RETI
|
| 824 |
+
ORG 0030H
|
| 825 |
+
MAIN:MOV TMOD,#02H
|
| 826 |
+
MOV P0,#0FFH
|
| 827 |
+
MOV TH0,#-92
|
| 828 |
+
MOV IE,#82H
|
| 829 |
+
SETB TRO
|
| 830 |
+
BACK:MOV A, P0
|
| 831 |
+
MOV P1,A
|
| 832 |
+
SJMP BACK
|
| 833 |
+
END
|
| 834 |
+
15)GENERATE TWO WAVES FOR DUTY CYCLE 40% AND 70%
|
| 835 |
+
USING INTERRUPT
|
| 836 |
+
ORG 0X000
|
| 837 |
+
MOV TMOD,#01H
|
| 838 |
+
MOV TH0,#0FDH
|
| 839 |
+
MOV TH0,#0F0H
|
| 840 |
+
MOV TH1,#0C9H
|
| 841 |
+
MOV TL1,#0C7H
|
| 842 |
+
MOV TCON,#52H
|
| 843 |
+
MOV P1,#00H
|
| 844 |
+
MOV P2,#00H
|
| 845 |
+
SETB ET0
|
| 846 |
+
SETB ET1
|
| 847 |
+
SETB EA
|
| 848 |
+
MAIN: LOOP:
|
| 849 |
+
SJMP MAIN-LOOP
|
| 850 |
+
TIME Q0-ISR
|
| 851 |
+
CLR TF0
|
| 852 |
+
MOV TH0,#0FDH
|
| 853 |
+
MOV TL0,#0FDH
|
| 854 |
+
CPL P1.0
|
| 855 |
+
RETI
|
| 856 |
+
TIME Q1-ISR
|
| 857 |
+
CLR TF1
|
| 858 |
+
MOV TH1,#0C7H
|
| 859 |
+
MOV TL1,#0C7H RETE
|
| 860 |
+
CPL P2.0
|
| 861 |
+
END
|
| 862 |
+
16)WAVEFORM THAT GENERATES (ON-50MS, OFF-80MS)
|
| 863 |
+
ORG 0000H
|
| 864 |
+
LJMP MAIN
|
| 865 |
+
ORG 000BH
|
| 866 |
+
DJNZ R0,TEN
|
| 867 |
+
MOV R0,#36H
|
| 868 |
+
JB P1.1,0HN
|
| 869 |
+
DJNZ R2,TEN
|
| 870 |
+
MOV R2,#8
|
| 871 |
+
SETB P1.1
|
| 872 |
+
CPL P0.1
|
| 873 |
+
SJMP TEN
|
| 874 |
+
CONN:DJNZ R1,TEN
|
| 875 |
+
MOV R1,#5
|
| 876 |
+
CPL P1.1
|
| 877 |
+
CPL P0.1
|
| 878 |
+
TEN RETI
|
| 879 |
+
ORG 0030H
|
| 880 |
+
MAIN:
|
| 881 |
+
MOV R0,#36
|
| 882 |
+
MOV R1,#5
|
| 883 |
+
MOV R2,#8
|
| 884 |
+
MOV TMOD,#24
|
| 885 |
+
MOV THO,#-255
|
| 886 |
+
MOV IE,#82H
|
| 887 |
+
SETB P1.1
|
| 888 |
+
SETB TR0
|
| 889 |
+
BACK:SJMP BACK
|
| 890 |
+
END
|