You are on page 1of 19

BO CO N

TI
NG H CASIO HIN TH BNG GLCD

NHM 2
ng Sn Tng
Hunh Nguyn Phan Sinh
Vng Tn Pht

50903185
50902251
50901922
Gio vin hng dn: V Trng Thin

MC LC
Contents
BI BO CO NG H CASIO ..................................................................................................................... 3
1.

2.

THIT K NIM...................................................................................................................................... 3
1.1

Phn tch ti ....................................................................................................................................... 3

1.2

Thit k nim: ...................................................................................................................................... 3

1.2.1

Mi trng thc hin: C ................................................................................................................. 3

1.2.2

M t h thng ................................................................................................................................ 3

THIT K LUN L................................................................................................................................... 5


2.1

Thit k logic ca h thng ..................................................................................................................... 5

Chng trnh: Proteus ................................................................................................................................... 5


2.2

3.

Cc moun ca h thng ........................................................................................................................ 5

2.2.1

Vi iu khin .................................................................................................................................. 5

2.2.2

H thng nt bm iu khin ......................................................................................................... 6

2.2.3

H thng mch to xung ................................................................................................................. 6

2.2.4

GLCD .............................................................................................................................................. 7

HIN THC ................................................................................................................................................. 7


3.1

Phn cng: .............................................................................................................................................. 7

3.1.1 Graphic LCD 128x64 ............................................................................................................................. 7


3.2

4.

Phn mm: ............................................................................................................................................ 13

3.2.1

Mode hin th gi .......................................................................................................................... 13

3.2.2

Mode chnh gi.............................................................................................................................. 14

3.2.3

Mode hn gi ................................................................................................................................. 16

3.2.4

Mode ng h th thao.................................................................................................................. 18

KT LUN ................................................................................................................................................. 19
4.1

H thng t c nhng yu cu ca bi a ra ..................................................................... 19

4.2

Nhng iu cha hon thin ................................................................................................................ 19

4.3

C th pht trin ................................................................................................................................... 19

4.4

Kinh nghim bn thn sau khi lm ti ............................................................................................ 19

BI BO CO NG H CASIO
1. THIT K NIM
1.1 Phn tch ti
Tn :
Thit k ng h Casio:
+ Vi iu khin la chn: 8951 v quen thuc vi sinh vin
+ Hin th ra GLCD
+ ng h c chc nng ging vi ng h Casio F98

Chc nng hin th ngy thng, gi, pht, giy


Chc nng hn gi, bo chung khi ti gi hn
Chc nng chnh gi
Chc nng bm gi th thao

1.2 Thit k nim:


1.2.1 Mi trng thc hin: C
1.2.2 M t h thng
o ng h c 4 trng thi th hin 4 chc nng
o C 2 nt nhn dng chuyn trng thi v chc nng tng ng vi tng trng thi
o Trng thi 1: ng h hin th thi gian
ng h c 3 ch hin th: Ch , ngy thng v thi gian
Nt bm mt dng chuyn ch
Nt bm 2 dng thc hin cc chc nng trong cc ch
Thi gian l ch 12h ting, c am v pm

Trng thi 2: Chnh gi


ng h c 3 ch hin th: Ch , ngy thng v thi gian
Nt bm mt dng chuyn sang ch khc hoc tng gi
Nt bm 2 dng bt u v chuyn sang tng v tr gi pht giy
Thi gian l ch 12h ting, c am v pm
Hn ch vic chnh sai ngy (vd: 31-4 th s t ng thnh 1-5)

Trng thi 3: Hn gi
ng h c 3 ch hin th: Ch , ngy thng v thi gian
Nt bm mt dng chuyn sang ch khc hoc tng gi
Nt bm 2 dng bt u v chuyn sang tng v tr gi pht giy
Thi gian l ch 12h ting, c am v pm
Hn ch vic chnh sai ngy (vd: 31-4 th s t ng thnh 1-5)

Trng thi 4: ng h th thao


ng h c 2 ch hin th: Ch v thi gian
Nt bm mt dng chuyn sang ch khc hoc reset
Nt bm 2 dng bt u bt u v dng thi gian
Thi gian tnh theo miligiay, m t 1 cho ti 100 pht

2. THIT K LUN L
2.1 Thit k logic ca h thng
Chng trnh: Proteus

2.2 Cc moun ca h thng


2.2.1 Vi iu khin
a. Chc nng:
Thc hin chc nng x l ca ng h (m gi, xut tn hiu,).
Nhn v x l tn hiu t cc cng tc v switch.
b. Kt ni ti cc modun khc:
Kt ni vi Graphic LCD thng qua cc chn P2(chn d liu) , P3.2 P3.6 (chn iu
khin).
Kt ni vi mch to xung thng qua chn XTAL1 v XTAL2.
Kt ni vi 3 nt nhn qua cc chn P1.0 P1.2, kt ni vi switch qua chn P1.4.

2.2.2 H thng nt bm iu khin


a. Chc nng: iu khin vic x l d liu ca 89C51.
b. Kt ni ti cc modun khc: Kt ni vi cc chn P1.0 P1.2 & P1.4 ca 89C51.

2.2.3 H thng mch to xung


a. Chc nng: To xung dao ng.
b. Kt ni ti cc modun khc: Kt ni vo chn XTAL1 v XTAL2 ca 89C51.

2.2.4 GLCD
a. Chc nng: Hin th gi v nhng yu cu theo mun ca ngi lp trnh.
b. Kt ni ti cc modun khc: Kt ni n cc chn P2(chn d liu) , P3.2 P3.6 (chn
iu khin) ca 89C51.

3. HIN THC
3.1 Phn cng:
3.1.1 Graphic LCD 128x64
Graphic LCD (gi tt l GLCD) loi chm khng mu l cc loi mn hnh tinh th lng nh dng
hin th ch, s hoc hnh nh. Khc vi Text LCD, GLCD khng c chia thnh cc hin th
cc m ASCII v GLCD khng c b nh CGRAM (Character Generation RAM). GLCD 128x64 c
128 ct v 64 hng tng ng c 128x64=8192 chm (dot). Mi chm tng ng vi 1 bit d liu, v
nh th cn 8192 bits hay 1024 bytes RAM cha d liu hin th y mi 128x64 GLCD. Ty theo
loi chip iu khin, nguyn l hot ng ca GLCD c th khc nhau, trong bi ny ti gii thiu loi
GLCD c iu khin bi chip KS0108 ca Samsung, c th ni GLCD vi KS0108 l ph bin nht
trong cc loi GLCD loi ny (chm, khng mu).

Hnh 1. Graphic LCD 128x64.


Chip KS0108 ch c 512 bytes RAM (4096 bits = 64x64) v v th ch iu khin hin th c 64
dng x 64 ct. iu khin GLCD 168x64 cn 2 chip KS0108, v thc th trong cc loi GLCD c 2
chip KS0108, GLCD 128x64 do tng t 2 GLCD 64x64 ghp li. Chng ta s ln lt kho st
s chn, cu trc b nh v nguyn l hot ng ca GLCD, chip KS0108 trong phn tip theo.
S chn
Cc GLCD 128x64 dng KS0108 thng c 20 chn trong ch c 18 chn l thc s iu khin
trc tip GLCD, 2 chn (thng l 2 chn cui 19 v 20) l 2 chn Anode v Cathode ca LED nn.
Trong 18 chn cn li, c 4 chn cung cp ngun v 14 chn iu khin+d liu. Khc vi cc Text
LCD HD44780U, GLCD KS0108 khng h tr ch giao tip 4 bit, do bn cn dnh ra 14 chn
iu khin 1 GLCD 128x64. S chn ph bin ca GLCD 128x64 c m t trong bng 1.
Bng 1. S chn GLCD GDM-12864-04.

Ch l trn mt s GLCD, th t cc chn c th khc (nh GLCD WG12864A2) nhng s


lng v chc nng chn th khng i. Hnh 2 m t cch kt ni GLCD vi ngun v mch iu
khin.

Hnh 2. Kt ni GLCD.
Chn VSS c ni trc tip vi GND, chn VDD ni vi ngun +5V, mt bin tr khong 20K
c dng chia in p gia Vdd v Vee cho chn Vo, bng cch thay i gi tr bin tr chng ta
c th iu chnh tng phn ca GLCD. Cc chn iu khin RS, R/W, EN v cc ng d liu
c ni trc tip vi vi iu khin. Ring chn Reset (RST) c th ni trc tip vi ngun 5V.
EN (Enable): cho php mt qu trnh bt u, bnh thng chn EN c gi mc thp, khi
mt thc hin mt qu trnh no (c hoc ghi GLCD), cc chn iu khin khc s c ci t
sn sng, sau kch chn EN ln mc cao. Khi EN c ko ln cao, GLCD bt u lm thc hin
qu trnh c yu cu, chng ta cn ch mt khong thi gian ngn cho GLCD c hoc gi d liu.
Cui cng l ko EN xung mc thp kt thc qu trnh v cng chun b chn EN cho qu trnh
sau ny.
RS (Register Select): l chn la chn gia d liu (Data) v lnh (Instruction), v th m trong
mt s ti liu bn c th thy chn RS c gi l chn DI (Data/Instruction Select). Chn RS=1 bo
rng tn hiu trn cc ng DATA (D0:7) l d liu ghi hoc c t RAM ca GLCD. Khi RS=0, tn
hiu trn ng DATA l mt m lnh (Instruction).
RW (Read/Write Select): chn la gia vic c v ghi. Khi RW=1, chiu truy cp t GLCD ra
ngoi (GLCD->AVR). RW=0 cho php ghi vo GLCD. Giao tip vi GLCD ch yu l qu trnh ghi
(AVR ->GLCD), ch duy nht trng hp c d liu t GLCD l c bit BUSY v c d liu t
RAM. c bit BUSY th chng ta kho st cho Text LCD, bit ny bo GLCD c ang bn hay
khng, vic c ny s c dng vit hm wait_GLCD. c d liu t RAM ca GLCD l mt
kh nng mi m Text LCD khng c, bng vic c ngc t GLCD vo AVR, chng ta c th thc
hin nhiu php logic hnh (hay mt n, mask) lm cho vic hin th GLCD thm th v.
CS2 v CS1 (Chip Select): nh ti trnh by trong phn trn, mi chip KS0108 ch c kh
nng iu khin mt GLCD c kch thc 64x64, trn cc GLCD 128x64 c 2 chip KS0108 lm vic
cng nhau, mi chip m nhim mt na LCD, 2 chn CS2 v CS1 cho php chn mt chip KS0108
lm vic. Thng thng nu CS2=0, CS1=1 th na tri c kch hot, ngc li khi CS2=1,
CS1=0 th na phi c chn. Chng ta s hiu r hn cch phi hp lm vic ca 2 na GLCD trong
phn kho st b nh ca LCD.
T chc b nh
Chip KS0108 c mt loi b nh duy nht l RAM, khng c b nh cha b font hay cha m
font t to nh chip HD44780U ca Text LCD. V vy, d liu ghi vo RAM s c hin th trc tip
trn GLCD. Mi chip KS0108 c 512 bytes RAM tng ng vi 4096 chm trn mt na (64x64)
LCD. RAM ca KS0108 khng cho php truy cp tng bit m theo tng byte, iu ny c ngha l mi
ln chng ta vit mt gi tr vo mt byte no trn RAM ca GLCD, s c 8 chm b tc ng, 8
chm ny nm trn cng 1 ct. V l do ny, 64 dng GLCD thng c chia thnh 8 pages, mi
page c cao 8 bit v rng 128 ct (c 2 chip gp li). Hnh 3 m t b mt mt GLCD v cng l
cch sp xp RAM ca cc chip KS0108.

Hnh 3. T chc ca RAM.


T chc RAM ca 2 chip KS0108 tri v phi hon ton tng t, vic c hay ghi vo RAM ca
2 chip cng c thc hin nh nhau. Chng ta s chn na tri GLCD kho st. Nh bn thy trn
hnh 3, 64 dng t trn xung di c chia thnh 8 dy m ta gi l 8 pages. Page trn cng l
page 0 v page di cng la page 7. Trong cc GLCD, page cn c gi l a ch X (X address),
hay ni cch khc X=0 l a ch ca page trn cng, tng t nh th, X=7 l a ch ca page di
cng. Mi page cha 64 ct (ch xt 1 chip KS0108), mi ct l mt byte RAM 8 bit, mi bit tng
ng vi 1 chm trn LCD, bit c trng s thp (LBS - tc bit D0 nh trong hnh 3) tng ng vi
chm trn cao nht. Bit c trng s cao nht (MBS - tc bit D7 nh trong hnh 3) tng ng vi chm
thp nht trong 1 page. Th t cc ct trong 1 page gi l a ch Y (Y address), nh th ct u tin
c a ch Y = 0 trong khi ct cui cng c a ch Y l 63. Bng cch phi hp a ch X v a ch Y
chng ta xc nh c v tr ca byte cn c hoc ghi. Chip KS0108, tt nhin, s h tr cc lnh di
chuyn n a ch X v Y ghi hay c RAM. Hy quan st hnh 4 xem cch m mt ch ci a
c hin th trn GLCD.

Hnh 4. Hin th ch ci a trn GLCD.


Trong cch hin th hnh 4, ch a ch nm trong page 0, tc X=0. Mun hin th ch ci a
chng ta cn ghi vo cc ct (a ch Y) ca page 0 ln lt cc gi tr nh sau: 0, 228, 146, 74, 252 v
128., xem bng bn di.

10

Tp lnh chip KS0108


Bng 2 tm tt cc lnh ca chip KS0108.

So vi HD44780U ca Text LCD, lnh cho KS0108 ca GLCD n gin v t hn v v th vit


chng trnh iu khin GLCD cng tng i d hn Text LCD. C tt c 7 lnh (Instruction) c th
giao tip vi KS0108. Ti s ln lt gii thch ngha v cch s dng ca tng lnh.
- Display ON/OFF Hin th GLCD: lnh ny cho php GLCD hin th ni dung trn RAM ra
b mt GLCD. vit lnh ny cho GLCD, 2 chn RS v RW cn c ko xung mc thp
(RS=0: y l Instrucion, RW=0: AVR->GLCD). M lnh (code) c cha trong 7 bit cao (D7:1) v
bit D0 cha thng s. Quan st bng 2, d thy m lnh nh phn cho Display ON/OFF l 0011111x
(0x3E+x) trong x=1: cho php GLCD hin th, x=0: tt hin th.
- Set Address chn a ch: ng hn y l lnh chn ct hay chn a ch Y. Hai bit D7 v D6
cha m lnh (01000000=0x40=64) v 6 bit cn li cha ch s ca ct mun di chuyn n. Ch l
mi na GLCD c 64 ct nn cn 6 bit cha ch s ny (26=64). Vy lnh ny c dng 0x40+Y. V
d nu chng ta mun di chuyn n ct 36 chng ta ghi vo GLCD m lnh: 0x40+36. Hai chn RS
v RW c gi mc thp khi thc hin lnh ny.
- Set Page chn trang: lnh cho php chn page (hay a ch X) cn di chuyn n, do GLCD ch
c 8 pages nn ch cn 3 bit cha a ch page. M lnh cho lnh ny c dng 0xB8+X. Trong
bin X l ch s page cn di chuyn n. Hai chn RS v RW c gi mc thp khi thc hin lnh
ny.
- Display Start Line chn line u tin: hay cn gi l lnh cun, lnh ny cho php di
chuyn ton b hnh nh trn GLCD (hay RAM) ln pha trn mt s dng no , chng ta gi l
LOffset. S lng LOffset c th t 0 n 63 nn cn 6 bit cha gi tr ny. M lnh Display Start Line
c dng 0xC0+LOffset. Hai chn RS v RW c gi mc thp khi thc hin lnh ny. Khi di
11

chuyn GLCD ln pha trn, phn d liu pha trn b che khut s cun xung pha di. Hnh 5 l
mt v d cun GLCD ln 20 dng.

- Status Read c trng thi GLCD: y l mt trong 2 lnh c t GLCD. Cng ging nh vi
Text LCD, lnh c trng thi GLCD ch yu xt bit BUSY (bit th 7) xem GLCD c ang bn
hay khng, lnh ny s c dng vit mt hm wait_GLCD ch cho n khi GLCD rnh. V y
l lnh c t GLCD nn chn RW phi c set ln mc 1 trc khi thc hin, chn RS vn mc
thp (c Instruction).
- Write Display Data ghi d liu cn hin th vo GLCD hay RAM: v y l 1 lnh ghi d liu
hin th nn chn RS cn c set ln 1 trc khi thc hin, chn RW gi mc 0. Lnh ny cho php
ghi mt byte d liu vo RAM ca KS0108 v cng l d liu s hin th ln GLCD ti v tr hin hnh
ca 2 con tr a ch X v Y. 8 bit d liu ny s tng ng vi 8 chm trn ct Y page X. Ch l
sau lnh Write Display Data, a ch ct Y t ng c tng ln 1 v v th nu c mt d liu mi
c ghi, d liu mi s khng ln d liu c. Vic tng t ng a ch Y rt c li cho vic ghi
d liu lin tip, n gip gim thi gian set li a ch ct Y. Sau khi thc hin ghi ct Y=63 (ct
cui cng trong 1 page, i vi 1 chip KS0108), Ys v 0.
- Read Display Data c d liu hin th t GLCD (cng l d liu t RAM ca KS0108): lnh
c ny mi so vi Text LCD, n cho php chng ta c ngc 1 byte d liu t RAM ca KS0108 ti
v tr hin hnh v AVR. Sau khi c c gi tr ti v tr hin hnh, chng ta c th thc hin cc
php Logic nh o bit, or hay andlm tng kh nng thao tc hnh nh. Trc khi thc hin c
chng ta cn di chuyn n v tr mun c bng 2 lnh set a ch X v Y, sau khi c gi tr a ch
page X v ct Y khng thay i, do nu c tip m khng di chuyn a ch th vn thu c gi
tr c.
Trnh t giao tip
So vi Text LCD th vic giao tip vi GLCD d hn nhiu v GLCD c t Instruction hn, GLCD
ch c mt loi b nh l RAM tng ng trc tip vi mn hnh hin th, GLCD khng c cursor nn
khng cn set cursor, GLCD ch h tr giao tip 8 bit nn khng cn bn tm chn mode, qu trnh
khi ng cho GLCD v th rt n gin bng cch gi lnh DISPLAY ON/OFF. Trong hnh 5 ti
trnh by qu trnh khi ng v s dng GLCD.

Hnh 5. Trnh t giao tip vi GLCD.

12

Sau khi khi ng GLCD bng hm DISPLAY ON chng ta c th set a ch X v Y ghi d


liu, thm ch c th ghi d liu m khng cn set X, Y. Tuy nhin, cn nhc li l c n 2 chip
KS0108 trn GLCD 128x64, v vy tt c cc qu trnh u phi thc hin cho 2 chip.

3.2 Phn mm:

3.2.1

Mode hin th gi
//Bt u mode hin th bng 1 vng lp thi gian
for (thoigian = 0; thoigian <43200; thoigian++)
{

//Xa trng mn hnh trc khi bt u


if (SW0 == 0){count=1;}
ShowString (0, 0, "
");
ShowString (0, 0, "Hien Thi");

//Chuyen mode
// Dong nay dung de xoa trang man hinh

//iu kin ngy thng


if (ngay > 31) {
if (thang==1 || thang==3 || thang==5|| thang==7 || thang==8 || thang==10) {ngay = 1; thang++;}
else if (thang==12) {ngay = 1; thang = 1;}
}
if (ngay > 30)
if (thang==4 || thang==6 || thang==9 || thang==11) {ngay = 1; thang++;}
if (ngay > 28 && thang == 2) {ngay = 1; thang = 3;}

//Hin th ngy thng


ShowChar(1, 11, '0' + ngay/10);
ShowChar(1, 12, '0' + ngay%10);
ShowChar(1, 13, '-');

13

ShowChar(1, 14, '0' + thang/10);


ShowChar(1, 15, '0' + thang%10);
SW3 = 0;
if (mmm == 0) ShowString (3, 14, "AM");
else ShowString (3, 14, "PM");
ShowString (2, 0, "
");
if (SW0 == 0){count=1;}

//Chuyen mode

SW3 = 0;
//Chuong bao = 0

//Hin th gi pht giy


ShowString (2, 0, "

");

ShowChar(3, 5, '0' + (thoigian/36000));


ShowChar(3, 6, '0' + (thoigian/3600)%10);
ShowChar(3, 8, '0' + ((thoigian/60)%60)/10);
ShowChar(3, 9, '0' + ((thoigian/60)%60)%10);
ShowChar(3, 11, '0' + ((thoigian%60)/10));
ShowChar(3, 12, '0' + ((thoigian%60)%10));
if (SW0 == 0){count=1;}

//Chuyen mode

------------------------------------------------------------

3.2.2

Mode chnh gi

while (count == 1) {
if (SW0 == 0)

count=2;

ShowString (0, 0, "

// chuyen mode
");

ShowString(0, 0, "Chinh Gio");


ShowChar(3, 11, ' ');
ShowChar(3, 12, ' ');
if (SW0 == 0)

count=2;

// chuyen mode

if (vitriThang == 0)
ShowChar (2, vitriNgay, '*');
else if (vitriNgay == 0)
ShowChar (0, vitriThang, '*');
if (SW0 == 0) count=2;

// Bt u chuyn v tr bng cch nhn nt START


if (START == 0) {
ShowChar (2, vitriNgay, ' ');
ShowChar (0, vitriThang, ' ');

Chuyen vi tri lien tuc

if (vitriNgay == 9) {vitriNgay = 6;vitriThang=0;}


else if (vitriNgay == 6) {vitriThang=11;vitriNgay=0;}
else if (vitriThang ==11) {vitriThang=12;vitriNgay=0;}

14

else if (vitriThang ==12) {vitriThang=14;vitriNgay=0;}


else if (vitriThang ==14) {vitriThang=15;vitriNgay=0;}
else {vitriNgay = 9;vitriThang=0;}
if (vitriThang == 0)
ShowChar (2, vitriNgay, '*');
else if (vitriNgay == 0)
ShowChar (0, vitriThang, '*');
} // end of if (START ==0)
if (SW0 == 0)count=2;
if (tt == 1) dhtt = dhtt + 100;

// chuyen mode
// dk cho dong ho the thao

// Thay i gi tr bng cch nhn phm RESET


if (RESET == 0) {

// Ch ny thay i gi tr kim gi hng n v (ghi nhm bin thnh vitriNgay)


if (vitriNgay == 6) {
thoigian = thoigian + 3600;
if (thoigian >= 43200) {
thoigian = thoigian - 43200;
mmm = (mmm+1)%2; //day = day + 0.5;
if (mmm == 0) {ShowString (3, 14, "AM"); ngay=ngay+1;}
else ShowString (3, 14, "PM");
}
}

// Ch ny thay i gi tr kim pht hng n v (ghi nhm bin thnh vitriNgay)


else if (vitriNgay == 9) {
thoigian = thoigian + 60;
if (thoigian >= 43200) {
thoigian = thoigian - 43200;
mmm = (mmm+1)%2; //day = day + 0.5;
if (mmm == 0) {ShowString (3, 14, "AM"); ngay=ngay+1;}
else ShowString (3, 14, "PM");
}
}
// Ch ny thay i v tr kim ngy hng chc (ghi nhm bin thnh vitriThang)
else if (vitriThang == 11) {
ngay+=10;
if (ngay > 31) {
if (thang==1 || thang==3 || thang==5|| thang==7 || thang==8 || thang==10)
ngay = 1;
else if (thang==12) ngay = 1; }
if (ngay > 30){
if (thang==4 || thang==6 || thang==9 || thang==11) ngay = 1;
if (ngay > 28 && thang == 2) {ngay = 1; thang = 3;}
}

// Ch ny thay i v tr kim ngy hng n v (ghi nhm bin thnh vitriThang)


15

else if (vitriThang == 12) {


ngay+=1;
if (ngay > 31) {
if (thang==1 || thang==3 || thang==5|| thang==7 || thang==8 || thang==10)
ngay = 1;
else if (thang==12) ngay = 1; }
if (ngay > 30)
if (thang==4 || thang==6 || thang==9 || thang==11) ngay = 1;
if (ngay > 28 && thang == 2) {ngay = 1; thang = 3;}
}

// Ch ny thay i v tr kim thng hng chc


else if (vitriThang == 14) {
thang+=10;
if (thang > 12) thang=1;
}

// Ch ny thay i v tr kim thng hng n v


else if (vitriThang == 15) {
thang+=1;
if (thang > 12) thang=1;
}

//Hin th thi gian sau khi thay i


ShowChar(3, 5, '0' + (thoigian/36000));
ShowChar(3, 6, '0' + (thoigian/3600)%10);
ShowChar(3, 8, '0' + ((thoigian/60)%60)/10);
ShowChar(3, 9, '0' + ((thoigian/60)%60)%10);
ShowChar(1, 11, '0' + ngay/10);
ShowChar(1, 12, '0' + ngay%10);
ShowChar(1, 13, '-');
ShowChar(1, 14, '0' + thang/10);
ShowChar(1, 15, '0' + thang%10);
} //End of Reset
if (SW0 == 0)

count=2;

delay(20);
thoigian++;
if (tt == 1) dhtt = dhtt + 100;
}// End of mode Hn gi
if (thoigian/60 == hengio/60)

// Luon check do hen gio ngay tai bat cu mode nao

Buzz();
------------------------------------------------------------

3.2.3

Mode hn gi

16

// Trong mode ny ta dng bin hengio l bin thi gian chnh hin th, khng phi bin thoigian
while (count == 2) {
delay(30);
if (SW0==0) count = 3;
ShowString(0, 0, "

//Chuyen mode
");

ShowString(0, 0, "Hen Gio");


ShowChar(3, 5, '0' + (hengio/36000));
ShowChar(3, 6, '0' + (hengio/3600)%10);
ShowChar(3, 8, '0' + ((hengio/60)%60)/10);
ShowChar(3, 9, '0' + ((hengio/60)%60)%10);
ShowChar(3, 11, ' ');
ShowChar(3, 12, ' ');
ShowChar (2, vitriNgay, '*');
if (SW0==0) count = 3;

//Chuyen mode

// Chnh v tr gi ging nh mode chnh gi hn gi bo thc


if (START == 0) {
ShowChar (2, vitriNgay, ' ');
if (vitriNgay == 6) vitriNgay = 9;
else vitriNgay = 6;
ShowChar (2, vitriNgay, '*');
}
if (SW0==0) count = 3;

//Chuyen mode

if (RESET == 0) {
if (vitriNgay == 6) {
hengio = hengio + 3600;
if (hengio >= 43200) {
hengio = hengio - 43200;
mmm1 = (mmm1+1)%2;
if (mmm1 == 0) ShowString (3, 14, "AM");
else ShowString (3, 14, "PM");
ShowChar(3, 5, '0' + (hengio/36000));
ShowChar(3, 6, '0' + (hengio/3600)%10);
ShowChar(3, 8, '0' + ((hengio/60)%60)/10);
ShowChar(3, 9, '0' + ((hengio/60)%60)%10);}
}
else if (vitriNgay == 9) {
hengio = hengio + 60;
if (hengio >= 43200) {
hengio = hengio - 43200;
mmm1 = (mmm1+1)%2;
if (mmm1 == 0) ShowString (3, 14, "AM");
else ShowString (3, 14, "PM");
ShowChar(3, 5, '0' + (hengio/36000));
ShowChar(3, 6, '0' + (hengio/3600)%10);
ShowChar(3, 8, '0' + ((hengio/60)%60)/10);
ShowChar(3, 9, '0' + ((hengio/60)%60)%10);}
}
}

17

if (tt == 1) dhtt = dhtt + 100;


if (SW0==0) count = 3;

//Chuyen mode

delay(20);thoigian++;
}// End of mode Hn gi
if (thoigian/60 == hengio/60)
Buzz();

// Luon check do hen gio ngay tai bat cu mode nao


------------------------------------------------------------

3.2.4

Mode ng h th thao

while (count ==3) {


delay (30);
if (START == 0) {tt = 1;aaa=150;}

// aaa la de lam cham viec bam start de dung dong

ho
if (SW0==0) count = 0;
if (RESET == 0) dhtt = 0;
ShowString (0, 0, "
");
ShowString (2, 0, "
");
ShowString (0, 0, "Dong Ho The Thao");
ShowChar (3, 5, '0' + dhtt/60000);
ShowChar (3, 6, '0' + (dhtt/6000)%10);
ShowChar (3, 8, '0' + ((dhtt%6000)/100)/10);
ShowChar (3, 9, '0' + ((dhtt%6000)/100)%10);
ShowChar (3, 11, '0' + (dhtt%100)/10);
ShowChar (3, 12, '0' + (dhtt%100)%10);
ShowString(3, 13," ");
if (START == 0) {tt = 1;aaa=150;}
// bat dau chay dong ho
if (SW0==0) count = 0;
// Chuyen mode
if (START == 0) {tt = 1;aaa=150;}

// bat dau chay dong ho

if (RESET == 0) dhtt = 0;

// Khi bm START s bt u thi gian chy


if (tt == 1) for(dhtt = dhtt; dhtt < 60000; dhtt++) {

//maximum time = 10

phut
ShowChar (3, 5, '0' + dhtt/60000);
ShowChar (3, 6, '0' + (dhtt/6000)%10);
ShowChar (3, 8, '0' + ((dhtt%6000)/100)/10);
ShowChar (3, 9, '0' + ((dhtt%6000)/100)%10);
ShowChar (3, 11, '0' + (dhtt%100)/10);
ShowChar (3, 12, '0' + (dhtt%100)%10);

18

//--------------------------------------delay(1);
if (aaa!=0) aaa--;
if (dhtt%6 == 0) dhtt++;
//------------------------------------------if(dhtt%100==0)thoigian++;
if (RESET == 0) {dhtt = 0;}
if(aaa==0){
if (START == 0) {tt = 0;
break;} }
}
if (SW0==0) count = 0;
delay(88);thoigian++;
if (RESET == 0) dhtt = 0;
if (START == 0) {tt = 1;aaa=150; }
if (thoigian/60 == hengio/60) { // Luon check do hen gio ngay tai bat cu mode nao
Buzz();
}
}

4. KT LUN
4.1 H thng t c nhng yu cu ca bi a ra
Hin th thnh cng trn GLCD
Chc nng hin th ngy thng, gi, pht, giy
Chc nng hn gi, bo chung khi ti gi hn
Chc nng chnh gi
Chc nng bm gi th thao
4.2 Nhng iu cha hon thin
Cc nt bm i khi cn cha nhy
Cha ch nhiu ti kiu dng cng nh trang tr
S dng thm 1 nt chuyn cc mode trong khi thc t ch c 2 nt

4.3 C th pht trin


B sung nhng im cha hon thin
B sung thm nhiu chc nng khc nh lch m lch, hn gi nhiu ln, lch
4.4 Kinh nghim bn thn sau khi lm ti
K nng thit k tng, lm mch, layout
K nng thc t trong vic thit k mt mch 8951 hon chnh
K nng coding bng ngn ng C vi mt mch thc t
K nng lm vic nhm, phn chia cng vic

19