วันพฤหัสบดีที่ 8 กรกฎาคม พ.ศ. 2553

การเขียนโปรแกรมผ่านบอร์ด p-master ด้วย MSW-logo เพื่อควบคุม Data Port

ชุดสื่อ P-Master
เป็นบอร์ดอิเล็กทรอนิกส์ที่ทำหน้าที่เป็นอินพุทและเอาท์พุทของคอมพิวเตอร์ผ่านทางพอร์ตขนาน (Printer) เบื้องต้น เพื่อฝึกการเขียนโปรแกรมเชิงควบคุมอย่างง่าย สามารถนำไปประยุกต์เป็นโครงงานต่าง ๆ เช่น โครงงานควบคุมการเปิด-ปิดไฟฟ้าด้วยคอมพิวเตอร์, โครงงานสัญญาณกันขโมย, โครงงานเครื่องรดน้ำอัตโนมัติ ฯลฯ
คุณสมบัติ
- เชื่อมต่อกับคอมพิวเตอร์ผ่าน DB-25 (pin)
ขนาด 9.5 x 13 cm. (กว้าง ยาว)
- ใช้กับหม้อแปลงแรงดันไฟ 12V.
- รองรับการเขียนโปรแกรมผ่าน Data Port, Status Port และControl Port พร้อมไฟ LED แสดงสถานะ
- รองรับระบบปฏิบัติการ Dos, Windows95, Windows98, WinME, Windows 2000, Windows XP, Linux ฯลฯ
- ใช้กับคอมไพล์เลอร์ทุกตัวที่มีฟังก์ชันติดต่อกับ Parallel Port เช่น Java, C, C++, Pascal, VB ฯลฯ

การเปิดโปรแกรม Mswlogo Outport
การเรียกโปรแกรม Mswlogo Outport จะคล้ายกับ Mswlogo
เพียงแต่ให้ไปคลิกที่ไอคอน LogoOutport แทน
เมื่อเปิดโปรแกรมได้แล้วให้ทดสอบ โดยการพิมพ์
Outport 888 0 (ในกรณีที่มีไฟติดอยู่) หรือ
Outport 888 1 (ในกรณีที่ไฟดับ)
ถ้าผลลัพธ์ได้ตรงข้ามแสดงว่าใช้โปรแกรมได้แล้ว

ให้เปิด Notepad แล้วสร้างกระบวนความ ชื่อ Exam1
พิมพ์คำสั่งต่อไปนี้

to exam1
outport 888 0
outport 888 1 wait 30
outport 888 2 wait 30
outport 888 4 wait 30
outport 888 8 wait 30
outport 888 16 wait 30
outport 888 32 wait 30
outport 888 64 wait 30
outport 888 128 wait 30
outport 888 0 wait 30
outport 888 255 wait 30
outport 888 0
end

หากพิมพ์ code โปรแกรมได้ถูกต้อง ไฟ LED ที่
P-Master จะดับหมด แล้วจะติดทีละดวงตั้งแต่ดวงที่ 1 ถึงดวงที่ 8 จากนั้นก็จะดับหมดอีกครั้ง แล้วก็จะติดหมดทั้ง 8 ดวง หากที่ช่อง Command Box ขึ้นข้อความ Error ก็ให้กลับไปแก้ code โปรแกรมใหม่ใน Editor

ทดสอบโปรแกรมต่อไปนี้ เพื่อดูผลลัพธ์ที่ได้

โปรแกรมไฟวิ่ง จาก D0 ==> D7 แล้วดับลง

to ledrun1
make "x 1
do.until [
outport 888 :x wait 30
make "x :x*2
][:x>128]
outport 888 0
end

โปรแกรมไฟวิ่งเป็นคู่ จากเริ่มเข้ามาจนหายออกไปจาก module เช่น 
D0->D0D1->D1D2->D2D3->D3D4->D4D5->D5D6->D6D7->D7
แล้วดับทั้งหมด

to ledrun2
outport 888 0
outport 888 1 wait 30
outport 888 3 wait 30
outport 888 6 wait 30
outport 888 12 wait 30
outport 888 24 wait 30
outport 888 48 wait 30
outport 888 96 wait 30
outport 888 192 wait 30
outport 888 128 wait 30
outport 888 0
end

โปรแกรมไฟวิ่งเป็นคู่เหมือนกับ โปรแกรม ledrun2 แต่วนแบบไม่มีที่สิ้นสุดด้วยเงื่อนไข do.until

to ledrun3
make "x 0
do.until [
outport 888 1 wait 30
outport 888 3 wait 30
outport 888 6 wait 30
outport 888 12 wait 30
outport 888 24 wait 30
outport 888 48 wait 30
outport 888 96 wait 30
outport 888 192 wait 30
outport 888 128 wait 30
outport 888 0 wait 30
][:x=1]
end

โปรแกรมไฟวิ่งเป็นคู่เหมือนกับ โปรแกรม ledrun3 แต่เพิ่มเสียง beep สั้นๆ เข้าไปทุกครั้ง

to ledrun4
make "x 0
do.until [
outport 888 1 beep wait 30
outport 888 3 beep wait 30
outport 888 6 beep wait 30
outport 888 12 beep wait 30
outport 888 24 beep wait 30
outport 888 48 beep wait 30
outport 888 96 beep wait 30
outport 888 192 beep wait 30
outport 888 128 beep wait 30
outport 888 0 beep wait 30
][:x=1]
end

to beep
sound [2000 50]
end

โปรแกรมแสดงนับถอยหลังบนจอแสดงผลพร้อมเสียงระหว่างนับ เมื่อถึง 0 ให้ไฟที่ LED กระพริบ 3 ครั้งพร้อมเสียงที่เปลี่ยนไป

to countdown
setlabelfont [[Times New Roman] -80 0 0 400 0 0 0 0 3 2 1 18]
cs ht
make "number 9
do.until [
cs pu setxy -20 0 rt 90
label :number beep1 wait 40
make "number :number-1
][:number=0]
cs pu setxy -20 0 rt 90
label :number
repeat 3 [outport 888 255 beep2 wait 10
outport 888 0 wait 5]
end

to beep1
sound [2000 50]
end

to beep2
sound [1000 50]
end

****โปรแกรมตั้งเวลาเปิด relay

to relay
setlabelfont [[Times New Roman] -100 0 0 400 0 0 0 0 3 2 1 18]
cs pu ht
make "y 0
do.until [
make "x item 4 time
cs setxy -200 0 rt 90
setpencolor [0 0 255]
label :x
if :x = "xx:xx:xx [outport 888 1]
if :x = "yy:yy:yy [outport 888 2]
if :x = "zz:zz:zz [outport 888 0]
][:y=1]
end



การประยุกต์ใช้คำสั่งโลโกสำหรับการบังคับรถ (อย่าลืม ต้องมีรถด้วย)
outport 888 0 หยุด
outport 888 1 เลี้ยวขวา
outport 888 2 ถอยซ้าย
outport 888 3 เลี้ยวขวา (เหมือน outport 888 1 )
outport 888 4 เลี้ยวซ้าย
outport 888 5 เดินหน้า
outport 888 6 ถอยซ้าย
outport 888 7 เดินหน้า
outport 888 8 ถอยขวา
outport 888 9 เลี้ยวขวาoutport 888 10 ถอยหลัง
อ้างอิง http://mikan-logoblog.blogspot.com/2010/01/msw-logo.html

0 ความคิดเห็น:

แสดงความคิดเห็น