thiết bị đo tốc độ động cơ... Bấm vào đây để xem hình cỡ đầy đủ.
Trang 1thiết bị đo tốc độ động cơ <99000rpm
Trang 2=
nh
miso
sck
mosi
ATIB8S52
L1
P1.0T2 P1.1/T2-E%0.0/ADn P142 Pñ.1/AD1
P1.3 PO.2/AD2 P14 Pñ.3/AD3S P145 Pñ.4/AD4 P148 Pñ.5/ADS P17 Pñ.8/ADB
Pñ.7/ADZ7
ISP
RxD 10 10k TxD 11
* 12
13 phaset® 14
phase2 15
16
Rw 17
RST
ALEPROG P3.0RXD PSEN P3.1/TXD
P3.2ANTO P2.7/A15 P3.3NT1 P2.6/A14 P3.4/T0 P2.5/A13 P3.5I1_ P2.4/A12 P3BAVR P2.3/A11
je P2.2/A10
a P2AsA9
Pt te | ae P2.0/A8
'xTAL1$ 8 °
v1 Y2
OK
R18
D7 D8 D4 D3
sị €3 &
D2 D1
Dũ
10k
Trang 3
T4L6151
|
a Anh đã được thu nhỏ Bấm vào đây để xem hình cỡ đầy đủ Hình
gốc cỡ 634x603 và dung lượng 12KB.
Trang 4
le
kì
10u [ 1k 3 ott S
- >
¬L_ 4tco+” Trout 4 1 L_/}+ 5] 65 erin 13 2
+[ 10u —EAN [7X
Zz
— ö
oO
2
4
CON4
5V
lL
Trang 6
Ƒ
~thiết lập các chân nhập tín hiệu
+khai báo LCD
:
+nhap gia tri dg kinh dia , nhân OK đê lưu giá trị
+nhập giá trị dø kính trục (can đo tốc độ), nhân OK
+hé so tỉ lệ = (dg kính đĩa/dg trục)
|
+khoi tao ngat:
- counter0 mode2
- timer] mode2(ngat sau 250us)
- ưu tiên ngắt counter0
Trang 7
ngăt ngoài counter0
tăng biến đếm số lần ngắt COUTIẨ lên |
thoát ngắt
| tăng biến §0_ lan lên 1 |
i
luu gia tri xung :
gtr[3]=gtri[2]
gtr[2]=gtri[1]
gtr[ I ]=gtri|0]
gtt[0]~ TLO +count* 256
| xóa bộ đêm TL0, xóa biên đêm eount |
+xuat gtri_TB ra LCD
txóa biến dém so_lan
đừng các ngắt dé xem ket qua |
Wena
tY
| cho phép ngat hoat dong lai |
Code:
#include<AT89S53.h>
void delay_ms( unsigned int ms )
{ unsigned int i,j];
Trang 8
unsigned char digit;
void LCD_PutChar(unsigned char k )
{ P2=k ; RS=l ; RW=0 ; E=1l ; E=0 ; delay_ms(1);}
void LCD _PutCmd(unsigned char k )
{ P2=k ; RS=0 ; RW=0 ; h=l ; E=0 ; delay_ms(1);}
void int_LCD()
{ delay_ms (50);
LCD _PutCmd (0x38) ;
LCD _PutCmd (0x80);
LCD PutChar('d');LCD_ PutChar('1i');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 (1=1; 1<=b;1++) {j*=a; }
return (3);
}
void update_tocdo(float k)
{float y=0;
unsigned int x=0;
Trang 9
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);
sbit OK = 0x82;
sbit D_A = 0x90;// P1_0
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;
}7
if (!Y¥2) {delay_ms (10) ;while(!Y2);delay_ms(10);//8
LCD_PutChar('8');key[count++]=8;
}7
1£(!Y1){delay ms(10);while(!Y1);delay ms (10); //3
LCD_PutChar('3');key[count++]=3;
};
Trang 10fl
f1
Y1=Y2=1;D A=0;D B=l;D C=0;
LCD_PutChar('4');key[count++]=4;
};
1f(!Y2) {delay_ms (10) ;while(!Y2);delay_ms (10);
LCD PutChar('.');
};
Y1=Y2=1;D_A=0;D_B=1;D_C=1;
LCD_PutChar('1');key[count++]=1;
}7
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;
}7 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;
};
oat gtri[]=0;
oat gtri_TB=0;
unsigned char so_lan=0;
Trang 11
unsigned char gtri_dia=0;
unsigned int gtri_truc=0;
unsigned char he_so=1;
setup_interrupts ()
{
TMOD = 0x26; //counter O in mode 2 (8bit reload),
TH)
PT1 = Ô;
}
chuan_mau() interrupt 3 //timer 1 interrupt
{
so_ lan+*+;
]=gtr1 [3];
gtri[3]=gtri [2];
gtri[2]=gtri [1];
gtri[1]=gtri[0];
gtri[0]=TLO+count*256;
TLO=0;
count=0;
if (so_lan==5)
{gtri_TB
=((gtri[0]+gtri[1]+gtri[2]+gtri[3]+gtri[4])/(5*100*250*so 1 an))*he_ so;
update_tocdo (gtri_TB);
so_lan=0;
}7 // -nhan OK de dung lai xem gia tri -
1f£(!OK) {TRO=TR1I=ETO=ET1=0; gtri[O]J=gtri[l]=gtri[2]=gtri
[3]=gtri[4]=0;
Trang 12
count=so_lan=0; TLO=THO=0;
delay_ms (50);while(!OK);delay_ms (10);
while (OK) ;
delay_ms (50) ;while(!OK);delay_ms (10) ; ETO=TRO=ET1=TRI1=1
hi
{count++;
}
TLO=0;
{
}
TMOD = 0x20;
SCON = 0x50;
THỊ = OXxFD;
TRL = 1;
RI = 1;
TT = 1;
void main()
{ Y1=Y2=OK=1;
P3 3 = 1;
P3 4 = 1;
1nt_ LCD ();
LCD_ PutCmd (Ôx84);
while (OK) scan key (); // OK lan 1 : nhap gtri dgkinh
banh đa
delay_ms (50) ;wh1ile(!OKX) ;delay_ ms (50);
so_lan=count;
for (count=0; count<so_lan; count++)
{gtri_diat=key [count] *ham_mu(10,so_lan-count-—1);};
count=0;
LCD _PutCmd(0x8D) ;
while (OK)scan_key(); // OK lan 2 : nhap gtri dgkinh
Trang 13
delay_ ms (10);wh1ile(!OKX);delay_ ms (10);
so_lan=count;
for (count=0; count<so_lan; count++)
LCD _PutCmd (0x01); LCD _PutCmd(0x0C) ; LCD PutCmd (0x80);
LCD _ PutChar('(');LCD PutChar('v');LCD PutChar('/');LCD PutC har('s');LCD PutChar(')');
LCD PutChar('="');
he_so=gtri_dia/gtri_truc;
count=0;
setup_interrupts();
while(1);