Tiểu luận Thiết kế card giao tiếp máy tính ứng dụng điều khiển bộ nguồn

LỜI NÓI ĐẦU Ngày nay tin học đã thâm nhập vào tất cả mọi hoạt động trong xã hội và máy vi tính đã trở thành một công cụ đắc lực trong việc hỗ trợ con người. Nó không chỉ làm giảm nhẹ lao động (kể cả lao động trí tuệ) mà còn giúp cho con người có những năng lực mới mà trước đây chúng ta khó hình dung được. Máy vi tính ngày càng được sử dụng rộng rãi trong nhiều cơ quan, trường học, trong các ngành kinh tế và ngay cả trong gia đình. Theo đà phát triển hiện nay của nước ta thì quá trình hiện đại hoá, công nghiệp hoá là hai mục tiêu đứng đầu. Nói đến công nghiệp hoá, hiện đại hóa thì không thể không nói đến quá trình tự động hóa, đó là một quá trình mà sự can thiệp của con người là tối thiểu. Mà để có tự động hoá trong các khâu, các nghành thì nhất thiết phải có sự hổ trợ của tin học mà cụ thể là các máy tính. Việc sử dụng máy vi tính trong lĩnh vực đo lường và điều khiển ngày càng phổ biến đòi hỏi phải ghép nối máy tính với các thiết bị bên ngoài trong đó tải hay các yếu tố chấp hành phải điều khiển được, còn các phần tử nhập liệu và các đầu đo thì được liên tục kiểm tra để cập nhật dữ liệu bằng một phần mềm được thiết kế riêng. Thông thường cách giải quyết vấn đề này một cách tốt nhất là thiết kế một khối ghép nối với bên ngoài máy tính để trao đổi thông tin với máy tính, khối đó chính là card giao tiếp. Trong thực tiễn sản xuất, việc đo lường và xử lý các đại lượng của thế giới thực như nhiệt độ, tốc độ, nguồn điện áp là một yêu cầu cấp bách và thường xuyên. Để phần nào đáp ứng được yêu cầu đó, nhóm em quyết định thực hiện đề tài: THIẾT KẾ VÀ THI CÔNG CARD GIAO TIẾP MÁY TÍNH Từ những vấn đề đó, nhóm em đã được Thầy LÊ VIẾT PHÚ hướng dẫn thực hiện đề tài theo hướng tự động hóa bằng máy tính cá nhân (Personal Computer) và đơn giản phần cứng bằng kỹ thuật lập trình. Tuy nhiên vì thời gian có hạn, nên trong quá trình thiết kế tập luận văn này không thể tránh khỏi những sai sót, chúng em rất mong sự giúp đỡ của Quý Thầy Cô và các bạn để cuốn Luận Văn Tốt Nghiệp này được hoàn thiện hơn.

doc114 trang | Chia sẻ: lvcdongnoi | Lượt xem: 2214 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Tiểu luận Thiết kế card giao tiếp máy tính ứng dụng điều khiển bộ nguồn, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
naøy. III.Caùc böôùc xaây döïng chöông trình: 1.Phaân tích: a. Phaân tích nhaäp xuaát. b. Xaây döïng caùc boä soá lieäu thöû nghieäm. 2.Thieát keá: Thieát keá döõ lieäu: + Thieát keá caùc kieåu döõ lieäu. + Thieát keá döõ lieäu haèng. + Thieát keá döõ lieäu nhaäp. + Thieát keá döõ lieäu xuaát. Thieát keá caùc haøm: + Sô ñoà haøm. + Ñaëc taû caùc haøm. + Löu ñoà caùc haøm chính. 3. Laäp trình: - Phieân baûn khoâng kieåm tra raøng buoäc, khoâng chuù yù giao dieän. - Phieân baûn coù kieåm tra raøng buoäc, khoâng chuù yù giao dieän. - Phieân baûn coù kieåm tra raøng buoäc, coù chuù yù giao dieän. 4.Thöû nghieäm: - Thöû nghieäm töøng haøm. - Thöû nghieäm toaøn boä chöông trình. IV.Phaân tích nhaäp xuaát: - Nhaäp: söû duïng chuoät hoaëc baøn phieám nhaäp caùc giaù trò ñieän aùp coá ñònh hay caùc daïng soùng vaø caùc thoâng soá cuûa noù theo yeâu caàu ngöôøi duøng. - Xuaát: cho ra caùc giaù trò nhò phaân 8 bit töông öùng vôùi caùc giaù trò ñieän aùp caàn xuaát theo caùc ñòa chæ ñöôïc choïn tröôùc. V.Xaây döïng boä soá lieäu thöû nghieäm: Soá thöù töï Nhaäp Xuaát 1 0 V 0000 0000 2 1.5 V 0000 1111 3 3.0 V 0001 1110 4 5.0 V 0011 0010 5 9.0 V 0101 1010 6 12 V 0111 1000 7 15 V 1001 0110 8 18 V 1011 0100 9 24 V 1111 0000 10 25.5 V 1111 1111 VI.Thieát keá döõ lieäu: Döõ lieäu haèng: STT Teân Kieåu Giaù Trò Ghi chuù 1 TRUE Soá nguyeân 1 Haèng logic 2 FALSE Soá nguyeân 0 Haèng logic 3 MAXSCENE Soá nguyeân 5 Soá hình 4 INT_MOUSE Soá Hexa 33 Ngaét 33 5 M_LEFT Soá Hexa 01 Nuùt traùi chuoät 6 M_CHANGE Soá Hexa 08 Traïng thaùi chuoät 7 ADD Soá Hexa 307 Ñòa chæ Döõ lieäu nhaäp: STT Teân Kieåu Raøng buoäc Ghi chuù 1 dienap Soá thöïc 0 £ dienap £ 25.5 Ñieän aùp 2 dienapmax Soá thöïc buocdienap £ dienapmax £25.5 Ñieän aùp max 3 buocdienap Soá thöïc 0 £ buocdienap £ dienapmax Böôùc ñieän aùp 4 tocdo Soá thöïc 0.5 £ tocdo £ 25 Toác ñoä 5 dangsong 1 £ dangsong £ 6 Daïng soùng Döõ lieäu xuaát: STT Teân Kieåu Raøng buoät Ghi chuù 1 dienap Soá Hexa 0h £ dienap £ FFh Ñieän aùp Caùc kieåu döõ lieäu: STT Teân Moâ taû Ghi chuù 1 Cn[10] Maûng caùc chuoåi kyù töï Caùc ñieän aùp chuaån 2 EVENT Caáu truùc: Msg,Posx,Posy: soá nguyeân Thoâng tin veà chuoät 3 LPEVENT Con troû troû ñeán kieåu EVENT 4 LPBYTE Con troû kyù töï VII.Thieát keá haøm: Sô ñoà haøm: CHÖÔNG TRÌNH CHÍNH Giao dieän Khôûi ñoäng cheá ñoä ñoà hoïa Trôï giuùp Khôûi ñoäng chuoät Phaàn giôùi thieäu Phaàn chính cuûa CT Xuaát Xöû lyù döõ lieäu nhaäp Nhaäp giaù trò ñieän aùp hay daïng soùng Maïch beân ngoaøi Laáy döõ lieäu hoài tieáp vaø xöû lyù Nhaäp baèng chuoät Nhaäp baèng baøn phieám Caùc daïng soùng Giaù trò ñieän aùp leû Caùc giaù trò ñ/a chuaån Danh saùch caùc haøm: Soá TT Teân haøm Kieåu traû veà Tham trò Tham bieán 1 InitGraph 2 LoadImage Soá nguyeân 3 ShowImage x,y, lpBuff, Forward 4 CreatANDMask LpANDMask, lpData, FlagVal 5 CreatXORMask LpXORMask, lpData, FlagVal 6 CreatBuffer lpBuff, lpANDMask, lpXORMask, lpBkImg 7 GetBkImage LpBkImg,x,y, Width, Height 8 PutBkImage LpBkImg,x,y, Width, Height 9 PutImage Left, t Top, lpANDMask, lpXORMask, lpBkImg, lpBuff, Forward 10 Demo 11 My_bar ax1,ax2,ay1,ay2, color 12 NutNoi ax1,ax2,ay1, ay2, color 13 Window a1, x2, y 1, y 2, *Title 14 Trang_bia 15 Gioi_Thieu 16 Trang_Help 17 Help 18 SetMouseRange x1,x2,y1,y2 19 InitMouse Soá nguyeân 20 ShowMouse 21 HideMouse 22 MouseRead lpEvent 23 ResetEvent lpEvent 24 GetEvent LPEVENT 25 Release Msg 26 GetKey Soá nguyeân 27 Nut_Chim ax1, ax2, ay1, ay2, color 28 ChonTuMouse Soá nguyeân x, y, dai, socot, ax, ay 29 Thuhep *Title 30 Doi so 31 Doi_1 so 32 Inchuoi a[ ] 33 Inchuoi_1 a[ ] 34 Doi_tt x, y *mc, &chon 35 Doi_tt1 x1, x2, y 1, y 2, z, poly[ ], kieu 36 Doi_tt2 x1, x2, y 1, y 2, kieu 37 Doi_tt3 x1, x2, y 1, y 2, kieu, 38 NutTG1 x, y, canh, kieu 39 NutTG2 x, y, canh, kieu 40 Menu socot, x, y *mc, &chon 41 Giaodien 42 Doi_tt_Nut_Stop 43 Main 3. Ñaëc taû caùc haøm: 1. void InitGraph Khôûi taïo cheá ñoä ñoà hoïa: haøm naøy seõ baùo loãi neáu nhö khoâng khôûi taïo ñöôïc cheá ñoä ñoà hoïa. 2. int LoadImage Ñoïc caùc file .dat (chöùa döõ lieäu hình con meøo), neáu quaù trình ñoïc thaønh coâng haøm traû veà giaù trò TRUE, neáu khoâng seõ traû veà giaù trò FALSE. 3. void ShowImage Xuaát hình con meøo. 4. void CreatANDMask Taïo maët naï AND. 5. void CreatXORMask Taïo maët naï XOR. 6. void CreatBuffer Taïo vuøng ñeäm. 7. void GetBkImage Laáy thoâng tin veà hình con meøo. 8. void PutBkImage Xuaát caùc pixel. void PutImage Taïo vuøng ñeäm vaø xuaát hình con meøo. void Demo(void) Taïo hieäu öùng hoaït hình: laøm 2 con meøo chaïy qua laïi. void my_bar Taïo moät bar (thanh) rieâng vôùi maøu color. void NutNoi Taïo moät nuùt noåi vôùi maøu color vaø ñoä noåi z. void Window Taïo moät window, trong window coù doøng chöõ *Title. void Trang_bia() Xuaát caùc thoâng tin veà chöông trình. void Gioi_Thieu() Xuaát giôùi thieäu veà chöông trình. Trang_Help() Xuaát caùc thoâng tin höôùng daãn söû duïng chöông trình. 17. Help() Xuaát phaàn höông daãn söû duïng chöông trình. 18. void SetMouseRange Ñaët vuøng di chuyeån cho chuoät. int InitMouse() Khôûi ñoäng chuoät. void ShowMouse(void) Xuaát con troû chuoät. void HideMouse(void) Daáu con troû chuoät. void MouseRead(LPEVENT lpEvent) Ñoïc traïng thaùi chuoät. void ResetEvent(LPEVENT lpEvent) Ñaët laïi bieán coá chuoät. GetEvent(void) Laáy bieán coá chuoät: nuùt ñöôïc nhaán, toaï ñoä chuoät luùc nhaán. void Release Traû laïi traïng thaùi cuûa chuoät sau khi daáu. int GetKey Laáy maõ cuûa phím ñöôïc nhaán. void Nut_Chim Taïo nuùt chìm coù maøu color. int ChonTuMouse Traû veà soá thöù töï cuûa nuùt ñöôïc nhaán. void thuhep Thu heïp maøn hình ñoà hoïa, vaø thoaùt khoûi chöông trình. 30. void doi Ñoåi soá ra chuoãi kyù töï ñeå xuaát ra maøn hình. void doi_1 Ñoåi soá ra chuoåi kyù töï ñeå xuaát ra maøn hình. 32.void inchuoi Xuaát chuoåi kyù töï a[ ] ra maøn hình. 33. void inchuoi_1 Xuaát chuoåi kyù töï a[ ] ra maøn hình vôùi toïa ñoä (y1, y2 , y3). 34. void doi_tt Ñoåi traïng thaùi: töø nuùt noåi sang nuùt chìm, duøng cho caùc nuùt ñieän aùp chuaån. void doi_tt1 Ñoåi traïng thaùi: töø nuùt noåi sang nuùt chìm, duøng cho caùc nuùt daïng soùng. 36. void doi_tt2 Ñoåi traïng thaùi: töø nuùt noåi sang nuùt chìm, duøng cho nuùt STOP. void doi_tt3 Ñoåi traïng thaùi: töø nuùt noåi sang nuùt chìm, duøng cho nuùt GIA TRI. void NutTG1 Taïo nuùt tam giaùc chæ thò giaûm. 39. void NutTG2 Taïo nuùt tam giaùc chæ thò taêng. void menu Taïo menu caùc nuùt ñieän aùp chuaån. Traû veà giaù trò cuûa bieán choïn, xaùc ñònh nuùt naøo ñöôïc choïn. 41. void Giaodien() Taïo giao dieän cho phaàn ñieàu khieån. Doi_tt_Nut_Stop(); Ñoåi traïng thaùi töø nuùt noåi sang nuùt chìm, duøng cho nuùt Stop. 43. void main(void) Haøm chính cuûa chöông trình, trong haøm naøy coù lôøi goïi tôùi taát caû caùc haøm treân, laø nôi xöû lyù chính cuûa chöông trình. Löu ñoà thuaät toaùn cuûa caùc chöông trình chính: Haøm main: Begin Khôûi ñoäng chuoät Khôûi ñoäng cheá ñoä ñoà hoïa Giôùi thieäu Giao dieän cuûa phaàn ñieàu khieån A Xuaát caùc thoâng soá ban ñaàu Menu (choïn ) T Choïn = 0 - Xuaát 00 - Hoài tieáp - Xöû lyù F - Xuaát 15 - Hoài tieáp - Xöû lyù Choïn = 1 - Xuaát 30 - Hoài tieáp - Xöû lyù Choïn = 2 - Xuaát 50 - Hoài tieáp - Xöû lyù Choïn = 3 - Xuaát 90 - Hoài tieáp - Xöû lyù Choïn = 4 Choïn = 5 - Xuaát 120 - Hoài tieáp - Xöû lyù - Xuaát 150 - Hoài tieáp - Xöû lyù Choïn = 6 - Xuaát 180 - Hoài tieáp - Xöû lyù Choïn = 7 Choïn = 8 - Xuaát 240 - Hoài tieáp - Xöû lyù - Xuaát 255 - Hoài tieáp - Xöû lyù Choïn = 9 Giaûm ñieän aùp Choïn=11 Choïn=12 Taêng ñieän aùp Choïn=13 Giaûm ñieän aùp max Choïn=14 Taêng ñieän aùp max Choïn=15 Giaûm böôùc ñieän aùp Choïn=16 Taêng böôùc ñieän aùp Giaûm toác ñoä Choïn=17 Choïn=18 Taêng toác ñoä Choïn=19 STOP (Ñieän aùp = 0) Choïn=20 Xuaát daïng soùng 1 Choïn=21 Xuaát daïng soùng 2 Choïn=22 Xuaát daïng soùng 3 Choïn=23 Xuaát daïng soùng 4 Choïn=24 Xuaát daïng soùng 5 Choïn=25 Xuaát daïng soùng 6 Nuùt giaù trò Choïn=26 Choïn=27 Nuùt Trôï giuùp Nuùt Thoaùt ôû goùc treân traùi maøn hình Choïn=28 Choïn=29 Nuùt THOAT Choïn=30 Phím thoaùt ESC A True End Haøm menu: Begin Veõ caùc nuùt ñieän aùp chuaån A Laáy bieán coá chuoät Chuoät coù di chuyeån Laáy soá thöù töï cuûa nuùt chuoät troû tôùi Veõ khung chöõ nhaät di chuyeån theo chuoät. Nuùt traùi chuoät ñöôïc nhaán Xeùt nuùt naøo ñöôïc nhaán vaø traû veà soá thöù töï cuûa nuùt ñöôïc nhaán Phím ñöôïc nhaán Laáy maõ soá cuûa phím ñöôïc nhaán Phím ¬ choïn=choïn -1 Phím ® choïn=choïn +1 Phím ñöôïc nhaán khaùc phím Enter, ESC A Phím ESC ñöôïc nhaán choïn=30 End (Phaàn chöông trình cuï theå xin xem ôû phaàn phuï luïc) ê Thöû Nghieäm: Sau khi duøng boä soá lieäu thöû nghieäm trong chöông Phaân Tích, vaø caùc thöû nghieäm khaùc veà daïng soùng, caùc giaù trò ñieän aùp leû, chöùc naêng cuûa caùc nuùt, thì nhaän thaáy keát quaû raát toát ñuùng nhö muïc tieâu thieát keá ñaët ra ban ñaàu. Höôùng daãn söû duïng chöông trình: Caùch chaïy chöông trình: CoÙ 3 caùch chaïy chöông trình: - Caùch 1: vaøo RUN cuûa Window, ñaùnh teân chöông trình vaøo vôùi ñuoâi file laø .EXE, cuï theå nhö sau: LVTN.EXE. Sau ñoù nhaán phím Enter ñeå chaïy chöông trình. - Caùch 2: vaøo NC file LVTN.EXE, di chuyeån veät saùng tôùi file naøy vaø nhaán Enter. - Caùch 3: vaøo Explorer tìm file LVTN, duøng chuoät troû vaøo file LVTN nhaán 2 laàn lieân tuïc. Sau khi ñaõ vaøo ñöôïc chöông trình ta seõ thaáy phaàn giôùi thieäu veà Luaän Vaên, sau ñoù ñeå vaøo phaàn chính cuûa chöông trình, töùc laø phaàn ñieàu khieån boä nguoàn, ta nhaán 1 phím baát kyø. Khi ñoù ta seõ thaáy chöông trình coù phaàn giao dieän nhö sau: (chuïp hình daùn voâ, hoaëc scan hình vaøo) Caùch söû duïng phaàn ñieàu khieån: Caùc giaù trò ñieän aùp chuaån: Muoán xuaát caùc caùc trò trong phaàn ñieän aùp chuaån ta chæ caàn duøng phím muõi teân di chuyeån khung saùng tôùi giaù trò muoán xuaát vaø nhaán Enter, hoaëc ta cuõng coù theå söû duïng chuoät troû vaøo giaù trò muoán xuaát vaø aán nuùt traùi chuoät. Caùc giaù trò ñieän aùp leû: Muoán xuaát caùc giaù trò ñieän aùp leû ( ví duï 0.4 V ) ta laøm nhö sau: + Duøng chuoät chæ vaøo nuùt tam giaùc coù muõi teân höôùng leân vaø baám nuùt traùi chuoät cho ñeán khi giaù trò ñieän aùp trong oâ giaù trò ñaït tôùi giaù trò mong muoán. + Duøng chuoät chæ vaøo nuùt giaù trò vaø aán nuùt traùi chuoät thì giaù trò ñieän aùp ñöôïc xuaát ra ngoaøi. Laøm töông töï cho nuùt tam giaùc coù muõi teân höôùng xuoáng. c. Ngoaøi caùc ñieän aùp DC, trong chöông trình coøn taïo ra caùc daïng soùng ñieän aùp baèng caùch keát hôïp caùc ñieän aùp DC vôùi caùc giaù trò vaø thôøi gian toàn taïi ôû möùc giaù trò ñoù do ngöôøi söû duïng ñaët tröôùc. Daïng soùng 1: Laø daïng soùng vuoâng vôùi giaù trò ôû möùc [1] laø giaù trò ñöôïc thieát laäp trong oâ ñieän aùp max vaø thôøi gian toàn taïi ôû möùc [1] cuõng nhö thôøi gian toàn taïi ôû möùc [0] ñöôïc thieát laäp trong oâ Toác ñoä. Caùch ñaët caùc giaù trò vaøo 2 oâ ñieän aùp max vaø Toác ñoä cuõng duøng chuoät chæ vaøo caùc nuùt tam giaùc nhö treân. Daïng soùng vuoâng treân seõ hoaït ñoäng laëp laïi cho ñeán khi ta nhaán nuùt STOP. Daïng soùng 2: Laø daïng naác thang vôùi ñieän aùp taêng daàn töø giaù trò min laø 0V tôùi giaù trò max laø giaù trò trong oâ ñieän aùp max, khoaûng caùch giöõa 2 laàn keá tieáp laø giaù trò ñöôïc thieát laäp trong oâ Böôùc ñieän aùp vaø thôøi gian ñeå giaù trò ñieän aùp thay ñoåi laø khoaûng thôøi gian ñöôïc thieát laäp trong oâ Toác ñoä. Daïng soùng 3: Laø daïng naát thang vôùi ñieän aùp giaûm daàn töø giaù trò max laø giaù trò trong oâ ñieän aùp max tôùi 0V, khoaûng caùch giöõa 2 laàn keá tieáp laø giaù trò ñöôïc thieát laäp trong oâ Böôùc ñieän aùp vaø thôøi gian ñeå giaù trò ñieän aùp thay ñoåi laø khoaûng thôøi gian ñöôïc thieát laäp trong oâ Toác ñoä. Daïng soùng 4: Laø daïng soùng naác thang vôùi ñieän aùp taêng daàn nhö daïng soùng 2 vaø sau ñoù giaûm daàn nhö daïng soùng 3, vieäc taêng giaûm ñoù cöù laëp laïi hoaøi cho ñeán khi nuùt STOP ñöôïc nhaán. Daïng soùng 5: Laø daïng soùng naát thang gioáng nhö daïng soùng 2 nhöng ñöôïc laäp laïi hoaøi cho ñeán khi nuùt STOP ñöôïc nhaán. Daïng soùng 6: Laø daïng soùng naát thang gioáng nhö daïng soùng 3 nhöng ñöôïc laäp laïi hoaøi cho ñeán khi nuùt STOP ñöôïc nhaán. Chöùc naêng cuûa caùc nuùt khaùc: Nuùt Stop: khi nhaán vaøo noù thì laøm cho caùc ñieän aùp coù daïng soùng 1, 4, 5, 6 ngöøng hoaït ñoäng vaø ñaët ñieän aùp ngoõ ra = 0V. Nuùt Thoaùt: khi nhaán vaøo noù thì seõ thoaùt khoûi chöông trình, ngoaøi ra ta coøn coù theå thoaùt khoûi chöông trình baèng nuùt vuoâng ôû treân goùc traùi phía treân maøn hình hay phím ESC treân baøn phím. Nuùt Trôï Giuùp: khi nhaán vaøo noù thì seõ xuaát hieän phaàn höôùng daãn söû duïng chöông trình. PHAÀN F: PHUÏ LUÏC I. CHÖÔNG TRÌNH ÑIEÀU KHIEÅN BOÄ NGUOÀN #include #include #include #include #include #include #include #include #define TRUE 1 #define FALSE 0 #define MAXSCENE 5 // scene : hình. #define INT_MOUSE 0x33 // ngaét 33. #define M_LEFT 0x01 // nuùt traùi chuoät. #define M_RIGHT 0x02 // nuùt phaûi chuoät. #define M_CENTER 0x04 // nuùt giöõa chuoät. #define M_CHANGE 0x08 // chuoät thay ñoåi traïng thaùi. #define ADD 0x307 // ñòa chæ. float dienap=0, dienapmax=0.1, buocdienap=0.1, tocdo=0.5; int MaxX,MaxY,MaxColors; int H_SIZE=18; // chieàu cao cuûa moät kyù töï bình thöôøng (18 pixel) int W_CHAR=8; // chieàu roäng cuûa moät kyù töï bình thöôøng (8 pixel) int H_LINE=10; // khoaûng caùch giöõa 2 doøng (10 pixel) char chuoi[10],chuoi1[10]; typedef char far *string; string cn[10] = {" Min "," 1.5V "," 3V "," 5V "," 9V " ," 12V "," 15V "," 18V "," 24V "," Max "}; typedef struct tagEVENT{ int Msg; int Posx, Posy; // toïa ñoä xaõy ra bieán coá chuoät. } EVENT; typedef EVENT far *LPEVENT; LPEVENT lpEvent; void InitGraph(void) { int gdrive= DETECT, gmode, errorcode; initgraph(&gdrive,&gmode,""); errorcode = graphresult(); if (errorcode != grOk) { printf("\n Chua khoi tao che do DO HOA : %s\n", grapherrormsg(errorcode)); printf("Nhan nut bat ky de dung..."); getch(); exit(1); } MaxX=getmaxx(); MaxY=getmaxy(); MaxColors=getmaxcolor()+1; } typedef unsigned char far *LPBYTE; int LoadImage(char *szFName, LPBYTE &lpBuff) // load hình con meøo (caùc file .dat) { FILE *f; int Width, Height, Ntemp; f = fopen(szFName, "rb"); if(f==NULL) return FALSE; fread(&Width, 1, sizeof(int), f); fread(&Height, 1, sizeof(int), f); lpBuff = (LPBYTE)farmalloc(Width*Height+4); if(lpBuff == NULL) return FALSE; LPBYTE lpTemp = lpBuff+4; *(int *)(&lpBuff[0]) = Width; *(int *)(&lpBuff[2]) = Height; for(int i=0; i<Height; i++) for(int j=0; j<Width; j++) { fread(&Ntemp, 1, 1, f); _fmemcpy(&lpTemp[i*Width+j],&Ntemp,1); } fclose(f); return TRUE; } void ShowImage(int x, int y, LPBYTE lpBuff,int Forward) { int Width, Height; LPBYTE lpTemp = lpBuff+4; Width = *(int *)(&lpBuff[0]); Height= *(int *)(&lpBuff[2]); for(int i=0; i<Height; i++) for(int j=0; j<Width; j++) { if (Forward) putpixel(x+j, y+i, lpTemp[i*Width+j]); else putpixel(x+j, y+i, lpTemp[i*Width+(Width-j)]); } } void CreatANDMask(LPBYTE lpANDMask, LPBYTE lpData, int FlagVal) { int Width, Height; LPBYTE lpTemp Width = *(int *)(&lpData[0]); Height= *(int *)(&lpData[2]); _fmemcpy(lpANDMask, lpData, Width*Height+4); lpTemp = lpANDMask+4; for(int i=0; i<Height; i++) for(int j=0; j<Width; j++) if(lpTemp[i*Width+j] == FlagVal) lpTemp[i*Width+j] = 0xFF; else lpTemp[i*Width+j] = 0; } void CreatXORMask(LPBYTE lpXORMask, LPBYTE lpData, int FlagVal) { int Width, Height; LPBYTE lpTemp; Width = *(int *)(&lpData[0]); Height= *(int *)(&lpData[2]); _fmemcpy(lpXORMask, lpData, Width*Height+4); lpTemp = lpXORMask+4; for(int i=0; i<Height; i++) for(int j=0; j<Width; j++) if(lpTemp[i*Width+j] == FlagVal) lpTemp[i*Width+j] = 0; } void CreatBuffer(LPBYTE lpBuff, LPBYTE lpANDMask, LPBYTE lpXORMask, LPBYTE lpBkImg) { int Width, Height; LPBYTE lpTemp; Width = *(int *)(&lpBuff[0]); Height= *(int *)(&lpBuff[2]); _fmemcpy(lpBuff, lpANDMask, Width*Height+4); lpTemp = lpBuff+4; for(int i=0; i<Height; i++) for(int j=0; j<Width; j++) { lpTemp[i*Width+j] &= lpBkImg[4+i*Width+j]; lpTemp[i*Width+j] ^= lpXORMask[4+i*Width+j]; } } void GetBkImage(LPBYTE lpBkImg, int x, int y, int Width, int Height) { LPBYTE lpTemp; *(int *)(&lpBkImg[0]) = Width; *(int *)(&lpBkImg[2]) = Height; lpTemp = lpBkImg+4; for(int i=0; i<Height; i++) for(int j=0; j<Width; j++) lpTemp[i*Width+j] = getpixel(x+j, y+i); } void PutBkImage(LPBYTE lpBkImg,int x,int y,int Width,int Height) { LPBYTE lpTemp; *(int *)(&lpBkImg[0]) = Width; *(int *)(&lpBkImg[2]) = Height; lpTemp = lpBkImg+4; for(int i=0; i<Height; i++) for(int j=0; j<Width; j++) putpixel(x+j,y+i,lpTemp[i*Width+j]); } void PutImage(int Left, int Top,LPBYTE lpANDMask,LPBYTE lpXORMask, LPBYTE lpBkImg, LPBYTE lpBuff,int Forward) { CreatBuffer(lpBuff, lpANDMask, lpXORMask, lpBkImg); ShowImage(Left, Top, lpBuff, Forward); } void Demo(void) { int Width, Height; int Maxx=getmaxx(); LPBYTE lpCat[10], lpCatANDMask[10], lpCatXORMask[10], lpBkImg, lpBuff; char szFName[80]; for(int i=1; i<=MAXSCENE; i++) { sprintf(szFName, "CAT%d.DAT", i); if (!LoadImage(szFName, lpCat[i])) return; Width = *(int *)(&lpCat[i][0]); Height= *(int *)(&lpCat[i][2]); lpCatANDMask[i] = (LPBYTE)farmalloc(Width*Height+4); if (lpCatANDMask[i]==NULL) return; lpCatXORMask[i] = (LPBYTE)farmalloc(Width*Height+4); if (lpCatXORMask[i]==NULL) return; CreatANDMask(lpCatANDMask[i], lpCat[i], 4); CreatXORMask(lpCatXORMask[i], lpCat[i], 4); } lpBkImg = (LPBYTE)farmalloc(Width*Height+4); if (lpBkImg==NULL) return; lpBuff = (LPBYTE)farmalloc(Width*Height+4); if (lpBuff==NULL) return; int k = 10, l = Maxx-100; int Forward=1; GetBkImage(lpBkImg, 50, 360, Width, Height); do{ for(i=1; i<=MAXSCENE; i++) { PutImage(k, 393, lpCatANDMask[i], lpCatXORMask[i], lpBkImg, lpBuff,Forward); PutImage(l, 393, lpCatANDMask[i], lpCatXORMask[i], lpBkImg, lpBuff,!Forward); delay(100); // Neáu muoán meøo chaïy nhanh hôn ta giaûm giaù trò trong haøm Delay(). if (Forward) { k+=8; l-=8; } else { k-=8; l+=8; } if(k>(Maxx-158)/2) Forward=0; else if (k<=10) Forward=1; } } while(!kbhit()); } void my_bar(int ax1,int ay1,int ax2,int ay2,int color) { setfillstyle(1,color); bar(ax1,ay1,ax2,ay2); } void NutNoi(int ax1,int ay1,int ax2,int ay2, int color, int z) { my_bar(ax1,ay1,ax2,ay2,color); setcolor(15); for (int i=1;i<z;i++) { line(ax1+i,ay1+i,ax2-i,ay1+i); line(ax1+i,ay1+i,ax1+i,ay2-i); } setcolor(8); for (i=1;i<z;i++) { line(ax1+i,ay2-i,ax2-i,ay2-i); line(ax2-i,ay1+i,ax2-i,ay2-i); } setcolor(0); rectangle(ax1,ay1,ax2,ay2); } void Window(int x1,int y1,int x2,int y2,char *Title) { int maucu=getcolor(); int ax=x1+(x2-x1+1-W_CHAR*strlen(Title))/2+1; int ay=y1+7; my_bar(x1,y1,x2,y2,7); my_bar(x1,y1,x1+H_SIZE,y1+H_SIZE,7); my_bar(x1+H_SIZE+1,y1,x2,y1+H_SIZE,1); setcolor(14); outtextxy(ax,ay,Title); setcolor(15); line(x1,y1+H_SIZE+1,x2,y1+H_SIZE+1); setcolor(0); line(x1,y1+H_SIZE+2,x2,y1+H_SIZE+2); setcolor(0); rectangle(x1+H_SIZE/2-5,y1+H_SIZE/2- 1,x1+H_SIZE/2+5,y1+H_SIZE/2+1); line(x1+H_SIZE,y1,x1+H_SIZE,y1+H_SIZE); rectangle(x1,y1,x2,y2); setcolor(maucu); } void Trang_bia() { setfillstyle(SOLID_FILL, CYAN); NutNoi(6,46,632,452,3,4); rectangle(2,43,640-4,480-3); rectangle(5,46,640-7,480-6); setcolor(YELLOW); outtextxy(180,54," BO GIAO DUC VA DAO TAO"); outtextxy(180,64," TRUONG DAI HOC SU PHAM KY THUAT"); outtextxy(180,84," KHOA DIEN - BO MON DIEN TU "); outtextxy(180,104," ---oOo---"); outtextxy(55,127,"LUAN VAN TOT NGHIEP"); outtextxy(54,170,"DE TAI: "); settextstyle(DEFAULT_FONT,HORIZ_DIR,2); setcolor(BLACK); outtextxy(13,170," THIET KE VA THI CONG CARD "); outtextxy(13,203," GIAO TIEP MAY TINH UNG DUNG "); outtextxy(13,236," DIEU KHIEN BO NGUON"); setcolor(WHITE); outtextxy(10,165," THIET KE VA THI CONG CARD "); outtextxy(10,198," GIAO TIEP MAY TINH UNG DUNG "); outtextxy(10,231," DIEU KHIEN BO NGUON"); setcolor(BLACK); outtextxy(358,300,"Le Viet Phu"); outtextxy(358,330,"Nguyen Lam Vu"); outtextxy(358,360,"Nguyen Minh Tuan"); setcolor(WHITE); outtextxy(355,295,"Le Viet Phu"); outtextxy(355,325,"Nguyen Lam Vu"); outtextxy(355,355,"Nguyen Minh Tuan"); setcolor(YELLOW); settextstyle(DEFAULT_FONT,0,1); outtextxy(130,302," GIAO VIEN HUONG DAN:"); outtextxy(130,330," SINH VIEN THUC HIEN:"); outtextxy(130,385,"TP HO CHI MINH - THANG 3 - NAM 2000"); } void Gioi_Thieu() { int Maxx=getmaxx(); int Maxy=getmaxy(); rectangle(0,0,Maxx,Maxy); Window(0,0,Maxx,Maxy,"CHUONG TRINH DIEU KHIEN BO NGUON "); Trang_bia(); NutNoi(6,455,634,475,3,3); setcolor(YELLOW); outtextxy(170,462,"Hay nhan phim bat ky de bat dau..."); Demo(); // Haøm chaïy con meøo getch(); } void Trang_Help() { setfillstyle(SOLID_FILL, CYAN); NutNoi(6,23,632,452,3,3); rectangle(2,20,640-4,480-3); rectangle(5,23,640-7,480-6); setcolor(14); outtextxy(20,45," 1. Cac gia tri dien ap chuan: "); setcolor(15); outtextxy(10,63,"- Dung phim ® hay ¬ de di chuyen khung sang toi gia tri muon xuat va an Enter."); outtextxy(10,81,"- Dung chuot tro vao gia tri muon xuat va bam nut trai chuot. "); setcolor(14); outtextxy(20,99," 2. Cac gia tri dien ap le: "); setcolor(15); outtextxy(10,117,"- Dung chuot tro vao 2 nut tam giac va bam nut trai chuot cho den khi dat gia"); outtextxy(10,135,"tri muon xuat. Sau do dung chuot tro vao nut GIA TRI va bam nut trai chuot."); setcolor(14); outtextxy(20,153," 3. Cac nut dang song: "); setcolor(15); outtextxy(20,171," a. Dang song 1 (nut thu 6): la dang song vuong, voi muc [1] = DIEN AP MAX,"); outtextxy(10,189,"thoi gian o muc [1] = thoi gian o muc [0] = TOC DO "); outtextxy(20,207," b. Dang song 2 (nut thu 4): la dang song nat thang, voi dien ap tang dan:"); outtextxy(10,225,"tu 0V ö DIEN AP MAX, moi lan tang mot BUOC DIEN AP, thoi gian tang = TOC DO."); outtextxy(20,243," c. Dang song 3 (nut thu 5): la dang song nat thang, voi dien ap giam dan:"); outtextxy(10,261,"tu DIEN AP MAX ö 0V, moi lan giam mot BUOC DIEN AP, thoi gian giam = TOC DO."); outtextxy(20,279," d. Dang song 4 (nut thu 2): la su ket hop cua dang song 2 va 3."); outtextxy(20,297," e. Dang song 5 (nut thu 1): giong dang song 2 nhung duoc lap lai nhieu lan."); outtextxy(20,315," f. Dang song 6 (nut thu 3): giong dang song 3 nhung duoc lap lai nhieu lan."); setcolor(14); outtextxy(20,333," 4. Chuc nang cac nut khac: "); setcolor(15); outtextxy(10,351,"- Nut STOP: lam dung cua cac dang song 1,4,5,6 va dat dien ap = 0V. "); outtextxy(10,369,"- Nut TRO GIUP: la phan huong dan su dung chuong trinh."); outtextxy(10,387,"- Nut THOAT: de thoat khoi chuong trinh. "); outtextxy(10,405,"- Ngoai ra chung ta co the thoat khoi chuong trinh bang nut hinh vuong o goc "); outtextxy(10,423,"trai tren dinh cua man hinh, hay phim ESC tren ban phim. "); } void Help() { int Maxx=getmaxx(); int Maxy=getmaxy(); rectangle(0,0,Maxx,Maxy); Window(0,0,Maxx,Maxy," HUONG DAN SU DUNG CHUONG TRINH "); Trang_Help(); NutNoi(6,455,634,475,3,3); setcolor(YELLOW); outtextxy(20,462," Hay nhan phim bat ky de tro lai phan dieu khien ..."); getch(); } void SetMouseRange(int x1,int y1,int x2,int y2) // ñaët vuøng di chuyeån cho chuoät { _AX = 0x07; _CX = x1; _DX = y1; geninterrupt(INT_MOUSE); _AX = 0x08; _CX = x2; _DX = y2; geninterrupt(INT_MOUSE); } int InitMouse() // Khôûi ñoäng chuoät { int ax; _AX = 0; geninterrupt(INT_MOUSE); ax = _AX; if (ax == 0) return FALSE; SetMouseRange(0,0,MaxX,MaxY); return TRUE; } void ShowMouse(void) // Hieån thò chuoät { _AX = 1; geninterrupt(INT_MOUSE); } void HideMouse(void) // Daáu chuoät { _AX = 2; geninterrupt(INT_MOUSE); } void MouseRead(LPEVENT lpEvent) // Traû veà bieán coá nhaän ñöôïc töø chuoät : Nuùt traùi hay phaûi ñöôïc baám { int bx,cx,dx; _AX = 3; geninterrupt(INT_MOUSE); bx = _BX; lpEvent->Msg = bx; lpEvent->Posx = _CX; lpEvent->Posy = _DX; } void ResetEvent(LPEVENT lpEvent) // ñaët laïi bieán coá chuoät { lpEvent->Msg = 0; lpEvent->Posx = lpEvent->Posy = 0; } EVENT PrevEvent, CurEvent; // Bieán coá tröôùc , Bieán coá hieän haønh. LPEVENT GetEvent(void) // Haøm laáy bieán coá chuoät { ResetEvent(&CurEvent); MouseRead(&CurEvent); CurEvent.Posx = CurEvent.Posx; CurEvent.Posy = CurEvent.Posy; // xeùt traïng thaùi chuoät coù thay ñoåi hay khoâng if((CurEvent.Posx!=PrevEvent.Posx)&& (CurEvent.Posy!=PrevEvent.Posy)) CurEvent.Msg |= M_CHANGE; PrevEvent = CurEvent; return (&CurEvent); } void Release(int Msg) // traû laïi traïng thaùi ( vò trí ) cuûa chuoät sau khi daáu. { while(GetEvent()->Msg & Msg); } int GetKey(void) { int ch; ch = getch(); if (ch == 0) ch = getch() | 0x80; return ch; } void Nut_Chim(int ax1,int ay1,int ax2,int ay2,int color) { my_bar(ax1,ay1,ax2,ay2,color); setcolor(7); for (int i=1;i<3;i++) { line(ax1+i+1,ay1+i,ax2-i,ay1+i); line(ax1+i,ay1+i+1,ax1+i,ay2-i); } setcolor(15); for (i=1;i<3;i++) { line(ax1+i,ay2-i,ax2-i-1,ay2-i); line(ax2-i,ay1+i,ax2-i,ay2-i-1); } setcolor(0); rectangle(ax1,ay1,ax2,ay2); } int ChonTuMouse(int x,int y,int dai,int socot,int ax,int ay) { for (int i=0;i<socot;i++) { if ((ax>=(x+dai*i)*W_CHAR)&&(ax<=(x+6+dai*i)*W_CHAR)&& (ay>=(y-1)*W_CHAR)&&(ay<=(y+2)*W_CHAR) ) return i; } if ((ax>=80) &&(ax=160)&&(ay<=190)) return 11; if ((ax>=150)&&(ax=160)&&(ay<=190)) return 12; if ((ax>=450)&&(ax=310)&&(ay<=340)) return 13; if ((ax>=490)&&(ax=310)&&(ay<=340)) return 14; if ((ax>=450)&&(ax=360)&&(ay<=390)) return 15; if ((ax>=490)&&(ax=360)&&(ay<=390)) return 16; if ((ax>=450)&&(ax=410)&&(ay<=440)) return 17; if ((ax>=490)&&(ax=410)&&(ay<=440)) return 18; if ((ax>=355)&&(ax=310)&&(ay<=440)) return 19; if ((ax>= 25)&&(ax=310)&&(ay<=370)) return 20; if ((ax>=135)&&(ax=310)&&(ay<=370)) return 21; if ((ax>=245)&&(ax=310)&&(ay<=370)) return 22; if ((ax>= 25)&&(ax=380)&&(ay<=440)) return 23; if ((ax>=135)&&(ax=380)&&(ay<=440)) return 24; if ((ax>=245)&&(ax=380)&&(ay<=440)) return 25; if ((ax>=250)&&(ax=140)&&(ay<=190)) return 26; if ((ax>=550)&&(ax=455)&&(ay<=477)) return 27; if ((ax>= 00)&&(ax= 00)&&(ay<= 20)) return 28; if ((ax>=518)&&(ax= 85)&&(ay<=110)) return 29; if ((ax>=420)&&(ax=455)&&(ay<=477)) return 30; return -1; } void thuhep(char *Title) { int i,midx,midy; for (i=0;i<10;i++) { cleardevice(); Window(0+i*32,0+i*24,MaxX-i*32,MaxY-i*24,Title); delay(100); } } void doi(float so) { sprintf(chuoi,"%2.1f%s",so,"V"); } void doi_1(float so) { sprintf(chuoi,"%2.1f",so); } void inchuoi(char a[]) { settextstyle(DEFAULT_FONT,HORIZ_DIR,3); Nut_Chim(425,140,570,190,7); setcolor(14); outtextxy(445,155,a); settextstyle(0,0,1); } void inchuoi_1(char a[], int y1, int y2, int y3) { settextstyle(DEFAULT_FONT,HORIZ_DIR,2); Nut_Chim(550,y2,620,y3,7); setcolor(14); outtextxy(553,y1,a); settextstyle(0,0,1); } void doi_tt(string *mc,int x, int y,int &chon) // ñoåi traïng thaùi: töø nuùt noåi sang nuùt chìm, duøng cho caùc nuùt ñieän aùp chuaån. { int dai=7; doi(dienap); Nut_Chim((x+dai*chon)*W_CHAR,(y1)*W_CHAR,(x+6+dai*chon) *W_CHAR,(y+2)*W_CHAR,7); setcolor(14); rectangle((x+dai*chon)*W_CHAR+6,(y-1)*W_CHAR+6, (x+6+dai*chon)*W_CHAR-4,(y+2)*W_CHAR-4); outtextxy((x+dai*chon)*W_CHAR+3,y*W_CHAR+1,mc[chon]); inchuoi(chuoi); delay(200); NutNoi((x+dai*chon)*W_CHAR,(y-1)*W_CHAR, (x+6+dai*chon)*W_CHAR,(y+2)*W_CHAR,7,3); rectangle((x+dai*chon)*W_CHAR+5,(y-1)*W_CHAR+5, (x+6+dai*chon)*W_CHAR-5,(y+2)*W_CHAR-5); outtextxy((x+dai*chon)*W_CHAR+2,y*W_CHAR,mc[chon]); } void doi_tt1( int x1, int y1,int x2, int y2 , int z, int poly[], int kieu) // ñoåi traïng thaùi: töø nuùt noåi sang nuùt chìm, duøng cho caùc nuùt daïng soùng. { if (kieu==1) { NutNoi(x1,y1,x2,y2,7,3); my_bar(x1+5,y1+5,x2-5,y2-5,9); setcolor(14); drawpoly(z,poly); } else { Nut_Chim(x1,y1,x2,y2,7); my_bar(x1+6,y1+6,x2-4,y2-4,9); setcolor(14); drawpoly(z,poly); } } void doi_tt2(int x1,int y1,int x2,int y2, int kieu) // duøng cho nuùt STOP. { if (kieu==1) NutNoi(x1,y1,x2,y2,7,3); else Nut_Chim(x1,y1,x2,y2,7); } void doi_tt3(int x1,int y1,int x2,int y2, int kieu) // duøng cho nuùt GIA TRI. { int poly7[]={265,165,325,165,325,160,335,170,325, 180,325,175,265,175,275,170,265,165}; int poly7_7[]={266,166,326,166,326,161,336,171,326, 181,326,176,266,176,276,171,266,166}; if (kieu==1) { NutNoi(x1,y1,x2,y2,7,3); drawpoly(9,poly7); setcolor(BLACK); setfillstyle(1,YELLOW); drawpoly(9,poly7); floodfill(300,168,BLACK); outtextxy(34*W_CHAR,8*H_SIZE+2,"GIA TRI"); } else { Nut_Chim(x1,y1,x2,y2,7); drawpoly(9,poly7_7); setcolor(BLACK); setfillstyle(1,YELLOW); drawpoly(9,poly7_7); floodfill(300,168,BLACK); outtextxy(34*W_CHAR+1,8*H_SIZE+3,"GIA TRI"); } } void NutTG1(int x,int y,int canh,int kieu) { int g=canh/2; // g=giöõa if (kieu==1) { int poly8[]={x+g-4,y+g-4,x+g+4,y+g-4,x+g, y+g+4,x+g-4,y+g-4}; NutNoi(x,y,x+canh,y+canh,7,3); setcolor(BLACK); setfillstyle(1,14); drawpoly(4,poly8); floodfill(x+g,y+g,BLACK); } else { int poly8[]={x+g-3,y+g-3,x+g+5,y+g-3,x+g+1, y+g+5,x+g-3,y+g-3}; Nut_Chim(x,y,x+canh,y+canh,7); setcolor(BLACK); setfillstyle(1,14); drawpoly(4,poly8); floodfill(x+g,y+g,BLACK); } } void NutTG2(int x,int y,int canh,int kieu) { int g=canh/2; // g=giöõa if (kieu==1) { int poly8[]={x+g,y+g-4,x+g+4,y+g+4,x+g-4, y+g+4,x+g,y+g-4}; NutNoi(x,y,x+canh,y+canh,7,3); setcolor(BLACK); setfillstyle(1,14); drawpoly(4,poly8); floodfill(x+g,y+g,BLACK); } else { int poly8[]={x+g+1,y+g-3,x+g+5,y+g+5,x+g-3, y+g+5,x+g+1,y+g-3}; Nut_Chim(x,y,x+canh,y+canh,7); setcolor(BLACK); setfillstyle(1,14); drawpoly(4,poly8); floodfill(x+g,y+g,BLACK); } } void menu(string *mc,int socot,int x,int y,int &chon) { int i,j,ch,dai=7; setcolor(0); for (i=0;i<socot;i++) { NutNoi((x+dai*i)*W_CHAR,(y-1)*W_CHAR, (x+6+dai*i)*W_CHAR,(y+2)*W_CHAR,7,3); setcolor(0); outtextxy((x+dai*i)*W_CHAR+2,y*W_CHAR,mc[i]); } setcolor(14); rectangle((x+dai*chon)*W_CHAR+5,(y-1)*W_CHAR+5, (x+6+dai*chon)*W_CHAR-5,(y+2)*W_CHAR-5); outtextxy((x+dai*chon)*W_CHAR+2,y*W_CHAR,mc[chon]); int MouseChon=-1; do { ShowMouse(); lpEvent = GetEvent(); if (lpEvent->Msg==M_CHANGE) { MouseChon=ChonTuMouse(x,y,dai,socot, lpEvent->Posx,lpEvent->Posy); if ((MouseChon>=0) && (chon!=MouseChon)) { HideMouse(); NutNoi((x+dai*chon)*W_CHAR,(y-1)*W_CHAR, (x+6+dai*chon)*W_CHAR,(y+2)*W_CHAR,7,3); outtextxy((x+dai*chon)*W_CHAR+2,y*W_CHAR,mc[chon]); chon=MouseChon; setcolor(14); rectangle((x+dai*chon)*W_CHAR+5,(y-1)*W_CHAR+5, (x+6+dai*chon)*W_CHAR-5,(y+2)*W_CHAR-5); outtextxy((x+dai*chon)*W_CHAR+2,y*W_CHAR,mc[chon]); } } if (lpEvent->Msg==M_LEFT) { MouseChon=ChonTuMouse(x,y,dai,socot, lpEvent->Posx,lpEvent->Posy); if (MouseChon>=0) { HideMouse(); Release(M_LEFT); chon=MouseChon; return; } } if (kbhit()) { HideMouse(); ch=getch(); if (ch==0) ch=getch(); switch (ch) { case 75: // phím ¬ { setcolor(7); rectangle((x+dai*chon)*W_CHAR+5,(y-1)*W_CHAR+5, (x+6+dai*chon)*W_CHAR-5,(y+2)*W_CHAR-5); setcolor(0); outtextxy((x+dai*chon)*W_CHAR+2,y*W_CHAR,mc[chon]); if (chon==0) chon=socot-1; else chon=chon-1; setcolor(14); rectangle((x+dai*chon)*W_CHAR+5,(y-1)*W_CHAR+5, (x+6+dai*chon)*W_CHAR-5,(y+2)*W_CHAR-5); outtextxy((x+dai*chon)*W_CHAR+2,y*W_CHAR,mc[chon]); break; } case 77: // phím ® { setcolor(7); rectangle((x+dai*chon)*W_CHAR+5,(y-1)*W_CHAR+5, (x+6+dai*chon)*W_CHAR-5,(y+2)*W_CHAR-5); setcolor(0); outtextxy((x+dai*chon)*W_CHAR+2,y*W_CHAR,mc[chon]); if (chon==socot-1) chon=0; else chon=chon+1; setcolor(14); rectangle((x+dai*chon)*W_CHAR+5,(y-1)*W_CHAR+5, (x+6+dai*chon)*W_CHAR-5,(y+2)*W_CHAR-5); outtextxy((x+dai*chon)*W_CHAR+2,y*W_CHAR,mc[chon]); break; } } ShowMouse(); } } while ((ch!=27)&&(ch!=13)); if (ch==27) chon=31; } void Giaodien() { setviewport(0,0,MaxX,MaxY,1); Window(0,0,MaxX,MaxY,"LUAN VAN TOT NGHIEP _ KHOA : 1995 - 2000 _ LOP : 95KDD "); setcolor(0); line(0,2*H_SIZE+1,MaxX,2*H_SIZE+1); setcolor(7); rectangle(0,0,MaxX,MaxY); setcolor(14); outtextxy(1*W_CHAR+5,26*H_SIZE-7,"KHOA DIEN – DAI HOC SU PHAM KY THUAT "); NutNoi(10,50,630,120,7,4); settextstyle(DEFAULT_FONT,HORIZ_DIR,2); setcolor(0); outtextxy(65,66,"CHUONG TRINH DIEU KHIEN BO NGUON"); outtextxy(187,91,"(0 - 25.5V / 2A)"); setcolor(15); outtextxy(62,63,"CHUONG TRINH DIEU KHIEN BO NGUON"); setcolor(14); outtextxy(184,89,"(0 - 25.5V / 2A)"); settextstyle(0,0,1); NutNoi(550,455,630,477,7,4); // nut TRÔÏ GIUÙP outtextxy(560,463,"TRO GIUP"); NutNoi(420,455,520,477,7,4); // nut GIÔÙI THIEÄU outtextxy(430,463,"GIOI THIEU"); NutNoi(10,130,630,200,7,4); NutNoi(10,210,630,280,7,4); NutNoi(10,290,630,450,7,4); NutNoi(518,85,570,110,7,3); // nut THOAÙT outtextxy(525,95,"THOAT"); NutNoi(25,310,125,370,7,3) ; my_bar(30,315,120,365,9) ; //1 NutNoi(135,310,235,370,7,3); my_bar(140,315,230,365,9); //2 NutNoi(245,310,345,370,7,3); my_bar(250,315,340,365,9); //3 NutNoi(25,380,125,440,7,3) ; my_bar(30,385,120,435,9) ; //4 NutNoi(135,380,235,440,7,3); my_bar(140,385,230,435,9); //5 NutNoi(245,380,345,440,7,3); my_bar(250,385,340,435,9); //6 NutNoi(355,310,435,440,7,3); int poly1[]={30,328,33,325,33,355,75,325,75,355, 117,325,117,355,120,352}; int poly2[]={140,355,180,325,220,355,230,350}; int poly3[]={250,352,253,355,253,325,295,355,295, 325,337,355,337,325,340,328}; int poly4[]={30,425,50,425,100,395,120,395}; int poly5[]={140,395,160,395,210,425,230,425}; int poly6[]={250,425,258,425,258,395,273,395,273, 425,288,425,288,395,303,395,303,425, 318,425,318,395,333,395,333,425,340,425}; setcolor(14); drawpoly(8,poly1); // Veõ caùc nuùt daïng soùng drawpoly(4,poly2); drawpoly(8,poly3); drawpoly(4,poly4); drawpoly(4,poly5); drawpoly(14,poly6); // Heát caùc nuùt daïng soùng setcolor(BLACK); // baét ñaàu veõ nuùt STOP. setfillstyle(1,RED); circle(395,390,30); floodfill(395,390,BLACK); my_bar(372,382,417,398,15); // heát nuùt STOP. Nut_Chim(425,140,570,190,7); // nuùt chìm hieån thò soá ñieän aùp. NutNoi(250,140,350,190,7,3); // Veõ nuùt giaù trò int poly7[]={265,165,325,165,325,160,335,170, 325,180,325,175,265,175,275,170,265,165}; drawpoly(9,poly7); setcolor(BLACK); setfillstyle(1,YELLOW); drawpoly(9,poly7); floodfill(300,168,BLACK); outtextxy(34*W_CHAR,8*H_SIZE+2,"GIA TRI");// heát nuùt giaù trò NutTG1(80,160,30,1); NutTG2(150,160,30,1); outtextxy(8*W_CHAR+4,8*H_SIZE+2,"THAY DOI DIEN AP"); NutTG1(450,310,30,1); NutTG2(490,310,30,1); NutTG1(450,360,30,1); NutTG2(490,360,30,1); NutTG1(450,410,30,1); NutTG2(490,410,30,1); outtextxy(55*W_CHAR,17*H_SIZE-7,"DIEN AP MAX(V)"); outtextxy(55*W_CHAR,19*H_SIZE+5,"BUOC DIEN AP(V)"); outtextxy(58*W_CHAR,22*H_SIZE+1,"TOC DO(S)"); Nut_Chim(550,310,620,340,7); // hieån thò bieân ñoä max Nut_Chim(550,360,620,390,7); // hieån thò böôùc ñieän aùp Nut_Chim(550,410,620,440,7); // hieån thò toác ñoä rectangle(371 ,318 ,417 ,335 ); outtextxy(47*W_CHAR+3,18*H_SIZE,"STOP"); outtextxy(31*W_CHAR,12*H_SIZE+5,"CAC DIEN AP CHUAN "); outtextxy(16*W_CHAR+6,17*H_SIZE-7,"CAC DANG SONG"); outtextxy(7*W_CHAR,15*H_SIZE-2,"0V "); outtextxy(69*W_CHAR,15*H_SIZE-2,"25.5V "); } void Doi_tt_Nut_Stop() { doi_tt2(355,310,435,440,0); setcolor(BLACK); setfillstyle(1,RED); circle(396,391,30); floodfill(396,391,BLACK); my_bar(373,383,418,399,15); rectangle(372,319,418,336); outtextxy(47*W_CHAR+4,18*H_SIZE+1,"STOP"); delay(200); doi_tt2(355,310,435,440,1); setcolor(BLACK); setfillstyle(1,RED); circle(395,390,30); floodfill(395,390,BLACK); my_bar(372,382,417,398,15); rectangle(371,318,417,335); outtextxy(47*W_CHAR+3,18*H_SIZE,"STOP"); } void main(void) { int tam; int chon=0; if (!InitMouse()) { printf("Chua cai dat Mouse driver!!! Chuong trinh ngung"); return; } InitGraph(); Gioi_Thieu(); Giaodien(); ShowMouse(); outp(0x306,0x00); outp(ADD,0x00); sound(3500); delay(50); nosound(); do { doi(dienap); inchuoi(chuoi); doi_1(dienapmax); inchuoi_1(chuoi,317,310,340); doi_1(buocdienap); inchuoi_1(chuoi,367,360,390); doi_1(tocdo); inchuoi_1(chuoi,417,410,440); ShowMouse(); menu(cn,10,5,31,chon); sound(3500); delay(50); nosound(); switch (chon) { case 0: // nuùt 0V { dienap=0; outp(ADD,0); doi_tt(cn,5,31,chon); HideMouse(); break; } case 1: // nuùt 1.5V { int t1,ss1,s1; dienap=1.5; outp(ADD,15); doi_tt(cn,5,31,chon); HideMouse(); t1=inp(ADD); while (t1<15) { ss1=15-t1; s1=15+ss1; outp(ADD,s1); t1=inp(ADD); } break; } case 2: // nuùt 3V { int t2,ss2,s2; dienap=3; outp(ADD,30); doi_tt(cn,5,31,chon); HideMouse(); t2=inp(ADD); while (t2<30) { ss2=30-t2; s2=30+ss2; outp(ADD,s2); t2=inp(ADD); } break; } case 3: // nuùt 5V { int t3,ss3,s3; dienap=5; outp(ADD,50); doi_tt(cn,5,31,chon); HideMouse(); t3=inp(ADD); while (t3<50) { ss3=50-t3; s3=50+ss3; outp(ADD,s3); t3=inp(ADD); } break; } case 4: // nuùt 9V { int t4,ss4,s4; dienap=9; outp(ADD,90); doi_tt(cn,5,31,chon); HideMouse(); t4=inp(ADD); while (t4<90) { ss4=90-t4; s4=90+ss4; outp(ADD,s4); t4=inp(ADD); } break; } case 5: // nuùt 12V { int t5,ss5,s5; dienap=12; outp(ADD,120); doi_tt(cn,5,31,chon); HideMouse(); t5=inp(ADD); while (t5<120) { ss5=120-t5; s5=120+ss5; outp(ADD,s5); t5=inp(ADD); } break; } case 6: // nuùt 15V { int t6,ss6,s6; dienap=15; outp(ADD,150); doi_tt(cn,5,31,chon); HideMouse(); t6=inp(ADD); while (t6<150) { ss6=150-t6; s6=150+ss6; outp(ADD,s6); t6=inp(ADD); } break; } case 7: // nuùt 18V { int t7,ss7,s7; dienap=18; outp(ADD,180); doi_tt(cn,5,31,chon); HideMouse(); t7=inp(ADD); while (t7<180) { ss7=180-t7; s7=180+ss7; outp(ADD,s7); t7=inp(ADD); } break; } case 8: // nuùt 24V { int t8,ss8,s8; dienap=24; outp(ADD,240); doi_tt(cn,5,31,chon); HideMouse(); t8=inp(ADD); while (t8<240) { ss8=240-t8; s8=240+ss8; outp(ADD,s8); t8=inp(ADD); } break; } case 9: // nuùt 25.5V { int t9,ss9,s9; dienap=25.5; outp(ADD,255); doi_tt(cn,5,31,chon); HideMouse(); t9=inp(ADD); while (t9<255) { ss9=255-t9; s9=255+ss9; outp(ADD,s9); t9=inp(ADD); } break; } case 11: // nuùt giaûm ñieän aùp { sound(3500); delay(10); nosound(); NutTG1(80,160,30,0); delay(100); NutTG1(80,160,30,1); if (dienap>0) { dienap=dienap-0.1; doi(dienap); inchuoi(chuoi); } if (dienap<=0) { dienap=0; doi(dienap); inchuoi(chuoi); } break; } case 12: // nuùt taêng ñieän aùp { sound(3500); delay(50); nosound(); NutTG2(150,160,30,0); delay(100); NutTG2(150,160,30,1); if (dienap<25.5) { dienap=dienap+0.1; doi(dienap); inchuoi(chuoi); } if (dienap>=25.5) { dienap=25.5; doi(dienap); inchuoi(chuoi); } break; } case 13: // nuùt giaûm ñieän aùp max { sound(3500); delay(10); nosound(); NutTG1(450,310,30,0); delay(100); NutTG1(450,310,30,1); if (dienapmax>buocdienap) { dienapmax=dienapmax-0.1; doi_1(dienapmax); inchuoi_1(chuoi,317,310,340); } if (dienapmax<=buocdienap) { dienapmax=buocdienap; doi_1(dienapmax); inchuoi_1(chuoi,317,310,340); } break; } case 14: // nuùt taêng ñieän aùp max { sound(3500); delay(10); nosound(); NutTG2(490,310,30,0); delay(100); NutTG2(490,310,30,1); if (dienapmax<25.5) { dienapmax=dienapmax+0.1; doi_1(dienapmax); inchuoi_1(chuoi,317,310,340); } if (dienapmax>=25.5) { dienapmax=25.5; doi_1(dienapmax); inchuoi_1(chuoi,317,310,340); } break; } case 15: // nuùt giaûm böôùc ñieän aùp { sound(3500); delay(10); nosound(); NutTG1(450,360,30,0); delay(100); NutTG1(450,360,30,1); if (buocdienap>0.1) { buocdienap=buocdienap-0.1; doi_1(buocdienap); inchuoi_1(chuoi,367,360,390); } if (buocdienap<=0.1) { buocdienap=0.1; doi_1(buocdienap); inchuoi_1(chuoi,367,360,390); } break; } case 16: // nuùt taêng böôùc ñieän aùp { sound(3500); delay(10); nosound(); NutTG2(490,360,30,0); delay(100); NutTG2(490,360,30,1); if (buocdienap<2.5) { if ((dienapmax<2.5)&&(dienapmax==buocdienap)) { dienapmax=dienapmax+0.1; doi_1(dienapmax); inchuoi_1(chuoi,317,310,340); } buocdienap=buocdienap+0.1; doi_1(buocdienap); inchuoi_1(chuoi,367,360,390); } if (buocdienap>=2.5) { buocdienap=2.5; doi_1(buocdienap); inchuoi_1(chuoi,367,360,390); dienapmax=2.5; doi_1(dienapmax); inchuoi_1(chuoi,317,310,340); } break; } case 17: // nuùt giaûm toác ñoä { sound(3500); delay(10); nosound(); NutTG1(450,410,30,0); delay(100); NutTG1(450,410,30,1); if (tocdo>0.5) { tocdo=tocdo-0.1; doi_1(tocdo); inchuoi_1(chuoi,417,410,440); } if (tocdo<=0.5) { tocdo=0.5; doi_1(tocdo); inchuoi_1(chuoi,417,410,440); } break; } case 18: // nuùt taêng toác ñoä { sound(3500); delay(10); nosound(); NutTG2(490,410,30,0); delay(100); NutTG2(490,410,30,1); if (tocdo<25) { tocdo=tocdo+0.1; doi_1(tocdo); inchuoi_1(chuoi,417,410,440); } else tocdo=25; break; } case 19: // nuùt STOP { sound(3500); delay(50); nosound(); Doi_tt_Nut_Stop(); dienap=0; outp(ADD,0); doi(dienap); inchuoi(chuoi); break; } case 20: // nuùt daïng soùng 1 { int temp1,ax,ay,stop=0; long int dem=0; int poly1[]={30,328,33,325,33,355,75,325, 75,355,117,325,117,355,120,352}; int poly11[]={31,329,34,326,34,356,76,326, 76,356,118,326,118,356,121,353}; doi_tt1(25,310,125,370,8,poly11,0); delay(200); doi_tt1(25,310,125,370,8,poly1,1); ShowMouse(); while( !stop ) { lpEvent=GetEvent(); if (lpEvent->Msg==M_LEFT) { ax=lpEvent->Posx;ay=lpEvent->Posy; Release(M_LEFT); if ((ax>=355)&&(ax=310)&&(ay<=440)) //Toa do nut Stop { stop=1; HideMouse(); Doi_tt_Nut_Stop(); ShowMouse(); } } dienap=0; while(dienap<dienapmax) { if (dem<=tocdo*2500000) { dem++; } else { dem=0; dienap=dienap+buocdienap; doi(dienap); inchuoi(chuoi); tem1=dienap*10; outp(ADD,tem1); } } } break; } case 21: // nuùt daïng soùng 2 { long int dem=0; int ax,ay,temp21,temp22,stop=0; int poly2[]={140,355,180,325,220,355,230,350}; int poly22[]={141,356,181,326,221,356,231,351}; doi_tt1(135,310,235,370,4,poly22,0); delay(200); doi_tt1(135,310,235,370,4,poly2,1); dienap=0; doi(dienap); inchuoi(chuoi); outp(ADD,0); ShowMouse(); while(!stop) { lpEvent=GetEvent(); if (lpEvent->Msg==M_LEFT) { ax=lpEvent->Posx;ay=lpEvent->Posy; Release(M_LEFT); if ((ax>=355)&&(ax=310)&&(ay<=440)) //Toa do nut Stop { stop=1; HideMouse(); Doi_tt_Nut_Stop(); ShowMouse(); } } dienap=0; doi(dienap); inchuoi(chuoi); //outp(ADD,0); while (dienap<dienapmax) { if (dem<=tocdo*1700000) { dem++; } else { dem=0; dienap=dienap+buocdienap; if (dienap>=dienapmax) dienap=dienapmax; doi(dienap); inchuoi(chuoi); temp21=dienap*10; outp(ADD,temp21); } } dienap=dienapmax; doi(dienap); inchuoi(chuoi); temp5=dienap*10; outp(ADD,temp5); while (dienap > 0) { if (dem<=tocdo*1700000) { dem++; } else { dem=0; dienap=dienap-buocdienap; if (dienap<=0) dienap=0; doi(dienap); inchuoi(chuoi); temp22=dienap*10; outp(ADD,temp22); } } } break; } case 22: // nuùt daïng soùng 3 { long int dem=0; int temp3,ax,ay,stop=0; int poly3[]={250,352,253,355,253,325,295,355, 295,325,337,355,337,325,340,328}; int poly33[]={251,353,254,356,254,326,296,356, 296,326,338,356,338,326,341,329}; doi_tt1(245,310,345,370,8,poly33,0); delay(200); doi_tt1(245,310,345,370,8,poly3,1); ShowMouse(); while(!stop) { lpEvent=GetEvent(); if (lpEvent->Msg==M_LEFT) { ax=lpEvent->Posx;ay=lpEvent->Posy; Release(M_LEFT); if ((ax>=355)&&(ax=310)&&(ay<=440)) //Toa do nut Stop { stop=1; HideMouse(); Doi_tt_Nut_Stop(); ShowMouse(); } } dienap=dienapmax; doi(dienap); inchuoi(chuoi); temp3=dienap*10; outp(ADD,temp3); while (dienap>0) { if (dem<=tocdo*2500000) { dem++; } else { dem=0; dienap=dienap-buocdienap; doi(dienap); inchuoi(chuoi); temp3=dienap*10; outp(ADD,temp3); if (dienap<=0) { dienap=0; doi(dienap); inchuoi(chuoi); outp(ADD,0); } } } } break; } case 23: // nuùt daïng soùng 4 { long int dem=0; int temp4; int poly4[]={30,425,50,425,100,395,120,395}; int poly44[]={31,426,51,426,101,396,121,396}; doi_tt1(25,380,125,440,4,poly44,0); delay(200); doi_tt1(25,380,125,440,4,poly4,1); dienap=0; doi(dienap); inchuoi(chuoi); outp(ADD,0); while (dienap<dienapmax) { if (dem<=tocdo*1700000) { dem++; } else { dem=0; dienap=dienap+buocdienap; if (dienap>=dienapmax) dienap=dienapmax; doi(dienap); inchuoi(chuoi); temp4=dienap*10; outp(ADD,temp4); } } break; } case 24: // nuùt daïng soùng 5 { int temp5; long int dem=0; int poly5[]={140,395,160,395,210,425,230,425}; int poly55[]={141,396,161,396,211,426,231,426}; doi_tt1(135,380,235,440,4,poly55,0); delay(200); doi_tt1(135,380,235,440,4,poly5,1); dienap=dienapmax; doi(dienap); inchuoi(chuoi); temp5=dienap*10; outp(ADD,temp5); while (dienap > 0) { if (dem<=tocdo*1700000) { dem++; } else { dem=0; dienap=dienap-buocdienap; if (dienap<=0) dienap=0; doi(dienap); inchuoi(chuoi); temp5=dienap*10; outp(ADD,temp5); } } break; } case 25: // nuùt daïng soùng 6 { int temp6,ax,ay,stop=0; int flag=0; int poly6[]={250,425,258,425,258,395,273,395, 273,425,288,425,288,395,303,395,303,425, 318,425,318,395,333,395,333,425,340,425}; int poly66[]={251,426,259,426,259,396,274,396, 274,426,289,426,289,396,304,396,304,426, 319,426,319,396,334,396,334,426,341,426}; long int dem=0; doi_tt1(245,380,345,440,14,poly66,0); delay(200); doi_tt1(245,380,345,440,14,poly6,1); ShowMouse(); while(!stop) { lpEvent=GetEvent(); if (lpEvent->Msg==M_LEFT) { ax=lpEvent->Posx;ay=lpEvent->Posy; Release(M_LEFT); if ((ax>=355)&&(ax=310)&&(ay<=440)) //Toa do nut Stop { stop=1; HideMouse(); Doi_tt_Nut_Stop(); ShowMouse(); } } if (dem<=tocdo*170000) { dem++; } else { dem=0; flag=!flag; if (flag) { doi(dienapmax); inchuoi(chuoi); temp6=dienapmax*10; outp(ADD,temp6); } else { doi(0); inchuoi(chuoi); outp(ADD,0); } } } break; } case 26: // nuùt GIAÙ TRÒ { sound(3500); delay(10); nosound(); doi_tt3(250,140,350,190,0); delay(200); doi_tt3(250,140,350,190,1); tam=dienap*10; outp(ADD,tam); break; } case 27: // nuùt TRÔÏ GIUÙP { sound(3500); delay(10); nosound(); Help(); Giaodien(); break; } case 28: // nuùt Thoaùt treân goùc traùi maøn hình { sound(3500); delay(10); nosound(); thuhep("LUAN VAN TOT NGHIEP - KHOA : 1995 - 2000 - LOP : 95KDD "); closegraph(); return; } case 29: // Nuùt THOAÙT { sound(3500); delay(10); nosound(); thuhep("LUAN VAN TOT NGHIEP - KHOA : 1995 - 2000 - LOP : 95KDD "); closegraph(); return; } case 30: // Nuùt GIÔÙI THIEÄU { sound(3500); delay(10); nosound(); Gioi_Thieu(); Giaodien(); break; } case 31: // phím ESC { sound(3500); delay(10); nosound(); thuhep("LUAN VAN TOT NGHIEP - KHOA : 1995 - 2000 - LOP : 95KDD "); closegraph(); return; } } } while (1); }

Các file đính kèm theo tài liệu này:

  • docLUANVAN.DOC
  • bmp02.BMP
  • bmp04.BMP
  • bmp126.BMP
  • bmp138.BMP
  • bmp244.BMP
  • bmp245.BMP
  • bmp373.BMP
  • bmp4040.BMP
  • datCAT1.DAT
  • datCAT2.DAT
  • datCAT3.DAT
  • datCAT4.DAT
  • datCAT5.DAT
  • bgiEGAVGA.BGI
  • cppLVTN.CPP
  • exeLVTN.EXE
  • objLVTN.OBJ
  • schMODUN1.SCH
  • schMODUN2A.SCH
  • schMODUN2B.SCH
  • schMODUN2C.SCH
  • schMODUN3.SCH
  • schMODUN4.SCH
  • schMODUN5.SCH