| Tiêu đề: code khối lập phương có điều xung Fri Nov 04, 2011 9:02 am |
|
|
| | | | Tiêu đề: Re: code khối lập phương có điều xung Fri Nov 04, 2011 9:05 am |
|
|
| | | | Tiêu đề: Re: code khối lập phương có điều xung Fri Nov 04, 2011 10:04 am |
|
|
| | | | Tiêu đề: Re: code khối lập phương có điều xung Fri Nov 04, 2011 11:17 am |
| | | | | - Code:
-
#include<REGX51.H> 2 #include<intrins.h> 3 #define on 1// muc logic xuat tu chan vdk de mo c1815 4 #define off 0//c1815 mo => den tat c1815 dong => den bat 5 6 bit all_chanel=0; 7 unsigned char x,y,z,k1,k2,pwmval=0,pwmval1=0; 8 unsigned char chanel,chanel1; 9 10 sbit a0=P1^0; 11 sbit a1=P1^1; 12 sbit a2=P1^2; 13 sbit a3=P1^3; 14 sbit a4=P1^4; 15 sbit a5=P1^5; 16 sbit b0=P3^0; 17 sbit b1=P3^1; 18 sbit b2=P3^2; 19 sbit b3=P3^3; 20 unsigned char code sdant[]={0x01,0x03,0x07,0x0f,0x1f,0x3f}; 21 //unsigned char code sdanp[]={0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00}; 22 //unsigned char code schayp[]={0x00,0x01,0x02,0x04,0x08,0x10,0x20}; 23 //unsigned char code schayt[]={0x00,0x20,0x10,0x08,0x04,0x02,0x01}; 24 unsigned char code quayt[]={0x01,0x02,0x04,0x08}; 25 unsigned char code quayp[]={0x08,0x04,0x02,0x01}; 26 27 void tre (long time); 28 long u; 29 void tre (long time) 30 { 31 1 for(u=0;u<time;u++); 32 1 {} 33 1 } 34 void delay_us(unsigned short int abcd) 35 { 36 1 unsigned short int de1; 37 1 for (de1=0;de1<=abcd;de1++) 38 1 { 39 2 // do nothing 40 2 } 41 1 } 42 void sang(void) 43 { 44 1 P1=P3=0xff; 45 1 tre(1000); 46 1 } 47 void tat(void) 48 { 49 1 P1=P3=0x00; 50 1 tre(1000); 51 1 } 52 ////////////////////// 53 int i,j; 54 void quaytrongp(int sl) //4 canh trong quayp ok 55 { C51 COMPILER V9.01 TEP 11/04/2011 08:57:46 PAGE 2
56 1 for(j=0;j<sl;j++) 57 1 { 58 2 tat(); 59 2 { 60 3 for(i=0;i<4;i++) 61 3 { 62 4 a0=a2=1; 63 4 P3=quayp[i]; 64 4 tre(6000); 65 4 } 66 3 for(i=0;i<4;i++) 67 3 { 68 4 a0=a2=1; 69 4 P3=quayp[i]; 70 4 tre(6000); 71 4 } 72 3 for(i=0;i<4;i++) 73 3 { 74 4 a0=a2=1; 75 4 P3=quayp[i]; 76 4 tre(5000); 77 4 } 78 3 for(i=0;i<4;i++) 79 3 { 80 4 a0=a2=1; 81 4 P3=quayp[i]; 82 4 tre(4500); 83 4 } 84 3 for(i=0;i<4;i++) 85 3 { 86 4 a0=a2=1; 87 4 P3=quayp[i]; 88 4 tre(4000); 89 4 } 90 3 for(i=0;i<4;i++) 91 3 { 92 4 a0=a2=1; 93 4 P3=quayp[i]; 94 4 tre(3500); 95 4 } 96 3 for(i=0;i<4;i++) 97 3 { 98 4 a0=a2=1; 99 4 P3=quayp[i]; 100 4 tre(3000); 101 4 } 102 3 for(i=0;i<4;i++) 103 3 { 104 4 a0=a2=1; 105 4 P3=quayp[i]; 106 4 tre(2500); 107 4 } 108 3 for(i=0;i<4;i++) 109 3 { 110 4 a0=a2=1; 111 4 P3=quayp[i]; 112 4 tre(2000); 113 4 } 114 3 for(i=0;i<4;i++) 115 3 { 116 4 a0=a2=1; 117 4 P3=quayp[i]; C51 COMPILER V9.01 TEP 11/04/2011 08:57:46 PAGE 3
118 4 tre(1500); 119 4 } 120 3 for(i=0;i<4;i++) 121 3 { 122 4 a0=a2=1; 123 4 P3=quayp[i]; 124 4 tre(1500); 125 4 } 126 3 for(i=0;i<4;i++) 127 3 { 128 4 a0=a2=1; 129 4 P3=quayp[i]; 130 4 tre(1500); 131 4 for(i=0;i<4;i++) 132 4 { 133 5 a0=a2=1; 134 5 P3=quayp[i]; 135 5 tre(1500); 136 5 } 137 4 for(i=0;i<4;i++) 138 4 { 139 5 a0=a2=1; 140 5 P3=quayp[i]; 141 5 tre(1500); 142 5 } 143 4 for(i=0;i<4;i++) 144 4 { 145 5 a0=a2=1; 146 5 P3=quayp[i]; 147 5 tre(1500); 148 5 } 149 4 }}}} 150 void quaytrongt(int sl) //4 canh trong quayt ok 151 { 152 1 for(j=0;j<sl;j++) 153 1 { 154 2 tat(); 155 2 { 156 3 for(i=0;i<4;i++) 157 3 { 158 4 a0=a2=1; 159 4 P3=quayt[i]; 160 4 tre(6000); 161 4 } 162 3 for(i=0;i<4;i++) 163 3 { 164 4 a0=a2=1; 165 4 P3=quayt[i]; 166 4 tre(6000); 167 4 } 168 3 for(i=0;i<4;i++) 169 3 { 170 4 a0=a2=1; 171 4 P3=quayt[i]; 172 4 tre(5000); 173 4 } 174 3 for(i=0;i<4;i++) 175 3 { 176 4 a0=a2=1; 177 4 P3=quayt[i]; 178 4 tre(4500); 179 4 } C51 COMPILER V9.01 TEP 11/04/2011 08:57:46 PAGE 4
180 3 for(i=0;i<4;i++) 181 3 { 182 4 a0=a2=1; 183 4 P3=quayt[i]; 184 4 tre(4000); 185 4 } 186 3 for(i=0;i<4;i++) 187 3 { 188 4 a0=a2=1; 189 4 P3=quayt[i]; 190 4 tre(3500); 191 4 } 192 3 for(i=0;i<4;i++) 193 3 { 194 4 a0=a2=1; 195 4 P3=quayt[i]; 196 4 tre(3000); 197 4 } 198 3 for(i=0;i<4;i++) 199 3 { 200 4 a0=a2=1; 201 4 P3=quayt[i]; 202 4 tre(2500); 203 4 } 204 3 for(i=0;i<4;i++) 205 3 { 206 4 a0=a2=1; 207 4 P3=quayt[i]; 208 4 tre(2000); 209 4 } 210 3 for(i=0;i<4;i++) 211 3 { 212 4 a0=a2=1; 213 4 P3=quayt[i]; 214 4 tre(1500); 215 4 } 216 3 for(i=0;i<4;i++) 217 3 { 218 4 a0=a2=1; 219 4 P3=quayt[i]; 220 4 tre(1500); 221 4 } 222 3 for(i=0;i<4;i++) 223 3 { 224 4 a0=a2=1; 225 4 P3=quayt[i]; 226 4 tre(1500); 227 4 } 228 3 for(i=0;i<4;i++) 229 3 { 230 4 a0=a2=1; 231 4 P3=quayt[i]; 232 4 tre(1500); 233 4 for(i=0;i<4;i++) 234 4 { 235 5 a0=a2=1; 236 5 P3=quayt[i]; 237 5 tre(1500); 238 5 } 239 4 for(i=0;i<4;i++) 240 4 { 241 5 a0=a2=1; C51 COMPILER V9.01 TEP 11/04/2011 08:57:46 PAGE 5
242 5 P3=quayt[i]; 243 5 tre(1500); 244 5 } 245 4 for(i=0;i<4;i++) 246 4 { 247 5 a0=a2=1; 248 5 P3=quayt[i]; 249 5 tre(1500); 250 5 } 251 4 }}}} 252 void h1(int sl) // dap 2 canh trong 1 253 { for (j=0;j<sl;j++) 254 1 { 255 2 tat(); 256 2 a4=a5=1; 257 2 b1=b2=1; 258 2 tre(6000); 259 2 b1=b2=0; 260 2 b0=b3=1; 261 2 tre(6000); 262 2 b1=b2=1; 263 2 b0=b3=0; 264 2 tre(5000); 265 2 b1=b2=0; 266 2 b0=b3=1; 267 2 tre(4000); 268 2 b1=b2=1; 269 2 b0=b3=0; 270 2 tre(4500); 271 2 b1=b2=0; 272 2 b0=b3=1; 273 2 tre(4000); 274 2 b1=b2=1; 275 2 b0=b3=0; 276 2 tre(3500); 277 2 b1=b2=0; 278 2 b0=b3=1; 279 2 tre(2000); 280 2 b1=b2=1; 281 2 b0=b3=0; 282 2 tre(1000); 283 2 b1=b2=0; 284 2 b0=b3=1; 285 2 tre(1000); 286 2 b1=b2=1; 287 2 b0=b3=0; 288 2 tre(1000); 289 2 } 290 1 } 291 void ht1(int sl) // dap 2 canh trong 2 292 { for (j=0;j<sl;j++) 293 1 { 294 2 tat(); 295 2 a3=a1=1; 296 2 b0=b1=1; 297 2 tre(6000); 298 2 b1=b0=0; 299 2 b2=b3=1; 300 2 tre(6000); 301 2 b3=b2=0; 302 2 b0=b1=1; 303 2 tre(5000); C51 COMPILER V9.01 TEP 11/04/2011 08:57:46 PAGE 6
304 2 b1=b0=0; 305 2 b2=b3=1; 306 2 tre(4000); 307 2 b3=b2=1; 308 2 b0=b1=0; 309 2 tre(4500); 310 2 b3=b2=0; 311 2 b0=b1=1; 312 2 tre(4000); 313 2 b3=b2=1; 314 2 b0=b1=0; 315 2 tre(3500); 316 2 b3=b2=0; 317 2 b0=b1=1; 318 2 tre(2000); 319 2 b3=b2=1; 320 2 b1=b0=0; 321 2 tre(1000); 322 2 b3=b2=0; 323 2 b0=b1=1; 324 2 tre(1000); 325 2 b3=b2=1; 326 2 b0=b1=0; 327 2 tre(1000); 328 2 } 329 1 } 330 void h2(int sl) // trong sang ngoai quay ok 331 { 332 1 for(j=0;j<sl;j++) 333 1 { 334 2 tat(); 335 2 P3=0xff; 336 2 tre(3000); 337 2 a0=1; 338 2 tre(3000); 339 2 a0=0; 340 2 a1=1; 341 2 tre(3000); 342 2 a1=0; 343 2 a2=1; 344 2 tre(3000); 345 2 a2=0; 346 2 a3=1; 347 2 tre(3000); 348 2 } 349 1 } 350 void h21(int sl) // trong sang ngoai quay ok 3p 351 { 352 1 for(j=0;j<sl;j++) 353 1 { 354 2 tat(); 355 2 P3=0xff; 356 2 tre(1500); 357 2 a4=1; 358 2 tre(1500); 359 2 a4=0; 360 2 a1=1; 361 2 tre(1500); 362 2 a1=0; 363 2 a5=1; 364 2 tre(1500); 365 2 a5=0; C51 COMPILER V9.01 TEP 11/04/2011 08:57:46 PAGE 7
366 2 a3=1; 367 2 tre(1500); 368 2 a3=0; 369 2 a2=1; 370 2 tre(1500); 371 2 a3=0; 372 2 a0=1; 373 2 tre(1500); 374 2 375 2 } 376 1 } 377 378 void h5(int sl) // sang tat 3 mat truoc sau ,trong quay ok 379 { 380 1 for(j=0;j<sl;j++) 381 1 { 382 2 tat(); 383 2 a1=a2=a4=1; 384 2 tre(2000); 385 2 a1=a2=a4=0; 386 2 a0=a3=a5=1; 387 2 tre(2000); 388 2 a0=a3=a5=0; 389 2 } 390 1 } 391 392 void h6(int sl) // sang tat toan khoi ok 393 { 394 1 for(j=0;j<sl;j++) 395 1 { 396 2 sang(); 397 2 tat(); 398 2 } 399 1 } 400 void h61(int sl) // sang tat p ok 401 { 402 1 for(j=0;j<sl;j++) 403 1 { 404 2 tat(); 405 2 P1=0x00; 406 2 P3=0xff; 407 2 tre(5000); 408 2 P3=0x00; 409 2 P1=0xff; 410 2 tre(5000); 411 2 P1=0x00; 412 2 P3=0xff; 413 2 tre(4000); 414 2 P3=0x00; 415 2 P1=0xff; 416 2 tre(4000); 417 2 P1=0x00; 418 2 P3=0xff; 419 2 tre(3500); 420 2 P3=0x00; 421 2 P1=0xff; 422 2 tre(3500); 423 2 P1=0x00; 424 2 P3=0x00; 425 2 tre(3000); 426 2 P3=0x00; 427 2 P1=0xff; C51 COMPILER V9.01 TEP 11/04/2011 08:57:46 PAGE 8
428 2 tre(3000); 429 2 } 430 1 } 431 void h612(int sl) // sang tat p2 ok 432 { 433 1 for(j=0;j<sl;j++) 434 1 { P1=0xff; 435 2 P3=0x00; 436 2 tre(1000); 437 2 P1=0x00; 438 2 P3=0xff; 439 2 tre(1000); 440 2 } 441 1 } 442 void h7(int sl) // 4 tam giac quay ok 443 { 444 1 for(j=0;j<sl;j++) 445 1 { 446 2 tat(); 447 2 a4=b0=b3=1; 448 2 tre(5000); 449 2 a4=b0=b3=0; 450 2 a3=b0=b1=1; 451 2 tre(5000); 452 2 a3=b0=b1=0; 453 2 a5=b1=b2=1; 454 2 tre(5000); 455 2 a5=b1=b2=0; 456 2 a1=b2=b3=1; 457 2 tre(5000); 458 2 a1=b2=b3=0; 459 2 } 460 1 } 461 void h8(int sl) // hai tam giac doi xung quay ok 462 { 463 1 for(j=0;j<sl;j++) 464 1 { 465 2 tat(); 466 2 a1=b2=b3=b0=b1=a3=1; 467 2 tre(5000); 468 2 a1=b2=b3=b0=b1=a3=0; 469 2 a4=a5=b0=b1=b2=b3=1; 470 2 tre(5000); 471 2 a4=a5=b0=b1=b2=b3=1; 472 2 } 473 1 } 474 void h9(int sl) // hai tam giác day canh trong quay ok 475 { 476 1 for(j=0;j<sl;j++) 477 1 { 478 2 tat(); 479 2 b0=b2=a4=a1=1; 480 2 tre(5000); 481 2 b0=b2=a4=a1=0; 482 2 b0=b2=a3=a5=1; 483 2 tre(5000); 484 2 b0=b2=a3=a5=0; 485 2 b1=b3=a4=a3=1; 486 2 tre(5000); 487 2 b1=b3=a4=a3=0; 488 2 b1=b3=a5=a1=1; 489 2 tre(5000); C51 COMPILER V9.01 TEP 11/04/2011 08:57:46 PAGE 9
490 2 b1=b3=a5=a1=0; 491 2 } 492 1 } 493 void h10(int sl) // trong ngoai quay nguoc chieu nhau 494 { 495 1 for(j=0;j<sl;j++) 496 1 { 497 2 tat(); 498 2 a4=b3=1; 499 2 tre(1500); 500 2 a4=b3=0; 501 2 a1=b0=1; 502 2 tre(1500); 503 2 a1=b0=0; 504 2 a5=b1=1; 505 2 tre(1500); 506 2 a5=b1=0; 507 2 a3=b2=1; 508 2 tre(1500); 509 2 } 510 1 } 511 512 void h11(int sl) // sang dan toan khoi ok 513 { 514 1 for(j=0;j<sl;j++) 515 1 { 516 2 tat(); 517 2 for (i=0;i<4;i++) 518 2 { 519 3 P3=sdant[i]; 520 3 tre(5000); 521 3 } 522 2 i=0; 523 2 tat(); 524 2 for (i=0;i<6;i++) 525 2 { 526 3 P1=sdant[i]; 527 3 tre(5000); 528 3 } 529 2 i=0; 530 2 }} 531 void h112(int sl) // sang dan toan khoi 2 ok 532 { 533 1 for(j=0;j<sl;j++) 534 1 { 535 2 tat(); 536 2 for (i=0;i<4;i++) 537 2 { 538 3 P3=sdant[i]; 539 3 tre(1000); 540 3 } 541 2 i=0; 542 2 tat(); 543 2 for (i=0;i<6;i++) 544 2 { 545 3 P1=sdant[i]; 546 3 tre(1000); 547 3 } 548 2 i=0; 549 2 }} 550 ////////////////////////// bam xung 551 void sang_toi_tat_ca() C51 COMPILER V9.01 TEP 11/04/2011 08:57:46 PAGE 10
552 { 553 1 all_chanel=1; 554 1 pwmval=255; 555 1 for (x=0;x<255;x++) 556 1 { 557 2 pwmval=pwmval-1; 558 2 delay_us(1); 559 2 } 560 1 all_chanel=0; 561 1 } 562 void init_timer0(void)//init=initialization, ham cai dat timer 0 de phuc vu ngat 563 { 564 1 //TMOD=0x02;// timer 0 duoc su dung o che do 1, 16 bit 565 1 TH0=0x0D8;//thuc hien ngat sau moi 10ms (TL0 se tu nap lai gia tri chu trong TH0) 566 1 TL0=0xF0; 567 1 EA=1;//cho phep ngat toan cuc 568 1 ET0=1;// cho phep ngat timer 0 569 1 TR0=1; 570 1 } 571 void ngat_timer0() interrupt 1 using 0 572 { 573 1 k1++; 574 1 if (k1==255) k1=0; 575 1 if (k1>=0&k1<=pwmval)//1000x1ms=1s ( no understand) 576 1 { 577 2 if (all_chanel==1) 578 2 { 579 3 goto all_on; 580 3 } 581 2 582 2 all_on: 583 2 P1=0x00;P3=0xff; 584 2 P2=0xff; 585 2 //P3=0x00; 586 2 587 2 exit: 588 2 x=x; 589 2 //k=0;//10.000x0.1 =1000us=1s (thuc hien sau moi 1s) 590 2 } 591 1 else if (k1>=pwmval&k1<=255) 592 1 { 593 2 if (all_chanel==1) 594 2 { 595 3 goto all_off; 596 3 } 597 2 598 2 all_off: 599 2 P1=0xff;P3=0x00; 600 2 P2=0x00; 601 2 exit1: 602 2 y=y; 603 2 //k++; 604 2 } 605 1 TF0=0; 606 1 } *** WARNING C280 IN LINE 587 OF TEP.C: 'exit': unreferenced label *** WARNING C280 IN LINE 601 OF TEP.C: 'exit1': unreferenced label 607 //////////////// 608 void main(void) 609 { 610 1 int n=1; 611 1 while (n<50) C51 COMPILER V9.01 TEP 11/04/2011 08:57:46 PAGE 11
612 1 { 613 2 h6(20); //chop tat toan khoi 614 2 h612(10); //sang tat P 615 2 h21(10); //dap 2 canh trong 616 2 ht1(5); 617 2 h21(5); 618 2 h6(10); 619 2 h1(2); 620 2 h612(5); //////////////////////////3 phut 621 2 h6(5); 622 2 h1(5); 623 2 h61(2); 624 2 h21(5); 625 2 ht1(3); 626 2 h6(10); 627 2 h1(2); 628 2 h6(5); 629 2 ht1(5); 630 2 h112(1);//sang dan trong ngoai 631 2 h1(2); 632 2 h612(15); 633 2 h21(5); 634 2 h6(3); 635 2 h21(5); 636 2 } 637 1 while(1) 638 1 { 639 2 TMOD=0x22; 640 2 init_timer0(); 641 2 //tatca(); 642 2 tre(1000); 643 2 644 2 ET1=0; 645 2 ET0=1;// Enable timerintterrupt 646 2 chanel=255; 647 2 sang_toi_tat_ca(); 648 2 ET0=0;// Disable timerintterrupt 649 2 //delay_us(1000); 650 2 651 2 ET0=1;// Enable timerintterrupt 652 2 chanel=255; 653 2 tat_toi_sang_ca(); *** WARNING C206 IN LINE 653 OF TEP.C: 'tat_toi_sang_ca': missing function-prototype 654 2 ET0=0;// Disable timerintterrupt 655 2 delay_us(2000); 656 2 657 2 ET1=0; 658 2 ET0=1;// Enable timerintterrupt 659 2 chanel=255; 660 2 sang_toi_tat_ca(); 661 2 ET0=0;// Disable timerintterrupt 662 2 //delay_us(1000); 663 2 664 2 ET0=1;// Enable timerintterrupt 665 2 chanel=255; 666 2 tat_toi_sang_ca(); 667 2 ET0=0;// Disable timerintterrupt 668 2 delay_us(2000); 669 2 h6(20); 670 2 h1(10); 671 2 h6(30); 672 2 ht1(20); C51 COMPILER V9.01 TEP 11/04/2011 08:57:46 PAGE 12
673 2 quaytrongt(3); 674 2 h11(5);//sang dan trong ngoai 675 2 h10(5); //trong ngoai quay nguoc chieu 676 2 h1(1); //dap 2 canh trong 677 2 ht1(1); 678 2 h2(5); //trong sang ngoai quay 679 2 h5(5); //sang 3 mat truoc sau 680 2 h61(5); //sang tat P 681 2 quaytrongp(2); 682 2 ht1(3); // dap 2 canh trong 2 683 2 h7(5); // 4 tam giac quay 684 2 h8(5); // hai tam giac doi xung quay 685 2 h9(5); //hai tam giac day canh trong quay 686 2 } 687 1 } | | | | |
| | | | Trang 1 trong tổng số 1 trang | | ::. | Permissions in this forum: | Bạn không có quyền trả lời bài viết
| |
| |
| Free forum | ©phpBB | Free forum support | Báo cáo lạm dụng | Cookies | Thảo luận mới nhất |
|
|
|