You are on page 1of 9

Khi lp trnh bng CCS PIC, vi PIC 16F877A, em c mt vn nh sau: chng trnh chnh main() gi lp li v tn mt chng trnh con

n lap() (bng c php while(true)). chng trnh con lap() c gi cc hm delay dng to sng. Em mun khi ngt xy ra (c phc v bng chng trnh EXT_isr) th PIC r n mt chng trnh con dacbiet(), v thot khi tt c cc chng trnh con ang c chy k c chng trnh lap(), sau khi dacbiet() chy xong th hm main() li chy li t u. Do , trong chng trnh EXT_isr, em dng lnh goto ca C hoc ASM r nhnh n chng trnh dacbiet() v iu kin. M phng cho thy chng trnh chy ng vi yu cu. Tuy nhin khi dng lnh goto: cc bin tm ca chng trnh trc ngt l lap() cha c xa, cc bin stack ca EXT_isr cng cha c xa (r v dacbiet() ngay lp tc m). Vy chng trnh chy n mt lc no s b trn stack v li. (ko bit em lp lun c ng ko v em cng cha ngi i m phng n lu vy) Xin cc bc gii p gip em v c phng php no cht ch logic hn khng em xin cm n cc bc c namqn 07-12-2008, 10:21 PM Khng r thc ra bn ang mun hin thc iu g, nhng bn ang hi cch a PIC v trng thi reset sau khi thc hin xong chng trnh con dacbiet(). Nh vy, ti cho rng cui chng trnh con dacbiet() th bn c th dng lnh reset mm ca cc PIC li 14-bit (m PIC16F877A l mt trong s ). CCS C cung cp mt hm lm vic , tn l reset_cpu(). Thn, tdungk7 07-12-2008, 10:56 PM Khng r thc ra bn ang mun hin thc iu g, nhng bn ang hi cch a PIC v trng thi reset sau khi thc hin xong chng trnh con dacbiet(). Nh vy, ti cho rng cui chng trnh con dacbiet() th bn c th dng lnh reset mm ca cc PIC li 14-bit (m PIC16F877A l mt trong s ). CCS C cung cp mt hm lm vic , tn l reset_cpu(). Thn, Em cm n thy Nam, d cha c gp thy bao gi nhng em rt knh v mn thy hihi (em kha 2004, lc chc thy va i du hc). ca em ngn gn nh sau: lm sao khi chng trnh ngt phc v xong, th con tr PC khng tr li v a ch ang thc hin ngay trc khi ngt (lu trong stack), m tr n mt v tr khc do mnh chn. V phi xa c bin m stack trc khi reset cpu v 0000h. Nu thc hin lnh reset_cpu() nh thy ni th vn b trn stack (m phng cho thy trn rt nhanh), cn thc t th khng chy ng yu cu. Gi gii php lm sao ? Nh thy v cc bn gip em vi namqn ... 08-12-2008, 02:38 PM

ca em ngn gn nh sau: lm sao khi chng trnh ngt phc v xong, th con tr PC khng tr li v a ch ang thc hin ngay trc khi ngt (lu trong stack), m tr n mt v tr khc do mnh chn. V phi xa c bin m stack trc khi reset cpu v 0000h. Nu thc hin lnh reset_cpu() nh thy ni th vn b trn stack (m phng cho thy trn rt nhanh), cn thc t th khng chy ng yu cu. Gi gii php lm sao ? Nh thy v cc bn gip em vi Ti t dng PIC16, nn khng nh r c lnh reset trong tp lnh hp ng hay khng. Ti va xem li th thy PIC16 khng c lnh ny trong tp lnh hp ng, do CCS C s phi gi lp thao tc reset bng cch t PC = 0x0000. Tuy nhin, thanh ghi con tr stack khng th c/ghi trong PIC16. Do , CCS C khng th x l stack trc khi t PC = 0x0000 khi thc thi hm reset_cpu().

Bn c cc la chn sau: 1. Trnh by vn gc, ch khng hi cch hin thc mt gii php bt kh thi bng phn mm vi PIC16. 2. Chuyn sang mt PIC18 c s chn tng thch vi PIC16F877A. PIC18 c lnh reset trong tp lnh hp ng, v hin thc thao tc tng ng vi reset bng chn MCLR. Ngoi ra, con tr ngn xp ca PIC18 cng c th c/ghi. 3. Hin thc gii php trn ca bn bng mt phn cng cho PIC16. Thn, namqn 18-12-2008, 06:35 PM Ti t dng PIC16, nn khng nh r c lnh reset trong tp lnh hp ng hay khng. Ti va xem li th thy PIC16 khng c lnh ny trong tp lnh hp ng, do CCS C s phi gi lp thao tc reset bng cch t PC = 0x0000. Tuy nhin, thanh ghi con tr stack khng th c/ghi trong PIC16. Do , CCS C khng th x l stack trc khi t PC = 0x0000 khi thc thi hm reset_cpu(). ... Cc vi iu khin PIC16 tm trung ci tin (Enhanced Mid-range), tc l cc PIC16F1xxx s bt u ra mt vo qu 1 nm 2009, c b sung cc c ch h tr vic thc hin reset t phn mm. Tp lnh hp ng c b sung lnh RESET cng mt s lnh khc nhm h tr tt hn cho vic hin thc cc RTOS trn PIC16. Thn, 28-04-2012, 11:06 AM Trn y l n kha s ca mnh. (http://www.mediafire.com/?u768ru0uvahl7fs) Vi chc nng : ng m ca khi nhp ng pass, iu khin ng m bng vic dng ng c. 1 nhp pass 8 k t 2 i pass 3 cnh bo chm. tn hiu cnh bo l bng n (tm thi) + cch dng : 1. hai nt kha xong v m xong c tc dng nh tip im thng m cnh ca ng hoc m s chm vo tip im thng m . V vy bn phi nhn tt nt kha xong hoc m xong xung khi mun m phng kha xong hoc m xong 2. ban u s yu cu bn nhp phm th chng ta c th thao tc trn tt c cc phm. Khi nhp pass xong th chng ta nhn phm m ca. nt kha ca th khng cn nhp pass. 3. nt ok i pass. Khi nhn phm i pass th LCD s yu cu nhp ng pass c. Khi nhp ng pass c th nhn phm ok ri nhp pass mi c 8 k t. nhp xong li nhn ok. 4. mt khu hin ti l 12345678. 5. ch chng trnh. Khi m ta thay i chng trnh th trong chng trnh lp trnh c mt on m rt quan trng ch di 3 dng thi, on m s quyt nh vic i mt khu ca bn c thnh cng hay khng, v vic cnh bo c hot ng hay khng. Nu on m th s mc nh mt khu l 00000000. ta xa on m i th s thay i c mt khu. v on m s xa b nh ni EEPROM ca PIC cc bn c th download ti y (http://www.mediafire.com/?u768ru0uvahl7fs) hoc ti link http://www.mediafire.com/?u768ru0uvahl7fs .................................................. .................................................. ............ mi kin thc mc xin lin h : V nh Thng Lp K43KT - Trng HKTCN Thi Nguyn sdt : 0976 08 08 03 0918 337 558 01678 667 772 mail : vudinhthang1989@gmail.com vudinhthang1989 Dng vi PIC 16f877a eunix 28-04-2012, 11:07 AM

28-04-2012, 12:11 PM

- Sao bn ny phi dng lnh reset_cpu nhi. - Bn nn b sung tnh nng xa ngc khi nhp sai 1 k t. - Khi i pass, nhp sai pass th yu cu nhp li pass, ch khng th mi ln nhp sai li chn i pass tip. - Thut ton quyt phm cha c ti u.

http://www.dientumaytinh.com/2012/02/lap-trinh-pic-bo-chuyen-oi-adc-cac-ham.html

CNG N MN HC PHN 1
GVHD: ThS.NGUYN L CNG LP: 4DTVT

TI: KHA S IN T
Nhm: 10

I MC TIU - Thit k kha s in t bng mt khu s dng vi iu khin. - Dng bn phm hex (16 phm) thc hin chc nng giao tip. - Dng ng c mt chiu ng m kha. - Mt khu c th thay i c. - Bo ng ra loa v treo h thng khi mt khu nhp sai 3 ln. V vy bi ton chnh l ta cn quan tm l : - Thut ton qut phm - Qu trnh lu mt m trong eeprom v thay i eeprom - Hin th thng tin ra mn hnh LCD hoc led - ng c hot ng

II PHNG PHP GII QUYT - Lp s khi. - Lp s gii thut. - Tm hiu nguyn tc hot ng ca bn phm hex. - Thit k khi iu khin o chiu ng c ng m ca. - Thit k khi bo ng. - Tm hiu chip x l v cc linh kin c s dng. Thit b chnh: Vi iu khin PIC 16f877A Bn phm 16 phm vi cc phm s v chc nng a vo mt khu v cc lnh ng m ca ti vi iu khin. ng c iu khin ng m ca. - Vit chng trnh theo s gii thut. S dng phn mm lp trnh CCS. - Lin kt cc khi. - Lp mch kim tra v chy th.

III S KHI CA H THNG

IV- CC KHI TRONG H THNG 1.Khi iu khin trung tm

Khi vi iu khin s dng vi iu khin Pic16F877A, n ng vai tr ht sc quan trng trong h thng iu khin h thng kha s. Khi VK bao gm mch to dao ng thch anh, mch Reset reset h thng li trng thi ban u. Cc chn ca VK s c kt ni vi cc khi khc nh ng c, bn phm, khi hin th. Lu tr mt khu qua b nh EEPROM c th lu tr ngay khi mt in. Ton b d liu m ta thit k iu khin h thng kha s u c cha trong b nh ca VK.

Cc cng RB, RC, RD l cng vo ra 8 bt, vi cc chn RX0 n RX7. Chn cng vo ra kt ni vi thit b ngoi vi :

a.Do trong phn mm CCS c h ch file LCD.C mc nh dng cng PORTD nn ta dng cng RD kt ni vi LCD. Cc chn t RD4 => RD7 ca PIC ni vi cc chn d liu D4 => D7 ca LCD Chn RD0 ca pic ni vi chn cho php E (enable) ca LCD. Chn RD1 ni vi chn RS chn chn thanh ghi ca LCD Chn RD2 ni vi chn RW chn chn ch c/ ghi ca LCD.

b.Chn cng qut 16 phm: ma trn phm ni vi cng RC. c.Chn cng iu khin ng c , ci bo ng : cng RB

2. Khi hin th
Khi sn xut LCD, nh sn xut tch hp chp iu khin (HD44780) bn trong lp v v ch a cc chn giao tip cn thit. Cc chn ny c nh s th t v t tn nh bn di :

Chn s 1 2 3 4

Tn Vss Vdd Vee Rs

Chc nng Chn ni t cho LCD, khi thit k mch ta ni chn ny vi GND ca mch iu khin Chn cp ngun cho LCD, khi thit k mch ta ni chn ny vi VCC=5V ca mch iu khin Chn ny dng iu chnh tng phn ca LCD. Chn chn thanh ghi (Register select). Ni chn RS vi logic 0 (GND) hoc logic 1 (VCC) chn thanh ghi.

+ Logic 0: Bus DB0-DB7 s ni vi thanh ghi lnh IR ca LCD ( ch ghi - write) hoc ni vi b m a ch ca LCD ( ch c - read) + Logic 1: Bus DB0-DB7 s ni vi thanh ghi d liu DR bn trong LCD. 5 R/w Chn chn ch c/ghi (Read/Write). Ni chn R/W vi logic 0 LCD hot ng ch ghi, hoc ni vi logic 1 LCD ch c. 6 E Chn cho php (Enable). Sau khi cc tn hiu c t ln bus DB0-DB7, cc lnh ch c chp nhn khi c 1 xung cho php ca chn E. + ch ghi: D liu bus s c LCD chuyn vo(chp nhn) thanh ghi bn trong n khi pht hin mt xung (high-to-low transition) ca tn hiu chn E. + ch c: D liu s c LCD xut ra DB0DB7 khi pht hin cnh ln (low-to-high transition) chn E v c LCD gi bus n khi no chn E xung mc thp. 7-14 DB0DB7 Tm ng ca bus d liu dng trao i thng tin vi MPU. C 2 ch s dng 8 ng bus ny : + Ch 8 bit : D liu c truyn trn c 8 ng, vi bit MSB l bit DB7. + Ch 4 bit : D liu c truyn trn 4 ng t DB4 ti DB7, bit MSB l DB7

3. Khi bn phm

Thc hin chc nng giao tip vi vi iu khin PIC 16F877, dng hin th nhp password, thay i password, m kha ca . S dng bn phm ma trn 16 phm Vi cc phm s t 0 =>9 v cc phm chc nng m ca, kha ca, v i mt khu, reset. Dng cc phm bm c 4 chn ging nh hnh v:

4. Khi ngun

S Khi Ngun Dng ngun 12V xoay chiu a vo cu it to ra in p mt chiu, qua t san phng cho in p bng phng hn. Dng IC7805 n nh in p u ra cho mch ca khi iu khin 5.Khi bo ng H thng bo ng: cnh bo khi nhp sai mt khu qu 3 ln. Thng qua h thng chng bo ng.