Tải bản đầy đủ (.doc) (30 trang)

thiết kế mạch đo tần số hiện thị kết quả trên máy tính sử dụng 8051

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (443.04 KB, 30 trang )

Mc lc

Chương 1 !"#$%$
&%&%'()%$
&%%* !"#$%+
Chương 2*,-./%&
%&%#,0./1%&
%%*23&
%$%#,0 456%7
Chương 3.%$
$%&%8.9%$
$%%*:,;<.9=
>58?
@5).A$7
&
LỜI NÓI ĐẦU
;B C1.D !@EF56GH2:(
:I28@@ @H5(@JK.
D.L8)K%MN2)O;@;9P.L8
5@@)F;-4Q@RK,%S;B
5(;):.L8)KT8;J;U@D5VOP
KJAEB.@EUJ%WH) !5(
/) !TWH).9 G
)23CCX@ P:%Y(
<9/RCH2JP.D.L8)K@
CCAEB@CC:,H:IO:(RZ
@!Q[P \KB]%^UO)@_M.9
23RC2X !FRC0K`%a;<J92b
K4Rcd/;)O)@e.G;
.f%g @2K9249h9B
:ITd,%



1. Tổng quan về đo tần số và chuẩn giao tiếp máy tính RS232
1.1. Tổng quan về đo tần số
Tần sốijj;hh k:IE32-.l5N5KPO 
!);J,3%5@J;G
;DBP;<RJ.l%
 Chu kỳ ihh;Rh 5hk5@.AfB@;3
P!)5N5KJ5(Pi/5@AU:,;<ikminkk%
o)H@.lP!)RJ5@
&
p q
p q
f hz
T s
=
Tần số góc tức thờiirk:IE3:5@ThP
P!)/5@
i k
d
t
dt
ω
Ψ
=
%
Y<!)@s1h 58 !4j5@J
K5:I.G%
&
%
 

d
f
dt
ω
π π
=
Ψ
=
>A:IFRC;5VO.:G )F
OJ856!)G545K%%%(RAWJtu
@<'tu%
.5@RCC9%S@;b9vH
P.AJR@E%%%
Các phương pháp đo tần số)5OD:,:IE
3h.AhJ!E 4hRK:@G
B0!)@J .%
M9P!)):,:,2w
@:,
kĐo tần số bằng phương pháp biến đổi thẳng:I@2X5K
.J:-.,).C).v3
$
x*.,):,Oi.)W)Jd)Jk
:IFRC9;.AW7tuy+.tu;K
0(B!E.GiB!E7z7+z&+z+k%
*5K.@ KFRC<4CGB.5(
@23;%
x*.)R:,O9;RAW&7tuy
+77.tu:IFRC.)v5d;23T@;G%%%%
x.v3:IFRC9!EP!)
E@!)@;RAW&7tuy+7'tu%*bFRC9v

.lJR@E.A%
2kĐo tần số bằng phương pháp so sánh:IO)GE5GG
E CJ..J:-%%%
x#FRCGE5GG:IO)2XD;O;4@<
N(PJ 3iRO;4
:!uk%\:,@ Rc9!)E 
N!)E;RAW&7tu7gtu%
x.;JFRC9P!)E !)
24J;.AW&77.tuy7'tu;.V8G )
F%
x*E CJ9;.AW7tu
7.tu%
x.J:-9E !)24
JE;.AW+7.tuy&7'tuz:FRC.5d
23G %
;H1T .v3:IFRC;J;U@b@
N4{\9.9@FRC.AH%%%
a:(T s@E|J:,@RCC2
B20
xM2X:,J:-%
x.)W%
=
x*%
x.v3%( Trích [1] Trang 89-90)
Như vậy để đo tần số trong vi điều khiển, ta có thể thực hiện theo cách đếm số
xung mà nguồn phát xung trong 1 khoảng thời gian nhất định(ví dụ là 1s), từ
đó tìm ra tần số của nguồn cần đo.
1.2. Tổng quan giao tiếp máy tính RS232.
1.2.1 Đặt vấn đề
YBH\*@.9;B;D;/RC

.95:%%%'|"#$5@J;H.L
8:IFRC;J;U9|23K( !%S5@
JRc3RK.G02J.B
5@23R@.5(B|9A2ARH5)5@&%+
+%=J7.2}G.5@J&&+.2}(J23N2)%~
VP; GV5@;J9vJ
2:IFRDh:; %
*42A"#$:I5:@;:,R@5@"#$•
@"#$*%S: <42A"#$•e<!:IRcb
"#$*)Z:IRc@0K::ID5@4€D5@
"#$
* !:&Nh"#$*:ID5@
*%*Q:IRc|JRh23
5:%%%;4 !5K?TN5K+Tc @ @
P !%Y).("#$e:,R•
R@N2).DJKJ5@.G02J@J; RH
5)B%
1.2.2 Ưu điểm của giao diện nối tiếp RS232
n>A1•P
n23K95d A. !:IB)
+
n*K),A98:I)0GG

1.2.3 Những đặc điểm cần lưu ý trong chuẩn RS232
n;"#$/(K;4@R:(i57@&k5@n&Y%
t) :I3;-.A;KW$777G‚777G
ng/5&)X;.A$Y&Y/57Wn$Y
&Y
nJ; 8RH5)OK5@&77.2i@  95(,k
n*5@A)Rf,+77ƒ

n;-.AA5(,$777G:Af,‚777G
nMJR@PH !@23K|
"#$.G:I&+Q.GFRh5
n*;3J; RH5)
+7‚+&&7‚+7$77„77&77=77=…77?„77&?77……77$…=77%%%%+„„77&&+
772
1.2.4 Các mức điện áp đường truyền
"#$FRC:,/; G.GE//5@FRC!
))45)HJRT RZ@B%a W4;
U†5‡PBFRC/):,
!9GA/57@&%S@/)4e
3;3;-.A:IB@2P2J8@;-.;
P2J%
g/)P4"#$*i:Rc2T k:IGA
:
ng/57n$Yn&Y
ng/5&&Y$Y
*/);KW$Y$Y5@;K 9 %*!
<W$Y($Y5@K.G:I3V;;:I 
;35WB54NWEBJ!)A:I
UJ;J,<dI56%M@ RZ)AK

)RP23@PA:; %J
; RZCJ@R@PRT RZ%M))
 v‡;I(J&?.•R%
1.2.5 Cổng RS232 trên PC
t !T) :I;23!B5@&*
 "#$%#5:I*954(=c W5K
 !%>*:IRB5@*&**
$%%%;45K:IFRC"#$5K?T

ia•?kN+Tia•+k% 5K@ c:
5K@ :IT2)2-Oia•?k@ia•+k
E|,0T*?T

;45@.!)T@<RKPa•?
*/1PT:
nT&a*;;h;ahhia*ak\!)RH5)
nT"hhhai"EakS8RH5)
nT$;aiEak; RH5)
nT=ah;5"hR ia"kMRH5)€@:I.!
K2-2J8.; RH5)
nT+#5';Ri#'kgP!)
nT„a#h"hR ia#"kaH5)€@:I.!K2-2J

; .€@8RH5)
nT‚"hh#hR 4F2G; N:@ 54/K
J.€@; RH5)
nT…*5h;#hRi*#kˆ9F2G8N:@ 54/
.!KJ9G22J; 5@€@8!)
nT?"‰Rhi"‰k•G25@2J88!
);G
*ba•…2T (;.G@ H%S4G
.G8-T %
1.2.6 Quá trình dữ liệu
a) Quá trình truyền dữ liệu
; RH5)"#$:IO).G02J%a8 
4KJ9vJ2:I; i&.!Ok%•J; FJ2
2di2;k9G22J82J.!Os:IF;
5; 2h%•@ 5G2d2X/7%%h5@2
RH5)i2Rk:IFR:(RKU]#*‰‰i95@+„‚ …2RH

5)k#5@J\; 2i>9;2€5† .Gk@c5@
2RW295@&&+ 2RW%
b) Tốc độ Baud
MT 5@JN;:P"#$%@ !5@N;:
;<; RH5)"#$5@J; 8RH5)
 bD5@J2%J2:I3V5@2; :I;
&T  2; :I;&T %J2@ 
A:I58-24@248AJ:iJ
H.9@ !A&J; 2k
S@J2bJ9GAJ; 5@J•R%J
•R54J@FURH5):IFRC9R•A
2:I; bGJ2<AJO@2:I
; %Y<JF2)OUJ24.J2@
J2R5@A0B

gJJ•R:Rc+7‚+&&7&+7$77„77&77=77=…77
?„77&?77……77$…=77+„777&&+77Š;23D:Rc
J5@&?77
>FRC"#$< 4.FRC5@
 9/5.G:I=‹; &2%a8 J
2@<; &2@f< 9/5
@Af%M@ 5@(K•R@.A; %
c) Bit chẵn lẻ hay Parity bit
MT 5@2.9;5‡;4:; %OBP;<.9;5‡
.; RH5)5@2E4RH5):I; 9<;NFJ
5‡;;<; %a;"#$FRCJ.L8
.9;€5†%
gJ2€5†:I2@RH5):I; 9B 5:I
2Œ&Œ:IF;J.; 5@€ 5†%
gJ\; 2v9<;J5†5‡AK:&$+‚?%%%S

:J2€:Id5‡<\; 2s;c;3(;:I
.Gd5‡<.G);5‡%a;.L8U5‡@
.G:IFRC;;:I.A1J@223d5‡%
*b/; RZ%\@ G.G82K5bEh
;;<%
1.2.7 Sơ đồ ghép nối RS232
*;BKP"#$H.9 23.%
a:(T 5@HK::IRc%
a) Mạch chuẩn giao RS232 dùng IC Max232
gE$5@‰* 4RcH"#$@23K%
gE$5@‰*PUgE%MT 5@‰* 3@:IFRC
2;K"#$%'@PgE$cI
i&> &7>k@!I;.4; "#$%ab
!):I."#$%g‡; ;@8!
):I2A)5KOV)i<:5@&+>Yk%S@
?
;gE$b:I.(0n+YB0GBf%
gK:
MT 5@K&.4RcgE$%*b.4<:,O%
gK@ :IFRC.;"#$%
b) Mạch chuẩn giao tiếp RS232 dùng DS275
MT e5@‰*PUgE%a#‚+:IRc;K
P"#$:Rv5@2G@Rc;.
GBf%
&7
gK.,A%a2G4;/RC!:I
Rc%
c) Mạch chuẩn giao tiếp RS232 dùng transitor
gKFRC;;9"#$%
1.2.8 Phần mềm giao tiếp

'H"#$@.9AGR)982
:IRH5); 54@8E:@%t)K;B58;<
"#$(EF56:@ RcB5@2JGCY5*nn%•JGC
@ 58;<Q58;<R)G"#$%S@2JGC@ b2J
GCPah5e:IRc.%
;;:I:Rc@.G258;<R)<9FRCGC
;OP•R•%M5@t h;h;5%*GC@ R).,Av
; 8RH5)G"#$%M(Žˆ\<2K9@T 95B 
;#;}]55\;;}]h;h}}t h;h;5}%58G
;D5@.%
•JGCt h;h;5R).)4:Rc..9:IRH
5); 548E:@%a8 ;4K2T 2JGC58;<€
%M5@h;5%\@ R).,
t h;h;5:v2E8RH5)@; RH5)%(Trích từ [2])
&&
2. Cơ sở thiết kế phần cứng
2.1. Sơ đồ khối chức năng:
 >QB(EF56.-J@d)
 >0B0)%
 >935B !);W.9O)(
.9993.A;4@< !%
 YEF5!8!)W.KERJE;@
.ACC)!%
 >KERJK;ERJ5@!)@
.9%
2.2 Lựa chọn linh kiện
2.2.1. Nguồn 5V lấy từ ắcquy
2.2.2 Vi điều khiển AT89C51
]…?*+&5@J2JEF56…25K*g•#J@GBB
(2J(ƒ5958;<:I%S:IAEB(G)2J(

>ˆF
56
>
QB
>9
3
>
K
E
R
J
>0
&
.G2 ,8JPU]h5@:,!(Dg*#+&
g

T;@85)%
]…?*+&N;:,2A:=>2 hƒ5&…2 h"]g$
:EB82J3}&„2JB;Qd/:4
@+ 4TdJportGKRJ@KE
clock;4chip.]…?*+&:I.(5VKJ
AE7@‡;IJ.)15:I:I5OD2X
%*JvRW*\•;.Z|"]g2J3
}port@)dCKJ%*J0A
R ;<JRP"]g:.GKRJBE
clockXG)KJ.Pchip.reset/
h%

Sơ đồ khối của AT89C51
&$

Sơ đồ các chân 89C51
Như vậy AT89C51 có tất cả 40 chân với các chức năng như sau:
- Vcc (40)
*TB)i+Yk
- GND (20)
*TBi7Yk
- Port 0 (32-39)
Port75@;EB8…2%Port7b:IB<5@2
3vi2 hBk@2RH5)I;.; EB2J(RH5)
@@2J(:,;<@%Port7e82 hU;.58
;<ƒ5@EB2 hU;..9;:,;<i*)
;-.|5424@:I;..9;:,;<k%
- Port 1(1-8)
Port&5@portEB8…2% Port &e82 h3v
B;58;<ƒ5%
&=
- Port 2 (21-28)
Port5@portEB8…2%PortK;2 hP2
3v;<K5)W2J(:,;<@@;
; EB2J(RH5)@FRC3v&„2%;
; EB2J(RH5)@FRC3v…2PortJ
RP/1N2)\%Porte82!3v
@@!).9;58;<ƒ5@.9;:,
;<%
- Port 3 (10-17)
Port$5@PortEB8…2%Port$eb5@/
1.P]…?*+&%*/1@ :I5).4:

*T 4 */1
\$%7 "Ea S‘@\;

\$%& Ea S‘;\;
\$%
INT0
S‘@d@7
\$%$
INT1
S‘@d@&
\$%= 7 S‘@24@P2J3&
\$%+ & S‘@24@P2J37
\$%„
WR
M.92J(RH5)@
\$%‚
RD
M.9D2J(RH5)@
Port$e8J@!).9)58;<ƒ5@
.9;:,;<%
- RST (9)
S‘@reset%g/;4T@ ;.l ;.2J
RJJsreset]…?*+&%
Mạch reset tác động bằng tay và tự động reset khi khởi động máy
&+
RST
- ALE/
PROG
(30)
]^5@JE‘;92 hBP3v;.; EB
2J(@%*T@ e5@‘@E58;<i
PROG
k;

58;<ƒ5%
>KJ2<:E‘;]^5’.G5@
&}„PKRJ9:IRcC!3W
24@{KEclock% 45:65@JE]^s232f
;‡J.l; EB2J(RH5)@%
>KJ]^9:IG)2Xset27P
/1N2)3v…^%>2@ :Iset]^v!
O;O)5)g•YˆNg•Y*%S:I5KT@ s
:I.|54%Y)set2.G|KJ2 hBP3
vs.GRC2J.9-JO:,
;<@%

PSEN
(29)
PSEN
 i\;;#;h ^25hk5@ E.9 ; EB2J (
:,;<@%>]…?*+O:,;<W2J(:,
;<@
PSEN
:I.!K5‡.l :KJ
PSEN
s232f‡.; 82J(RH5)@%
-
EA
/Vpp(31)

EA
i^Eh;5]h^25hk5@T|; EB2J(:,
;<@i2dW7777tƒƒƒƒtk%
EA

m7|; EB2J(:,;<@:I5K
EA
m&
sO:,;<24;chip
 45:6;X2.&i5.2&k:I58;<
EA
s
:I24;.;hh%
&„
*T@ e8)|58;<Ym&Y.58;<
ƒ5
- XTAL1 và XTAL2
ˆ]&@ˆ]5@‘@@;PJ2J.KAP
KRJ:IB<9Rc:J2JRJ;4%

>G 4@.l)CP!)Eclock24
@R!)@ AJj5j5;:(.KK
Eclock 24; 4.L8/B@
/)O9@OKA:IEhE|%
2.2.3 IC 555
+++5@J5K5.).5@22T ()R•R@K:IE
G@9 c !(,0K,A
:IJ;JE%S:I/RC@KKEd
 5@HKRJ.%MT 5@5.)PU*g•#AEB
%#T 5@2AGP+++;43;:
nM)@&…Yic W5KP+++g+++S^+++
S^‚+++%%k
nab)B„]&+]
nM)5-/7%+&+Y
nM)5-/B7%7$7%7„Y

n*GB5(B5@„77Ž
* Các chức năng của 555:
&‚
n@23KE!E
ng E
nM:IJ;JEi\Žgk
nM3;!Ei\\gkit Rc;0Kk
MB v5@HG,2AP+++%*bHG.2K
.ARhh“p$q
>6)
U 1
L M 5 5 5
3
4 8
1 5
2 6
7
O U T
R S T V C C
G N D C V
T R G T H R
D S C H G

*) Chức năng của các chân IC555
T .6) /1
& 'Sa *T
 "' S‘@EA
$ •• S‘;
= "# "hhi0Ck
+ *Y M).9

„ t" ”:[
‚ a#*t' ˆA)
… Y** S0R:,
2.2.4 Max232
* 9/)H*•g@.9%
2.2.5 Thạch anh 12 MHz
;KsFRCKJ5K&gu9KRJ
]…?*+&
&…
2.2.6 T điện
C)5@5.))FCJ:IFRC;B;J;U;K
)FQ:IFRC;K5D05D•K; 
!)E KKRJ%;K@ sFRCJC
.;hh@C.RJ%
Tụ gốm Tụ hóa
2.2.7 Điện trở
;23)F);-5@J5.);DQ:I5@W
IB2@.5Klh•5);J@:K;:I
5K);-;3.%
Hình dạng của điện trở trong thiết bị điện tử.
2.2.8 Nút bấm button
;K@ FRC$Q2B9.9h1A
)@N@ 1%
&?
Nút bấm
2.3 Sơ đồ nguyên lý:
Trong đó có:
-Phần tạo xung dao động: cấp tín hiệu vào cho Vi điều khiển, gồm 1
IC555, 1 biến trở để điều chỉnh tần số cần đo.
Chân 3 tức đầu ra của IC555 nối với chân P3.5/T1 của AT89C51

7
- Thành phần hiển thị: gồm một con IC Max 232, 1 cổng com ảo, và một
màn hình hiển thị ảo
&
- Khối Xử lý: gồm 1 Vi điều khiển AT89C51, 1 khối điện trở băng, 1 bộ
tạo dao động thạch anh
3. Thiết kế phần mềm
3.1 Thuật toán điều khiển.
3.1.1 Thuật toán tổng thể

3.1.2 Thuật toán chi tiết
$
3.2 Chương trình điều khiển.
;code do tan so
#include <sfr51.inc>
org 0H
;tao nut bat dau
START:JB P3.7,START ;doi den luc nut bat dau duoc an xuong muc
thap
sjmp main
org 0BH ;TMR0 ISR
ajmp TMR0_ISR
h;&E
h;.A&
•h
Ñ
Ñ
#
t93;4@< !
^

; RH5)*•g
MEP;&
=
org 1BH ;TMR1 ISR
ajmp TMR1_ISR
main:
mov SP,#50H; Khoi tao ngan xep
mov R6, #20; nap so lan lap la 20 lan
mov tmod, #51H; khoi dong timer 1, che do 16-bit
mov R7, #00; tan so ban dau la 0
setb ET0; bat ngatTimer 0
setb ET1; Bat ngat Timer 1
setb EA; Bat tat ca cac ngat
clr TF0
mov a,#'T'; truyen chu T ra man hinh
Acall TRANS; goi ham truyen du lieu ra man hinh
mov a,#'A';truyen chu A ra man hinh
Acall TRANS
mov a,#'N'
Acall TRANS
mov a,#'S'
Acall TRANS
mov a,#'O'
Acall TRANS
mov a,#':'
Acall TRANS
mov a,#' '
again:
mov TH0, #3CH
mov TL0, #0BAH

mov R6, #20
+

×