thiết bị đo tốc độ động cơ <99000rpm Ảnh đã được thu nhỏ. Bấm vào đây để xem hình cỡ đầy đủ. H ì nh gốc cỡ 634x603 và dung lượng 12KB. Code: #include<AT89S53.h> void delay_ms( unsigned int ms ) { unsigned int i,j; for (i=0;i<ms;i++) for (j=0;j<120;j++){}; } //========= LCD ===================== sbit RS = 0x93; // RS = P1_3 sbit RW = 0xB7; // RW = P3_7 sbit E = 0x94; // E = P1_4 unsigned char digit; void LCD_PutChar(unsigned char k ) { P2=k ; RS=1 ; RW=0 ; E=1 ; E=0 ; delay_ms(1);} void LCD_PutCmd(unsigned char k ) { P2=k ; RS=0 ; RW=0 ; E=1 ; E=0 ; delay_ms(1);} void int_LCD() { delay_ms(50); LCD_PutCmd(0x38); LCD_PutCmd(0x06); // dich con tro sang phai LCD_PutCmd(0x0E); // nhap nhay con tro LCD_PutCmd(0x01); // xoa man hinh LCD_PutCmd(0x02); // ve dau dong LCD_PutCmd(0x80); LCD_PutChar('d');LCD_PutChar('i');LCD_PutChar('a');LCD_PutC har('=');LCD_PutChar(' '); LCD_PutChar(' ');LCD_PutChar(' ');LCD_PutChar(';'); LCD_PutChar('t');LCD_PutChar('r');LCD_PutChar('u');LCD_PutC har('c'); LCD_PutChar('='); } //================= ham mu a^b========= unsigned int ham_mu(unsigned char a,unsigned char b) { unsigned char i; unsigned int j=1; for(i=1;i<=b;i++){j*=a;} return(j); } void update_tocdo(float k) {float y=0; unsigned int x=0; x=k/1; LCD_PutCmd(0x86); digit=(x/10000)+0x30;LCD_PutChar(digit); digit=((x/1000)%10)+0x30;LCD_PutChar(digit); digit=((x/100)%10)+0x30;LCD_PutChar(digit); digit=((x/10)%10)+0x30;LCD_PutChar(digit); digit=(x%10)+0x30;LCD_PutChar(digit); LCD_PutChar(','); y=(k-x)*ham_mu(10,4); x=y/1; digit=((x/1000)%10)+0x30;LCD_PutChar(digit); digit=((x/100)%10)+0x30;LCD_PutChar(digit); digit=((x/10)%10)+0x30;LCD_PutChar(digit); digit=(x%10)+0x30;LCD_PutChar(digit); }//+++++++++++++++++++++++++++++++++++++++++++++++ //========= key ===================== sbit Y1 = 0x80; sbit Y2 = 0x81; sbit OK = 0x82; sbit D_A = 0x90;// P1_0 sbit D_B = 0x91;// P1_1 sbit D_C = 0x92;// P1_2 unsigned char count=0; unsigned char key[10]=0; void scan_key() { Y1=Y2=1;D_A=0;D_B=0;D_C=0; if(!Y1){delay_ms(10);while(!Y1);delay_ms(10);//7 LCD_PutChar('7');key[count++]=7; }; if(!Y2){delay_ms(10);while(!Y2);delay_ms(10);//8 LCD_PutChar('8');key[count++]=8; }; Y1=Y2=1;D_A=0;D_B=0;D_C=1; if(!Y1){delay_ms(10);while(!Y1);delay_ms(10);//3 LCD_PutChar('3');key[count++]=3; }; Y1=Y2=1;D_A=0;D_B=1;D_C=0; if(!Y1){delay_ms(10);while(!Y1);delay_ms(10);//4 LCD_PutChar('4');key[count++]=4; }; if(!Y2){delay_ms(10);while(!Y2);delay_ms(10); LCD_PutChar('.'); }; Y1=Y2=1;D_A=0;D_B=1;D_C=1; if(!Y1){delay_ms(10);while(!Y1);delay_ms(10);//1 LCD_PutChar('1');key[count++]=1; }; Y1=Y2=1;D_A=1;D_B=0;D_C=0; if(!Y1){delay_ms(10);while(!Y1);delay_ms(10);//6 LCD_PutChar('6');key[count++]=6; }; if(!Y2){delay_ms(10);while(!Y2);delay_ms(10);//9 LCD_PutChar('9');key[count++]=9; }; Y1=Y2=1;D_A=1;D_B=0;D_C=1; if(!Y1){delay_ms(10);while(!Y1);delay_ms(10);//2 LCD_PutChar('2');key[count++]=2; }; Y1=Y2=1;D_A=1;D_B=1;D_C=0; if(!Y1){delay_ms(10);while(!Y1);delay_ms(10);//5 LCD_PutChar('5');key[count++]=5; }; Y1=Y2=1;D_A=1;D_B=1;D_C=1; if(!Y1){delay_ms(10);while(!Y1);delay_ms(10);//0 LCD_PutChar('0');key[count++]=0; }; } //=============== encoder ============= float gtri[]=0; float gtri_TB=0; unsigned char so_lan=0; . thiết bị đo tốc độ động cơ <99000rpm Ảnh đã được thu nhỏ. Bấm vào đây để xem