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 äÇ ´Ç Â) ÊíÒËÃѺ¢Ò¾Íà µÊÒÁÒöà»ÅÕÂè ¹á»Å§ä´ µÒÁµ ͧ¡ÒÃ
ÃÙ»·Õè 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) ÃÐËÇ Ò§ÍØ»¡Ã³ ÁÒÊàµÍÃ ã¹·Õ¹è ¤Õé Í× ¤ÍÁ¾ÔÇàµÍà áÅÐÍØ»¡Ã³ ÊàÅ¿ «Ö§è ¡ç¤Í× ZX-BLUETOOTH (㹪×Íè BT GPS) 3.1.4.5 ¡ ͹¡ÒõԴµ ͡ѺÍØ»¡Ã³ ͹×è æ ¨Ðµ ͧÁÕ¡ÒèѺ¤Ù (Pair) ÃÐËÇ Ò§ÍØ»¡Ã³ ÁÒÊàµÍà áÅÐ ÊàÅ¿ 㹡óչÕé¤ÍÁ¾ÔÇàµÍà ¨Ðà» ¹µÑÇÁÒÊàµÍà áÅÐ 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 àÁ×Íè àª×Íè Áµ ÍÊíÒàÃ稨ÐÁÕ˹ Òµ Ò§ºÍ¡ËÁÒÂàÅ¢¾Íà µÍ¹Ø¡ÃÁ¨íÒÅͧ·ÕÊè à ҧ¢Ö¹é ¾Ã ÍÁ¡Ñº ¶ÒÁÇ Òµ ͧ¡ÒÃãË àª×Íè Áµ ;Íà µÍ¹Ø¡ÃÁ¨íÒÅͧ¹Õãé Ë ÍµÑ â¹ÁѵàÔ Á×Íè ÁÕ¡ÒÃàÃÕ¡㪠¾Íà µ¨Ò¡â»Ãá¡ÃÁÍ×¹è ËÃ×ÍäÁ ¡´ No à¾×Íè äÁ ãË àª×Íè Áµ ÍÍѵâ¹ÁÑµÔ ÃÙ»·Õè 10
ÃÙ»·Õè 10 ˹ Òµ ҧᨠ§¡ÒÃàª×Íè Áµ ÍÊíÒàÃç¨ «Ö§è ¨Ðᨠ§ËÁÒÂàÅ£¢Í§¾Íà µÍ¹Ø¡ÃÁ¨íÒÅͧ¢Í§ÍØ»¡Ã³ ºÅÙ·¸Ù ·Õ¹è Òí ÁÒµÔ´µ Í´ Ç ¨Ò¡ÃÙ»¤×Í COM11
ZX-BLUETOOTH
ἧǧ¨ÃÊ×Íè ÊÒâ ÍÁÙÅäà ÊÒ¼ Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿
l 9
3.1.5 µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ ZX-BLUETOOTH ¡Ñº i-Stamp ´ ǺÍà ´ SCi-BOX 3.1.5.1 µÑÇÍ ҧ·Õè 1 ¡ÒÃÃÑºÊ §¢ ÍÁÙÅÃÐËÇ Ò§ 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 áÊ´§ÅíҴѺ¡Ò÷íÒ§Ò¹¢Í§¡ÒÃÃÑºÊ §¢ ÍÁÙÅ͹ءÃÁÃÐËÇ Ò§ 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 â»Ãá¡ÃÁ·´Êͺ¡ÒÃÃÑºÊ §¢ ÍÁÙÅàº×Íé §µ ¹ÃÐËÇ Ò§ i-Stamp ¡Ñº¤ÍÁ¾ÔÇàµÍà ¼Ò ¹âÁ´ÙÅ ZXBLUETOOTH áÅÐÍØ»¡Ã³ ºÅÙ·¸Ù º¹¤ÍÁ¾ÔÇàµÍà (ä¿Å EX_Pc01.bsx - ´Òǹ âËÅ´ä´ ¨Ò¡ www.inex.co.th) ¡Ãкǹ¡Ò÷íÒ§Ò¹·Ñ§é ËÁ´áÊ´§ã¹ÃÙ»·Õè 11 àÁ×Íè àÃÔÁè µ ¹Ë¹ Òµ Ò§¢Í§ Hyper Terminal ¨ÐÇ Ò§ ¨Ò¡¹Ñ¹é ãË ¡´¤ÕÂã ´æ ·Õ¤è ÂÕ º Íà ´¢Í§¤ÍÁ¾ÔÇàµÍÃ ã¹·Õ¹è ·Õé ´Åͧ¡´¤Õ a ¢ ÍÁÙŢͧÍÑ¡Éà a ¨Ð¶Ù¡ Ê §ÍÍ¡¨Ò¡¤ÍÁ¾ÔÇàµÍà ¼Ò ¹¾Íà µÍ¹Ø¡ÃÁ¨íÒÅͧ·Õàè ¡Ô´¨Ò¡ Service ¢Í§ºÅÙ·¸Ù ÍÍ¡ÍÒ¡ÒÈÁÒÂѧâÁ´ÙÅ ZX-BLUETOOTH áÅ ÇÊ §à¢ Òä»Âѧ i-Stamp ¨Ò¡¹Ñ¹é i-Stamp ¨ÐÊ §¢ ÍÁÙÅà´ÔÁ¹Ñ¹é ¡ÅѺÁÒÂѧ¤ÍÁ¾ÔÇàµÍà ¾Ã ÍÁ¡ÑºàÅ¢·Õ¢è ͧ¢ ÍÁÙÅ «Ö§è ¨ÐÁÒ»ÃÒ¡¯·ÕËè ¹ Òµ Ò§¢Í§ Hyper Terminal à» ¹ 0001 a ËÁÒ¶֧ ÃѺ ¢ ÍÁÙŵÑÇ·Õè 1 à» ¹µÑÇÍÑ¡Éà a ´Ñ§ÃÙ»·Õè 13 ¨Ò¡¹Ñ¹é ·´ÅÍ§Ê §¤ ҢͧµÑÇÍÑ¡ÉÃÍ×¹è æ µÒÁµ ͧ¡ÒÃ
ÃÙ»·Õè 13 ˹ Òµ Ò§ HyperTerminal áÊ´§¼Å¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁ·Õè 1 Íѹ໠¹¡ÒÃÃÑºÊ §¢ ÍÁÙÅÍ ҧ§ Ò ÃÐËÇ Ò§ i-Stamp º¹ºÍà ´ SCi-BOX ¡Ñº¤ÍÁ¾ÔÇàµÍà ¼Ò ¹·Ò§ ZX-BLUETOOTH
12 l ZX-BLUETOOTH
ἧǧ¨ÃÊ×Íè ÊÒâ ÍÁÙÅäà ÊÒ¼ Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿
3.1.5.2 µÑÇÍ ҧ·Õè 2 ¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅÃÐËÇ Ò§ 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 Íѹ໠¹¡ÒÃÊ×èÍÊÒâ ÍÁÙÅ ÃÐËÇ Ò§ 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 ¨Ò¡¹Ñ¹é ÃÍÃѺ¢ ÍÁÙÅà¾×Íè àÅ×Í¡ª ͧÊÑÒ³¢Í§µÑǵÃǨ¨Ñº¨Ò¡¤ÍÁ¾ÔÇàµÍà àÁ×Íè ä´ áŠǨзíÒ¡ÒõÃǨÊͺ¢ ÍÁÙÅÇ Òà» ¹¢ ÍÁÙÅÍÑ¡Éà 0 ¶Ö§ 7 ËÃ×ÍäÁ ¶ ÒäÁ 㪠i-Stamp ¨ÐÊ §¢ ͤÇÒÁ Error ¡ÅѺä»Âѧ¤ÍÁ¾ÔÇàµÍà ¶ Òà» ¹µÑÇÍÑ¡Éà 0 ¶Ö§ 7 ¶Ù¡µ ͧ i-Stamp ¨ÐÍ Ò¹¤ Ò¨Ò¡µÑǵÃǨ¨ÑºáÅ ÇÊ §¢ ÍÁÙŢͧª ͧÊÑÒ³ ¹Ñ¹é æ ¡ÅѺä»Âѧ¤ÍÁ¾ÔÇàµÍÃ
â»Ãá¡ÃÁ·Õè 2 â»Ãá¡ÃÁ·´Êͺ¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅÃÐËÇ Ò§ 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 áÊ´§¡ÒÃàÅ×Í¡¤íÒÊÑ§è »Å´¡ÒÃàª×Íè Áµ ÍÃÐËÇ Ò§ÍØ»¡Ã³ ºÅÙ·¸Ù ·Õ¤è ÍÁ¾ÔÇàµÍà ¡ºÑ ZX-BLUETOOTH (㹪×Íè BT GPS)
ZX-BLUETOOTH
ἧǧ¨ÃÊ×Íè ÊÒâ ÍÁÙÅäà ÊÒ¼ Ò¹âÁ´ÙźÅÙ·¸Ù ẺÊàÅ¿
l 19
3.2.6 ¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ·´Êͺ¡ÒõԴµ ÍÃÐËÇ Ò§ 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){} â´Â¤ÍÂǹµÃǨÊ꼂 ÒÁÕ¡ÒÃÃѺÍÑ¡¢ÃÐ ¤Õ + ËÃ×Í - ¨Ò¡á» ¹¤Õ ¤ÍÁ¾ÔÇàµÍà ࢠÒÁÒËÃ×ÍäÁ à¾×èÍ¡íÒ˹´¡ÒÃàÃÕÂ¡Í Ò¹¤ Ò KNOB ä»áÊ´§Âѧ HyperTerminal ÀÒÂËÅѧ¡ÒÃàª×Íè Áµ ÍÊíÒàÃç¨áÅ Ç à§×Íè ¹ä¢¤Çº¤ØÁ¡Ò÷íÒ§Ò¹ã¹â»Ãá¡ÃÁ¹ÕÁé Õ 4 à§×Íè ¹ä¢´Ñ§¹Õé (1) àÁ×Íè µÃǨ¾º¡Òá´¤Õ + (à¤Ã×Íè §ËÁÒºǡ) µÑÇá»Ã send ¶Ù¡¡íÒ˹´à» ¹ 1 à¾×Íè ÃÍ¡ÒÃÊ §ÊÒÂÍÑ¡¢ÃÐ·Õ¶è ¡Ù á»Å§ÁÒ¨Ò¡¤ Ò KNOB ¨Ð¶Ù¡Ê §Í͡仼 Ò¹·Ò§ ZX-BLUETOOTH ´ Ç¡ÒÃàª×Íè Áµ Í UART ¾Ã ÍÁ¡ÑºáÊ´§¢ ͤÇÒÁ·Õâè Á´ÙÅ LCD Ç ÒÍÂÙ㠹ʶҹСÒÃÊ §¤ Ò KNOB ä»áÊ´§ (2) àÁ×Íè µÃǨ¾º¡Òá´¤Õ - (à¤Ã×Íè §ËÁÒÂź) µÑÇá»Ã send ¶Ù¡¡íÒ˹´à» ¹ 0 à¾×èÍÃÍ¡ÒÃÊ §ÊÒÂÍÑ¡¢ÃÐ Pause...\r ¼ Ò¹·Ò§ ZXBLUETOOTH ÍÍ¡ä» ¾Ã ÍÁ¡ÑºáÊ´§¢ ͤÇÒÁ·Õâè Á´ÙÅ LCD Ç ÒÍÂÙ㠹ʶҹСÒÃËÂØ´Ê §¤ Ò 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 â´Â¢ ÍÁÙÅ·Õäè ´ ÃºÑ ¨Ð¶Ù¡à¡çº äÇ ·ÃÕè ¨Õ ÊÔ àµÍà UDR â´Â¨ÐÁÕµÇÑ á»Ã key ·íÒ˹ Ò·Õâè ËÅ´à¡çºÍÑ¡¢ÃзÕÃè ºÑ à¢ ÒÁÒà¾×Íè 㪠໠¹µÑǵÃǨÊͺ à§×Íè ¹ä§ÀÒÂã¹â»Ãá¡ÃÁËÅÑ¡ÍÕ¡¤Ãѧé ˹֧è Ç ÒÍÑ¡¢ÃзÕÃè ºÑ à¢ ÒÁÒ¹Ñ¹é µÃ§¡Ñº¤ÇÒÁµ ͧ¡ÒÃËÃ×ÍäÁ â´ÂÁÕ⤠´ â»Ãá¡ÃÁÀÒÉÒ 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 ¢Í§äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ¡àÇ ¹ ¡ÅØ Á ¢Í§àºÊÔ ¡ áʵÁ» ·Õè Ê ÒÁÒöµ Í 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) ·Ò§´ Ò¹¤ÇÒÁàÃçÇ㹡Òö Ò·ʹ¢ ÍÁÙÅ ¶Ù¡¡íÒ˹´äÇ µÒµÑÇ·Õè 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