Professional Documents
Culture Documents
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
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
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!!!
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.
n mn Vi iu khin
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
n mn Vi iu khin
n mn Vi iu khin
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
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
n mn Vi iu khin
n mn Vi iu khin
10
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
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
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
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
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
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
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
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
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
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