ý em hỏi là tại sao lại có số 33000. tức là mình tính như thế nào để có 1 khoảng thời gian gần 1s. nó dùng thạch anh 12Mhz!!
unsigned int x;
for(x=0;x<33000;x++)
unsigned int x;
for(x=0;x<33000;x++)
#include <REGX51.H> void delay (unsigned int ms) { unsigned int i; unsigned char j; for(i=0;i<ms;i++) for(j=0;j<30;j++);{} } void main(void) { unsigned int x,y,m,n; unsigned int AA[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00}; unsigned int dd[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff}; while (1) { P0=P1=P2=P3=0xff; for (x=0;x<=2;x++) for (y=0;y<=7;y++) { if (x==0)P3 = AA[y]; if (x==1)P2 = AA[y]; if (x==2)P1 = AA[y]; delay (1000);} P0=P1=P2=P3=0x00; for (m=0;m<=2;m++) for (n=0;n<=7;n++) { if(m==0)P1 = dd[n]; if(m==1)P2 = dd[n]; if(m==2)P3 = dd[n]; delay (1000);} } }
#include <REGX51.H> #define high(x) (((65536-x) & 0xFF00) >> 8) #define low(x) ((unsigned char)(65536-x)) void delay (unsigned int time) { while (time--) { TMOD = 0X01; TH0 = high(1000); TL0 = low(1000); TF0 = 0; TR0 = 1; while(!TF0); TR0 = 0; } } main () { char x,y; //khai bao int or char chay khong bi loi, unsigned int or unsigned char bi lois char A[]={0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff}; P0 = 0xff; //tat port 0 P1 = 0xff; //tat port 1 P2 = 0xff; //tat port 2 P3 = 0xff; //tat port 3 while (1) { //---------------------------------------- //sang dan tu duoi len tren, tat dan tu tren xuong duoi for (x=3;x>=0;x--) //sang dan for (y=7;y>=0;y--) { if (x==3) P3 = A[y]; if (x==2) P2 = A[y]; if (x==1) P1 = A[y]; if (x==0) P0 = A[y]; delay (100); } delay(100); for (x=3;x>=0;x--) //tat dan for(y=1;y<=8;y++) { if (x==3) P0 = A[y]; if (x==2) P1 = A[y]; if (x==1) P2 = A[y]; if (x==0) P3 = A[y]; delay (100); } } }
for (x=3;x>=0;x--) //sang dan for (y=7;y>=0;y--) { if (x==3) P3 = A[y]; if (x==2) P2 = A[y]; if (x==1) P1 = A[y]; if (x==0) P0 = A[y]; delay (100); }
Comment