You are on page 1of 20

Trng H Cng Nghip H Ni

n mn Vi iu khin

B CNG THNG
TRNG I HC CNG NGHIP H NI
KHOA : IN T

N MN HC
TI: THIT K M HNH KHI LED 3D

Gio vin hng dn:


V Th Thu Hng
Sinh vin thc hin:
1.L c H
2.Nguyn nh Ti
3.Mai Ngc Khi

Trng H Cng Nghip H Ni

n mn Vi iu khin

Mc Lc
Li ni u :...................................................................................................3
Phn mt: C s l thuyt.
I: Gii thiu v b vi iu khin 8051(89S52):.. .4
1: c im ca IC vi iu khin:...4
2: Cu trc bn trong ca 8051(89S52)...4
3: Cc Port ca 89S52.......................................................................................6
a: Port 0 (P0.0-P0.7).......................................................................................6
b: Port 1 (P1.0-P1.7).......................................................................................6
c: Port 2 (P2.0-P2.7).......................................................................................6
d: Port 3 (P3.0-P3.7).......................................................................................6
4: Nghin cu tng th v vi iu khin. 7
4.1: Hot ng nh thi:................................................................................8
4.2: Cng ni tip:..........................................................................................8
4.2: Ngt v x l ngt:..................................................................................8
II: Gii thiu v 74HC595:...........................................................................9
1: Cu to v hot ng ca 74HC595:..........................................................9
III: Gii thiu v khi led 3D cube 5x5x5...................................................9
1: Cu to v hot ng:.................................................................................9
Phn hai :Ni dung thit k sn phm.10
1: S nguyn l:.........................................................................................10
2: Nguyn l hot ng:.................................................................................11
3: Thut ton:..................................................................................................12
4: Code lp trnh: ...........................................................................................12
Phn ba: ng dng v hng pht trin..20
1: Hng pht trin:........................................................................................ 20
2: ng dng thc t:....................................................................................... 20

Trng H Cng Nghip H Ni

n mn Vi iu khin

LI NI U
B vi iu khin vit tt l Micro-controller, l mch tch hp trn mt
chp c th lp trnh c, dng iu khin hot ng ca h thng. B vi
iu khin tin hnh c, lu tr thng tin, x l thng tin, o lng thi gian
v tin hnh c m mt c cu no .
Ngi lp trnh c th s dng nhiu ngn ng lp trnh cho vi iu
khin; Nhng thng s dng hai ngn ng chnh lp trnh l : Ngn ng
lp trnh C v ngn ng lp trnh Assembly (lp trnh trn phn cng ca my
tnh).
Sau khi lp trnh xong phn trnh dch c np vo IC v dng IC ny iu
khin cc h thng theo yu cu ra:
Hin nay vi iu khin rt pht trin, n c ng dng vo rt nhiu
lnh vc nh: Sn xut cng nghip, t ng ho v rt nhiu lnh vc khc. So
vi k thut s th vi iu khin nh gn hn rt nhiu do n c tch hp li
v c lp trnh iu khin.
Vi ti : Thit k khi led 3D cube dng 5x5x5 chng em mun vit
ln mt s ng dng ca IC ny ng thi th hin nhng kin thc mnh
hc c. C th trong qu trnh thit k v ng dng c nhiu vn c th
cha c nh mong mun, chng em mong c s nhn xt ch bo ca cc
thy chng em c th hon thnh tt hn nhng n v sau.
Chng em xin chn thnh cm n!!!

Gio vin hng dn : Nguyn Thu Hng


Sinh vin thc hin : L c H
Nguyn nh Ti
Mai Ngc Khi

Trng H Cng Nghip H Ni

n mn Vi iu khin

PHN MT
C S L THUYT
I: Gii thiu s lc v b vi iu khin 8051(89S52):
1: IC vi iu khin thuc h MCS51 c cc c im sau:
4 kbyte ROM
128 byte RAM
4 port I/O 8 bit
2 b nh thi
1 cng ni tip
6 ngun ngt
Nhng thc t hin nay ta hay s dng 8052 (89S52) cng l mt thnh vin h
8051 . 8052 c tt c cc c tnh ca 8051 ngoi ra cn c thm 4 kbyte ROM,
128 byte RAM v mt b nh thi na.

Vi iu khin 8051
2: Cu trc bn trong IC8051:
Phn chnh ca vi iu khin 8051 l b vi x l trung tm ( CPU: central
processing unit).
n v x l trung tm nhn trc tip xung t b dao ng, ngoi ra cn c kh
nng a mt tn hiu gi nhp t bn ngoi.

Trng H Cng Nghip H Ni

n mn Vi iu khin

Chng trnh ang chy c th dng li nh mt khi iu khin ngt bn


trong. Cc ngun ngt c th l : Cc bin c bn ngoi, s trn ca b m
nh thi hoc cng c th l giao din ni tip.
Ba b nh thi 16bit hot ng nh mt b m.
Cc cng Port0, Port1, Port2, Port3. S dng vo mc ch iu khin v xut
nhp tn hiu. cng Port3 c thm cc ng dn iu khin dng trao i
vi b nh bn ngoi, hoc u ni giao din ni tip, cng nh cc ng
ngt dn bn ngoi.

S khi 89S52.
Giao din ni tip c cha mt b truyn v mt b nhn khng ng b, lm
vic c lp vi nhau. Tc truyn qua cng ni tip c th t trong di rng
v c n nh bng mt b nh thi.
Trong vi iu khin 8051 c hai thnh phn quan trng khc l b nh v
cc thanh ghi:
B nh gm c b nh RAM v b nh ROM dng l tr d liu v m
lnh.
5

Trng H Cng Nghip H Ni

n mn Vi iu khin

Cc thanh ghi s dng l tr thng tin trong qu trnh x l. Khi CPU lm


vic n thay i ni dung cc thanh ghi.
3: Cc Port ca 89S52:
a :Port0 (P0.0-P0.7):
Port 0 gm 8 chn, ngoi chc nng xut nhp, Port 0 cn l bus a hp d
liu v a ch (AD0-AD7), chc nng ny s c s dng khi 8051 giao tip
vi tht b ngoi c cc kin trc bus nh mch nh, mch PIO

Cu trc ca cc chn trn Port 0.


b :Port1 (P1.0-P1.7):
i vi 8051, chc nng duy nht ca Port 1 l chc nng xut nhp, cng nh
cc Port khc Port 1 c th xut nhp theo bit hoc theo byte.

Hnh 4: Cu trc ca cc chn trn Port 1 v Port3.


c :Port2 (P2.0-P2.7):
Port 2 l mt Port cng dng kp trn cc chn 21-28 c dng nh cc
ng xut nhp hoc l byte cao cua Bus a ch vi cc thit k dng b nh
m rng
6

Trng H Cng Nghip H Ni

n mn Vi iu khin

Hnh 5 : Cu trc cc chn trn Port 2

d :Port3 (P3.0-P3.7):
Mi chn trn Port 3 ngoi chc nng xut nhp cn c mt chc nng ring,
c th nh sau :
Port
P3.0
P3.1
P3.2
P3.3
P3.4
P3.5
P3.6
P3.7

Tn
RXD
TXD
INT0
INT1
T0
T1
WR
RD

Chc nng chuyn i


D liu nhn cho Port ni tip
D liu pht cho Port ni tip
Ngt 0 bn ngoi
Ngt 1 bn ngoi
Ng vo ca Timer/Counter 0
Ng vo ca Timer/Counter 1
Xung ghi b nh d liu ngoi
Xung c b nh d liu ngoi

4 : Nghin cu tng th v vi iu khin :


Nhn tng th chng ta c th tn hiu v vi iu khin trong 3 mng vn
chnh l: Cc b nh thi Timer, Port ni tip v Ngt.
4.1: Hot ng nh thi :
Cc thanh ghi:
Timer 0 v Timer 1 : Thanh ghi ch nh thi (TMOD)
Thanh ghi iu khin Timer ( TCON)
Cc thanh ghi cha gi tr ca cc b nh thi.
Timer 2 : Thanh ghi T2CON.
Thanh ghi T2MOD
Thanh ghi TH2 v TL2,RCAP2H v RCAP2L
Cc ch hot ng ca Timer:
Timer 0 v Timer 1: Ch 0 : Timer 13 bit.
Ch 1: Timer 16 bit.
Ch 2 : 8 bit t ng np li.
7

Trng H Cng Nghip H Ni

n mn Vi iu khin

Ch 3 : Tch Timer
Timer 2 : Ch thu nhn (Captuer) : 16bit t np li
Ch t np li (Auto-Reload) : 16bit thu nhn
Ch cung cp tc Baud cho cng ni tip.
4.2: Cng ni tip:
Cc thanh ghi cng ni tip: Thanh ghi iu khin cng ni tip (SCON), thanh
ghi m truyn nhn cng ni tip (SBUF).
Cc ch hot ng: Ch 0 v ch 1, ch 2.
ng dng truyn nhn qua cng ni tip v truyn thng a x l.
4.3: Ngt v x l ngt:
Thanh ghi cho php ngt IE ( Interrupt Enable).
Thanh ghi u tin ngt IP.
Cc vector ngt v s hiu ngt.
Ngt
Reset h thng
Bn ngoi 0
Timer 0
Bn ngoi 1
Timer 1
Port ni tip
Timer 2

C
RST
IE0
TF0
IE1
TF1
TI hoc RI
TX2 hoc EXF2

a ch vector
0000H
0003H
000BH
0013H
001BH
0023H
002BH

S hiu
0
1
2
3
4
5

89S52 c 6 ngun ngt:Ngt ngoi INT0.


Ngt ngoi INT1.
Ngt do b Timer 0.
Ngt do b Timer 1.
Ngt do b Timer 2.
Ngt do Port ni tip.
Cc ngt ngoi sy ra khi c mc thp hoc sn xung trn chn INT0 hoc
INT1 ca vi iu khin. y l chc nng chuyn i ca cc bit Port 3 (P3.2
v P3.3).
Ngt cng ni tip xy ra khi c pht (TI) hoc c ngt thu (RI) c t ln
mc1. Ngt pht xy ra khi mt k t nhn xong v ang i trong SBUF
c c.
Cc ngt cng ni tip khc vi cc ngt Timer. C gy ra ngt cng ni tip
khng b xo bng phn cng khi CPU chuyn ti ngt, do c hai ngun ngt
cng ni tip TI v RI. Ngun ngt phi c xc nh trong ISR v c to
ngt s c xo bng phn mm. Cc ngt Timer c ngt c xo bng phn
cng khi CPU hng ti ISR.

Trng H Cng Nghip H Ni

n mn Vi iu khin

II : Gii thiu v IC ghi dch 74HC595:


Cu to v hot ng ca 74HC595

Cu to v hnh dng thc t ca 74HC595


74HC595 l IC ghi dch c ng di dng v 16 chn.Chc nng v
hot ng ca tng chn:
- Chn 8 v chn 16 l chn GND v VCC cp ngun cho IC
- Chn 1,2,3,4,5,6,7,15 l 8 u ra d liu song song
- Chn 9 l chn ra d liu ni tip
- Chn 10 l chn Reset tch cc mc thp. Khi a mc 0 vo chn ny
tt c d liu ca IC b reset v mc 0
- Chn 14 l chn nhn d liu ni tip t bn ngoi
- Chn 13 cho php xut d liu ra tch cc mc thp. Khi hot ng chn
ny thng c ni vi GND
- Chn 11 l chn cho php nhn xung d liu ghi dch vo chn 14
- Chn 12 l chn cho php xut d liu ra, mi khi chn ny c a
ln mc cao, IC li xut d liu qua cc u ra d liu song song.
III : Gii thiu v khi led 3D cube 5x5x5
Led 3D cube 5x5x5 l khi led n sc bao gm 125 led n lin kt vi
nhau c b tr thnh mt ma trn 3 chiu bao gm 5 lp, mi lp gm 25 led
n nh mt ma trn 5x5, c th hiu n gin n ging nh mt khi led c
xp li t 5 led ma trn 5x5. Trong cc Katot ca cc led trn cng mt lp
c ni chung v cc Anot trn cng mt ct c ni chung li. Mun mt
led bt k ti v tr mong mun sng ta ch cn cp ngun cho ct v lp tng
ng
Vic cp in th cao cho cc lp c thc hin bi 5 transistor PNP.
9

Trng H Cng Nghip H Ni

n mn Vi iu khin

Nm Transistor ny c iu khin bi 5 chn IO ca vi iu khin v c


phn cc vng bo ha v vng ngng tng ng vi mc logic 0 v 1 (
ngc mc logic vi chn IO ca vi iu khin).
Vic cp in th thp cho cc ct c thc hin bi 25 chn IO ca vi iu
khin, do khng c transistor nhn dng nn khi khi tnh ton in tr hn
dng cho led phi lu n kh nng nhn dng ca chn IO vi iu khin
(thng s IOL khong 200mA l ti a).

10

Trng H Cng Nghip H Ni

n mn Vi iu khin

PHN HAI
NI DUNG THIT K SN PHM
1: S nguyn l
Mch gm cc thnh phn chnh: IC89S52, LM7805, khi cube 5x5x5,
ULN2803, IC ghi dch 74HC595

S nguyn l
2: Nguyn l hot ng ca mch:
Nguyn l hot ng ca khi led ging nh nguyn l hot ng ca
led ma trn thng, ngha l vo mi thi im ch c 1 lp LED c cp
ngun, v tng ng vi m led ti mi ct s cho ra led sng tng ng.
Vi iu khin 89S52 lm nhim v chuyn i d liu cho khi led t
song song sang ni tip v ghi vo 74HC595 cp m cho cc led sng theo
mong mun to ra cc hiu ng

11

Trng H Cng Nghip H Ni

n mn Vi iu khin

3: Thut ton

4: Code lp trnh
#include<reg52.h>
#include<stdlib.h>
/////////////////////////////////////
sbit DATA = P2^5;
sbit SCK = P2^7;
sbit LACH = P2^6;
sbit L1=P1^0;
sbit L2=P1^1;
sbit L3=P1^2;
sbit L4=P1^3;
sbit L5=P1^4;
unsigned char temp1,temp2,temp3,temp4;
unsigned char i,j;
/////////////////////////////////////////
void delay(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<125;j++);
}
12

Trng H Cng Nghip H Ni

n mn Vi iu khin

////////////////////////
void hienthi(unsigned char x)
{
unsigned int i,temp;
for(i=0;i<8;i++)
{
temp=x;
temp=temp&0x80
if(temp==0x80)
DATA=1; else
DATA=0
x*=2;
SCK=0;
SCK=1;
}}
void xuat()
{
hienthi(temp4);
hienthi(temp3);
hienthi(temp2);
hienthi(temp1);
LACH=0;
LACH=1;
}
/////////////////////////////////////////////////////
void chaychu(unsigned int ms)
{
//chu D
for(j=0;j<ms;j++)
{
temp1=0x00;temp2=0x00,temp3=0xf0;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L2=1;delay(1);L2=0;
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L3=1;delay(1);L3=0;
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x00,temp3=0xf0;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
P2=0;delay(300);
//chu T
for(j=0;j<ms;j++)
{
temp1=0x00;temp2=0x00,temp3=0x40;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x00;temp2=0x00,temp3=0x40;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x00;temp2=0x00,temp3=0x40;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x00;temp2=0x00,temp3=0x40;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x00,temp3=0xf0;temp4=0x01;xuat();L5=1;delay(1);L5=0;
}
P2=0;delay(300);
//so 3
for(j=0;j<ms;j++)
{
13

Trng H Cng Nghip H Ni

n mn Vi iu khin

temp1=0x00;temp2=0x00,temp3=0xf0;temp4=0x01;xuat();L1=1;delay(1);L1=0;
temp1=0x00;temp2=0x00,temp3=0x00;temp4=0x01;xuat();L2=1;delay(1);L2=0;
temp1=0x00;temp2=0x00,temp3=0xf0;temp4=0x01;xuat();L3=1;delay(1);L3=0;
temp1=0x00;temp2=0x00,temp3=0x00;temp4=0x01;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x00,temp3=0xf0;temp4=0x01;xuat();L5=1;delay(1);L5=0;
}
P2=0;delay(300);
//CHU K
for(j=0;j<ms;j++)
{
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L1=1;delay(1);L1=0;
temp1=0x00;temp2=0x00,temp3=0x90;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x00;temp2=0x00,temp3=0x70;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x00;temp2=0x00,temp3=0x90;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L5=1;delay(1);L5=0;
}
P2=0;delay(300);
//so 3
for(j=0;j<ms;j++)
{
temp1=0x00;temp2=0x00,temp3=0xf0;temp4=0x01;xuat();L1=1;delay(1);L1=0;
temp1=0x00;temp2=0x00,temp3=0x00;temp4=0x01;xuat();L2=1;delay(1);L2=0;
temp1=0x00;temp2=0x00,temp3=0xf0;temp4=0x01;xuat();L3=1;delay(1);L3=0;
temp1=0x00;temp2=0x00,temp3=0x00;temp4=0x01;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x00,temp3=0xf0;temp4=0x01;xuat();L5=1;delay(1);L5=0;
}
P2=0;delay(300);
//CHU H
for(j=0;j<ms;j++)
{
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L1=1;delay(1);L1=0;
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L2=1;delay(1);L2=0;
temp1=0x00;temp2=0x00,temp3=0xf0;temp4=0x01;xuat();L3=1;delay(1);L3=0;
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L5=1;delay(1);L5=0;
}
P2=0;delay(300);
//CHU A
for(j=0;j<ms;j++)
{
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L1=1;delay(1);L1=0;
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L2=1;delay(1);L2=0;
temp1=0x00;temp2=0x00,temp3=0xf0;temp4=0x01;xuat();L3=1;delay(1);L3=0;
temp1=0x00;temp2=0x00,temp3=0xa0;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x00,temp3=0x40;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
P2=0;delay(300);
//CHU U
for(j=0;j<ms;j++)
{
14

Trng H Cng Nghip H Ni

n mn Vi iu khin

temp1=0x00;temp2=0x00,temp3=0xe0;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L2=1;delay(1);L2=0;
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L3=1;delay(1);L3=0;
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x00,temp3=0x10;temp4=0x01;xuat();L5=1;delay(1);L5=0;
}
P2=0;delay(300);
//CHU I
for(j=0;j<ms;j++)
{
temp1=0x00;temp2=0x00,temp3=0xf0;temp4=0x01;xuat();L1=1;delay(1);L1=0;
temp1=0x00;temp2=0x00,temp3=0x40;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x00;temp2=0x00,temp3=0x40;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x00;temp2=0x00,temp3=0x40;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x00,temp3=0xf0;temp4=0x01;xuat();L5=1;delay(1);L5=0;
}
P2=0;delay(300);
}
/////////////////////////////////////////////////////
void locxoay(unsigned char ms,unsigned int m)
{
for(i=0;i<m
;i++)
{
//FAMER 1
for(j=0;j<ms;j++)
{
temp1=0x01;temp2=0x00,temp3=0x00;temp4=0x01;xuat();L1=1;delay(1);L1=0;
temp1=0x02;temp2=0x00,temp3=0x80;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x04;temp2=0x00,temp3=0x40;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x08;temp2=0x00,temp3=0x20;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x10;temp2=0x00,temp3=0x10;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
//FAMER 2
for(j=0;j<ms;j++)
{
temp1=0x02;temp2=0x00,temp3=0x80;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x04;temp2=0x00,temp3=0x40;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x08;temp2=0x00,temp3=0x20;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x10;temp2=0x00,temp3=0x10;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x82,temp3=0x00;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
//FAMER 3
for(j=0;j<ms;j++)
{
temp1=0x04;temp2=0x00,temp3=0x40;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x08;temp2=0x00,temp3=0x20;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x10;temp2=0x00,temp3=0x10;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x00;temp2=0x82,temp3=0x00;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x44,temp3=0x00;temp4=0x00;xuat();L5=1;delay(1);L5=0;
15

Trng H Cng Nghip H Ni

n mn Vi iu khin

}
//FAMER 4
for(j=0;j<ms;j++)
{
temp1=0x08;temp2=0x00,temp3=0x20;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x10;temp2=0x00,temp3=0x10;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x00;temp2=0x82,temp3=0x00;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x00;temp2=0x44,temp3=0x00;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x20;temp2=0x00,temp3=0x08;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
//FAMER 5
for(j=0;j<ms;j++)
{
temp1=0x10;temp2=0x00,temp3=0x10;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x00;temp2=0x82,temp3=0x00;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x00;temp2=0x44,temp3=0x00;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x20;temp2=0x00,temp3=0x08;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x01;temp2=0x00,temp3=0x00;temp4=0x01;xuat();L5=1;delay(1);L5=0;
}
//FAMER 6
for(j=0;j<ms;j++)
{
temp1=0x00;temp2=0x82,temp3=0x00;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x00;temp2=0x44,temp3=0x00;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x20;temp2=0x00,temp3=0x08;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x01;temp2=0x00,temp3=0x00;temp4=0x01;xuat();L4=1;delay(1);L4=0;
temp1=0x02;temp2=0x00,temp3=0x80;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
//FAMER 7
for(j=0;j<ms;j++)
{
temp1=0x00;temp2=0x44,temp3=0x00;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x20;temp2=0x00,temp3=0x08;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x01;temp2=0x00,temp3=0x00;temp4=0x01;xuat();L3=1;delay(1);L3=0;
temp1=0x02;temp2=0x00,temp3=0x80;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x04;temp2=0x00,temp3=0x40;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
//FAMER 8
for(j=0;j<ms;j++)
{
temp1=0x20;temp2=0x00,temp3=0x08;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x01;temp2=0x00,temp3=0x00;temp4=0x01;xuat();L2=1;delay(1);L2=0;
temp1=0x02;temp2=0x00,temp3=0x80;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x04;temp2=0x00,temp3=0x40;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x08;temp2=0x00,temp3=0x20;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
}}
///////////////////////////////////////////////////////////////////////
void songbien(unsigned char ms,unsigned int m)
{
16

Trng H Cng Nghip H Ni

n mn Vi iu khin

for(i=0;i<m;i++)
{
//FAMER 1
for(j=0;j<ms;j++)
{
temp1=0x00;temp2=0x00,temp3=0x00;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x00;temp2=0x00,temp3=0x00;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x31;temp2=0xc6,temp3=0x18;temp4=0x01;xuat();L3=1;delay(1);L3=0;
temp1=0x4a;temp2=0x29,temp3=0xa5;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x84;temp2=0x10,temp3=0x42;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
//FAMER 2
for(j=0;j<ms;j++)
{
temp1=0x00;temp2=0x00,temp3=0x00;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x21;temp2=0x84,temp3=0x10;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x42;temp2=0x08,temp3=0x21;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x94;temp2=0x52,temp3=0x4a;temp4=0x01;xuat();L4=1;delay(1);L4=0;
temp1=0x08;temp2=0x21,temp3=0x84;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
//FAMER 3
for(j=0;j<ms;j++)
{
temp1=0x21;temp2=0x84,temp3=0x10;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x42;temp2=0x08,temp3=0x21;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x84;temp2=0x10,temp3=0x42;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x08;temp2=0x21,temp3=0x84;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x10;temp2=0x42,temp3=0x08;temp4=0x01;xuat();L5=1;delay(1);L5=0;
}
//FAMER 4
for(j=0;j<ms;j++)
{
temp1=0x42;temp2=0x08,temp3=0x21;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0xa5;temp2=0x94,temp3=0x52;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x08;temp2=0x21,temp3=0x84;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x10;temp2=0x42,temp3=0x08;temp4=0x01;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x00,temp3=0x00;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
//FAMER 5
for(j=0;j<ms;j++)
{
temp1=0x84;temp2=0x10,temp3=0x42;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x4a;temp2=0x29,temp3=0xa5;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x31;temp2=0xc6,temp3=0x18;temp4=0x01;xuat();L3=1;delay(1);L3=0;
temp1=0x00;temp2=0x00,temp3=0x00;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x00,temp3=0x00;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
//FAMER 6
for(j=0;j<ms;j++)
{
17

Trng H Cng Nghip H Ni

n mn Vi iu khin

temp1=0x08;temp2=0x21,temp3=0x84;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x94;temp2=0x52,temp3=0x4a;temp4=0x01;xuat();L2=1;delay(1);L2=0;
temp1=0x42;temp2=0x08,temp3=0x21;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x21;temp2=0x84,temp3=0x10;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x00;temp2=0x00,temp3=0x00;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
//FAMER 7
for(j=0;j<ms;j++)
{
temp1=0x10;temp2=0x42,temp3=0x08;temp4=0x01;xuat();L1=1;delay(1);L1=0;
temp1=0x08;temp2=0x21,temp3=0x84;temp4=0x00;xuat();L2=1;delay(1);L2=0;
temp1=0x84;temp2=0x10,temp3=0x42;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0x42;temp2=0x08,temp3=0x21;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x21;temp2=0x84,temp3=0x10;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
//FAMER 8
for(j=0;j<ms;j++)
{
temp1=0x00;temp2=0x00,temp3=0x00;temp4=0x00;xuat();L1=1;delay(1);L1=0;
temp1=0x10;temp2=0x42,temp3=0x08;temp4=0x01;xuat();L2=1;delay(1);L2=0;
temp1=0x08;temp2=0x21,temp3=0x84;temp4=0x00;xuat();L3=1;delay(1);L3=0;
temp1=0xa5;temp2=0x94,temp3=0x52;temp4=0x00;xuat();L4=1;delay(1);L4=0;
temp1=0x42;temp2=0x08,temp3=0x21;temp4=0x00;xuat();L5=1;delay(1);L5=0;
}
}}
///////////////////////////////////////////////////////////////////////
void diemsang(unsigned char ms,unsigned int m)
{
for(i=0;i<m;i++)
{
//FAMER 1
temp1=0x00;temp2=0x10;temp3=0x00;temp4=0x00;xuat();L3=1;delay(ms);L3=0;
//FAMER 2
temp1=0x40;temp2=0x01;temp3=0x05;temp4=0x00;xuat();L2=L4=1;delay(ms);L2
=L4=0;
//FAMER 3
temp1=0x11;temp2=0x00;temp3=0x10;temp4=0x01;xuat();L1=L5=1;delay(ms);L1
=L5=0;
//FAMER 4
temp1=0x40;temp2=0x01;temp3=0x05;temp4=0x00;xuat();L2=L4=1;delay(ms);L2
=L4=0;
//FAMER 5
temp1=0x00;temp2=0x10;temp3=0x00;temp4=0x00;xuat();L3=1;delay(ms);L3=0;
}}
///////////////////////////////////////////////////////////////////////
void pittong(unsigned int ms,unsigned int m)
{
for(i=0;i<m;i++)
{
//FAMER 1
18

Trng H Cng Nghip H Ni

n mn Vi iu khin

temp1=0x00;temp2=0x00;temp3=0xf0;temp4=0x01;xuat();L1=L2=L3=L4=L5=1;de
lay(ms);
//FAMER 2
temp1=0x00;temp2=0x80;temp3=0x0f;temp4=0x00;xuat();delay(ms);
//FAMER 3
temp1=0x00;temp2=0x7f;temp3=0x00;temp4=0x00;xuat();delay(ms);
//FAMER 4
temp1=0xe0;temp2=0x03;temp3=0x00;temp4=0x00;xuat();delay(ms);
//FAMER 5
temp1=0x1f;temp2=0x00;temp3=0x00;temp4=0x00;xuat();delay(ms);
//FAMER 6
temp1=0xe0;temp2=0x03;temp3=0x00;temp4=0x00;xuat();delay(ms);
//FAMER 7
temp1=0x00;temp2=0x7f;temp3=0x00;temp4=0x00;xuat();delay(ms);
//FAMER 8
temp1=0x00;temp2=0x80;temp3=0x0f;temp4=0x00;xuat();delay(ms);L1=L2=L3=L
4=L5=0;
}}
///////////////////////////////////////////////////////////////////////
void songbien2(unsigned int ms,unsigned int m)
{
L1=L2=L3=L4=L5=1;
for(i=0;i<m;i++)
{
//FAMER 1
temp1=0x41;temp2=0x10,temp3=0x11;temp4=0x00;xuat();delay(ms);
//FAMER 2
temp1=0x22;temp2=0x08,temp3=0x82;temp4=0x00;xuat();delay(ms);
//FAMER 3
temp1=0x41;temp2=0x10,temp3=0x04;temp4=0x01;xuat();delay(ms);
//FAMER 4
temp1=0x82;temp2=0x20,temp3=0x88;temp4=0x00;xuat();delay(ms);
//FAMER 5
temp1=0x04;temp2=0x41,temp3=0x44;temp4=0x00;xuat();delay(ms);
//FAMER 6
temp1=0x08;temp2=0x22,temp3=0x22;temp4=0x00;xuat();delay(ms);
//FAMER 7
temp1=0x10;temp2=0x11,temp3=0x11;temp4=0x00;xuat();delay(ms);
//FAMER 8
temp1=0x88;temp2=0x88,temp3=0x20;temp4=0x00;xuat();delay(ms);
}
L1=L2=L3=L4=L5=0;}
/////////////////////////////////////////////////////////////////////////
void nuocdang(unsigned int ms,unsigned int m)
{
for(i=0;i<m;i++)
{
//FAMER 1
temp1=0xff;temp2=0xff;temp3=0xff;temp4=0x01;xuat();
L1=1;delay(ms);L1=0;
19

Trng H Cng Nghip H Ni

n mn Vi iu khin

//FAMER 2
L2=1;delay(ms);L2=0;
//FAMER 3
L3=1;delay(ms);L3=0;
//FAMER 4
L4=1;delay(ms);L4=0;
//FAMER 5
L5=1;delay(ms);L5=0;
//FAMER 6
L4=1;delay(ms);L4=0;
//FAMER 7
L3=1;delay(ms);L3=0;
//FAMER 8
L2=1;delay(ms);L2=0;
}
}
//////////////////////////////////////////////////////////////////////
void main()
{
P2=0;
delay(1000);
chaychu(100);
while(1)
{
locxoay(12,10);
diemsang(100,4);
nuocdang(80,3);
pittong(80,3);
songbien2(100,10);
songbien(16,10);
}}

PHN BA
NG DNG V HNG PHT TRIN
1: Hng pht trin
Vi khi led 5x5x5 ta c th xy dng mch theo 2 phng php khc
ngoi phng php s dng IC ghi dch 74HC595. Th nht l tn dng chn
vi iu khin 89S52 (c sn 32 chn), trong c 25 chn iu khin ct v 5
chn iu khin lp nhng phng php ny c nhc im l tn chn In/Out
ca vi iu khin, khng thc hin c cc cng vic khc nu cn. Th hai l
phng php qut 3 bt kt hp transistor lm kha in t, phng php ny
d qut nhng code lp trnh ln, khng thch hp vi vi iu khin 89S52 c
b nh thp (8kB), ta c th m rng phng php ny vi cc h vi iu khin
khc c b nh ln v ph bin hin nay nh PIC, AVR
Vic xy dng c khi led 5x5x5 chng ta c th pht trin ln vi
cc khi led c kch thc ln hn nh 8x8x8 hoc 16x16x16.
2: ng dng thc t:
Rt thch hp lm n nhy trong cc qun bar, nh hng to cc hiu
ng p mt
20

You might also like