e đang tập viết cái code sao băng mà không hiểu sao không delay được đúng giá trị mong muốn
code của em đây ạ,thuật toán nó lủng củng mọi người đừng cười nhé :
đáng lẽ chu kỳ xung phải là 0.1x24=2.4 ms nhưng không hiểu sao e mô phỏng được tới 17ms luôn @@
mọi người giúp em với!
code của em đây ạ,thuật toán nó lủng củng mọi người đừng cười nhé :
Code:
#include <REGX52.H> //thach anh 12 Mhz sbit c1=P0^0; sbit c2=P0^1; sbit c3=P0^2; sbit c4=P0^3; sbit c5=P0^4; sbit c6=P0^5; sbit c7=P0^6; sbit c8=P0^7; sbit c9=P1^0; sbit c10=P1^1; sbit c11=P1^2; sbit c12=P1^3; sbit c13=P1^4; sbit c14=P1^5; sbit c15=P1^6; sbit c16=P1^7; sbit c17=P2^0; sbit c18=P2^1; sbit c19=P2^2; sbit c20=P2^3; sbit c21=P2^4; sbit c22=P2^5; sbit c23=P2^6; sbit c24=P2^7; unsigned char i,j,k; //ham delay 0.1 ms void delay_01ms(unsigned int time) { while(time--) { unsigned char ck=13; while(ck--); } } void saobang(void) { unsigned char b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23; unsigned char code a[24][24]= { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,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=b9-24; b10=k+10; if (b10>23) b10=b10-24; b11=k+11; if (b11>23) b11=b11-24; b12=k+12; if (b12>23) b12=b12-24; b13=k+13; if (b13>23) b13=b13-24; b14=k+14; if (b14>23) b14=b14-24; b15=k+15; if (b15>23) b15=b15-24; b16=k+16; if (b16>23) b16=b16-24; b17=k+17; if (b17>23) b17=b17-24; b18=k+18; if (b18>23) b18=b18-24; b19=k+19; if (b19>23) b19=b19-24; b20=k+20; if (b20>23) b20=b20-24; b21=k+21; if (b21>23) b21=b21-24; b22=k+22; if (b22>23) b22=b22-24; b23=k+23; if (b23>23) b23=b23-24; for (i=0;i<8;i++) { for (j=0;j<24;j++) { c1=a[b0][j]; c2=a[b1][j]; c3=a[b2][j]; c4=a[b3][j]; c5=a[b4][j]; c6=a[b5][j]; c7=a[b6][j]; c8=a[b7][j]; c9=a[b8][j]; c10=a[b9][j]; c11=a[b10][j]; c12=a[b11][j]; c13=a[b12][j]; c14=a[b13][j]; c15=a[b14][j]; c16=a[b15][j]; c17=a[b16][j]; c18=a[b17][j]; c19=a[b18][j]; c20=a[b19][j]; c21=a[b20][j]; c22=a[b21][j]; c23=a[b22][j]; c24=a[b23][j]; delay_01ms(1); } } } } void main() { while(1) { saobang(); } }
mọi người giúp em với!
Comment