Issuu on Google+

ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

l 1

ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿ 1. ʋǹ»ÃСͺ㹪ش ἧǧ¨Ã ZX-BLUETOOTH, ÊÒ JST3-8AA 2 àʌ¹, àÊÒÃͧ¾ÃŒÍÁÊ¡ÃÙÊÒí ËÃѺµÔ´µÑ§é áÅÐ àÍ¡ÊÒûÃСͺ¡ÒÃ㪌§Ò¹

2. ¤Ø³ÊÁºÑµ·Ô ҧ෤¹Ô¤ l 㪌âÁ´ÙÅ MB-CB04 ºÅÙ·¸ ٠ẺÊàÅ¿ (໚¹µÑÇÅÙ¡) ¤ÅÒÊ 2 ÁÕÃËÑÊ»ÃШíÒµÑÇ੾ÒÐ

ÁÕÊÒÂÍÒ¡ÒÈã¹µÑÇ l ÃÑÈÁÕ·Òí ¡ÒÃÊÙ§ÊØ´ 30 àÁµÃ l ÃͧÃѺ¡Ò÷íҧҹẺ¾Íϵ͹ءÃÁËÃ×Í SPP (Serial Port Profile) l ÍѵÃÒàÃçÇ㹡Òö‹Ò·ʹ¢ŒÍÁÙÅËÃ×ÍÍѵÃҺʹ 9,600 ºÔµµ‹ÍÇÔ¹Ò·Õ ÃٻẺ¢ŒÍÁÙÅ 8N1 (8 ºÔµ¢ŒÍÁÙÅ äÁ‹Á¡Õ ÒõÃǨÊͺ¾ÒÃÔµÕé áÅÐ 1 ºÔµËÂØ´) l ÁÕ¨´ Ø µ‹Í TxD ÊíÒËÃѺʋ§¢ŒÍÁÙÅÍÍ¡ áÅÐ RxD ÊíÒËÃѺÃѺ¢ŒÍÁÙÅ͹ءÃÁ l 㪌§Ò¹ä´Œ¡º Ñ äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ䴌·¡Ø µÃСÙÅ â´Âá¹Ð¹íÒãˌµ´Ô µ‹Í¼‹Ò¹·Ò§âÁ´ÙÅ UART ¢Í§äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ (µ‹Í TxD ¢Í§ ZX-BLUETOOTH ࢌҡѺ RxD ¢Í§äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ áÅе‹Í RxD ¢Í§ ZX-BLUETOOTH ࢌҡѺ TxD ¢Í§äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ) l ÁÕ¢Ç Ñé µ‹ÍẺ JST ÊÒÁÒöàª×Íè Áµ‹Í¡Ñºá¼§Ç§¨ÃäÁâ¤Ã¤Í¹â·ÃÅàÅÍϢͧ inex 䴌·¹Ñ ·Õ l ÁÕ¨´ Ø µ‹ÍẺÍÔÊÃÐà¾×Íè ÃͧÃѺ¡Ñºá¼§Ç§¨Ã·Õ¼è ãٌ ªŒ§Ò¹·íÒ¢Ö¹é àͧ l 㪌ä¿àÅÕÂ é § +5V º¹á¼§Ç§¨ÃÁÕǧ¨Ã¤Çº¤ØÁä¿àÅÕÂé §¤§·Õ·è Õè +3.3V ÊíÒËÃѺàÅÕÂé §âÁ´ÙźÅÙ·¸Ù l ÊÒÁÒö㪌§Ò¹Ã‹ÇÁ¡ÑººÅÙ·¸ Ù ¢Í§¤ÍÁ¾ÔÇàµÍÏ·ÃÕè ͧÃѺ¡Ò÷íҧҹẺ SPP â´Â¡íÒ˹´ãˌºÅÙ ·Ù¸¢Í§¤ÍÁ¾ÔÇàµÍÏ໚¹ÍØ»¡Ã³ÁÒÊàµÍÏ (㪌䴌·§Ñé ¡ÑººÅÙ·¸Ù ẺµÔ´µÑ§é 㹤ÍÁ¾ÔÇàµÍÏáÅÐ USB ºÅÙ·¸Ù ) l ÊÒÁÒö㪌§Ò¹Ã‹ÇÁ¡ÑºâÁ´ÙźÅÙ·¸ Ù ESD02 áÅÐ ESD100 â´Â¡íÒ˹´ãˌ ESD02 ËÃ×Í ESD100 ໚¹ÁÒÊàµÍÏ l ¢¹Ò´ 3x4 ૹµÔàÁµÃ l


2 l ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

ÊÒÂÍÒ¡ÒÈ ä¿áÊ´§Ê¶Ò¹Ð ¡Ò÷íÒ§Ò¹

ZX-BLUETOOTH

56)675

ÃËÑÊ»ÃШíÒµÑǢͧ âÁ´ÙźÅÙ·¸Ù

+ TxD RxD GND

)!) ,#**

6N,

¨Ø´àª×Íè Áµ‹ÍẺ IDC µÑÇàÁÕÂ

4N,

¨Ø´àª×Íè Áµ‹ÍẺ JST µÑǼٌ TxD ¨Ø´Ê‹§¢ŒÍÁÙÅÍÍ¡¨Ò¡âÁ´ÙÅ RxD ¨Ø´ÃѺ¢ŒÍÁÙÅࢌÒâÁ´ÙÅ

ÃÙ»·Õè 1 ʋǹ»ÃСͺ·Ñ§é ËÁ´¢Í§ºÍÏ´ ZX-BLUETOOTH ʋǹ»ÃСͺ·Ñ§é ËÁ´¢Í§ºÍÏ´ ZX-BLUETOOTH áÊ´§ã¹ÃÙ»·Õè 1 ʋǹǧ¨ÃÊÁºÙóáÊ´§ ã¹ÃÙ»·Õè 2 +3.3V IC1 LM1117 MPX-3.3

Q1 KRA102S

+3.3V

Q2 KRC102S

K1 RxD

C1 10µF 16V

R1 10k

C2 10µF 16V +3.3V C4 0.1µF 16V

1 3 6

12 14

K2 TxD

R2 10k

GND GND

16 C5 0.1µF 16V

Q3 KRC102S

ÃÙ»·Õè 2 ǧ¨ÃÊÁºÙó¢Í§ºÍÏ´ ZX-BLUETOOTH

C7 0.3pF

RESET

TxD

17

STATUS

24 LED1 BLUE

RxD

+3.3V Q4 KRA102S

C6 10pF

34 GND 33 ANT GND 32

MD1 MB-C04 Bluetooth Module

R3 120k

+3.3V

Antenna

C3 0.1µF 16V

Vcc (3.3V) GND

R4 1k

C8 0.3pF


ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

l 3

3. ¡ÒÃ㪌§Ò¹¡ÑººÍÏ´äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏà¾×Íè µÔ´µ‹Í¡Ñº¤ÍÁ¾ÔÇàµÍÏ 3.1 㪌§Ò¹¡Ñº i-Stamp ËÃ×ÍàºÊÔ¡áʵÁ»Š 2SX 3.1.1 à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ (1) ºÍÏ´ Stamp-BOX, SCi-BOX, JS-2SX ·ÕÁè ¡Õ ÒõԴµÑ§é i-Stamp áÅŒÇ ËÃ×ÍÊÌҧǧ¨Ãàª×Íè Áµ‹Íàͧ (2) USB ºÅÙ·¸Ù ´Í§à¡ÔŠ㹡óշ¤Õè ÍÁ¾ÔÇàµÍÏäÁ‹ÁÇÕ §¨ÃºÅÙ·¸Ù (3) ZX-BLUETOOTH ¾ÃŒÍÁÊÒÂàª×Íè Áµ‹Í

3.1.2 ¡ÒÃàª×Íè Áµ‹Í·Ò§ÎÒÏ´áÇÏ ã¹ÃÙ»·Õè 3 áÊ´§¡ÒÃàª×èÍÁµ‹Í·Ò§ÎÒÏ´áÇÏà¾×èÍ㪌§Ò¹ ZX-BLUETOOTH ¡Ñº i-Stamp áÅÐ ¤ÍÁ¾ÔÇàµÍÏ ã¹µÑÇÍ‹ҧ¹Õµé ͋ P0 ¡Ñº TxD áÅÐ P1 µ‹Í¡Ñº RxD ¢Í§ ZX-BLUETOOTH àÊÕº USB Bluetooth Dongle ࢌҡѺ¾Íϵ USB *

ÃÐÂзíÒ¡ÒÃÊÙ§ÊØ´ 30 àÁµÃ (ã¹¾×¹é ·Õâè ŋ§áÅÐÍÒ¨µŒÍ§à¾ÔÁè ¤ÇÒÁÂÒÇ ¢Í§ÊÒÂÍÒ¡ÒÈ)

A P0

BASIC Stamp2SX interpreter

P7

P3

RxD

P5

P4 P8

TxD

P6

P9

P2

i-Stamp

RESET

ANALOG-6 ANALOG-4 ANALOG-2 ANALOG-0

ANALOG-7 ANALOG-5 ANALOG-3 ANALOG-1

P1

B

Stamp-BOX

)!) ,#**

+ TxD RxD GND

P11-PIEZO

STATUS

ZX-BLUETOOTH

ON

POWER

MOTOR

RS-232

+V

DIRECT INVERT DIRECT INVERT

* ¶ŒÒ¤ÍÁ¾ÔÇàµÍÏÁÇÕ §¨ÃºÅÙ·¸Ù ã¹µÑÇ ÊÒÁÒö¢ŒÒÁ¢Ñ¹é µÍ¹¹Õäé »ä´Œ

ºÍÏ´ Stamp-BOX ËÃ×Í SCi-BOX ËÃ×ͺÍÏ´ JX-2SX plusII (µŒÍ§µÔ´µÑ§é i-Stamp änj´ÇŒ Â) ÊíÒËÃѺ¢Ò¾ÍϵÊÒÁÒöà»ÅÕÂè ¹á»Å§ä´ŒµÒÁµŒÍ§¡ÒÃ

ÃÙ»·Õè 3 ¡Òõ‹Í㪌§Ò¹ ZX-BLUETOOTH ¡Ñº i-Stamp äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ


4 l ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

3.1.3 àµÃÕÂÁ¡ÒÃ㪌§Ò¹¡Ñº USB ºÅÙ·¸Ù ´Í§à¡ÔÅÊíÒËÃѺ¤ÍÁ¾ÔÇàµÍÏ USB ºÅÙ·¸Ù ´Í§à¡ÔÅÊíÒËÃѺ¤ÍÁ¾ÔÇàµÍÏ·¨Õè йíÒÁÒ·´Êͺ㪌§Ò¹ã¹·Õ¹è àÕé »š¹Ãع‹ ·Õãè ªŒ«Í¿µáÇÏ ¨Ñ´¡ÒÃàª×Íè Áµ‹ÍËÃ×Í Bluetooth Connection Management ª×Íè BlueSoleil ¾Ñ²¹Òâ´Â IVT Corporation «Ö§è â´Â»¡µÔ¨ÐÁÕÁҾÌÍÁ¡ÑºµÑÇ USB ºÅÙ·¸Ù ´Í§à¡ÔÅ Í‹ҧäáçµÒÁ ZX-BLUETOOTH ÊÒÁÒö㪌§Ò¹ ¡Ñº«Í¿µáÇϵÇÑ Í×¹è ¢Í§ USB ºÅÙ·¸Ù ´Í§à¡ÔÅÃع‹ Í×¹è æ 䴌 à¾Õ§µÔ´µÑ§é â»Ãá¡ÃÁä´ÃàÇÍÏãˌàËÁÒÐÊÁ «Ö§è ÇÔ¸¡Õ ÒõԴµÑ§é ä´àÇÍÏäÁ‹¢Í¡Å‹ÒǶ֧㹷չè Õé ¢ŒÍÁÙÅà¾ÔÁè àµÔÁ¢Í§«Í¿µáÇÏ BlueSoleil ÊÒÁÒö´Ù䴌·Õè www.bluesoleil.com ¡ÒÃ͸ԺÒÂã¹àÍ¡ÊÒùըé СŋÒǶ֧¡ÒÃ㪌àÁ¹ÙẺ¡ÃЪѺ¢Í§ BlueSoleil ෋ҹÑé¹à¾×èÍãˌàËç¹ á¹Ç·Ò§ã¹¡ÒÃ㪌§Ò¹áÅлÃѺ㪌¡ÑºUSB ºÅٷٸ´Í§à¡ÔÅÊíÒËÃѺ¤ÍÁ¾ÔÇàµÍϨҡ¼ÙŒ¼ÅÔµÍ×è¹æ

3.1.4 ¡ÒÃ㪌§Ò¹â»Ãá¡ÃÁ BlueSoleil à¾×Íè µÔ´µ‹Í¡Ñº ZX-BLUETOOTH 3.1.4.1 ËÅѧ¡ÒõԴµÑ§é â»Ãá¡ÃÁä´àÇÍϢͧ BlueSoleil ໚¹·Õàè ÃÕºÌÍÂáŌǨлÃÒ¡¯äͤ͹ ¢Í§â»Ãá¡ÃÁãˌºÃÔ¡Òõ‹Ò§æ¢Í§ USB ºÅÙ·¸Ù ´Í§à¡ÔÅ 3.1.4.2 àÁ×èͼٌ¾Ñ²¹ÒµŒÍ§¡ÒÃ㪌§Ò¹ºÃÔ¡Òõ‹Ò§æ ¢Í§USB ºÅٷٸ´Í§à¡ÔÅÊÒÁÒöࢌҶ֧â´Â ¡ÒôѺàºÔÅê ¤ÅÔ¡·Õäè ͤ͹

«Ö§è ¨Ðແ´Ë¹ŒÒµ‹Ò§ËÅÑ¡¢Í§¡ÒèѴ¡ÒÃàª×Íè Áµ‹Í¢Ö¹é ÁÒµÒÁÃÙ»·Õè 4

ÃÙ»·Õè 4 áÊ´§Ë¹ŒÒµ‹Ò§ My Bluetooth Places ÊíÒËÃѺࢌҶ֧ºÃÔ¡Òõ‹Ò§æ¢Í§ USB ºÅÙ·¸Ù ´Í§à¡ÔÅ


ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

l 5

»Ø†Á·Ã§¡ÅÁÊÕʌÁ·ÕèÍÂً¡Ö觡ÅÒ§¢Í§Ë¹ŒÒµ‹Ò§à»š¹ÊÑ­Åѡɳá·¹¤ÍÁ¾ÔÇàµÍϢͧ¼ÙŒ ¾Ñ²¹Ò«Ö觡íÒÅѧ㪌§Ò¹ USB ºÅٷٸ´Í§à¡ÔÅÍÂً㹢³Ð¹Õé ʋǹᶺÃÒ¡ÒúÃÔ¡Òõ‹Ò§æ¨ÐáÍ¡µÕ¿ (»ÃÒ¡¯¡ÃͺÊÕàËÅ×ͧ·ÕÃè Ò¡Òùѹé ) µÒÁª¹Ô´¢Í§ÍØ»¡Ã³ºÅÙ·¸Ù 3.1.4.3 ¨‹ÒÂä¿ãˌᡋ ZX-BLUETOOTH «Ö觨Ð䴌ä¿àÅÕ駨ҡ¨Ø´àª×èÍÁµ‹Í¡ÑººÍÏ´äÁâ¤Ã ¤Í¹â·ÃÅàÅÍÏ 3.1.4.4 ¨Ò¡ËÑÇ¢ŒÍ 3.1.4.2 àÁ×Íè ແ´Ë¹ŒÒµ‹Ò§ËÅÑ¡¢Í§â»Ãá¡ÃÁ ¼Ù¾Œ ² Ñ ¹ÒÊÒÁÒö¤Œ¹ËÒÍØ»¡Ã³ ºÅÙ·¸Ù Ãͺ¢ŒÒ§ã¹ÃÑÈÁÕ·Õè USB ºÅÙ·¸Ù ´Í§à¡ÔÅʹѺʹع â´Â¤ÅÔ¡·Õ»è Á؆ ·Ã§¡ÅÁÊÕÊÁŒ à¾×Íè àÃÔÁè µŒ¹¡Ò䌹 ËÒ ËÅѧ¨Ò¡¡Ò䌹ËÒÊÔé¹Êشŧ¨Ð»ÃÒ¡¯ÃÒª×èÍÍØ»¡Ã³ºÅٷٸµ‹Ò§æ·Õ辺µÒÁÃÙ»·Õè 5â´Â¨ÐÁÕÃÙ» ÍØ»¡Ã³ª¹Ô´¹Ñé¹»ÃÒ¡¯¢Ö鹾ÌÍÁ¡ÑºàÅ¢áÍ´à´ÃÊ ËÅѧ¨Ò¡¡Ò䌹ËÒÍØ»¡Ã³ËÂشŧ â»Ãá¡ÃÁ¨Ð àÃÔÁè ͋ҹª×Íè ¢Í§ÍØ»¡Ã³ ª×Íè ¢Í§ ZX-BLUETOOTH ·Õ¾è º¨Ð໚¹ “BT GPS” ËÁÒÂàËµØ ã¹¡Ò䌹ËÒÍØ»¡Ã³ºÅÙ·¸Ù Ãͺ¢ŒÒ§¤ÃÑ§é µ‹Íä» ¼Ù¾Œ ² Ñ ¹ÒÊÒÁÒöà¤ÅÕÂÏ ÃÒª×Íè ÍØ»¡Ã³à´ÔÁà¾×Íè ¤Œ¹ËÒÍØ»¡Ã³ºÅÙ·¸Ù ¤Ãѧé ãËÁ‹â´Â¡ÒäÅÔ¡àÅ×Í¡àÁ¹Ù¤Òí Êѧè View>Refresh Device ËÃ×Í¡´»ØÁ† F5 Í‹ҧã´Í‹ҧ˹֧è

ÃÙ»·Õè 5 áÊ´§¡Ò䌹¾ºÍØ»¡Ã³ºÅٷٸ â´ÂÁÕ¡ÒÃáÊ´§áÍ´à´ÃʢͧÍØ»¡Ã³·ÕèµÃǨ¾º¢Öé¹ÁÒ¡‹Í¹ ¨Ò¡¹Ñ¹é ¨Ö§áÊ´§ª×Íè ¢Í§ÍØ»¡Ã³¹¹Ñé æ ã¹ÅíҴѺµ‹Íä»


6 l ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

ÃÙ»·Õè 6 áÊ´§¡ÒèѺ¤Ù‹ (Pair) ÃÐËNjҧÍØ»¡Ã³ÁÒÊàµÍÃã¹·Õ¹è ¤Õé Í× ¤ÍÁ¾ÔÇàµÍÏ áÅÐÍØ»¡Ã³ÊàÅ¿ «Ö§è ¡ç¤Í× ZX-BLUETOOTH (㹪×Íè BT GPS) 3.1.4.5 ¡‹Í¹¡ÒõԴµ‹Í¡ÑºÍØ»¡Ã³Í¹×è æ ¨ÐµŒÍ§ÁÕ¡ÒèѺ¤Ù‹ (Pair) ÃÐËNjҧÍØ»¡Ã³ÁÒÊàµÍÏáÅÐ ÊàÅ¿ 㹡óչÕé¤ÍÁ¾ÔÇàµÍϨÐ໚¹µÑÇÁÒÊàµÍÏáÅÐ ZX-BLUETOOTH ໚¹ÊàÅ¿ ¡ÒèѺ¤Ù‹·íÒâ´Â ¤ÅÔ¡àÁÒʏ¢ÇÒ·ÕÍè »Ø ¡Ã³àÅ×Í¡ Pair Device ´Ñ§ÃÙ»·Õè 6 3.1.4.6 ¨Ò¡¹Ñ¹é ˹ŒÒµ‹Ò§ãʋÃËÑʼ‹Ò¹ÊíÒËÃѺ¡ÒèѺ¤Ù¨‹ ÐáÊ´§¢Ö¹é ÁÒ â´Â·ÑÇè ä»ÃËÑʼ‹Ò¹ÁÑ¡¨Ð ໚¹àÅ¢ “0000” ËÃ×ÍáŌÇᵋ¼¼ÙŒ ÅÔµ¨Ð¡íÒ˹´ ÊíÒËÃѺµÑÇ ZX-BLUETOOTH ¹ÕÁé ÃÕ ËÑÊ໚¹ “0000” ᵋ µÑÇÍÑ¡É÷Õãè ʋ㹪‹Í§ÃËÑʨÐ໚¹ “*” ´Ñ§ÃÙ»·Õè 7

ÃÙ»·Õè 7 áÊ´§¡ÒÃãʋÃËÑʼ‹Ò¹à¾×Íè ¨Ñº¤Ù‹ ZX-BLUETOOTH (㹪×Íè BT GPS) ¡Ñº¤ÍÁ¾ÔÇàµÍÏ


ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

l 7

ÃÙ»·Õè 8 ·Õäè ͤ͹¢Í§ Serial Port Service ¨Ð»ÃÒ¡¯¡ÃͺÊÕàËÅ×ͧ¢Ö¹é ËÅѧ¨Ò¡·ÕÁè ¡Õ ÒõÃǨÊͺ Service ¢Í§ ZX-BLUETOOTH (㹪×Íè BT_GPS) 3.1.4.7 ¤ÅÔ¡àÁÒʏ¢ÇÒ·ÕÍè »Ø ¡Ã³ BT GPS àÅ×Í¡ Refresh Services à¾×Íè µÃǨÊͺ Service ¢Í§ ZXBLUETOOTH ¨ÐàË繡ÃͺÊÕàËÅ×ͧ¢Ö¹é ÍÂÙ·‹ Õè Bluetooth Serial Port Service ´Ñ§ÃÙ»·Õè 8 ·íÒãˌÊÒÁÒöÃѺ ʋ§¢ŒÍÁÙż‹Ò¹¾Íϵ͹ءÃÁ䴌 â´Â㪌ÊÒÂÊÑ­­Ò³ 2 ÊÑ­­Ò³¤×Í TxD áÅÐ RxD 3.1.4.8 ·íÒ¡ÒÃàª×Íè Áµ‹Í¡Ñº ZX-BLUETOOTH ´ŒÇ Bluetooth Serial Port Service â´Â¡ÒäÅÔ¡ ·ÕÃè »Ù ¾Íϵ͹ءÃÁÊÕàËÅ×ͧ´ŒÒ¹º¹ ËÃ×ͤÅÔ¡àÁÒʏ¢ÇÒ·Õè BT GPS àÅ×Í¡ Connect > Bluetooth Serial Port Service ´Ñ§ÃÙ»·Õè 9


8 l ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

ÃÙ»·Õè 9 áÊ´§¡ÒÃàª×Íè Áµ‹Í ZX-BLUETOOTH (㹪×Íè BT GPS) ¡Ñº Bluetooth Serial Port Service 3.1.4.9 àÁ×Íè àª×Íè Áµ‹ÍÊíÒàÃ稨ÐÁÕ˹ŒÒµ‹Ò§ºÍ¡ËÁÒÂàÅ¢¾Íϵ͹ءÃÁ¨íÒÅͧ·ÕÊè Ìҧ¢Ö¹é ¾ÃŒÍÁ¡Ñº ¶ÒÁNjҵŒÍ§¡ÒÃãˌàª×Íè Áµ‹Í¾Íϵ͹ءÃÁ¨íÒÅͧ¹Õãé ËŒÍµÑ â¹ÁѵàÔ Á×Íè ÁÕ¡ÒÃàÃÕ¡㪌¾Íϵ¨Ò¡â»Ãá¡ÃÁÍ×¹è ËÃ×ÍäÁ‹ ¡´ No à¾×Íè äÁ‹ãˌàª×Íè Áµ‹ÍÍѵâ¹ÁÑµÔ ÃÙ»·Õè 10

ÃÙ»·Õè 10 ˹ŒÒµ‹Ò§á¨Œ§¡ÒÃàª×Íè Áµ‹ÍÊíÒàÃç¨ «Ö§è ¨Ðᨌ§ËÁÒÂàÅ£¢Í§¾Íϵ͹ءÃÁ¨íÒÅͧ¢Í§ÍØ»¡Ã³ºÅÙ·¸Ù ·Õ¹è Òí ÁÒµÔ´µ‹Í´ŒÇ ¨Ò¡ÃÙ»¤×Í COM11


ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

l 9

3.1.5 µÑÇÍ‹ҧ¡ÒÃ㪌§Ò¹ ZX-BLUETOOTH ¡Ñº i-Stamp ´ŒÇºÍÏ´ SCi-BOX 3.1.5.1 µÑÇÍ‹ҧ·Õè 1 ¡ÒÃÃѺʋ§¢ŒÍÁÙÅÃÐËNjҧ i-Stamp ¡Ñº¤ÍÁ¾ÔÇàµÍÏ ¼‹Ò¹ ZX BLUETOOTH áÅÐ USB ºÅÙ·¸Ù ´Í§à¡ÔÅ à¹×Íè §¨Ò¡ ZX-BLUETOOTH äÁ‹µÍŒ §ãªŒ¤Òí Êѧè 㹡ÒäǺ¤ØÁ¡Ò÷íÒ§Ò¹ã´æ ÊÒÁÒöÃѺáÅÐʋ§ ¢ŒÍÁÙÅ͹ءÃÁ¼‹Ò¹ÊÑ­­Ò³ºÅÙ·¸Ù ´ŒÇ Serial Port Profile ä´ŒÍµÑ â¹ÁѵËÔ Åѧ¨Ò¡àª×Íè Áµ‹ÍÍØ»¡Ã³ºÅÙ·¸Ù µÑÇáÁ‹áÅŒÇ ¤íÒÊÑ§è ·Õãè ªŒã¹¡ÒÃÃѺʋ§¢ŒÍÁÙÅ͹ءÃÁ¢Í§ i-Stamp ¡Ñº ZX-BLUETOOTH ¤×Í SERIN ÊíÒËÃѺ ÃѺ¢ŒÍÁÙÅ áÅÐ SEROUT ÊíÒËÃѺʋ§¢ŒÍÁÙż‹Ò¹ ZX-BLUETOOTH ÃٻẺ¡ÒÃµÑ§é ¤‹Ò¢Í§¡ÒÃʋ§¢ŒÍÁÙÅ͹ءÃÁ¤×Í ÍѵÃҺʹ (BaudRate) 9600 bps ¤ÇÒÁÂÒÇ¢ŒÍÁÙÅ 8 ºÔµ ºÔµËÂØ´ 1 ºÔµ äÁ‹Á¾Õ ÒÃÔµºÕé µÔ ÊÒÁÒö¤íҹdz໚¹¤‹Ò¾ÒÃÒÁÔàµÍÏÊÒí ËÃѺ¤íÒÊѧè SERIN áÅÐ SEROUT 䴌໚¹ 240 3.1.5.1.1 àª×Íè Áµ‹Í SCi-BOX ¡Ñº ZX-BLUETOOTH ´Ñ§ÃÙ»·Õè 11 3.1.5.1.2 à¢Õ¹â»Ãá¡ÃÁ·Õè 1 áŌǴÒǹâËÅ´â»Ãá¡ÃÁä»Âѧ i-Stamp

POWER DC. IN 6-16V

SCi-BOX

P12 SOUND

SENSOR3

P11 P10

P9

P3

#2

SENSOR2 SENSOR1 SENSOR0

Stepper motor Co-processor

P4

ADC

Co-processor

P8

Fit jumper at RELAY position to select Relay driver circuit

RELAY

+ TxD RxD GND

P13 : A/D

000A3A 21D5BB

TxD

RxD

P2

SENSOR4

ZX-BLUETOOTH

i-Stamp

P5

RESET

MOTOR

P1

SENSOR5

#1

STATUS

P0

SENSOR6

ADC

Co-processor

BASIC Stamp in Science Experiment

P6

SENSOR7

ON

P7

SERIAL PORT

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

RELAY 12V 5A

STEPPER MOTOR1

P11 RELAY P10 RELAY

P9 RELAY

P8 RELAY

MOTOR A

B

INV-A

INV-B

P8-P9 MotorA P10-P11 MotorB

ON

ÃÙ»·Õè 11 ¡ÒÃàª×Íè Áµ‹Í SCi-BOX ¡Ñº ZX-BLUETOOTH à¾×Íè ·´Êͺ¡ÒÃÃѺʋ§¢ŒÍÁÙšѺ¤ÍÁ¾ÔÇàµÍÏ


10 l ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

3.1.5.1.3 ´ŒÒ¹¤ÍÁ¾ÔÇàµÍÏ·ãÕè ªŒã¹¡ÒõԴµ‹Í¡Ñº SCi-BOX ãˌ·Òí ¡ÒÃແ´¡Ò÷íÒ§Ò¹¢Í§Ç§¨Ã ºÅÙ·¸Ù ¨Ò¡¹Ñ¹é ·íÒ¡ÒèѺ¤Ù¡‹ ºÑ ZX-BLUETOOTH ·Ò§½˜§› äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ áŌÇàª×Íè Áµ‹Í¼‹Ò¹·Ò§ Serial Port Service 3.1.5.1.4 ແ´â»Ãá¡ÃÁ HyperTerminal µÑ§é ¤‹Ò¾ÍϵãˌµÃ§¡Ñº¾Íϵ͹ءÃÁ¨íÒÅͧ·ÕÊè Ìҧ¢Ö¹é áŌǡíÒ˹´ÃٻẺ¡ÒÃÃѺʋ§¢ŒÍÁÙÅ໚¹ÍѵÃҺʹ 9600 ºÔµµ‹ÍÇÔ¹Ò·Õ 8 ºÔµ¢ŒÍÁÙÅ 1 ºÔµËÂØ´ áÅÐäÁ‹ ÁÕ¾ÒÃÔµÕé (8N1) 3.1.5.1.5 Ãѹâ»Ãá¡ÃÁ·Õºè ÍÏ´ SCi-BOX Êѧࡵ¼Å¡Ò÷í��§Ò¹¼‹Ò¹·Ò§Ë¹ŒÒµ‹Ò§ Hyper Terminal 

¡´¤ÕÂʏ §‹ ¢ŒÍÁÙŨҡ¤ÍÁ¾ÔÇàµÍÏ ·ÕËè ¹ŒÒµ‹Ò§ HyperTerminal ˹ŒÒµ‹Ò§ HyperTerminal '

!

¾Íϵ͹ءÃÁ¨íÒÅͧ ·Õàè ¡Ô´¨Ò¡ Serial Port Service

"

¢ŒÍÁÙŶ١ʋ§ÍÍ¡ÍÒ¡ÒÈ ä»Âѧ ZX-BLUETOOTH

&

áÊ´§¢ŒÍÁÙÅ·ÕËè ¹ŒÒµ‹Ò§ HyperTerminal

%

¢ŒÍÁÙŶ١ʋ§ÍÍ¡ÍÒ¡ÒÈ ä»ÂѧÍØ»¡Ã³ºÅÙ ·Ù¸·Ò§ ½˜§› ¤ÍÁ¾ÔÇàµÍÏ POWER DC. IN 6-16V

SCi-BOX

P12 SOUND

SENSOR3

P11 P10

P9

P3

#2

SENSOR2 SENSOR1 SENSOR0

Stepper motor Co-processor

P4

ADC

Co-processor

P8

Fit jumper at RELAY position to select Relay driver circuit

RELAY

RELAY 12V 5A

RELAY 12V 5A

TxD

RxD

$ MOTOR

RELAY 12V 5A

RELAY 12V 5A

STEPPER MOTOR1

P11 RELAY P10 RELAY

000A3A 21D5BB

+ TxD RxD GND

P13 : A/D

P2

SENSOR4

ZX-BLUETOOTH

i-Stamp

P5

RESET

P1

SENSOR5

#1

STATUS

P0

SENSOR6

ADC

Co-processor

BASIC Stamp in Science Experiment

P6

SENSOR7

ON

P7

SERIAL PORT

P9 RELAY

P8 RELAY

MOTOR A

B

INV-A

INV-B

P8-P9 MotorA P10-P11 MotorB

ON

#

¢ŒÍÁÙÅࢌÒÁÒä»Âѧ i-Stamp

ʋ§¢ŒÍÁÙŤ‹Ò¢Í§¤Õ· ÃÕè ºÑ ä´Œ ¡ÅѺ仾ÌÍÁ¡Ñº ÃËÑÊËÁÒÂàÅ¢¢ŒÍÁÙÅ

ÃÙ»·Õè 12 áÊ´§ÅíҴѺ¡Ò÷íÒ§Ò¹¢Í§¡ÒÃÃѺʋ§¢ŒÍÁÙÅ͹ءÃÁÃÐËNjҧ SCI-BOX ¡Ñº¤ÍÁ¾ÔÇàµÍϼҋ ¹·Ò§ ÍØ»¡Ã³ºÅÙ·¸Ù


ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

l 11

‘ {$STAMP BS2sx} ‘ {$PBASIC 2.5} TX CON 0 RX CON 1 BAUD CON 240 Ack VAR Byte i VAR Word main:SERIN RX,BAUD,[Ack] i = i+1 SEROUT TX, BAUD, [DEC4 i, “ “, Ack, CR, LF] GOTO main

¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ â»Ãá¡ÃÁ¹Õàé ºÊÔ¡áʵÁ»Š¨ÐÃѺ¢ŒÍÁÙŨҡâ»Ãá¡ÃÁ HyperTerminal ¼‹Ò¹·Ò§¾Íϵ͹ءÃÁ¨íÒÅͧ¢Í§ ºÅÙ·¸Ù ¨Ò¡à¤Ã×Íè §¤ÍÁ¾ÔÇàµÍÏ áŌǹíÒÁÒà¾ÔÁè ¤‹ÒµÑÇá»Ã i ¨Ò¡¹Ñ¹é ʋ§¤‹ÒµÑÇá»Ã i ª‹Í§Ç‹Ò§ ¢ŒÍÁÙÅ·ÕÃè ºÑ ä´ŒáÅеÑÇ ÍÑ¡¢ÃÐ Carrier Return à¾×Íè ¢Ö¹é ºÃ÷ѴãËÁ‹ ¡ÅѺ价Õàè ¤Ã×Íè §¤ÍÁ¾ÔÇàµÍÏà¾×Íè áÊ´§º¹Ë¹ŒÒµ‹Ò§ HyperTerminal

â»Ãá¡ÃÁ·Õè 1 â»Ãá¡ÃÁ·´Êͺ¡ÒÃÃѺʋ§¢ŒÍÁÙÅàº×Íé §µŒ¹ÃÐËNjҧ i-Stamp ¡Ñº¤ÍÁ¾ÔÇàµÍϼҋ ¹âÁ´ÙÅ ZXBLUETOOTH áÅÐÍØ»¡Ã³ºÅÙ·¸Ù º¹¤ÍÁ¾ÔÇàµÍÏ (ä¿Å EX_Pc01.bsx - ´ÒǹâËŴ䴌¨Ò¡ www.inex.co.th) ¡Ãкǹ¡Ò÷íÒ§Ò¹·Ñ§é ËÁ´áÊ´§ã¹ÃÙ»·Õè 11 àÁ×Íè àÃÔÁè µŒ¹Ë¹ŒÒµ‹Ò§¢Í§ Hyper Terminal ¨ÐNjҧ ¨Ò¡¹Ñ¹é ãˌ¡´¤ÕÂ㏠´æ ·Õ¤è ÂÕ º ÍÏ´¢Í§¤ÍÁ¾ÔÇàµÍÏ ã¹·Õ¹è ·Õé ´Åͧ¡´¤Õ a ¢ŒÍÁÙŢͧÍÑ¡Éà a ¨Ð¶Ù¡ ʋ§ÍÍ¡¨Ò¡¤ÍÁ¾ÔÇàµÍϼҋ ¹¾Íϵ͹ءÃÁ¨íÒÅͧ·Õàè ¡Ô´¨Ò¡ Service ¢Í§ºÅÙ·¸Ù ÍÍ¡ÍÒ¡ÒÈÁÒÂѧâÁ´ÙÅ ZX-BLUETOOTH áŌÇʋ§à¢ŒÒä»Âѧ i-Stamp ¨Ò¡¹Ñ¹é i-Stamp ¨Ðʋ§¢ŒÍÁÙÅà´ÔÁ¹Ñ¹é ¡ÅѺÁÒÂѧ¤ÍÁ¾ÔÇàµÍÏ ¾ÃŒÍÁ¡ÑºàÅ¢·Õ¢è ͧ¢ŒÍÁÙÅ «Ö§è ¨ÐÁÒ»ÃÒ¡¯·ÕËè ¹ŒÒµ‹Ò§¢Í§ Hyper Terminal ໚¹ 0001 a ËÁÒ¶֧ ÃѺ ¢ŒÍÁÙŵÑÇ·Õè 1 ໚¹µÑÇÍÑ¡Éà a ´Ñ§ÃÙ»·Õè 13 ¨Ò¡¹Ñ¹é ·´Åͧʋ§¤‹Ò¢Í§µÑÇÍÑ¡ÉÃÍ×¹è æ µÒÁµŒÍ§¡ÒÃ

ÃÙ»·Õè 13 ˹ŒÒµ‹Ò§ HyperTerminal áÊ´§¼Å¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁ·Õè 1 Íѹ໚¹¡ÒÃÃѺʋ§¢ŒÍÁÙÅÍ‹ҧ§‹Ò ÃÐËNjҧ i-Stamp º¹ºÍÏ´ SCi-BOX ¡Ñº¤ÍÁ¾ÔÇàµÍϼҋ ¹·Ò§ ZX-BLUETOOTH


12 l ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

3.1.5.2 µÑÇÍ‹ҧ·Õè 2 ¡ÒÃÊ×Íè ÊÒâŒÍÁÙÅÃÐËNjҧ i-Stamp ¡Ñº¤ÍÁ¾ÔÇàµÍϼҋ ¹ ZX-BLUETOOTH 㹡ÒÃ㪌§Ò¹¨ÃÔ§ ÍØ»¡Ã³ÊàÅ¿¨ÐµŒÍ§Ê×Íè ÊÒáѺ¤ÍÁ¾ÔÇàµÍÏà¾×Íè ÃѺ¤íÒÊѧè áÅÐʋ§¢ŒÍÁÙÅ¡ÅѺ «Ö§è ¨ÐµŒÍ§Áբ͌ ¤ÇÒÁËÃ×ͤíÒÊѧè ÊíÒËÃѺᨌ§ËÃ×ÍáÊ´§Ê¶Ò¹Ð µÑÇÍ‹ҧ¹Õãé ªŒºÍÏ´ SCi-BOX ໚¹ÍØ»¡Ã³ÊàÅ¿ ãˌÍҋ ¹¤‹Ò¢Í§µÑǵÃǨ¨Ñº¨Ò¡ª‹Í§ÊÑ­­Ò³ SENSR0 ¶Ö§ 7 ¡ÒÃàª×Íè Áµ‹ÍàËÁ×͹¡ÑºµÑÇÍ‹ҧ·Õè 1 3.1.5.2.1 à¢Õ¹â»Ãá¡ÃÁ·Õè 2 áŌǴÒǹâËÅ´â»Ãá¡ÃÁä»Âѧ i-Stamp 3.1.5.2.2 àª×Íè Áµ‹Í¤ÍÁ¾ÔÇàµÍÏ¡ºÑ ºÍÏ´ i-Stamp ¼‹Ò¹·Ò§ºÅÙ·¸Ù ´ŒÇ Serial Port Service 3.1.5.2.3 ແ´â»Ãá¡ÃÁ HyperTerminal µÑ§é ¤‹Ò¾ÍϵãˌµÃ§¡Ñº¾Íϵ͹ءÃÁ¨íÒÅͧ·ÕÊè Ìҧ¢Ö¹é 3.1.5.2.4 Ãѹâ»Ãá¡ÃÁ Êѧࡵ¼Å¡Ò÷íÒ§Ò¹¼‹Ò¹·Ò§Ë¹ŒÒµ‹Ò§ Hyper Terminal àÁ×Íè àÃÔÁè µŒ¹ ˹ŒÒµ‹Ò§¢Í§ Hyper Terminal ¨ÐáÊ´§¢ŒÍ¤ÇÒÁ BASIC Stamp with ZX-BLUETOOTH press number to read data(0-7)

µ‹Íἧǧ¨ÃµÑǵÃǨ¨ÑºáººÍйÒÅÍ¡ ÍÒ·Ô á¼§Ç§¨ÃµÑǵŒÒ¹·Ò¹»ÃѺ¤‹Ò䴌 (POTENTIOMETER) «Ö§è ÁÕÁÒ㹪ش¢Í§ SCi-BOX à¢ŒÒ·Õ¨è ´Ø µ‹Í SENSOR0 ¶Ö§ 7 (â´ÂàÅ×Í¡µ‹ÍµÒÁµŒÍ§¡ÒÃ) ¨Ò¡¹Ñ¹é ¡´¤Õ µÑÇàÅ¢ 0 ¶Ö§ 7 µÒÁµŒÍ§¡ÒÃà¾×Íè ͋ҹ¤‹Ò¨Ò¡ª‹Í§ SENSOR0 ¶Ö§ 7 ¢Í§ºÍÏ´ SCi-BOX ¨Ò¡¹Ñ¹é i-Stamp ¨Ðʋ§ ¤‹Ò¡ÅѺÁÒ ËÒ¡¡´ 0 ¨ÐáÊ´§¢ŒÍ¤ÇÒÁ´Ñ§¹Õé Data Ch 0 = xxxx

â´Â·Õè xxxx ¤×Í¢ŒÍÁÙÅ㹪‹Ç§ 0 ¶Ö§ 1023 ¼Å¡Ò÷íÒ§Ò¹º¹Ë¹ŒÒµ‹Ò§ Hyper Terminal áÊ´§´Ñ§ã¹ÃÙ»·Õè 14

ÃÙ»·Õè 14 ˹ŒÒµ‹Ò§ HyperTerminal áÊ´§¼Å¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁ·Õè 2 Íѹ໚¹¡ÒÃÊ×èÍÊÒâŒÍÁÙÅ ÃÐËNjҧ i-Stamp º¹ºÍÏ´ SCi-BOX ¡Ñº¤ÍÁ¾ÔÇàµÍϼҋ ¹·Ò§ ZX-BLUETOOTH


ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

‘ {$STAMP BS2sx} ‘ {$PBASIC 2.5} TX CON 0 RX CON 1 BAUD CON 240 SD PIN 13

‘ ‘ ‘ ‘

VALUE CH

‘ VALUE as SENSOR1-8 variable ‘ Channel variable

VAR Word VAR Byte

Connect Connect 9600bps Sci-BOX

l 13

to ZX-BLUETOOTH RX pin to ZX-BLUETOOTH TX pin constant serial communication port

SEROUT TX,BAUD,[“BASIC Stamp with ZX-BLUETOOTH.”,CR,LF] main: SEROUT TX,BAUD,[“press number to read data(0-7) > “] SERIN RX,BAUD,[STR CH\1] IF (CH < 48) OR (CH > 55) THEN SEROUT TX,BAUD,[“Error”,CR,LF] GOTO main ENDIF SEROUT TX,BAUD,[CH,CR,LF] GOSUB Read_Sensor SEROUT TX,BAUD,[“Data Ch “,CH,” = “,DEC4 value,CR,LF] GOTO main Read_Sensor: LOW SD : PAUSE 1 : HIGH SD ‘ Break signal SEROUT SD,BAUD,[CH] ‘ Request SENSOR SERIN SD,BAUD,[VALUE.LOWBYTE,VALUE.HIGHBYTE] ‘ Received data 2 byte to 1 word RETURN

¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ àÁ×Íè àÃÔÁè â»Ãá¡ÃÁ i-Stamp ʋ§¢ŒÍ¤ÇÒÁä»Âѧ¤ÍÁ¾ÔÇàµÍϼҋ ¹ ZX-BLUETOOTH à¾×Íè áÊ´§¢ŒÍ¤ÇÒÁµ‹Ò§æ º¹Ë¹ŒÒµ‹Ò§ HyperTerminal ¨Ò¡¹Ñ¹é ÃÍÃѺ¢ŒÍÁÙÅà¾×Íè àÅ×Í¡ª‹Í§ÊÑ­­Ò³¢Í§µÑǵÃǨ¨Ñº¨Ò¡¤ÍÁ¾ÔÇàµÍÏ àÁ×Íè 䴌áŌǨзíÒ¡ÒõÃǨÊͺ¢ŒÍÁÙÅNjÒ໚¹¢ŒÍÁÙÅÍÑ¡Éà 0 ¶Ö§ 7 ËÃ×ÍäÁ‹ ¶ŒÒäÁ‹ãª‹ i-Stamp ¨Ðʋ§¢ŒÍ¤ÇÒÁ Error ¡ÅѺä»Âѧ¤ÍÁ¾ÔÇàµÍÏ ¶ŒÒ໚¹µÑÇÍÑ¡Éà 0 ¶Ö§ 7 ¶Ù¡µŒÍ§ i-Stamp ¨Ð͋ҹ¤‹Ò¨Ò¡µÑǵÃǨ¨ÑºáŌÇʋ§¢ŒÍÁÙŢͧª‹Í§ÊÑ­­Ò³ ¹Ñ¹é æ ¡ÅѺä»Âѧ¤ÍÁ¾ÔÇàµÍÏ

â»Ãá¡ÃÁ·Õè 2 â»Ãá¡ÃÁ·´Êͺ¡ÒÃÊ×Íè ÊÒâŒÍÁÙÅÃÐËNjҧ i-Stamp º¹ºÍÏ´ SCI-BOX ¡Ñº¤ÍÁ¾ÔÇàµÍϼҋ ¹ âÁ´ÙÅ ZX-BLUETOOTH áÅÐÍØ»¡Ã³ºÅÙ·¸Ù º¹¤ÍÁ¾ÔÇàµÍÏ (ä¿Å EX_Pc02.bsx - ´ÒǹâËŴ䴌¨Ò¡ www.inex.co.th)


ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

14 l ZX-BLUETOOTH

3.2 㪌§Ò¹¡ÑºäÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ ATmega16 3.2.1 à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ (1) ºÍÏ´ VX-Mega16 ·ÕÁè µÕ ´Ô µÑ§é äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ ATmega16 ËÃ×ÍÊÌҧǧ¨Ãàª×Íè Áµ‹Íàͧ (2) USB ºÅÙ·¸Ù ´Í§à¡ÔŠ㹡óշ¤Õè ÍÁ¾ÔÇàµÍÏäÁ‹ÁÇÕ §¨ÃºÅÙ·¸Ù (3) ZX-BLUETOOTH ¾ÃŒÍÁÊÒÂàª×Íè Áµ‹Í

3.2.2 ¡ÒÃàª×Íè Áµ‹Í·Ò§ÎÒÏ´áÇÏ ã¹ÃÙ»·Õè 15 áÊ´§¡ÒÃàª×èÍÁµ‹Í·Ò§ÎÒÏ´áÇÏà¾×èÍ㪌§Ò¹ ZX-BLUETOOTH ¡Ñº ATmega16 º¹ºÍÏ´ VX-Mega16 áÅФÍÁ¾ÔÇàµÍÏ ã¹µÑÇÍ‹ҧ¹Õµé ͋ ¨Ø´ RxD (PD0) ¢Í§ VX-Mega16 ¡Ñº TxD ¢Í§ ZX-BLUETOOTH áÅÐ TxD (PD1) ¢Í§ VX-Mega16 µ‹Í¡Ñº RxD ¢Í§ ZX-BLUETOOTH àÊÕº USB Bluetooth Dongle ࢌҡѺ¾Íϵ USB *

* ¶ŒÒ¤ÍÁ¾ÔÇàµÍÏÁÇÕ §¨ÃºÅÙ·¸Ù ã¹µÑÇ ÊÒÁÒö¢ŒÒÁ¢Ñ¹é µÍ¹¹Õäé »ä´Œ PA7

PA6 PA0

ATMEGA16

PA2

PA1

+ Vin -

PA3

VX - Mega16 >>> Activity Board

PD1

PD7

PD0

PD6

ISP

TxD

PD5

PB4

VX-Mega16

RxD

PD4

PB2 SW3

PD3

PB0

PB3

SW2

TxD

PD2

PB1

SW1 RESET

)!) ,#**

+ TxD RxD GND

RS-232

SDA

STATUS

ZX-BLUETOOTH

PORTC

LCD

DC input

OFF

ON

PA4

PA5

GND PC0 PC1 PC2 PC3 PC4 PC5 PC6 PC7 +5V

SCL

KNOB PA7

RxD

ºÍÏ´ VX-Mega16 ໚¹ºÍÏ´·´ÅͧáÅÐ㪌§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ ATmega16/32 ¢Í§ inex ÊÒÁÒö´Ù ÃÒÂÅÐàÍÕ´¢Í§ºÍÏ´à¾ÔÁè àµÔÁ·Õè www.inex.co.th

ÃÙ»·Õè 15 ¡Òõ‹Í㪌§Ò¹ ZX-BLUETOOTH ¡Ñº ATmega16 º¹ºÍÏ´ VX-Mega16


ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

l 15

3.2.3 àµÃÕÂÁ¡ÒÃ㪌§Ò¹ ZX-BLUETOOTH ¡ÑººÅÙ·¸Ù ¢Í§¤ÍÁ¾ÔÇàµÍÏ ¨ÐÁÕ¢¹Ñé µÍ¹·Ñ§é ËÁ´àËÁ×͹¡ÑºµÑÇÍ‹ҧã¹ËÑÇ¢ŒÍ 3.1.3 áÅÐ 3.1.4

3.2.4 ¾Ñ²¹Òâ»Ãá¡ÃÁ·Ò§½˜§› âÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ ¡ÒþѲ¹Òâ»Ãá¡ÃÁãˌᡋ ATmega16 ã¹µÑÇÍ‹ҧ¹Õãé ªŒâ»Ãá¡ÃÁÀÒÉÒ C â´Â¾Ñ²¹Ò¼‹Ò¹·Ò§ ªØ´«Í¿µáÇÏ AVR Studio4 áÅÐ㪌 WINAVR 㹡ÒäÍÁä¾Åâ»Ãá¡ÃÁÀÒÉÒ C ÊÌҧâ»Ãà¨ç¡µãËÁ‹â´ÂµÑ§é ª×Íè ໚¹ zx_bluetooth áŌÇà¢Õ¹â»Ãá¡ÃÁ·Õè 3 ·íÒ¡ÒäÍÁä¾Å áŌǴÒǹ âËŴŧÊÙº‹ ÍÏ´ VX-Mega16 (´ÒǹâËÅ´ä¿ÅµÇÑ Í‹ҧ䴌·Õè www.inex.co.th)

3.2.5 ¢Ñ¹é µÍ¹¡Ò÷´Êͺ 3.2.5.1 ¨‹ÒÂä¿àÅÕÂé §ãˌ¡ºÑ ºÍÏ´ VX-Mega16 3.2.5.2. ¡´ÊÇÔµª RESET à¾×Íè àÃÔÁè µŒ¹Ãѹâ»Ãá¡ÃÁ 3.2.5.3 ´ŒÒ¹¤ÍÁ¾ÔÇàµÍÏ·ãÕè ªŒã¹¡ÒõԴµ‹Í¡Ñº SCi-BOX ãˌ·Òí ¡ÒÃແ´¡Ò÷íÒ§Ò¹¢Í§Ç§¨ÃºÅÙ·¸Ù ¨Ò¡¹Ñ¹é ·íÒ¡ÒèѺ¤Ù¡‹ ºÑ ZX-BLUETOOTH ·Ò§½˜§› äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ áŌÇàª×Íè Áµ‹Í¼‹Ò¹·Ò§ Serial Port Service 3.2.5.4 ແ´â»Ãá¡ÃÁ HyperTerminal µÑ駤‹Ò¾ÍϵãˌµÃ§¡Ñº¾Íϵ͹ءÃÁ¨íÒÅͧ·ÕèÊÌҧ¢Öé¹ áŌǡíÒ˹´ÃٻẺ¡ÒÃÃѺʋ§¢ŒÍÁÙÅ໚¹ÍѵÃҺʹ 9600 ºÔµµ‹ÍÇÔ¹Ò·Õ 8 ºÔµ¢ŒÍÁÙÅ 1 ºÔµËÂØ´ áÅÐäÁ‹ ÁÕ¾ÒÃÔµÕé (8N1)

ÃÙ»·Õè 16 áÊ´§Ë¹ŒÒµ‹Ò§â»Ãá¡ÃÁ HyperTerminal ÃÙ»·Õè 17 ˹ŒÒµ‹Ò§â»Ãá¡ÃÁ HyperTerminal áÊ´§ ¢³ÐáÊ´§¼Å¤‹ÒÍйÒÅÍ¡·ÕÊè §‹ ¼‹Ò¹ÍØ»¡Ã³ºÅÙ·¸Ù ʶҹТͧ¡ÒÃËÂشʋ§¢ŒÍÁÙÅ


16 l ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

//—————————————————————————————————————————————————————————————————————————// // Program : Example of Bluetooth data communication // Description : Sending KNOB value to show on terminal program via bluetooth // Frequency : 16MHz // Filename : zx_bluetooth.c //—————————————————————————————————————————————————————————————————————————// #include <avr/io.h> // Header file for AVR MCU #include <avr/interrupt.h>// Header file for use sei() function #include <avr/signal.h> // Header file for use define vector interrupt #include <lcd.h> // Library for lcd display #include <analog.h> // Library for read KNOB value #include <stdlib.h> // Library for used ltoa function #define F_OSC 16000000 // Constant for Crystal frequency in Hz #define UART_BAUD_CALC(x,F_OSC) ((F_OSC)/((x)*16l)-1) // Baudrate equation unsigned char key=0; // For Keep character //————————————— Function for initial USART ——————————// void uart_init(unsigned int baud) { UBRRH = (unsigned int)(UART_BAUD_CALC(baud,F_OSC)>>8); // Keep baudrate high byte UBRRL = (unsigned int)UART_BAUD_CALC(baud,F_OSC); // Keep baudrate low byte // Enable receiver and transmitter, enable RX interrupt UCSRB |= (1 << RXEN) | (1 << TXEN) | (1 << RXCIE); // Asynchronous 8N1 UCSRC |= (1 << URSEL) | (1 << UCSZ1)| (1 << UCSZ0); sei(); // enable interrupts } //————————————— Function for send 1 character —————————// void uart_putc(unsigned char c) { while(!(UCSRA & (1 << UDRE))); // Wait for transmit Ready UDR = c; // send character } //————————————— Function for sending string ———————————// void uart_puts(char *s) { while (*s) // Loop for send string { uart_putc(*s); // Send character s++; // Point to next character } }

â»Ãá¡ÃÁ·Õè 3 â»Ãá¡ÃÁÀÒÉÒ C ä¿Å zx_bluetooch.c ÊíÒËÃѺ·´Åͧ㪌§Ò¹¡Ñº ZX-BLUETOOTH à¾×Íè ÃѺʋ§¢ŒÍÁÙšѺ¤ÍÁ¾ÔÇàµÍϼҋ ¹ÍØ»¡Ã³ºÅÙ·¸Ù (Áյ͋ )


ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

l 17

//————————————— ISR for USART Receiving —————————————// SIGNAL(SIG_UART_RECV) { key = UDR; // Keep character } //————————————— Main Program —————————————————// void main() { unsigned char send=0; // Variable for check status to send KNOB value char str[8]; // Keep string for sending to LCD lcd_init(); // Initial LCD display uart_init(9600); // Initial UART baudrate 9600 bps lcd_puts(0x80,”Ready!...”); // Display title message while(1) // Infinite loop { if(key==’+’) // Check pressing key “+” { key = 0; // Clear key value after checking send = 1; // Set status for sending KNOB value lcd_puts(0x80,”Send... “); // Display Sending status message } if(key==’-’) // Check presings key “-” { key = 0; // Clear key value after checking send = 0; // Clear status of not sending KNOB value lcd_puts(0x80,”Pause! “); // Display Not sending status message } if(send==1) // Check flag status of sending KNOB value { uart_puts(“KNOB: “); // Show screen ltoa(knob(),str,10); // Convert KNOB value uart_puts(str); // Send KNOB value uart_puts(“ \r “); // Return to left position of Terminal program delay_ms(100); // Less delay for displaying } else { uart_puts(“Pause... “);// Send Not sending status message uart_puts(“ \r “); // Return to left position of Terminal program delay_ms(500); // Less delay for displaying } } }

â»Ãá¡ÃÁ·Õè 3 â»Ãá¡ÃÁÀÒÉÒ C ä¿Å zx_bluetooch.c ÊíÒËÃѺ·´Åͧ㪌§Ò¹¡Ñº ZX-BLUETOOTH à¾×Íè ÃѺʋ§¢ŒÍÁÙšѺ¤ÍÁ¾ÔÇàµÍϼҋ ¹ÍØ»¡Ã³ºÅÙ·¸Ù (¨º)


18 l ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

3.2.5.5 àÃÔÁè µŒ¹Ë¹ŒÒµ‹Ò§ HyperTerminal áÊ´§¢ŒÍ¤ÇÒÁ Pause... ¨Ò¡¹Ñ¹é ãˌ¼¾ÙŒ ² Ñ ¹Ò·´Êͺ ¡´¤Õ + ·Õ¤è ÍÁ¾ÔÇàµÍÏ à¾×Íè ãˌ VX-Mega16 ʋ§¤‹Ò¢Í§¡ÒÃá»Å§ÊÑ­­Ò³ÍйÒÅ͡໚¹´Ô¨µÔ ÍÅ·ÕÍè ҋ ¹ 䴌¨Ò¡ KNOB ÁÒáÊ´§¼Åº¹Ë¹ŒÒµ‹Ò§ HyperTerminal ¼‹Ò¹·Ò§ÍØ»¡Ã³ºÅÙ·¸Ù «Ö§è ¼ÅÅѾ¸¨Ð»ÃÒ¡¯ µÒÁÃÙ»·Õè 16 ¼Ù¾Œ ² Ñ ¹ÒÊÒÁÒö·´Êͺ»ÃѺ¤‹Òáç´Ñ¹¨Ò¡µÑǵŒÒ¹·Ò¹»ÃѺ¤‹Ò KNOB áŌÇÊѧࡵ¼Å·Õè ˹ŒÒµ‹Ò§â»Ãá¡ÃÁ HyperTerminal 3.2.5.6 ¨Ò¡¹Ñ¹é ·´Êͺ¡´¤Õ - (à¤Ã×èͧËÁÒÂź) à¾×Íè ãˌºÍÏ´ VX-Mega16 ËÂشʋ§¢ŒÍÁÙÅ·Õè ͋ҹ䴌¨Ò¡ KNOB «Ö§è ¼ÅÅѾ¸¨Ð»ÃÒ¡¯µÒÁÃÙ»·Õè 17 àËÁ×͹¡ÑºµÍ¹àÃÔÁè µŒ¹ 3.2.5.7 àÁ×Íè ¼Ù¾Œ ² Ñ ¹ÒµŒÍ§¡ÒûŴ¡ÒÃàª×Íè Áµ‹Í·íÒ䴌´ÇŒ ¡ÒÃàÅ×Í¡ÃÒ¡ÒäíÒÊѧè àÅÔ¡àª×Íè Áµ‹Í¨Ò¡ µÑÇÍØ»¡Ã³·ËÕè ¹ŒÒµ‹Ò§ËÅÑ¡¢Í§â»Ãá¡ÃÁ â´Â¤ÅÔ¡àÁÒʏ¢ÇÒ·Õäè ͤ͹ BT GPS à¾×Íè ແ´àÁ¹Ù¤Òí Êѧè áÅŒÇ àÅ×Í¡ÃÒ¡Òà Disconnect>Bluetooth Serial Port Service à¾×Íè »Å´¡ÒÃàª×Íè Áµ‹Í ´Ñ§ÃÙ»·Õè 18

ÃÙ»·Õè 12 áÊ´§¡ÒÃàÅ×Í¡¤íÒÊÑ§è »Å´¡ÒÃàª×Íè Áµ‹ÍÃÐËNjҧÍØ»¡Ã³ºÅÙ·¸Ù ·Õ¤è ÍÁ¾ÔÇàµÍÏ¡ºÑ ZX-BLUETOOTH (㹪×Íè BT GPS)


ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

l 19

3.2.6 ¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ·´Êͺ¡ÒõԴµ‹ÍÃÐËNjҧ ATmega16 ¡Ñº¤ÍÁ¾ÔÇàµÍϼҋ ¹ ZXBLUETOOTH áÅÐ Serial Port Service ¢Í§ÍØ»¡Ã³ìºÅÙ·¸Ù (â»Ãá¡ÃÁ·Õè 3) ã¹Ê‹Ç¹ááÊØ´¢Í§â»Ãá¡ÃÁ¹Õé໚¹¡Òü¹Ç¡·ÃѾÂҡâͧäÁâ¤Ã¤Í¹â·ÃÅàÅÍÏáÅСÅ؋Á äźÃÒÃÕµ‹Ò§æ·Õè¨ÐÁÕ¡ÒÃàÃÕ¡㪌§Ò¹ÀÒÂã¹â»Ãá¡ÃÁ¹Õé #include <avr/io.h>

// àÃÕ¡㪌§Ò¹·ÃѾÂÒ¡ÃáÅÐÃÕ¨ÊÔ àµÍϢͧäÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ

#include <avr/interrupt.h>

// ÊíÒËÃѺàÃÕ¡㪌§Ò¹¿˜§¡ª¹ Ñè sei()

#include <avr/signal.h>

// ÊíÒËÃѺ¡ÒõͺʹͧÍÔ¹àµÍÃÃ»Ñ µ

#include <lcd.h>

// àÃÕ¡㪌§Ò¹¿˜§¡ª¹ Ñè ¨Ñ´¡ÒÃáÊ´§¼Å·Õâè Á´ÙÅ LCD

#include <analog.h>

// àÃÕ¡㪌§Ò¹¿˜§¡ª¹ Ñè ͋ҹ¤‹Ò KNOB

#include <stdlib.h>

// àÃÕ¡㪌§Ò¹¿˜§¡ª¹ Ñè ltoa

ã¹Ê‹Ç¹áá¢Í§â»Ãá¡ÃÁ¨Ð໚¹¡ÒÃÍÔ¹ÔàªÕÂÅâÁ´ÙÅ LCD áÅеÒÁ´ŒÇ¡ÒáíÒ˹´ãˌâÁ´ÙÅ UART Ê×Íè ÊÒâŒÍÁÙÅ·ÕÍè µÑ ÃҺʹ 9600 ºÔµµ‹ÍÇÔ¹Ò·Õ â´ÂÁÕ¡ÒÃÃѺ¢ŒÍÁÙÅẺÍÔ¹àµÍÃÃ»Ñ µ ¨Ò¡¹Ñ¹é â»Ãá¡ÃÁ¨Ð·íÒ§Ò¹ÀÒÂã¹ÅÙ»·íÒ«éÒí while(1){} â´Â¤ÍÂǹµÃǨÊͺNjÒÁÕ¡ÒÃÃѺÍÑ¡¢ÃÐ ¤Õ + ËÃ×Í - ¨Ò¡á»‡¹¤Õ¤ÍÁ¾ÔÇàµÍÏࢌÒÁÒËÃ×ÍäÁ‹à¾×èÍ¡íÒ˹´¡ÒÃàÃÕ¡͋ҹ¤‹Ò KNOB ä»áÊ´§Âѧ HyperTerminal ÀÒÂËÅѧ¡ÒÃàª×Íè Áµ‹ÍÊíÒàÃç¨áÅŒÇ à§×Íè ¹ä¢¤Çº¤ØÁ¡Ò÷íÒ§Ò¹ã¹â»Ãá¡ÃÁ¹ÕÁé Õ 4 à§×Íè ¹ä¢´Ñ§¹Õé (1) àÁ×Íè µÃǨ¾º¡ÒᴤՏ + (à¤Ã×Íè §ËÁÒºǡ) µÑÇá»Ã send ¶Ù¡¡íÒ˹´à»š¹ “1” à¾×Íè ÃÍ¡ÒÃʋ§ÊÒÂÍÑ¡¢ÃÐ·Õ¶è ¡Ù á»Å§ÁÒ¨Ò¡¤‹Ò KNOB ¨Ð¶Ù¡Ê‹§Í͡仼‹Ò¹·Ò§ ZX-BLUETOOTH ´ŒÇ¡ÒÃàª×Íè Áµ‹Í UART ¾ÃŒÍÁ¡ÑºáÊ´§¢ŒÍ¤ÇÒÁ·Õâè Á´ÙÅ LCD NjÒÍÂÙ㋠¹Ê¶Ò¹Ð¡ÒÃʋ§¤‹Ò KNOB ä»áÊ´§ (2) àÁ×Íè µÃǨ¾º¡ÒᴤՏ - (à¤Ã×Íè §ËÁÒÂź) µÑÇá»Ã send ¶Ù¡¡íÒ˹´à»š¹ 0 à¾×èÍÃÍ¡ÒÃʋ§ÊÒÂÍÑ¡¢ÃÐ Pause...\r ¼‹Ò¹·Ò§ ZXBLUETOOTH ÍÍ¡ä» ¾ÃŒÍÁ¡ÑºáÊ´§¢ŒÍ¤ÇÒÁ·Õâè Á´ÙÅ LCD NjÒÍÂÙ㋠¹Ê¶Ò¹Ð¡ÒÃËÂشʋ§¤‹Ò KNOB (3) àÁ×Íè µÃǨ¾ºÇ‹ÒµÑÇá»Ã send = 1 ÊÒÂÍÑ¡¢ÃÐ·Õ¶è ¡Ù á»Å§ÁÒ¨Ò¡¤‹Ò KNOB ¨Ð¶Ù¡Ê‹§ÍÍ¡¼‹Ò¹·Ò§ ZX-BLUETOOTH (4) àÁ×Íè µÃǨ¾ºÇ‹ÒµÑÇá»Ã send = 0 ÊÒÂÍÑ¡¢ÃÐ Pause... \r Í͡仼‹Ò¹·Ò§ ZX-BLUETOOTH


20 l ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

3.2.7 ¿˜§¡ª¹Ñè ·ÕÊè Òí ¤Ñ­ã¹â»Ãá¡ÃÁ l

uart_init

·íÒ˹ŒÒ·Õè¡íÒ˹´¤Ø³ÊÁºÑµÔ¡ÒÃÊ×èÍÊÒâŒÍÁÙÅ͹ءÃÁµÒÁҵðҹ RS-232 ´ŒÇÂÍѵÃҺʹ·Õè ¡íÒ˹´¨Ò¡ÍСÔÇàÁ¹µ â´Â͸ԺÒ¤íÒÊѧè ÀÒ¿˜§¡ª¹Ñè à¾ÔÁè àµÔÁ䴌´§Ñ ¹Õé UBRRH = (unsigned int)(UART_BAUD_CALC(baud,F_OSC)>>8); // ¤íҹdz¤‹ÒÍѵÃҺʹ¢Í§äºµÊ§Ù áŌÇâËÅ´ä»ÂѧÃÕ¨ÊÔ àµÍÏ UBRRH UBRRL = (unsigned int)UART_BAUD_CALC(baud,F_OSC); // ¤íҹdz¤‹ÒÍѵÃҺʹ¢Í§äºµµÒèí áŌÇâËÅ´ä»ÂѧÃÕ¨ÊÔ àµÍÏ UBRRL UCSRB |= (1 << RXEN) | (1 << TXEN) | (1 << RXCIE); // ແ´¡ÒÃ㪌§Ò¹ÀÒ¤ÃѺáÅÐʋ§¢ŒÍÁÙŢͧâÁ´ÙÅ USART áÅÐແ´¡ÒÃ㪌§Ò¹ÀÒ¤ÃѺ // ã¹áººÍÔ¹àµÍÃÃ»Ñ µ UCSRC |= (1 << URSEL) | (1 << UCSZ1) | (1 << UCSZ0); // ¡íÒ˹´ÃٻẺ¡ÒÃÊ×Íè ÊÒâŒÍÁÙÅẺÍЫԧâ¤Ã¹ÑÊ, 8 ºÔµ¢ŒÍÁÙÅ, äÁ‹ãªŒ¾ÒÃÔµ,Õé // áÅÐ 1 ºÔµËÂØ´ sei(); // ແ´ÍÔ¹àµÍÃÃ»Ñ µÃÇÁ¢Í§Ãкº

¡ÒäíҹdzÍѵÃҺʹà¾×Íè »‡Í¹ãˌ¡ºÑ ÃÕ¨ÊÔ àµÍÏ UBRRH áÅÐ UBRRL ¨ÐÍÒÈÑÂÁÒâ¤Ã F_OSC «Ö§è ໚¹µÑÇ¡íÒ˹´¤ÇÒÁ¶Õ¤è ÃÔʵÍŢͧÃкº ã¹â»Ãá¡ÃÁ¡íÒ˹´·Õè 16000000 (¤ÇÒÁ¶Õè 16 MHz) ¨Ò¡ #define F_OSC 16000000

ÊíÒËÃѺÁÒâ¤Ãã¹Ê‹Ç¹¡Òäíҹdz UART_BAUD_CALC(baud,F_OSC) ¹Ñ¹é ÁÒ¨Ò¡¡ÒùÔÂÒÁ ¢Í§ÁÒâ¤Ã UART_BAUD_CALC(x,F_OSC) ¨Ò¡ #define UART_BAUD_CALC(x,F_OSC) ((F_OSC)/((x)*16)-1)

«Ö§è ¨ÐÊÑÁ¾Ñ¹¸¡ºÑ ÊÁ¡Òäíҹdz¤‹Ò·Õâè ËÅ´ãˌ¡ºÑ ÃÕ¨ÊÔ àµÍÏ UBRR à¾ÕÍè ãËŒä´ŒÍµÑ ÃҺʹ x ·Õµè ͌ § ¡Òà «Ö§è ໚¹ä»µÒÁÊÁ¡Òà UBRR = [F_OSC/(Baud*16)]-1 â´Â·Õè UBRR ¤×Í¢ŒÍÁÙÅ 16 ºÔµ·Õäè ´Œ¨Ò¡¡Òäíҹdzà¾×Íè âËÅ´ãˌ¡ºÑ ÃÕ¨ÊÔ àµÍÏ UBRRH áÅÐ UBRRL F_OSC ¤×Í ¤ÇÒÁ¶Õ¤è ÃÔʵÍŢͧÃкº Baud ¤×Í ÍѵÃҺʹ·Õµè ͌ §¡ÒÃ


ZX-BLUETOOTH

l

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

l 21

uart_putc

·íÒ˹ŒÒ·ÕÊè §‹ ¢ŒÍÁÙÅ 1 亵ÍÍ¡·Ò§ÀҤʋ§¢Í§âÁ´ÙÅ USART «Ö§è ¡íÒ˹´¢ŒÍÁÙÅ·Õµè ͌ §¡ÒÃʋ§ãˌ ¡Ñº¾ÒÃÒÁÔàµÍÏ c â´Â͸ԺÒ¤íÒÊѧè ÀÒÂã¹à¾ÔÁè àµÔÁ䴌´§Ñ ¹Õé void uart_putc(unsigned char c) { while(!(UCSRA & (1 << UDRE))); UDR = c; } l

// µÃǨÊÍºÇ‹Ò ¡ÒÃʋ§¢ŒÍÁÙÅÊÔ¹ é ÊØ´ËÃ×ÍÂѧ // âËÅ´¢ŒÍÁÙÅ·Õµè ͌ §¡ÒÃʋ§ä»ÂѧÃÕ¨ÊÔ àµÍÏ UDR

uart_puts

·íÒ˹ŒÒ·Õèʋ§¢ŒÍÁÙÅÊÒÂÍÑ¡¢ÃÐÍÍ¡·Ò§ÀҤʋ§¢Í§âÁ´ÙÅ USART «Ö觡íÒ˹´¢ŒÍÁÙÅ·Õ赌ͧ¡Òà ʋ§ãˌ¡ºÑ ¾ÒÃÒÁÔàµÍÏ s «Ö§è ໚¹µÑǪբé ͌ ÁÙÅ â´Â͸ԺÒ¤íÒÊѧè ÀÒÂã¹à¾ÔÁè àµÔÁ䴌´§Ñ ¹Õé void uart_puts(char *s) { while (*s) { uart_putc(*s); s++; } } l

// Åٻ㹡ÒÃǹʋ§ÍÑ¡¢ÃзÕÅÐ亵¨¹¡Ç‹Ò¨Ð¤Ãº // ʋ§ÍÑ¡¢ÃзÕÍè Âً ³ »˜¨¨Øº¹ Ñ // à¾ÔÁè ¤‹ÒµÑǪÕàé ¾×Íè ªÕÍé ¡Ñ ¢ÃеÑǶѴä»

SIGNAL(SIG_UART_RECV)

â»Ãá¡ÃÁ¨Ð¡ÃÐâ´´¨Ò¡¡Ò÷íÒ§Ò¹ËÅѡࢌÒÁÒ·íÒ§Ò¹ÀÒÂ㹿˜§¡ª¹Ñè ¹Õé àÁ×Íè ä´ŒÃºÑ ¢ŒÍÁÙÅ·Õàè ¢ŒÒÁÒ ·Ò§¢ÒÊÑ­­Ò³ RXD ¶ŒÒÁͧÀÒ¾ÃÇÁ¡ç¤Í× ÃѺ¼‹Ò¹ÁÒ·Ò§ ZX-BLUETOOTH â´Â¢ŒÍÁÙÅ·Õäè ´ŒÃºÑ ¨Ð¶Ù¡à¡çº änj·ÃÕè ¨Õ ÊÔ àµÍÏ UDR â´Â¨ÐÁÕµÇÑ á»Ã key ·íÒ˹ŒÒ·Õâè ËÅ´à¡çºÍÑ¡¢ÃзÕÃè ºÑ à¢ŒÒÁÒà¾×Íè 㪌໚¹µÑǵÃǨÊͺ à§×Íè ¹ä§ÀÒÂã¹â»Ãá¡ÃÁËÅÑ¡ÍÕ¡¤Ãѧé ˹֧è NjÒÍÑ¡¢ÃзÕÃè ºÑ à¢ŒÒÁÒ¹Ñ¹é µÃ§¡Ñº¤ÇÒÁµŒÍ§¡ÒÃËÃ×ÍäÁ‹ â´ÂÁÕ⤌´ â»Ãá¡ÃÁÀÒÉÒ C ´Ñ§¹Õé SIGNAL(SIG_UART_RECV) { key = UDR; // âËÅ´ÍÑ¡¢ÃзÕäè ´ŒÃºÑ ¨Ò¡¤ÍÁ¾ÔÇàµÍÏÁÒà¡çºÂѧµÑÇá»Ã key }


22 l ZX-BLUETOOTH

l

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

ltoa

·íÒ˹ŒÒ·Õèá»Å§àÅ¢¨íҹǹàµçÁä»à»š¹ÊÒÂÍÑ¡¢ÃЫÖ觨Ѵà¡çºÍÂًÀÒÂã¹äźÃÒÃÕ stdlib.h «Öè§ÁÒ ¾ÃŒÍÁ¡Ñº¤ÍÁä¾àÅÍÏ ÃٻẺ char *ltoa(long __val, char *__s, int __radix);

¾ÒÃÒÁÔàµÍÏ __val ¤×Í ¤‹Ò¨íҹǹàµçÁ·Õµè ͌ §¡ÒÃá»Å§ __s ¤×Í µÑǪÕËé Ã×ÍʵÃÔ§·ÕÁè ÒÃѺ¤‹Ò·Õäè ´Œ¨Ò¡¡ÒÃá»Å§ __radix ¤×Í àÅ¢°Ò¹·Õµè ͌ §¡ÒÃá»Å§à»š¹¼ÅÅѾ¸

¡Òä׹¤‹Ò l

ÅѡɳÐà´ÕÂǡѺ __s key

໚¹µÑÇá»ÃʋǹÃÇÁ(Global variable) ·íÒ˹ŒÒ·ÕèÃѺ¢ŒÍÁÙÅ·ÕèࢌÒÁÒÂѧǧ¨ÃÀÒ¤ÃѺ¢Í§âÁ´ÙÅ UART «Ö§è ¨ÐÃѺ¤‹Ò¨Ò¡ÍÑ¡¢ÃзÕàè ¢ŒÒÁÒ·Ò§¢ÒÊÑ­­Ò³ RXD (¾Íϵ PD0) 㪌໚¹µÑǵÃǨ¨Ñº¡Òá´ ệ¹¤Õ + áÅÐ - ÀÒÂã¹â»Ãá¡ÃÁ ËÃ×ÍÍÒ¨¹íÒ仵ÃǨ¨Ñº¡ÒÃÃѺ¤ÕÂ㏠´æ䴌´ÇŒ  ËÅѧ¨Ò¡¡ÒÃ͋ҹ¤‹Ò µÑÇá»Ã key áŌÇá¹Ð¹íÒÇ‹Ò ¤ÇÃà¤ÅÕÂϤҋ à¾×Íè ãˌÊÒÁÒö¡ÅѺä»ÃѺ¤‹Ò¤ÕÂ㏠ËÁ‹ä´Œ

4. ¡ÒÃ㪌§Ò¹ ZX-BLUETOOTH ¡ÑºäÁâ¤Ã¤Í¹â·ÃÅàÅÍϵÇÑ Í×¹è æ ¨Ò¡ 2 µÑÇÍ‹ҧ·Õ¹è Òí àʹ͡ÒÃ㪌§Ò¹ ZX-BLUETOOTH ¡Ñº i-Stamp áÅÐ ATmega16 ¨ÐàËç¹ ä´ŒÇҋ ¡Òõ‹Í㪌§Ò¹·íÒ䴌§Ò‹  à¾Õ§µ‹Í¢Ò RxD áÅÐ TxD ¢Í§ ZX-BLUETOOTH ࢌҡѺ¢ÒÃѺʋ§¢ŒÍÁÙŠ͹ءÃÁ¨Ò¡âÁ´ÙÅ UART ¢Í§äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏã´æ ¡çÊÒÁÒö㪌§Ò¹ä´ŒáÅŒÇ â´Â¢Ò RxD ¢Í§ ZX-BLUETOIOTH µŒÍ§µ‹Í¡Ñº¢Ò TxD ¢Í§äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ áÅÐ TxD ¢Í§ ZX-BLUETOOTH µ‹ Í ¡Ñ º ¢Ò RxD ¢Í§äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ ¡ànj ¹ ¡Å؋ Á ¢Í§àºÊÔ ¡ áʵÁ»Š ·Õè Ê ÒÁÒöµ‹ Í ZXBLUETOOTH ࢌҡѺ¢Ò¾Íϵã´æ 䴌 ᵋµÍŒ §¡íÒ˹´·ÔÈ·Ò§¢Í§¢Ò¾Íϵãˌª´Ñ à¨¹Ç‹Ò ¢Ò¾Íϵ·Õµè ͋ ¡Ñº RxD µŒÍ§à»š¹àÍÒµ¾µØ áÅТҾÍϵ·Õµè ͋ ¡Ñº TxD ¢Í§ ZX-BLUETOOTH µŒÍ§à»š¹ÍÔ¹¾Øµ ¡ÒÃà¢Õ¹â»Ãá¡ÃÁµÔ´µ‹Í¡çàËÁ×͹¡Ñº¡ÒÃà¢Õ¹â»Ãá¡ÃÁà¾×èÍÃѺʋ§¢ŒÍÁÙż‹Ò¹âÁ´ÙÅÊ×èÍÊÒà ¢ŒÍÁÙÅ UART ¡Ñº¾Íϵ͹ءÃÁ¢Í§¤ÍÁ¾ÔÇàµÍÏ à¹×Íè §¨Ò¡ÃٻẺ¡Ò÷íÒ§Ò¹¢Í§ÍØ»¡Ã³ºÅÙ·¸Ù ¹Ñ¹é ໚¹ SPP ËÃ×Í Serial Port Profile


ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

l 23

5. ¢ŒÍ¨íÒ¡Ñ´¢Í§ ZX-BLUETOOTH ZX-BLUETOOTH 㪌âÁ´ÙźÅØ·¸Ù MB-CB04 «Ö§è ÊÒÁÒö·íҧҹ໚¹ÍØ»¡Ã³Å¡Ù ËÃ×ÍÊàſ䴌 à¾Õ§Í‹ҧà´ÕÂÇ ´Ñ§¹Ñé¹ËÒ¡ã¹ÃкºÍØ»¡Ã³ÁÒÊàµÍÏ㪌äÁâ¤Ã¤Í¹â·ÃÅàÅÍÏàËÁ×͹¡Ñ¹ ·ÕèÍØ»¡Ã³ ÁÒÊàµÍϨеŒÍ§ãªŒâÁ´ÙźÅÙ·¸Ù ·ÕÊè ÒÁÒö¡íÒ˹´¡Ò÷íҧҹ໚¹ÁÒÊàµÍÏ䴌 ÍÒ·Ô âÁ´ÙÅ ESD02 ËÃ×Í ESD100 (´ÙÃÒÂÅÐàÍÕ´䴌·Õè www.inex.co.th) ·Ò§´ŒÒ¹¤ÇÒÁàÃçÇ㹡Òö‹Ò·ʹ¢ŒÍÁÙÅ ¶Ù¡¡íÒ˹´änjµÒµÑÇ·Õè 9600 ºÔµµ‹ÍÇÔ¹Ò·Õ áÅÐÃٻẺ ¢ŒÍÁÙÅÃͧÃѺÁҵðҹ 8N1 «Öè§à¾Õ§¾Íµ‹Í¡ÒÃÊ×èÍÊÒâŒÍÁÙšѺäÁâ¤Ã¤Í¹â·ÃÅàÅÍÏ ᵋ¶ŒÒËÒ¡ÁÕ ¤ÇÒÁµŒÍ§¡ÒÃ㪌§Ò¹ÍѵÃҺʹ·ÕÊè §Ù ¡Ç‹Ò¹ÕËé Ã×ÍàÅ×Í¡»ÃѺ䴌¹¹Ñé ÍÒ¨µŒÍ§à»ÅÕÂè ¹ä»ãªŒâÁ´ÙÅ ESD02 ËÃ×Í ESD100 á·¹

ESD02

ESD100

INNOVATIVE EXPERIMENT

ESD200


24 l ZX-BLUETOOTH

ἧǧ¨ÃÊ×Íè ÊÒâŒÍÁÙÅäÌÊÒ¼‹Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿

ºÃÔÉÑ· ÍÔ¹â¹àǵտ àÍç¡à¾ÍÃÔàÁ¹µ ¨íÒ¡Ñ´ INNOVATIVE EXPERIMENT

3133/53 «.ÊØ¢ÁØ ÇÔ· 101/2 ¶.ÊØ¢ÁØ ÇÔ· á¢Ç§ºÒ§¹Ò ࢵºÒ§¹Ò ¡ÃØ§à·¾Ï 10260 â·ÃÈѾ· 0-2747-7001-4 â·ÃÊÒà 0-2747-7005

URL : www.inex.co.th

e-mail : tech@inex.co.th


ZX-Bluetooth