i-Stamp2P24_TextLab

Page 1

Microcontroller in Experiment

·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç  ÀÒÉÒàºÊÔ¡¡Ñº i-Stamp2P24

â´Â ªÑÂÇѲ¹ ÅÔÁé ¾Ã¨ÔµÃÇÔäÅ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡¡Ñº i-Stamp2P24 â´Â ªÑÂÇѲ¹ ÅÔÁé ¾Ã¨ÔµÃÇÔäÅ

ã¤Ã¤ÇÃ㪠˹ѧÊ×ÍàÅ Á¹Õé 1. ¹Ñ¡àÃÕ¹ ¹ÔÊµÔ ¹Ñ¡ÈÖ¡ÉÒ áÅкؤ¤Å·ÑÇè ä»·ÕÁè ¤Õ ÇÒÁʹã¨ã¹¡ÒÃàÃÕ¹ÃÙä Áâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡ 2. ʶҺѹ¡ÒÃÈÖ¡ÉÒ âçàÃÕ¹ ÇÔ·ÂÒÅÑ ÁËÒÇÔ·ÂÒÅÑ ·ÕÁè ¡Õ ÒÃà» ´¡ÒÃàÃÕ¹¡ÒÃÊ͹ÇÔªÒÍÔàÅç¡·ÃÍ¹Ô¡Ê ËÃ×Í ÀÒ¤ÇÔªÒÇÔÈÇ¡ÃÃÁÍÔàÅç¡·ÃÍ¹Ô¡Ê áÅФÍÁ¾ÔÇàµÍà 3. ¤³Ò¨Òà·ÁÕè ¤Õ ÇÒÁµ ͧ¡ÒÃÈÖ¡ÉÒ áÅÐàµÃÕÂÁ¡ÒÃàÃÕ¹¡ÒÃÊ͹ÇÔªÒäÁâ¤Ãâ»Ãà«Êà«Íà - äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ¾×¹é °Ò¹ 4. ˹ ǧҹàÍ¡ª¹·ÕÁè ¡Õ ÒþѲ¹Ò¼ÅÔµÀѳ± ´Ò ¹ÍÔàÅç¡·ÃÍ¹Ô¡Ê áÅФÍÁ¾ÔÇàµÍÃ

´íÒà¹Ô¹¡ÒèѴ¾ÔÁ¾ áÅШíÒ˹ ÒÂâ´Â ºÃÔÉ·Ñ ÍÔ¹â¹àǵտ àÍç¡à¾ÍÃÔàÁ¹µ ¨íÒ¡Ñ´ 108 «.ÊØ¢ÁØ ÇÔ· 101/2 ¶.ÊØ¢ÁØ ÇÔ· á¢Ç§ºÒ§¹Ò ࢵºÒ§¹Ò ¡ÃØ§à·¾Ï 10260 â·ÃÈѾ· 0-2747-7001-4 â·ÃÊÒà 0-2747-7005

ÃÒÂÅÐàÍÕ´·Õ»è ÃÒ¡¯ã¹Ë¹Ñ§Ê×ÍàÅ Á¹Õäé ´ ¼Ò ¹¡ÒõÃǨ·Ò¹Í ҧÅÐàÍÕ´áÅж ǹ¶Õè à¾×Íè ãË Á¤Õ ÇÒÁÊÁºÙó áÅж١µ ͧ ÁÒ¡·ÕÊè ´Ø ÀÒÂãµ à§×Íè ¹ä¢áÅÐàÇÅÒ·Õ¾è §Ö ÁÕ¡Í ¹¡ÒèѴ¾ÔÁ¾ à¼Âá¾Ã ¤ÇÒÁàÊÕÂËÒÂÍѹÍÒ¨à¡Ô´¨Ò¡ ¡ÒùíÒ¢ ÍÁÙÅã¹Ë¹Ñ§Ê×Í àÅ Á¹Õäé »ãª ·Ò§ºÃÔÉ·Ñ ÍÔ¹â¹àǵտ àÍç¡à¾ÍÃÔàÁ¹µ ¨íÒ¡Ñ´ ÁÔä´ ÁÀÕ ÒÃÐ㹡ÒÃÃѺ¼Ô´ªÍºáµ »ÃСÒÃã´ ¤ÇÒÁ¼Ô´¾ÅÒ´ ¤ÅÒ´à¤Å×Íè ¹·ÕÍè Ò¨ÁÕáÅÐä´ ÃºÑ ¡ÒèѴ¾ÔÁ¾ à¼Âá¾Ã ÍÍ¡ä»¹Ñ¹é ·Ò§ºÃÔÉ·Ñ Ï ¨Ð¾ÂÒÂÒÁªÕáé ¨§áÅÐá¡ ä¢ã¹¡ÒèѴ¾ÔÁ¾ ¤ÃÑ§é µ Íä» Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


ÊÒúѭ º··Õè 1 á¹Ð¹íÒ iStamp2P24..........................................................................................................5 º··Õè 2 ¡ÒÃ㪠§Ò¹â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ....................................................................17 º··Õè 3 ÃÒÂÅÐàÍÕ´áÅСÒÃ㪠§Ò¹¤íÒÊÑ§è ¢Í§àºÊÔ¡áʵÁ» 2P.......................................................23 º··Õè 4 ªØ´¤íÒÊÑ§è ·Ò§¤³ÔµÈÒʵà áÅÐÅͨԡ¢Í§àºÊÔ¡áʵÁ» 2P..............................................183 º··Õè 5 ¡Ò÷´Åͧ㪠§Ò¹¢Ò¾Íà µ¢Í§ i-Stamp2p24...............................................................209 º··Õè 6 ¡ÒÃ㪠§Ò¹Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁÀÒÂã¹ i-Stamp2P24..................................................231 º··Õè 7 ¡ÒÃ㪠§Ò¹ i-Stamp2P24 ¢Ñº LED µÑÇàÅ¢ 7 Ê Ç¹ .............................................................239 º··Õè 8 ¡ÒÃ㪠§Ò¹¤íÒÊѧè RCTIME ¢Í§ i-Stamp2P24..............................................................251 º··Õè 9 i-Stamp2P24 ¡Ñº¡ÒÃÁÍ´ÙàÅªÑ¹è ·Ò§¤ÇÒÁ¡Ç Ò§¢Í§¾ÑÅÊ (PWM) .....................................257 º··Õè 10 i-Stamp2P24 ¡Ñº¡ÒâѺà«Íà âÇÁÍàµÍà ........................................................................263 º··Õè 11 ¢ÑºâÁ´ÙÅ LCD ẺÍÑ¡¢ÃÐâ´Â㪠i-Stamp2P24..............................................................271 º··Õè 12 ¡ÒÃ㪠§Ò¹ i-Stamp2P24 ¡ÑºÍØ»¡Ã³ ÃкººÑÊ I2C ........................................................281 º··Õè 13 㪠§Ò¹ i-Stamp2P24 ¡ÑºÍØ»¡Ã³ ÃкººÑÊ 1 ÊÒ ....................................................313

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


º··Õè 1

á¹Ð¹íÒ i-Stamp2P24

i-Stamp2P24 à» ¹ºÍà ´·Õ¾è ² Ñ ¹Òâ´ÂºÃÔÉ·Ñ ÍÔ¹â¹àǵտ àÍç¡à¾ÍÃÔàÁ¹µ ¨íÒ¡Ñ´ã¹»ÃÐà·Èä·ÂÀÒÂãµ ¤ÇÒÁà ÇÁÁ×ͧ͢ Parallax Inc. â´Â i-Stamp2P24 ä´ ÃºÑ ¡ÒÃÍ͡ẺãË ÁÕ¡ÒèѴ¢ÒàËÁ×͹¡Ñº¢Ò¾Íà µ¢Í§ BS2P24-IC à¡×ͺ·Ñ§é ËÁ´ ¡àÇ ¹à¾Õ§¢Ò 24 ·Õäè Á 㪠§Ò¹ ã¹ÃÙ»·Õè 1-1 áÊ´§Ë¹ ҵҢͧ i-Stamp2P24

1.1 ¡ÒèѴ¢ÒáÅÐǧ¨Ã¢Í§ i-Stamp2P24 ã¹ÃÙ»·Õè 1-2 áÊ´§¡ÒèѴ¢Ò㪠§Ò¹¢Í§ i-Stamp2P24 ǧ¨ÃÊÁºÙó áÊ´§ã¹ÃÙ»·Õè 1-3 ËÑÇ㨢ͧǧ¨Ã¤×Í IC2 «Ö§è à» ¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà àºÍà SX48BD «Ö§è ÀÒÂ㹺ÃèØâ»Ãá¡ÃÁá»ÅÀÒÉÒ¾ÕàºÊÔ¡ 2P ËÃ×ÍàÃÕÂ¡Ç Ò àºÊÔ¡ áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍÃì â´ÂÁÕà«ÃÒÁÔ¡àÃâ«à¹àµÍà 20MHz à» ¹ÍØ»¡Ã³ ¡Òí à¹Ô´ÊÑ­­Ò³¹ÒÌ ¡Òà¾×Íè ¡íÒ˹´ ¨Ñ§ËÇСÒ÷íÒ§Ò¹ ·Ò§´ ҹ˹ ǤÇÒÁ¨íҢͧ i-Stamp2P24 㪠äÍ«Õ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ͹ءÃÁàºÍà 24LC128 ÁÕ¤ÇÒÁ¨Ø 16 ¡ÔâÅ亵 (16KB) ºÃèؤÒí ÊÑ§è ¢Í§ PBASIC-2 ·Õãè ª Ã¹Ñ â»Ãá¡ÃÁ¢Í§àºÊÔ¡áʵÁ» 2P ä´ 4,000 ¤íÒÊѧè â´ÂẠ§ÍÍ¡à» ¹ 8 ª ǧ ª ǧÅÐ 2 ¡ÔâÅ亵 â´ÂäÁâ¤Ã¤Í¹â·ÃÅàÅÍà ÊÒÁÒöàÃÕ¡â»Ãá¡ÃÁà¾×Íè ·íÒ§Ò¹ä´ ¤ÃÒÇÅÐ 1 ª ǧËÃ×ÍäÁ à¡Ô¹ 2 ¡ÔâÅ亵 áµ ÊÒÁÒöàÃÕ¡㪠§Ò¹â»Ãá¡ÃÁµ Íà¹×Íè §¡Ñ¹ä´ ¡ÒÃà¡çºÃÑ¡ÉÒ¢ ÍÁÙÅ·íÒä´ ¹Ò¹ 10 » áÅÐ ÁÕÃͺ¢Í§â»Ãá¡ÃÁãËÁ ä´ 100,000 Ãͺ â´ÂàÁ×Íè ¼Ùã ª §Ò¹à¢Õ¹â»Ãá¡ÃÁ¾ÕàºÊÔ¡àÃÕºà ÍÂáÅ Ç ¨Ð´Òǹ âËŴŧ ÁÒÂѧ i-Stamp2P24 ¼ Ò¹¾Íà µÍ¹Ø¡ÃÁ ÊÑ­­Ò³ä¿¿ Ҩж١á»Å§ÃдѺÊÑ­­Ò³ãË à» ¹ÃдѺ·Õ·áÕ ÍÅ´ ÇÂǧ¨Ãá»Å§ ÃдѺÊÑ­­Ò³«Ö§è 㪠IC1 äÍ«ÕàºÍà MAX232 (ËÃ×ÍÍÒ¨á·¹ä´ ´Ç ÂàºÍà ICL232) ÃÇÁ·Ñ§é ÊÑ­­Ò³·Õãè ª 㹡Òà ÃÕ૵´ Ç Í ҧäáçµÒÁ¼Ùã ª §Ò¹ÊÒÁÒö·íÒ¡ÒÃÃÕ૵Ãкºä´ ´Ç ¡Òõ ÍÊÇÔµª ¡´µÔ´»Å Í´Ѻࢠҷբè Ò RESET Ê Ç¹¡ÒÃâ»Ãá¡ÃÁ¢ ÍÁÙÅ㪠¡ÒÃâ»Ãá¡ÃÁã¹ÅѡɳÐ͹ءÃÁ´ Ç¡ÒõԴµ ͡Ѻ¾Íà µÍ¹Ø¡ÃÁ¢Í§à¤Ã×èͧ ¤ÍÁ¾ÔÇàµÍà â´Âµ ÍÊÒ¨ҡ¢Ò TxD, RxD, DTR áÅÐ ¡ÃÒÇ´ ¢Í§¾Íà µÍ¹Ø¡ÃÁࢠÒÊÙ¢ Ò SIN, SOUT, ATN áÅÐ ¡ÃÒÇ´ ¢Í§ i-Stamp2P24 ¹Í¡¨Ò¡¹Ñ¹é ·Õ¢è Ò 6 áÅÐ 7 ¢Í§¾Íà µÍ¹Ø¡ÃÁµ ͧµ Ͷ֧¡Ñ¹´ Ç à¾×Íè ãË ÊÒÁÒöâ»Ãá¡ÃÁ ¢ ÍÁÙź¹ i-Stamp2P2424 ä´ µÅÍ´àÇÅÒÍ ҧÍѵâ¹ÁÑµÔ ´Ñ§áÊ´§ã¹ÃÙ»·Õè 1-4 ÊÑ­­Ò³¨Ò¡¾Íà µÍ¹Ø¡ÃÁ¢Í§¤ÍÁ¾ÔÇàµÍà â´Â·ÑèÇä» ÁÕÃдѺáç´Ñ¹ÊÙ§¡Ç ÒÃдѺ·Õ·ÕáÍÅ ¡Å ÒǤ×ÍÁÕ áç´Ñ¹»ÃÐÁÒ³ 12V ÊíÒËÃѺ¤ÍÁ¾ÔÇàµÍà µ§Ñé âµ Ð áÅÐ 3V ¶Ö§ 8V ÊíÒËÃѺ¤ÍÁ¾ÔÇàµÍà ⹠µºØ¡ ´Ñ§¹Ñ¹é ¨Ö§µ ͧÁÕǧ¨Ãá»Å§ÃдѺÊÑ­­Ò³¨Ò¡¤ÍÁ¾ÔÇàµÍà ãË à» ¹ÃдѺ·Õ·áÕ ÍÅ (0-5V) à¾×Íè ãË ÊÒÁÒöµÔ´µ ͡Ѻ IC2 «Ö§è ¡ç¤Í× àºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍÃ ä´ â´Âǧ¨Ã´Ñ§¡Å ÒÇ¹Ñ¹é ¨Ð㪠IC1 àºÍà MAX232 ·íÒ˹ Ò·Õ¹è Õé ¢Ò SIN à» ¹¢ÒÊíÒËÃѺÃѺ¢ ÍÁÙŨҡ¤ÍÁ¾ÔÇàµÍà àÁ×Íè ¢Ò¤ÍÁ¾ÔÇàµÍà ʧ ¢ ÍÁÙÅ 1 ÁÒ ¨Ð·íÒãË SIN à» ¹ ź IC1 ¨Ð¨Ñ´¡Ò÷íÒãË ·¢Õè Ò RxD ¢Í§ IC2 ÁÕáç´Ñ¹ +5V à¡Ô´à» ¹Åͨԡ 1 ã¹·Ò§µÃ§¢ ÒÁàÁ×Íè ¤ÍÁ¾ÔÇàµÍà ʧ ¢ ÍÁÙÅ 0 ¢Ò SIN ¨Ðà» ¹ºÇ¡ IC1 ¨Ð¡ÅѺÅͨԡ·íÒãË ¢Ò RxD àÊÁ×͹µ Íŧ¡ÃÒÇ´ ÁÕÅͨԡ໠¹ 0 ã¹¢³Ð·Õ¢è Ò SOUT 㪠ÊÒí ËÃÑºÊ §¢ ÍÁÙŨҡàºÊÔ¡áʵÁ» 2P ä»Âѧ¤ÍÁ¾ÔÇàµÍà àÁ×èÍà» ¹àª ¹¹Õé㹡ÒõԴµ ÍÃÐËÇ Ò§ i-Stamp2P24 ¡Ñº¤ÍÁ¾ÔÇàµÍà ¨Ðµ ͧ¼ÅÑ´¡Ñ¹ÃÑºÊ §¢ ÍÁÙÅ àÁ×èÍ ¤ÍÁ¾ÔÇàµÍà ʧ ¢ ÍÁÙÅÁÒ i-Stamp2P24 µ ͧÃѺ¢ ÍÁÙÅÍ ҧà´ÕÂÇ äÁ ÊÒÁÒÃ¶Ê §¢ ÍÁÙÅ¡ÅѺä»ã¹àÇÅÒà´ÕÂǡѹä´

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#


˹ ǤÇÒÁ¨íÒâ»Ãá¡ÃÁ 16 ¡ÔâÅ亵 (2x8 ¡ÔâÅ亵 ) ºÃèØâ»Ãá¡ÃÁ¾ÕàºÊÔ¡ 4,000 ºÃ÷Ѵ

PBASIC-2P ÍÔ¹àµÍà ¾ÃÕµàµÍÃ

32 ¢ÒÍÔ¹¾ØµàÍÒµ ¾Øµáºº´Ô¨ÔµÍÅ 55 ¤íÒÊÑè§ÀÒÉÒ¾ÕàºÊÔ¡ l ÁÕ¤íÒÊÑ觷ҧ¤³ÔµÈÒʵà áÅÐÅͨԡ¢Ñ鹡 ÒÇ˹ Ò l ˹ ǤÇÒÁ¨íÒáÃÁ 32+64 亵 l ¤ÇÒÁàÃçÇ 12,000 ¤íÒÊÑè§ÀÒÉÒàºÊÔ¡µ ÍÇÔ¹Ò·Õ l ÍѵÃҺʹ㹡ÒÃÊ×èÍÊÒÃ͹ءÃÁ 115 kbps l ¿ §¡ ªÑè¹¾ÔàÈɢͧ¢ÒÍÔ¹¾ØµàÍÒµ ¾Øµ ¡íÒà¹Ô´ÊÑ­­Ò³¾ÑÅÊ , PWM,DTMF, ÊÑ­­Ò³àÊÕ§, ÍÔ¹¾ØµµÑǵ Ò¹·Ò¹»ÃѺ¤ Òä´ , ÇÑ´¤ÇÒÁ¶Õè, àª×èÍÁµ ÍÍØ»¡Ã³ ÃкººÑÊ 1 ÊÒÂáÅÐ I C l l

µ ͡Ѻ¾Íà µÍ¹Ø¡ÃÁ à¾×Íè âËÅ´â»Ãá¡ÃÁ µ Íä¿àÅÕÂé § +5V

¢ÒÍÔ¹¾ØµàÍÒµ ¾µØ 16 ¢Ò (P0 ¶Ö§ P15)

ÃÙ»·Õè 1-1 ˹ ÒµÒáÅÐä´ÍÐá¡ÃÁàº×Íé §µ ¹¢Í§ i-Stamp2P24 âÁ´ÙÅàºÊÔ¡áʵÁ» 2P Ãع 24 ¢Ò ¢Ò·Õè TX RX ATN GND P0 P1 P2 P3 P4 P5 P6 P7

1 2 3 4 5 6 7 8 9 10 11 12

24 23 22 21 20 19 18 17 16 15 14 13

GND RES +5V P15 P14 P13 P12 P11 P10 P9 P8

ª×èÍ¢Ò

˹ Ò·Õè Ê §¢ ÍÁÙÅÍ͡Ẻ͹ءÃÁ àª×èÍÁµ ͡Ѻ¢Ò RxD (¢Ò 2) ¢Í§¾Íà µÍ¹Ø¡ÃÁ¢Í§¤ÍÁ¾ÔÇàµÍà ¼ Ò¹¤Í¹à¹ç¡àµÍà DB-9 ÃѺ¢ ÍÁÙÅࢠÒẺ͹ءÃÁ àª×èÍÁµ ͡Ѻ¢Ò TxD (¢Ò 3) ¢Í§¾Íà µÍ¹Ø¡ÃÁ¢Í§¤ÍÁ¾ÔÇàµÍà ¼ Ò¹¤Í¹à¹ç¡àµÍà DB-9 ¢ÒÃÕ૵ÅͨԡÊÙ§ àª×èÍÁµ ͡Ѻ¢Ò DTR (¢Ò 4) ¢Í§¾Íà µÍ¹Ø¡ÃÁ¢Í§ ¤ÍÁ¾ÔÇàµÍà ¼ Ò¹¤Í¹à¹ç¡àµÍà DB-9

1

Tx ËÃ×Í S OUT

2

Rx ËÃ×Í S IN

3

ATN

4

VSS/GND

¢Ò¡ÃÒÇ´ àª×èÍÁµ ͡Ѻ¢Ò GND (¢Ò 5) ¢Í§¾Íà µÍ¹Ø¡ÃÁ¢Í§¤ÍÁ¾ÔÇàµÍà ¼ Ò¹¤Í¹à¹ç¡àµÍà DB-9

5-20 21 22 23 24

P0-P15 +5V RES Vss/GND N/A

¢Ò¾Íà µÍÔ¹¾ØµàÍÒµ ¾Øµ 16 ¢Ò

i-Stamp2P24

¢Òä¿àÅÕé§ +5V ¨Ò¡ÀÒ¹͡ ¢ÒÃÕ૵ÅͨԡµíèÒÊíÒËÃѺÃÕ૵ i-Stamp2P24 ¢Ò¡ÃÒÇ´ ¢Í§ i-Stamp2P24 ¢Ò¹ÕéäÁ ÁÕ¡ÒÃ㪠§Ò¹

ÃÙ»·Õè 1-2 áÊ´§¡ÒèѴ¢ÒáÅСÒ÷íÒ§Ò¹ã¹áµ ÅТҢͧ i-Stamp2P24 $

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¤Ø³ÊÁºÑµ¢Ô ͧ i-Stamp2P24 l

ÁÕ¤ÇÒÁÊÒÁÒö·Ñ´à·ÕÂÁ¡ÑºâÁ´ÙÅàºÊÔ¡áʵÁ» 2P Ãع BS2P24-IC

l

㪠àºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍà ÅÔ¢ÊÔ·¸Ô¶ì ¡Ù µ ͧ¨Ò¡ Paralalx Inc., USA.

l

¤ÇÒÁ¶ÕÊè ­ Ñ ­Ò³¹ÒÌ ¡Ò 20MHz 㪠à«ÃÒÁÔ¡àÃâ«à¹àµÍà 20MHz 㹡ÒáíÒà¹Ô´ÊÑ­­Ò³¹ÒÌ ¡Ò

l

¤ÇÒÁàÃçÇ㹡ÒûÃÐÁÇżŠ12,000 ¤íÒÊѧè ÀÒÉÒ¾ÕàºÊÔ¡µ ÍÇÔ¹Ò·Õ

l ¢¹Ò´Ë¹ ǤÇÒÁ¨íÒ 16 ¡ÔâÅ亵 Ạ§à» ¹ 8 Ê Ç¹ Ê Ç¹ÅÐ 2 ¡ÔâÅ亵 ·íÒãË ÊÒÁÒöà¡çºâ»Ãá¡ÃÁÊíÒËÃѺ

·íÒ§Ò¹·Õáè µ¡µ Ò§áÅÐäÁ à¡ÕÂè Ç¢ ͧ¡Ñ¹ä´ ÁÒ¡¶Ö§ 8 â»Ãá¡ÃÁ ÃÇÁ·Ñ§é ÂѧÊÒÁÒöàÃÕ¡ãË ·Òí §Ò¹µ Íà¹×Íè §¡Ñ¹·Ñ§é 8 â»Ãá¡ÃÁä´ ¢ ÍÁÙÅã¹Ë¹ ǤÇÒÁ¨íÒäÁ Ê­ Ù ËÒ áÁ äÁ ¡Òè ÒÂä¿àÅÕÂé § áÅÐà¡çº¢ ÍÁÙÅä´ ¹Ò¹ 10 » ÊÒÁÒö à¢ÕÂ¹Åºä´ 100,000 Ãͺ l

˹ ǤÇÒÁ¨íÒáÃÁ 32 亵

˹ ǤÇÒÁ¨íÒáÃÁÊá¤Ãµª á¾´ (scratch pad RAM) 128 亵 Ạ§à» ¹ 2 Ê Ç¹ 1 亵 ÊÒí ËÃѺà¡çº¤ Ò µíÒá˹ §¢Í§â»Ãá¡ÃÁ áÅÐÍÕ¡ 127 亵 ÊÒí ËÃѺà¡çº¢ ÍÁÙÅ·ÑÇè ä»

l l

㪠ä¿àÅÕÂé § +5V µ ͧ¡ÒáÃÐáÊ 65mA ã¹¢³Ð·íÒ§Ò¹ áÅÐ 200mA ã¹âËÁ´ÊÅÕ»

l

àª×Íè Áµ ͡Ѻ¤ÍÁ¾ÔÇàµÍà ¼Ò ¹¾Íà µÍ¹Ø¡ÃÁ RS-232 ÊíÒËÃѺ´Òǹ âËÅ´â»Ãá¡ÃÁ áÅÐÊ×Íè ÊÒâ ÍÁÙÅ

l

¨íҹǹ¾Íà µÍÔ¹¾ØµàÍÒµ ¾µØ 16 ª ͧ ·íÒ§Ò¹ÍÔÊÃШҡ¡Ñ¹ ËÃ×ͨѴ໠¹¡ÅØÁ ä´ µ§Ñé áµ 4, 8 áÅÐ 16 ¢Ò

l

¤ÇÒÁÊÒÁÒö㹨 Ò¡ÃÐáÊ«Íà Ê/«Ô§¡ µÍ ¢Ò 30mA/30mA

l

¤ÇÒÁÊÒÁÒö㹨 Ò¡ÃÐáÊ«Íà Ê/«Ô§¡ ʧ٠ÊØ´µ Í¡ÅØÁ 8 ¢Ò (P0-7 áÅÐ P8-15) 60mA/60mA

l

ÊÒÁÒö¢Ñº LED áÅÐà«Íà âÇÁÍàµÍà ¢¹Ò´àÅç¡ä´ â´ÂµÃ§

l

ÊÒÁÒöÊà ҧÊÑ­­Ò³àÊÕ§, DTMF (ÊÑ­­Ò³»ØÁ â·ÃÈѾ· ), PWM ä´ â´ÂäÁ µÍ §ãª Í»Ø ¡Ã³ µÍ à¾ÔÁè

ÃͧÃѺ¡ÒÃàª×Íè Áµ ͡ѺÍØ»¡Ã³ ÀÒ¹͡·Õ·è Òí §Ò¹â´Â㪠ÃкººÑÊ I2C ¢Í§ Philips áÅÐÃкººÑÊ 1 ÊÒ ¢Í§ Dallas Semiconductor l l

¾Ñ²¹Ò´ ÇÂÀÒÉÒ¾ÕàºÊÔ¡ ªØ´¤íÒÊѧè àËÁ×͹¡Ñº BS2P24-IC ·Ø¡»ÃСÒÃ

l

ÁÕ¤Òí ÊÑ§è ·Ñ§é ÊÔ¹é 55 ¤íÒÊѧè

l

¢Òàª×Íè Áµ Í㪠¤Í¹à¹ç¡àµÍà IDC µÑǼ٪ ºØ ·Í§Í ҧ´Õ ÊÒÁÒö㪠¡ºÑ ¤Í¹à¹ç¡àµÍà IDC µÑÇàÁÕÂä´

l

â»Ãá¡ÃÁ¾Ñ²¹Ò㪠àºÊÔ¡áʵÁ» àÍ´ÔàµÍà V2.39 ¢Ö¹é ä» ´Òǹ âËÅ´ä´ ·Õè http://www.parallax.com

l

ÁÕä¿áÊ´§ÊÀÒÇСÒ÷íÒ§Ò¹

l

¢¹Ò´¢Í§ºÍà ´ 1.5 x 1.2 ¹ÔÇé

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%


+5V

C6 0.1/63V +5V C1 16 1

C2

SOUT SIN ATN GND GND

RESET

2 4

IC1

C3

3 MAX3232 5

R1 4k7

20

19

26

19

33

25

18

47 48

24

17

23

16

22

15

21

14

20

13

17

12

16

11

15

10

14

9

7

10

9

2

8

9

8

3

13

12

1

4

D1 1N4148 15

6

23

TxD RxD

1 MCLR R2 150

32

27

5

C1-C5 10/25V

21 4

R3 150

C4

IC2 13 SX48AC BASIC Stamp2P 12 Interpreter

22 +5V

46 18

3 2 1

A2 A1 A0

SDA SCL 4

7

11

6

10

5

P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0

2

R4 4k7

8

8

+5V

3

5

6

6

7

IC3 24LC128

SDA SCL

CR1 20MHz

ÃÙ»·Õè 1-3 ǧ¨Ã¢Í§ i-Stamp2P24 ºÍà ´äÁâ¤Ã¤Í¹â·ÃÅàÅÍà àºÊÔ¡áʵÁ» 2P24

¢Ò¢Í§ i-Stamp2P24

1

2 3 4 5

6 7 8 9

&

SOUT (1) SIN (2) ATN (3) GND (4)

ÃÙ»·Õè 1-4 ¡ÒÃàª×èÍÁµ Í i-Stamp2P24 ¡Ñº¾Íà µ ͹ءÃÁ¢Í§¤ÍÁ¾ÔÇàµÍà Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¢Ò ATN «Ö§è µ ÍࢠҡѺ¢Ò DTR (Data Terminal Ready) 㪠µÃǨÊͺ¤ÇÒÁ¾Ã ÍÁ㹡ÒÃÃÑºÊ §¢ ÍÁÙÅ ¶ Ò¤ÍÁ¾ÔÇàµÍà ʧ ¢ ÍÁÙÅ 0 ¨Ðà» ¹¡ÒÃÃÕ૵ IC2 ´Ñ§¹Ñ¹é ã¹¢³Ð·Õâè »Ãá¡ÃÁ¢ ÍÁÙÅŧº¹àºÊÔ¡áʵÁ» «Í¿µ áÇà ¨ÐÊ §¾ÑÅÊ ÁÒÂѧ¢Ò ATN à¾×Íè ÃÕ૵ IC2 áŠǵÒÁ´ Ç¡ÒÃÊ §¢ ÍÁÙÅÁÒÂѧ¢Ò SIN à¾×Íè ᨠ§Ç Ò µ ͧ¡ÒÃà¢Õ¹â»Ãá¡ÃÁ ãËÁ ŧº¹àºÊÔ¡áʵÁ» áµ ¶Ò «Í¿µ áÇà ·Òí ãË ¢Ò ATN à» ¹Åͨԡ 1 àºÊÔ¡áʵÁ» ¨ÐÍÂÙã ¹âËÁ´Ãѹ IC2 ¨Ðá»ÅÀÒÉÒ·Õàè ¢Õ¹¢Ö¹é áÅ Çà¡çº¢ ÍÁÙŢͧâ»Ãá¡ÃÁŧ㹠IC3 «Ö§è à» ¹äÍ«Õ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ ͹ءÃÁ¢¹Ò´ 16 ¡ÔâÅ亵 àºÍà 24LC128 ¹Ñ¹è ¤×Í IC3 ·íÒ˹ Ò·Õàè » ¹Ë¹ ǤÇÒÁ¨íÒâ»Ãá¡ÃÁ¢Í§Ãкº ÊíÒËÃѺ¾Íà µÍÔ¹¾ØµàÍÒµ ¾µØ ·Ñ§é 16 ¢Ò¢Í§ i-Stamp2P24 ¨Ð㪠¢Ò¾Íà µµÑ§é áµ ¢Ò 10 ¶Ö§ 17 áÅÐ 20 ¶Ö§ 27 à» ¹¢Ò¾Íà µ P0 ¶Ö§ P15 µÒÁÅíҴѺ Ê Ç¹ÊÑ­­Ò³¹ÒÌ ¡Ò·Õãè ª ä´ ÁÒ¨Ò¡à«ÃÒÁÔ¡àÃâ«à¹àµÍà 20MHz i-Stamp2P24 µ ͧ¡ÒÃä¿àÅÕÂé § +5V ¡ÃÐáÊÍ ҧ¹ Í 65mA ¼Ùã ª §Ò¹à¾Õ§µ ÍÊÒ +5V áÅСÃÒÇ´ à¢ Ò ÁÒÂѧ i-Stamp2P24 ¡ç¨ÐÊÒÁÒö㪠§Ò¹ä´ ·¹Ñ ·Õ äÁ ¨Òí à» ¹µ Í§ãª Í»Ø ¡Ã³ ÊÒí ËÃѺÊà ҧǧ¨ÃÀÒ¤¨ ÒÂä¿à¾ÔÁè àµÔÁÍÕ¡

1.2 ¡ÒèѴ˹ ǤÇÒÁ¨íÒÀÒÂã¹ i-Stamp2P24 i-Stamp2P24 ÁÕ˹ ǤÇÒÁ¨íÒËÅÑ¡ÍÂÙ 2 »ÃÐàÀ·¤×Í Ë¹ ǤÇÒÁ¨íÒáÃÁÊíÒËÃѺà¡çº¢ ÍÁÙŪÑÇè ¤ÃÒÇ áÅÐ ¨ÐËÒÂä»àÁ×Íè äÁ ÁäÕ ¿àÅÕÂé §Ç§¨Ã «Ö§è ÂѧÊÒÁÒöẠ§ä´ Í¡Õ 2 ¡ÅØÁ ¤×Í Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÊíÒËÃѺà¡çº¤ ÒµÑÇá»Ã (Variable RAM) 32 亵 áÅÐ˹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´áÃÁ (scratchpad RAM) 64 亵 ÍÕ¡»ÃÐàÀ·Ë¹Ö§è ¤×Í Ë¹ ǤÇÒÁ¨íÒÍÕÍÕ¾ÃÍÁ·íÒ˹ Ò·Õèà» ¹Ê ǹà¡çº¢ ÍÁÙŢͧâ»Ãá¡ÃÁ¾ÕàºÊÔ¡áÅТ ÍÁÙÅÍ×è¹æ ·Õèà¡ÕèÂÇ¢ ͧ «Öè§ ¢ ÍÁÙÅäÁ Ê­ Ù ËÒÂ㹡óշäÕè ¿àÅÕÂé §ËÒÂä» à¹×Íè §¨Ò¡Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁà» ¹Ë¹ ǤÇÒÁ¨íÒẺ¹Í¹-âÇÅÒä·Å (nonvolatile) «Ö§è à» ¹Ë¹ ǤÇÒÁ¨íÒ»ÃÐàÀ·à¡çºÃÑ¡ÉÒ¢ ÍÁÙÅäÇ ä´ â´ÂäÁ µÍ §ãª ä¿àÅÕÂé § à»ÃÕºà·Õº¡Ñº¤ÍÁ¾ÔÇàµÍà áÅ Ç Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ¡çàËÁ×͹¡ÑºÎÒà ´´ÔÊ¡ ¹¹Ñè àͧ â´ÂÁѹÊÒÁÒöà¡çºä´ ·§Ñé â»Ãá¡ÃÁáÅÐá¿ Á¢ ÍÁÙÅ

1.2.1 ˹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅáÃÁÊíÒËÃѺà¡çº¤ ÒµÑÇá»Ã ËÃ×ÍàÃÕÂ¡Ç Ò ÃÕ¨ÊÔ àµÍà (register) à» ¹Ë¹ ǤÇÒÁ¨íÒËÅÑ¡·ÕÃè кºäÁâ¤Ã¤Í¹â·ÃÅàÅÍà µÍ §ÁÕ à¹×Íè §¨Ò¡ã¹¡Òà à¢Õ¹â»Ãá¡ÃÁµ ͧÁÕ¡ÒáíÒ˹´¤ ÒµÑÇá»Ãà¾×Íè »ÃÐÁÇżŠáÅÐ㪠¾¹×é ·ÕÊè Òí ËÃѺà¡çº¢ ÍÁÙŪÑÇè ¤ÃÒÇ ã¹ i-Stamp2P24 ÁÕ Ë¹ ǤÇÒÁ¨íÒáÃÁ 32 亵 ËÃ×Í 16 àÇÔô (1 àÇÔô ෠ҡѺ 16 ºÔµ ËÃ×Í 2 亵 ) ÊÒÁÒö¨Ñ´¡ÅØÁ ¢Í§Ë¹ ǤÇÒÁ¨íÒ¹Õé ä´ µ§Ñé áµ ÃдѺºÔµ, ¹ÔºàºÔÅ (෠ҡѺ 4 ºÔµ), 亵 (෠ҡѺ 8 ºÔµ) áÅÐàÇÔô ã¹µÒÃÒ§·Õè 1-1 áÊ´§¡ÒèѴÊÃõíÒá˹ § áÅЪ×Íè ¢Í§Ë¹ ǤÇÒÁ¨íÒáÃÁ ¨ÐàËç¹ä´ ÇÒ ¡ÒèѴ¡ÅØÁ ¨Ðµ ͧ¨Ñ´ÊÃèҡµíÒá˹ §ºÔµËÃ×͹Ժà¹ÔºËÃ×Í亵 ¢Í§Ë¹ ǤÇÒÁ ¨íÒ·Õµè ´Ô ¡Ñ¹ ઠ¹ ºÔµ 0 ¶Ö§ 3, ºÔµ 0 ¶Ö§ 7, ºÔµ 4 ¶Ö§ 7, ºÔµ 8 ¶Ö§ 15 ËÃ×ͺԵ 12 ¶Ö§ 15 äÁ ÊÒÁÒö¨Ñ´¡ÅØÁ ¢ ÒÁä»ÁÒä´ ã¹¾×¹é ·Õ¢è ͧ˹ ǤÇÒÁ¨íÒáÃÁ 3 àÇÔô ËÃ×Í 6 亵 áÃ¡ä´ ÃºÑ ¡ÒÃʧǹäÇ ÊÒí ËÃѺÃÕ¨ÊÔ àµÍà ¾Íà µ à¾×Íè ¡íÒ˹´ÅѡɳСÒ÷íÒ§Ò¹¢Í§¢Ò¾Íà µ·Ñ§é 16 ¢Ò ÍÑ¹ä´ á¡ INS ÊíÒËÃѺÃѺÊÑ­­Ò³ËÃ×Í¢ ÍÁÙÅࢠҷҧ¢Ò¾Íà µÍÔ¹¾Øµ OUTS ÊíÒËÃÑºÊ §¢ ÍÁÙÅÍÍ¡¢Ò¾Íà µàÍÒµ ¾µØ DIRS ÊíÒËÃѺ¤Çº¤ØÁ·ÔÈ·Ò§¢Í§¢Ò¾Íà µ Ê Ç¹·Õàè ËÅ×ÍÍÕ¡ 26 亵 ¨Ðà» ¹Ë¹ ǤÇÒÁ¨íÒÍÔÊÃÐ㪠ÊÒí ËÃѺà¡çº¢ ÍÁÙŢͧµÑÇá»Ãã´æ ã¹â»Ãá¡ÃÁ áµ µ ͧ¾Ö§ÃÐÅÖ¡äÇ àÊÁÍÇ Ò ¢ ÍÁÙÅÀÒÂã¹Ë¹ ǤÇÒÁ¨íÒã¹Ê ǹ¹Õ¨é ÐÊÙ­ËÒÂä»àÁ×Íè äÁ ÁäÕ ¿àÅÕÂé §Ç§¨Ã áÅÐàÁ×Íè ä¿àÅÕÂé § ǧ¨Ã¡ÅѺÁÒ ¤ Ңͧ¢ ÍÁÙŷѧé ËÁ´¨Ðà» ¹ 0 ËÅѧ¨Ò¡¹Ñ¹é ¨Ð¶Ù¡¡íÒ˹´ãËÁ ¨Ò¡â»Ãá¡ÃÁËÅÑ¡·Õàè ¢Õ¹¢Ö¹é

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'


ÃдѺàÇÔô INS OUTS DIRS W0

ª×Íè ÃÕ¨ÊÔ àµÍà ÃдѺ亵 ÃдѺ¹ÔºàºÔÅ

ÃдѺºÔµ

INL

INA, INB

IN0-IN7

INH

INC, IND

IN8-IN15

OUTL

OUTA, OUTB

OUT0-OUT7

OUTH

OUTC, OUTD

OUT8-OUT15

DIRL

DIRA, DIRB

DIR0-DIR7

DIRH

DIRC, DIRD

DIR8-DIR15

B0 B2

㪠§Ò¹·ÑÇè ä»

B3 W2....W11

B4....B23

W12

B24

¡íÒ˹´ãË à» ¹¢Ò ÍÔ¹¾Øµ ¡íÒ˹´ãË à» ¹¢Ò àÍÒµ ¾µØ ¡íÒ˹´·ÔÈ·Ò§ ¢Í§¢Ò¾Íà µ 㪠§Ò¹·ÑÇè ä»

B1 W1

˹ Ò·Õè

㪠§Ò¹·ÑÇè ä» ãª §Ò¹·ÑÇè ä»

B25

µÒÃÒ§·Õè 1-1 áÊ´§¡ÒèѴÊÃÃÃÕ¨ÊÔ àµÍà ÀÒÂ㹢ͧ i-Stamp2P24

1.2.2 ˹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´áÃÁ ÁÕ¢¹Ò´ 127 亵 à» ¹¾×¹é ·Õ¾è àÔ ÈÉ·Õàè ¢ Ò¶Ö§ä´ ´Ç ¡ÒÃ㪠¤Òí Êѧè GET áÅÐ PUT ¢Í§ i-Stamp2P24 à· Ò ¹Ñ¹é â´Â¾×¹é ·Õ¢è ͧ˹ ǤÇÒÁ¨íÒ¹Õãé ª ÊÒí ËÃѺà¡çº¢ ÍÁÙŪÑÇè ¤ÃÒÇ㹡óշÁÕè ¡Õ ÒáÃÐâ´´¢ ÒÁä»·íÒ§Ò¹ã¹â»Ãá¡ÃÁ ·ÕÍè ÂÙµ Ò §à¾¨¡Ñ¹¢Í§ i-Stamp2P24 â´Â¡ ͹¡Ò÷íÒ§Ò¹µ ͧÁÕ¡ÒÃà¡çº¢ ÍÁÙŢͧµÑÇá»Ãà´ÔÁäÇ ´Ç ¤íÒÊѧè PUT áÅÐ àÁ×Íè ·íÒ§Ò¹ã¹â»Ãá¡ÃÁ¹Ñ¹é àÃÕºà ÍÂáÅ Ç µ ͧ¡ÒáÃÐâ´´¡ÅѺÁÒ·íÒ§Ò¹·Õâè »Ãá¡ÃÁà´ÔÁ áÅÐÁÕ¤ÇÒÁµ ͧ¡ÒÃ㪠¢Í ÁÙÅ à´ÔÁ·Õàè ¡çºäÇ ã¹Ë¹ ǤÇÒÁ¨íÒÊᤵª á¾´áÃÁ¡çÊÒÁÒöàÃÕ¡¡ÅѺÁÒä´ ´Ç ¤íÒÊѧè GET ÍÒ¨ÁÍ§ä´ ÇÒ Ë¹ ǤÇÒÁ ¨íÒÊá¤Ãµª á¾´¤×Í Êáµç¡ (stack) ¹Ñ¹è àͧ â´ÂÁÕÅ¡Ñ É³Ð㹡ÒÃà¡çºáÅÐÍ Ò¹¢ ÍÁÙÅẺ FIFO (First-In-First-Out) ËÃ×Íà¡çº¡ Í¹Í Ò¹ÍÍ¡ÁÒ¡ ͹ «Ö§è ᵡµ Ò§¨Ò¡Êáµç¡¢Í§äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ·ÇÑè ä»·Õ¨è Ðà» ¹áºº FILO (first-In-LastOut) ËÃ×Íà¡çºà¢ Ò仡 Í¹Í Ò¹ÍÍ¡ÁÒ·ÕËÅѧ â´Âã¹ 127 亵 áá㪠à¡çº¢ ÍÁÙÅ Ê Ç¹äºµ Ê´Ø · Ò·յè Òí á˹ § 128 㪠à¡çºàÅ¢ËÁÒÂâ»Ãá¡ÃÁ·Õàè ºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍà ·Òí §Ò¹ÍÂÙã ¹¢³Ð¹Ñ¹é à¾×Íè ¨Ðä´ ·ÃÒºÇ Ò¢³Ð¹Õ¡é Òí Åѧ Ãѹâ»Ãá¡ÃÁã´ÍÂÙà ÐËÇ Ò§â»Ãá¡ÃÁ 0 ¶Ö§ 7 ¹Ñ¹è ¤×Í˹ ǤÇÒÁÊá¤Ãµª á¾´·Õµè Òí á˹ §¹ÕÊé ÒÁÒÃ¶Í Ò¹ä´ à¾Õ§Í ҧ à´ÕÂÇ àÁ×Íè ¨ ÒÂä¿àÅÕÂé §ãËÁ ËÃ×Íà¡Ô´¡ÒÃÃÕ૵ ¢ ÍÁÙŷѧé ËÁ´¨Ðà» ¹Èٹ ¨Ðµ ͧ¡íÒ˹´ãËÁ ¨Ò¡â»Ãá¡ÃÁ·Õàè ¢Õ¹¢Ö¹é

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


1.3.3 ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ ˹ ǤÇÒÁ¨íÒÊ Ç¹¹Õàé » ¹ËÑÇã¨ËÅѡ㹡Ò÷íÒ§Ò¹¢Í§ i-Stamp2P24 à¹×Íè §¨Ò¡¨Ð㪠ÊÒí ËÃѺà¡çºâ»Ãá¡ÃÁ ¾ÕàºÊÔ¡·Õàè ¢Õ¹¢Ö¹é ËÃ×ÍàÃÕÂ¡Ç Òà» ¹Ë¹ ǤÇÒÁ¨íÒâ»Ãá¡ÃÁ (program memory) ÃÇÁ¶Ö§à¡çº¢ ÍÁÙÅÊíÒËÃѺ¡Òà »ÃÐÁÇżŷÕäè Á µÍ §¡ÒÃãË Ê­ Ù ËÒÂ㹡óշäÕè Á ÁäÕ ¿àÅÕÂé §Ç§¨ÃËÃ×Íà» ¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅ (data memory) i-Stamp2P24 㪠˹ ǤÇÒÁ¨íÒ 16 ¡ÔâÅ亵 à¡çºâ»Ãá¡ÃÁä´ 8 â»Ãá¡ÃÁ â»Ãá¡ÃÁÅÐ 2 ¡ÔâÅ亵 «Ö§è µ Í ä»¹Õ¨é ТÍàÃÕ¡¡ÒÃẠ§Ê ǹ¢Í§Ë¹ ǤÇÒÁ¨íÒ¹ÕÇé Ò à¾¨ (page) ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ¢Í§ i-Stamp2P24 Ạ§ ÍÍ¡à» ¹ 8 ྨ ྨÅÐ 2 ¡ÔâÅ亵 àºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍà ¨ÐÊÒÁÒöࢠҶ֧à¾×Íè Ãѹâ»Ãá¡ÃÁä´ ¤ÃÒÇ ÅÐ 2 ¡ÔâÅ亵 ෠ҹѹé áµ ÊÒÁÒö·íÒ§Ò¹·Ø¡â»Ãá¡ÃÁã¹Ë¹ ǤÇÒÁ¨íÒ¹Õäé ´ ËÒ¡ÁÕ¡ÒÃ㪠¤Òí ÊÑ§è ·Õàè ª×Íè Áâ§ãË ¡ÃÐâ´´ ä»·íÒ§Ò¹Âѧâ»Ãá¡ÃÁã¹µíÒá˹ §Í×¹è ¹Ñ¹è ¤×ͤíÒÊѧè RUN àÁ×Íè ¨ ÒÂä¿ãË ¤Ãѧé áá àºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍà ¨ÐàÅ×Í¡·íÒ§Ò¹·Õâè »Ãá¡ÃÁ 0 ã¹à¾¨ááËÃ×Í à¾¨ 0 àÊÁÍ áÅÐÊÒÁÒö¡ÃÐâ´´ä»·íÒ§Ò¹Âѧâ»Ãá¡ÃÁÍ×¹è ä´ ´Ç ¤íÒÊѧè RUN áŠǵÒÁ´ ÇÂàÅ¢¢Í§â»Ãá¡ÃÁ·Õµè Í § ¡ÒáÃÐâ´´ä»·íÒ§Ò¹ «Ö§è àÁ×Íè 㪠¤Òí ÊÑ§è ¹Õáé Å Ç ¨ÐÁÕ¡ÒÃà¡çºµíÒá˹ §¢Í§â»Ãá¡ÃÁ·Õàè ºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍà 价íÒ§Ò¹äÇ ã¹Ë¹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´áÃÁã¹µíÒá˹ § 128 ·Ñ§é ¹Õàé ¾×Íè ᨠ§ãË â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ·ÃÒº¶Ö§¾×¹é ·Õ·è Òí §Ò¹¢Í§â»Ãá¡ÃÁ¾ÕàºÊÔ¡ã¹¢³Ð¹Ñ¹é ËÒ¡µ ͧ¡ÒÃá¡ ä¢â»Ãá¡ÃÁ੾ÒÐã¹Ê ǹ¹Ñ¹é ¡çÊÒÁÒö·íÒä´ â´ÂäÁ ¨Òí à» ¹µ ͧ´Òǹ âËÅ´ãËÁ ËÁ´·Ñ§é 16 ¡ÔâÅ亵 ¢Í§Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ ÊíÒËÃѺ¡ÒèѴÊÃõíÒá˹ §¢Í§ ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁà¾×Íè ÃͧÃѺâ»Ãá¡ÃÁ·Ñ§é ËÁ´¢Í§ i-Stamp2P24 áÊ´§ã¹µÒÃÒ§·Õè 1-2

áÍ´à´Ãʢͧ˹ ǤÇÒÁ¨íÒÍÕ; Õ ÃÍÁ $0000-$07FF $0800-$0FFF $1000-$17FF $1800-$1FFF $2000-$27FF $2800-$2FFF $3000-$37FF $3800-$3FFF

â»Ãá¡ÃÁ â»Ãá¡ÃÁ 0 â»Ãá¡ÃÁ 1 â»Ãá¡ÃÁ 2 â»Ãá¡ÃÁ 3 â»Ãá¡ÃÁ 4 â»Ãá¡ÃÁ 5 â»Ãá¡ÃÁ 6 â»Ãá¡ÃÁ 7

µÒÃÒ§·Õè 1-2 ¡ÒèѴÊÃÃ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁà¾×Íè ÃͧÃѺâ»Ãá¡ÃÁ¾ÕàºÊÔ¡¢Í§ i-Stamp2P24

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


1.4 JX-2SX plus II á¼ ¹Ç§¨Ãà͹¡»ÃÐʧ¤ ÊÒí ËÃѺ¾Ñ²¹Òâ¤Ã§§Ò¹´ Ç i-Stamp2P24 ǧ¨ÃÊÁºÙó áÊ´§ã¹ÃÙ»·Õè 1-5 Ê Ç¹Ãٻà ҧ˹ ÒµÒáÊ´§ã¹ÃÙ»·Õè 1-6 ºÍà ´ JX-2SX plus II ¹Õäé ´ ¨´Ñ àµÃÕÂÁ ǧ¨Ã¨ ÒÂä¿ áÅФ͹à¹ç¡àµÍà µÇÑ àÁÕ¢¹Ò´ 24 ¢ÒÊíÒËÃѺµÔ´µÑ§é i-Stamp áÅÐ i-Stamp2P24 ¾Ã ÍÁ·Ñ§é ¾×¹é ·ÕÊè Òí ËÃѺ Êà ҧǧ¨Ã¢¹Ò´ 2.5 : 4 ¹ÔÇé â´ÂÁÕ¨´Ø ºÑ´¡ÃÕ 984 ¨Ø´ à¾×Íè ¡ÒÃàÃÕ¹ÃÙà ºÊÔ¡áʵÁ» 2P Í ҧ»ÃÐËÂÑ´ÊÒÁÒö 㪠ºÍà ´ JX-2SX plus II à ÇÁ¡Ñº i-Stamp2P24 áŠǨѴËÒÍØ»¡Ã³ ·´Åͧ ¹íÒÁҺѴ¡ÃÕµ´Ô µÑ§é ŧº¹ºÍà ´ JX2SX plus II ¡çÊÒÁÒö·´ÅͧàÃÕ¹ÃÙä ´ ઠ¹¡Ñ¹ SW2 SERVO POWER

K4 +Vm SERVO 4.8-7.2V supply K3 Battery input

C8 C9 C10 1000 F 1000 F 1000 F 10V 10V 10V

+5V

+Vm

PORT GND

+Vin 6-16V

SW1 POWER

K2 +Vin DC input 7.5-16V

~ ~

IC1 7805

+ C1 220 F 25V

-

C2 0.1 F 63V

+5V

MCU port

C4 47 F 16V

J1 P0

+5V LED1 POWER R1 510

C3 0.1 F 63V

J2 P1 J3 P2

BD1 1A50V

J4 P3

+5V 1 2 C5 C5-C6 0.1 F 63V x2

K1 RS-232 (RJ-11 female)

3 4 C6

23

21

i-Stamp Socket

J5 P4

C7 0.1 F 63V

J6 P5 J7 P6

22 SW2 RESET

20 19 18 17 16 15 14 13 12 11 10

9

8

7

6

5

J8 P7

P8 +Vm GND P9 +Vm GND +Vm

P10 +Vm GND

P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0

i-Stamp PORT

ÃÙ»·Õè 1-5 ǧ¨ÃÊÁºÙó ¢Í§ JX-2SX plus II ºÍà ´¾Ñ²¹Òâ¤Ã§§Ò¹ÊíÒËÃѺ i-Stamp áÅÐ i-Stamp2P24

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


RS-232

Vs 4.8 to 6V for SERVO SERVO PORT

i-Stamp POWER

+Vs P10

P9

P8

P

6-12Vdc

Vin

RESET

ON +Vs

Microcontroller port (P15-P0) +5V # " ! 9 8 7 6 5 4 3 2 1 0 GND

GND

+Vs

JX-2SXplusII

¾×é¹·ÕèÊíÒËÃѺµ Íǧ¨ÃËÃ×͵ԴµÑé§á¼§µ Íǧ¨Ã (àºÃ´ºÍà ´) ¢¹Ò´¡ÅÒ§

- 2% +

- 2$ +

- 2# +

- 2" +

- 2! +

- 2 +

- 2 +

- 2 +

ÃÙ»·Õè 2 áÊ´§Ë¹ ÒµÒáÅеíÒá˹ §¢Í§Ê ǹ»ÃСͺµ Ò§æ ¢Í§ºÍà ´ JX-2SX plus II

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


ÊíÒËÃѺ¡ÒÃ㪠§Ò¹Ã ÇÁ¡Ñº i-Stamp2P24 ÊÒÁÒö·íÒä´ Í ҧ§ Ò´ÒµÒÁ¢Ñ¹é µÍ¹µ Í仹Õé (1) ¹íÒ i-Stamp2P24 ÁÒµÔ´µÑ§é ŧº¹¤Í¹à¹ç¡àµÍà µÇÑ àÁÕ 24 ¢Ò·ÕÇè Ò §º¹ºÍà ´ JX-2SX plus II â´ÂÊѧࡵ·ÔÈ·Ò§ãË ¶¡Ù µ ͧ ´Ñ§ÃÙ»

(2) àª×Íè Áµ ͺÍà ´ JX-2SX plus II ࢠҡѺ¾Íà µÍ¹Ø¡ÃÁ¢Í§¤ÍÁ¾ÔÇàµÍà â´Â㪠ÊÒ´Òǹ âËÅ´ CX-4 ¶ ÒËÒ¡¤ÍÁ¾ÔÇàµÍà ÁàÕ ©¾ÒоÍà µ USB ¨Ðµ ͧ㪠µÇÑ á»Å§ USB à» ¹ RS-232 ã¹·Õ¹è ¢Õé Íá¹Ð¹íÒÃع UCON-232S ¢Í§ INEX (www.inex.co.th) â´ÂÁÕä´ÍÐá¡ÃÁ¡Òõ Í㪠§Ò¹´Ñ§ÃÙ»·Õè 1-7 (3) ¨ ÒÂä¿ãË á¡ ºÍà ´ JX-2SX plus II ¨ÐàËç¹ä¿ ON ·Õµè ÇÑ i-Stamp2P24 µÔ´ÊÇ Ò§ µ ÍࢠҡѺ¾Íà µÍ¹Ø¡ÃÁ ¢Í§¤ÍÁ¾ÔÇàµÍà â´ÂµÃ§

ÊÒÂ CX-4 UCON-232S

Vs

SERVO PORT

i-Stamp2P24

4.8 to 6V for SERVO

POWER

+Vs P10

P9

P8

P

Vin

RS-232

6-12Vdc

µ ÍÊÒ CX-4 ࢠҡѺ UCON-232S µÑÇá»Å§ÊÑ­­Ò³¾Íà µ USB à» ¹¾Íà µÍ¹Ø¡ÃÁ 㹡óշ¤èÕ ÍÁ¾ÔÇàµÍà äÁ Á¾ Õ Íà µÍ¹Ø¡ÃÁ

µ ͡Ѻ¾Íà µ USB ¢Í§¤ÍÁ¾ÔÇàµÍÃ

RESET

ON

Microcontroller port (P15-P0) +5V # " ! 9 8 7 6 5 4 3 2 1 0 GND

+Vs GND

+Vs

JX-2SXplusII

ÃÙ»·Õè 1-7 áÊ´§¡Òõ Í㪠§Ò¹ºÍà ´ JX-2SX plus II ¡Ñº¤ÍÁ¾ÔÇàµÍÃ

"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¤Í¹à¹ç¡àµÍà DB-9 µÑÇàÁÕÂ

»ÅÑ¡ê âÁ´ÙÅÒ Ã RJ11 Ẻ 6P4C

# "

#

!

!

¢Ò RxD

!

¢Ò TxD

"

¢Ò DTR

#

¢Ò GND

"

´ ҹ˹ ÒÊÑÁ¼ÑÊ

ÃÙ»·Õè 1-8 áÊ´§ÃÒÂÅÐàÍÕ´¡ÒÃàª×Íè Áµ ͧ͢ÊÒ CX-4 ·Õãè ª ¡ºÑ ºÍà ´ JX-2SX plus II (4) à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ·ÕËè ¹ Òµ Ò§àÍ´ÔàµÍà ࢠÒä»ã¹àÁ¹Ù Run àÅ×Í¡ Identified ¶ Ò·Ø¡Í ҧ¶Ù¡µ ͧ ¨Ð»ÃÒ¡¯Ë¹ Òµ Ò§áÊ´§¡ÒõԴµ ʹѧÃÙ»

¨ÐàËç¹Ç Ò㹪 ͧ COM1 ¨Ð»ÃÒ¡¯ª×Íè BASIC Stamp2P40 Vxx (xx à» ¹àÅ¢àÇÍà ª¹Ñè ) Ê Ç¹ã¹ª ͧ Loopback áÅÐ echo »ÃÒ¡¯¢ ͤÇÒÁ Yes à» ¹¡ÒÃᨠ§ãË ·ÃÒºÇ Ò â»Ãá¡ÃÁÊÒÁÒöµÔ´µ ͡Ѻ àºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍÃ ä´ áÅ Ç Ê Ç¹¡ÒÃàª×Íè Áµ ÍÊÒÂáÅСÒÃÃÑºÊ §ÊÑ­­Ò³¶Ù¡µ ͧ¾Ã ÍÁ·íÒ§Ò¹ (5) ¶ Ò»ÃÒ¡¯¢ ͤÇÒÁµÒÁÃÙ»

áÊ´§Ç Ò ¡ÒÃàª×Íè Áµ ÍÃÐËÇ Ò§¤ÍÁ¾ÔÇàµÍà ¡ºÑ i-Stamp2P24 Å ÁàËÅÇ«Ö§è ÍÒ¨à¡Ô´¨Ò¡ ÊÒÂàª×Íè Áµ ÍÃÐËÇ Ò§¤ÍÁ¾ÔÇàµÍà ¡ºÑ ºÍà ´·´Åͧ¢Ò´ËÃ×͵ ÍäÁ ¶¡Ù µ ͧ ãË µÃǨÊͺÊÒÂàª×Íè Áµ ÍÇ Òµ Ͷ١µ ͧ ËÃ×ÍäÁ â´ÂÁÕä´ÍÐá¡ÃÁ¡Òõ ÍÊÒ·Õãè ª 㹡ÒÃàª×Íè Áµ ÍËÃ×Í·Õàè ÃÕÂ¡Ç ÒÊÒ´Òǹ âËÅ´áÊ´§ã¹ÃÙ»·Õè 1-8 ËÃ×ÍÍÒ¨ à¡Ô´¨Ò¡äÁ ä´ ¨Ò Âä¿ãË á¡ µÇÑ ºÍà ´ ËÃ×͵ԴµÑ§é i-Stamp2P24 ¼Ô´µíÒá˹ § ËÃ×͵ÑÇÍÔ¹àµÍà ¾ÃÕµàµÍà àÊÕÂËÒ «Ö§è 㹡óÕËÅѧà¡Ô´¢Ö¹é ä´ ÂÒ¡ÁÒ¡ ãË µÃǨÊͺ¡Òè ÒÂä¿á¡ Ç Ò¶Ù¡¢ÑÇé ËÃ×ÍäÁ ÊÒÂä¿àÅÕÂé §µ Íá¹ ¹Ë¹ÒÊÁºÙó ´ËÕ Ã×Í äÁ ÃÇÁ¶Ö§¡ÒõԴµÑ§é i-Stamp2P24 (6) ·´Åͧà¢Õ¹â»Ãá¡ÃÁ§ ÒÂæ â´ÂàÃÔÁè ¨Ò¡àÅ×Í¡ä´àÃ硵տËÃ×ͪ¹Ô´¢Í§àºÊÔ¡áʵÁ» ·µÕè Í § ¡ÒÃ㪠§Ò¹ ã¹·Õ¹è ¤Õé Í× àºÊÔ¡áʵÁ» 2P ä»·Õàè Á¹Ù Directive àÅ×Í¡ BS2P ¨Ð»ÃÒ¡¯¢ ͤÇÒÁ '{$STAMP BS2P} ¢Ö¹é º¹ºÃ÷Ѵáá ¡´ Enter Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#


¡ÒõÃǨÊͺµíÒá˹ §¢Í§¾Íà µÍ¹Ø¡ÃÁàÊÁ×͹ ËÃ×Í USB Serial port ¡ÒõÃǨÊͺµíÒá˹ §¢Í§¾Íà µÍ¹Ø¡ÃÁàÊÁ×͹·Õèà¡Ô´¢Öé¹ËÅѧ¨Ò¡·Õèµ ÍµÑÇá»Å§ÊÑ­­Ò³¾Íà µ USB à» ¹¾Íà µÍ¹Ø¡ÃÁ RS-232 ࢠҡѺ¾Íà µ USB ¢Í§¤ÍÁ¾ÔÇàµÍà ÁÕ¢¹Ñé µÍ¹´Ñ§¹Õé (1) ¤ÅÔ¡·Õ»è ÁØ Start áÅ ÇàÅ×Í¡ä»·Õè Control Panel (2) ¨Ò¡¹Ñ¹é ´ÑºàºÔŤÅÔ¡àÅ×Í¡·Õè System (3) àÅ×Í¡ä»·Õáè ·ç» Hardware áŠǤÅÔ¡·Õè Device Manager

(4) µÃǨÊͺÃÒ¡ÒÃÎÒà ´áÇà ·ËÕè ÇÑ ¢ Í Port ¨Ð¾º USB Serial port ãË ´ÇÙ Ò ÁÕ¡ÒÃàÅ×Í¡µíÒá˹ §¢Í§¾Íà µ ͹ءÃÁ USB Serial port äÇ ·µÕè Òí á˹ §ã´ »¡µÔ¨Ðà» ¹ COM3 ¢Ö¹é ä» ãË ãª ¤Ò ¢Í§µíÒá˹ §¢Í§¾Íà µÍ¹Ø¡ÃÁ¹Õãé ¹ ¡ÒáíÒ˹´¡ÒÃàª×Íè Áµ ͡Ѻâ»Ãá¡ÃÁµ Íä» µÒÁÃÙ»µÑÇÍ ҧ¨Ðà» ¹ COM6

$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


(7) ä»·Õàè Á¹Ù Directive àÅ×Í¡ PBASIC µÒÁ´ Ç Version 2.5 à¾×Íè àÅ×Í¡Ãع ¢Í§«Í¿µ áÇà ·Õè 㪠㹡ÒþѲ¹Ò ¨Ð»ÃÒ¡¯¢ ͤÇÒÁ '{$PBASIC 2.5} ¡´ Enter (8) ÂѧÍÂÙ· àÕè Á¹Ù Directive ÅíҴѺµ Íä»à» ¹¡ÒÃàÅ×Í¡µíÒá˹ §¢Í§¾Íà µÍ¹Ø¡ÃÁ·Õãè ª àª×Íè Áµ ͡Ѻ ºÍà ´ JX-2SX plus II ·Õµè ´Ô µÑ§é i-Stamp2P24 áÅ Ç â´ÂàÅ×Í¡ Port µÒÁ´ Ç COM1 ËÃ×͵íÒá˹ § COM Í×¹è ·Õ¹è Òí ºÍà ´ JX-2SX plus II ÁÒµ Í´ Ç ¨Ð»ÃÒ¡¯¢ ͤÇÒÁ '{$PORT COM1} ¡´ Enter 㹡óշãÕè ª µÇÑ á»Å§¾Íà µ USB à» ¹¾Íà µÍ¹Ø¡ÃÁ RS-232 ¨Ðµ ͧµÃǨÊͺµíÒá˹ §¢Í§¾Íà µÍ¹Ø¡ÃÁ·Õäè ´ÃàÇÍà ¢Í§µÑÇá»Å§¾Íà µÊà ҧ¢Ö¹é (´ÙÃÒÂÅÐàÍÕÂ´ä´ ¨Ò¡¡Ãͺá¡ : ¡ÒõÃǨÊͺµíÒá˹ §¢Í§¾Íà µÍ¹Ø¡ÃÁàÁ×Íè 㪠µÇÑ á»Å§ USB à» ¹ RS-232) (9) ¾ÔÁ¾ ¤Òí Êѧè debug "welcome" à» ¹¡ÒÃÊѧè ãË i-Stamp2P24 Ê §¢ ͤÇÒÁ welcome ä» áÊ´§Âѧ˹ Òµ Ò§ Debug Terminal ¢Í§â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Ç¡´ Enter (10) ¡´»Ø Á Run ¨Ð»ÃÒ¡¯Ë¹ Òµ Ò§µÃǨÊͺ¡ÒÃàª×èÍÁµ ÍàºÊÔ¡áʵÁ» ¡Ñº¤ÍÁ¾ÔÇàµÍà µÒÁ´ ÇÂ˹ Òµ Ò§´Òǹ âËÅ´â»Ãá¡ÃÁ áÅÐÊØ´· Ò»ÃÒ¡¯Ë¹ Òµ Ò§ Debug Terminal áÊ´§¢ ͤÇÒÁ welcome ´Ñ§ã¹ÃÙ» ËÒ¡¡´ÊÇÔµª RESET º¹ºÍà ´ â»Ãá¡ÃÁ¨ÐáÊ´§¢ ͤÇÒÁ«éÒí ÍÕ¡

(11) ËÒ¡à¢Õ¹â»Ãá¡ÃÁ·´ÅͧàÃÕºà ÍÂáÅ Ç áÅе ͧ¡ÒÃà¡çºã¹ÃٻῠÁ¢ ÍÁÙÅ ãË º¹Ñ ·Ö¡á¿ Á ¢ ÍÁÙÅâ´Â¡íÒ˹´ãË Á¹Õ ÒÁÊ¡ØÅ .BSP àÊÁÍ (12) »Å´ä¿àÅÕÂé §áÅÐÊÒÂàª×Íè Áµ ͤÍÁ¾ÔÇàµÍà ÍÍ¡ ·íÒ¡Òõ Íǧ¨ÃµÒÁµ ͧ¡Òà â´Â¡ÒúѴ¡ÃÕ µÔ´µÑ§é ÍØ»¡Ã³ º¹ºÍà ´ JX-2SX plus II µÒÁ·Õµè Í §¡Òà ¨Ò¡¹Ñ¹é µ ÍÊÒÂࢠҡѺ¤ÍÁ¾ÔÇàµÍà áŠǨ ÒÂä¿ à¢Õ¹â»Ãá¡ÃÁ ´Òǹ âËÅ´â»Ãá¡ÃÁ à¾ÕÂ§à· Ò¹Ñ¹é ¡ç¨ÐÊÒÁÒöàÃÕ¹ÃÙá ÅÐ㪠§Ò¹àºÊÔ¡áʵÁ» 2P ¼ Ò¹·Ò§ i-Stamp2P24 áÅкÍà ´ JX-2SX plus II ä´ Í ҧÊÁºÙó

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%


&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


º··Õè 2

¡ÒÃ㪠§Ò¹â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 㹡ÒÃà¢Õ¹â»Ãá¡ÃÁà¾×Íè ¤Çº¤ØÁ¡Ò÷íÒ§Ò¹¢Í§àºÊÔ¡áʵÁ» 2P ¹Ñ¹é ¨Ð㪠ÀÒÉÒàºÊÔ¡·Õàè ÃÕÂ¡Ç Ò ¾ÕàºÊÔ¡ (PBASIC) â´Â¼ Ò¹â»Ãá¡ÃÁ·Õªè Í×è Ç Ò àºÊÔ¡áʵÁ» àÍ´ÔàµÍà (BASIC Stamp Editor) â»Ãá¡ÃÁ¹Õ¨é ж١㪠㹠¡ÒõԴµ ͤÍÁ¾ÔÇàµÍà ¡ºÑ àºÊÔ¡áʵÁ» 2P ¼ Ò¹·Ò§¾Íà µÍ¹Ø¡ÃÁ 㪠㹡ÒÃà¢Õ¹áÅÐá¡ ä¢â»Ãá¡ÃÁÀÒÉÒàºÊÔ¡ ËÃ×Í·íÒ˹ Ò·Õàè » ¹àÍ´ÔàµÍà ¹¹Ñè àͧ â´Ââ»Ãá¡ÃÁ¨Ð·íÒ¡ÒõÃǨÊͺ¡ÒÃà¢Õ¹â»ÃááÁã¹·Ø¡ºÃÃ·Ñ´Ç Ò¼Ô´¾ÅÒ´ËÃ×Í äÁ áÅÐ㪠㹡ÒÃâËÅ´ËÃ×Íà¢Õ¹â»Ãá¡ÃÁŧº¹µÑÇàºÊÔ¡áʵÁ» à¾×Íè ·íÒ¡ÒÃÃѹ ÍÒ¨¡Å ÒÇä´ ÇÒ â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà à¾Õ§µÑÇà´ÕÂÇ·íÒ§Ò¹ä´ ¤ÃºÇ§¨Ã ·íÒãË ¡ÒÃàÃÕ¹ÃÙà ºÊÔ¡áʵÁ» §Ò ÂáÅÐÁÕ¢¹Ñé µÍ¹¹ Í·ÕÊè ´Ø

2.1 Ãкº¤ÍÁ¾ÔÇàµÍà ·µÕè Í §¡Òà 㪠«¾Õ ÂÕ àÙ ¾¹àµÕÂÁ 3 ¢Ö¹é ä» l µÔ´µÑ§é Ãкº»¯Ôºµ Ñ ¡Ô ÒÃÇÔ¹â´ÇÊ XP/2000 ËÃ×Í NT l ˹ ǤÇÒÁ¨íÒáÃÁÍ ҧ¹ Í 24 àÁ¡Ð亵 l ¾×¹ é ·ÕÇè Ò §º¹ÎÒà ´´ÔÊ¡ Í ҧ¹ Í 10 àÁ¡Ð亵 l ¨ÍÀÒ¾ÊÕ SVGA l ¾Íà µÍ¹Ø¡ÃÁÇ Ò§Í ҧ¹ Í 1 ¾Íà µ 㹡óշÕèà¤Ã×èͧ¤ÍÁ¾ÔÇàµÍà äÁ ÁÕ¾Íà µÍ¹Ø¡ÃÁ ÊÒÁÒö㪠ÍØ»¡Ã³ á»Å§¾Íà µ USB à» ¹¾Íà µÍ¹Ø¡ÃÁ (USB to Serial port converter) á·¹ä´ l

2.2 ¡ÒõԴµÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 2.2.1 µÔ´µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ¼Ò ¹·Ò§á¼ ¹«Õ´ÃÕ ÍÁ ࢠÒä»·Õäè ´àÃ硵ÍÃÕè Software ã¹á¼ ¹«Õ´ÃÕ ÍÁ ¨Ð¾ºä¿Å Setup-Stamp-Editor-v2.4.exe ãË ´ºÑ àºÔÅé ¤ÅÔ¡·Õè ä¿Å ¹¹Ñé à¾×Íè àÃÔÁè µ ¹µÔ´µÑ§é â»Ãá¡ÃÁ

2.2.2 ´Òǹ âËÅ´¨Ò¡àǺ䫵 ÊÒÁÒö´Òǹ âËÅ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍÃ Ã¹Ø Å ÒÊØ´ä´ ¨Ò¡ http://www.parallax.com ËÅѧ¨Ò¡ ´Òǹ âËÅ´ä¿Å µ´Ô µÑ§é ÁÒàÃÕºà ÍÂáÅ Ç ãË ·Òí ¡ÒôѺàºÔÅä¿Å µ´Ô µÑ§é ¹Ñ¹é áÅ Ç´íÒà¹Ô¹¡ÒõÒÁ¢Ñ¹é µÍ¹·Õáè ¨ §

2.2.3 ¡ÒÃàµÃÕÂÁâ»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ÊÒí ËÃѺµÔ´µ ͡Ѻ i-Stamp2P24 (1) ËÅѧ¨Ò¡µÔ´µÑ§é â»Ãá¡ÃÁáÅ Ç à» ´â»Ãá¡ÃÁ¢Ö¹é ÁÒ㪠§Ò¹ â´Âä»·Õè Start à Program à Parallax Inc à Stamp editor v2.4.0 à BASIC Stamp editor V2.4.0 ¨Ð»ÃÒ¡¯Ë¹ Òµ Ò§¢Í§â»Ãá¡ÃÁµÒÁÃÙ»·Õè 2-1

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'


àÅ×Í¡àºÊÔ¡áʵÁ» 2P àÅ×Í¡àºÊÔ¡áʵÁ» 2SX

µÃǨÊͺäÇ¡ó

àÅ×Í¡àºÊÔ¡áʵÁ» 2E

´Ù˹ ǤÇÒÁ¨íÒ

àÅ×Í¡àºÊÔ¡áʵÁ» 2 Preference à» ´Ë¹ Òµ Ò§µÑ§é ¤ Ò

Ãѹâ»Ãá¡ÃÁ Identify

Êà ҧä¿Å ãËÁ à» ´ä¿Å » ´ä¿Å ºÑ¹·Ö¡ä¿Å

à» ´Ë¹ Òµ Ò§ Debug terminal

¾ÔÁ¾ ä¿Å ÍÍ¡à¤Ã×Íè §¾ÔÁ¾ µÑ´¢ ͤÇÒÁ

à» ´ä¿Å ªÇ ÂàËÅ×Í (Help)

¤Ñ´ÅÍ¡¢ ͤÇÒÁ ÇÒ§¢ ͤÇÒÁ ¤ ¹ËÒ

¾×¹é ·Õàè ¢Õ¹â»Ãá¡ÃÁ

áÊ´§µíÒá˹ §à¤Íà à«Íà ᶺáÊ´§Ê¶Ò¹Ð

ÃÙ»·Õè 2-1 áÊ´§Ë¹ Òµ Ò§ËÅÑ¡¢Í§â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ¾Ã ÍÁáÊ´§Ê ǹ»ÃСͺµ Ò§æ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


(2) ä»·Õàè Á¹Ù Directive àÅ×Í¡ Stamp à BS2P

(3) ä»·Õàè Á¹Ù Edit à Preference ¨Ð»ÃÒ¡¯Ë¹ Òµ Ò§ preference ¢Ö¹é áÅ ÇàÅ×Í¡ä»·Õ¡è Ãͺ Stamp mode and ports àÅ×Í¡ Default Com Port ãË áÊ´§ AUTO áÅзաè Ãͺ Stamp mode and ports àÅ×Í¡ Default Project Downlode Mode ãË áÊ´§ Modified

(4) ¤ÅÔ¡·Õ»è ÁØ OK à¾×Íè ¡ÅѺä»Âѧ˹ Òµ Ò§àÍ´ÔàµÍÃ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


2.3 ¡ÒÃàÃÕ¡㪠§Ò¹â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ¡ºÑ i-Stamp2P24 àÁ×Íè ¹íÒ i-Stamp2P24 µÔ´µÑ§é ŧº¹ºÍà ´·ÕÊè ÒÁÒöàª×Íè Áµ ͡Ѻ¤ÍÁ¾ÔÇàµÍà áÅ Ç (ä´ á¡ ºÍà ´ JX-2SX plus II) µ ÍÊÒÂࢠҡѺ¾Íà µÍ¹Ø¡ÃÁ¢Í§¤ÍÁ¾ÔÇàµÍà ¨ ÒÂä¿ãË á¡ Ç§¨Ã áÅ Çà» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ¢Ñ¹é µÍ¹µ Íä»à» ¹¡ÒõÃǨÊÍºÇ Ò â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ÊÒÁÒöµÔ´µ ͡Ѻ i-Stamp2P24 ä´ ËÃ×ÍäÁ â´Â¡´¤Õ Ctrl I ËÃ×Í㪠àÁÒÊ ¤ÅÔ¡»ØÁ Identify ËÃ×ÍࢠÒä»·Õàè Á¹Ù Run àÅ×Í¡ Identify ¶ Ò·Ø¡Í ҧ¶Ù¡µ ͧ ¨Ð»ÃÒ¡¯Ë¹ Òµ Ò§áÊ´§¡ÒõԴµ ʹѧ¹Õé

¨ÐàËç¹Ç Ò㹪 ͧ COM1 ¨Ð»ÃÒ¡¯ª×Íè BASIC Stamp2P Vx.x (x à» ¹àÅ¢àÇÍà ª¹Ñè ) Ê Ç¹ã¹ª ͧ Loopback áÅÐ echo »ÃÒ¡¯¢ ͤÇÒÁ Yes à» ¹¡ÒÃᨠ§ãË ·ÃÒºÇ Ò â»Ãá¡ÃÁÊÒÁÒöµÔ´µ ͡ѺàºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµ àµÍÃ ä´ áÅ Ç Ê Ç¹¡ÒÃàª×Íè Áµ ÍÊÒÂáÅСÒÃÃÑºÊ §ÊÑ­­Ò³¶Ù¡µ ͧ¾Ã ÍÁ·íÒ§Ò¹ ·´Åͧà¢Õ¹â»Ãá¡ÃÁ§ ÒÂæ µÒÁ¢Ñ¹é µÍ¹´Ñ§¹Õé (1) àÅ×Í¡ä´àÃ硵տËÃ×ͪ¹Ô´¢Í§àºÊÔ¡áʵÁ» ·µÕè Í §¡ÒÃ㪠§Ò¹ ã¹·Õ¹è ¤Õé Í× àºÊÔ¡áʵÁ» 2P ä»·Õàè Á¹Ù Directive àÅ×Í¡ BS2P ¨Ð»ÃÒ¡¯¢ ͤÇÒÁ {$STAMP BS2P} ¢Ö¹é º¹ºÃ÷Ѵáá ¡´ Enter (2) ¾ÔÁ¾ ¤Òí Êѧè debug welcome à» ¹¡ÒÃÊѧè ãË i-Stamp2P24 Ê §¢ ͤÇÒÁ welcome ä»áÊ´§·ÕËè ¹ Òµ Ò§ Debug Terminal ¢Í§â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Ç¡´ Enter (3) ¡´»ØÁ Run ¨Ð»ÃÒ¡¯Ë¹ Òµ Ò§µÃǨÊͺ¡ÒÃàª×Íè Áµ ÍàºÊÔ¡áʵÁ» µÒÁ´ ÇÂ˹ Òµ Ò§´Òǹ âËÅ´ â»Ãá¡ÃÁ áÅÐÊØ´· Ò»ÃÒ¡¯Ë¹ Òµ Ò§ Debug Terminal áÊ´§¢ ͤÇÒÁ welcome ´Ñ§ÃÙ»

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


2.4 ÃÒÂÅÐàÍÕ´¢Í§â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍÃ

2.4.1 àÁ¹Ùà¤Ã×Íè §Á×ͨѴ¡ÒÃá¿ Á¢ ÍÁÙÅÁҵðҹáÅСÒþÔÁ¾ ª×Íè ¢Í§àÁ¹Ù¹¤Õé Í× File ÁÕ´Ç Â¡Ñ¹ 5 à¤Ã×Íè §Á×Í Í´ѧ¹Õé New Document 㪠ÊÒí ËÃѺÊà ҧῠÁ¢ ÍÁÙÅãËÁ Open File 㪠ÊÒí ËÃѺ໠´á¿ Á¢ ÍÁÙÅ ¹ÒÁÊ¡ØÅ .BSP ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+O Save 㪠ÊÒí ËÃѺºÑ¹·Ö¡á¿ Á¢ ÍÁÙÅ㹪×Íè à´ÔÁ ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+S Save As 㪠ÊÒí ËÃѺºÑ¹·Ö¡¢ ÍÁÙÅ àÁ×Íè µ ͧ¡ÒÃà»ÅÕÂè ¹ª×Íè á¿ Á¢ ÍÁÙÅ Print 㪠¾ÁÔ ¾ «Íà Êä¿Å (á¿ Á¢ ÍÁÙÅÀÒÉÒàºÊÔ¡·Õàè ¢Õ¹¢Ö¹é ) ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+P Close File 㪠ÊÒí ËÃѺ» ´á¿ Á¢ ÍÁÙÅ Exit 㪠ÊíÒËÃѺÍÍ¡¨Ò¡â»Ãá¡ÃÁ

2.4.2 àÁ¹Ùá¡ ä¢á¿ Á¢ ÍÁÙÅ ª×Íè ¢Í§àÁ¹Ù¹¤Õé Í× Edit à» ¹àÁ¹Ùà¤Ã×Íè §Á×Í·ÕÁè ÅÕ ¡Ñ ɳÐàËÁ×͹¡Ñºâ»Ãá¡ÃÁà·ç¡« àÍ´ÔàµÍà (text editor) ËÃ×Íâ»Ãá¡ÃÁᡠ䢢 ͤÇÒÁ·ÑÇè ä» ´Ñ§ÁÕÃÒÂÅÐàÍÕ´¢Í§à¤Ã×Íè §Á×Í ÍÂã¹àÁ¹Ù Edit µ Í仹Õé Undo 㪠ÊÒí ËÃѺ¡àÅÔ¡¡ÒÃ㪠§Ò¹à¤Ã×Íè §Á×Íᡠ䢢 ÍÁÙÅ¡ ͹˹ Ò¹Õé ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+Z Cut 㪠µ´Ñ à¾×Íè  ÒµíÒá˹ §¢Í§¢ ͤÇÒÁ·Õàè Å×Í¡ ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+X Copy 㪠¤´Ñ ÅÍ¡¢ ͤÇÒÁ ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+C Paste 㪠ÇÒ§¢ ͤÇÒÁ·Õµè ´Ñ ËÃ×ͤѴÅÍ¡ÁÒ ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+V Select All 㪠àÅ×Í¡¢ ͤÇÒÁ·Ñ§é ËÁ´ã¹á¿ Á¢ ÍÁÙÅ ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+A Find/Replace 㪠¤¹ ËÒáÅÐá·¹·Õ¢è Í ¤ÇÒÁ ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+F Find Next 㪠¤¹ ËÒ¢ ͤÇÒÁµ Íä» ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í »ØÁ F3 Preference 㪠»ÃѺà»ÅÕÂè ¹á¡ ä¢¾ÒÃÒÁÔàµÍà µÒ §æ ¢Í§àºÊÔ¡áʵÁ» àÍ´ÔàµÍà ÁÕ´Ç Â¡Ñ¹ 5 Ê Ç¹¤×Í 1. »ÃѺà»ÅÕÂè ¹¡ÒÃáÊ´§¼Å¢Í§Ë¹ Òµ Ò§àÍ´ÔàµÍà (Editor Appearance) ·Ñ§é ÊÕ¾¹×é áÅÐ ÊբͧµÑÇÍÑ¡Éà 2. »ÃѺà»ÅÕÂè ¹¡ÒÃáÊ´§¼Å¢Í§Ë¹ Òµ Ò§ Debug Terminal (Debug Appearance) ·Ñ§é ÊÕ¾×é¹áÅÐÊբͧµÑÇÍÑ¡ÉÃáÅТ ͤÇÒÁµ Ò§æ 3. ¡íÒ˹´¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà (Editor Operation) 4. ¡íÒ˹´ÃٻẺ¡Ò÷íÒ§Ò¹¢Í§´Õº¡Ñ (Debug Function) 5. ¡íÒ˹´ÃÒÂÅÐàÍÕ´¾Íà µ¢Í§¤ÍÁ¾ÔÇàµÍà ·ãÕè ª 㹡Òôպ¡Ñ (Debug Port) ¶Ö§áÁ ÇÒ ·ÕËè ¹ Òµ Ò§ Preference ¨ÐÊÒÁÒö㪠»ÃѺà»ÅÕÂè ¹¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍÃ ä´ Í ҧÁÒ¡ÁÒ ᵠ㹡ÒÃ㪠§Ò¹¨ÃÔ§ â»Ãá¡ÃÁ¨Ð·íÒ¡ÒûÃѺà»ÅÕÂè ¹áÅÐàÅ×Í¡¤ Ò·Õàè ËÁÒÐÊÁâ´ÂÍѵâ¹ÁÑµÔ ¼Ùã ª §Ò¹á·º äÁ Á¤Õ ÇÒÁ¨íÒà» ¹µ ͧ»ÃѺà»ÅÕÂè ¹ËÃ×Í»ÃѺᵠ§ã´æ Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


2.4.3 àÁ¹ÙàÅ×Í¡ä´àÃ硵տ (Directive) ÁÕà¤Ã×Íè §Á×Í Í 3 µÑÇËÅÑ¡¤×Í 1. Stamp : àÅ×Í¡Ãع ¢Í§àºÊÔ¡áʵÁ» 2 ·Õµè Í §¡Ò÷íÒ§Ò¹ (BS2, BS2E, BS2SX, BS2P, BS2PE) ËÃ×ͨÐàÃÕ¡㪠§Ò¹¼ Ò¹»ØÁ «Ö§è ÁÕ´Ç Â¡Ñ¹ 5 ÊÕá·¹Ãع ¢Í§àºÊÔ¡áʵÁ» ¡äç ´ ÊÕà¢ÕÂÇ㪠àÅ×Í¡àºÊÔ¡áʵÁ» 2 (BS2) ÊÕᴧ㪠àÅ×Í¡àºÊÔ¡áʵÁ» 2E (BS2E) ÊÕ¹Òéí à§Ô¹ãª àÅ×Í¡àºÊÔ¡áʵÁ» 2SX (BS2SX) ÊÕàËÅ×ͧ㪠à Å×Í¡àºÊÔ¡áʵÁ» 2P (BS2P) i-Stamp2P24 ¨Ð㪠ä´àÃ硵տµÑǹÕé ÊÕ¹Òéí µÒÅ㪠àÅ×Í¡àºÊÔ¡áʵÁ» 2PE (BS2PE) 2. PBASIC : àÅ×Í¡Ãع ¢Í§â»Ãá¡ÃÁ¾ÕàºÊÔ¡ â´Â i-Stamp2P24 ¨Ð㪠Version 2.5 3. Port : àÅ×Í¡¾Íà µÍ¹Ø¡ÃÁ·Õµè Í §¡ÒõԴµ Í´ ÇÂ

2.4.4 àÁ¹ÙáÊ´§¡Ò÷íÒ§Ò¹ ª×èͧ͢àÁ¹Ù¹Õé¤×Í Run à» ¹àÁ¹Ùà¤Ã×èͧÁ×Í·ÕèÁÕº·ºÒ·ÁÒ¡·ÕèÊش㹡ÒþѲ¹ÒáÅÐ㪠§Ò¹àºÊÔ¡áʵÁ» ÁÕ à¤Ã×Íè §Á×Í Í·ѧé ÊÔ¹é 5 µÑǤ×Í RUN

㪠ÊÒí ËÃѺÃѹâ»Ãá¡ÃÁ·Õàè ¢Õ¹¢Ö¹é ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+R

Check Syntax 㪠ÊÒí ËÃѺµÃǨÊͺäÇ¡ó ¢Í§â»Ãá¡ÃÁ·Õàè ¢Õ¹¢Ö¹é Ç Ò ÁÕ¡ÒÃ㪠¤Òí ÊÑ§è ¼Ô´¾ÅÒ´ ËÃ×ÍäÁ ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+T Memory Map 㪠µÃǨÊͺ¤ Òã¹Ë¹ ǤÇÒÁ¨íÒâ»Ãá¡ÃÁ·ÕèÍÂÙ ã¹Ë¹ ǤÇÒÁ¨íÒÍÕÍÕ¾ÃÍÁ ¢Í§àºÊÔ¡áʵÁ» áÅÐ˹ ǤÇÒÁ¨íÒáÃÁÀÒÂã¹ ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+M Debug

㪠ÊíÒËÃѺµÔ´µ ÍàºÊÔ¡áʵÁ» ¡Ñº¤ÍÁ¾ÔÇàµÍà àÁ×èÍ㪠à¤Ã×èͧÁ×͹Õé˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+D

Identify

㪠ÊÒí ËÃѺ¤ ¹ËÒàºÊÔ¡áʵÁ» ·µÕè Í ¡Ñº¾Íà µÍ¹Ø¡ÃÁ ÊÒÁÒö㪠¤ÂÕ Å ´Ñ ¤×Í Ctrl+I

·Õàè Á¹Ùà¤Ã×Íè §Á×͹ըé ÐÁÕà¾Õ§ Memory Map áÅÐ Debug à· Ò¹Ñ¹é ·Õàè Á×Íè àÃÕ¡㪠§Ò¹áŠǨлÃÒ¡¯Ë¹ Òµ Ò§ áÊ´§¡Ò÷íÒ§Ò¹¢Öé¹ÁÒãËÁ ¹Í¡¹Ñ鹨ÐáÊ´§¡Ò÷íÒ§Ò¹¼ Ò¹ºÒà áÊ´§Ê¶Ò¹Ð (status bar) «Öè§ÍÂÙ ´ ҹŠҧ¢Í§ ˹ Òµ Ò§ËÅÑ¡¢Í§â»Ãá¡ÃÁ ¹Í¡à˹×Í仨ҡ¹Ñ¹é à¤Ã×Íè §Á×ͷѧé ËÁ´ã¹àÁ¹Ù¹ÂÕé ¡àÇ ¹ Check Syntax ¨ÐÊÒÁÒö㪠§Ò¹ä´ ¡çµ ÍàÁ×èÍàºÊÔ¡áʵÁ» àª×èÍÁµ ÍࢠҡѺ¤ÍÁ¾ÔÇàµÍà áÅÐÊÒÁÒöµÔ´µ ÍÊ×èÍÊÒáѹä´

"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


º··Õè 3

¡ÒÃ㪠§Ò¹ªØ´¤íÒÊÑ§è ¢Í§àºÊÔ¡áʵÁ» 2P

ÃÒÂÅÐàÍÕ´¢Í§¤íÒÊÑ§è ·Ñ§é ËÁ´¢Í§àºÊÔ¡áʵÁ» 2P ·Õ¨è зíÒ¡ÒÃ͸ԺÒÂ㹺·¹Õé àÃÕ§ÅíҴѺµÒÁµÑÇÍÑ¡Éà ÀÒÉÒÍѧ¡ÄɵÑé§áµ µÑÇ A à» ¹µ ¹ä» â´Âã¹áµ ÅФíÒÊÑ觨ÐÁÕµÑÇÍ ҧ¡ÒÃ㪠§Ò¹ áÅÐ㹺ҧ¤íÒÊÑ觡ç¨ÐÁÕµÑÇÍ ҧ â»Ãá¡ÃÁÊѹé æ ·ÕÊè ÒÁÒö·´Åͧâ´Â㪠i-Stamp2P24 ¡ÑººÍà ´ JX-2SX plus II à¾×Íè µÃǨÊͺ¼Å¡Ò÷íÒ§Ò¹ä´ ·Ñ¹·Õ Íѹ໠¹¡Òê ÇÂà¾ÔÁè ¤ÇÒÁࢠÒã¨ã¹¤íÒÊÑ§è ¹Ñ¹é æ á¡ ¼àÙ ÃÕ¹áÅмÙã ª §Ò¹ä´ à» ¹Í ҧ´Õ Í ҧäáçµÒÁ ÊÔ§è ·Õ¼è ÊÙ ¹ã¨ÈÖ¡ÉÒáÅÐ㪠§Ò¹àºÊÔ¡áʵÁ» 2P ¨íÒà» ¹µ ͧ·ÃÒºã¹àº×Íé §µ ¹¡ ͹¤×Í ÃÙ» Ẻ㹡ÒÃà¢Õ¹â»Ãá¡ÃÁàº×Íé §µ ¹¢Í§àºÊÔ¡áʵÁ» 2P ·Ñ§é ¹Õàé ¾×Íè »ÃѺãË ¡ÒÃà¢Õ¹â»Ãá¡ÃÁ㪠§Ò¹¤íÒÊÑ§è µ Ò§æ ¢Í§àºÊÔ¡áʵÁ» 2P ÊÍ´¤Å ͧä»ã¹á¹Ç·Ò§à´ÕÂǡѹ áÅÐÂѧª ÇÂãË ¡ÒäÇÒÁࢠÒã¨ã¹¡Ò÷íÒ§Ò¹¢Í§áµ ÅФíÒÊѧè à» ¹ä»Í ҧÁÕÃкºáÅЧ Ò¢Öé¹

3.1 ÃٻẺ¡ÒÃà¢Õ¹â»Ãá¡ÃÁ â»Ãá¡ÃÁ·Õàè ¢Õ¹¢Ö¹é à¾×Íè 㪠§Ò¹àºÊÔ¡áʵÁ» 2P à» ¹â»Ãá¡ÃÁÀÒÉÒàºÊÔ¡·Õàè ÃÕÂ¡Ç Ò ¾ÕàºÊÔ¡ (PBASIC) áÅÐ µ ͧºÑ¹·Ö¡à» ¹á¿ Á¢ ÍÁÙŹÒÁÊ¡ØÅ .bsp ෠ҹѹé ÁÕ¡¯à¡³± áÅÐÃٻẺ·Õµè Í §·ÃÒºáÅл¯ÔºµÑ µÔ ÒÁ´Ñ§¹Õé

3.1.1 ¤ Ò¤§·Õè «Ö§è ¡ç¤Í× ¤ ҢͧµÑÇàÅ¢·Õ»è ÃÒ¡¯ã¹â»Ãá¡ÃÁ ÊÒÁÒöẠ§ä´ à» ¹ 4 ÃٻẺ¤×Í 1. µÑÇàÅ¢°Ò¹ÊÔº (decimal ËÃ×Í DEC) »ÃСͺ´ ǵÑÇàÅ¢ 0-9 àÁ×Íè µ ͧ¡ÒáíÒ˹´¤ Ò¤§·Õàè » ¹àÅ¢ °Ò¹ÊÔº ÊÒÁÒö¡íÒ˹´ä´ â´ÂµÃ§ â´Â·ÕäÁ µÍ §ÁÕÊ­ Ñ Åѡɳ ËÃ×Í¡ÒÃÃкØ͹×è ã´à» ¹¾ÔàÈÉ ´Ñ§µÑÇÍ ҧ 100 ËÁÒ¶֧ ¢ ÍÁÙÅ 100 °Ò¹ÊÔº 2. µÑÇàÅ¢°Ò¹ÊԺˡ (hexadcimal ËÃ×Í HEX) »ÃСͺ´ Ç¢ ÍÁÙÅ 0-F àÇÅÒà¢Õ¹µ ͧ¹íÒ˹ Ò´ Ç à¤Ã×Íè §ËÁÒ $ àÊÁÍ Â¡µÑÇÍ ҧ $11 ËÁÒ¶֧ ¢ ÍÁÙÅ 11 °Ò¹ÊԺˡ ෠ҡѺ 17 ã¹àÅ¢°Ò¹ÊÔº áÅÐ 0001 0001 ã¹àÅ¢°Ò¹Êͧ $FF ËÁÒ¶֧ ¢ ÍÁÙÅ FF °Ò¹ÊԺˡ ෠ҡѺ 255 ã¹àÅ¢°Ò¹ÊÔº áÅÐ 1111 1111 ã¹àÅ¢°Ò¹Êͧ 3. µÑÇàÅ¢°Ò¹Êͧ (binary ËÃ×Í BIN) »ÃСͺ´ Ç¢ ÍÁÙÅ 0 áÅÐ 1 㹡ÒÃà¢Õ¹ËÃ×ÍÍ Ò§¶Ö§µ ͧãÊ à¤Ã×Íè §ËÁÒ % ¹íÒ˹ ÒµÑÇàÅ¢àÊÁÍ Â¡µÑÇÍ ҧ %00110001 ËÁÒ¶֧ ¢ ÍÁÙÅ 00110001 ã¹àÅ¢°Ò¹Êͧ ෠ҡѺ 31 ã¹àÅ¢°Ò¹ÊԺˡ ËÃ×Í 49 ã¹àÅ¢°Ò¹ÊÔº

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#


4. ÃËÑÊáÍÊ¡Õé (ASCII) ÊíÒËÃѺÃËÑÊáÍÊ¡Õàé » ¹ÃËÑʢͧµÑÇÍÑ¡ÉÃáÅеÑÇàÅ¢µ Ò§æ ÃÇÁ¶Ö§¡ÒÃàÇ ¹ÇÃä ¡ÒâÖé¹µ ¹ºÃ÷ѴãËÁ  Í˹ Ò «Öè§à¡Ô´¢Öé¹ã¹·Ø¡¤ÃÑ駷ÕèÁÕ¡ÒþÔÁ¾ ¢ ͤÇÒÁº¹â»Ãá¡ÃÁ¤ÍÁ¾ÔÇàµÍà â´ÂÃËÑÊ áÍÊ¡Õ¹é ¨Õé ÐÁÕ¢¹Ò´ 7 ºÔµ ¹Ñ¹è ¤×Í ÃËÑÊáÍÊ¡ÕÊé ÒÁÒö㪠᷹¢ ÍÁÙŵÑÇàÅ¢, µÑÇÍÑ¡Éà ËÃ×ÍÊÑ­Åѡɳ ¾àÔ ÈÉ·Õàè ¡Ô´ ¢Ö¹é 㹡ÒþÔÁ¾ ·§Ñé ËÁ´¶Ö§ 214 ËÃ×Í 128 µÑÇ â´ÂµÑÇÍÑ¡ÉÃáÅеÑÇàŢᵠÅеÑǨÐÁÕ¤Ò ËÃ×Í¢ ÍÁÙÅ»ÃШíÒµÑÇÍÂ٠¡µÑÇÍ ҧ ª Í§Ç Ò§ËÃ×ÍàÇ ¹ÇÃä ÁÕÃËÑÊáÍÊ¡Õ¤é Í× $20 ($ ·ÕÍè ÂÙË ¹ ÒµÑÇàŢ໠¹¡ÒÃᨠ§ãË ·ÃÒºÇ Ò µÑÇàÅ¢·Õµè Í ¨Ò¡¹Õàé » ¹µÑÇàÅ¢°Ò¹ÊԺˡ) 㹡ÒÃÃкØÇÒ ¢ ͤÇÒÁËÃ×͵ÑÇàÅ¢µ Í仹Õàé » ¹ÃËÑÊáÍÊ¡ÕÊé ÒÁÒö·íÒä´ â´Âà¢Õ¹¢ ÍÁÙÅ ãË ÍÂÙÀ ÒÂã¹à¤Ã×Íè §ËÁÒ¤íÒ¾Ù´ËÃ×Í ... ´Ñ§µÑÇÍ ҧ A ¢ ÍÁÙÅ·ÕÃè кع¤Õé Í× ÃËÑÊáÍÊ¡Õ¢é ͧµÑÇÍÑ¡Éà A «Ö§è ÁÕ¤Ò à· Ò¡Ñº $65 Hello ¢ ÍÁÙÅ·ÕÃè кعàÕé » ¹ÃËÑÊáÍÊ¡Õé â´ÂÁÕ¤Ò à· Ò¡Ñº¡ÒáíÒ˹´à» ¹ÃËÑÊáÍÊ¡Õ¢é ͧµÑÇÍÑ¡Éà H, e, l, l áÅÐ o µÒÁÅíҴѺ ã¹µÒÃÒ§·Õè 3-1 áÊ´§¢ ÍÁÙÅáÅÐÃÒÂÅÐàÍÕ´ÃËÑÊáÍÊ¡Õ¢é ͧµÑÇÍÑ¡ÉÃáÅÐÊÑ­Åѡɳ ¾àÔ Èɵ Ò§æ

ÃËÑʤǺ¤ØÁ

µÑÇÍÑ¡ÉÃ

¿ §¡ ªÑè¹

ÃËÑÊÍÑ¡ÉÃ

¤ÇÒÁËÁÒÂ

ÃËÑÊáÍÊ¡Õé

µÑÇÍÑ¡ÉÃ

ÃËÑÊáÍÊ¡Õé

µÑÇÍÑ¡ÉÃ

ÃËÑÊáÍÊ¡Õé

µÑÇÍÑ¡ÉÃ

ÃËÑÊáÍÊ¡Õé

null start of heading start of text end of text end of xmit enquiry acknowledge bell backspace horizontal tab line feed vertical tab form feed carriage return shift out shift in data line escape device control 1 device control 2 device control 3 device control 4 non ackowledge synchronous idle

NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US

äÁ Á¡Õ Ò÷íÒ§Ò¹ àÃÔÁè ËÑǨ´ËÁÒ àÃÔÁè µ ¹¢ ͤÇÒÁ ÊÔ¹é ÊØ´¢ ͤÇÒÁ ÊÔ¹é ÊØ´¡ÒÃÊ § Êͺ¶ÒÁ ÃѺÃÙ/ µÍºÊ¹Í§ ¡Ãдԧè /ÊÑ­­Ò³àÃÕ¡ źáÅжÍÂËÅѧ á·ç»·Ò§á¹Ç¹Í¹ àÅ×Íè ¹ºÃ÷Ѵ á·ç»·Ò§á¹ÇµÑ§é àÅ×Íè ¹Ë¹ Ò ¢Ö¹é ºÃ÷ѴãËÁ àÅ×Íè ¹ÍÍ¡ àÅ×Íè ¹à¢ Ò ÍÍ¡¨Ò¡ºÃ÷Ѵ¢ ÍÁÙÅ ÃËÑʤǺ¤ØÁÍØ»¡Ã³ 1 ÃËÑʤǺ¤ØÁÍØ»¡Ã³ 2 ÃËÑʤǺ¤ØÁÍØ»¡Ã³ 3 ÃËÑʤǺ¤ØÁÍØ»¡Ã³ 4 äÁ ÃºÑ ÃÙ/ äÁ µÍºÊ¹Í§ ÃËÑÊ«Ô§â¤Ã¹ÑÊ ÊÔ¹é ÊØ´¡ÒÃÊ §ºÅçÍ¡¢ ÍÁÙŠ¡àÅÔ¡ ÊÔ¹é ÊØ´µíÒá˹ §¡Ö§è ¡ÅÒ§ ÃËÑÊá·¹ ÍÍ¡¨Ò¡¡Ò÷íÒ§Ò¹ á¡ῠÁ¢ ÍÁÙÅ á¡¡ÅØÁ ¢ ÍÁÙÅ á¡¡Òúѹ·Ö¡¢ ÍÁÙÅ á¡˹ Ç¢ͧ¢ ÍÁÙÅ

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

<space> ! " # $ % & ' ( ) * + , . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

@ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

a b c d e f g h i g k l m n o p q r s t u v w x y z { | } ~ <delete>

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

end of xmit block

cancel end of medium substitue escape file separator group separator record separator unit separator

µÒÃÒ§·Õè 3-1 µÒÃÒ§¢ ÍÁÙÅÃËÑÊáÍÊ¡Õ¢é ͧµÑÇÍÑ¡Éà µÑÇàÅ¢ áÅÐÊÑ­Åѡɳ ¾àÔ Èɵ Ò§æ $

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡ÒÃ㪠§Ò¹·ÑÇè æ 仼Ùã ª §Ò¹ÁÑ¡¤Ô´Ç Òã¹â»Ãá¡ÃÁ¨ÐÁÕ¡ÒÃ㪠§Ò¹à©¾ÒÐàÅ¢°Ò¹ÊԺ෠ҹѹé ᵠ㹡ÒÃà¢Õ¹ â»Ãá¡ÃÁáÅ Ç ¢ ÍÁÙÅàÅ¢°Ò¹ÊԺˡáÅаҹÊͧ໠¹ÊÔ§è ¨íÒà» ¹ à¹×Íè §¨Ò¡¡ÒõԴµ ͡Ѻ¢Ò¾Íà µáµ ÅТҹѹé ËÒ¡ 㪠¢Í ÁÙÅàÅ¢°Ò¹ÊÔº¡ÒÃ㪠§Ò¹´Ù¨ÐäÁ Êдǡ ¡µÑÇÍ ҧ µ ͧ¡ÒáíÒ˹´ãË ¢Ò P0-P3 ¢Í§àºÊÔ¡áʵÁ» 2P ·íÒ˹ Ò·Õàè » ¹¢ÒàÍÒµ ¾µØ áÅСíÒ˹´ãË ¢Ò P4 ¶Ö§ P7 ·íÒ˹ Ò·Õàè » ¹ÍÔ¹¾Øµ ¨Ðµ ͧ¡íÒ˹´ãË ºµÔ 0-3 ¢Í§ÃÕ¨ÊÔ àµÍà DIRS 㧠i-Stamp2P24 à» ¹ 1 Ê Ç¹ºÔµ 4 ¶Ö§ 7 µ ͧ¡íÒ˹´ãË à» ¹ 0 ÊÒÁÒö㪠¤Òí Êѧè ä´ ´§Ñ ¹Õé DIRS = %00001111 㹡óÕ㪠¢Í ÁÙÅàÅ¢°Ò¹Êͧ DIRS = $0F

㹡óÕ㪠¢Í ÁÙÅàÅ¢°Ò¹ÊԺˡ

DIRS = 15

㹡óÕ㪠¢Í ÁÙÅàÅ¢°Ò¹ÊÔº

¨ÐàËç¹ä´ ÇÒ ¡ÒáíÒ˹´ãË áÊ´§¼Åà» ¹àÅ¢°Ò¹Êͧ¨ÐàË繶֧˹ Ò·Õ¢è ͧᵠÅТҾÍà µ¢Í§ i-Stamp2P24 Í ҧªÑ´à¨¹ÁÒ¡·ÕÊè ´Ø Ëҡ㪠¢Í ÁÙÅàÅ¢°Ò¹ÊԺˡ ¡ç处 ¾Í·íÒ¤ÇÒÁࢠÒ㨶֧¢ ÍÁÙÅÃдѺºÔµä´ äÁ ÂÒ¡ ã¹¢³Ð·Õè ¡ÒÃ㪠¢Í ÁÙÅàÅ¢°Ò¹ÊÔº ¨ÐãË ÀÒ¾¢Í§Ë¹ Ò·Õãè ¹áµ ÅТҾÍà µ¢Í§ i-Stamp2P24 äÁ ª´Ñ ਹ µ ͧµÕ¤ÇÒÁà» ¹àÅ¢ °Ò¹ÊͧàÊÕ¡ ͹¨Ö§¨Ðà¡ç¹ÀÒ¾·Õªè ´Ñ ਹ Í ҧäáçµÒÁ ¡ÒÃ㪠¢Í ÁÙÅàÅ¢°Ò¹Êͧ¨ÐàËÁÒСѺ¢¹Ò´¢Í§¢ ÍÁÙÅäÁ à¡Ô¹ 8 ºÔµ à¾ÃÒÐÊÒÁÒÃ¶Í Ò¹áÅÐà¢ÕÂ¹ä´ §Ò  à¡Ô´¤ÇÒÁࢠÒ㨤ÅÒ´à¤Å×Íè ¹¹ Í ËÒ¡¢ ÍÁÙÅÁÕÁÒ¡¶Ö§ 16 ºÔµ ¤ÇÃàÅ×Í¡à¢Õ¹¢ ÍÁÙÅã¹ÃÙ»¢Í§àÅ¢°Ò¹ÊԺˡ¨ÐàËÁÒÐÊÁ¡Ç Ò à¾ÃÒШÐà¡Ô´¢ ÍÁÙÅà¾Õ§ 4 ËÅÑ¡ ¨´¨íÒáÅФѴÅÍ¡ ä´ §Ò  µÑÇàÅ¢°Ò¹ÊÔº¨ÐàËÁÒÐÊÁ㹡óշÁÕè ¡Õ Òäíҹdz·Ò§¤³ÔµÈÒʵà à¹×Íè §¨Ò¡¼Ùã ª §Ò¹¨Ð¤Ø¹ à¤Â ·íÒãË ÊÒÁÒö µÃǨÊͺ¼ÅÅѾ¸ ä´ §Ò Â Ê Ç¹ÃËÑÊáÊ¡Õ¨é ÐàËÁÒСѺ¢ ÍÁÙÅ·Õàè ¡ÕÂè ǡѺµÑÇÍÑ¡ÉÃËÃ×Í¢ ͤÇÒÁ¨íҹǹÁÒ¡ ¨ÐÁÕ㪠§Ò¹ º Í àÁ×Íè µ ͧ¡ÒÃãË i-Stamp2P24 áÊ´§¢ ͤÇÒÁº¹ÍØ»¡Ã³ áÊ´§¼ÅäÁ ÇÒ ¨Ðà» ¹ LED µÑÇàÅ¢ 7 Ê Ç¹ áÅÐ·Õ ¹ÔÂÁÁÒ¡·ÕÊè ´Ø ¤×Í âÁ´ÙÅ LCD ẺµÑÇÍÑ¡ÉÃ

3.1.2 ÅÒàºÅ¢Í§áÍ´à´ÃÊ ÅÒàºÅ (label) ¤×Í¡ÒÃ㪠¢ ͤÇÒÁµÑÇÍÑ¡ÉÃËÃ×ÍÊÑ­Åѡɳ 㹡ÒÃá·¹áÍ´à´Ãʢͧ˹ ǤÇÒÁ¨íÒ â»Ãá¡ÃÁ·Õè i-Stamp2P24¨Ðµ ͧ¡ÃÐâ´´ä»·íÒ§Ò¹ÂѧµíÒá˹ §àËÅ Ò¹Ñ¹é ·Ñ§é ¹Õàé ¾×Íè ËÅÕ¡àÅÕÂè §¡ÒÃÃкØáÍ´à´ÃÊ´ Ç¡Òà à¢Õ¹µÑÇàÅ¢áÍ´à´Ãʢͧ˹ ǤÇÒÁ¨íÒâ»Ãá¡ÃÁŧã¹â»Ãá¡ÃÁ¾ÕàºÊÔ¡«Ö§è ·íÒä´ ÂÒ¡áÅÐà¡Ô´¤ÇÒÁ¼Ô´¾ÅÒ´ä´ §Ò  ª×èͧ͢ÅÒàºÅÊÒÁÒöãË ¢Öé¹µ ¹´ ǵÑÇÍÑ¡ÉÃËÃ×Íà¤Ã×èͧËÁÒ (_) áµ ¨ÐäÁ ÊÒÁÒö¢Öé¹µ ¹´ ǵÑÇàÅ¢ áÅЪ×Íè ¢Í§ÅÒàºÅ¨Ðµ ͧäÁ à» ¹¤íÒʧǹ ઠ¹ ª×Íè ¢Í§¤íÒÊѧè (SERIN, toggle, GOTO) áÅÐ ª×Íè ¢Í§µÑÇá»Ã (port, w2, b13) à» ¹µ ¹ ª×èͧ͢ÅÒàºÅ¨Ðµ ͧµÒÁ´ ÇÂà¤Ã×èͧËÁÒ : áµ àÁ×è͵ ͧ¡ÒáíÒ˹´ãË ¡ÃÐâ´´ä»ÂѧÅÒàºÅ·Õèµ Í§¡Òà ¡ÒÃà¢Õ¹¤íÒÊѧè à¾×Íè ¡ÃÐâ´´ä»¹Ñ¹é ª×Íè ÅÒàºÅäÁ ¨Òí à» ¹µ ͧÁÕà¤Ã×Íè §ËÁÒ : ÍÕ¡ ´Ñ§µÑÇÍ ҧµ Í仹Õé LOOP: TOGGLE 0 FOR B0 = 1 to 10 TOGGLE 1 NEXT GOTO LOOP

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%


ÅÒàºÅ¢Í§¤ Ò¤§·Õè

ઠ¹à´ÕÂǡѺÅÒàºÅ¢Í§áÍ´à´ÃÊ ¼Ùã ª §Ò¹ÊÒÁÒö¡íÒ˹´¤ ÒÅÒàºÅãË ¡ºÑ ¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õäè ´ â´ÂÅÒ àºÅẺ¹Õäé Á ¨Òí à» ¹µ ͧµÒÁ´ ÇÂà¤Ã×Íè §ËÁÒ (:) áÅÐÊÒÁÒö¡íÒ˹´¤ ÒÅÒàºÅä´ â´Â㪠¤Òí Êѧè symbol ´Ñ§µÑÇÍ ҧ symbol start = 1 symbol end = 10 symbol count = b0

3.1.3 ¤ÍÁàÁ¹µ (comment) àÁ×Íè µ ͧ¡ÒÃà¾ÔÁè ¢ ͤÇÒÁà¾×Íè ͸ԺÒ¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁ ¢ ͤÇÒÁ·Õàè ¾ÔÁè ¢Ö¹é ÁÒ¹Õàé ÃÕÂ¡Ç Ò ¤ÍÁàÁ¹µì ¨Ðµ ͧ¢Öé¹µ ¹´ ÇÂà¤Ã×èͧËÁÒ ·Ø¡¤ÃÑé§ ¢ ͤÇÒÁ·ÕèÍÂÙ ËÅѧà¤Ã×èͧËÁÒ ¨¹¨ººÃ÷Ѵ¨Ðà» ¹¤íÒ͸ԺÒ ËÃ×ͤÍÁàÁ¹µ ·§Ñé ËÁ´ ËÃ×ÍÍҨ㪠¤Òí Êѧè REM ¹íÒ˹ Ò¢ ͤÇÒÁ·Õäè Á µÍ §¡ÒÃãË à¡Ô´¡ÒäÍÁä¾Å ËÃ×Í¡ÒÃá»Å§ ÀÒÉÒ àª ¹à´ÕÂǡѺã¹ÀÒÉÒàºÊÔ¡·ÑÇè æ ä» áÊ´§à» ¹µÑÇÍÂ Ò§ä´ ´§Ñ ¹Õé pins = %00000000 Make all pins low ¢ ͤÇÒÁ Make all pins low à» ¹¤ÍÁàÁ¹µ ËÃ×ͤíÒ͸ԺÒ ¨ÐäÁ ä´ ÃºÑ ¡ÒäÍÁä¾Å REM this is the main loop ¢ ͤÇÒÁ this is the main loop à» ¹¤ÍÁàÁ¹µ ËÃ×ͤíÒ͸ԺÒ ¨ÐäÁ ä´ ÃºÑ ¡ÒäÍÁä¾Å

3.2 ÃٻẺ¡ÒÃà¢Õ¹â»Ãá¡ÃÁ¾ÕàºÊÔ¡ ÁÕËÅѡࡳ± ·äÕè Á «ºÑ « ͹áÅÐÊíҤѭÍÂÙ 3 »ÃСÒä×Í 1. 㹺Ã÷Ѵáá¢Í§â»Ãá¡ÃÁµ ͧÃкØÃØ ¹¢Í§àºÊÔ¡áʵÁ» ·Õè㪠§Ò¹ â´ÂàÃÕÂ¡Ç Ò ¡íÒ˹´ä´àÃ硵տ (directive) «Ö§è ·íÒä´ 2 ÇÔ¸¤Õ Í× 1.1 ¾ÔÁ¾ ¢Í ¤ÇÒÁ {$STAMP BS2p} ŧ㹺Ã÷Ѵáá¢Í§â»Ãá¡ÃÁ (äÁ ¹ºÑ ¤ÍÁàÁ¹µ ¡Í ¹ ˹ Ò¹Õ)é à¾×Íè àÅ×Í¡Ãع ¢Í§àºÊÔ¡áʵÁ» 2 ´Ñ§ã¹ÃÙ»·Õè 3-1 1.2 àÅ×Í¡ä´àÃ硵տ¨Ò¡àÁ¹Ù Directive â´ÂàÅ×Í¡ä»·Õè BS2P ´Ñ§ã¹ÃÙ»·Õè 3-2

ÃÙ»·Õè 3-1 ¡ÒÃãÊ ä´àÃ硵տ¢Í§àºÊÔ¡áʵÁ» 2P ÃÙ»·Õè 3-2 ¡ÒÃãÊ ä´àÃ硵տ¢Í§àºÊÔ¡áʵÁ» 2P ´ Ç¡ÒþÔÁ¾ ࢠÒä»ã¹â»Ãá¡ÃÁ ´ Ç¡ÒÃàÅ×Í¡¨Ò¡àÁ¹Ù¤Òí Êѧè Directive &

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


ÃÙ»·Õè 3-3 ¡Ãͺ¢ ͤÇÒÁᨠ§àµ×͹ãË ¼àÙ ¢Õ¹â»Ãá¡ÃÁãÊ ä´àÃ硵տ¢Í§àºÊÔ¡áʵÁ» ŧã¹â»Ãá¡ÃÁ

ÃÙ»·Õè 3-4 áÊ´§¢Ñ¹é µÍ¹¡ÒÃãÊ ä´àÃ硵տ¢Í§àºÊÔ¡ÊáµÁ» 2P Íѵâ¹ÁѵÅÔ §ã¹â»Ãá¡ÃÁÍաẺ˹֧è (¡) à¢Õ¹â»Ãá¡ÃÁáŠǺѹ·Ö¡à» ¹ä¿Å ¹ÒÁÊ¡ØÅ .bsp ¨Ò¡¹Ñ¹é àÅ×Í¡àÁ¹Ù¤Òí Êѧè Check Syntax (¢) ËÅѧ¨Ò¡¹Ñ¹é «Í¿µ áÇà ¨ÐãÊ ä´àÃ硵տ¢Í§àºÊÔ¡áʵÁ» 2P ŧ㹺Ã÷Ѵáá¢Í§â»Ãá¡ÃÁãË àͧ Í ҧäáçµÒÁ ËÒ¡¼Ùà ¢Õ¹â»Ãá¡ÃÁÅ×Á¡íÒ˹´ä´àÃ硵տ àÁ×Íè ·íÒ¡ÒäÍÁä¾Å áÅдÒǹ âËÅ´ â»Ãá¡ÃÁ «Í¿µ áÇà àºÊÔ¡áʵÁ» àÍ´ÔàµÍà ¨Ð»ÃÒ¡¯Ë¹ Òµ Ò§ÁÒᨠ§àµ×͹áÅÐãË ·Òí ¡ÒÃàÅ×Í¡ä´àÃ硵տ ´Ñ§ã¹ ÃÙ»·Õè 3-3 àÁ×Íè àÅ×Í¡áÅ Ç «Í¿µ áÇà ¨ÐºÃèØä´àÃ硵տŧ㹺Ã÷Ѵáá¢Í§â»Ãá¡ÃÁãË àͧâ´ÂÍѵâ¹ÁÑµÔ ËÃ×Ͷ Ò ËÒ¡à¢Õ¹â»Ãá¡ÃÁáŠǺѹ·Ö¡à» ¹ä¿Å ¹ÒÁÊ¡ØÅ .bsp â´Â·ÕÂè §Ñ äÁ ä´ ãÊ ä´àÃ硵տ ¨Ò¡¹Ñ¹é ·íÒ¡ÒõÃǨÊͺÃٻẺ ¡ÒÃà¢Õ¹â»Ãá¡ÃÁ´ Ç¡ÒÃàÅ×Í¡¤íÒÊѧè Check Syntax «Í¿µ áÇà àºÊÔ¡áʵÁ» àÍ´ÔàµÍà ¨Ð·íÒ¡ÒÃãÊ ãË àͧâ´Â Íѵâ¹ÁÑµÔ ´Ñ§ã¹ÃÙ»·Õè 3-4 (¡) áÅÐ (¢) 2. 㹡ÒÃà¢Õ¹â»Ãá¡ÃÁ¤íÒÊѧè ËÃ×͵ÑÇá»Ãµ Ò§æ ¨Ðà» ¹µÑǾÔÁ¾ ãË­ ËÃ×͵ÑǾÔÁ¾ àÅç¡¡çä´ 3. ÊÒÁÒöà¢Õ¹¤íÒÊѧè ËÅÒÂæ ¤íÒÊÑ§è º¹ºÃ÷Ѵà´ÕÂÇ¡Ñ¹ä´ â´ÂᡤíÒÊÑ§è ´ Ç¡ÒÃ㪠à¤Ã×Íè §ËÁÒ : ¤Ñ¹è µÑÇÍ ҧµ Í仹Õé¨ÐáÊ´§ãË àË繶֧¡ÒÃà¢Õ¹â»Ãá¡ÃÁẺá¡໠¹ºÃ÷ѴáÅÐẺà¢Õ¹ÍÂ٠㹺Ã÷Ѵà´ÕÂǡѹ ¡ÒÃà¢Õ¹â»Ãá¡ÃÁẺ᡺Ã÷Ѵ DIRS = 255 Make all pins outputs for b2 = 0 to 100 Count from 0 to 100 pins = b2 Make pins = count (b2) next Continue counting til 100 ¡ÒÃà¢Õ¹â»Ãá¡ÃÁẺºÃ÷Ѵà´ÕÂÇ DIRS = 255 : for b2 = 0 to 100 : pins = b2 : next Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'


A ABS

D DATA

E END

I I2CIN

L LCDCMD

N NAP

AND ASC AUXIO

DCD DEBUG DEC

F FOR FREQOUT

I2COUT IHEX

LCDIN LCDOUT LIGHTSON

NCD NEXT NIB

B

DEC1..DEC5

G

IF

POLLRUN

SERIN

U

BELL

DIG

GET

IN0..IN15

LOOKUP

NOT

POLLWAIT

SEROUT

UNITOFF

GOSUB GOTO H

INA INB INC

LOW LOWBIT LOWNIB

O OR

SHEX SHEX1..SHEX4

OUT0..OUT15

PULSIN PULSOUT PUT

SHIFTIN

UNITON UNITSOFF V

BKSP DIM BIN DIR0..DIR15 BIN1..BIN14 DIRA

IHEX1..IHEX4

LOOKDOWN NIB0..NIB3

P PAUSE

S SBIN

SBIN1..SBIN16 POLLIN POLLMODE SDEC POLLOUT SDEC1..SDEC5

T TAB THEN TO TOGGLE

BIT BIT0..BIT15

DIRB DIRC

HEX HEX1..HEX4

IND INH

LSBFIRST LSBPOST

OUTA OUTB

PWM R

SHIFTOUT SIN

VAR W

BRANCH BRIGHT

DIRD DIRH

HIGH HIGHBIT

INL INPUT

LSBPRE M

OUTC OUTD

RANDOM RCTIME

SKIP SLEEP

WAIT WAITSTR

BUTTON BYTE C

DIRL DIRS DTMFOUT

HIGHNIB HOME

INS IOTERM ISBIN

MAX MAINIO MIN

OUTH OUTL OUTPUT

READ REP REV

SQR STEP STOP

WORD WRITE X

CLS CON

ISBIN1..ISBIN16

ISHEX

MSBFIRST MSBFIRST

OUTS OWIN

REVERSE RUN

STORE STR

XOR XOUT

COS

ISHEX1..ISHEX4

MSBPOST

OWOUT

COUNT CR

MSBPRE

µÒÃÒ§·Õè 3-2 ¤íÒµ Í§Ë ÒÁ·Õäè Á ÊÒÁÒö¹íÒÁÒ㪠㹡ÒÃµÑ§é ª×Íè ÅÒàºÅ ËÃ×͵ÑÇá»Ãã´æ ä´ ã¹â»Ãá¡ÃÁ ¢Í§àºÊÔ¡áʵÁ» 2P

3.3 ¤íÒʧǹ 㹡ÒÃà¢Õ¹â»Ãá¡ÃÁ¾ÕàºÊÔ¡ ¨ÐÁÕ¤Òí ʧǹ·Õ¼è àÙ ¢Õ¹â»Ãá¡ÃÁäÁ ÊÒÁÒö¡íÒ˹´ËÃ×Í㪠໠¹ª×Íè µÑÇá»Ãä´ à¹×èͧ¨Ò¡¤íÒàËÅ Ò¹Ñé¹ÍҨ໠¹ª×èͧ͢ªØ´¤íÒÊÑ觷Ñ駷ҧµÃ§áÅФíÒÊÑè§à·ÕÂÁ¢Í§àºÊÔ¡áʵÁ» 2P ã¹µÒÃÒ§·Õè 3-2 áÊ´§¤íÒËÃ×Í¢ ͤÇÒÁʧǹ «Ö§è ¼Ùà ¢Õ¹â»Ãá¡ÃÁ¾ÕàºÊÔ¡µ ͧËÅÕ¡àÅÕÂè §äÁ ãª

3.4 ÊÑ­Åѡɳ ¢Í§¡ÒûÃÐÁÇżŷҧ¤³ÔµÈÒʵà ¢ ͤÇÒÁ µÑÇ ÍáÅÐÊÑ­Åѡɳ µÒ §æµ Í仹Õàé » ¹à¤Ã×Íè §ËÁÒ·Õãè ª á·¹¡ÒáÃзíÒ·Ò§¤³ÔµÈÒʵà ÀÒÂã¹ â»Ãá¡ÃÁÀÒÉÒ¾ÕàºÊÔ¡¢Í§àºÊÔ¡áʵÁ» 2P + á·¹¡Òúǡ á·¹¡ÒÃź * á·¹¡Òäٳ (Ê §¤ Ò¼ÅÅѾ¸ 亵 ´Ò ¹µèÒí ¡ÅѺÁÒ) ** á·¹¡Òäٳ (Ê §¤ Ò¼ÅÅѾ¸ 亵 ´Ò ¹ÊÙ§¡ÅѺÁÒ) / á·¹¡ÒÃËÒà (Ê §¤ Ò¼ÅÅѾ¸ ·äÕè ´ ¨Ò¡¡ÒÃËÒáÅѺÁÒ) // á·¹¡ÒÃËÒà (Ê §¤ ÒàÈÉ·Õàè ËÅ×ͨҡ¡ÒÃËÒáÅѺÁÒ) min à¡çº¤ ÒµÑÇá»Ã·ÕÁè ¤Õ Ò ÁÒ¡¡Ç ÒËÃ×Í෠ҡѺ¤ Ò¢ ÍÁÙÅ·Õ¡è Òí ˹´ËÅѧ¤íÒÊÑ§è ¹Õé max à¡çº¤ ÒµÑÇá»Ã·ÕÁè ¤Õ Ò ¹ ÍÂ¡Ç ÒËÃ×Í෠ҡѺ¤ Ò¢ ÍÁÙÅ·Õ¡è Òí ˹´ËÅѧ¤íÒÊÑ§è ¹Õé

!

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


(OR) ·Ò§Åͨԡ

& |

á·¹¡ÒÃá͹´ (AND) ·Ò§Åͨԡ (à» ¹¤ÕÂà дѺÊͧ¢Í§¤Õ \ àÅ×Í¡â´Â¡Òá´ Shift áŠǵÒÁ´ Ǥՠ\) á·¹¡ÒÃÍÍÃ

^ &/ |/ ^/

á·¹¡ÒÃàÍ硤ÅÙ«¿Õ ÍÍà (XOR) ·Ò§Åͨԡ á·¹¡ÒÃá͹´ -¹Íµ (AND NOT) ËÃ×Íá¹¹´ (NAND) ·Ò§Åͨԡ á·¹¡ÒÃÍÍà -¹Íµ (OR NOT) ËÃ×͹Íà (NOR) ·Ò§Åͨԡ á·¹¡ÒÃàÍ硤ÅÙ«¿Õ ÍÍà -¹Íµ (XOR NOT) ËÃ×ÍàÍ硤ÅÙ«¿Õ ¹Íà (XNOR) ·Ò§Åͨԡ

µÑÇÍ ҧáÊ´§¡ÒáÃзíÒ·Ò§¤³ÔµÈÒʵà count = count + 1 à¾ÔèÁ¤ ÒµÑǹѺ timer = timer * 2 ¤Ù³¤ Ò timer ´ Ç 2 b2 = b2 / 8 ËÒÃÃÕ¨ÊÔ àµÍà b2 ´ Ç 8 w3 = w3 & 255 àÅ×͡੾ÒТ ÍÁÙÅ亵 ´Ò ¹µèÒí ¢Í§ÃÕ¨ÊÔ àµÍà w3 b0 = b0 + 1 max 99 à¾ÔÁè ¤ ÒÃÕ¨ÊÔ àµÍà b0 áµ äÁ ÂÍÁãË Ã¨Õ ÊÔ àµÍà b0 ÁÕ¤Ò à¡Ô¹ 99 b3 = b3 - 1 min 10 Å´¤ ÒÃÕ¨ÊÔ àµÍà b3 áµ äÁ ÂÍÁãË Ã¨Õ ÊÔ àµÍà b3 ÁÕ¤Ò ¹ ÍÂ¡Ç Ò 10

3.5 ÃÒÂÅÐàÍÕ´ªØ´¤íÒÊÑ§è ¢Í§àºÊÔ¡áʵÁ» 2P ¤íÒÊѧè ËÅÑ¡ã¹â»Ãá¡ÃÁ¾ÕàºÊÔ¡¢Í§àºÊÔ¡áʵÁ» 2P ÁÕ·§Ñé ÊÔ¹é 80 ¤íÒÊѧè â´Â¨ÐÃÇÁËÁ´·Ñ§é ¤íÒÊѧè 㪠§Ò¹ ·Ò§ÎÒà ´áÇà 56 ¤íÒÊѧè , ¤íÒÊѧè à·ÕÂÁ·Õãè ª »ÃСͺ㹡ÒÃà¢Õ¹â»Ãá¡ÃÁ 2 ¤íÒÊѧè áÅФíÒÊÑ§è ¤íҹdz·Ò§«Í¿µ áÇà 22 ¤íÒÊѧè Ạ§ÍÍ¡à» ¹¡ÅØÁ µÒÁÅѡɳСÒ÷íÒ§Ò¹ä´ 17 ¡ÅØÁ ä´ ´§Ñ ¹Õé

3.5.1. ¡ÅØÁ ¤íÒÊÑ§è ¡ÃÐâ´´áÅФǺ¤ØÁ¡Ò÷íÒ§Ò¹ (Branching/Program control) ÁÕ 8 ¤íÒÊÑ§è ¤×Í IF...THEN BRANCH GOTO GOSUB RETURN RUN POLLRUN STOP

à»ÃÕºà·Õºà§×è͹䢡 ͹¡ÃÐâ´´ ¡ÃÐâ´´ä»ÂѧµíÒá˹ §·Õè¡íÒ˹´µÒÁ¤ ҢͧµÑÇá»Ã ¡ÃÐâ´´ä»ÂѧáÍ´à´ÃÊã´æ ¡ÃÐâ´´ä»Âѧâ»Ãá¡ÃÁ Í ¡ÃÐâ´´ÍÍ¡¨Ò¡â»Ãá¡ÃÁ Í Ãѹâ»Ãá¡ÃÁ·Õµè Í §¡Òà àÅ×Í¡ä´ 8 â»Ãá¡ÃÁ ¡ÃÐâ´´ä»Ãѹâ»Ãá¡ÃÁã¹à¾¨·Õè¡íÒ˹´àÁ×èÍà¡Ô´¡ÒÃÍÔ¹àµÍà ÃÑ»µ ẺǹÃÍ (polling interrupt) ¢Ö¹é ËÂØ´¡Ò÷íÒ§Ò¹

3.5.2 ¡ÅØÁ ¤íÒÊÑ§è ·íҧҹǹÃͺ (Looping) FOR...NEXT ¡íÒ˹´¨íҹǹÃͺ·Õèµ Í§¡ÒÃǹÅÙ»ËÃ×Íǹ·íÒ§Ò¹«éíÒ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


3.5.3 ¡ÅØÁ ¤íÒÊÑ§è µÔ´µ Í˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ (EEPROM access) ÁÕ 4 ¤íÒÊÑ§è ¤×Í DATA READ WRITE STORE

à¡çº¢ ÍÁÙÅŧã¹Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ¡ ͹´Òǹ âËÅ´â»Ãá¡ÃÁ¾ÕàºÊÔ¡ Í Ò¹¢ ÍÁÙÅÃдѺ亵 ¨Ò¡Ë¹ ǤÇÒÁ¨íÒÍÕÍÕ¾ÃÍÁÁÒà¡çºäÇ ã¹µÑÇá»Ã à¢Õ¹¢ ÍÁÙÅÃдѺ亵 ä»à¡çºäÇ ã¹Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ ÊÅѺ¡ÒÃÍ Ò¹/à¢Õ¹¢ ÍÁÙÅã¹Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ·Õ¨è ´Ñ ÊÃÃà» ¹·Õàè ¡çºâ»Ãá¡ÃÁ

3.5.4 ¡ÅØÁ ¤íÒÊÑ§è µÔ´µ Í˹ ǤÇÒÁ¨íÒáÃÁ (RAM access) ÁÕ 2 ¤íÒÊÑ§è ¤×Í GET PUT

Í Ò¹¢ ÍÁÙŨҡ˹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´áÃÁã¹µÑÇÍÔ¹àµÍà ¾ÃÕµàµÍà à¡çº¢ ÍÁÙÅŧã¹Ë¹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´áÃÁã¹µÑÇÍÔ¹àµÍà ¾ÃÕµàµÍÃ

3.5.5 ¡ÅØÁ ¤íÒÊÑ§è ¨Ñ´¡ÒõÑÇàÅ¢ (Numerics)

ÁÕ 3 ¤íÒÊÑ§è ¤×Í LOOKUP à» ´µÒÃÒ§¢ ÍÁÙÅ LOOKDOWN ¤ ¹ËÒµÑÇàÅ¢·Õàè ËÁ×͹¡Ñ¹ áÅ Çà¡çº¤ ÒäÇ ã¹µÑÇá»Ã RANDOM ÊØÁ µÑÇàÅ¢

3.5.6 ¡ÅØÁ ¤íÒÊÑ§è ¨Ñ´¡ÒÃÍÔ¹¾ØµàÍÒµ ¾µØ ´Ô¨µÔ ÍÅ (Digital I/O) ÁÕ 17 ¤íÒÊÑ§è ¤×Í INPUT OUTPUT REVERSE LOW HIGH TOGGLE PULSIN PULSOUT BUTTON COUNT XOUT AUXIO MAINIO

!

¡íÒ˹´ãË ·íҧҹ໠¹ÍÔ¹¾Øµ ¡íÒ˹´ãË ·íҧҹ໠¹àÍÒµ ¾Øµ à»ÅÕ蹨ҡ¢ÒÍÔ¹¾Øµà» ¹àÍÒµ ¾ØµËÃ×ͨҡàÍÒµ ¾Øµà» ¹ÍÔ¹¾Øµ ·íÒãË ¢ÒàÍÒµ ¾µØ à» ¹Åͨԡ 0 ·íÒãË ¢ÒàÍÒµ ¾µØ à» ¹Åͨԡ 1 ·íÒãË ¢ÒàÍÒµ ¾Øµ¡ÅѺʶҹÐÅͨԡ ÇÑ´ÊÑ­­Ò³¾ÑÅÊ Í¹Ô ¾Øµ (¤ÇÒÁÅÐàÍÕ´ 2 äÁâ¤ÃÇÔ¹Ò·Õ) Ê §ÊÑ­­Ò³¾ÑÅÊ ÍÍ¡ (¤ÇÒÁÅÐàÍÕ´ 2 äÁâ¤ÃÇÔ¹Ò·Õ) µÃǨ¨Ñº¡Òá´ÊÇÔµª áÅÐá¡ ¡ÒÃàºÒ« ¢Í§ÊÇÔµª ¹Ñº¨íҹǹä«à¡ÔŢͧÊÑ­­Ò³ÍÔ¹¾Øµ (ÁÕ¤Ò 0 ¶Ö§ 125kHz) ¡íÒà¹Ô´ÃËÑʤǺ¤ØÁÊíÒËÃѺÍØ»¡Ã³ µÍ ¾ ǧ͹ءÃÁ X-10 àÅ×Í¡¢Ò¾Íà µàÊÃÔÁ (Auxiliary I/O : A0 ¶Ö§ A15) ·íҧҹ᷹¢Ò¾Íà µËÅÑ¡ P0 ¶Ö§ P15 (äÁ 㪠§Ò¹ã¹ i-Stamp2P24) àÅ×Í¡¢Ò¾Íà µËÅÑ¡ P0 ¶Ö§ P15 ·íҧҹ᷹¢Ò¾Íà µàÊÃÔÁ A0 ¶Ö§ A15 Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


IOTERM POLLIN POLLOUT POLLMODE

àÅ×Í¡¡ÅØ Á¢Ò¾Íà µ·Õèµ Í§¡ÒÃãË ·íÒ§Ò¹ µÃǨ¨Ñº¡ÒÃà¡Ô´ÍÔ¹àµÍÃ Ã»Ñ µ ẺǹÃÍ (polling interrupt) ¡íÒ˹´ãË ¢Ò¾Íà µ·íҧҹ໠¹àÍÒµ ¾µØ àÁ×Íè à¡Ô´¡ÒÃÍÔ¹àµÍÃ Ã»Ñ µ ẺǹÃÍ¢Ö¹é àÅ×Í¡âËÁ´¢Í§¡ÒÃÍÔ¹àµÍà ÃÑ»µ ẺǹÃÍ

3.5.7 ¡ÅØÁ ¤íÒÊÑ§è ¨Ñ´¡ÒÃÍÔ¹¾ØµàÍÒµ ¾µØ ͹ءÃÁẺÍЫԧâ¤Ã¹ÑÊ (Asynchronous I/O) ÁÕ 4 ¤íÒÊÑ§è ¤×Í SERIN SEROUT OWIN OWOUT

ÃѺ¢ ÍÁÙÅ͹ءÃÁà¢ Ò ÁÕû٠Ẻ¢ ÍÁÙÅẺ N81 ËÃ×Í E71 Ê §¢ ÍÁÙÅ͹ءÃÁã¹ÃٻẺ N81 ËÃ×Í E71 ÍÍ¡ä»·Ò§¢Ò SOUT ¢Í§ i-Stamp2P24 ÃѺ¢ ÍÁÙÅ͹ءÃÁࢠҨҡÍØ»¡Ã³ ÃкººÑÊ 1 ÊÒ (1-Wire) Ê §¢ ÍÁÙÅ͹ءÃÁÁÍÍ¡ä»ÂѧÍØ»¡Ã³ ÃкººÑÊ 1 ÊÒ (1-Wire)

3.5.8 ¡ÅØÁ ¤íÒÊÑ§è ¨Ñ´¡ÒÃÍÔ¹¾ØµàÍÒµ ¾µØ ͹ءÃÁẺ«Ô§â¤Ã¹ÑÊ (Synchronous I/O) ÁÕ 4 ¤íÒÊÑ§è ¤×Í SHIFTIN SHIFTOUT I2CIN I2COUT

àÅ×è͹¢ ÍÁÙÅࢠҨҡẺ¢¹Ò¹à» ¹áººÍ¹Ø¡ÃÁ Ê §¢ ÍÁÙÅÍÍ¡¨Ò¡áººÍ¹Ø¡ÃÁ ÃѺ¢ ÍÁÙÅ͹ءÃÁࢠҨҡÍØ»¡Ã³ ÃкººÑÊ I2C Ê §¢ ÍÁÙÅ͹ءÃÁÁÍÍ¡ä»ÂѧÍØ»¡Ã³ ÃкººÑÊ I2C

3.5.9 ¡ÅØÁ ¤íÒÊÑ§è ¨Ñ´¡ÒÃÍÔ¹¾ØµàÍÒµ ¾µØ Ẻ¢¹Ò¹ (Parallel I/O) ÁÕ 3 ¤íÒÊÑ§è ¤×Í LCDCMD LCDIN LCDOUT

à¢Õ¹¤íÒÊѧè ä»ÂѧâÁ´ÙÅ LCD Í Ò¹¢ ÍÁÙŨҡâÁ´ÙÅ LCD à¢Õ¹¢ ÍÁÙÅËÃ×ͤíÒÊѧè ä»ÂѧâÁ´ÙÅ LCD

3.5.10 ¡ÅØÁ ¤íÒÊÑ§è ¨Ñ´¡ÒÃÍÔ¹¾ØµàÍÒµ ¾µØ ¡ÑºÊÑ­­Ò³ÍйÒÅÍ¡ (Analog I/O) ÁÕ 2 ¤íÒÊÑ§è ¤×Í PWM RCTIME

Êà ҧÊÑ­­Ò³ PWM ¢¹Ò´ 0 ¶Ö§ 5V ÍÍ¡ä»·Ò§¢Ò¾Íà µ ÇÑ´¤ ÒàÇÅÒ¡ÒûÃШØáÅФÒ»ÃШآͧǧ¨Ã RC ¹íÒä»ãª Ç´Ñ ¤ ҢͧµÑǵ Ò¹·Ò¹

3.5.11 ¡ÅØÁ ¤íÒÊÑ§è ¨Ñ´¡Òô Ò¹àÇÅÒ (Timing) ÁÕ 2 ¤íÒÊÑ§è ¤×Í PAUSE POLLWAIT

˹ ǧàÇÅÒ 0 ¶Ö§ 65,536 ÁÔÅÅÔÇ¹Ô Ò·Õ ¡íÒ˹´¤ Ò˹ ǧàÇÅҢͧ¡ÒÃÍÔ¹àµÍÃ Ã»Ñ µ ẺǹÃÍ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!!


3.5.12 ¡ÅØÁ ¤íÒÊѧè Êà ҧÊÑ­­Ò³àÊÕ§ (Sound) ÁÕ 2 ¤íÒÊÑ§è ¤×Í FREQOUT DTMFOUT

¡íÒà¹Ô´ÊÑ­­Ò³ä«¹ ˹֧è ËÃ×ÍÊͧ¤ÇÒÁ¶Õè µÑ§é áµ 0 ¶Ö§ 32.767kHz ¡íÒà¹Ô´ÊÑ­­Ò³ DTMF ¢Í§Ãкºâ·ÃÈѾ·

3.5.13 ¡ÅØÁ ¤íÒÊÑ§è ¤Çº¤ØÁ¾Åѧ§Ò¹ (Power control) ÁÕ 3 ¤íÒÊÑ§è ¤×Í NAP SLEEP END

ËÂØ´·íҧҹ㹪 ǧàÇÅÒÊѹé æ ¡ÒáԹ¾Åѧ§Ò¹¨ÐŴŧ ·íÒ§Ò¹ã¹âËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹ ·íÒ§Ò¹ã¹âËÁ´ÊÅÕ»¨¹¡Ç Ò¨ÐÁÕ¡Òè ÒÂä¿ËÃ×͵ ÍàºÊÔ¡áʵÁ» 2P ࢠҡѺ ¤ÍÁ¾ÔÇàµÍà àÁ×Íè ¡ÃзíÒ¤íÒÊÑ§è ¹Õé i-Stamp2P24 ¨Ð¡Ô¹¡ÃÐáÊä¿¿ ÒŴŧàËÅ×Í 60PA

3.5.14. ¡ÅØÁ ¤íÒÊÑ§è µÃǨÊͺ¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁ (Program debugging) DEBUG

áÊ´§¤ ҢͧµÑÇá»Ã¼ Ò¹·Ò§¤ÍÁ¾ÔÇàµÍÃ

3.5.15. ¡ÅØÁ ¤íÒÊѧè à·ÕÂÁÊíÒËÃѺ㪠»ÃСͺ¡ÒÃà¢Õ¹â»Ãá¡ÃÁ ÁÕ 2 ¤íÒÊÑ§è ¤×Í CON VAR

㪠¡Òí ˹´¤ Ò¤§·Õè 㪠¡íÒ˹´µÑÇá»Ã

3.5.16. ¡ÅØÁ ¤íÒÊÑ§è »ÃÐÁÇżŷҧ¤³ÔµÈÒʵà ÁÕ 16 ¤íÒÊÑ§è ¤×Í + * ** / // */ >> << MIN MAX

!"

¤íÒÊÑ觡Òúǡ ¤íÒÊÑ觡ÒÃź ¤íÒÊÑ§è ¡Òäٳ â´ÂÊ §¤ Ò¼ÅÅѾ¸ 亵 ´Ò ¹µèÒí ¡ÅѺÁÒ ¤íÒÊÑ§è ¡Òäٳ â´ÂÊ §¤ Ò¼ÅÅѾ¸ 亵 ´Ò ¹ÊÙ§¡ÅѺÁÒ ¤íÒÊÑ§è ¡ÒÃËÒà â´ÂÊ §¤ Ò¼ÅÅѾ¸ ·äÕè ´ ¨Ò¡¡ÒÃËÒáÅѺÁÒ ¤íÒÊÑ§è ¡ÒÃËÒà â´ÂÊ §¤ ÒàÈÉ·Õàè ËÅ×ͨҡ¡ÒÃËÒáÅѺÁÒ ¤íÒÊÑ觤ٳàÅ¢·È¹ÔÂÁ ¤íÒÊѧè àÅ×Íè ¹¢ ÍÁÙÅä»·Ò§¢ÇÒ ÁÕ¤Ò à· Ò¡ÑºËÒô Ç 2 ¤íÒÊѧè àÅ×Íè ¹¢ ÍÁÙÅä»·Ò§« Ò ÁÕ¤Ò à· Ò¡Ñº¤Ù³´ Ç 2 à¡çº¤ ÒµÑÇá»Ã·ÕèÁÕ¤ ÒÁÒ¡¡Ç ÒËÃ×Í෠ҡѺ¤ Ò¢ ÍÁÙÅ·Õè¡íÒ˹´ËÅѧ¤íÒÊÑ觹Õé à¡çº¤ ÒµÑÇá»Ã·ÕèÁÕ¤ Ò¹ ÍÂ¡Ç ÒËÃ×Í෠ҡѺ¤ Ò¢ ÍÁÙÅ·Õè¡íÒ˹´ËÅѧ¤íÒÊÑ觹Õé Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


ABS SQR SIN COS DIG

»ÃÐÁÇżÅ੾ÒТ ÍÁÙŵÑÇàŢẺäÁ ¤Ô´à¤Ã×èͧËÁÒ ¶Í´ÃÒ¡·ÕèÊͧ ¤íҹdz¤ Ò SINE ·Ò§µÃÕ⡳ÁÔµÔ ¤íҹdz¤ Ò COSINE ·Ò§µÃÕ⡳ÁÔµÔ àÃÕ¡¤ Ңͧ¢ ÍÁÙÅã¹ËÅÑ¡·Õ¡è Òí ˹´ã¹ÃÙ»¢Í§àÅ¢°Ò¹ÊÔº

3.5.17. ¡ÅØÁ ¤íÒÊÑ§è »ÃÐÁÇżŷҧÅͨԡ ÁÕ·§Ñé ÊÔ¹é 6 ¤íÒÊÑ§è ¤×Í & | ^ REV DCD NCD

á͹´ (AND) ·Ò§Åͨԡ ÍÍà (OR) ·Ò§Åͨԡ àÍ硤ÅÙ«¿Õ ÍÍà (XOR) ·Ò§Åͨԡ ÊÅѺºÔµ¢ ÍÁÙÅ àÅ×͡૵ºÔµ·Õµè Í §¡Òâͧ¢ ÍÁÙÅ¢¹Ò´ 16 ºÔµ áÊ´§ºÔµ¹ÑÂÊíҤѭ¢Í§¢ ÍÁÙÅ¢¹Ò´ 16 ºÔµ

3.6 PBASIC 2.5 ä´àÃ硵տ

à¹×Íè §¨Ò¡â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà V2 ¢Ö¹é ä» ÊÒÁÒöÃͧÃѺ¡ÒÃá»ÅÀÒÉÒ¾ÕàºÊÔ¡·Ñ§é PBASIC 2.0 áÅÐ 2.5 ã¹·Õ¹è ¢Õé Íá¹Ð¹íÒãË ãª PBASIC 2.5 ¨Ö§µ ͧÁÕ¡ÒûÃСÒÈä´àÃ硵տäÇ ·ÊÕè Ç ¹ËÑǢͧâ»Ãá¡ÃÁ â´Â ÊÒÁÒö·íÒä´ 3 ÇÔ¸¤Õ Í× 1. ä»·Õàè Á¹Ù Directive ࢠÒä»·Õè PBASIC àÅ×Í¡ Version 2.5 ¨Ð»ÃÒ¡¯¢ ͤÇÒÁ {$PBASIC 2.5} 2. àÅ×Í¡¨Ò¡»ØÁ 3. ¾ÔÁ¾ ¢Í ¤ÇÒÁ {$PBASIC 2.5} ŧº¹ºÃ÷Ѵáá¢Í§â»Ãá¡ÃÁ â´Â»¡µÔáŠǤÇÃãª Ç¸Ô ·Õ Õè 1 áÅÐ 2 à¾×Íè » ͧ¡Ñ¹¤ÇÒÁ¼Ô´¾ÅҴ㹡ÒþÔÁ¾

3.7 ¡ÒÃ㪠¨ÅØ ÀÒ¤ËÃ×Í comma (,) 㹡ÒÃàª×Íè Áµ ͤíÒÊѧè ã¹àºÊÔ¡áʵÁ» àÍ´ÔàµÍà PBASIC 2.5 ä´ à¾ÔÁè ¤ÇÒÁÊÒÁÒö¾ÔàÈÉ·Õàè » ¹»ÃÐ⪹ ÁÒ¡¤×Í ãª ¨ÅØ ÀÒ¤ ËÃ×ͤÍÁÁ Ò (,) 㹡ÒÃàª×Íè Áµ ͤíÒÊÑ§è ¢Í§â»Ãá¡ÃÁ·ÕÁè ¤Õ ÇÒÁÂÒÇÁÒ¡æ ãË ÊÒÁÒö¢Ö¹é µ ¹ºÃ÷ѴãËÁ á·¹ ·Õè¨Ðà¢Õ¹µ ͡ѹä»ã¹ºÃ÷Ѵà´ÕÂÇáÅ ÇÁÕ¤ÇÒÁÂÒÇÁÒ¡ ¨¹äÁ Êдǡµ Í¡ÒõÃǨÊͺ¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁ ´Ñ§µÑÇÍ ҧ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!#


Ẻà´ÔÁã¹ PBASIC 2.0 DEBUG Hello, World , CR, PBASIC 2.5 is ready for action! BRANCH idx, [Target1, Target2, Target3,Target4, Target5, Target5] SELECT idx CASE 1, 2, 6, 10, 11, 12 HIGH 0 CASE 3, 4, 5, 13, 14, 15 HIGH 1 ENDSELECT

ẺãËÁ ã¹ PBASIC 2.5 DEBUG Hello, World , CR, PBASIC 2.5 is ready for action! BRANCH idx, [Target1, Target2, Target3, Target4, Target5, Target5] SELECT idx CASE 1, 2, 6, 10, 11, 12 HIGH 0 CASE 3, 4, 5, 13, 14, 15 HIGH 1 ENDSELECT

3.8 ¡ÒÃãÊ à¤Ã×Íè §ËÁÒ¨ش¤ÙË Ã×Íâ¤Å͹ (:) à¾×Íè »ÃСÒÈÅÒàºÅ 㹡ÒûÃСÒÈÅÒàºÅ¢Í§â»Ãá¡ÃÁã¹ PBASIC 2.5 ¨íÒà» ¹Í ҧÂÔ§è ¨Ðµ ͧãÊ à¤Ã×Íè §ËÁÒ¨ش¤ÙË Ã×Í â¤Å͹ (:) µÒÁËÅѧª×Íè ·Õµè Í §ÒáíÒ˹´ãË à» ¹ÅÒàºÅ¢Í§â»Ãá¡ÃÁàÊÁÍ

!$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡ÒÃàµÃÕÂÁÍØ»¡Ã³ ÊíÒËÃѺ·íÒ¡Ò÷´Åͧ Í 㹡ÒÃ͸ԺÒ¡Ò÷íÒ§Ò¹áÅСÒÃ㪠§Ò¹¤íÒÊÑ§è ¢Í§àºÊÔ¡áʵÁ» 2P ¨Ð㪠¡Ò÷´Åͧ ÍÂà ÇÁ´ Ç à¾×Íè ª Ç ãË ÊÒÁÒöࢠÒã¨ä´ §Ò Â¢Ö¹é ¡ÒÃàµÃÕÂÁ¤ÇÒÁ¾Ã ÍÁã¹¢Ñ¹é µ ¹ÁÕ¹Õé (1) ¹íÒ i-Stamp2P24 µÔ´µÑ§é ŧº¹¤Í¹à¹ç¡àµÍà 24 ¢Ò·ÕÇè Ò §º¹ºÍà ´ JX-2SX plusII (2) àª×Íè Áµ ÍÊÒÂÃÐËÇ Ò§ºÍà ´ JX-2SX plus II ¡Ñº¾Íà µÍ¹Ø¡ÃÁ·ÕÇè Ò §¢Í§¤ÍÁ¾ÔÇàµÍà ËÒ¡ÁÕ੾ÒоÍà µ USB ¨Ðµ ͧ㪠µÇÑ á»§ÊÑ­­Ò³¾Íà µ USB à» ¹¾Íà µÍ¹Ø¡ÃÁ á¹Ð¹íÒÃع UCON-232S (www.inex.co.th) (3) àµÃÕÂÁáËÅ §¨ ÒÂ俵ç 9V ¢Ö¹é ä» ÊÙ§ÊØ´ 16V ¡ÃÐáÊ 300 ¶Ö§ 800mA ÍҨ㪠ÍÐá´»àµÍà ÊÒí àÃç¨ÃÙ»ä´ â´ÂäÁ ¨Òí à» ¹µ ͧ¤íÒ¹Ö§¶Ö§¢ÑÇé ¢Í§ÍÐá´»àµÍà à¹×Íè §¨Ò¡º¹ºÍà ´ JX-2SX plus II ÁÕǧ¨Ã¨Ñ´¢ÑÇé áç´Ñ¹ä¿àÅÕÂé §ÍÂÙá Å Ç (4) àµÃÕÂÁËÑÇáà § ¤ÕÁµÑ´ ÊÒÂä¿ÊíÒËÃѺºÑ´¡ÃÕà¾×Íè Êà ҧǧ¨Ã·´Åͧ ÊÒµ Íǧ¨Ã ἧµ Íǧ¨Ã áÅÐÍØ»¡Ã³ ·ÕÃè кØäÇ ã¹áµ ÅСÒ÷´Åͧ 㹡Ò÷´Åͧ ÍÂáµ ÅСÒ÷´Åͧ¢ÍãË »¯ÔºÑµÔµÒÁ¢Ñ鹵͹Í ҧà¤Ã §¤ÃÑ´ à¾×èÍ» ͧ¡Ñ¹äÁ ãË à¡Ô´¤ÇÒÁ àÊÕÂËÒÂá¡ µÇÑ i-Stamp2P24 áÅкÍà ´ JX-2SX plus II ·Ø¡¤ÃÑ§é ·Õàè ÊÃç¨ÊÔ¹é ¡Ò÷´Åͧã¹áµ ÅÐâ»Ãá¡ÃÁ¢Í§áµ ÅСÒà ·´Åͧ¤ÇûŴÊÒµ Íǧ¨ÃÍÍ¡¨Ò¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 àÊÁÍ

¡ÒÃ㪠§Ò¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ º¹ºÍà ´ JX-2SX plus II ÁÕ¾¹×é ·Õãè Ë ¼ãÙ ª §Ò¹ÊÒÁÒöÊà ҧǧ¨Ãà¾×Íè ·íÒ¡Ò÷´ÅÍ§ä´ àͧ´ Ç¡ÒúѴ¡ÃÕ µ Íǧ¨Ã Í ҧäáçµÒÁ¡çÊÒÁÒöµÔ´µÑ§é ἧµ Íǧ¨Ã ËÃ×Í àºÃ´ºÍà ´ (breadboard) ¢¹Ò´ 2.5 x 3.5 ¹ÔÇé ¨Ø´µ Í 400 ¨Ø´ä´ ·íÒãË ÊÒÁÒöµ ÍáÅдѴá»Å§á¡ 䢡Òõ Íǧ¨Ãä´ Êдǡ¢Ö¹é â´ÂäÁ µÍ §ºÑ´¡ÃÕ ã¹ÃÙ» A áÊ´§â¤Ã§Êà ҧÀÒÂ㹢ͧἧµ Íǧ¨Ã ÁÕ¡ÒÃàª×Íè Áµ ÍÀÒÂã¹ÍÂÙ 2 Ẻ¤×Í µ Ͷ֧¡Ñ¹µÒÁá¹Ç µÑ§é áÅе Ͷ֧¡Ñ¹µÒÁá¹Ç¹Í¹ ´Ñ§¹Ñ¹é 㹡ÒÃ㪠§Ò¹¨Ö§µ ͧÃÐÁÑ´ÃÐÇѧãË ´Õ ÊíÒËÃѺÊÒµ Íǧ¨Ã㪠ÅÇ´·Í§á´§à´ÕÂè Ç àÊ ¹¼ Ò¹Èٹ ¡ÅÒ§ 0.65 ÁÔÅÅÔàÁµÃ ËÃ×ÍàºÍà 22AWG µÑ´ãË ÁÕ¤ÇÒÁÂÒÇÍ ҧàËÁÒÐÊÁ áÅл͡»ÅÒÂÊÒÂãË àËç¹ÅÇ´µÑǹíÒÂÒÇ»ÃÐÁÒ³ 1 ૹµÔàÁµÃ ÊíÒËÃѺàÊÕºŧ º¹á¼§µ Íǧ¨Ãä´ áÅФÇôѴãË »ÅÒ ÅÇ´·Í§á´§ ©¹Ç¹ µÑ§é ©Ò¡ ´Ñ§áÊ´§µÑÇÍ ҧã¹ÃÙ» B Ê Ç¹ã¹ÃÙ» C áÊ´§ãË àË繶֧¡Òà àª×èÍÁµ ÍÀÒÂã¹á¼§µ Íǧ¨ÃàÁ×èÍÁÕ¡Òà àÊÕºÊÒÂŧº¹á¼§µ Íǧ¨Ã ¤ÇÃàÊÕº ÃÙ» B ¡ÒÃàµÃÕÂÁÊÒÂÊíÒËÃѺµ Íǧ¨Ã ÊÒÂãË á¹º¡Ñºá¼§µ Íǧ¨Ã ·Ñ駹Õéà¾×èÍ ÊÒµ Íǧ¨ÃÊͧàÊ ¹¹Õé ª ÇÂ㹡ÒõÃǨÊͺ¡Òõ Íǧ¨ÃáÅÐ äÁ µ Ͷ֧¡Ñ¹ ÊÒµ Íǧ¨Ã ÃÙ » A áÊ´§¡ÒÃàª×è Í Áµ Í ÀÒÂ㹢ͧ ÊͧàÊ ¹¹Õéµ Í¶Ö§¡Ñ¹ à¾×Íè ¤ÇÒÁÊǧÒÁ ¹Í¡¨Ò¡¹Ñ¹é Âѧª Ç ἧµ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ (Ãٻà ҧ¢Í§ ãË ¡Òõ ÍÍØ»¡Ã³ à¾ÔèÁàµÔÁŧº¹á¼§ ἧµ Í Ç§¨Ãã¹ÃÙ » à» ¹ ¡Òèí Ò Åͧ ÍÒ¨ µ Íǧ¨ÃÊÒÁÒö·íÒä´ Í ҧÊдǡ äÁ ᵡµ Ò §¨Ò¡¢Í§¨ÃÔ § ) â´ÂàÊ ¹ ÊÕ ´í Ò Ë¹Ò áÊ´§¡Òõ Ͷ֧¡Ñ¹¢Í§áµ ÅШشµ ͺ¹á¼§ ÃÙ» C ¡ÒÃàª×èÍÁµ ͧ͢ἧµ Íǧ¨Ã ÁÕÊÒµ Íǧ¨Ã¾Ò´ä»ÁÒ ¨¹äÁ ÁàÕ ¹×Íé ·Õè ÊíÒËÃѺµÔ´µÑ§é ÍØ»¡Ã³ à¾ÔÁè àµÔÁ µ Íǧ¨Ã àÁ×èÍàÊÕºÊÒÂŧº¹á¼§µ Íǧ¨Ã A B C D E

#

#

#

#

#

#

F G H I J

) *

+

,

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!%


AUXIO (äÁ 㪠㹠i-Stamp2P24) ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè AUXIO

à» ¹¤íÒÊѧè àÅ×Í¡ãË ·Òí §Ò¹¡Ñº¢Ò¾Íà µàÊÃÔÁ A0 ¶Ö§ A15 á·¹¢Ò¾Íà µÁҵðҹ P0 ¶Ö§ P15 (ãª ä´ ¡ºÑ BS2P40 áÅÐ i-Stamp2P ෠ҹѹé ) àÁ×Íè àÅ×͡㪠¤Òí ÊÑ§è ¹Õé àºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍà ¨Ðà»ÅÕÂè ¹¡ÒõԵµ ͡Ѻ¢Ò¾Íà µ»¡µÔ P0 ¶Ö§ P15 ä»Âѧ¢Ò¾Íà µàÊÃÔÁ A0 ¶Ö§ A15 á·¹ â´Âáµ ÅТҢͧ¾Íà µàÊÃÔÁ¹ÕÊé ÒÁÒö·íÒ§Ò¹ä´ àËÁ×͹¡Ñº¢Ò¾Íà µ Áҵðҹ·Ø¡Í ҧ ¨Ö§·íÒãË àÊÁ×͹¡ÑºÇ ÒÁÕ¾Íà µãª §Ò¹à¾ÔÁè ¢Ö¹é ¨Ò¡àºÊÔ¡áʵÁ» 2 »¡µÔ·ÁÕè Õ 16 ¢Òà» ¹ 32 ¢Ò ËÒ¡áµ µÍ §·íÒ§Ò¹ÊÅѺä»ÁÒâ´Â㪠¡ÒäǺ¤ØÁ¨Ò¡¤íÒÊѧè ෠ҹѹé àÁ×Íè µ ͧ¡ÒáÅѺ价íÒ§Ò¹¡Ñº¢Ò¾Íà µËÅÑ¡ P0 ¶Ö§ P15 ¡çÊÒÁÒö·íÒä´ â´Â㪠¤Òí Êѧè MAINIO ´Ñ§ÁÕµÇÑ Í ҧµ Í仹Õé HIGH 0 AUXIO LOW 0 ¨Ò¡â»Ãá¡ÃÁµÑÇÍ ҧ¹Õé 㹺Ã÷Ѵáá໠¹¡ÒáíÒ˹´ãË ¢Ò¾Íà µ 0 ÁÕÅͨԡ 1 «Ö§è »¡µÔàÁ×Íè àÃÔÁè µ ¹ ·íÒ§Ò¹»¡µÔ àºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍà ¨ÐµÔ´µ ͡Ѻ¢Ò¾Íà µÁҵðҹ P0 ¶Ö§ P15 à» ¹ËÅÑ¡ ´Ñ§¹Ñ¹é ¢Ò ¾Íà µ 0 㹤íÒÊÑ§è ¹Õ¨é §Ö à» ¹¡ÒÃÊ §Åͨԡ 1 ÍÍ¡ä»Âѧ¢Ò P0 㹺Ã÷Ѵµ ÍÁÒàÃÕ¡㪠¤Òí Êѧè AUXIO ¨Ð·íÒãË àºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍà à»ÅÕÂè ¹¡ÒõԴµ Íä»Âѧ¡ÅØÁ ¢Í§¢Ò¾Íà µàÊÃÔÁ A0 ¶Ö§ A15 ·Ñ¹·Õ «Ö§è ã¹ ºÃ÷Ѵ·ÕÊè ÒÁà» ¹¡ÒáíÒ˹´ãË Ê§ Åͨԡ 0 ÍÍ¡ä»Âѧ¢Ò¾Íà µ 0 ¹Ñ¹è ¤×Í·Õ¢è Ò A0 ¨ÐÁÕÅͨԡ 0 â´Â·Õ¢è Ò P0 ¡ç处 ¤§à» ¹Åͨԡ 1 ¤ Ò§ÍÂÙ áÅÐËÅѧ¨Ò¡¹Õ¡é ÒõԴµ Í¢Ò¾Íà µÂѧ¤§·íÒ§Ò¹ÍÂÙ· ¢Õè Ò¾Íà µàÊÃÔÁ ¨¹¡Ç Ò¨ÐÁÕ ¡ÒÃ㪠¤Òí Êѧè MAINIO ¨Ö§¨ÐÊÒÁÒö¡ÅѺ价íÒ§Ò¹¡Ñº¢Ò¾Íà µ»¡µÔä´ ´Ñ§¹Ñ¹é ´ ǤسÊÁºÑµ¾Ô àÔ Èɢͧ¤íÒÊÑ§è ¹Õ·é Òí ãË àºÊÔ¡áʵÁ» 2P ÁÕ¢Ò¾Íà µÁÒ¡¢Ö¹é ¡Ç Òà´ÔÁ¶Ö§ 2 à· Ò ÃÇÁ 32 ¢Ò Ê §¼ÅãË ¢Í ¨íÒ¡Ñ´´ Ò¹¨íҹǹ¾Íà µ¢Í§àºÊÔ¡áʵÁ» Ŵŧ ¹Í¡¨Ò¡¹Ñ¹é ·Õ¾è àÔ Èɤ×Í¢Ò¾Íà µàÊÃÔÁ·Õàè ¾ÔÁè ¢Öé¹ÁÒ¹Ñé¹ÊÒÁÒö·íÒ§Ò¹ä´ àËÁ×͹¡Ñº¢Ò¾Íà µËÅÑ¡·Ø¡»ÃСÒÃ

!&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


BRANCH ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè BRANCH Offset, [Label0, Label1, ...LabelN]

㪠¡ÃÐâ´´ä»ÂѧáÍ´à´ÃÊ·Õ¡è Òí ˹´µÒÁ¤ Ò offset (¤ Ò offset µ ͧÍÂÙã ¹ª ǧ·Õ¡è Òí ˹´áÍ´à´ÃÊ´ ÇÂ) Offset à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè 㪠¡Òí ˹´µíÒá˹ §·Õ¨è СÃÐⴴ仵ÒÁ·Õ¡è Òí ˹´ã¹ Label â´Âµ ͧÍÂÙã ¹ª ǧ 0-N Label à» ¹ª×Íè ÅÒàºÅ·Õãè ª ¡Òí ˹´µíÒá˹ §¢Í§áÍ´à´ÃÊ·Õ¨è СÃÐâ´´ä» ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè BRANCH ÊÒÁÒöáÊ´§´ ǵÑÇÍ ҧµ Í仹Õé

BRANCH B2, [Case_0, Case_1, Case_2]

ËÒ¡¤ Ңͧ B2 ෠ҡѺ 0 àºÊÔ¡áʵÁ» 2P ¨Ð¡ÃÐâ´´ä»ÂѧáÍ´à´ÃÊ·Õ¡è Òí ˹´´ ÇÂÅÒàºÅ Case_0 ËÒ¡ ¤ Ңͧ B2 ෠ҡѺ 1 àºÊÔ¡áʵÁ» 2P ¨Ð¡ÃÐâ´´ä»ÂѧáÍ´à´ÃÊ·Õ¡è Òí ˹´´ ÇÂÅÒàºÅ Case_1 áÅШСÃÐâ´´ä»Âѧ áÍ´à´ÃÊ·Õ¡è Òí ˹´´ ÇÂÅÒàºÅ Case_2 àÁ×Íè B2=2 ¶ Ò¤ Ò¢ ÍÁÙÅäÁ ÍÂÙ㠹 ҹ·Õ¡è Òí ˹´¤×ͤ ÒÃÕ¨ÊÔ àµÍà B2 ÁÒ¡¡Ç Ò 2 ¤íÒÊѧè BRANCH ¨ÐäÁ ·Òí ¡ÒÃã´æ áÅÐâ»Ãá¡ÃÁ¨Ð¡ÃзíÒ¤íÒÊÑ§è ¶Ñ´ä»ËÅѧ¨Ò¡¤íÒÊѧè BRANCH á·¹

¡Ò÷´Åͧ Í·Õè 1 ¡ÒÃ㪠¤Òí Êѧè BRANCH (1) µÔ´µÑ§é i-Stamp2P24 ŧº¹ºÍà ´ JX-2SX plus II áÅ Çàª×Íè Áµ ͡Ѻ¤ÍÁ¾ÔÇàµÍà ¨Ò¡¹Ñ¹é ¨ ÒÂä¿àÅÕÂé § (2) à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà à¢Õ¹â»Ãá¡ÃÁ·´Åͧµ Í仹Õé ****** PRELAB2p24-01.BSP : BRANCH command demonstration ****** ' {$STAMP BS2p} ' {$PBASIC 2.5} PICK VAR NIB ' ¡íÒ˹´µÑÇá»Ã PICK à» ¹áºº 4 ºÔµ ËÃ×Í ¹ÔºàºÔÅ FOR PICK = 0 to 3 ' ¡íÒ˹´¤ Ңͧ PICK à¾×Íè ãË Ç¹·íҧҹ໠¹ 0,1,2 áÅÐ 3 DEBUG "Pick= ",DEC PICK,CR ' áÊ´§¤ Ңͧ PICK ·ÕËè ¹ Òµ Ò§ Debug Terminal BRANCH PICK,[Zero,One,Two] ' Branch based on pick. DEBUG "Pick exceeded # of items",CR, in BRANCH list. Fell through! ,CR ' áÊ´§¢ ͤÇÒÁ·ÕËè ¹ Òµ Ò§ Debug Terminal NEXTPICK: NEXT ' àÅ×Íè ¹¤ Òµ Í仢ͧµÑÇá»Ã PICK STOP ZERO: ' àÁ×Íè PICK = 0 ãË ÁÒ·íÒ§Ò¹·Õ¹è Õè DEBUG "Branched to 'zero.'",CR,CR ' áÊ´§¢ ͤÇÒÁ·Õ¡è Òí ˹´äÇ ÊÒí ËÃѺâ»Ãá¡ÃÁ Í ZERO ·ÕËè ¹ Òµ Ò§ Debug Terminal GOTO NEXTPICK ' ÍÍ¡¨Ò¡â»Ãá¡ÃÁ Í ONE: ' àÁ×Íè PICK = 1 ãË ÁÒ·íÒ§Ò¹·Õ¹è Õè DEBUG "Branched to 'one.'",CR,CR ' áÊ´§¢ ͤÇÒÁ·Õ¡è Òí ˹´äÇ ÊÒí ËÃѺâ»Ãá¡ÃÁ Í ONE ·ÕËè ¹ Òµ Ò§ Debug Terminal GOTO NEXTPICK ' ÍÍ¡¨Ò¡â»Ãá¡ÃÁ Í TWO: ' àÁ×Íè PICK = 2 ãË ÁÒ·íÒ§Ò¹·Õ¹è Õè DEBUG "Branched to 'two.'",CR,CR ' áÊ´§¢ ͤÇÒÁ·Õ¡è Òí ˹´äÇ ÊÒí ËÃѺâ»Ãá¡ÃÁ Í TWO ·ÕËè ¹ Òµ Ò§ Debug Terminal GOTO NEXTPICK ' ÍÍ¡¨Ò¡â»Ãá¡ÃÁ ÍÂ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!'


(3) Ãѹâ»Ãá¡ÃÁ ¨Ðä´ ¼Å¡Ò÷íÒ§Ò¹µÒÁÃÙ»

àÁ×Íè PICK = 0 ¨ÐáÊ´§¢ ͤÇÒÁ Branch to zero àÁ×Íè PICK = 1 ¨ÐáÊ´§¢ ͤÇÒÁ Branch to one àÁ×Íè PICK = 2 ¨ÐáÊ´§¢ ͤÇÒÁ Branch to two àÁ×Íè PICK = 3 ¨ÐáÊ´§¢ ͤÇÒÁ Pick exceeded # of items áÅ Ç¢Ö¹é µ ¹ºÃ÷ѴãËÁ áÊ´§¢ ͤÇÒÁ in BRANCH list. Fell through!

"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


BUTTON ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè BUTTON Pin,Downstate,Delay,Rate,ByteVariable,TargetState,Address

à» ¹¤íÒÊѧè ÊíÒËÃÑºÍ Ò¹¤ ҢͧÊÇÔµª Í¹Ô ¾Øµ ÊÒÁÒö¡íÒ˹´ãË Á¡Õ Òû ͧ¡Ñ¹¡ÒáÃÐà¾×Íè ÁÍѹà¹×Íè §ÁÒ¨Ò¡¡Òà ¡´ÊÇÔµª ËÃ×Í¡ÒÃàºÒ« (bounce) â´Â¤íÒÊÑ§è ¹Õ¨é СíÒ˹´ãË àºÊÔ¡áʵÁ» 2P Êà ҧÊÑ­­Ò³¡Òá´ÊÇÔµª «Òéí (autorepeat) áÅСÃÐâ´´ä»ÂѧµíÒá˹ §·ÕÃè ÐºØ¶Ò »ØÁ ·Õ¡è ´¹Ñ¹é µÃ§¡Ñº¤ Ò·Õ¡è Òí ˹´äÇ ·Õè targetstate â´Âǧ¨ÃÊà ҧÊÑ­­Ò³ ¡Òá´¤Õ¹ ÊÕé ÒÁÒöãË áÍ¡µÕ¿ËÃ×Í·íÒ§Ò¹·ÕÅè ͨԡ 0 ËÃ×Í 1 ¡çä´ ¾ÒÃÒÁÔàµÍà Pin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò µÑ§é áµ 0 ¶Ö§ 15 à¾×Íè ¡íÒ˹´µíÒá˹ §¢Í§¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õµè Í §¡ÒÃ㪠§Ò¹ â´Â¢Ò·ÕÃè кع¨Õé ж١¡íÒ˹´ãË à» ¹¢ÒÍÔ¹¾Øµ Downstate à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò à· Ò¡Ñº 0 ËÃ×Í 1 㪠ÊÒí ËÃѺ¡íÒ˹´Ê¶Ò¹ÐÅͨԡàÁ×Íè ÊÇÔµª ¶Ù¡¡´ ¶ Òà» ¹ 0 ËÁÒ¤ÇÒÁÇ Ò ¨Ðà¡Ô´Åͨԡ 0 àÁ×Íè ÁÕ¡Òá´ÊÇÔµª ¶ Òà» ¹ 1 ËÁÒ¤ÇÒÁÇ Ò ¨Ðà¡Ô´Åͨԡ 1 ¢Öé¹·Õè¢Ò¾Íà µ·Õè¡íÒ˹´àÁ×èÍÁÕ¡Òá´ÊÇÔµª à¡Ô´¢Öé¹ ·Ñ駹Õéµ Í§¢Öé¹ÍÂÙ ¡Ñº¡ÒèѴǧ¨Ã·Ò§ÎÒà ´áÇà ¢Í§¡Òõ ÍÊÇÔµª ࢠҷÕè¢Ò ¾Íà µ¢Í§ i-Stamp2P24 ´Ñ§ÃÙ» +5V

+5V

S1

10k µ Í¢Ò¾Íà µ¢Í§ i-Stamp2P24

µ Í¢Ò¾Íà µ¢Í§ i-Stamp2P24

àÁ×Íè ¡´ÊÇÔµª ¨Ðà¡Ô´Åͨԡ "1" Ê §ä»Âѧ¢Ò¾Íà µ¢Í§ i-Stamp2P24

àÁ×Íè ¡´ÊÇÔµª ¨Ðà¡Ô´Åͨԡ "0" Ê §ä»Âѧ¢Ò¾Íà µ¢Í§ i-Stamp2P24

10k

Delay à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕèÁÕ¤ ÒµÑé§áµ 0 ¶Ö § 255 㪠¡íÒ˹´ÃÐÂÐË Ò§¢Í§ª ǧàÇÅÒ¡ ͹·Õè¨Ð Êà ҧÊÑ­­Ò³¡Òá´ÊÇÔµª «Òéí ˹ Ǥ×Í ÁÔÅÅÔÇ¹Ô Ò·Õ ¶ Ò¤ Ò delay ෠ҡѺ 0 ¨ÐäÁ Á¡Õ ÒÃá¡ Ê­ Ñ ­Ò³Ãº¡Ç¹ÍѹÁÒ¨Ò¡¡Òà ¡´ÊÇÔµª ËÃ×ÍäÁ à¡Ô´¡ÒôÕàºÒ« ¢¹Öé ¨ÐÁÕ¡ÒÃÊà ҧÊÑ­­Ò³¡Òá´ÊÇÔµª «Òéí ·Ñ¹·Õ ·íÒãË ¤Ò ·ÕÍè Ò ¹ä´ ÍÒ¨¼Ô´¾ÅÒ´ä´ ¶ Ò¤ Ò delay ෠ҡѺ 255 ¨ÐÁÕ¡ÒÃá¡ Ê­ Ñ ­Ò¹Ãº¡Ç¹¨Ò¡¡Òá´ÊÇÔµª áµ ¨ÐäÁ Á¡Õ ÒÃÊà ҧÊÑ­­Ò³¡Òá´ÊÇÔµª «Òéí Rate à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò µÑ§é áµ 0 ¶Ö§ 255 à¾×Íè 㪠¡Òí ˹´¨íҹǹ¢Í§Ç§Ãͺã¹ÃÐËÇ Ò§¡ÒÃÊà ҧ ÊÑ­­Ò³¡´ÊÇÔµª «éíÒ ByteVariable à» ¹µíÒá˹ §¾×¹é ·Õ·è Òí §Ò¹¢Í§¤íÒÊѧè BUTTON ¤ Ò¹Õ¨é е ͧ¡íÒ˹´ãË à» ¹ 0 ¡ ͹㪠¤Òí Êѧè BUTTON ¤Ãѧé áá TargetState à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕèÁÕ¤ Ò෠ҡѺ 0 ËÃ×Í 1 à¾×èÍ㪠¡íÒ˹´à§×è͹䢢ͧ¡Òá´ÊÇÔµª ¶ ÒÁÕ¤Ò à· Ò¡Ñº 0 ËÁÒ¶֧äÁ Á¡Õ Òá´ÊÇÔµª ¶ ÒÁÕ¤Ò à· Ò¡Ñº 1 ËÁÒ¶֧ÊÇÔµª ¶¡Ù ¡´ Address à» ¹ÅÒàºÅ·Õ¡è Òí ˹´µíÒá˹ §·Õâè »Ãá¡ÃÁ¨Ð¡ÃÐâ´´ä» ¶ Ò»ØÁ ·Õ¡è ´ÁÕ¤Ò µÃ§¡Ñº¤ Ò targetstate Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"


¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ÊÇÔµª ¡´µÔ´»Å Í´Ѻ·ÕÁè ãÕ ª §Ò¹·ÑÇè ä» àÁ×Íè ÁÕ¡Òá´ÊÇÔµª 1 ¤Ãѧé ÊÑ­­Ò³¾ÑÅÊ ·àÕè ¡Ô´¨Ò¡¡Òá´ÊÇÔµª ÁÁÕ Ò¡¡Ç Ò 1 ÅÙ¡ ´Ñ§¹Ñ¹é ¡ÒÃÍ Ò¹¤ Ò¨Ò¡¡Òá´ÊÇÔµª Í񬊫 ¤Ò ·Õ¼è ´Ô ¾ÅÒ´ÍÍ¡ÁÒ ´Ñ§ÃÙ» +5V R1 10k

S1

+5V

OUTPUT

+5V

R1 10k

S1

OUTPUT

R1 10k

S1

+5V

+5V

+5V

0V

0V

0V

ÊÑ­­Ò³Ãº¡Ç¹·Õàè ¡Ô´¢Ö¹é ¨Ò¡¡Òá´ÊÇÔµª

ÊÑ­­Ò³Ãº¡Ç¹·Õàè ¡Ô´¢Ö¹é ¨Ò¡¡ÒûŠÍÂÊÇÔµª

¤íÒÊѧè BUTTON ¨Ð·íÒ˹ Ò·Õàè ËÁ×͹¡Ñº¡Òá´¤Õº Íà ´·Õ¤è ÍÁ¾ÔÇàµÍà ¡Å ÒǤ×Í àÁ×Íè ÁÕ¡Òá´¤Õ¨ ÐÁÕµÇÑ ÍÑ¡ÉûÃÒ¡¯·ÕËè ¹ Ò¨Í ¶ ÒÁÕ¡Òá´¤Õ¤ Ò §äÇ àÇ ¹ÃÐÂÐ仪ÑÇè ¤ÃÙ µÑÇÍÑ¡ÉõÑÇà´ÔÁ¨Ð¾ÔÁ¾ «Òéí ÍÍ¡ÁÒáÊ´§·ÕËè ¹ Ò¨Í ¤íÒÊѧè BUTTON ¡çÊÒÁÒö¡íÒ˹´ãË ·Òí §Ò¹àª ¹¹Õäé ´ ¤íÒÊѧè BUTTON ¶Ù¡Í͡ẺÁÒãË ãª ã¹â»Ãá¡ÃÁÅÙ» 㹡ÒÃǹÅٻᵠÅФÃÑ§é ¤íÒÊѧè BUTTON ¨ÐµÃǨÊͺ ʶҹТͧ¢Ò·Õ¡è Òí ˹´ àÁ×Íè ¢Ò·Õµè ÃǨÊͺÁÕ¤Ò µÃ§¡Ñº¤ Ò downstate ¤íÒÊѧè BUTTON ¨Ð» ͧ¡Ñ¹¡ÒÃàºÒ« ¨Ò¡¡Òá´ ÊÇÔµª ¨Ò¡¹Ñ¹é ¶ ÒµÃǨÊ꼂 ÒÁÕ¡Òá´¤ÕÂá ¹ ¹Í¹ áÅСíÒ˹´¤ Ò targetstate äÇ à· Ò¡Ñº 1 â»Ãá¡ÃÁ¨Ð¡ÃÐâ´´ä»Âѧ µíÒá˹ §áÍ´à´ÃÊ·Õ¡è Òí ˹´äÇ áµ ¶Ò ¡íÒ˹´¤ Ò tagetstate ෠ҡѺ 0 â»Ãá¡ÃÁ¨Ð¡ÃзíÒ¤íÒÊÑ§è ¶Ñ´ä» ¶ ÒÊÇÔµª 处 ¤ ҧʶҹÐÍÂÙ· Õè downstate ¤íÒÊѧè BUTTON ¨Ð¹Ñº¨íҹǹ¡ÒÃǹÅÙ»¢Í§â»Ãá¡ÃÁ àÁ×Íè ¤ Ò¨íҹǹ ·Õ¹è ºÑ ෠ҡѺ¤ Ò delay ¤íÒÊѧè BUTTON ¨Ð¡Ãеع ¡Ò÷íÒ§Ò¹µÒÁ·ÕÃè кØäÇ ã¹ tagetstate áÅÐáÍ´à´ÃÊÍÕ¡¤ÃÑ§é ¹Ñ¹è ¤×Í ¨ÐáÊ´§¤ ҢͧÊÇÔµª ·¶Õè ¡Ù ¡´¹Ñ¹é «éÒí ÍÕ¡¤Ãѧé ËÅѧ¨Ò¡¹Õ¶é Ò ÊÇÔµª 处 ÍÂÙ· ÊÕè ÀÒÇÐ downstate ¤íÒÊѧè BUTTON ¨ÐµÃǨ Êͺ¤ Ò¨íҹǹ rate à¾×Íè ¡Ãеع ¡Ò÷íÒ§Ò¹ÍÕ¡¤ÃÑ§é ¨Ðà¡Ô´¡ÒÃáÊ´§¤ ҢͧÊÇÔµª µÇÑ ¹Ñ¹é Í ҧµ Íà¹×Íè §àËÁ×͹¡ÒäÕ ¤ Ò§º¹¤Õº Íà ´¢Í§¤ÍÁ¾ÔÇàµÍà ¨¹¡Ç ҨлŠÍÂÊÇÔµª áÅÐâ»Ãá¡ÃÁµÃǨÊͺ¾º

¡Ò÷´Åͧ Í·Õè 2 ¡ÒÃ㪠¤Òí Êѧè BUTTON (1) µÔ´µÑ§é i-Stamp2P24 ŧº¹ºÍà ´ JX-2SX plus II áÅ Çàª×Íè Áµ ͡Ѻ¤ÍÁ¾ÔÇàµÍà (2) µ Íǧ¨ÃµÒÁÃÙ»·Õè 3-1 (3) à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁ·´Åͧµ Í仹Õé

"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


+5V

10k P8

i-Stamp2P24

S1

ÃÙ»·Õè 3-1 ǧ¨Ã·´Åͧ¡ÒÃ㪠§Ò¹¤íÒÊѧè BUTTON áÅÐ COUNT '****** PRELAB2p24-02.BSP : BUTTON command demonstration ****** ' {$STAMP BS2p} ' {$PBASIC 2.5} BTNWK VAR BYTE BTNWK = 0 LOOP1: BUTTON 8,0,255,250,BTNWK,0,NO_PRESS ' µÃǨÊͺ¡Òá´ÊÇÔµª ·¢Õè Ò P8 ' ¶ ÒäÁ Á¡Õ Òá´ ¨Ð¡ÃÐâ´´ä»Âѧâ»Ãá¡ÃÁ Í NO_PRESS DEBUG "* " ' àÁ×Íè ¡´ÊÇÔµª ¢Ò P8 à» ¹ 0 ¨ÐÊ §à¤Ã×Íè §ËÁÒ´͡¨Ñ¹ä»áÊ´§ ' ·ÕËè ¹ Òµ Ò§ debug Terminal. NO_PRESS: GOTO LOOP ' ǹµÃǨÊͺ仵ÅÍ´

(4) ¨ ÒÂä¿àÅÕÂé §ãË Ç§¨Ã áÅ ÇÃѹâ»Ãá¡ÃÁ â´Â¡Òá´»ØÁ RUN ËÃ×Í¡´ Ctrl + R ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é (5) ·´Åͧ¡´ÊÇÔµª 1 ¤ÃÑ§é ¨ÐàËç¹à¤Ã×Íè §ËÁÒ´͡¨Ñ¹ * »ÃÒ¡¯¢Ö¹é ·ÕËè ¹ Òµ Ò§ Debug Terminal

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"!


(6) ·´Åͧ¡´ÊÇÔµª Í¡Õ 1 ¤ÃÑ§é ¨ÐàËç¹à¤Ã×Íè §ËÁÒ´͡¨Ñ¹ * à¾ÔÁè ¢Ö¹é ÁÒÍÕ¡ 1 µÑÇ·ÕËè ¹ Òµ Ò§ Debug Terminal

(7) ·´Åͧ¡´ÊÇÔµª Í¡Õ 20 ¤ÃÑ§é ¨ÐàËç¹à¤Ã×Íè §ËÁÒ´͡¨Ñ¹ * à¾ÔÁè ¢Ö¹é ÁÒÍÕ¡ 20 µÑÇ·ÕËè ¹ Òµ Ò§ Debug Terminal ÃÇÁ·Ñ§é ÊÔ¹é 22 µÑÇ

""

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


(8) ÍÍ¡¨Ò¡Ë¹ Òµ Ò§ Debug Terminal ÁÒÂѧ˹ Òµ Ò§àÍ´ÔàµÍà ·íÒ¡ÒÃá¡ ä¢â»Ãá¡ÃÁ·Õºè Ã÷Ѵ BUTTON 8,0,255,250,BTNWK,0,NO_PRESS à» ¹ BUTTON 8,0,100,250,BTNWK,0,NO_PRESS ¨Ò¡¹Ñ¹é ¡´»ØÁ RUN ËÃ×Í Ctrl+R (9) ·´Åͧ¡´ÊÇÔµª â´Â¡´à¾Õ§¤Ãѧé à´ÕÂÇ ¨ÐàËç¹à¤Ã×Íè §ËÁÒ´͡¨Ñ¹»ÃÒ¡¯¢Ö¹é áµ ÍÒ¨ÁÕÁÒ¡¡Ç ÒË¹Ö§è µÑÇ (¨Ò¡ÃÙ»»ÃÒ¡¯ 3 µÑÇ) ·Ñ§é ¹Õàé » ¹¼ÅÁÒ ¨Ò¡¡ÒÃÅ´¤ Ò DELAY ŧ áÅж Ò¡´ÊÇÔµª ¤Ò §¨Ð»ÃÒ¡¯à¤Ã×Íè §ËÁÒ´͡¨Ñ¹º¹Ë¹ Ò¨ÍÍ ҧµ Íà¹×Íè §¨¹¡Ç ҨР»Å ÍÂÊÇÔµª

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"#


CON ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè Id CON

Value

à» ¹¤íÒÊѧè à·ÕÂÁ㪠ÊÒí ËÃѺ¡íÒ˹´¤ Ò¤§·Õè (Value) ãË á¡ µÇÑ á»Ã (Id) ÁÑ¡»ÃÒ¡¯ÍÂÙã ¹Ê Ç¹ËÑǢͧâ»Ãá¡ÃÁ

¡Ò÷´Åͧ Í·Õè 3 ¡ÒÃ㪠¤Òí Êѧè CON '****** PRELAB2p24-03.BSP : CON command demonstration ****** ' {$STAMP BS2p} ' {$PBASIC 2.5} MAXCOUNT CON 100 FOR B1 = 0 to MAXCOUNT PAUSE 10 DEBUG DEC ? B1 NEXT

àÁ×Íè ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ¢ Ò§µ ¹¹Õé ¨Ð»ÃÒ¡¯Ë¹ Òµ Ò§ Debug Terminal ¢Ö¹é ¾Ã ÍÁ¡ÑºáÊ´§¤ Ңͧ B1 µÑ§é áµ 0 ¶Ö§ 100 à» ¹¡ÒÃáÊ´§ãË àËç¹Ç Ò ¤íÒÊѧè CON 㪠ÊÒí ËÃѺ¡íÒ˹´¤ Ò 100 ãË á¡ µÇÑ á»Ã MAXCOUNT

"$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


COUNT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè COUNT Pin, Period, Variable

㪠¹Ñº¨íҹǹÃͺËÃ×Íä«à¡ÔŢͧÊÑ­­Ò³ÍÔ¹¾Øµ·Õè¢Ò¾Íà µ¢Í§ i-Stamp2P24 µÒÁÃÐÂÐàÇÅÒ ·Õ¡è Òí ˹´â´ÂµÑÇá»Ã period «Ö§è ÁÕ˹ ÇÂà» ¹ 0.4 ÁÔÅÅÔÇ¹Ô Ò·Õ áÅÐà¡çº¤ Ò·Õ¹è ºÑ ä´ äÇ ã¹µÑÇá»Ã variable ¾ÒÃÒÁÔàµÍà Pin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò µÑ§é áµ 0 ¶Ö§ 15 à¾×Íè ¡íÒ˹´¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õãè ª §Ò¹ â´Â ¢Ò·ÕÃè кع¨Õé ж١¡íÒ˹´ãË à» ¹¢ÒÍÔ¹¾Øµ â´Â¡ÒÃà¢Õ¹Åͨԡ 0 ä»ÂѧºÔµ·Õ¡è Òí ˹´ÀÒÂã¹ÃÕ¨ÊÔ àµÍà DIRS Period à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò µÑ§é áµ 1 ¶Ö§ 65,535 ÁÕ˹ ÇÂà» ¹ 0.287 ÁÔÅÅÔÇ¹Ô Ò·Õà¾×Íè 㪠¡Òí ˹´ ª ǧàÇÅÒ㹡ÒùѺ ¹Ñ¹è ¤×Í ¶ Ò period = 10 ª ǧàÇÅÒ㹡ÒùѺ෠ҡѺ 10 x 0.287 = 2.87 ÁÔÅÅÔÇ¹Ô Ò·Õ Variable à» ¹¤ ÒµÑÇá»Ã·ÕÁè ªÕ ¹Ô´¢ ÍÁÙÅà» ¹áºº word 㪠à¾×Íè à¡çº¤ Ò¡ÒùѺ ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ¤íÒÊѧè COUNT ¨Ð¡íÒ˹´ãË ¢Ò·Õµè Í §¡ÒÃà» ¹ÍÔ¹¾Øµ ¨Ò¡¹Ñ¹é ¡íÒ˹´ÃÐÂÐàÇÅÒ㹡ÒùѺ ÁÕ˹ ÇÂà» ¹ 0.287 ÁÔÅÅÔÇ¹Ô Ò·Õ ËÃ×Í 287 äÁâ¤ÃÇÔ¹Ò·Õ áÅÐà¡çº¤ Ò·Õäè ´ ¨Ò¡¡ÒùѺäÇ ã¹µÑÇá»Ã·Õ¡è Òí ˹´ ǧÃͺ¢Í§¡ÒùѺ ¤×Íà¡Ô´¡ÒÃà»ÅÕÂè ¹Ê¶Ò¹Ð¨Ò¡Åͨԡ 1 à» ¹ 0 áÅÐà»ÅÕÂè ¹¡ÅѺÁÒà» ¹ 1 ËÃ×ͨҡÅͨԡ 0 à» ¹ 1 áÅ Ç¡ÅѺä»à» ¹Åͨԡ 0 ¡ÒùѺ¹ÕÊé ÒÁÒöµÍºÊ¹Í§¡ÒÃà»ÅÕÂè ¹á»Å§ä´ ·¤Õè ÇÒÁàÃçÇÊÙ§ÊØ´ 1.2 äÁâ¤ÃÇÔ¹Ò·Õ ã¹¡ÒùѺ 1 ǧÃͺ¨Ð»ÃСͺ仴 Ç¡ÒÃà»ÅÕÂè ¹á»Å§ 2 Ê Ç¹¤×Í ¨Ò¡Åͨԡ 0 à» ¹ 1 áÅШҡ Åͨԡ 1 à» ¹ 0 ´Ñ§¹Ñ¹é ¤íÒÊѧè COUNT ÊÒÁÒöµÍºÊ¹Í§µ ;ÑÅÊ Ã»Ù ÊÕàè ËÅÕÂè Á·ÕÁè ¤Õ ÒºàÇÅÒµèÒí Êش෠ҡѺ 2.4 äÁâ¤ÃÇÔ¹Ò·ÕËÃ×ͤÇÒÁ¶Õàè · ҡѺ 416.67kHz ÊíÒËÃѺÃÙ»¤Å×¹è ·Õäè Á 㪠¾ÅÑ Ê Ã»Ù ÊÕàè ËÅÕÂè Á¨ÑµÃØ ÊÑ (¤ Ò¤ÒºàÇÅÒª ǧºÇ¡ ¡Ñº¤ Ò¤ÒºàÇÅÒª ǧźÁÕ¤ ÒäÁ ෠ҡѹ) ¤ÒºàÇÅÒ·ÕèÊÑé¹·ÕèÊØ´¢Í§·Ñé§ÃÙ»¤Å×蹪 ǧºÇ¡áÅÐÃÙ»¤Å×蹪 ǧźµ ͧÁÕ¤ Ò ÁÒ¡¡Ç Ò 1.2 äÁâ¤ÃÇÔ¹Ò·Õ ¶ Ò¼Ùã ª §Ò¹·íÒ¡ÒùѺ¤ ÒÃÙ»¤Å×¹è ·ÕÁè ¡Õ ÒÃà»ÅÕÂè ¹á»Å§¢Í§ÊÑ­­Ò³Í ҧª Òæ ઠ¹ ÃÙ»¤Å×¹è 䫹 ¤ Ò·Õ¹è ºÑ ä´ ÍÒ¨ÁÕ¤Ò ÁÒ¡Ç Ò¤ Ò·Õ¤è ÇèÐà» ¹ à¹×Íè §¨Ò¡ÊÑ­­Ò³ÁÕʶҹзÕäè Á ÊÒÁÒö¡íÒ˹´ÃдѺÅÍ¨Ô¡ä´ Í ҧªÑ´à¨¹ (·Õáè ç´Ñ¹ »ÃÐÁÒ³ 1.5 V) ·íÒãË à¡Ô´¡ÒùѺ·Õ¼è ´Ô ¾ÅÒ´ ÊÒÁÒöᡠ»­ ËÒÅѡɳйÕäé ´ â´Â㪠äÍ«ÕªÁÔµµ ·ÃÔ¡à¡Íà ઠ¹ àºÍà 74HCT14 µ Í¡ ͹˹ Ò·Õ¨è м Ò¹ÊÑ­­Ò³à¢ ÒÁÒÂѧ¢Ò¾Íà µ¢Í§ i-Stamp2p24

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"%


¡Ò÷´Åͧ Í·Õè 4 ¡ÒÃ㪠¤Òí Êѧè COUNT (1) µÔ´µÑ§é i-Stamp2P24 ŧº¹ºÍà ´ JX-2SX plus II áÅ Çàª×Íè Áµ ͡Ѻ¤ÍÁ¾ÔÇàµÍà (2) µ Íǧ¨ÃµÒÁÃÙ»·Õè 3-1 (3) à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁ·´Åͧµ Í仹Õé '*****PRELAB2p24-04.BSP : COUNT command demonstration***** ' {$STAMP BS2P} ' {$PBASIC 2.5} CYCLES VAR Word ' Variable TO STORE counted cycles. LOOP1: DEBUG CYCLES,"How many times can you press the BUTTON in 1 second?",CR PAUSE 1000 DEBUG "Ready, set... " PAUSE 500 DEBUG "GO!",CR COUNT 8,2500,CYCLES DEBUG CR,"Your score: ", DEC CYCLES,CR PAUSE 3000 DEBUG "Press BUTTON TO go again." HOLD: IF IN8 = 1 THEN HOLD GOTO LOOP1

(4) ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ â´Â¡Òá´»ØÁ RUN ËÃ×Í¡´ Ctrl + R ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é ¾Ã ÍÁáÊ´§¢ ͤÇÒÁ How many times can you press the button in 1 second? µÒÁ´ Ç Ready, set . áÅÐ GO!

"&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


(5) ãË ¡´ÊÇÔµª ·µÕè Í ÍÂÙ¡ ºÑ P8 ãË ä´ ÁÒ¡¤ÃÑ§é ·ÕÊè ´Ø ÀÒÂã¹àÇÅÒ 1 ÇÔ¹Ò·Õ·¹Ñ ·Õ·àÕè Ë繤íÒÇ Ò GO! »ÃÒ¡¯¢Ö¹é ·ÕËè ¹ Ò¨Í ·ÕËè ¹ Òµ Ò§ Debug Terminal áÊ´§¢ ͤÇÒÁ Your score: à¾×Íè ᨠ§¨íҹǹ¤ÃÑ§é ¢Í§¡Òá´ÊÇÔµª ··Õè Òí ä´ ¨Ò¡¹Ñ¹é ·ÕËè ¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¢ ͤÇÒÁãË ¡´ÊÇÔµª «Òéí ÍÕ¡¤Ãѧé à¾×Íè àÃÔÁè µ ¹¡Ò÷íÒ§Ò¹ãËÁ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"'


DATA ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè Label DATA

Data_list

㪠¡íÒ˹´¾×¹é ·ÕËÃ×͢ͺࢵ¢Í§Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ·Õãè ª à» ¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅã¹ i-Stamp2P24 ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ·íÒ˹ Ò·Õè 2 Í ҧ¤×Í ãª à¡çº¢ ÍÁÙŢͧâ»Ãá¡ÃÁÀÒÉÒ¾ÕàºÊÔ¡·Õãè ª 㹡ÒÃÃѹ¢Í§ i-Stamp2P24 áÅзíÒ˹ Ò·Õàè » ¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÊíÒËÃѺà¡çº¢ ÍÁÙÅ (data) ·Õäè Á µÍ §¡ÒÃãË Ê­ Ù ËÒÂàÁ×Íè »Å´ä¿àÅÕÂé § «Ö§è µ Ò§¡Ñº ÃÕ¨ÊÔ àµÍà ËÃ×Í˹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅáÃÁ·Õ¨è ÐËÒÂä»ËÃ×Í¡ÅÒÂà» ¹Èٹ àÁ×Íè »Å´ä¿àÅÕÂé § ¾ÒÃÒÁÔàµÍà ¤íÒÊѧè DATA ÁÕÅ¡Ñ É³Ð¤Å ÒÂæ ¡Ñº¤íÒÊѧè CON ËÃ×Í VAR â´Â Label ¨Ðà» ¹ª×Íè ¢Í§µÑÇá»Ã Ê Ç¹ Data_list ¤×Í¢ ÍÁÙÅ·Õèµ Í§¡ÒáíÒ˹´Å§ã¹Ë¹ ǤÇÒÁ¨íÒÍÕÍÕ¾ÃÍÁ ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ â´Â»¡µÔ¾¹×é ·Õ¢è ͧ˹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍ¾Õ ÃÍÁ¨ÐàÃÔÁè ·Õáè Í´à´ÃÊ 0 áÅÐàÅ×Íè ¹¤ ÒáÍ´à´ÃÊ¢Ö¹é ¤Ãѧé ÅÐ 1 亵 àÁ×Íè ·Õ¡ÒÃà¢Õ¹ËÃ×Í¡íÒ˹´¢ ÍÁÙÅÅ§ä» áµ ¡Êç ÒÁÒöà¡çº¢ ÍÁÙÅä´ ¤ÃÒÇÅÐ 1 àÇÔô ËÃ×Í 16 ºÔµ ËÃ×Í 2 亵 ä´ â´Â¡ÒÃ㪠¤ÂÕ à ÇÔô ¾ÔàÈɤ×Í word ¹íÒ˹ Ò¢ ÍÁÙÅ Í ҧäáçµÒÁ¼Ùã ª §Ò¹ÊÒÁÒö¢ ÒÁáÍ´à´ÃÊä´ ´Ç  2 ÇÔ¸¡Õ Òä×Í ÇÔ¸·Õ Õè 1 㪠à¤Ã×Íè §ËÁÒ @ áŠǵÒÁ´ ÇÂáÍ´à´Ãʢͧ˹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍ¾Õ ÃÍÁ·Õµè Í §¡ÒõԴµ Í ËÃ×Í¡íÒ˹´¢Íºà¢µ¢ ÍÁÙÅ ´Ñ§µÑÇÍ ҧ

ACC100 DATA @100, $3F, $3F

à» ¹¡ÒáíÒ˹´ãË ÅÒàºÅ ACC100 á·¹¢ ÍÁÙÅã¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍÕ¾ÃÍÁ·ÕèáÍ´à´ÃÊ $100 áÅÐ $101 «Ö§è ÁÕ¢Í ÁÙÅ෠ҡѺ $3F ·Ñ§é 2 áÍ´à´ÃÊ ÇÔ¸Õ·Õè 2 㪠¡ÒáíÒ˹´¢ ÍÁÙÅ·Õàè ËÁ×͹¡Ñ¹Å§ã¹áÍ´à´Ãʢͧ˹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍ¾Õ ÃÍÁ㹤ÃÒÇ à´ÕÂÇËÅÒÂáÍ´à´Ãʵ Íà¹×Íè §¡Ñ¹ â´ÂÃÐºØ¢Í ÁÙÅ·Õµè Í §¡ÒÃáŠǵÒÁ´ ǨíҹǹáÍ´à´ÃÊ·Õµè Í §¡Òâ ÒÁã¹Ç§ àÅçºËÅѧ¢ ÍÁÙÅ ´Ñ§µÑÇÍ ҧ

BLANKS DATA (100)

à» ¹¡ÒÃàµÔÁ¢ ÍÁÙÅ Ç Ò§ ŧã¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍ¾Õ ÃÍÁ 100 áÍ´à´Ãʵ Íà¹×Íè §¡Ñ¹ Ê §¼ÅãË ÊÒÁÒö µÔ´µ ͡Ѻ˹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍ¾Õ ÃÍÁã¹ÍÕ¡ 100 µíÒá˹ §¶Ñ´ÁÒä´ àÁ×Íè ·íÒ¡ÒõÃǨÊͺ¢ ÍÁÙÅã¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕ ÍÕ¾ÃÍÁ â´ÂàÅ×Í¡·Õàè Á¹Ù RUN à Memory map ¢Í§â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ¨ÐàËç¹Ç ÒÁÕ¡ÒúÃÃ¨Ø¢Í ÁÙÅ $20 ŧã¹Ë¹ ǤÇÒÁ¨íÒ 100 µíÒá˹ § ´Ñ§ã¹ÃÙ»·Õè 3-2 à˵طàÕè » ¹¤ Ò $20 à¹×Íè §¨Ò¡ÃËÑÊáÍÊ¡Õ¢é ͧ¢ ÍÁÙÅÇ Ò§ËÃ×Í space ¨ÐÁÕ¤Ò à· Ò¡Ñº $20 áÅж ÒËÒ¡àÅ×Í¡ª ͧ Display ASCII ·Õ¾è ¹×é ·Õ¢è ͧ˹ ǤÇÒÁ¨íҨСÅÒÂà» ¹ª Í§Ç Ò§·Ñ¹·Õ

#

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


ÃÙ»·Õè 3-2 ˹ Òµ Ò§ Memory map ¢Í§Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁÀÒÂã¹ i-Stamp2P24 áÊ´§ãË àË繡ÒúÃÃ¨Ø ¢ ÍÁÙÅ $20 ŧã¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅ â´Â¡ÒÃ㪠¤Òí Êѧè DATA

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#


DEBUG ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè DEBUG OutputData{,OutputData...}

㪠㹡ÒÃáÊ´§¤ ÒµÑÇá»ÃáÅТ ͤÇÒÁº¹Ë¹ Ҩͧ͢¤ÍÁ¾ÔÇàµÍà ¾ÒÃÒÁÔàµÍà OutputData à» ¹Ê ǹ»ÃСͺ¢Í§¢ ͤÇÒÁ, µÑÇá»Ã, ¤ Ò¤§·Õè áÅеÑÇÍÑ¡ÉäǺ¤ØÁ ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ¤íÒÊÑè§ DEBUG à» ¹¤íÒÊÑ觷Õèª ÇÂÍíҹǤÇÒÁÊдǡ㹡ÒÃÊ §¢ ͤÇÒÁä»Âѧ¤ÍÁ¾ÔÇàµÍà ã¹ÃÐËÇ Ò§ ¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁ ·íÒãË ¼ãÙ ª §Ò¹ÊÒÁÒöàË繼šÒ÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁä´ ·¹Ñ ·Õ·¹Ñ ã´ Ê §¼ÅãË ÊÒÁÒöµÃǨ Ê꼂 Òâ»Ãá¡ÃÁ·Õàè ¢Õ¹¢Ö¹é ¹Õ·é Òí §Ò¹¶Ù¡µ ͧËÃ×ÍäÁ 㹡ÒÃà¢Õ¹â»Ãá¡ÃÁà¾×Íè Ê §¢ ͤÇÒÁä»Âѧ¤ÍÁ¾ÔÇàµÍà ¤ Ò·Õè ¹íÒÁÒáÊ´§¹Ñ¹é ¨ÐÁÕ·§Ñé ¤ ҢͧµÑÇá»Ã·Õäè ´ ¨Ò¡¡ÒûÃÐÁÇżŢͧ i-Stamp2P24 áÅТ ͤÇÒÁ·Õ¨è к͡¼Ùã ª §Ò¹Ç Ò ¢³Ð¹Õâé »Ãá¡ÃÁ·íÒ§Ò¹ä»¶Ö§Ê Ç¹ã´áÅ Ç µ ͧ¡ÒÃãË ¼ãÙ ª §Ò¹µÍºÊ¹Í§µ Í¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁÍ ҧäú Ò§ ÊÒÁÒö·´Êͺ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè DEBUG ´ Ç¡ÒÃà¢Õ¹â»Ãá¡ÃÁ§ ÒÂ æ ´Ñ§¹Õé '*********DebugExample01.bsp : Debug command example******************** ' {$STAMP BS2p} ' {$PBASIC 2.5} DEBUG "Hello world"

ËÅѧ¨Ò¡ÊÑè§Ãѹâ»Ãá¡ÃÁà¾×èÍ´Òǹ âËÅ´¤íÒÊÑ觹Õéä»ÊÙ i-Stamp2P24 ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é ÁҾà ÍÁ¡ÑºáÊ´§¢ ͤÇÒÁ Hello World! ´Ñ§ã¹ÃÙ»

#

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


µÑÇÍ ҧµ ÍÁÒà» ¹¡ÒáíÒ˹´ãË i-Stamp2P24 ·íÒ¡ÒÃá»Å§¤ Ò x ãË à» ¹àÅ¢°Ò¹ÊÔº ¨Ò¡¹Ñ¹é áÊ´§¤ Ò·Õè ˹ Òµ Ò§ Debug Terminal '*********DebugExample01.bsp : Debug command example******************** ' {$STAMP BS2p} ' {$PBASIC 2.5} X VAR Byte X = $30 DEBUG DEC? X ' áÊ´§¤ ҢͧµÑÇá»Ã X ã¹ÃÙ»¢Í§àÅ¢°Ò¹ÊÔº

àÁ×Íè ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ·ÕËè ¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§ x = 48 à¹×Íè §¨Ò¡¤ Ò $30 ã¹àÅ¢ °Ò¹ÊԺˡàÁ×Íè á»Å§à» ¹àÅ¢°Ò¹ÊÔº¨Ð෠ҡѺ 48 ´ Ç¡ÒÃ㪠à¤Ã×Íè §ËÁÒ ? à ÇÁ㹤íÒÊѧè DEBUG ¨Ðà» ¹ ¡ÒáíÒ˹´ãË áÊ´§µÑÇá»ÃáÅФ ҢͧµÑÇá»Ã·ÕËè ¹ Òµ Ò§ Debug Terminal ´ ÇÂ

(1) ¡ÒÃ㪠¤Òí Êѧè DEBUG ¡Ñº¡Òäíҹdz·Ò§¤³ÔµÈÒʵà µÑÇÍ ҧµ Í仹Õàé » ¹¡ÒÃ㪠¤Òí Êѧè DEBUG à¾×Íè áÊ´§¼Å¡Òäíҹdz˹ Òµ Ò§ Debug Terminal '*********DebugExample03.bsp : Debug command example******************** ' {$STAMP BS2p} ' {$PBASIC 2.5} X VAR Byte X = 65 DEBUG DEC ? 2*(x-1) ' áÊ´§¤ Òã¹ÃÙ»¢Í§àÅ¢°Ò¹ÊÔº¢Í§¡Òäíҹdz¤ Ò "2*(x-1) = "

àÁ×Íè Ãѹâ»Ãá¡ÃÁ i-Stamp2P24 ¨Ð¤íҹdz¤ Ңͧ X «Ö§è ¡ç¤Í× 65 ź´ Ç 1 ෠ҡѺ 64 áŠǤٳ´ Ç 2 ෠ҡѺ 128 ¼ÅÅѾ¸ ·»Õè ÃÒ¡¯º¹Ë¹ Òµ Ò§ Debug Terminal ¤×Í 2*(X-1) = 128

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#!


(2) ¡ÒÃ㪠¤Òí Êѧè DEBUG â´ÂäÁ ¡Òí ˹´ÃٻẺ¢ ÍÁÙÅàÍÒµ ¾µØ ¶ Ò㪠¤Òí Êѧè DEBUG â´ÂäÁ ÃкØû٠Ẻ ¤ Ò·Õäè ´ ¨Ðà» ¹ÃËÑÊáÍÊ¡Õé ´Ñ§¹Õé '*********DebugExample04.bsp : Debug command example******************** ' {$STAMP BS2p} ' {$PBASIC 2.5} X VAR Byte X = 65 DEBUG X ' áÊ´§¤ ҢͧµÑÇá»Ã X ã¹ÃÙ»¢Í§ÃËÑÊáÍÊ¡Õé

àÁ×Íè X = 65 à·Õº໠¹ÃËÑÊáÍÊ¡Õé ¨ÐËÁÒ¶֧µÑÇÍÑ¡Éà A ˹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§ A

¹Í¡¨Ò¡¹Õ¼é ãÙ ª §Ò¹ÊÒÁÒöáÊ´§ä´ ·§Ñé ¢ ͤÇÒÁáÅеÑÇá»Ãä´ ¾Ã ÍÁ æ ¡Ñ¹ â´Â¤Ñ¹è ´ ÇÂà¤Ã×Íè §ËÁÒ (,) ´Ñ§¹Õé '*********DebugExample05.bsp : Debug command example******************** ' {$STAMP BS2p} ' {$PBASIC 2.5} X VAR Byte X = 65 DEBUG "The ASCII code FOR A is: ", DEC X ' áÊ´§¢ ͤÇÒÁáÅФ Ңͧ X ã¹ÃÙ»¢Í§àÅ¢°Ò¹ÊÔº

àÁ×Íè ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ ·ÕËè ¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¢ ͤÇÒÁ The ASCII code for is: 65 â»Ãá¡ÃÁ¹Õ¨é Ðà» ¹¡ÒáíÒ˹´ãË áÊ´§ÃËÑÊáÍÊ¡Õ¢é ͧµÑÇÍÑ¡Éà A «Ö§è ¡ç¤Í× ¤ Ò 65 º¹Ë¹ Òµ Ò§ Debug Terminal

#"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¤íÒÊѧè DEBUG 1 ¤íÒÊѧè ÊÒÁÒöá·Ã¡¢ ͤÇÒÁä´ ËÅÒÂÃٻẺáÅÐã¹â»Ãá¡ÃÁÂѧÊÒÁÒöá·Ã¡¤íÒÊѧè DEBUG ä´ ËÅÒÂæ ¤íÒÊѧè ÍÕ¡´ Ç ¹Í¡¨Ò¡¹ÕÂé §Ñ ÁÕ¿§ ¡ ª¹Ñè ¾ÔàÈÉÀÒÂã¹ÍÕ¡ 14 ¿ §¡ ª¹Ñè «Ö§è á·¹´ ǵÑÇ ʹѧ¹Õé µÑÇÂ Í CLS HOME BELL BKSP TAB CR

¤ Ò 0 1 7 8 9 13

¼Å·Õàè ¡Ô´¢Ö¹é à¤ÅÕÂà ¨ÍÀÒ¾ ¡íÒ˹´ãË à¤Íà à«Íà ä»ÍÂÙ· ÁÕè ÁØ º¹´ Ò¹« Ò¢ͧ¨ÍÀÒ¾ËÃ×͵íÒá˹ § Home ¢ÑºàÊÕ§ÍÍ¡·Ò§ÅíÒ⾧¢Í§¤ÍÁ¾ÔÇàµÍà ·íÒãË à¡Ô´ª Í§Ç Ò§¾Ã ÍÁ¡Ñº¶ÍÂËÅѧ 1 µíÒá˹ § àÅ×Íè ¹µíÒá˹ §¢Í§à¤Íà à«Íà 令Ãѧé ÅÐ 8 µíÒá˹ §¢Í§µÑÇÍÑ¡Éà ¢Ö¹é ºÃ÷ѴãËÁ

CRSRXY

àÅ×Íè ¹µíÒá˹ §à¤Íà à«Íà ä»Âѧ¾Ô¡´Ñ X áÅÐ Y â´Â X ¤×;ԡ´Ñ á¹Ç¹Í¹ Ê Ç¹ Y ¤×;ԡ´Ñ ·Ò§á¹ÇµÑ§é ·Ñ§é X áÅÐ Y à» ¹¢ ÍÁÙÅ¢¹Ò´ 1 亵 CRSRLF àÅ×Íè ¹µíÒá˹ §¢Í§à¤Íà à«Íà 价ҧ« Ò CRSRRT àÅ×Íè ¹µíÒá˹ §¢Í§à¤Íà à«Íà 价ҧ« Ò CRSRUP àÅ×Íè ¹µíÒá˹ §¢Í§à¤Íà à«Íà ¢¹Öé 1 ºÃ÷Ѵ CRSRDN àÅ×Íè ¹µíÒá˹ §¢Í§à¤Íà à«Íà ŧ 1 ºÃ÷Ѵ LF Ê §ÃËÑÊàÅ×Íè ¹ºÃ÷Ѵ CLREOL à¤ÅÕÂà µÇÑ ÍÑ¡ÉÃáÅÐàÅ×Íè ¹à¤Íà à«Íà ä»ÂѧµíÒá˹ §ÊØ´· Ò¢ͧºÃ÷Ѵ » ¨¨Øº¹Ñ CLRDN à¤ÅÕÂà µÇÑ ÍÑ¡ÉèҡµíÒá˹ §» ¨¨Øº¹Ñ 仨¹¶Ö§ºÃ÷ѴÊØ´· ÒÂã¹Ë¹ Òµ Ò§¹Ñ¹é æ ¿ §¡ ª¹Ñè ¾ÔàÈÉàËÅ Ò¹ÕÊé ÒÁÒö¡íÒ˹´ãË ·Òí §Ò¹ËÃ×ÍäÁ ¨Ò¡Ë¹ Òµ Ò§ Debug function â´ÂࢠÒä»·Õàè Á¹Ù Edit àÅ×Í¡ Preference

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

##


µÑÇ¡íÒ˹´¡ÒÃà»ÅÕÂè ¹á»Å§ ¼Å¡ÒÃà»ÅÕÂè ¹á»Å§ áÊ´§ª×èͧ͢µÑÇá»Ã ("variablename = 'character'") ASC? µÒÁ´ Ç carriage return â´Â character µ ͧ໠¹¢ ÍÁÙÅ ÃËÑÊáÍÊ¡Õé DEC {1...5} SDEC {1...5} HEX {1...4} SHEX {1...4} IHEX {1...4}

áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊÔº ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-5) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊԺẺ¤Ô´à¤Ã×èͧËÁÒ ¶ ÒÁÕ¡Òà ¡íÒ˹´¤ ÒµÑÇàÅ¢ (1-5) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊԺˡ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊԺˡẺ¤Ô´à¤Ã×èͧËÁÒ ¶ ÒÁÕ¡Òà ¡íÒ˹´¤ ÒµÑÇàÅ¢ (1-5) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊԺˡâ´ÂáÊ´§ÊÑ­Åѡɳ ($)¹íÒ˹ Ò àª ¹ $37A à» ¹µ ¹ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· Ò ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§

ËÁÒÂà赯 1

1, 2 1 1, 2 1

ISHEX {1...4}

áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊԺˡẺ¤Ô´à¤Ã×èͧËÁÒÂâ´ÂáÊ´§ ÊÑ­Åѡɳ ($)¹íÒ˹ Ò ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§

1, 2

BIN {1...16}

áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹Êͧ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊͧẺ¤Ô´à¤Ã×èͧËÁÒ ¶ ÒÁÕ¡Òà ¡íÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹Êͧâ´ÂáÊ´§ÊÑ­Åѡɳ (%) ¹íÒ˹ Ò àª ¹ %10111000 à» ¹µ ¹ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§

1

SBIN {1...16} IBIN {1...16}

ISBIN {1...16}

áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊͧẺ¤Ô´à¤Ã×èͧËÁÒ â´ÂáÊ´§ ÊÑ­Åѡɳ (%) ¹íÒ˹ Ò ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§

STR bytearray STR bytearray\n REP bytearray\n

áÊ´§µÑÇÍÑ¡ÉÃáÍÊ¡Õé¨Ò¡ bytearray ¨¹¡ÃзÑè§äºµ ෠ҡѺ 0 áÊ´§µÑÇÍÑ¡ÉÃáÍÊ¡Õé¨íҹǹ n 亵 ¨Ò¡ bytearray áÊ´§µÑÇÍÑ¡ÉÃáÍÊ¡Õé¢Í§ byte ¨íҹǹ n ¤ÃÑé§ àª ¹ REP "X"/10 ¼ÅÅѾ¸ ·Õèä´ ¤×Í XXXXXXXXXX

1, 2 1, 2

1, 2

ËÁÒÂà赯 (1) ¡ÒáíÒ˹´¨íҹǹËÅÑ¡·ÕèáÊ´§ ઠ¹ DEC4 ¶ Ò¤ Ò·ÕèáÊ´§ÁÕäÁ ¶Ö§ 4 ËÅѡ˹ ҨͨÐáÊ´§àÅ¢ "0" ¹íÒ˹ Ò Â¡µÑÇÍ ҧ DEC4 65 ˹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§ 0065 ¶ Ò¤ ÒµÑÇàÅ¢ÁÕ¨íҹǹËÅÑ¡ÁÒ¡¡Ç Ò·Õè¡íÒ˹´ äÇ Ë¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¢ ÍÁÙŢͧËÅÑ¡´ Ò¹µíèÒà· Ò¹Ñé¹ àª ¹ DEC4 56422 ¤ Ò·ÕèáÊ´§·Õè˹ Òµ Ò§ Debug Terminal ¤×Í 6422 (2) ¡ÒáíÒ˹´¤ Òà¤Ã×èͧËÁÒ ¨Ð㪠¡¯·Ù¤ÍÁ¾ÅÕàÁ¹µ ¤ Ò¢ ÍÁÙŨе ͧÁÕ¢¹Ò´äÁ à¡Ô¹¤ ÒµÑÇá»Ã Word

µÒÃÒ§·Õè 3-3 áÊ´§ÃÒÂÅÐàÍÕ´¡ÒÃ㪠¿§ ¡ ª¹Ñè ¾ÔàÈɢͧ¤íÒÊѧè DEBUG à¾×Íè áÊ´§¼Åã¹ÃٻẺµ Ò§æ #$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


µÑÇÍ ҧ¡ÒÃ㪠¿§ ¡ ª¹Ñè ¾ÔàÈÉ CR ÀÒÂ㹤íÒÊѧè DEBUG ÁÕ´§Ñ ¹Õé '*********DebugExample06.bsp : Debug command example******************** ' {$STAMP BS2p} ' {$PBASIC 2.5} DEBUG "A carriage RETURN",CR DEBUG "starts a new line"

àÁ×Íè ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debig Terminal ¨ÐáÊ´§¢ ͤÇÒÁ A carriage return ¨Ò¡¹Ñ¹é ¨Ð¢Ö¹é ºÃ÷ѴãËÁ áÅ ÇáÊ´§¢ ͤÇÒÁ starts a new line ¡ÒÃ¢Ö¹é ºÃ÷ѴãËÁ à» ¹¼Å¨Ò¡¿ §¡ ª¹Ñè CR

¹Í¡¨Ò¡¹Ñ¹é ¤íÒÊѧè DEBUG ÊÒÁÒöáÊ´§¼Åä´ ËÅÒÂÃٻẺ ´Ñ§áÊ´§ÃÒÂÅÐàÍÕ´㹵ÒÃÒ§·Õè 3-3 (3) ¡ÒÃ㪠¤Òí Êѧè DEBUG 㹡ÒÃáÊ´§¢ ÍÁÙŢͧàÅ¢°Ò¹Êͧ àÁ×Íè ÁÕ¡ÒÃàÃÕ¡㪠¤Òí Êѧè DEBUG ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é à¾×Íè áÊ´§¢ ÍÁÙÅ·Õàè ºÊÔ¡áʵÁ» 2P Ê §¡ÅѺä»Âѧ¤ÍÁ¾ÔÇàµÍà «Ö§è ÃٻẺ¡ÒÃáÊ´§¢ ÍÁÙŢͧ¤íÒÊѧè DEBUG ÁÕËÅÒÂÃٻẺ ÊÒÁÒöÊÃØ»ä´ ´Ç  µÑÇÍ ҧµ Í仹Õé (àÁ×Íè à¢Õ¹â»Ãá¡ÃÁã¹áµ ÅеÑÇÍ ҧàÊÃç¨áÅ Ç Ãѹâ»Ãá¡ÃÁ´ Ç¡ÒûØÁ RUN ËÃ×Í CTRL+R) µÑÇÍ ҧ·Õè 1 DEBUG ? 65 IN5 à» ¹¡ÒÃáÊ´§¢ ÍÁÙŢͧ IN5 ã¹ÃÙ»¢Í§àÅ¢°Ò¹ÊÔº ¡ÒÃáÊ´§¼Å : IN5=0

µÑÇÍ ҧ·Õè 2

DEBUG 65 áÊ´§ÃËÑÊáÍÊ¡Õ¢é ͧµÑÇÍÑ¡É÷ÕÁè ¤Õ Ò ¢ ÍÁÙÅ෠ҡѺ 65 «Ö§è ¡ç¤Í× µÑÇÍÑ¡Éà A ¡ÒÃáÊ´§¼Å : A

µÑÇÍ ҧ·Õè 3

X VAR BYTE x = 66 DEBUG x áÊ´§ÃËÑÊáÍÊ¡Õ¢é ͧµÑÇá»Ã x ·ÕÁè ¤Õ Ò ¢ ÍÁÙÅ 66 «Ö§è ¡ç¤Í× µÑÇÍÑ¡Éà B ¡ÒÃáÊ´§¼Å : B

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#%


µÑÇÍ ҧ·Õè 4 DEBUG DEC 65 áÊ´§àÅ¢ 65 °Ò¹ÊÔº DEBUG IBIN8 66 áÊ´§àÅ¢ 66 ã¹ÃÙ»¢Í§àÅ¢°Ò¹Êͧ¢¹Ò´ 8 ºÔµ ¡ÒÃáÊ´§¼Å : 65%01000010 µÑÇÍ ҧ·Õè 5 DEBUG HELLO áÊ´§µÑÇÍÑ¡Éà ¡ÒÃáÊ´§¼Å : HELLO µÑÇÍ ҧ·Õè 6 DEBUG The ASCII character 67 is ,67,CR, And 67 in binary is ,IBIN8 67,CR à» ¹¡ÒÃáÊ´§¼Å â´ÂÁÕ¡ÒÃ¢Ö¹é ºÃ÷ѴãËÁ ËÅѧ¨º¢ ͤÇÒÁË¹Ö§è ªØ´ à» ¹µÑÇÍ ҧ¢Í§¡ÒÃ㪠»ÃÐ⪹ ¨Ò¡¤íÒÊѧè CR ËÃ×Í Carriage Return à¾×Íè ¡íÒ˹´ãË à¡Ô´¡ÒÃ¢Ö¹é ºÃ÷ѴãËÁ ÊÒí ËÃѺ¡ÒÃáÊ´§¢ ͤÇÒÁ㹡ÅØÁ ¶Ñ´ä» ¡ÒÃáÊ´§¼Å : The ASCII character 67 is C And 67 in binary is %01000010 (4) ¢ ÍÁÙŷҧ෤¹Ô¤¢Í§¤íÒÊѧè DEBUG DEBUG à» ¹¤íÒÊÑ§è ¾ÔàÈÉÃÙ»áººË¹Ö§è ¢Í§¤íÒÊѧè SEROUT â´ÂÁÕû٠Ẻ¡ÒÃÊ §¢ ÍÁÙÅ͹ءÃÁ¼ Ò¹¢Ò SOUT ¢Í§ i-Stamp2P24 ¤×Í ¡íÒ˹´ÍѵÃҺʹ (baud rate) ËÃ×ÍÍѵÃÒàÃçÇ㹡Òö Ò·ʹ¢ ÍÁÙÅẺ͹ءÃÁ෠ҡѺ 9,600 ºÔµµ ÍÇÔ¹Ò·Õ äÁ ÁºÕ µÔ ¾ÒÃÔµÕé (parity bit) ËÃ×ͺԵµÃǨÊͺ ¢¹Ò´¢Í§¢ ÍÁÙÅ (data) ෠ҡѺ 8 ºÔµ áÅÐÁÕºµÔ » ´· Ò (STOP bit) 1 ºÔµ ¹Í¡¨Ò¡¨Ð㪠â»Ãá¡ÃÁ Stampw «Ö§è ¡ç¤Í× àºÊÔ¡áʵÁ» àÍ´ÔàµÍà (BASIC Stamp editor for Windows) Í Ò¹¤ ÒáÅ Ç ÂѧÊÒÁÒö㪠â»Ãá¡ÃÁ»ÃÐàÀ·Ê×Íè ÊÒâ ÍÁÙÅËÃ×ÍàÃÕÂ¡Ç Ò à·Íà Á¹Ô ÍÅ (terminal) â»Ãá¡ÃÁ ã´¡çä´ ã¹¡ÒÃÍ Ò¹¢ ÍÁÙŨҡ i-Stamp2P24 à¾Õ§¡íÒ˹´¤ Ò¾ÒÃÒÁÔàµÍà µ Ò§æ ãË µÃ§¡Ñ¹ ¨Ò¡¹Ñé¹·íÒ¡Òà »Å´ÊÒ·Õàè ª×Íè Áµ Í¢Ò 3 ¢Í§ i-Stamp2P24 «Ö§è µ ÍÍÂÙ¡ ºÑ ¢Ò DTR (¢Ò 4 㹡óÕ㪠¤Í¹à¹ç¡àµÍà Ẻ DB-9) ¢Í§¾Íà µ ͹ءÃÁÍÍ¡ ¡ç¨ÐÊÒÁÒÃ¶Í Ò¹¤ Ò¨Ò¡ i-Stamp2P24 ä´ à¾Õ§Í ҧà´ÕÂÇ äÁ ÊÒÁÒö´Òǹ âËÅ´â»Ãá¡ÃÁµÑÇãËÁ ¨Ò¡ ¤ÍÁ¾ÔÇàµÍÃ ä´ ·Ñ§é ¹Õàé ¹×Íè §¨Ò¡¢Ò DTR ¢Í§¾Íà µÍ¹Ø¡ÃÁ·Õ»è Å´ÍÍ¡¹Ñ¹é ¶Ù¡ãª 㹡ÒÃÃÕ૵ÊíÒËÃѺ¡ÒÃâ»Ãá¡ÃÁ ¹Ñ¹è ËÁÒ¤ÇÒÁÇ Ò ËÒ¡µ ͧ¡ÒÃÃÑ¡ÉÒ¢ ÍÁÙÅã¹ i-Stamp2P24 äÇ ÊÒÁÒö·íÒä´ â´Â¡ÒûŴ¢Ò 3 ¢Í§ i-Stamp2P24 ÍÍ¡ àÁ×Íè ã´·Õµè Í §¡ÒÃà¢Õ¹¢ ÍÁÙÅËÃ×Í´Òǹ âËÅ´â»Ãá¡ÃÁãËÁ ¨§Ö ¤ ͵ Í¢Ò¹Õàé ¢ ҡѺ¢Ò DTR ¢Í§¾Íà µÍ¹Ø¡ÃÁ ´ ÇÂÇÔ¸¡Õ Òùըé ÐÁÕ»ÃÐ⪹ Í ҧÁÒ¡àÁ×Íè 㪠§Ò¹ i-Stamp2P24 㹡ÒÃÊ×Íè ÊÒâ ÍÁÙšѺ¤ÍÁ¾ÔÇàµÍà à¹×Íè §¨Ò¡ã¹ÃÐËÇ Ò§ ¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅ¹Ñ¹é ¢Ò DTR ¢Í§¾Íà µÍ¹Ø¡ÃÁÍÒ¨ÁÕâÍ¡ÒÊáÍ¡µÕ¿à» ¹Åͨԡ 1 ËÒ¡äÁ Á¡Õ ÒûŴ¢Ò¹ÕÍé Í¡¨Ò¡ i-Stamp2P24 ¨Ð·íÒãË i-Stamp2P24 à¡Ô´¡ÒÃÃÕ૵ áÅзíÒãË ¢Í ÁÙÅÀÒÂã¹Ë¹ ǤÇÒÁ¨íÒâ»Ãá¡ÃÁàÊÕÂËÒ àÁ×Íè »Å´¢Ò DTR ÍÍ¡¨Ò¡ i-Stamp2P24 ¨Ð·íÒãË ÊÒÁÒö㪠§Ò¹ i-Stamp2P24 㹡ÒÃÊ×Íè ÊÒâ ÍÁÙÅä´ Í ҧÊÁºÙó â´ÂäÁ µ ͧ¡Ñ§ÇÅÇ Ò¢ ÍÁÙÅã¹Ë¹ ǤÇÒÁ¨íÒâ»Ãá¡ÃÁ¢Í§ i-Stamp2P24 ¨ÐÊÙ­ËÒÂËÃ×Ͷ١ࢠҶ֧¨¹·íÒãË à¡Ô´¤ÇÒÁàÊÕÂËÒÂ

#&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ Í·Õè 5 ¡ÒÃ㪠¤Òí Êѧè DEBUG à¾×Íè áÊ´§µÑÇÍÑ¡ÉÃáÅеÑÇàÅ¢ (1) à¢Õ¹â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé '*****PRELAB05.BSP : DEBUG command demonstration***** ' {$STAMP BS2p} LETTER VAR BYTE PAUSE 10 DEBUG "ALPHABET -> ASCII CHART",BELL,CR,CR FOR LETTER = "A" to "Z" DEBUG "Character: ",LETTER,TAB, ASCII code: ",DEC LETTER,CR PAUSE 200 NEXT

(2) ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ â´Â¡Òá´»ØÁ RUN ËÃ×Í¡´ Ctrl + R ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é ¾Ã ÍÁáÊ´§¢ ÍÁÙÅÃËÑÊáÍÊ¡Õ¢é ͧµÑÇÍÑ¡ÉÃÀÒÉÒÍѧ¡ÄɵÑǾÔÁ¾ ãË­ àÃÕ§µÒÁÅíҴѺµÑ§é áµ A ¶Ö§ Z â´Â¨ÐáÊ´§ºÃ÷ѴÅÐË¹Ö§è ¢ ÍÁÙÅ ÃÇÁ 26 ºÃ÷Ѵ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#'


DEBUGIN ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè DEBUGIN InputData{,InputData...}

ãª ÃºÑ ¢ ÍÁÙż Ò¹·Ò§Ë¹ Òµ Ò§ Debug Terminal ¾ÒÃÒÁÔàµÍà InputData à» ¹Ê ǹ»ÃСͺ¢Í§¢ ͤÇÒÁ, µÑÇá»Ã, ¤ Ò¤§·Õè áÅеÑÇÍÑ¡ÉäǺ¤ØÁ ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ à» ¹¤íÒÊѧè ÃѺ¢ ÍÁÙÅࢠҾÍà µÍ¹Ø¡ÃÁ¼ Ò¹·Ò§Ë¹ Òµ Ò§ Debug Terminal â´Â㪠¢Ò¾Íà µ 16 ¢Í§àºÊÔ¡ áʵÁ» 2 à» ¹·Ò§¼ Ò¹¢Í§¢ ÍÁÙÅ ÁÕ굄 ÃÒàÃçÇ㹡Òö Ò·ʹ¢ ÍÁÙÅ 9,600 ºÔµµ ÍÇÔ¹Ò·Õ ÃٻẺ¢Í§¢ ÍÁÙÅ·Õãè ª à ÇÁ¡Ñº¤íÒÊÑ§è ¹Õ¨é ÐàËÁ×͹¡Ñº·Õãè ª 㹤íÒÊѧè DEBUG, SERIN áÅÐ SEROUT

¡Ò÷´Åͧ Í·Õè 6 ¡ÒÃ㪠¤Òí Êѧè DEBUGIN à¾×Íè ÃѺ¤ ÒµÑÇàÅ¢ (1) à¢Õ¹â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé '*****PRELAB2p24-06.BSP : DEBUGIN command demonstration***** ' {$STAMP BS2P} ' {$PBASIC 2.5} HOURS VAR Byte Get_Hours: DEBUG HOME, "Enter hours: ", CLREOL DEBUGIN DEC HOURS IF (HOURS > 23) THEN Get_Hours

(2) ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ â´Â¡Òá´»ØÁ RUN ËÃ×Í¡´ Ctrl + R ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é ¾Ã ÍÁáÊ´§¢ ͤÇÒÁ Entrer Hours : ·´Åͧ» ͹¤ Ò 26

$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


â»Ãá¡ÃÁ¨ÐµÃǨÊͺ¤ Ò áŠǾºÇ ÒÁÒ¡¡Ç Ò 23 ·íÒãË Ë¹ Òµ Ò§ Debug Terminal ¡ÅѺÁÒáÊ´§¢ ͤÇÒÁ Entrer Hours :

¨Ò¡¹Ñ¹é ·´Åͧ» ͹¤ Ò 22 ·Õªè Í §» ͹¤ Ңͧ˹ Òµ Ò§ Debug Terminal

â»Ãá¡ÃÁ¨ÐµÃǨÊͺ¤ ÒÍÕ¡¤Ãѧé áŠǾºÇ Ò äÁ à¡Ô¹ 23 ·íÒãË Ë¹ Òµ Ò§ Debug Terminal áÊ´§¢ ͤÇÒÁ Entrer Hours : 22 áÅ ÇËÂØ´·íÒ§Ò¹

¨Ò¡â»Ãá¡ÃÁ¢ Ò§µ ¹ ¤íÒÊѧè DEBUGIN ¨Ð¶Ù¡ãª ÃºÑ ¢ ÍÁÙÅÁÒà¡çºäÇ ã¹µÑÇá»Ã HOURS ¨Ò¡¹Ñ¹é ·íÒ¡ÒõÃǨ ÊÍºÇ Ò ¤ Ңͧ HOURS ·ÕÃè ºÑ ä´ ÁÒ¡¡Ç Ò 23 ËÃ×ÍäÁ ¶ Ò㪠ãË ¡ÃÐâ´´ä»ÂѧÅÒàºÅ Get_Hours à¾×Íè àÃÔÁè ·íÒ§Ò¹ãËÁ ÍÕ¡¤Ãѧé

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$


DO...LOOP ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè DO { WHILE | UNTIL condition(s) } statement(s) LOOP { UNTIL | WHILE condition(s) }

à» ¹¤íÒÊÑ§è ¡íÒ˹´ãË àºÊÔ¡áʵÁ» ·Òí §Ò¹Ç¹ÅÙ»ÀÒÂãµ à§×Íè ¹ä¢·Õ¡è Òí ˹´ ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ¤íÒÊÑ§è ¹Õàé » ¹¤íÒÊÑ§è ¾ÔàÈÉ·Õãè ª 㹡ÒáíÒ˹´à§×Íè ¹ä¢ã¹¡Ò÷íҧҹẺǹÅÙ» «Ö§è ÁÕ´Ç Â¡Ñ¹ 2 ÅѡɳФ×Í 1. ·íҧҹ仡 ͹ áŠǵÃǨÊͺà§×Íè ¹ä¢Ç Òà» ¹¨ÃÔ§ËÃ×ÍäÁ àÁ×Íè à§×Íè ¹ä¢à» ¹¨ÃÔ§ ¨Ö§ÊÒÁÒöÍÍ¡ ¨Ò¡ÅÙ»¢Í§â»Ãá¡ÃÁä´ (DO...LOOP UNTIL) 2. µÃǨÊͺà§×Íè ¹ä¢¡ ͹áŠǨ֧·íÒ§Ò¹ (DO WHILE...LOOP) ¤íÒÊÑ§è ¹ÕÊé ÒÁÒöÃͧÃѺ¡ÒõÃǨÊͺà§×Íè ¹ä¢ä´ ÁÒ¡¶Ö§ 16 à§×Íè ¹ä¢ µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ #1 DO

TOGGLE AlarmPin PAUSE 100 LOOP DO WHILE (StatusPin = Okay) StatusLED = IsOn PAUSE 100 LOOP

¨Ò¡â»Ãá¡ÃÁµÑÇÍ ҧ Ạ§à» ¹ 2 Ê Ç¹¤×Í Ê Ç¹áá໠¹â»Ãá¡ÃÁÅٻẺ·íҧҹǹäÁ ʹÔé ÊØ´ äÁ Á·Õ Ò§ÍÍ¡¨Ò¡ â»Ãá¡ÃÁä´ ¨¹¡Ç Ò¨Ðà¡Ô´¡ÒÃÃÕ૵ Ê Ç¹ã¹â»Ãá¡ÃÁÊ Ç¹·ÕÊè ͧ àÃÔÁè µ ¹´ ǤíÒÊѧè DO WHILE (StatusPin = Okay) Íѹ໠¹¡ÒáíÒ˹´ãË µÃǨÊͺ¡ Í¹Ç Òà§×Íè ¹ä¢·Õè StatusPin à» ¹¨ÃÔ§ËÃ×ÍäÁ ¶ Òà» ¹¨ÃÔ§ ¨Ö§àÃÔÁè ·íÒ§Ò¹ áÅ Çǹ¡ÅѺÁÒ µÃǨÊͺ àÁ×Íè ¼Å¡ÒõÃǨÊͺäÁ à» ¹¨ÃÔ§ àºÊÔ¡áʵÁ» ¡¨ç ÐÍÍ¡¨Ò¡â»Ãá¡ÃÁÅÙ»¹Õäé »ä´ µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ #2 DO

AlarmLED = IsOn PAUSE 1000 LOOP UNTIL (OvenTemp < ResetThreshold)

Ê Ç¹ã¹â»Ãá¡ÃÁµÑÇÍ ҧ¹Õé ¨ÐàÃÔèÁµ ¹·íÒ§Ò¹¡ ͹ ¨Ò¡¹Ñ鹨֧µÃǨÊͺà§×è͹䢷Õè¤íÒÊÑè§ LOOP UNTIL (OvenTemp < ResetThreshold) â´Ââ»Ãá¡ÃÁ¨ÐǹÅÙ»µ Í件 Ò¤ Ңͧ OverTemp Âѧ¹ ÍÂ¡Ç Ò ResetThreshold ´ Ç¡ÒÃ㪠¤Òí Êѧè DO...LOOP ª ÇÂÅ´¢Ñ¹é µÍ¹ã¹¡ÒÃà¢Õ¹â»Ãá¡ÃÁµÃǨÊͺà§×Íè ¹ä¢¢Í§¡ÒÃǹÅٻŧ ä´ Í ҧÁÒ¡ Ê §¼ÅãË ¡Ò÷íÒ§Ò¹ÃÇ´àÃçÇ¢Ö¹é

$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


DTMFOUT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè DTMFOUT Pin,{Ontime,Offtime,}{,Tone...}

à» ¹¤íÒÊÑè§ÊíÒËÃѺÊà ҧÊÑ­­Ò³ÊͧⷹËÅÒ¤ÇÒÁ¶ÕèËÃ×Í DTMF (dual-tone multi-frequency) «Ö§è à» ¹ÊÑ­­Ò³àÊÕ§¡Òá´»ØÁ ¢Í§à¤Ã×Íè §â·ÃÈѾ· ÊÁÑÂãËÁ ËÃ×ÍÃкºâ·¹ ¾ÒÃÒÁÔàµÍà Pin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¢ ÍÁÙÅÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 15 㪠㹡ÒÃÃкآҷÕãè ª §Ò¹ â´Â¢Ò¹Õ¨é ж١¡íÒ˹´ãË ·íҧҹ໠¹¢ÒàÍÒµ ¾ØµªÑèǤÃÒÇà¾×èÍÊ §ÊÑ­­Ò³ DTMF ËÅѧ¨Ò¡¡ÒÃÊà ҧÊÑ­­Ò³ DTMF àÃÕºà ÍÂáÅ Ç ¢Ò¹Õé ¨Ð¶Ù¡à»ÅÕÂè ¹¡ÅѺãË à» ¹¢ÒÍÔ¹¾Øµ·Ñ¹·Õ áÁ ÇÒ ¡ ͹˹ Ò¹Ñ¹é ¨Ð¡íÒ˹´äÇ ãË à» ¹¢ÒàÍÒµ ¾µØ ¡çµÒÁ Ontime 㪠㹡ÒáíÒ˹´ÃÐÂÐàÇÅÒÊà ҧÊÑ­­Ò³ DTMF ÁÕ˹ ÇÂà» ¹ 0.265 ÁÔÅÅÔÇ¹Ô Ò·Õ ÊÒÁÒö¡íÒ˹´ ¤ Òä´ µ§Ñé áµ 0-65,535 ¤ Òâ´Â»¡µÔ¨ÐÍÂÙ· Õè 750 «Ö§è ෠ҡѺÃÐÂÐàÇÅÒ»ÃÐÁÒ³ 200 ÁÔÅÅÔÇ¹Ô Ò·Õ Offtime 㪠¡Òí ˹´ª ǧàÇÅÒËÂØ´ËÅѧ¨Ò¡¡ÒÃÊà ҧÊÑ­­Ò³ DTMF áÅ Ç ÁÕ˹ ÇÂà» ¹ 0.265 ÁÔÅÅÔÇ¹Ô Ò·Õ ÊÒÁÒö¡íÒ˹´¤ Òä´ µ§Ñé áµ 0-65,535 ¤ Òâ´Â»¡µÔ¨ÐÍÂÙ· Õè 188 «Ö§è ෠ҡѺÃÐÂÐàÇÅÒ»ÃÐÁÒ³ 50 ÁÔÅÅÔÇ¹Ô Ò·Õ Tone à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò µÑ§é áµ 0-15 㪠ÊÒí ËÃѺ¡íÒ˹´¤ Òâ·¹¢Í§ÊÑ­­Ò³ DTMF ·Õ¨è ÐÊ § ÍÍ¡ä» â´Â¤ Ò 0 ¶Ö§ 11 ¨Ð¡íÒ˹´ãË Ê­ Ñ ­Ò³àÊÕ§·ÕÊè § ÍÍ¡ä»¹Ñ¹é µÃ§¡Ñº»ØÁ â·ÃÈѾ· Áҵðҹ ¹Ñ¹è ¤×ͤ Ò 0 ¶Ö§ 9 ¤×Í»ØÁ àÅ¢ 0 ¶Ö§ 9 ¤ Ò 10 ¤×Í»ØÁ * áÅФ Ò 11 ¤×Í»ØÁ # Ê Ç¹¤ Ò 12 ¶Ö§ 15 ¨Ðà» ¹ÊÑ­­Ò³â·¹¤ÍÅÑÁ¹ ·Õè 4 »ØÁ A ¶Ö§ D «Ö§è Ê Ç¹ãË­ ¨Ð㪠ÍÂÙã ¹à¤Ã×Íè §·´Êͺâ·ÃÈѾ· áÅÐÇÔ·ÂØÃºÑ Ê § ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ àÁ×Íè µ ͧ¡ÒÃÊ §ÊÑ­­Ò³ DTMF ÊÒÁÒöà¢Õ¹â»Ãá¡ÃÁä´ ´§Ñ ¹Õé DTMFOUT 0,[0,2,7,4,7,7,0,0,1] Call destination ¤íÒÊÑ§è ¹Õãé Ë ¼ÅàËÁ×͹¡Ñº¡Òá´¤Õ 027477001 ·Õâè ·ÃÈѾ· ¶ Òµ ͧ¡ÒÃãË ¡Òá´¤ÕÂÁ ¤Õ ÇÒÁàÃçǵèÒí ¡Ç Ò¹Õé ÊÒÁÒö·íÒä´ â´Â¡ÒÃà¾ÔÁè ¤ Ò ontime áÅÐ offtime ࢠÒ仴ѧ¹Õé DTMFOUT 0,1900,400,[0,2,7,4,7,7,0,0,1] 㹤íÒÊÑ§è ¹Õé ª ǧàÇÅÒ Ontime ÁÕ¤Ò à· Ò¡Ñº 503.5 ÁÔÅÅÔÇ¹Ô Ò·Õ (ÁÒ¨Ò¡ 1,900 X 0.265 ÁÔÅÅÔÇ¹Ô Ò·Õ) áÅÐ Offtime ÁÕ¤Ò à· Ò¡Ñº 106 ÁÔÅÅÔÇ¹Ô Ò·Õ (ÁÒ¨Ò¡ 400 X 0.265 ÁÔÅÅÔÇ¹Ô Ò·Õ)

¡Ò÷´Åͧ Í·Õè 7 Ê §ÊÑ­­Ò³»ØÁ â·ÃÈѾ· ´Ç ¤íÒÊѧè DTMFOUT (1) µÔ´µÑ§é i-Stamp2P24 ŧº¹ºÍà ´ JX-2SX plus II áÅ Çàª×Íè Áµ ͡Ѻ¤ÍÁ¾ÔÇàµÍà (2) µ Íǧ¨ÃµÒÁÃÙ»·Õè 3-3 (3) à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2Â24-07.BSP : DTMFOUT command demonstration***** ' {$STAMP BS2P} ' {$PBASIC 2.5} DTMFOUT 12,[[ËÁÒÂàÅ¢â·ÃÈѾ· µÒÁ·Õµè Í §¡Òà â´Â¤Ñ¹è áµ ÅÐËÅÑ¡´ ǨØÅÀÒ¤]] Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$!


i-Stamp2P24

P12

SP1

Piezo Speaker

ÃÙ»·Õè 3-3 ǧ¨Ã·´Åͧ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè DTMFOUT (4) ¿ §àÊÕ§·Õäè ´ ¨Ò¡ÅíÒ⾧ (5) ¹íÒâ·ÃÈѾ· ·µÕè Í ÊÒÂࢠҡѺÊÒÂâ·ÃÈѾ· ÀÒ¹͡ ¡Ë٠ṺºÃÔàdz»Ò¡¾Ù´à¢ ҡѺÅíÒ⾧ áÅ ÇÃѹâ»Ãá¡ÃÁã¹¢ Í 3 ÍÕ¡¤ÃÑ§é ¨Ò¡¹Ñ¹é ¿ §¡ÒõͺÃѺ¨Ò¡»ÅÒ·ҧ ËÒ¡àÅ¢ËÁÒ·ÕËè Áع¶Ù¡µ ͧ áÅÐÊÑ­­Ò³àÊÕ§»ØÁ â·ÃÈѾ· ·ÊÕè § ÍÍ¡ä» äÁ à¡Ô´¤ÇÒÁ¼Ô´à¾ÕÂé ¹ ¨Ðµ ͧÊÒÁÒöµÔ´µ ͡Ѻ»ÅÒÂ·Ò§ä´ Í ҧ¶Ù¡µ ͧ (6) ·´ÅͧãÊ ¤Ò ¢Í§ Ontime áÅÐ Offtime áÅ Ç·íÒµÒÁ¢Ñ¹é µÍ¹·Õè 3 ¶Ö§ 4 ËÃ×Í 5 (7) 㹡óշµÕè Í §¡ÒÃÊ §ÊÑ­­Ò³ DTMF ¨Ò¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 ࢠÒä»ã¹ÊÒÂâ·ÃÈѾ· ¨ÃÔ§æ ÊÒÁÒö ·´ÅÍ§ä´ â´Âµ Íǧ¨Ãàª×Íè Áµ ͡ѺÊÒÂâ·ÃÈѾ· ´§Ñ ã¹ÃÙ»·Õè 3-4 à¾ÔÁè àµÔÁ áÅ Ç·íÒ¡Ò÷´ÅͧµÒÁ¢ Í 3 áÅÐ 6 Hook SW./Relay

Telephone Line

R1 10

T1 600 : 600

C1 0.001/250V

VARISTOR

R2 10

i-Stamp2P port

ZD1-ZD2 3.9V

ÃÙ»·Õè 3-4 ǧ¨Ãàª×Íè Áµ Í¢Ò¾Íà µ¢Í§ i-Stmamp2P24 ¡ÑºÊÒÂâ·ÃÈѾ· Í ҧ§ Ò (â´ÂËÁ Íá»Å§ T1 ÊÒÁÒöÊÑè§¾Ñ¹ä´ ¨Ò¡·Õèáʧ·Í§ÇÔ·ÂØ, ÇÒÃÔÊàµÍà 㪠¢¹Ò´ 400V ¢Öé¹ä» ÁÕ¨íÒ˹ Ò·Õè ¹Ñ°¾§É à«ÅÊ á͹´ à«Íà ÇÊÔ ÃÇÁ·Ñ§é «Õà¹Íà ä´âÍ´áÅеÑÇà¡çº»ÃÐ¨Ø´Ç Â)

$"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


END ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè END

㪠àÁ×Íè µ ͧ¡Òèºâ»Ãá¡ÃÁ ¹íÒ i-Stamp2P24 ࢠÒÊÙâ ËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹ ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ´ Ç¡ÒÃ㪠¤íÒÊÑè§ END ¨Ð·íÒãË i-Stamp2P24 ËÂØ´·íÒ§Ò¹áÅÐࢠÒÊÙ âËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹ ¡Òà ¡Ô¹¡ÃÐáʢͧ i-Stamp2P24 ¨ÐàËÅ×Í»ÃÐÁÒ³ 60PA ¡àÇ ¹¢ÒÍÔ¹¾ØµàÍÒµ ¾µØ ÂѧÁÕ¡Òè Ò¡ÃÐáÊÍÂÙ ¨¹¡Ç Ò ¨ÐÁÕ¡Òá´ÊÇÔµª ÃÕ૵ËÃ×Í¡ÒÃËÂØ´¨ ÒÂä¿àÅÕé§áÅШ ÒÂä¿àÅÕé§ãË «éíÒÍÕ¡¤ÃÑé§ ã¹ª ǧ·Õè i-Stamp2P24 ÍÂÙã ¹âËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹ ¢ÒÍÔ¹¾ØµàÍÒµ ¾µØ ¨Ð¤§Ê¶Ò¹Ðà´ÔÁ ¡ ͹·Õ¨è СÃÐ ·íÒ¤íÒÊѧè END ´Ñ§¹Ñ¹é ¶ Ò¢ÒÍÔ¹¾ØµàÍÒµ ¾µØ ¡íÒÅѧ¢ÑºâËÅ´ÍÂÙ¡ Í ¹·Õ¨è ÐÁÕ¤Òí Êѧè END ËÅѧ¡ÃзíÒ¤íÒÊѧè END áÅ Ç ¢ÒÍÔ¹¾ØµàÍÒµ ¾ØµÂѧ¤§¢ÑºâËÅ´µ Íä» Í ҧäáçµÒÁ㹪 ǧàÇÅÒ»ÃÐÁÒ³ 2.3 ÇԹҷնѴ¨Ò¡¹Ñé¹ ¢ÒàÍÒµ ¾Øµ ¨Ð¶Ù¡à»ÅÕÂè ¹à» ¹ÍÔ¹¾Øµà» ¹àÇÅÒ»ÃÐÁÒ³ 18 ÁÔÅÅÔÇ¹Ô Ò·Õ ¨Ò¡¹Ñ¹é ¨Ö§¨Ð¡ÅѺÁÒ·íÒ§Ò¹àËÁ×͹à´ÔÁ ¡µÑÇÍ ҧ ¶ Ò i-Stamp2P24 ¶Ù¡¹íÒÁÒ㪠¢ºÑ LED áÅÐÁÕ¡ÒáÃзíÒ¤íÒÊѧè END µÑÇ LED Âѧ¤§µÔ´ÊÇ Ò§ ÍÂÙ áµ ·¡Ø æ 2.3 ÇÔ¹Ò·Õ LED ¨Ð´Ñº´ Ǫ ǧàÇÅÒÊѹé æ »ÃÐÁÒ³ 18 ÁÔÅÅÔÇ¹Ô Ò·Õ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$#


EXIT

ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè 㪠ÃÇ Á¡Ñº¤íÒÊѧè FOR...NEXT ËÃ×Í DO...LOOP à¾×Íè ¡íÒ˹´ãË àºÊÔ¡áʵÁ» ÍÍ¡¨Ò¡¡Ò÷íҧҹǹ ÅÙ» â´ÂÊÒÁÒö㪠¤Òí Êѧè EXIT ¹Õäé ´ ÁÒ¡¶Ö§ 16 ¤Ãѧé 㹡ÒÃËÂØ´¡Ò÷íҧҹẺǹÅÙ»¢Í§â»Ãá¡ÃÁ µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè FOR samples = 1 TO 10 GOSUB Read_Temp GOSUB Display_Temp IF (temp > 100) THEN EXIT PAUSE 1000 NEXT

; ¡ÃÐâ´´ä»·íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í Read_Temp (µ ͧà¢Õ¹â»Ãá¡ÃÁà¾ÔÁè ) ; ¡ÃÐâ´´ä»·íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í Display_Temp (µ ͧà¢Õ¹â»Ãá¡ÃÁà¾ÔÁè )

¨Ò¡â»Ãá¡ÃÁ¢ Ò§µ ¹¹Õàé Á×Íè à§×Íè ¹ä¢¡ÒõÃǨÊͺ·Õºè Ã÷Ѵ IF (temp > 100) THEN EXIT ¶ ÒËÒ¡à» ¹¨ÃÔ§ äÁâ¤Ã¤Í¹â·ÃÅàÅÍà i-Stamp2P24 ¨ÐÍÍ¡¨Ò¡â»Ãá¡ÃÁÅÙ»à¾×Íè ä»·íÒ§Ò¹ÂѧºÃ÷Ѵ¶Ñ´¨Ò¡¤íÒÊѧè NEXT ¢Í§ÅÙ»» ¨¨Øº¹Ñ ·Ñ¹·Õ

$$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


FOR...NEXT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè FOR Variable = Start to End {STEP StepVal} ... NEXT

㪠Êà ҧÅÙ»¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁ«Ö§è ÍÂÙà ÐËÇ Ò§¤íÒÊѧè FOR ¡Ñº NEXT ¡ÒÃà¾ÔÁè ËÃ×ÍÅ´¤ ÒµÑÇá»Ã Variable ¢Ö¹é ÍÂÙ¡ ºÑ ¤ Ò StepVal â»Ãá¡ÃÁ¨ÐǹÅÙ»«éÒí ¨¹¡Ç Ò¤ Ò·Õàè ¾ÔÁè ËÃ×ÍÅ´¹Ñ¹é ÁÕ¤Ò à· Ò¡Ñº¤ Ò End ¾ÒÃÒÁÔàµÍà Variable à» ¹¢ ÍÁÙŪ¹Ô´ºÔµ,¹ÔºàºÔÅ (4 ºÔµ), 亵 ËÃ×ÍàÇÔô 㪠໠¹µÑÇá»ÃÊíÒËÃѺ¹Ñº¤ Ò¡ÒÃǹÅÙ» Start à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õ·è ãÕè ª 㹡ÒáíÒ˹´¤ ÒàÃÔÁè µ ¹ãË ¡ºÑ µÑÇá»Ã variable End à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§ãª ÊÒí ËÃѺ¡íÒ˹´¤ ÒÊØ´· Ò¢ͧµÑÇá»Ã Variable àÁ×Íè ¤ ҢͧµÑÇá»Ã Variable ÁÕ¤Ò à· Ò¡Ñº¤ Ò END ¡ÒÃǹÅÙ»¢Í§¤íÒÊѧè FOR NEXT ¨ÐÊÔ¹é ÊØ´áÅÐâ»Ãá¡ÃÁ¨Ðä»·íҧҹ㹤íÒÊÑ§è ¶Ñ´ä» StepVal à» ¹¡ÒáíÒ˹´¨íҹǹ¢Í§¡ÒÃà¾ÔÁè ¢Ö¹é ËÃ×ÍŴŧ¢Í§¤ ÒµÑÇá»Ã Variable ¶ Ò¤ Ò Start ÁÒ¡¡Ç Ò ¤ Ò End i-Stamp2P24 ¨ÐࢠÒã¨Ç Ò¤ Ңͧ StepVal à» ¹¤ Òź áÁ ¨ÐäÁ ÁàÕ ¤Ã×Íè §ËÁÒÂźÃкØäÇ ¡µç ÒÁ ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ÅÙ» FOR...NEXT ª ÇÂãË ÊÒÁÒöà¢Õ¹â»Ãá¡ÃÁãË ·Òí §Ò¹à´ÕÂǡѹ«éÒí æ ã¹ÅѡɳÐà´ÔÁä´ â´ÂÊÒÁÒö ÃкبÒí ¹Ç¹¤ÃÑ§é ¢Í§¡Ò÷íÒ§Ò¹«éÒí æ ¡Ñ¹¹Õäé ´ ÃٻẺÍ ҧ§ Ò·ÕÊè ´Ø ¢Í§¡ÒÃ㪠§Ò¹¤íÒÊѧè FOR NEXT ÁÕ´§Ñ ¹Õé REPS VAR NIB FOR REPS = 1 to 3 DEBUG "*" NEXT

' ¡íÒ˹´ª¹Ô´¢Í§µÑÇá»Ã·Õãè ª ¡Òí ˹´Ãͺ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè FOR..NEXT ' ¡íÒ˹´ãË ¤Ò ¢Í§µÑÇá»Ã reps = 1, 2 áÅÐ 3 ' Ê §ÍÑ¡¢ÃÐ * ä»áÊ´§Âѧ˹ Òµ Ò§ Debug Terminal ' ǹ价íÒ§Ò¹ã¹Ãͺµ Íä»

áµ ÅФÃÑ§é ·ÕÁè ¡Õ ÒÃǹÅÙ» FOR...NEXT ¤ ҢͧµÑÇá»Ã REPS ¨ÐÁÕ¡ÒÃà»ÅÕÂè ¹á»Å§ ã¹µÑÇÍ ҧµ Í仹Õàé » ¹¡ÒÃáÊ´§¤ ÒµÑÇá»Ãã¹·Ø¡¤ÃÑ§é ·Õ·è Òí §Ò¹¤Ãº 1 Ãͺ ¼ Ò¹·Ò§Ë¹ Òµ Ò§ Debug Terminal '*********For-NextExample01.bsp : For..Next command example************** ' {$STAMP BS2p} ' {$PBASIC 2.5} REPS VAR Nib ' ¡íÒ˹´µÑÇá»Ãà¡çº¤ Ò FOR REPS = 1 TO 10 ' ¡íÒ˹´Ãͺ¢Í§¡ÒÃǹ·íÒ§Ò¹ ¤ Ңͧ REPS ¨Ðà¾ÔÁè ¨Ò¡ 1, 2, 3 ¨¹¶Ö§ 10. DEBUG DEC ? REPS ' ã¹áµ ÅÐÃͺ¡Ò÷íÒ§Ò¹ µ ͧáÊ´§¤ Ңͧ REPS ·ÕËè ¹ Òµ Ò§ Debug Terminal NEXT

àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal áÊ´§¤ ҢͧµÑÇá»Ã REPS µÑ§é áµ 1 ¶Ö§ 10

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$%


㹡óշ¤Õè Ò àÃÔÁè µ ¹ (start) ÁÕ¤Ò ¹ ÍÂ¡Ç Ò¤ ÒÊÔ¹é ÊØ´ (end) i-Stamp2P24 ¨ÐÊÒÁÒöࢠÒã¨ä´ ´Ç µÑÇÁѹ àÍ§Ç Ò ¤ Ò¡ÒùѺ¨Ðµ ͧ໠¹¡ÒùѺŧ᷹ÃٻẺ¡ÒùѺ¢Ö¹é »¡µÔ ´Ñ§µÑÇÍ ҧ '*********For-NextExample02.bsp : For..Next command example************** ' {$STAMP BS2p} ' {$PBASIC 2.5} REPS VAR Nib FOR REPS = 10 TO 1 DEBUG DEC ? REPS NEXT

' ¡íÒ˹´µÑÇá»Ãà¡çº¤ Ò ' ¡íÒ˹´Ãͺ¢Í§¡ÒÃǹ·íÒ§Ò¹ ¤ Ңͧ REPS ¨ÐŴŧ¨Ò¡ 10, 9, 8 ¨¹¶Ö§ 1. ' ã¹áµ ÅÐÃͺ¡Ò÷íÒ§Ò¹ µ ͧáÊ´§¤ Ңͧ REPS ·ÕËè ¹ Òµ Ò§ Debug Terminal

àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal áÊ´§¤ ҢͧµÑÇá»Ã REPS µÑ§é áµ 10 ¶Ö§ 1

¶ Òµ ͧ¡ÒÃ㪠¤íÒÊÑè§ FOR...NEXT ÊíÒËÃѺ¡ÒÃà¾ÔèÁËÃ×ÍÅ´¤ ÒäÁ 㪠¤ÃÑé§ÅÐ˹Ö觤 Ò ¼Ù 㪠§Ò¹ÊÒÁÒö ¡íÒ˹´¤ Ò¡ÒÃà¾ÔÁè ËÃ×ÍÅ´ä´ â´Â㪠StepVal ã¹â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õàé » ¹¡ÒÃÅ´¤ Òŧ¤Ãѧé ÅÐ 3 ¤ Ò '*********ForNextExample03.bsp : For..Next command example******************** ' {$STAMP BS2p} ' {$PBASIC 2.5} REPS VAR Nib ' ¡íÒ˹´¤ ÒµÑÇá»Ã FOR REPS = 10 TO 1 STEP 3 ' Å´¤ ҢͧµÑÇá»Ã REPS ¨Ò¡ 10 ¶Ö§ 1 â´ÂŴŧ¤Ãѧé ÅÐ 3 DEBUG DEC ? REPS ' ã¹áµ ÅÐÃͺ¡Ò÷íÒ§Ò¹ µ ͧáÊ´§¤ Ңͧ REPS ·ÕËè ¹ Òµ Ò§ Debug Terminal NEXT

àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal áÊ´§¤ ҢͧµÑÇá»Ã REPS µÑ§é áµ 10 ¶Ö§ 1 â´ÂŴŧ¤Ãѧé ÅÐ 3

¨Ò¡â»Ãá¡ÃÁ¤ Ò StepVal à» ¹ºÇ¡ áµ ¤Ò ¢Í§µÑÇá»Ã REPS ¡ÅѺŴŧ¤Ãѧé ÅÐ 3 ¤ Ò à¹×Íè §¨Ò¡¡Òà ŴËÃ×Íà¾ÔÁè ¤ Ңͧ¤íÒÊѧè FOR NEXT ¢Ö¹é ¡Ñº¤ Ò Start áÅÐ End äÁ ä´ ¢¹Öé ÍÂÙ¡ ºÑ à¤Ã×Íè §ËÁÒ·Õè StepVal

$&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡ÒÃãÊ ¤Ò à¤Ã×Íè §ËÁÒÂź¹íÒ˹ ÒãË ¡ºÑ ¤ Ò StepVal â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ¨ÐäÁ Á¡Õ ÒÃàµ×͹ à¹×Íè §¨Ò¡äÁ ¼´Ô äÇÂҡóì áµ ¤Ò ·Õäè ´ ¨Ð¼Ô´ µÑÇÍ ҧઠ¹ ã¹â»Ãá¡ÃÁ ForNextExample04.bsp ¡íÒ˹´ãË ¤Ò StepVal ÁÕ¤Ò à· Ò¡Ñº -1 µÑÇá»Åâ»Ãá¡ÃÁÀÒÉÒàºÊÔ¡ÀÒÂã¹àºÊÔ¡áʵÁ» àÍ´ÔàµÍà ¨ÐÁͧ໠¹¨íҹǹàŢẺ äÁ ¤´Ô à¤Ã×Íè §ËÁÒ «Ö§è ÁÕ¤Ò à· Ò¡Ñº 65,535 ¼ÅÅѾ¸ ·äÕè ´ ÊÒÁÒöáÊ´§¼ Ò¹·Ò§Ë¹ Òµ Ò§ Debug Terminal «Ö§è ¤ Ò·Õäè ´ ¨ÐÁÕà¾Õ§¤ Òà´ÕÂÇà· Ò¹Ñ¹é ¤×Í 1 à¾ÃÒСÒÃǹÅÙ»Ãͺ¶Ñ´ä» ¤ Ңͧ REPS ¨Ð¡ÅÒÂà» ¹ 0 «Ö§è à¡Ô¹¢Íºà¢µ ¢Í§¤ Ò end '*********ForNextExample04.bsp : For..Next command example******************** ' {$STAMP BS2p} ' {$PBASIC 2.5} REPS VAR Word ' ¡íÒ˹´ª¹Ô´¢Í§µÑÇá»Ã FOR REPS = 1 TO 10 STEP -1 ' ¡íÒ˹´ãË à¾ÔÁè ¤ Ò¨Ò¡ 1 ¶Ö§ 10 â´Âà¾ÔÁè ¤Ãѧé ÅÐ 65535 «Ö§è à» ¹ä»äÁ ä´ DEBUG DEC ? REPS ' ã¹áµ ÅÐÃͺ¡Ò÷íÒ§Ò¹ µ ͧáÊ´§¤ Ңͧ REPS ·ÕËè ¹ Òµ Ò§ Debug Terminal NEXT

àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal áÊ´§¤ ҢͧµÑÇá»Ã REPS µÑ§é áµ 1 ¶Ö§ 10 â´Âà¾ÔÁè ¤Ãѧé ÅÐ 65,353 («Ö§è à» ¹ä»äÁ ä´ ã¹¡Ã³Õ¹)Õé ¤ Ò·Õäè ´ ¨§Ö áÊ´§à¾Õ§¤ Òà´ÕÂǤ×Í 1 «Ö§è à» ¹¤ ÒµÑ§é µ ¹

ÊíÒËÃѺ¤íÒÊѧè FOR NEXT ÁÕ¢Í ¨íÒ¡Ñ´»ÃСÒÃË¹Ö§è ·Õ¼è ãÙ ª §Ò¹µ ͧÃÐÇѧáÅÐËÅÕ¡àÅÕÂè §àÁ×Íè 㪠¡ºÑ µÑÇá»Ã·ÕÁè Õ ¢¹Ò´ 16 ºÔµ ¡ÒÃà¾ÔÁè ËÃ×ÍÅ´¤ Ò¡ÒùѺáÅÐà»ÃÕºà·Õº¤ ҡѺ¤ Ò end à¾×Íè ËÂØ´¡ÒÃǹÅÙ» ¤ ÒÊÙ§ÊØ´¢Í§¡Òû ͹ ¤ Ò´ ǵÑÇá»ÃẺàÇÔô ËÃ×ÍẺ 16 ºÔµ¹Õ¤é Í× 65,535 㹡óշ¤Õè Ò ¢Í§µÑÇá»Ãà¡Ô¹¤ Ò end áÅ Ç â»Ãá¡ÃÁ¨Ðµ ͧ ËÂØ´ ãË ·´Åͧà¢Õ¹â»Ãá¡ÃÁµ Í仹Õé (ä¿Å ForNextExample05.bsp) à¾×Íè ·´Êͺ¡Ò÷íÒ§Ò¹ '*********ForNextExample05.bsp : For..Next command example******************** ' {$STAMP BS2p} ' {$PBASIC 2.5} REPS VAR Word FOR REPS = 0 TO 65500 STEP 3000 ' à¾ÔÁè ¤ ÒµÑÇá»Ãã¹ÅÙ»¤Ãѧé ÅÐ 3000 DEBUG DEC ? REPS ' áÊ´§¤ ҢͧµÑÇá»Ã REPS ·ÕËè ¹ Òµ Ò§ Debug Terminal NEXT

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$'


àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal áÊ´§¤ Ҵѧ¹Õé

¤ÅÔ ¡ àÅ×è Í ¹á¶ºàÅ×è Í ¹·Ò§ ´ Ò¹¢ Ò§à¾×èÍ´Ù¤ Òà¾ÔèÁàµÔÁ

¨Ð¾ºÇ Òâ»Ãá¡ÃÁÂѧ¤§Ç¹ÅÙ»ä»àÃ×Íè  à¹×Íè §¨Ò¡àÁ×Íè µÑÇá»ÃÁÕ¡ÒÃà¾ÔÁè ¤ Ò¤Ãѧé ÅÐ 3,000 ¨¹¡ÃÐ·Ñ§è ¶Ö§ 63,000 ¤ Òµ Í仨СÅÒÂà» ¹ 464 à¹×Íè §¨Ò¡¤ ҢͧµÑÇá»Ã·Õàè ¾ÔÁè ¢Ö¹é áÅ ÇÁÕ¤Ò à¡Ô¹ 65,535 ¼ÅÅѾ¸ ·äÕè ´ ¨§Ö à» ¹¤ Ò·Õàè ¡Ô¹ ¨Ò¡¤ ÒÊÙ§ÊØ´ÍÍ¡ÁÒ ´Ñ§¹Ñ¹é ¼ÅÅѾ¸ ·äÕè ´ ¨§Ö ¢ ÒÁ¤ Ò end ·Õè 65,500 ä» àÁ×Íè ¤ ҢͧµÑÇá»Ã෠ҡѺ 464 ¡ç处 ¹ Í ¡Ç Ò 65,500 (¤ Ò End) â»Ãá¡ÃÁ¨Ö§Âѧ¤§·íҧҹǹÅÙ»µ Íä» ¨¹¡ÃÐ·Ñ§è ¤ Ò·Õàè ¾ÔÁè ¢Ö¹é ÁÕ¤Ò ÁÒ¡¡Ç Ò 65,500 áµ äÁ à¡Ô¹ 65,535 â»Ãá¡ÃÁ¨Ö§¨ÐËÂØ´¡ÒÃǹÅÙ» ´Ñ§¹Ñ¹é ¡ÒÃà¢Õ¹â»Ãá¡ÃÁ¨Ö§µ ͧÃÐÇѧàÃ×Íè §¡ÒÃ㪠µÇÑ àÅ¢ 16 ºÔµ´ ÇÂ

%

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ Í·Õè 8 ¡ÒÃ㪠¤Òí Êѧè FOR....NEXT 㹡Òäíҹdz·Ò§¤³ÔµÈÒʵà (1) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé «Ö§è à» ¹â»Ãá¡ÃÁËÒ¤ Ò¡íÒÅѧÊͧ¢Í§µÑÇàÅ¢¨Ò¡ 1 仨¹¶Ö§¤ Ò¼ÅÅѾ¸ ·äÕè Á à¡Ô¹ 250 '*****PRELAB2p24-08 : FOR...NEXT command demonstration***** ' {$STAMP BS2P} ' {$PBASIC 2.5} SQUARE VAR Byte ' ¡íÒ˹´ª¹Ô´µÑÇá»Ã·Õãè ª 㹡íÒ˹´¨íҹǹÃͺ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè FOR..NEXT STEPSIZE VAR Byte ' ¡íÒ˹´ª¹Ô´µÑÇá»Ã·Õè㪠à¾ÔèÁ¤ ҢͧµÑÇá»Ã·Õè㪠㹡íÒ˹´¨íҹǹÃͺ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊÑè§ FOR..NEXT STEPSIZE = 1 SQUARE = 1 FOR SQUARE = 1 TO 250 STEP STEPSIZE ' ¡íÒ˹´Ãͺ¡Ò÷íÒ§Ò¹ÊÙ§ÊØ´àÁ×Íè ¤ Ңͧ SQUAER ÊÙ§¶Ö§ 250. PAUSE 10 DEBUG DEC ? SQUARE ' áÊ´§¤ Ңͧ SQUARE ·ÕËè ¹ Òµ Ò§ Debug Terminal STEPSIZE = STEPSIZE +2 ' à¾ÔÁè ¤ ҢͧµÑÇá»Ã·Õãè ª à¾ÔÁè ¤ ҢͧµÑÇá»Ã¡íÒ˹´¨íҹǹÃͺ¡Ò÷íÒ§Ò¹ NEXT

(2) Ãѹâ»Ãá¡ÃÁ´ Ç¡Òá´»ØÁ RUN ËÃ×Í CTRL + R ¨Ð»ÃÒ¡¯¼Å¡Ò÷íÒ§Ò¹·ÕËè ¹ Òµ Ò§ Debug Terminal ´Ñ§¹Õé

àÁ×èÍàÃÔèÁ·íÒ§Ò¹ ¤ Ңͧ SQUARE áÅÐ STEPSIZE à» ¹ 1 ·Ñ駤٠ã¹Ãͺáá¢Í§¡Ò÷íÒ§Ò¹ ¤ Ңͧ SQUARE ෠ҡѺ 1 áÅж١¹íÒÁÒáÊ´§·ÕËè ¹ Òµ Ò§ Debug Terminal ¨Ò¡¹Ñ¹é ¤ Ңͧ STEPSIZE ¨Ð¡ÅÒÂà» ¹ 3 àÁ×Íè ¡ÃзíÒ¤íÒÊѧè STEPSIZE = STEPSIZE +2 àÁ×Íè ÁÒ·íÒ§Ò¹ã¹Ãͺ·Õè 2 ¤ Ңͧ SQUARE ¨Ðà» ¹ 4 à¹×Íè §¨Ò¡ ¤ Ңͧ STEPSIZE ෠ҡѺ 3 ¹Ñ¹è ¤×Í ¡íÒ˹´ãË ¤Ò ¢Í§ SQUARE à¾ÔÁè ¢Ö¹é ÍÕ¡ 3 ¤ Ò¨Ò¡¤ ÒµÑ§é µ ¹ 1 ¨Ò¡¹Ñ¹é ¤ Ңͧ STEPSIZE ¨Ð¡ÅÒÂà» ¹ 5 à¹×Íè §¨Ò¡¤ ÒÅ ÒÊØ´¢Í§ STEPSIZE ෠ҡѺ 3 àÁ×Íè ¡ÃзíÒ¤íÒÊѧè STEPSIZE = STEPSIZE +2 ã¹Ãͺ¹Õé ·íÒãË ¤Ò ¢Í§ STEPSIZE ෠ҡѺ 5 ÊíÒËÃѺ¡íÒ˹´¤ Ңͧ SQUARE ã¹Ãͺ¡Ò÷íÒ§Ò¹¶Ñ´ä»

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%


ã¹Ãͺ¡Ò÷íÒ§Ò¹µ ÍÁÒ ¤ Ңͧ SQUARE ¨Ò¡à´ÔÁ෠ҡѺ 4 àÁ×Íè ¤ Ңͧ STEPSIZE ෠ҡѺ 5 ¨Ö§·íÒãË ¤ Ңͧ SQUARE à¾ÔÁè ¢Ö¹é ¨Ò¡ 4 ä»ÍÕ¡ 5 ¤ Ò ¨Ö§à· ҡѺ 9 ¹íÒä»áÊ´§¼Å·ÕËè ¹ Òµ Ò§ Debug Terminal ¨Ò¡¹Ñ¹é ¤ Ò ¢Í§ STEPSIZE ¨Ð¶Ù¡ºÇ¡à¢ Òä»ÍÕ¡ 2 ෠ҡѺ 7 ã¹Ãͺ¡Ò÷íÒ§Ò¹µ ÍÁÒ ¤ Ңͧ SQUARE ¨Ò¡¡Ò÷íÒ§Ò¹ÃͺŠÒÊش෠ҡѺ 9 àÁ×Íè ¤ Ңͧ STEPSIZE ෠ҡѺ 7 ¨Ö§·íÒãË ¤Ò ¢Í§ SQUARE à¾ÔÁè ¢Ö¹é ¨Ò¡ 9 ä»ÍÕ¡ 7 ¤ Ò ¨Ö§à· ҡѺ 16 ¹íÒä»áÊ´§¼Å·ÕËè ¹ Òµ Ò§ Debug Terminal ¨Ò¡¹Ñ¹é ¤ Ңͧ STEPSIZE ¨Ð¶Ù¡ºÇ¡à¢ Òä»ÍÕ¡ 2 ෠ҡѺ 9 ¡Ò÷íÒ§Ò¹¨Ðà» ¹àª ¹¹Õ¨é ¹¡ÃÐ·Ñ§è ¤ Ңͧ SQUARE ÊÙ§¶Ö§ 250 ËÃ×ÍÁÒ¡¡Ç Ò ¡ç¨ÐËÂØ´¡Ò÷íÒ§Ò¹ ¨Ò¡¡Òà ·´Êͺ¾ºÇ Ò ¤ Ңͧ SQUARE ¤ ÒÊØ´· Ò·Õáè Ê´§¼Åº¹Ë¹ Òµ Ò§ Debug Terminal ¤×Í 225 ÊѧࡵãË ´Õ ¨Ð¾ºÇ Ò â»Ãá¡ÃÁ·´Êͺ¹Õ¤é Í× â»Ãá¡ÃÁ¤íҹdzàŢ¡¡íÒÅѧÊͧ¹Ñ¹è àͧ

%

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


FREQOUT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè FREQOUT Pin, Duration, Freq1{,Freq2}

㪠ÊÒí ËÃѺ¡íÒà¹Ô´ÊÑ­­Ò³ä«¹ ˹֧è ËÃ×ÍÊͧÊÑ­­Ò³ã¹ª ǧÃÐÂÐàÇÅÒ·Õ¡è Òí ˹´ ¾ÒÃÒÁÔàµÍà Pin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕèÁÕ¤ Ò෠ҡѺ 0 ¶Ö§ 15 à¾×èÍ¡íÒ˹´¢Ò¾Íà µ·Õè㪠§Ò¹ â´Â¢Ò¾Íà µ¹Õé¨Ðä´ ÃѺ¡ÒáíÒ˹´ãË à» ¹¢ÒàÍÒµ ¾Øµà¾×èÍ¡íÒà¹Ô´ÊÑ­­Ò³ áÅШСÅѺä»Ê¶Ò¹Ðà´ÔÁËÅѧ¨Ò¡¡íÒà¹Ô´ÊÑ­­Ò³áÅ Ç Duration à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò µÑ§é áµ 1 ¶Ö§ 65,535 㪠¡Òí ˹´ª ǧàÇÅҢͧÊÑ­­Ò³·Õ¡è Òí à¹Ô´ ¢Ö¹é ÁÕ˹ ÇÂà» ¹ 0.265 ÁÔÅÅÔÇ¹Ô Ò·Õ Freq1 à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 32,767 㪠à¾×Íè ¡íÒ˹´¤ Ò¤ÇÒÁ¶ÕËè ¹ ÇÂà» ¹ 3.77Hz ´Ñ§¹Ñ¹é ¨Ö§ÊÒÁÒö¡íÒà¹Ô´ÊÑ­­Ò³ä´ µ§Ñé áµ 0 ¶Ö§ 123.53kHz Freq2 à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õ·è ãÕè ª à¾×Íè ¡íÒ˹´¤ Ò¤ÇÒÁ¶ÕËè ¹ ÇÂà» ¹ 3.77Hz ÊÒÁÒö¡íÒ˹´¤ Òä´ µ§Ñé áµ 0 ¶Ö§ 32,767 ઠ¹à´ÕÂǡѺ Freq1 ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ¤íÒÊѧè FREQOUT ¨Ð·íÒ¡ÒáíÒà¹Ô´ÊÑ­­Ò³ä«¹ â´Â㪠ǧ¨ÃÁÍ´ÙàÅªÑ¹è ·Ò§¤ÇÒÁ¡Ç Ò§¢Í§¾ÑÅÊ ËÃ×;ÑÅÊ Ç´Ô ¸ ÁÍ´ÙàÅàµÍà (PWM) ¤ÇÒÁàÃçÇÊÙ§ ·Õàè ÍÒµ ¾µØ ¢Í§¢Ò¾Íà µ·Õãè ª §Ò¹ÍÒ¨µ ͧµ Íǧ¨Ã¡Ãͧ¤ÇÒÁ¶Õµè Òèí ¼ Ò¹ ´Ñ§ã¹ÃÙ»·Õè 3-5 ¡ ͹¨Ð» ͹ࢠÒÊÙÅ Òí ⾧ËÃ×Íǧ¨Ã¢ÂÒÂàÊÕ§ µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè FREQOUT ÁÕ´§Ñ ¹Õé FREQOUT 2,1000,1000 ¤íÒÊÑ§è ¹Õ¨é СíÒà¹Ô´ÊÑ­­Ò³ä«¹ ¤ÇÒÁ¶Õè 3,770Hz ´ Ǫ ǧàÇÅÒ 265 ÁÔÅÅÔÇ¹Ô Ò·Õ ¼ Ò¹·Ò§¢Ò P2 ¶ Òµ ͧ ¡ÒÃãË Êà ҧ¤ÇÒÁ¶Õè 2 ¤ÇÒÁ¶ÕÊè ÒÁÒöà¢Õ¹â»Ãá¡ÃÁä´ ´§Ñ ¹Õé FREQOUT 2,1000,500,1000 àÁ×Íè ¡ÃзíÒ¤íÒÊÑ§è ¹Õé i-Stamp2P24 ¨Ð¡íÒà¹Ô´ÊÑ­­Ò³Êͧ¤ÇÒÁ¶Õ¤è Í× 1,885 áÅÐ 3,770Hz ¼ÊÁ¡Ñ¹áÅÐ ãË àÊÕ§àËÁ×͹¡ÑºàÊÕ§´¹µÃÕËÃ×ÍàÊÕ§¡Ãдԧè ÊíÒËÃѺ¡ÒÃËÂØ´¡íÒà¹Ô´àÊÕ§·íÒä´ â´Â¡íÒ˹´ãË ¤Ò ¤ÇÒÁ¶Õàè · ҡѺ 0

¢Ò¾Íà µ¢Í§ i-Stamp2P24

1k 0.1/50V

1k 0.1/50V

µ Íä»Âѧ ǧ¨Ã¢ÂÒÂàÊÕ§

ÃÙ»·Õè 3-5 ǧ¨Ã¡Ãͧ¤ÇÒÁ¶Õµè Òèí ¼ Ò¹à¾×Íè Å´ÊÑ­­Ò³¤ÇÒÁ¶ÕÊè §Ù ·ÕÍè Ò¨»Ð»¹à¢ ÒÁÒÍѹà¹×Íè §ÁÒ¨Ò¡¡Ãкǹ ¡Òà PWM 㹡ÒÃÊà ҧÊÑ­­Ò³ä«¹ ÀÒÂã¹ i-Stamp2P24 Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%!


i-Stamp2P24

P12

SP1

Piezo Speaker

ÃÙ»·Õè 3-6 ǧ¨Ã·´Åͧ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè DTMFOUT

¡Ò÷´Åͧ Í·Õè 9 àÅ ¹à¾Å§â´Â¡ÒÃÍ Ò¹¤ ÒµÑÇâ¹ µ¨Ò¡µÒÃÒ§¢ ÍÁÙÅ (1) 㪠ǧ¨Ãã¹ÃÙ»·Õè 3-6 à¾×Íè ·íÒ¡Ò÷´Åͧ (2) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2p24-09.BSP : FREQOUT command demonstrate TO playing melody***** ' {$STAMP BS2P} ' {$PBASIC 2.5} I VAR Byte ' »ÃСÒȵÑÇá»ÃÊíÒËÃѺªÕµé ÒÃÒ§¢ ÍÁÙÅ F VAR Word ' ¡íÒ˹´µÑÇá»Ãà¡çº¤ Ò¤ÇÒÁ¶Õ¢è ͧàÊÕ§ C CON 784 ' ¤ ҢͧµÑÇâ¹ µ C ËÃ×Íâ´ D CON 968 ' ¤ ҢͧµÑÇâ¹ µ D ËÃ×Íàà E CON 1087 ' ¤ ҢͧµÑÇâ¹ µ E ËÃ×ÍÁÕ G CON 1294 ' ¤ ҢͧµÑÇâ¹ µ G R CON 0 ' Silent PAUSE (rest). FOR I = 0 TO 28 ' Play the 29 notes of the LOOKUP table. LOOKUP I,[E,D,C,D,E,E,E,R,D,D,D,R,E,G,G,R,E,D,C,D,E,E,E,E,D,D,E,D,C],F FREQOUT 12,700,F,(F-2) MAX 2600 NEXT STOP

â»Ãá¡ÃÁ¹Õ¨é ÐÍ Ò¹¤ ÒµÑÇâ¹ µ¨Ò¡µÒÃÒ§à¡çº¤ Ò¢ ÍÁÙÅ ÊÑ­­Ò³àÊÕ§·Õäè ´ ÁÒ¨Ò¡¡ÒüÊÁÊÑ­­Ò³ä«¹ â´Â¤ÇÒÁ¶Õáè á໠¹¤ÇÒÁ¶Õ¢è ͧµÑÇâ¹ µ ¤ÇÒÁ¶Õ·è ÊÕè ͧ໠¹¤ÇÒÁ¶Õ·è µÕè Òèí ¡Ç Ò¤ÇÒÁ¶Õáè á 7.54 Hz àÁ×Íè ÊÑ­­Ò³¼ÊÁ¡Ñ¹ ¤ÇÒÁ¶Õè¼ÅºÇ¡áÅФÇÒÁ¶Õè¼Åµ Ò§¨Ð¶Ù¡Êà ҧ¢Öé¹ ¤ÇÒÁ¶Õè·Õèµ Ò§¡Ñ¹¹Õé¨Ð·íÒãË à¡Ô´¡ÒÃÊÑ蹢ͧᵠÅеÑÇâ¹ µ ¨Ò¡â»Ãá¡ÃÁ¡ÒÃ㪠f-2 㹤íÒÊѧè FREQOUT àÁ×Íè ¤ Ò f ÁÕ¤Ò à· Ò¡Ñº 0 ËÅѧ¨Ò¡Åº 2 áŠǤ Ò f ¨ÐÁÕ¤Ò à» ¹ 65,534 ¤íÒÊѧè FREQOUT ¨ÐÁͧ¢ ÒÁºÔµº¹ÊØ´ ·íÒãË ¤Ò ·Õäè ´ ෠ҡѺ 123.5kHz ¤ÇÒÁ¶ÕÊè §Ù ¤ Ò¹ÕËé ÁÙ ¹ØÉ ¨ÐäÁ ÊÒÁÒö ä´ ÂÔ¹ ¨Ö§¤Å ÒÂ¡ÑºÇ ÒäÁ ÁÕÊÑ­­Ò³à¡Ô´¢Öé¹ ÊíÒËÃѺ¡ÒÃá¡ » ­ËÒ¹Õé·íÒä´ â´Â㪠¤íÒÊÑè§ MAX ࢠҪ Ç·ÕèºÃ÷Ѵ FREQOUT 0,1000,F,(F-2) MAX 2600 à¾×Íè à»ÅÕÂè ¹¤ Ò 65,534 ãË à» ¹ 2600 (3) Ãѹâ»Ãá¡ÃÁ·Õàè ¢Õ¹¢Ö¹é ¹Õé ¿ §àÊÕ§·Õàè ¡Ô´¢Ö¹é ¨Ò¡ÅíÒ⾧

%"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


GET ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè GET

Location, Variable

à» ¹¤íÒÊѧè Í Ò¹¢ ÍÁÙŨҡ˹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´áÃÁä»à¡çºäÇ ã¹µÑÇá»Ã·Õ¡è Òí ˹´ ¾ÒÃÒÁÔàµÍà Location à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õáè Ê´§µíÒá˹ §¢Í§Ë¹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´áÃÁÀÒÂã¹ i-Stamp2P24 ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 127 Variable à» ¹µÑÇá»Ã·Õµè Í §¡ÒÃà¡çº¢ ÍÁÙÅ ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ¤íÒÊÑ§è ¹Õ¨é ÐàÃÕ¡㪠àÁ×Íè µ ͧ¡ÒÃÍ Ò¹¢ ÍÁÙÅÍÍ¡¨Ò¡Ë¹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´áÃÁ ËÅѧ¨Ò¡·ÕÁè ¡Õ ÒÃà¡çº ŧ仴 ǤíÒÊÑè§ PUT â´Â¤íÒÊÑ觹Õé¨Ð¡ÃзíҡѺ¢ ÍÁÙÅã¹ÃдѺ亵 à· Ò¹Ñé¹ ¨íҹǹáÍ´à´Ãʢͧ˹ ǤÇÒÁ¨íÒ Êá¤Ãµª á¾´áÃÁ·ÕÊè ÒÁÒö㪠¤Òí Êѧè GET à¾×Íè Í Ò¹¤ ҹѹé ÁÕ·§Ñé ÊÔ¹é 128 µíÒá˹ § µÑ§é áµ 0 ¶Ö§ 127 â´Âã¹ 127 µíÒá˹ §áá (µÑ§é áµ 0 ¶Ö§ 126) ¨Ðà» ¹¢ ÍÁÙÅã´æ Ê Ç¹ã¹µíÒá˹ §ÊØ´· Ò¢ ÍÁÙÅ·ÕÍè Ò ¹ä´ à» ¹¢ ÍÁÙÅàÅ¢ËÁÒ â»Ãá¡ÃÁ «Ö§è 㪠㹡ÒõÃǨÊÍºÇ Ò¢³Ð¹Õàé ºÊÔ¡áʵÁ» ·Òí §Ò¹ÍÂÙ· âÕè »Ãá¡ÃÁã´ÃÐËÇ Ò§â»Ãá¡ÃÁ 0 ¶Ö§ 7 ¤íÒÊÑ§è ¹ÕÁé ÅÕ ¡Ñ ɳСÒ÷íÒ§Ò¹¤Å Ò¡Ѻ¤íÒÊѧè POP ¢Í§äÁâ¤Ã¤Í¹â·ÃÅàÅÍà àºÍà ͹×è

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%#


GOSUB ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè GOSUB AddressLabel

à» ¹¤íÒÊÑ§è ¡íÒ˹´ãË àºÊÔ¡áʵÁ» 2P ¡ÃÐâ´´ä»·íÒ§Ò¹ÂѧáÍ´à´ÃÊ·Õ¡è Òí ˹´â´Â AddressLabel áµ ¨ÐÁÕ¡ÒÃà¡çº¤ ÒáÍ´à´ÃÊÊØ´· ÒÂäÇ ã¹Êáµç¡ (Stack : ¾×¹é ·ÕÊè Òí ËÃѺà¡çº¢ ÍÁÙŪÑÇè ¤ÃÒÇ) àÁ×Íè ·íÒ§Ò¹àÊÃç¨áÅ Ç ¡ç¨Ð àÃÕ¡¤ ҢͧáÍ´à´ÃÊ·Õàè ¡çºäÇ ã¹Êáµç¡ÍÍ¡ÁÒ ¡ÅѺ价íÒ§Ò¹ÂѧáÍ´à´ÃÊ¹Ñ¹é ¾ÒÃÒÁÔàµÍà AddressLabel à» ¹µíÒá˹ §ÅÒàºÅÃкصÒí á˹ §·Õ¨è СÃÐâ´´ä» ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ¤íÒÊÑè§ GOSUB ·íÒ§Ò¹¤Å Ò¡Ѻ¤íÒÊÑè§ GOTO áµ ËÅѧ¨Ò¡·íÒ¤íÒÊÑè§ã¹â»Ãá¡ÃÁ Í·Õè¡ÃÐâ´´ä»àÊÃç¨ àÃÕºà ÍÂáÅ Ç ¨Ð¡ÃÐâ´´¡ÅѺÁÒ·íÒ§Ò¹µ Íã¹â»Ãá¡ÃÁ»¡µÔ â´Â¡ÒáÅѺÁÒ·íÒ§Ò¹¨Ðà¡Ô´¢Ö¹é ¡çµÍ àÁ×Íè ¾º¤íÒÊѧè RETURN ã¹â»Ãá¡ÃÁ¾ÕàºÊÔ¡¢Í§ i-Stamp2P24 ÊÒÁÒöºÃèؤÒí Êѧè GOSUB ä´ Ê§Ù ÊØ´ 255 ¤íÒÊѧè áÅÐ ÊÒÁÒö㪠¤Òí Êѧè GOSUB « ͹¡Ñ¹ä´ ʧ٠ÊØ´ 4 ªÑ¹é ¤íÒÊÑè§ GOSUB ¨Ð㪠§Ò¹¡çµ Í ÁÕ¡ÅØ Á¢Í§¤íÒÊÑ觡ÅØ Á˹Ö觷Õèµ Í§àÃÕ¡㪠§Ò¹ÍÂÙ àÊÁÍ ¼Ù 㪠§Ò¹ÊÒÁÒö ÃǺÃÇÁ¡ÅØ Á¤íÒÊÑè§àËÅ Ò¹Ñé¹äÇ ã¹ÅѡɳТͧâ»Ãá¡ÃÁ Í (subroutine) áÅеÑ駪×èÍÅÒàºÅ¢Í§â»Ãá¡ÃÁ Í ¹Ñ¹é àÍÒäÇ àÁ×Íè µ ͧ¡ÒÃ㪠§Ò¹â»Ãá¡ÃÁã¹Ê ǹ¹Õ¡é ãç ª ¤Òí Êѧè GOSUB à¾×Íè ¡ÃÐâ´´ä»Âѧâ»Ãá¡ÃÁ Í·ÕÁè ªÕ Í×è ÅÒàºÅ ´Ñ§¡Å ÒÇ àÁ×Íè ¡ÃзíÒ¤íÒÊѧè ã¹â»Ãá¡ÃÁ Í¹ѹé àÃÕºà ÍÂáÅ Ç ã¹ºÃ÷ѴÊØ´· Ò¢ͧâ»Ãá¡ÃÁ Í¨е ͧºÃèؤÒí Êѧè RETURN äÇ àÊÁÍ à¾×Íè ¡íÒ˹´ãË i-Stamp2P24 ÍÍ¡¨Ò¡â»Ãá¡ÃÁ Í ¡ÃÐâ´´¡ÅѺä»Âѧâ»Ãá¡ÃÁËÅÑ¡µ Íä»

%$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ Í·Õè 10 ¡ÒÃ㪠¤Òí Êѧè GOSUB (1) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2p24-10.BSP : GOSUB command demonstrate to randoming number******* ' {$STAMP BS2P} ' {$PBASIC 2.5} ROUNDS VAR Nib ' ¡íÒ˹´ª¹Ô´¢Í§µÑÇá»Ã ROUNDS NUM_GEN VAR Word ' ¡íÒ˹´ª¹Ô´¢Í§µÑÇá»Ã·Õãè ª ÊÁØ ¤ Ò ¨Ðµ ͧ¡íÒ˹´à» ¹ WORD ËÃ×Í 16 ºÔµà· ҹѹé MY_NUM VAR Nib ' ¡íÒ˹´ª¹Ô´¢Í§µÑÇá»Ã·Õãè ª à¡çº¤ Ò·Õäè ´ ¨Ò¡¡ÒÃÊØÁ FOR ROUNDS = 1 TO 3 ' ¡íÒ˹´Ãͺ¢Í§¡ÒÃÊØÁ à» Â 3 Ãͺ PAUSE 10 DEBUG CLS,"Pick a number from 1 TO 10",CR GOSUB PICK_NUM ' ¡ÃÐâ´´ä»·íÒ§Ò¹·Õâè »Ãá¡ÃÁ ÍÂÊØÁ µÑÇàÅ¢ 1 ¶Ö§ 10 PAUSE 2000 ' ˹ ǧàÇÅÒ 2 ÇÔ¹Ò·Õ DEBUG "My number was: ", DEC MY_NUM ' áÊ´§¤ ÒµÑÇàÅ¢·Õäè ´ ¨Ò¡ÒÃÊØÁ ·ÕËè ¹ Òµ Ò§ Debug Terminal PAUSE 2000 ' ˹ ǧàÇÅÒ 2 ÇÔ¹Ò·Õ NEXT STOP ' ËÂØ´¡Ò÷íÒ§Ò¹ â»Ãá¡ÃÁ ÍÂÊØÁ µÑÇàÅ¢ PICK_NUM: RANDOM NUM_GEN MY_NUM = NUM_GEN/6550 MIN 1 RETURN

' ·íÒ¡ÒÃÊØÁ µÑÇàÅ¢ áÅ Çà¡çºäÇ ã¹µÑÇá»Ã NUM_GEN ' »ÃѺ¤ Ò·ÕÊè ÁØ ä´ ãË ÍÂÙã ¹ª ǧ 1 ¶Ö§ 10

à» ¹â»Ãá¡ÃÁÊØ Á¤ ÒµÑÇàÅ¢â´Â㪠â»Ãá¡ÃÁ Í PICK_NUM áÅШÐËÂØ´·íÒ§Ò¹àÁ×èÍÁÕ¡ÒÃÊØ ÁµÑÇàÅ¢ ¤Ãº 3 ¤Ãѧé (2) Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é ¾Ã ÍÁ¡ÑºáÊ´§¼Å´Ñ§¹Õé

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%%


GOTO ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè GOTO AddressLabel

à» ¹¤íÒÊÑ§è ¡íÒ˹´ãË i-Stamp2P24 ¡ÃÐâ´´ä»ÂѧµíÒá˹ §µ Ò§æ ¢Í§â»Ãá¡ÃÁµÒÁ·ÕÃè кØã¹ AddressLabel ¾ÒÃÒÁÔàµÍà AddressLabel à» ¹ÅÒàºÅ·ÕÃè кصÒí á˹ §»ÅÒ·ҧ ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ àÁ×Íè ¡ÃФíÒÊÑ§è ¹Õé i-Stamp2p24 ¨Ð¡ÃÐâ´´ä»·íÒ§Ò¹ÂѧµíÒá˹ §·Õ¡è Òí ˹´ »ÃÐ⪹ ¢Í§¤íÒÊÑ§è ¹Õâé ´ÂÊ Ç¹ ãË­ ¨Ð㪠à¾×Íè Êà ҧ¡ÒÃǹÅٻẺäÁ Á·Õ ÊÕè ¹Ôé ÊØ´ â´Ââ»Ãá¡ÃÁ¨Ðǹ·íҧҹ㹡ÅØÁ ¤íÒÊÑ§è ·Õ«è Òéí æ ¡Ñ¹ÍÂÙÍ Â Ò§¹Ñ¹é µÅÍ´ àÇÅÒ ´Ñ§â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé LOOP1: DEBUG Looping... ,CR GOTO LOOP1 â»Ãá¡ÃÁ¹Õ¨é Ðà» ¹¡ÒÃǹÅٻẺäÁ Á·Õ ÊÕè ¹Ôé ÊØ´ à¾×Íè áÊ´§¢ ͤÇÒÁ Looping ·ÕËè ¹ Òµ Ò§ Debug Terminal µÅÍ´àÇÅÒ ¨¹¡Ç Ò¨ÐÊѧè ãË ËÂØ´¡Ò÷íÒ§Ò¹ â´Â¡ÒûŴä¿àÅÕÂé §ËÃ×Í» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍÃ

%&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


HIGH ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè HIGH Pin

㪠㹡ÒáíÒ˹´ãË ¢Ò¾Íà µàÍÒµ ¾µØ ÁÕÅͨԡ໠¹ 1 ¾ÒÃÒÁÔàµÍà Pin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò µÑ§é áµ 0 ¶Ö§ 15 à¾×Íè ¡íÒ˹´¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õµè Í §¡ÒÃ㪠§Ò¹ ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ 㹡ÒÃÊ §¤ ÒÅͨԡ 1 ä»Âѧ¢ÒàÍÒµ ¾µØ ¢Í§ i-Stamp2P24 ÁÕ 2 ¢Ñ¹é µÍ¹¤×Í (1) ¡íÒ˹´ãË ºµÔ ã¹ÃÕ¨ÊÔ àµÍà DIRS ã¹µíÒá˹ §·Õµè Í §¡ÒÃÊ §¤ ÒÁÕÅͨԡ 1 (2) ¡íÒ˹´ãË ºµÔ ã¹ÃÕ¨ÊÔ àµÍà OUTS ã¹µíÒá˹ §·Õµè Í §¡ÒÃÊ §¤ ÒÁÕÅͨԡ 1 ¤íÒÊѧè HIGH ÃÇÁÊͧ¢Ñ¹é µÍ¹¹Õàé ÍÒäÇ ã¹¤íÒÊѧè à´ÕÂÇà¾Õ§ÃкصÒí á˹ §¢Ò·Õµè Í §¡ÒÃãË ÁÅÕ Í¨Ô¡ 1 ෠ҹѹé

¡Ò÷´Åͧ Í·Õè 11 ¡ÒÃ㪠§Ò¹¤íÒÊѧè HIGH (1) 㪠ǧ¨ÃµÒÁÃÙ»·Õè 3-7 㹡Ò÷´Åͧ (2) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2p24-11.BSP : HIGH command demonstration******* ' {$STAMP BS2P} ' {$PBASIC 2.5} DEBUG "Before: ",CR áÊ´§¢ ͤÇÒÒÁ Before ·ÕËè ¹ Òµ Ò§ Debug Terminal DEBUG BIN16 ? DIRS,BIN16 ? OUTS,CR áÊ´§¤ ҢͧÃÕ¨ÊÔ àµÍà DIRS áÅÐ OUTS ã¹ÃÙ»¢Í§àÅ¢°Ò¹Êͧ ¢¹Ò´ 16 ºÔµ ·ÕËè ¹ Òµ Ò§ Debug Terminal PAUSE 1000 HIGH 3 ·íÒãË ¢Ò 3 à» ¹ÅͨԡÊÙ§ DEBUG "After: ",CR áÊ´§¢ ͤÇÒÒÁ After ·ÕËè ¹ Òµ Ò§ Debug Terminal DEBUG BIN16 ? DIRS,BIN16 ? OUTS áÊ´§¤ ҢͧÃÕ¨ÊÔ àµÍà DIRS áÅÐ OUTS ã¹ÃÙ»¢Í§àÅ¢°Ò¹Êͧ ¢¹Ò´ 16 ºÔµ ·ÕËè ¹ Òµ Ò§ Debug Terminal

i-Stamp2P24

P3

510

LED

ÃÙ»·Õè 3-7 ǧ¨Ã·´Åͧ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè HIGH Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%'


(3) Ãѹâ»Ãá¡ÃÁ áÅ ÇÊѧࡵ¡ÒÃáÊ´§¼Å¢Í§Ë¹ Òµ Ò§ Debug Terminal ¡Ñº¨Ñ§ËÇСÒ÷íÒ§Ò¹¢Í§ LED àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é ÁÒ¡ ͹ áÅÐáÊ´§¢ ͤÇÒÁ Before : DIRS = %0000000000000000 OUTS = %0000000000000000 LED ·ÕµÍ ¡Ñº¢Ò¾Íà µ P3 Âѧ´ÑºÍÂÙ ¨Ò¡¹Ñ¹é 1 ÇÔ¹Ò·Õ LED ·Õµè Í ¡Ñº¢Ò¾Íà µ P3 µÔ´ÊÇ Ò§¨Ò¡¼Å¢Í§¤íÒÊѧè HIGH 3 ¨Ò¡¹Ñ¹é ·ÕËè ¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¢ ͤÇÒÁ After : DIRS = %0000000000001000 OUTS = %0000000000001000

¤ ҢͧÃÕ¨ÊÔ àµÍà DIR áÊ´§Ê¶Ò¹Ð¢Í§·ÔÈ·Ò§¢Ò¾Íà µ¢Í§ i-Stamp2P24 ¡ ͹·íÒ¤íÒÊѧè à» ¹ 0 ËÁ´ ËÁÒ¶֧ ¢Ò¾Íà µ·Ø¡¢Òà» ¹ÍÔ¹¾Øµ ã¹¢³Ð·ÕÃè ¨Õ ÊÔ àµÍà OUT 㪠áÊ´§¤ ÒʶҹТͧ¾Íà µà» ¹·íҧҹ໠¹àÍÒµ ¾µØ ¡ ͹·íÒ ¤íÒÊѧè à» ¹ 0 ·Ñ§é ËÁ´ ·Ñ§é ¹Õàé » ¹¼ÅÁÒ¨Ò¡ÃÕ¨ÊÔ àµÍà DIR ·Õ¶è ¡Ù ¡íÒ˹´ãË à» ¹ÍÔ¹¾Øµ àÁ×èÍ¡ÃзíÒ¤íÒÊÑè§ HIGH ·ÕèºÔµ 3 ¢Í§ÃÕ¨ÔÊàµÍà DIR ¨Ðà»ÅÕè¹໠¹ 1 (¤ ҢͧÃÕ¨ÔÊàµÍà DIR = 0000000000001000) ·íÒãË ¡ÅÒÂà» ¹¢Ò¾Íà µàÍÒµ ¾µØ ¾Ã ÍÁ¡ÑºÁÕ¡ÒÃà¢Õ¹¤ Ò 1 ä»ÂѧºÔµ 3 ¢Í§ÃÕ¨ÊÔ àµÍà OUT ´ Ç (¤ ҢͧÃÕ¨ÊÔ àµÍà OUT = 0000000000001000) ·íÒãË ·¢Õè Ò¾Íà µ P3 ÁÕÅͨԡ 1 à¡Ô´¢Ö¹é

&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


I2CIN ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè I2CIN Pin, SlaveID, Address {\LowAddress}, [InputData]

à» ¹¤íÒÊѧè ÃѺ¢ ÍÁÙÅࢠҨҡÍØ»¡Ã³ ·ãÕè ª ¡ÒÃàª×Íè Áµ ͼ Ò¹ÃкººÑÊ I2C â´ÂÁÕ굄 ÃÒ¡Òö Ò·ʹ¢ ÍÁÙÅ »ÃÐÁÒ³ 81 ¡ÔâźԵµ ÍÇÔ¹Ò·Õ (äÁ ÃÇÁÊÑ­­Ò³µÍºÊ¹Í§µ Ò§æ) ¾ÒÃÒÁÔàµÍà Pin à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 à¾×Íè 㪠㹡ÒÃàÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 㹡Òà µÔ´µ ͡ѺÍØ»¡Ã³ ¼Ò ¹ÃкººÑÊ I2C â´Â㪠¢Ò¾Íà µ 2 ¢Ò¤×Í P0 à» ¹¢Ò¢ ÍÁÙÅ͹ءÃÁËÃ×Í SDA (Serial data) P1 à» ¹¢ÒÊÑ­­Ò³¹ÒÌ ¡Ò͹ءÃÁËÃ×Í SCL (Serial clock) 㹡ÒÃ㪠§Ò¹¨ÃÔ§µ ͧµ ͵Ñǵ Ò¹·Ò¹¤ ÒÃÐËÇ Ò§ 1.8 ¶Ö§ 4.7k: ¾ÙÅÍÑ»äÇ ·¢Õè Ò¾Íà µ·Ñ§é Êͧ´ Ç SlaveID à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ¶Ö§ 255 㪠áÊ´§¤ ÒÃËÑÊ»ÃШíÒµÑÇ (ID) ¢Í§ÍØ»¡Ã³ I2C ·Õµè ´Ô µ Í´ Ç »¡µÔ¨Ð¾Ô¨ÒóÒã¹ÃÙ»¢Í§¢ ÍÁÙÅ 8 ºÔµ â´Â 7 ºÔµº¹ (ºÔµ 1 ¶Ö§ 7) ¨Ðà» ¹¢ ÍÁÙÅÃËÑÊ੾ÒеÑǢͧ ÍØ»¡Ã³ µÇÑ ¹Ñ¹é æ «Ö§è ¡íÒ˹´ÁÒ¨Ò¡¼Ù¼ ÅÔµ Ê Ç¹ã¹ºÔµ LSB ËÃ×ͺԵ 0 ¹Ñ¹é à» ¹ºÔµ·Õãè ª ºÍ¡Ê¶Ò¹Ð¡ÒõԴµ ͡ѺÍØ»¡Ã³ I2C µÑǹѹé æ Ç Ò µ ͧ¡ÒÃÍ Ò¹ËÃ×Íà¢Õ¹¢ ÍÁÙÅ´ Ç â´Â¶ Òµ ͧ¡ÒÃÍ Ò¹¢ ÍÁÙŨСíÒ˹´ãË à» ¹ 1 áÅÐàÁ×Íè µ ͧ¡ÒÃà¢Õ¹ ¢ ÍÁÙŨСíÒ˹´ãË à» ¹ 0 ´Ñ§áÊ´§â¤Ã§Êà ҧ¢Í§¢ ÍÁÙŵÒÁÃÙ»·Õè 3-8 Address à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË ÁÕ¤ Ò෠ҡѺ 0-255 㪠¡íÒ˹´¤ ÒáÍ´à´ÃÊ·Ò§ÎÒà ´áÇà ¢Í§ ÍØ»¡Ã³ I2C ·Õµè ´Ô µ Í´ Ç «Ö§è ·Ã񼊫 ¨Ò¡Ê¶Ò¹Ð·Ò§Åͨԡ¢Í§¢Ò¡íÒ˹´áÍ´à´ÃÊ·Ò§ÎÒà ´áÇà A0 ¶Ö§ A2 ¢Í§ÍØ»¡Ã³ I2C µÑǹÑé¹æ ËÒ¡ã¹Ç§¨Ã¢Ò·Ñé§ÊÒÁµ Íŧ¡ÃÒÇ´ ËÁ´ à· Ò¡ÑºÇ Òä´ ÃѺÅͨԡ 0 ·Ñé§ËÁ´ ¤ Ò Address ¹Õé¨Ö§à· ҡѺ 0 Í ҧäáçµÒÁÊíÒËÃѺÍØ»¡Ã³ µÇÑ ã´·Õäè ÁÁÕ¢Ò A0 ¶Ö§ A2 ãË ¡Òí ˹´¤ Ò Address ¹Õàé · ҡѺ 0 àÊÁÍ Í ҧäáçµÒÁã¹ » ¨¨Øº¹Ñ áÅÐá¹Çâ¹ Áã¹Í¹Ò¤µä´ Á¡Õ ÒþѲ¹ÒÍØ»¡Ã³ I2C à¾ÔÁè ÁÒ¡¢Ö¹é ¨¹·íÒãË áÍ´à´Ãʢͧ¡ÒõԴµ Í·Õáè µ à´ÔÁãªã¹ Ãкº 7 ºÔµµ ͧà¾ÔÁè à» ¹Ãкº 10 ºÔµ (10-bit addressing) Ê §¼ÅãË µÍ §ãª µÇÑ á»Ãà¾ÔÁè àµÔÁ «Ö§è ã¹·Õ¹è ¤Õé Í× LowAddress «Ö§è ¨ÐàÃÕ¡㪠µÍ ¨Ò¡µÑÇá»Ã Address ¹Õé LowAddress à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0-255 ãªáÊ´§¤ ÒáÍ´à´ÃÊã¹ 2 ºÔµÅ Ò§¢Í§ ¡ÒõԴµ ÍẺ 10 ºÔµ ¨Ð㪠µÒÁÅíҾѧäÁ ä´ ã¹¡ÒÃ㪠§Ò¹µ ͧ¡íÒ˹´¤ Òµ ͨҡµÑÇá»Ã Address ෠ҹѹé InputData à» ¹¾×¹é ·ÕÊè Òí ËÃѺà¡çº¢ ÍÁÙÅ·ÕÍè Ò ¹ÁÒä´ ¨Ò¡ÍØ»¡Ã³ I2C ·Õµè ´Ô µ Í´ Ç â´ÂÊÒÁÒöà¯çºäÇ ä´ ã¹ ËÅÒÂÃٻẺ ·Ñ§é ÃËÑÊáÍÊ¡Õ,é àÅ¢°Ò¹Êͧ, àÅ¢°Ò¹ÊÔº, àÅ¢°Ò¹ÊԺˡ ËÃ×ÍÃٻẺ¢Í§µÑÇÍÑ¡Éà (string) ã¹µÒÃÒ§·Õè 3-4 áÊ´§ÃٻẺ¢Í§¢ ÍÁÙÅ·Õàè ¡çºä´ ¢Í§µÑÇá»Ã InputData ¹Õé ÊÒÁÒö㪠ÃÇ Á¡Ñº¤íÒÊѧè I2COUT ä´ ºÔµ 7

ºÔµ 6

ºÔµ 5

ºÔµ 4

ºÔµ 3

ºÔµ 2

ºÔµ 1

ºÔµ 0

X

X

X

X

A2

A1

A0

R/W

ºÔµ¡íÒ˹´áÍ´à´Ãʤ§·Õè

ºÔµ¡íÒ˹´áÍ´à´ÃÊ â»Ãá¡ÃÁä´

ÃÙ»·Õè 3-8 ÃٻẺ¢Í§¢ ÍÁÙÅ·Õãè ª 㹡ÒáíÒ˹´µÔ´µ ͡ѺÍØ»¡Ã³ ÃкººÑÊ I2C ã¹áºº 7 ºÔµ â´Â¼ Ò¹ µÑÇá»Ã SlaveID ¢Í§¤íÒÊѧè I2CIN áÅÐ I2COUT Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&


µÑÇ¡íÒ˹´¡ÒÃá»Å§¢ ÍÁÙÅ »ÃÐàÀ·¢Í§¢ ÍÁÙÅ ¢ ÍÁÙÅ·ÕÃè ºÑ ä´ 0 ¶Ö§ 9 àÅ¢°Ò¹ÊÔº ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-5) µ Í· ÒÂËÁÒ¶֧ DEC {1...5} ¨íҹǹËÅÑ¡·ÕèáÊ´§ -, 0 ¶Ö§ 9 àÅ¢°Ò¹ÊԺẺ¤Ô´à¤Ã×èͧËÁÒ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-5) SDEC {1...5} µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ 0 ¶Ö§ 9 áÅÐ àÅ¢°Ò¹ÊԺˡ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· Ò HEX {1...4} ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ A ¶Ö§ F SHEX {1...4} àÅ¢°Ò¹ÊԺˡẺ¤Ô´à¤Ã×èͧËÁÒ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-5) -, 0 ¶Ö§ 9 áÅÐ µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ A ¶Ö§ F IHEX {1...4} $, 0 ¶Ö§ 9 áÅÐ àÅ¢°Ò¹ÊԺˡâ´ÂáÊ´§ÊÑ­Åѡɳ $ ¹íÒ˹ Ò àª ¹ $37A à» ¹µ ¹ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· ÒÂËÁÒ¶֧ A ¶Ö§ F ¨íҹǹËÅÑ¡·ÕèáÊ´§

ËÁÒÂà赯 1

ISHEX {1...4}

àÅ¢°Ò¹ÊԺˡẺ¤Ô´à¤Ã×èͧËÁÒ â´ÂáÊ´§ÊÑ­Åѡɳ $ ¹íÒ˹ Ò ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· ÒÂËÁÒ¶֧ ¨íҹǹËÅÑ¡·ÕèáÊ´§

-, $, 0 ¶Ö§ 9 áÅÐ A ¶Ö§ F

1, 2, 3, 4

BIN {1...16}

àÅ¢°Ò¹Êͧ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· Ò ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ àÅ¢°Ò¹ÊͧẺ¤Ô´à¤Ã×èͧËÁÒ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-16) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ àÅ¢°Ò¹Êͧâ´ÂáÊ´§ÊÑ­Åѡɳ % ¹íÒ˹ Ò àª ¹ %10111000 à» ¹µ ¹ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-16) µ Í· Ò ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§

0, 1

1

-, 0, 1

1, 2

%, 0, 1

1, 4

-,%, 0, 1

1, 2, 4

SBIN {1...16} IBIN {1...16}

1, 2 1, 3 1, 2, 3 1, 3, 4

ISBIN {1...16}

àÅ¢°Ò¹ÊͧẺ¤Ô´à¤Ã×èͧËÁÒ â´ÂáÊ´§ÊÑ­Åѡɳ % ¹íÒ˹ Ò ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· Ò ËÁÒ¶֧ ¨íҹǹËÅÑ¡·ÕèáÊ´§

ÃٻẺ¡ÒÃÃѺ¢ ÍÁÙÅ STR ByteArray \L {\E}

ÃÒÂÅÐàÍÕ´ ÃѺ¢ ÍÁÙŵÑÇÍÑ¡ÉÃÁÕ¤ÇÒÁÂÒÇ෠ҡѺ·Õè¡íÒ˹´äÇ ã¹ µÑÇá»Ã L à¡çºÅ§ä»ã¹áÍà ààÊÒÁÒö¡íÒ˹´ÍÑ¡Éû ´· ÒÂŧ㹵ÑÇá»Ã E ä´ â´ÂäÁ ¨íÒà» ¹µ ͧÃѺ¢ ÍÁÙÅãË ¤ÃºµÒÁ¨íҹǹ ·Õè¡íÒ˹´äÇ ã¹µÑÇá»Ã L ¶ ÒËÒ¡¢ ÍÁÙÅ·ÕèࢠÒÁÒäÁ ¤ÃºµÒÁ·Õè¡íÒ˹´ ·ÕèàËÅ×ͨÐä´ ÃѺ¡ÒáíÒ˹´ ãË à» ¹ "0"

WAITSTR ByteArray {\L}

ÃͤÍ¢ ÍÁÙŵÑÇÍÑ¡É÷Õèµ Í§¡ÒÃáÅ Çà¡çºÅ§ã¹áÍà ààÊÒÁÒö¡íÒ˹´¤ÇÒÁÂÒǢͧµÑÇÍÑ¡ÉÃ ä´ ·ÕèµÑÇá»Ã L áµ ¶ ÒËÒ¡äÁ ÁÕ¡ÒáíÒ˹´ ¨Ðµ ͧ¡íÒ˹´¨Ø´ÊÔé¹ÊØ´¢Í§áÍà áഠǢ ÍÁÙÅ "0" äÁ ʹ㨤ÇÒÁÂÒǢͧ¢ ÍÁÙÅ

SKIP Length

ËÁÒÂà赯 (1) ¡ÒÃá»Å§¢ ÍÁÙŵÑÇàÅ¢¨Ð¡ÃзíÒÍ ҧµ Íà¹×èͧ ¨¹¡Ç Ò¨Ðä´ ¨íҹǹ¤ÃºµÒÁ·Õè¡íÒ˹´ (2) 㹡óÕ㪠à¤Ã×èͧËÁÒÂź (-) ¨Ðµ ͧµÒÁ´ ǵÑÇàÅ¢àÊÁÍ ÁԩйÑ鹨Ðà¡Ô´¡ÒõդÇÒÁÇ Òà» ¹µÑÇÍÑ¡Éà (3) ¢ ÍÁÙŵÑÇàÅ¢°Ò¹ÊԺˡäÁ ʹã¨Ç Ò¨Ðà» ¹µÑǾÔÁ¾ àÅç¡ËÃ×͵ÑǾÔÁ¾ ãË­ ¹Ñ蹤×Í a ¡Ñº A ÁÕ¤ÇÒÁËÁÒÂàËÁ×͹¡Ñ¹ (4) ¨ÐäÁ ʹ㨢 ÍÁÙÅ·ÕèÁÕ¡ÒüÊÁ¡ÑºµÑÇÍÑ¡É÷ÕèäÁ 㪠µÑÇàÅ¢ â´Âµ ͧÁÕ¡ÒÃãÊ à¤Ã×èͧËÁÒ $ ÊíÒËÃѺàÅ¢°Ò¹ÊԺˡ áÅÐ % ÊíÒËÃѺ àÅ¢°Ò¹Êͧ

µÒÃÒ§·Õè 3-4 ÃÒÂÅÐàÍÕ´ÃٻẺ¢Í§¢ ÍÁÙÅ·ÕÊè ÒÁÒÃ¶ãª ä´ ã¹µÑÇá»Ã InputData ¢Í§¤íÒÊѧè I2CIN &

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ãͺá¡·Õè 3-1 : ¤ÇÒÁÃÙà º×Íé §µ ¹¢Í§ÃкººÑÊ I2C I2C  ÍÁÒ¨Ò¡ Inter-IC Communication ËÁÒ¶֧ ¡ÒõԴµ ÍÊ×Íè ÊÒÃÃÐËÇ Ò§äÍ«Õ â´ÂºÑÊ I2C ä´ ÃºÑ ¡ÒþѲ¹Ò¢Ö¹é â´Â¿ ÅÔ»Ê (Philips) ´ ǨشÁØ §ËÁÒÂËÅÑ¡¤×Í µ ͧ¡ÒÃãË äÍ«ÕËÃ×ÍâÁ´ÙÅÊÒÁÒöµÔ´µ Í ÊÑ觧ҹ áÅФǺ¤ØÁÀÒÂãµ ÊÒ ÊÑ­­Ò³à¾Õ§ 2 àÊ ¹ àÊ ¹Ë¹Ö§è ¤×Í ÊÒ¢ ÍÁÙÅ ÍÕ¡àÊ ¹Ë¹Ö§è ¤×Í ÊÒÂÊÑ­­Ò³¹ÒÌ ¡Ò·Õãè ª 㹡ÒáíÒ˹´¨Ñ§ËÇСÒ÷íÒ§Ò¹ ¡Òõ Í Ã ÇÁ¡Ñ¹¢Í§ÍØ»¡Ã³ º¹ºÑÊ I2C ·íÒä´ §Ò ÂÁÒ¡ à¾Õ§µ ÍÊÒ¢ ÍÁÙÅáÅÐÊÒÂÊÑ­­Ò³¹ÒÌ ¡Ò¢Í§ÍØ»¡Ã³ áµ ÅеÑÇ¢¹Ò¹¡Ñ¹ä» Ê Ç¹¡ÒáíÒ˹´áÍ´à´ÃÊÊíÒËÃѺµÔ´µ ÍÍØ»¡Ã³ áµ ÅеÑÇ ¨Ð㪠ÃËÑÊ¢ ÍÁÙÅà ÇÁ¡Ñº¡ÒáíÒ˹´ÊÀÒÇÐÅͨԡ·Õè¢ÒáÍ´à´ÃÊ ÊÒ¢ ÍÁÙź¹ºÑÊ I2C ÁÕªÍ×è àÃÕ¡Í ҧ໠¹·Ò§¡ÒÃÇ Ò ÊÒ¢ ÍÁÙÅ͹ءÃÁ ËÃ×Í SDA (Serial Data line) Ê Ç¹ÊÒ ÊÑ­­Ò³¹ÒÌ ¡ÒÁÕªÍ×è àÃÕÂ¡Ç Ò ÊÒÂÊÑ­­Ò³¹ÒÌ ¡Ò͹ءÃÁ ËÃ×Í SCL (Serial Clock line) 㹡ÒÃ͸ԺÒµ Í仹ըé ÐàÃÕ¡ ÊÒÂÊÑ­­Ò³·Ñ§é ÊÍ§Ç Ò ÊÒ SDA áÅÐ SCL

¤Ø³ÊÁºÑµâÔ ´Â·ÑÇè 仢ͧºÑÊ I2C ÊÒ SDA áÅÐ SCL à» ¹ÊÒÂÊÑ­­Ò³ 2 ·ÔÈ·Ò§ (bi-directional line) µ ͧÁÕ¡Òõ ͵Ñǵ Ò¹·Ò¹¾ÙÅÍÑ»¡Ñºáç´Ñ¹ +5V äÇ µÅÍ´àÇÅÒ à¾×Íè ãË ÊÒÂÁÕʶҹÐÅͨԡÊ٧㹢³Ð·Õäè Á Á¡Õ ÒõԴµ Í㪠§Ò¹ ·Ñ§é Âѧª ÇÂ㹡Òû ͧ¡Ñ¹ÊÑ­­Ò³Ãº¡Ç¹·Õè ÍÒ¨ÁÕࢠÒÁÒã¹ÊÒÂÊÑ­­Ò³·Ñ§é Êͧǧ¨ÃàÍÒµ ¾µØ ¢Í§ÍØ»¡Ã³ ·µÕè Í ÍÂÙº ¹ºÑÊ I2C µ ͧÁÕÅ¡Ñ É³Ðà» ¹Ç§¨Ãà´Ã¹à» ´ (opendrain) ËÃ×ͤÍÅàÅç¡àµÍà ໠´ (open-collector) ´Ñ§áÊ´§ÃÒÂÅÐàÍÕ´ã¹ÃÙ»·Õè A3-1 ÍѵÃÒ¡Òö Ò·ʹ¢ ÍÁÙź¹ºÑÊ I2C ÊÙ§¶Ö§ 100 ¡ÔâźԵµ ÍÇÔ¹Ò·Õã¹âËÁ´»¡µÔ (standard mode) áÅÐÊÙ§¶Ö§ 400 ¡ÔâÅ ºÔµµ ÍÇÔ¹Ò·Õã¹âËÁ´¤ÇÒÁàÃçÇÊÙ§ (fast mode) (µÒÁ¤Ø³ÊÁºÑµ·Ô ҧ෤¹Ô¤·Õè Philips ¡íÒ˹´) ÍØ»¡Ã³ ·µÕè Í Ã ÇÁÍÂÙº ¹ºÑÊ I2C ¨Ðµ ͧÁÕ¤Ò ¤ÇÒÁ¨Øä¿¿ ÒÃÇÁ·Õàè ¡Ô´¢Ö¹é ÃÐËÇ Ò§ÊÒ SDA áÅÐ SCL äÁ à¡Ô¹ 400pF ¡ÒÃࢠҶ֧ÍØ»¡Ã³ º¹ºÑÊ I2C 㪠¢Í ÁÙÅ ÊíÒËÃѺ¡ÒÃࢠҶ֧ 2 ¤ Ò¤×Í 7 ºÔµ (7-bit addressing) ËÃ×Í 10 ºÔµ (10-bit addressing)

ËÅÑ¡¡ÒâͧºÑÊ I2C ºÑÊ I2C »ÃСͺ´ ÇÂÊÒÂÊÑ­­Ò³ 2 àÊ ¹ ´Ñ§·Õäè ´ ¡Å ÒÇÁÒáŠǤ×Í SDA áÅÐ SCL ÍØ»¡Ã³ ·µÕè Í ¾ ǧº¹ºÑÊÊÒÁÒö ÁÕä´ ÁÒ¡ÁÒ ´Ñ§¹Ñ¹é ¨Ö§µ ͧÁÕ¡ÒáíÒ˹´ÃٻẺ¢Í§¡ÒõԴµ ͺ¹ºÑÊ ËÃ×ÍàÃÕÂ¡Ç Ò â»ÃⵤÍÅ (protocol) à¾×Íè ãË ¼ãÙ ª §Ò¹ ·ÃÒºÇ Ò ¢³Ð¹ÕÍé »Ø ¡Ã³ ã´µÔ´µ ͡ѹÍÂÙ áÅÐÍØ»¡Ã³ µÇÑ ã´à» ¹µÑÇÃѺËÃ×͵ÑÇÊ § µ Í仹ըé ТÍ͸ԺÒÂÅѡɳР˹ Ò·Õè áÅйÔÂÒÁ ¢Í§ÍØ»¡Ã³ ·µÕè Í ÍÂÙº ¹ºÑÊ I2C à¾×Íè à» ¹¢ ͵¡Å§¾×¹é °Ò¹¡ ͹·Õ¨è Ð͸ԺÒ¡Ò÷íÒ§Ò¹¢Í§ºÑÊ I2C µ Íä» ÍØ»¡Ã³ ·àÕè » ¹¼ÙÊ Ã Ò§¢ ÍÁÙÅËÃ×ÍÊ §¢ ÍÁÙÅ àÃÕÂ¡Ç Ò µÑÇÊ § (transmitter) ÍØ»¡Ã³ ·àÕè » ¹¼Ùà ºÑ ¢ ÍÁÙÅ àÃÕÂ¡Ç Ò µÑÇÃѺ (receiver) ã¹ÍØ»¡Ã³ º¹ºÑÊ I2C ÊÒÁÒö໠¹ä´ ·Ñ駵ÑÇÃѺáÅеÑÇÊ § ºÒ§ÍØ»¡Ã³ ·íÒ˹ Ò·Õèà» ¹µÑÇÃѺà¾Õ§Í ҧà´ÕÂÇ ¨ÐäÁ ÁÕ ÍØ»¡Ã³ ã´º¹ºÑÊ I2C ·Õ·è Òí ˹ Ò·Õàè » ¹µÑÇÊ §à¾Õ§Í ҧà´ÕÂÇ ÍØ » ¡Ã³ ·Õè ·í Ò Ë¹ Ò ·Õè ¤ Ǻ¤Ø Á ¨Ñ § ËÇСÒ÷í Ò §Ò¹ ËÃ×Í¡ÒõԴµ ͺ¹ºÑÊ I2C àÃÕÂ¡Ç Ò ÁÒÊàµÍà (master) ÍØ»¡Ã³ ·Õè¶Ù¡¤Çº¤ØÁËÃ×ÍÍØ»¡Ã³ ·Õèµ Í¾ ǧࢠÒä» º¹ºÑÊ I2C àÃÕÂ¡Ç Ò ÊàÅ¿ (slave) ¢ Í¡íÒ˹´¢Í§¡ÒõԴµ ͺ¹ºÑÊ I2C ¤×Í (1) ¡Òö Ò·ʹ¢ ÍÁÙŨÐà¡Ô´¢Ö¹é ä´ àÁ×Íè ºÑÊÇ Ò§à· Ò¹Ñ¹é (2) ã¹ÃÐËÇ Ò§¡Òö Ò·ʹ¢ ÍÁÙÅ àÁ×èÍÊÒ SCL ÁÕʶҹÐÅͨԡÊÙ§ ÊÒ¢ ÍÁÙŵ ͧÃÑ¡ÉÒ¢ ÍÁÙÅäÇ Í ÒãË à¡Ô´ ÍØ»¡Ã³ ºÑÊ µÑÇ·Õè 1 ÍØ»¡Ã³ ºÑÊ µÑÇ·Õè 2 ¡ÒÃà»ÅÕÂè ¹á»Å§¢Ö¹é à´ç´¢Ò´ Áԩйѹé ÊÑ­­Ò³·Õàè ¡Ô´¢Ö¹é ¨Ð ÃÙ»·Õè A3-1 â¤Ã§Êà ҧǧ¨Ã·Ò§àÍÒµ ¾µØ ¢Í§ÍØ»¡Ã³ º¹ ä´ ÃºÑ ¡ÒÃá»Å¤ÇÒÁËÁÒÂà» ¹ÊÑ­­Ò³¤Çº¤ØÁá·¹ +5V

R2

SDA (Serial Data line)

R2

SCL (Serial Clock line)

SCLKN1 OUT

DATAN1 OUT

SCLKN2 OUT

DATAN2 OUT

SCLK IN

DATA IN

SCLK IN

DATA IN

IC

IC

ÃкººÑÊ I2C

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&!


ÊÀÒÇзÕàè ¡Ô´¢Ö¹é º¹ºÑÊ I2C ÁÕ´Ç Â¡Ñ¹ 5 ÊÀÒÇÐ ´Ñ§¹Õé (1) ºÑÊÇ Ò§ (Bus not busy) ÊÀÒÇйÕàé ¡Ô´¢Ö¹é àÁ×Íè ʶҹÐÅͨԡº¹ÊÒ SDA áÅÐ SCL à» ¹ÅͨԡÊÙ§·Ñ§é ¤Ù ¹Ñ¹è ËÁÒ ¤ÇÒÁÇ Ò ¡Òö Ò·ʹ¢ ÍÁÙÅÊÒÁÒöàÃÔÁè µ ¹¢Ö¹é ä´ (2) àÃÔÁè µ ¹¡Òö Ò·ʹ¢ ÍÁÙÅ (start data transfer) à¡Ô´¢Ö¹é àÁ×Íè ÊÒ SDA ÁÕ¡ÒÃà»ÅÕÂè ¹á»Å§ÃдѺÅͨԡ¨Ò¡ÊÙ§ 仵èÒí ã¹¢³Ð·ÕÊè Ò SCL ÁÕʶҹÐÅͨԡÊÙ§ àÃÕ¡ÊÀÒÇзÕàè ¡Ô´¢Ö¹é ¹ÕÇé Ò ÊÀÒÇÐàÃÔÁè µ ¹ (START) (3) ¢ ÍÁÙÅ´íÒçÍÂÙº ¹ºÑÊ (data valid) ÊÀÒÇйÕàé ¡Ô´¢Ö¹é ¶Ñ´¨Ò¡ÊÀÒÇÐàÃÔÁè µ ¹ â´ÂʶҹÐÅͨԡ·Õàè ¡Ô´¢Ö¹é º¹ÊÒ SDA ¡ç¤×Í¢ ÍÁÙÅ·Õè·íÒ¡Òö Ò·ʹ àÁ×èÍÊÒ SCL à» ¹ÅͨԡÊÙ§ ʶҹзÕèÊÒ SDA µ ͧ¤§·Õè à¾×èÍãË ÍØ»¡Ã³ ÃѺÃÙ ¢ ÍÁÙÅã¹ ¨Ñ§ËÇйѹé Ç Ò à» ¹ 0 ËÃ×Í 1 ¢ ÍÁÙÅÍÒ¨à¡Ô´¡ÒÃà»ÅÕÂè ¹á»Å§ä´ ã¹¢³Ð·ÕÊè Ò SCL à» ¹ÅͨԡµèÒí áµ àÁ×Íè ã´¡çµÒÁ·Õµè Í § ¡ÒÃãË à¡Ô´¡Òö Ò·ʹ¢ ÍÁÙÅÍ ҧÊÁºÙó ʶҹÐÅͨԡ·Õ¢è Ò SDA µ ͧ¤§·Õµè ÅÍ´ª ǧàÇÅÒ·ÕÊè Ò SCL ÁÕʶҹÐÅͨԡÊÙ§ ËÒ¡à¡Ô´¡ÒÃà»ÅÕÂè ¹á»Å§Ê¶Ò¹ÐÅͨԡ㹢³Ð·ÕÊè Ò SCL ÁÕÅͨԡÊÙ§ÍÂÙ¹ ¹Ñé ÍØ»¡Ã³ ÁÒÊàµÍà ··Õè Òí ¡ÒäǺ¤ØÁ¡Òö Ò·Í´ ¢ ÍÁÙŨÐá»Å¤ÇÒÁËÁÒÂà» ¹ÊÀÒÇÐËÂØ´ËÃ×ÍÊÀÒÇÐàÃÔÁè µ ¹¡çä´ ·íÒãË ¢Í ÁÙÅ·Õ·è Òí ¡Òö Ò·ʹ¹Ñ¹é à¡Ô´¤ÇÒÁ¼Ô´¾ÅÒ´¢Ö¹é (4) ÃѺÃÙ¢ Í ÁÙÅ (acknowledge) à¡Ô´¢Ö¹é ËÅѧ¨Ò¡·Õ¡è Òö Ò·ʹ¢ ÍÁÙŨҡµÑÇÊ §ÁÒÂѧµÑÇÃѺà¡Ô´¢Ö¹é Í ҧÊÁºÙó â´Â µÑÇÊ §¨Ð·íÒ¡ÒÃÊ §¢ ÍÁÙÅÁÒ 1 ºÔµàÃÕÂ¡Ç Ò ºÔµÃѺÃÙ (acknowledge bit) ÁÕʶҹÐà» ¹ÅͨԡÊÙ§ ËÅѧ¨Ò¡Ê §¢ ÍÁÙÅÁҤú¶ ǹ Ê Ç¹ÍØ»¡Ã³ ÁÒÊàµÍà ¨Ð·íÒ¡ÒÃÊ §ÊÑ­­Ò³ÃѺÃÙ¾ àÔ ÈÉ«Ö§è ÊÑÁ¾Ñ¹¸ ¡ºÑ ÊÑ­­Ò³¹ÒÌ ¡Ò ÍØ»¡Ã³ ÊàÅ¿·Õ¶è ¡Ù Í Ò§¶Ö§ã¹¡ÒõԴµ Í Ë Ã× Í ¡í Ò ÅÑ § µÔ ´ µ Í Í ÂÙ ã ¹ ¢ ³ Ð ¹Ñé ¹ ¡ç ¨ Ð ¡í Ò à ¹Ô ´ ºÔ µ ÃÑ º ÃÙ ·Õè ÁÕ Ê ¶ Ò ¹ Ð Å Í ¨Ô ¡ µèí Ò à ¾×è Í µ Í º Ê ¹ Í § ã Ë · Ã Ò º Ç Ò ä ´ ÃѺ¢ ÍÁÙÅã¹áµ ÅÐ亵 àÃÕºà ÍÂáÅ Ç (5) ËÂØ´¡Òö Ò·ʹ¢ ÍÁÙÅ (stop data transfer) à¡Ô´¢Ö¹é àÁ×Íè ÊÒ SDA ÁÕ¡ÒÃà»ÅÕÂè ¹á»Å§ÃдѺÅͨԡ¨Ò¡µèÒí ä» ÊÙ§ ã¹¢³Ð·ÕÊè Ò SCL ÁÕʶҹÐÅͨԡÊÙ§ àÃÕ¡ÊÀÒÇзÕàè ¡Ô´¢Ö¹é ¹ÕÇé Ò ÊÀÒÇÐËÂØ´ (STOP) ã¹ÃÙ»·Õè A3-2 à» ¹ä´ÍÐá¡ÃÁàÇÅÒ·Õáè Ê´§¶Ö§¡ÒÃà¡Ô´ÊÀÒÇе Ò§æ º¹ºÑÊ I2C äÁ ÇÒ ¨Ðà» ¹ÊÀÒÇкÑÊÇ Ò§,àÃÔÁè µ ¹, ¶ Ò ·Í´¢ ÍÁÙÅ, ÃѺÃÙ áÅÐËÂØ´¡Òö Ò·ʹ¢ ÍÁÙÅ

¡Ò÷íÒ§Ò¹º¹ºÑÊ I2C ¡ ͹·Õ¨è ÐàÃÔÁè µ ¹¡Òö Ò·ʹ¢ ÍÁÙÅÃÐËÇ Ò§ÍØ»¡Ã³ µÒ §æ ·Õµè Í ÍÂÙº ¹ºÑÊ µ ͧÁÕ¡ÒÃÍ Ò§¶Ö§ÍØ»¡Ã³ àÊÕ¡ ͹ â´Â¡ÒÃ Í Ò§¶Ö§ÍØ»¡Ã³ º¹ºÑÊ I2C ¹Ñ¹é ¨Ð㪠¡ÒÃÍ Ò§¶Ö§áºº 7 ºÔµËÃ×Í 10 ºÔµ 㹡óշÁÕè ÍÕ »Ø ¡Ã³ µÍ ÍÂÙº ¹ºÑÊäÁ ÁÒ¡ 㪠¡ÒÃÍ Ò§¶Ö§ Ẻ 7 ºÔµ¡çà¾Õ§¾Í áµ ¶Ò ÁÕÍ»Ø ¡Ã³ µÍ ÍÂÙº ¹ºÑÊÁÒ¡¡Ç Ò 127 áÍ´à´ÃÊ ¨íÒà» ¹µ ͧ㪠¡ÒÃÍ Ò§¶Ö§áºº 10 ºÔµ ËÅѧ¨Ò¡·Õè µÔ´µ ÍÍØ»¡Ã³ áµ ÅеÑÇä´ àÃÕºà ÍÂáÅ Ç ¡ç¨ÐàÃÔèÁµ ¹¡Òö Ò·ʹ¢ ÍÁÙšѹµ Íä» SDA à»ÅÕÂè ¹¨Ò¡ "1" à» ¹ "0" ã¹¢³Ð·Õè SCL à» ¹ "1" ¹Õ¤è Í× ÊÀÒÇÐàÃÔÁè µ ¹

SDA à»ÅÕÂè ¹¨Ò¡ "0" à» ¹ "1" ã¹¢³Ð·Õè SCL à» ¹ "1" ¹Õ¤è Í× ÊÀÒÇÐËÂØ´

SDA

SCL

SDA à» ¹ "1" SCL à» ¹ "1" ÊÀÒÇкÑÊÇ Ò§

SDA ¤§·Õ·è ÅèÕ Í¨Ô¡ "1" SDA ¤§·Õ·è ÅèÕ Í¨Ô¡ "0" ã¹¢³Ð·Õè SCL à» ¹ "1" ¶×Íà» ¹ ã¹¢³Ð·Õè SCL à» ¹ "1" ¶×Íà» ¹ ¡Òö Ò·ʹ¢ ÍÁÙÅ "1" ¡Òö Ò·ʹ¢ ÍÁÙÅ "0"

ÃÙ»·Õè A3-2 ä´ÍÐá¡ÃÁàÇÅÒáÊ´§Ê¶Ò¹Ðµ Ò§æ º¹ÃкººÑÊ I2C

&"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


ºÔµ 7

ºÔµ 6

ºÔµ 5

ºÔµ 4

ºÔµ 3

ºÔµ 2

ºÔµ 1

¡ÒÃÍ Ò§¶Ö§áºº 7 ºÔµ (7-bit addressing)

ºÔµ 0

¢ ÍÁÙÅ亵 áá·Õèà¡Ô´¢Öé¹ËÅѧ¨Ò¡ÊÀÒÇÐàÃÔèÁµ ¹¤×Í ºÔµ¡íÒ˹´áÍ´à´Ãʤ§·Õè ¢ ÍÁÙÅ·Õãè ª 㹡ÒÃÍ Ò§¶Ö§ÍØ»¡Ã³ ·µÕè Í §¡ÒõԴµ Í â´ÂÁÕû٠ẺáÊ´§ã¹ÃÙ»·Õè A3-3 ã¹ 7 ºÔµº¹ÃÇÁ·Ñ§é ºÔµ MSB ´ Ç ÃÙ»·Õè A3-3 ÃٻẺ¢ ÍÁÙÅ㹡ÒÃÍ Ò§áÍ´à´ÃÊ ¨Ðà» ¹¢ ÍÁÙÅáÍ´à´ÃʢͧÍØ»¡Ã³ ÊàÅ¿·Õèµ Í§¡ÒõԴµ Í â´ÂẠ§à» ¹ ºÔµ¡íÒ˹´áÍ´à´Ãʤ§·Õè (fixed address bit) ¨íҹǹ 4 ºÔµ «Ö§è ¢ ÍÁÙŹÕÍé »Ø ¡Ã³ áµ ÅеÑǨж١¡íÒ˹´ÁÒ¨Ò¡ ¼Ù ¼ÅÔµ äÁ ÊÒÁÒöà»ÅÕè¹á»Å§á¡ ä¢ä´ ¶Ñ´ÁÒÍÕ¡ 3 ºÔµà» ¹ºÔµ¡íÒ˹´áÍ´à´ÃÊ·ÕèÊÒÁÒöâ»Ãá¡ÃÁä´ (programmable address bit) â´Â¼Ùã ª §Ò¹µ ͧ¡íÒ˹´Ê¶Ò¹ÐÅͨԡãË á¡ ¢Ò A0 ¶Ö§ A2 ¢Í§ÍØ»¡Ã³ ·ÁÕè ¡Õ ÒÃàª×Íè Áµ ÍẺºÑÊ I2C Ê Ç¹ã¹ºÔµ LSB à» ¹ºÔµ·Õãè ª ¡Òí ˹´¡ÒÃÍ Ò¹ËÃ×Íà¢Õ¹¢ ÍÁÙšѺÍØ»¡Ã³ ÊàÅ¿µÑǹѹé æ ËÒ¡ºÔµ LSB à» ¹ 0 ËÁÒ¶֧µ ͧ¡ÒÃà¢Õ¹ ¢ ÍÁÙÅä»ÂѧÍØ»¡Ã³ ¹¹Ñé ¶ Òà» ¹ 1 ¨Ðà» ¹¡ÒÃÍ Ò¹¢ ÍÁÙŨҡÍØ»¡Ã³ ÊàÅ¿ ¢ ÍÁÙÅã¹äºµ µÍ ÁÒ¤×Í ¢ ÍÁÙŤǺ¤ØÁ (control byte) ã¹ÍØ»¡Ã³ áµ ÅеÑÇÁÕ¡ÒáíÒ˹´¢ ÍÁÙŤǺ¤ØÁ·Õáè µ¡µ Ò§¡Ñ¹ ä» Â¡µÑÇÍ ҧ äÍ«Õ¢ÂÒ¾Íà µÁÕ¢Í ÁÙŤǺ¤ØÁ·Õãè ª ¡Òí ˹´Ç Ò ºÔµã´à» ¹ÍÔ¹¾Øµ ºÔµã´à» ¹àÍÒµ ¾µØ ã¹¢³Ð·Õäè Í«Õ ADC/DAC µ ͧ¡Òâ ÍÁÙŤǺ¤ØÁà¾×Íè ¡íÒ˹´ãË ·Òí §Ò¹à» ¹Ç§¨Ã ADC ËÃ×Í DAC à» ¹µ ¹ ¢ ÍÁÙÅã¹äºµ µÍ ÁÒ¤×Í ¢ ÍÁÙÅ·Õ·è Òí ¡Òö Ò·ʹ¨ÃÔ§ (data) ËÅѧ¨Ò¡·ÕÁè ¡Õ Òö Ò·ʹ¢ ÍÁÙÅã¹áµ ÅÐ亵 ÍØ»¡Ã³ ÊàÅ¿·Õäè ´ ÃºÑ ¡ÒõԴµ ͵ Í§Ê §ÊÑ­­Ò³ÃѺÃÙµ ͺ¡ÅѺÁÒ´ Ç·ء ¤Ãѧé ã¹ÃÙ»·Õè A3-4 áÊ´§ÃٻẺ¢ ÍÁÙÅ͹ءÃÁ·Õàè ¡Ô´¢Ö¹é 㹡ÒõԴµ ͺ¹ºÑÊ I2C ¢Í§¡ÒÃÍ Ò§¶Ö§áºº 7 ºÔµ X

X

X

X

A2

A1

A0

R/W

ºÔµ¡íÒ˹´áÍ´à´ÃÊ â»Ãá¡ÃÁä´

¡ÒÃÍ Ò§¶Ö§áºº 10 ºÔµ ¨ÐÁÕ¢ ÍÁÙÅà¾ÔèÁàµÔÁ¢Öé¹ÁÒàÅ硹 Í â´Âã¹äºµ ááËÅѧ¨Ò¡à¡Ô´ÊÀÒÇÐàÃÔèÁµ ¹ µ ͧ¡íÒ˹´ãË 5 ºÔµº¹ÁÕ¢ ÍÁÙÅà» ¹ 11110 Ê Ç¹ÍÕ¡ 2 ºÔµ¶Ñ´ÁÒà» ¹ºÔµáÍ´à´ÃʢͧÍØ»¡Ã³ ·µÕè Í §¡ÒõԴµ Í ã¹ºÔµ LSB ¢Í§¢ ÍÁÙÅ亵 ááÂѧ¤§à» ¹¡ÒáíÒ˹´ Ç Ò µ ͧ¡ÒÃÍ Ò¹ËÃ×Íà¢Õ¹¢ ÍÁÙšѺÍØ»¡Ã³ ÊàÅ¿µÑÇ·Õèµ Í§¡ÒõԴµ Í´ Ç ¢ ÍÁÙÅ亵 µ ÍÁÒà» ¹¢ ÍÁÙÅáÍ´à´ÃÊã¹äºµ ·Õè 2 ¢Í§ÍØ»¡Ã³ ·µÕè Í §¡ÒõԴµ Í´ Ç ¢ ÍÁÙÅ亵 ¶´Ñ 仨֧໠¹¢ ÍÁÙŤǺ¤ØÁ ¢ ÍÁÙÅËÅѧ¨Ò¡¹Ñ¹é ¡ç¨Ðà» ¹¢ ÍÁÙŨÃÔ§·Õãè ª 㹡ÒõԴµ Í àª ¹à´ÕÂǡѺ¡ÒÃÍ Ò§¶Ö§áºº 7 ºÔµ ËÅѧ¨Ò¡¶ Ò·ʹ¢ ÍÁÙŤú·Ø¡äºµ µ ͧÁÕÊÀÒÇÐÃѺÃÙà ¡Ô´¢Ö¹é à¾×Íè ãË ¡Ãкǹ¡Òà ¶ Ò·ʹ¢ ÍÁÙÅÊÒÁÒö´íÒà¹Ô¹µ Íä»ä´ ã¹ÃÙ»·Õè A3-5 áÊ´§ÃٻẺ¢ ÍÁÙÅ͹ءÃÁ¢Í§¡ÒÃÍ Ò§¶Ö§áºº 10 ºÔµ ¢ ÍÁÙÅ亵 ·èÕ 1 àÅ×Í¡áÍ´à´Ãʢͧ ÍØ»¡Ã³ ·µèÕ Í §¡ÒõԴµ Í áÅШشÁا ËÁÒÂ㹡Òà µÔ´µ Í (Í Ò¹ËÃ×Íà¢Õ¹)

àÃÔÁè µ ¹

A6-A0

¢ ÍÁÙÅ亵 ·èÕ 2 Ê §¢ ÍÁÙŤǺ¤ØÁ¡Òà ·íÒ§Ò¹¢Í§ÍØ»¡Ã³ ·Õµè Í §¡ÒõԴµ ÍËÃ×Í control word R/W=0

ÃѺÃÙ

C6-C0

Ê §ÁÒ¨Ò¡ÍØ»¡Ã³ ÊàÅ¿·Õ·è Òí ¡ÒõԴµ Í´ ÇÂ

¢ ÍÁÙÅ亵 µÍ ä» (n 亵 ) ¢ ÍÁÙŨÃÔ§·Õµè Í §¡Òö Ò·ʹ R/W

ÃѺÃÙ

ÃѺÃÙ

D7-D0

ËÂØ´

Ê §ÁÒ¨Ò¡ÍØ»¡Ã³ ÊàÅ¿·Õ·è Òí ¡ÒõԴµ Í´ ÇÂ

ÃÙ»·Õè A3-4 ÃٻẺ¢ ÍÁÙÅ㹡ÒÃÍ Ò§¶Ö§áºº 7 ºÔµ ¢ ÍÁÙÅ亵 ·èÕ 1 àÅ×Í¡¡ÒÃÍ Ò§¶Ö§áºº 10 ºÔµ (¢ ÍÁÙŤ×Í 11110xx â´Â xx ¤×Í ºÔµáÍ´à´ÃÊ 2 ºÔµº¹)

àÃÔÁè µ ¹

)' )&

R/W=0 ÃѺÃÙ

¢ ÍÁÙÅ亵 ·èÕ 3 Ê §¢ ÍÁÙŤǺ¤ØÁ ¡Ò÷íÒ§Ò¹ ¢Í§ÍØ»¡Ã³ ·µèÕ Í §¡Òà µÔ´µ ÍËÃ×Í control word

¢ ÍÁÙÅ亵 ·èÕ 2 ¢ ÍÁÙÅáÍ´à´ÃÊ 8 ºÔµÅ Ò§

A7-A0

ÃѺÃÙ

C6-C0

¢ ÍÁÙÅ亵 µÍ ä» (n 亵 ) ¢ ÍÁÙŨÃÔ§·Õµè Í §¡Òà ¶ Ò·ʹ

R/W

Ê §ÁÒ¨Ò¡ÍØ»¡Ã³ ÊàÅ¿ ·Õ·è Òí ¡ÒõԴµ Í´ ÇÂ

ÃѺÃÙ

D7-D0

ÃѺÃÙ ËÂØ´

Ê §ÁÒ¨Ò¡ÍØ»¡Ã³ ÊàÅ¿ ·Õ·è Òí ¡ÒõԴµ Í´ ÇÂ

ÃÙ»·Õè A3-5 ÃٻẺ¢ ÍÁÙÅ㹡ÒÃÍ Ò§¶Ö§áºº 10 ºÔµ Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&#


µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ RESULT VAR BYTE I2CIN 0, $A1, 0, [RESULT] ¨Ò¡¤íÒÊÑ§è ¢ Ò§µ ¹ i-Stamp2P24 ¨ÐÊ §¤íÒÊѧè Í Ò¹ ä»ÂѧÍØ»¡Ã³ I2C ·Õµè Í §¡ÒõԴµ Í´ Ç â´Â㪠¢Ò ¾Íà µ 0 áÅÐ 1 ¨Ò¡¹Ñ¹é ÃÍÃѺ¢ ÍÁÙŵͺ¡ÅѺÁÒà¡çºäÇ ã¹µÑÇá»Ã RESULT ÍØ»¡Ã³ I2C ·Õµè ´Ô µ Í´ ǹѹé ÁÕ SlaveID ෠ҡѺ $A1 (10100001) â´Â 1 㹺ԵÊØ´· ÒÂ㪠㹡ÒÃᨠ§¡ÑºÍØ»¡Ã³ I2C Ç Òµ ͧ¡ÒÃÍ Ò¹¢ ÍÁÙÅ Ê Ç¹ Address ÁÕ¤Ò à· Ò¡Ñº 0 áÅÐà» ¹¡ÒõԴµ ͡ѺÍØ»¡Ã³ Ẻ 7 ºÔµ

¡Ò÷´Åͧ Í·Õè 12 ¡ÒÃ㪠§Ò¹¤íÒÊѧè I2CIN (1) 㪠ǧ¨ÃµÒÁÃÙ»·Õè 3-9 㹡Ò÷´Åͧ áÅ Çà¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRE-LAB2P24-12.BSP : I2CIN command demonstration***** ' {$STAMP BS2p} DATAIN VARNIB DIRD = %1111 ' ¡íÒ˹´ãË ¢Ò P15 ¶Ö§ P12 à» ¹àÍÒµ ¾µØ LOOP1: I2CIN 0,%01110001,[DATAIN] ' Í Ò¹¤ Ò¨Ò¡ÍØ»¡Ã³ ºÊÑ I2C ÁÒà¡çºäÇ ã¹µÑÇá»Ã DATAIN OUTD = DATAIN ^ %1111 ' Ê §¤ Ò·ÕÍè Ò ¹ä´ ¨Ò¡ÍØ»¡Ã³ I2C ä»áÊ´§·Õ¢è Ò¾Íà µàÍÒµ ¾µØ GOTO LOOP1

3. Ãѹâ»Ãá¡ÃÁ áÅ ÇÊѧࡵ¡ÒÃáÊ´§¼Å¢Í§ LED àÁ×Íè à» ´» ´ÊÇÔµª àÁ×Íè àÃÔÁè µ ¹·íÒ§Ò¹ LED ´ÑºËÁ´ à¹×Íè §¨Ò¡ÊÇÔµª S1 à» ´Ç§¨ÃËÁ´ ËÒ¡¡ÒõԴµ ͺÑÊ I2C ¶Ù¡µ ͧ ËÒ¡ à»ÅÕÂè ¹¤ Ò·ÕÊè ÇÔµª S1 i-Stamp2P24 ¨Ð¹íҼŹѹé ÁÒ¡ÅѺÅͨԡà¾×Íè ¢Ñº LED ·Õµè Í ¡Ñº¢Ò P12 ¶Ö§ P15 à¹×Íè §¨Ò¡µ ͧ ¡ÒÃáÊ´§ãË àËç¹Ç Ò ËÒ¡ÊÇÔµª µÍ ǧ¨Ã LED ¨ÐµÔ´ÊÇ Ò§ áÅж ÒÊÇÔµª à» ´Ç§¨Ã LED ã¹µíÒá˹ §·Õµè ç¡Ñ¹¨Ð´Ñº +5V

R1/1-4 4k7 x4 S1 DIP SW. x4

16

D3

12

D2

11

D1

10

D0

9

P7

SCL

P6

SDA

14 15

P5

R2 4k7

R3 4k7 LED1-LED4

P1 P0

P15 P14 P13 P12

P4 IC1 PCF8574A

,! , , ,

R4-R7 510 x4

i-Stamp2P P3 P2

A2

P1

A1

P0

A0

3 2 1

8

ÃÙ»·Õè 3-9 ǧ¨Ã·´Åͧ¤íÒÊѧè I2CIN «Ö§è 㹡Ò÷´Åͧ¹Õãé ª äÍ«Õ¢ÂÒ¾Íà µÍÔ¹¾ØµàÍÒµ ¾µØ àºÍà PCF8574A &$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


I2COUT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè I2COUT Pin, SlaveID, Address {\LowAddress}, [OutputData]

à» ¹¤íÒÊѧè à¢Õ¹ËÃ×ÍÊ §¢ ÍÁÙÅä»ÂѧÍØ»¡Ã³ ·ãÕè ª ¡ÒÃàª×Íè Áµ ͼ Ò¹ÃкººÑÊ I2C â´ÂÁÕ굄 ÃÒ¡Òö Ò·ʹ ¢ ÍÁÙÅ»ÃÐÁÒ³ 81 ¡ÔâźԵµ ÍÇÔ¹Ò·Õ (äÁ ÃÇÁÊÑ­­Ò³µÍºÊ¹Í§µ Ò§æ) ¾ÒÃÒÁÔàµÍà Pin à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ËÃ×Í 8 à¾×Íè 㪠㹡ÒÃàÅ×Í¡¢Ò¾Íà µ¢Í§àºÊÔ¡áʵÁ» 2P 㹡ÒõԴµ ͡ѺÍØ»¡Ã³ ¼Ò ¹ÃкººÑÊ I2C â´Â㪠¢Ò¾Íà µ 2 ¢Ò ¤×Í P0 à» ¹¢Ò¢ ÍÁÙÅ͹ءÃÁËÃ×Í SDA (Serial data) P1 à» ¹¢ÒÊÑ­­Ò³¹ÒÌ ¡Ò͹ءÃÁËÃ×Í SCL (Serial clock) 㹡ÒÃ㪠§Ò¹¨ÃÔ§µ ͧµ ͵Ñǵ Ò¹·Ò¹¤ ÒÃÐËÇ Ò§ 1.8 ¶Ö§ 4.7k: ¾ÙÅÍÑ»äÇ ·¢Õè Ò¾Íà µ·Ñ§é Êͧ´ Ç SlaveID à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ¶Ö§ 255 㪠áÊ´§¤ ÒÃËÑÊ»ÃШíÒµÑÇ (ID) ¢Í§ÍØ»¡Ã³ I2C ·Õµè ´Ô µ Í´ Ç »¡µÔ¨Ð¾Ô¨ÒóÒã¹ÃÙ»¢Í§¢ ÍÁÙÅ 8 ºÔµ â´Â 7 ºÔµº¹ (ºÔµ 1-7) ¨Ðà» ¹¢ ÍÁÙÅÃËÑÊ੾ÒеÑǢͧ ÍØ»¡Ã³ µÇÑ ¹Ñ¹é æ «Ö§è ¡íÒ˹´ÁÒ¨Ò¡¼Ù¼ ÅÔµ Ê Ç¹ã¹ºÔµ LSB ËÃ×ͺԵ 0 ¹Ñ¹é à» ¹ºÔµ·Õãè ª ºÍ¡Ê¶Ò¹Ð¡ÒõԴµ ͡ѺÍØ»¡Ã³ I2C µÑǹѹé æ Ç Ò µ ͧ¡ÒÃÍ Ò¹ËÃ×Íà¢Õ¹¢ ÍÁÙÅ´ Ç â´Â¶ Òµ ͧ¡ÒÃÍ Ò¹¢ ÍÁÙŨСíÒ˹´ãË à» ¹ 1 áÅÐàÁ×Íè µ ͧ¡ÒÃà¢Õ¹ ¢ ÍÁÙŨСíÒ˹´ãË à» ¹ 0 Address à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ¶Ö§ 255 㪠¡Òí ˹´¤ ÒáÍ´à´ÃÊ·Ò§ÎÒà ´áÇà ¢Í§ ÍØ»¡Ã³ I2C ·Õµè ´Ô µ Í´ Ç «Ö§è ·Ã񼊫 ¨Ò¡Ê¶Ò¹Ð·Ò§Åͨԡ¢Í§¢Ò¡íÒ˹´áÍ´à´ÃÊ·Ò§ÎÒà ´áÇà A0 ¶Ö§ A2 ¢Í§ÍØ»¡Ã³ I2C µÑǹѹé æ ËÒ¡ã¹Ç§¨Ã¢Ò·Ñ§é ÊÒÁµ Íŧ¡ÃÒÇ´ ËÁ´ à· Ò¡ÑºÇ Òä´ ÃºÑ Åͨԡ 0 ·Ñ§é ËÁ´ ¤ Ò Address ¹Õ¨é §Ö ෠ҡѺ 0 Í ҧäà ¡çµÒÁÊíÒËÃѺÍØ»¡Ã³ µÇÑ ã´·Õäè ÁÁÕ¢Ò A0 ¶Ö§ A2 ãË ¡Òí ˹´¤ Ò Address ¹Õàé · ҡѺ 0 àÊÁÍ Í ҧäáçµÒÁã¹» ¨¨Øº¹Ñ áÅÐá¹Ç â¹ Áã¹Í¹Ò¤µä´ Á¡Õ ÒþѲ¹ÒÍØ»¡Ã³ I2C à¾ÔÁè ÁÒ¡¢Ö¹é ¨¹·íÒãË áÍ´à´Ãʢͧ¡ÒõԴµ Í·Õáè µ à´ÔÁãªã¹Ãкº 7 ºÔµµ ͧà¾ÔÁè à» ¹Ãкº 10 ºÔµ (10-bit addressing) Ê §¼ÅãË µÍ §ãª µÇÑ á»Ãà¾ÔÁè àµÔÁ «Ö§è ã¹·Õ¹è ¤Õé Í× LowAddress «Ö§è ¨ÐàÃÕ¡㪠µÍ ¨Ò¡µÑÇ á»Ã Address ¹Õé LowAddress à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ¶Ö§ 255 ãªáÊ´§¤ ÒáÍ´à´ÃÊã¹ 2 ºÔµÅ Ò§ ¢Í§¡ÒõԴµ ÍẺ 10 ºÔµ ¨Ð㪠µÒÁÅíҾѧäÁ ä´ ã¹¡ÒÃ㪠§Ò¹µ ͧ¡íÒ˹´¤ Òµ ͨҡµÑÇá»Ã Address ෠ҹѹé OutputData à» ¹µÑÇá»ÃÊíÒËÃѺà¡çº¢ ÍÁÙÅ·Õµè Í §¡ÒÃÊ §ÍÍ¡ä»ÂѧÍØ»¡Ã³ I2C ÁÕû٠Ẻ¢Í§¢ ÍÁÙÅàËÁ×͹ ¡Ñº·Õãè ª 㹤íÒÊѧè DEBUG ã¹µÒÃÒ§·Õè 3-5 áÊ´§ÃٻẺ¢ ÍÁÙÅã¹Ê ǹ¢Í§ OutputData ¹Õé µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ #1 I2COUT 0, $A0, 5, [100] ¨Ò¡¤íÒÊÑ§è ¢ Ò§µ ¹ à» ¹¡ÒÃàÅ×͡㪠¢Ò¾Íà µ P0 à» ¹¢Ò SDA, ¢Ò P1 à» ¹¢Ò SCL à¢Õ¹¢ ÍÁÙÅä»ÂѧÍØ»¡Ã³ I2C ·ÕÁè ¤Õ Ò SlaveID ෠ҡѺ $A0 ÁÕáÍ´à´ÃÊ෠ҡѺ 5 Ê Ç¹¢ ÍÁÙÅ·Õàè ¢Õ¹ËÃ×ÍÊ §ä»¤×Í 100 °Ò¹ÊÔº

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&%


µÑÇ¡íÒ˹´¡ÒÃà»ÅÕÂè ¹á»Å§ »ÃÐàÀ·¢Í§¢ ÍÁÙÅ ËÁÒÂà赯 1 àÅ¢°Ò¹ÊÔº ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-5) µ Í· ÒÂËÁÒ¶֧ DEC {1...5} ¨íҹǹËÅÑ¡·ÕèáÊ´§ 1, 2 àÅ¢°Ò¹ÊԺẺ¤Ô´à¤Ã×èͧËÁÒ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-5) SDEC {1...5} µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ 1 àÅ¢°Ò¹ÊԺˡ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· Ò HEX {1...4} ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ SHEX {1...4} 1, 2 àÅ¢°Ò¹ÊԺˡẺ¤Ô´à¤Ã×èͧËÁÒ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-5) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ IHEX {1...4} 1 àÅ¢°Ò¹ÊԺˡâ´ÂáÊ´§ÊÑ­Åѡɳ $ ¹íÒ˹ Ò àª ¹ $37A à» ¹µ ¹ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· ÒÂËÁÒ¶֧ ¨íҹǹËÅÑ¡·ÕèáÊ´§ ISHEX {1...4}

àÅ¢°Ò¹ÊԺˡẺ¤Ô´à¤Ã×èͧËÁÒ â´ÂáÊ´§ÊÑ­Åѡɳ $ ¹íÒ˹ Ò ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· ÒÂËÁÒ¶֧ ¨íҹǹËÅÑ¡·ÕèáÊ´§

1, 2

BIN {1...16}

àÅ¢°Ò¹Êͧ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· Ò ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ àÅ¢°Ò¹ÊͧẺ¤Ô´à¤Ã×èͧËÁÒ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-16) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ àÅ¢°Ò¹Êͧâ´ÂáÊ´§ÊÑ­Åѡɳ % ¹íÒ˹ Ò àª ¹ %10111000 à» ¹µ ¹ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-16) µ Í· Ò ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§

1

SBIN {1...16} IBIN {1...16}

ISBIN {1...16}

àÅ¢°Ò¹ÊͧẺ¤Ô´à¤Ã×èͧËÁÒ â´ÂáÊ´§ÊÑ­Åѡɳ % ¹íÒ˹ Ò ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· Ò ËÁÒ¶֧ ¨íҹǹËÅÑ¡·ÕèáÊ´§

µÑÇ¡íÒ˹´¡ÒÃáÊ´§¼Å ?

ASC? STR ByteArray {\L} REP Byte \L

1, 2 1

1, 2

¡ÒÃáÊ´§¼Å 㪠áÊ´§ "ÊÑ­Åѡɳ = ¤ ÒµÑÇàÅ¢ + ¡ÒâÖ鹺Ã÷ѴãËÁ " ÃٻẺ»¡µÔ¨Ðà» ¹µÑÇàÅ¢°Ò¹ÊÔº áµ ÊÒÁÒöà»ÅÕè¹á»Å§µÒÁ¡ÒáíÒ˹´ ÃٻẺ ઠ¹ BIN ? x à» ¹¡ÒÃáÊ´§¤ Ңͧ x ã¹ÃÙ»¢Í§àÅ¢°Ò¹Êͧ áÊ´§ª×èͧ͢µÑÇá»ÃµÒÁ´ Ç carriage return (¡ÒâÖ鹺Ã÷ѴãËÁ ) â´Â character µ ͧ໠¹¢ ÍÁÙÅÃËÑÊáÍÊ¡Õé áÊ´§µÑÇÍÑ¡ÉÃáÍÊ¡Õé¨íҹǹ L 亵 ¨Ò¡ bytearray áÊ´§µÑÇÍÑ¡ÉÃáÍÊ¡Õé¢Í§ Byte ¨íҹǹ L ¤ÃÑé§ àª ¹ REP "X"/10 ¼ÅÅѾ¸ ·Õèä´ ¤×Í XXXXXXXXXX

ËÁÒÂà赯 (1) ¡ÒáíÒ˹´¨íҹǹËÅÑ¡·ÕèáÊ´§ ઠ¹ DEC4 ¶ Ò¤ Ò·ÕèáÊ´§ÁÕäÁ ¶Ö§ 4 ËÅѡ˹ ҨͨÐáÊ´§àÅ¢ "0" ¹íÒ˹ Ò Â¡µÑÇÍ ҧ DEC4 65 ˹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§ 0065 ¶ Ò¤ ÒµÑÇàÅ¢ÁÕ¨íҹǹËÅÑ¡ÁÒ¡¡Ç Ò·Õè¡íÒ˹´ äÇ Ë¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¢ ÍÁÙŢͧËÅÑ¡´ Ò¹µíèÒà· Ò¹Ñé¹ àª ¹ DEC4 56422 ¤ Ò·ÕèáÊ´§·Õè˹ Òµ Ò§ Debug Terminal ¤×Í 6422 (2) ¡ÒáíÒ˹´¤ Òà¤Ã×èͧËÁÒ ¨Ð㪠¡¯·Ù¤ÍÁ¾ÅÕàÁ¹µ ¤ Ò¢ ÍÁÙŨе ͧÁÕ¢¹Ò´äÁ à¡Ô¹¤ ÒµÑÇá»Ã Word

µÒÃÒ§·Õè 3-5 ÃÒÂÅÐàÍÕ´ÃٻẺ¢Í§¢ ÍÁÙÅ·ÕÊè ÒÁÒÃ¶ãª ä´ ã¹µÑÇá»Ã OutputData ¢Í§¤íÒÊѧè I2COUT &&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ Í·Õè 13 ¡ÒÃ㪠§Ò¹¤íÒÊѧè I2COUT (1) 㪠ǧ¨ÃµÒÁÃÙ»·Õè 3-10 㹡Ò÷´Åͧ (2) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé *****PRELAB2P24-13.BSP : I2COUT command demonstration***** {$STAMP BS2p} DELAY CON 250 LOOP1: I2COUT 0,%01110000,[%01110000] D3 ON PAUSE DELAY I2COUT 0,%01110000,[%10110000] D2 ON PAUSE DELAY I2COUT 0,%01110000,[%11010000] D1 ON PAUSE DELAY I2COUT 0,%01110000,[%11100000] D0 ON PAUSE DELAY GOTO LOOP1

(3) Ãѹâ»Ãá¡ÃÁ áÅ ÇÊѧࡵ¡ÒÃáÊ´§¼Å¢Í§ LED àÁ×Íè àÃÔÁè ·íÒ§Ò¹ ËÒ¡ i-Stamp2P24 µÔ´µ ͡Ѻ PCF8574A ä´ Í ҧ¶Ù¡µ ͧ LED ·Ñ§é 4 ´Ç§¨Ð·íҧҹ㹠ÅѡɳÐà» ¹ä¿ÇÔ§è àÃÔÁè ¨Ò¡ D3 äÅ ä»Âѧ D0 +5V

R1 4k7 P1 P0

R2 4k7

16 14 SCL 15 SDA

P3 7 P2 6 P1 5 P0 4

i-Stamp2P

IC1 PCF8574A

LED1-LED4 ,! , , ,

R3-R6 510 x4

3 A2 2 A1 1 A0 8

ÃÙ»·Õè 3-10 ǧ¨Ã·´Åͧ¤íÒÊѧè I2COUT à¾×Íè Ê §¢ ÍÁÙÅä»ÂѧÍØ»¡Ã³ ã¹ÃкººÑÊ I2C «Ö§è 㹡Ò÷´Åͧ ¹Õ¤é Í× äÍ«Õ¢ÂÒ¾Íà µÍÔ¹¾ØµàÍÒµ ¾µØ àºÍà PCF8574A Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&'


IF...THEN ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè IF Condition THEN AddressLabel

㪠µÃǨÊͺà§×Íè ¹ä¢ áÅж Òà§×Íè ¹ä¢à» ¹¨ÃÔ§ ¡ÃÐâ´´ä»ÂѧµíÒá˹ §áÍ´à´ÃÊ·ÕÃè кØäÇ ã¹ AddressLabel ¾ÒÃÒÁÔàµÍà Condition à» ¹¡ÒáíÒ˹´à§×Íè ¹ä¢ ÊÒÁÒö¡íÒ˹´à» ¹ÊÁ¡Òà áŠǵÃǨÊͺÊÁ¡ÒÃÇ Òà» ¹¨ÃÔ§ (true) ËÃ×Íà» ¹à·ç¨ (false) AddressLabel à» ¹¤ ÒÅÒàºÅ·Õè¡íÒ˹´µíÒá˹ §·Õèâ»Ãá¡ÃÁ¨Ð¡ÃÐⴴ件 Òà§×è͹䢷ÕèµÃǨÊͺ໠¹¨ÃÔ§ ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ¤íÒÊÑè§ IF...THEN ã¹¾ÕàºÊÔ¡à» ¹¡ÒÃÊà ҧ¡ÒõѴÊԹ㨠¶ Ò·íÒ¡ÒõÃǨÊͺà§×è͹䢷Õè¡íÒ˹´áÅ Çà» ¹ ¨ÃÔ§ â»Ãá¡ÃÁ¨Ð¡ÃÐâ´´ä»ÂѧáÍ´à´ÃÊ·Õ¡è Òí ˹´â´Â AddressLabel ·Ñ¹·Õ ¤ Ò Condition ¢Í§¤íÒÊѧè IF THEN à» ¹¡ÒüÊÁ¡Ñ¹ÃÐËÇ Ò§¡ÒÃà»ÃÕºà·ÕºáÅСÒáÃзíÒ·Ò§Åͨԡ ¡ÒÃà»ÃÕºà·ÕÂºä´ á¡ = ෠ҡѺ <> äÁ ෠ҡѺ > ÁÒ¡¡Ç Ò < ¹ ÍÂ¡Ç Ò >= ÁÒ¡¡Ç ÒËÃ×Í෠ҡѺ <= ¹ ÍÂ¡Ç ÒËÃ×Í෠ҡѺ ¢ ÍÁÙÅ·Õ¹è Òí ÁÒà»ÃÕºà·ÕºÊÒÁÒÃ¶ãª ä´ ¡ºÑ ¢ ÍÁÙÅ·Ø¡ª¹Ô´ äÁ ÇÒ ¨Ðà» ¹¢ ÍÁÙÅÃдѺºÔµ, 亵 , àÇÔô ËÃ×Í ¤ Ò¤§·Õè ¡ÒÃà»ÃÕºà·Õº·Ñ§é ËÁ´¨Ð㪠ª¹Ô´¢ ÍÁÙÅà» ¹áºº 16 ºÔµäÁ ¤´Ô à¤Ã×Íè §ËÁÒ ઠ¹ '{$STAMP BS2p} '{PBASIC2.5} A_NUMBER VAR BYTE A_NUMBER = 99 IF A_NUMBER < 100 THEN IS_LESS DEBUG "greater than or equal to 100" STOP IS_LESS: DEBUG "less than 100" STOP

àÁ×Íè Ãѹâ»Ãá¡ÃÁµÑÇÍ ҧ¢ Ò§µ ¹ ˹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¢ ͤÇÒÁ less than 100 à¹×Íè §¨Ò¡ ¡í Ò Ë¹´¤ Ò A_NUMBER = 99 㹺ÃÃ·Ñ ´ ·Õè Ê Í§¢Í§â»Ãá¡ÃÁ ¤í Ò ÊÑè § IF THEN ·í Ò ¡ÒõÃǨÊͺ ¤ ÒÊÁ¡Òà A_NUMBER < 100 àÁ×Íè ¾ºÇ Òà» ¹¨ÃÔ§¨Ö§¡ÃÐâ´´ä»·Õµè Òí á˹ §ÅÒàºÅ IS_LESS ¶ Òà»ÅÕÂè ¹¤ Ò A_NUMBER = 99 à» ¹ A_NUMBER = 100 ¢ ͤÇÒÁ·ÕËè ¹ Òµ Ò§ Debug Terminal ¨Ðà»ÅÕÂè ¹ ä»à» ¹ greater than or equal to 100,

'

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡ÒÃ㪠¤Òí Êѧè IF THEN ÊíÒËÃѺ¡ÒûÃÐÁÇżŷҧÅͨԡ ¡ÒÃ㪠IF THEN ¡Ñº¡ÒáÃзíÒ NOT à» ¹¡ÒáÅѺʶҹТͧà§×Íè ¹ä¢ à»ÅÕÂè ¹¨Ò¡¨Ãԧ໠¹à·ç¨ËÃ×Í à»ÅÕÂè ¹¨Ò¡à·ç¨à» ¹¨ÃÔ§ áÊ´§ä´ ´§Ñ µÑÇÍ ҧ IF x <> 100 THEN NOT_EQUAL IF NOT x = 100 THEN NOT_EQUAL

Goto Not_equal if x is not 100. Goto Not_equal if x is not 100.

Ê Ç¹¡ÒÃ㪠IF THEN ¡Ñº¡Òà AND, OR, áÅÐ XOR ¼ÅÅѾ¸ ·àÕè ¡Ô´¢Ö¹é ¨Ðà¡Ô´¨Ò¡ 2 à§×Íè ¹ä¢ ¡Ã³Õ ¡ÃзíÒ¤íÒÊѧè AND ¨Ðä´ ¼Å¡ÒõÃǨÊͺ໠¹¨ÃÔ§àÁ×Íè à§×Íè ¹ä¢·Ñ§é Êͧ໠¹¨ÃÔ§·Ñ§é ¤Ù ã¹¢³Ð·Õ¡è ÒáÃзíÒ¤íÒÊѧè OR ¨Ðä´ ¼Åà» ¹¨ÃÔ§àÁ×èÍà§×è͹䢵ÑÇã´µÑÇ˹Öè§ËÃ×Í·Ñé§ÊͧµÑÇà» ¹¨ÃÔ§ Ê Ç¹¡ÒáÃзíÒ¤íÒÊÑè§ XOR ¨Ðä´ ¼Åà» ¹¨ÃÔ§ àÁ×Íè ÁÕà§×Íè ¹ä¢ã´à§×Íè ¹ä¢Ë¹Ö§è à» ¹¨Ãԧ෠ҹѹé â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õàé » ¹¡ÒõÃǨÊͺà§×Íè ¹ä¢¢Í§¡Òà AND '{$STAMP BS2p} '{PBASIC2.5} B1 = 5 B2 = 9 IF B1 = 5 AND B2 = 10 THEN TRUE DEBUG "Statement was not true." STOP TRUE: DEBUG "Statement was true." STOP

' Change AND to OR and see ' what happens.

àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢ ͤÇÒÁ Statement was not true à¹×Íè §¨Ò¡à§×Íè ¹ä¢ B1 = 5 AND B2 = 10 à» ¹à·ç¨ ¨Ò¡¹Ñ¹é á¡ ä¢â»Ãá¡ÃÁ㹺Ã÷Ѵ¹Õ¨é Ò¡¤íÒÊѧè AND à» ¹¤íÒÊѧè OR áÅ ÇÃѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢ ͤÇÒÁ Statement was true à¹×Íè §¨Ò¡ÁÕà§×Íè ¹ä¢·Õàè » ¹¨ÃÔ§¤×Í B1 = 5

¡Ò÷´Åͧ Í·Õè 14 ¡ÒÃ㪠§Ò¹¤íÒÊѧè IF...THEN (1) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé à» ¹â»Ãá¡ÃÁÊØÁ µÑÇàÅ¢¢¹Ò´ 16 ºÔµ áÅ ÇËÒà 3 ËÒ¡äÁ ŧµÑǵ ͧÊØÁ ãËÁ ¶ ÒŧµÑÇãË ¹íÒä»áÊ´§·ÕËè ¹ Òµ Ò§ Debug Terminal ¨¹¤Ãº 10 ¤ Ò '****PRELAB2P24-14.BSP : IF...THEN command demonstrate to randoming number**** '{$STAMP BS2p} '{PBASIC2.5} SAMPLE VAR WORD ' ¡íÒ˹´µÑÇá»Ãà¡çº¤ Ò·Õäè ´ ¨Ò¡¡ÒÃÊØÁ à» ¹áºº Word SAMPS VAR NIB ' ¡íÒ˹´µÑÇá»Ã·Õãè ª à¡çº¨íҹǹ¢Í§¤ Ò·ÕËè Òà 3 ŧµÑÇ MUL3: RANDOM SAMPLE ' ·íÒ¡ÒÃÊØÁ ¤ Ò IF NOT SAMPLE//3 = 0 THEN MUL3 ' ¶ ÒËÒ¡ËÒà 3 äÁ ŧµÑÇ ãË ¡ÅѺä»ÊØÁ µÑÇàÅ¢ãËÁ DEBUG DEC SAMPLE," is divisible by 3.",CR ' áÊ´§¢ ͤÇÒÁᨠ§¤ Ò·Õ¼è Ò ¹¡ÒõÃǨÊͺ·ÕËè ¹ Òµ Ò§ Debug Terminal SAMPS = SAMPS + 1 ' à¾ÔÁè ¤ ÒµÑÇá»Ã·Õãè ª à¡çº¨íҹǹ¢Í§¤ Ò·ÕËè Òà 3 ŧµÑÇ IF SAMPS = 10 THEN DONE ' ÍÍ¡¨Ò¡¡ÒõÃǨÊͺ àÁ×Íè ä´ ¤Ò ¤Ãº 10 ¤ Ò GOTO MUL3 DONE : DEBUG CR,"All done." STOP

(2) Ãѹâ»Ãá¡ÃÁ Êѧࡵ¼Å¡Ò÷íÒ§Ò¹¼ Ò¹·Ò§Ë¹ Òµ Ò§ Debug Terminal

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'


IF...THEN...ELSE

ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè Ẻ·Õè 1 ¡Ã³Õà¢Õ¹ËÅÒºÃ÷Ѵ IF condition(s) THEN statement(s) { ELSE statement(s) } ENDIF

Ẻ·Õè 2 ¡Ã³Õà¢Õ¹µ Íà¹×Íè §ºÃ÷Ѵà´ÕÂǡѹ IF condition(s) THEN statement(s) { ELSE statement(s) }

à» ¹¤íÒÊÑ§è µÃǨÊͺà§×Íè ¹ä¢·Õãè Ë ¼Å¡ÒõÃǨÊͺ·Ñ§é 㹡óշàÕè §×Íè ¹ä¢à» ¹¨ÃÔ§áÅÐäÁ à» ¹¨ÃÔ§ ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊÑ§è ¹Õ¤é Í× ¶ Òà§×Íè ¹ä¢ (condition) à» ¹¨ÃÔ§ i-Stamp2P24 ¨Ð¡ÃÐâ´´ä»·íÒ§Ò¹ÂѧÅÒ àºÅ·Õµè Í · Ò¤íÒÊѧè THEN ËÃ×Ͷ Òà§×Íè ¹ä¢äÁ à» ¹¨ÃÔ§ ¨Ð¡ÃÐâ´´ä»·íÒ§Ò¹ÂѧÅÒàºÅ·Õµè Í · Ò¤íÒÊѧè ELSE ¹Í¡ ¨Ò¡¹Ñ¹é ÂѧÊÒÁÒöàÃÕ¡㪠¤Òí ÊÑ§è ¹Õàé ¾×Íè µÃǨÊͺà§×Íè ¹ä¢ä´ ÁÒ¡¶Ö§ 16 ¡Ã³Õ µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè

IF (score > 90) THEN DEBUG "Your grade is an A!", CR ELSE DEBUG "Perhaps more study is in order...", CR ENDIF IF (idx = 1) THEN HIGH 10 : LOW 11 ELSE LOW 10 : HIGH 11

¨Ò¡â»Ãá¡ÃÁà» ¹â»Ãá¡ÃÁµÃǨÊͺ¤ Ңͧ score Ç ÒÁÒ¡¡Ç Ò 90 ËÃ×ÍäÁ ¶ Ò㪠¨ÐáÊ´§¢ ͤÇÒÁ Your grade is an A! º¹Ë¹ Òµ Ò§ Debug Terminal áµ ¶Ò à§×Íè ¹ä¢äÁ à» ¹¨ÃÔ§ ¨ÐáÊ´§¢ ͤÇÒÁ Perhaps more study is in order... º¹Ë¹ Òµ Ò§ Debug Terminal á·¹ ËÅѧ¨Ò¡¹Ñ¹é ã¹Ê ǹ· Ò¢ͧâ»Ãá¡ÃÁà» ¹¡ÒÃ㪠¤Òí Êѧè IF...THEN...ELSE ã¹áººà¢Õ¹µ Íà¹×Íè §¡Ñ¹ã¹ºÃ÷Ѵà´ÕÂÇ «Ö§è à» ¹¡ÒõÃǨÊͺ¤ Ңͧ idx Ç Ò෠ҡѺ 1 ËÃ×ÍäÁ ¶ Òà· Ò i-Stamp2P24 ¨Ð·íÒãË ¢Ò¾Íà µ 10 à» ¹Åͨԡ 1 áÅТҾÍà µ 11 à» ¹Åͨԡ 0 áµ ¶Ò äÁ à· Ò ¨Ð·íÒãË ¢Ò¾Íà µ 10 à» ¹Åͨԡ 0 áÅТҾÍà µ 11 à» ¹Åͨԡ 1 á·¹

'

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


INPUT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè INPUT Pin

㪠¡Òí ˹´ãË ¢Ò¾Íà µ·Õµè Í §¡ÒÃà» ¹ÍÔ¹¾Øµ ¾ÒÃÒÁÔàµÍà Pin à» ¹¤ Ò¤§·ÕËè Ã×ͤ ÒµÑÇá»ÃÁÕ¤Ò ÍÂÙà ÐËÇ Ò§ 0 ¶Ö§ 15 㪠àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õµè Í §¡Òà ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ÁÕËÅÒÂÇÔ¸·Õ ¨Õè СíÒ˹´ãË ¢Ò¾Íà µ¢Í§ i-Stamp2P24 à» ¹¢ÒÍÔ¹¾Øµ â´Â»¡µÔàÁ×Íè àÃÔÁè µ ¹ãª §Ò¹â»Ãá¡ÃÁ ¤Ãѧé áá¢Ò¾Íà µ¢Í§ i-Stamp2P24 ¨Ðà» ¹¢ÒÍÔ¹¾ØµÍÂÙá Å Ç ¹Í¡¨Ò¡¹Ñ¹é ÊÒÁÒö㪠¤Òí ÊÑ§è ·Õàè ¡ÕÂè Ç¢ ͧ¡Ñº¡ÒÃÃѺ ÍÔ¹¾Øµàª ¹ PULSIN ËÃ×Í SERIN ¤íÒÊѧè àËÅ Ò¹Õ¨é зíÒ¡ÒáíÒ˹´Ê¶Ò¹Ð¢Í§¢Ò·Õãè ª §Ò¹à» ¹¢ÒÍÔ¹¾Øµâ´ÂÍѵâ¹ÁÑµÔ ÍÕ¡ÇÔ¸ËÕ ¹Ö§è ¤×Í ¡ÒÃ㪠¤Òí Êѧè INPUT àÁ×Íè 㪠§Ò¹¤íÒÊѧè INPUT ¨ÐÊÒÁÒÃ¶Í Ò¹¤ ÒʶҹТҾÍà µ¢Í§ i-Stamp2P24 ¹Ñ¹é ä´ ·¹Ñ ·Õ ´Ñ§µÑÇÍ ҧµ Í仹Õé INPUT 8 HOLD: IF IN8 = 0 THEN HOLD

' Stay here until P8 is 1.

â»Ãá¡ÃÁ¹Õ¨é ÐÍ Ò¹¤ Ò¨Ò¡¢Ò P8 ·Õäè ´ ÃºÑ ¡ÒáíÒ˹´ÁÒ¨Ò¡ÀÒ¹͡ ¨Ðà¡Ô´ÍÐäÃ¢Ö¹é ¶ ÒÊ §¤ Ò¢ ÍÁÙÅä»ÂѧÃÕ¨ÊÔ àµÍà OUTS ã¹¢³Ð·Õ¢è Ò¾Íà µæ ¹Ñ¹é à» ¹ÍÔ¹¾Øµ ¼Å¡ç¤Í× ¤ ÒʶҹР·ÕÊè § ¹Ñ¹é ¨Ð¶Ù¡Ê §ä»ÂѧÃÕ¨ÊÔ àµÍà OUTS áµ ·¢Õè Ò¾Íà µ¢Í§ i-Stamp2P24 ¨ÐäÁ à¡Ô´¡ÒÃà»ÅÕÂè ¹á»Å§ã´æ áµ àÁ×Íè ã´·Õè¢Ò¹Õé¶Ù¡à»ÅÕè¹໠¹àÍÒµ ¾Øµ ¤ Ò·Õèà¡çºã¹ÃÕ¨ÔÊàµÍà OUTS ¨Ð¶Ù¡Ê §Í͡价ѹ·Õ â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ¨ÐáÊ´§¡Ò÷íÒ§Ò¹¢Í§¤íÒÊÑè§ã¹ÅѡɳйÕé INPUT 7 ' Make pin 7 an input. DEBUG "State of P7: ", BIN IN7,CR OUT8 = 0 ' Write 0 to output latch. DEBUG "After 0 written to OUT7: ",BIN IN7,CR OUTPUT 7 ' Make pin 7 an output. DEBUG "After P7 changed to output: ",BIN IN7

â»Ãá¡ÃÁ¹Õé¨ÐáÊ´§ÇÔ¸Õ¡íÒ˹´·ÔÈ·Ò§¢Í§¢Ò¾Íà µ P7 â´ÂàÃÔèÁµ ¹¨Ò¡¡íÒ˹´ãË ¢Ò P7 à» ¹ÍÔ¹¾Øµ¡ ͹ ·íÒ¡ÒÃÍ Ò¹¤ ÒࢠÒÁÒ ¨Ò¡¹Ñ¹é Ê §¤ Ò 0 ä»Âѧ¢Ò P7 ã¹¢³Ð·ÕÂè §Ñ äÁ ä´ ¡Òí ˹´ãË ¢Ò¹Õàé » ¹àÍÒµ ¾µØ ·´ÅÍ§Í Ò¹¤ ÒÍÍ¡ ÁÒÍÕ¡¤ÃÑ§é ¨Ò¡¹Ñ¹é ¨Ö§¡íÒ˹´ãË ¢Ò¹Õàé » ¹àÍÒµ ¾µØ áÅ ÇÍ Ò¹¤ ÒÍÕ¡¤ÃÑ§é ¢ ÍÁÙÅ·Õ¢è ÒàÍÒµ ¾µØ ¨Ðà»ÅÕÂè ¹á»Å§àÁ×Íè ÁÕ¡ÒáíÒ˹´ ãË ¢Ò¹Õéà» ¹¢ÒàÍÒµ ¾ØµáÅ Ç

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'!


IOTERM ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè IOTERM Port

à» ¹¤íÒÊѧè à»ÅÕÂè ¹¡ÒõԴµ Í¡ÅØÁ ¢Í§¢Ò¾Íà µÃÐËÇ Ò§¾Íà µËÅÑ¡ P0 ¶Ö§ P15 ¡Ñº¾Íà µàÊÃÔÁ A0 ¶Ö§ A15 (ÁÕ㪠੾ÒÐã¹ BS2P40 áÅÐ i-Stamp2P ෠ҹѹé - äÁ 㪠¤Òí ÊÑ§è ¹Õ¡é ºÑ i-Stamp2P24) ¾ÒÃÒÁÔàµÍà Pin à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ËÃ×Í 1 à¾×Íè 㪠㹡ÒÃàÅ×Í¡¡ÅØÁ ¢Ò¾Íà µ¢Í§ i-Stamp2P24 ¶ Ò¡íÒ˹´à» ¹ 0 ¡ÅØÁ ¢Ò¾Íà µ·Õãè ª ¤Í× P0 ¶Ö§ P15 ¶ Ò¡íÒ˹´à» ¹ 1 ¡ÅØÁ ¢Ò¾Íà µ·Õãè ª ¤Í× A0 ¶Ö§ A15 (äÁ 㪠㹠i-Stamp2P24) µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ HIGH 0 IOTERM 1 LOW 0

¨Ò¡â»Ãá¡ÃÁ¢ Ò§µ ¹ àÁ×Íè àÃÔÁè ·íÒ§Ò¹»¡µÔ àºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍà ¨ÐµÔ´µ ͡Ѻ¡ÅØÁ ¢Ò¾Íà µËÅÑ¡ P0 ¶Ö§ P15 ã¹â»Ãá¡ÃÁºÃ÷Ѵáá¡íÒ˹´ãË ¢Ò¾Íà µ P0 à» ¹Åͨԡ 1 ¶Ñ´ÁÒà» ¹¤íÒÊѧè IOTERM 1 à» ¹¡ÒÃÊѧè ãË àºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍà µ´Ô µ ͡Ѻ¾Íà µàÊÃÔÁ A0 ¶Ö§ A15 á·¹ ¨Ò¡¹Ñ¹é ¨Ð·íÒ¡ÒÃÊ §Åͨԡ 0 ÍÍ¡ä»Âѧ ¢Ò A0 â´Â·ÕÊè ¶Ò¹ÐÅͨԡ·Õ¢è Ò¾Íà µ P0 Âѧ¤§à» ¹ 1 àËÁ×͹à´ÔÁ

'"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


LCDCMD

ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè LCDCMD Pin, Command

à» ¹¤íÒÊѧè ÊíÒËÃѺà¢Õ¹ËÃ×ÍÊ §¢ ÍÁÙŤíÒÊѧè (intruction) ä»ÂѧâÁ´ÙÅ LCD ẺÍÑ¡¢ÃÐ ¾ÒÃÒÁÔàµÍà Pin à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ËÃ×Í 1 ËÃ×Í 8 ËÃ×Í 9 à¾×Íè 㪠àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 㹡ÒõԴµ ͡ѺâÁ´ÙÅ LCD ẺÍÑ¡¢ÃÐ (Character LCD module) ¡ÒõԴµ Íà» ¹áºº 4 ºÔµ ÁÕÃÒÂÅÐàÍÕ´´Ñ§¹Õé ¡Ã³Õ¡Òí ˹´ Pin à» ¹ 0 ËÃ×Í 1 ¢Ò¾Íà µ 0 ËÃ×Í 1 (ãª ä´ ·§Ñé P0 ¡Ñº P1) µ ͡Ѻ¢ÒàÍç¹àÍàºÔÅËÃ×Í E ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 2 (P2) µ ͡Ѻ¢Ò R/W ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 3 (P3) µ ͡Ѻ¢Ò RS ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 4 ¶Ö§ 7 (P4 ¶Ö§ P7) µ ͡Ѻ¢Ò¢ ÍÁÙÅ D4 ¶Ö§ D7 ¢Í§âÁ´ÙÅ LCD ¡Ã³Õ¡Òí ˹´ Pin à» ¹ 8 ËÃ×Í 9 ¢Ò¾Íà µ 8 ËÃ×Í 9 ( ãª ä´ ·§Ñé P8 ¡Ñº P9) µ ͡Ѻ¢ÒàÍç¹àÍàºÔÅËÃ×Í E ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 10 (P10) µ ͡Ѻ¢Ò R/W ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 11 (P11) µ ͡Ѻ¢Ò RS ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 12 ¶Ö§ 15 (P12 ¶Ö§ P15) µ ͡Ѻ¢Ò¢ ÍÁÙÅ D4 ¶Ö§ D7 ¢Í§âÁ´ÙÅ LCD ã¹ÃÙ»·Õè 3-11 à» ¹Ç§¨Ã¡ÒÃàª×Íè Áµ Í i-Stamp2P24 ¡ÑºâÁ´ÙÅ LCD ẺÍÑ¡¢ÃÐ +5V P3/P11 P2/P10 P0/P1(P8/P9)

i-Stamp2P24

RS R/W E

LCD 16x2 LCD 20x4

D7 D6 D5 D4 D3 D2 D1 D0

+Vcc Vo GND

2 3 1

VR1 10k BRIGHTNESS

P7/P15 P6/P14 P5/P13 P4/P12

ÃÙ»·Õè 3-11 ¡ÒÃàª×Íè Áµ ͡ѺâÁ´ÙÅ LCD à¾×Íè ãË i-Stamp2P24 ÊÒÁÒö㪠§Ò¹¤íÒÊѧè à¡ÕÂè ǡѺâÁ´ÙÅ LCD ä´ â´Â㪠¡ÒõԴµ ÍẺ 4 ºÔµ Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'#


¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ l ã¹àºÊÔ¡áʵÁ» 2P (i-Stamp2p24) ÁÕ¤Òí ÊÑ§è ·Õàè ¡Õ è Ç¢ ͧ¡ÑºâÁ´ÙÅ LCD ẺÍÑ¡¢ÃÐ 3 ¤íÒÊÑ§è ¤×Í LCDCMD, LCDIN áÅÐ LCDOUT â´ÂâÁ´ÙÅ LCD ·ÕÊè ÒÁÒö㪠§Ò¹Ã ÇÁ´ ÇÂä´ ¹¹Ñé ¨Ðà» ¹âÁ´ÙÅ LCD ¢¹Ò´ 16 µÑÇÍÑ¡Éà 1 ºÃ÷Ѵ/2 ºÃ÷Ѵ áÅÐ 20 µÑÇÍÑ¡Éà 4 ºÃ÷Ѵ·Õãè ª µÇÑ ¤Çº¤ØÁàºÍà HD44780 ¢Í§ Hitachi ËÃ×ÍàºÍà ͹×è ·Õáè ·¹¡Ñ¹ä´ ´Ñ§¹Ñ¹é âÁ´ÙÅ LCD ¨Ö§µ ͧÁÕ¤Òí ÊÑ§è ·íҧҹ੾ÒÐ ¤íÒÊѧè LCDCMD ¨Ö§¶Ù¡ãª à¾×Íè ¡ÒùÕé â´Â¤íÒÊÑ§è ¢Í§âÁ´ÙÅ LCD ÊÃØ»äÇ áÅ Çã¹µÒÃÒ§·Õè 3-6 ¤íÒÊÑè§

¢ ÍÁÙÅÃËÑʤíÒÊÑè§ (àÅ¢°Ò¹ÊÔº)

äÁ ·íÒ§Ò¹ (Do Nothing)

0

äÁ ÁÕ¡ÒÃÊÑ觧ҹã´æ ÁÒÂѧâÁ´ÙÅ LCD

à¤ÅÕÂà ¨ÍáÊ´§¼Å (Clear Display)

1

áÊ´§µíÒá˹ §àÃÔèÁµ ¹ (Home Display)

2

ź¢ ÍÁÙÅ·Ñé§ËÁ´º¹¨ÍáÊ´§¼ÅáÅÐ àÅ×è͹à¤Íà à«Íà ÁÒÂѧµíÒá˹ §àÃÔèÁµ ¹ (home) àÅ×è͹à¤Íà à«Íà ÁÒÂѧµíÒá˹ §àÃÔèÁµ ¹¾Ã ÍÁáÊ´§¼Å

à¾ÔèÁ¤ Òà¤Íà à«Íà (Inc Cursor)

6

» ´¨ÍáÊ´§¼Å (Display Off)

8

¡íÒ˹´ãË à¤Íà à«Íà àÅ×è͹价ҧ¢ÇÒÁ×ͧ͢¨ÍáÊ´§¼Å â´Â¢ ÍÁÙÅáÊ´§¼ÅäÁ ÁÕ¡ÒÃàÅ×è͹µíÒá˹ § » ´¡ÒÃáÊ´§¼Å·Õè˹ Ò¨Í áµ ¢ ÍÁÙŢͧ¡ÒÃáÊ´§¼ÅÂѧÍÂÙ

à» ´¨ÍáÊ´§¼Å (Display On)

12

à» ´¡ÒÃáÊ´§¼Å·Õè˹ Ò¨Í (äÁ ÃÇÁ¡ÒÃáÊ´§à¤Íà à«Íà )

à¤Íà à«Íà ¡Ð¾ÃÔº (Blinking Cursor)

13

à» ´¡ÒÃáÊ´§¼Å·Õè˹ Ò¨ÍáÅФǺ¤ØÁãË à¤Íà à«Íà ¡Ð¾ÃÔº

áÊ´§à¤Íà à«Íà ໠¹àÊ ¹¢Õ´Å Ò§ (Underline Cursor)

14

à» ´¡ÒÃáÊ´§¼Å·Õè˹ Ò¨ÍáÅФǺ¤ØÁãË áÊ´§à¤Íà à«Íà ໠¹àÊ ¹¢Õ´Å Ò§ (underline)

àÅ×è͹à¤Íà à«Íà 价ҧ« Ò (Cursor Left)

16

àÅ×è͹µíÒá˹ §¢Í§à¤Íà à«Íà 价ҧ« Ò 1 µÑÇÍÑ¡ÉÃ

àÅ×è͹à¤Íà à«Íà 价ҧ¢ÇÒ (Cursor Right)

20

àÅ×è͹µíÒá˹ §¢Í§à¤Íà à«Íà 价ҧ¢ÇÒ 1 µÑÇÍÑ¡ÉÃ

àÅ×è͹¢ ͤÇÒÁä»·Ò§« Ò (Scroll Left)

24

àÅ×è͹¢ ͤÇÒÁáÊ´§¼Åä»·Ò§« Ò 1 µÑÇÍÑ¡ÉÃ

àÅ×è͹¢ ͤÇÒÁä»·Ò§¢ÇÒ (Scroll Right)

28

àÅ×è͹¢ ͤÇÒÁáÊ´§¼Åä»·Ò§¢ÇÒ 1 µÑÇÍÑ¡ÉÃ

àÅסâËÁ´/ºÃ÷Ѵ/¤ÇÒÁÅÐàÍÕ´ (Function set)

40

àÅ×Í¡âËÁ´µÔ´µ ÍẺ 4 ºÔµ ¡íÒ˹´ãË LCD áÊ´§¼ÅÁÒ¡¡Ç Ò 1 ºÃ÷Ѵ áÅФÇÒÁÅÐàÍÕ´¢Í§µÑÇÍÑ¡¢ÃÐà» ¹ 5x8 ¨Ø´ àÅ×Í¡âËÁ´µÔ´µ ÍẺ 8 ºÔµ 㪠ÍÔ¹ÔàªÕÂÅ¡ ͹¡íÒ˹´ãË âÁ´ÙÅ LCD ·íÒ§Ò¹ã¹âËÁ´ µÔ´µ ÍẺ 4 ºÔµ àÅ×Í¡âËÁ´µÔ´µ ÍẺ 8 ºÔµ ¡íÒ˹´ãË LCD áÊ´§¼ÅÁÒ¡¡Ç Ò 1 ºÃ÷Ѵ áÅФÇÒÁÅÐàÍÕ´¢Í§µÑÇÍÑ¡¢ÃÐà» ¹ 5x8 ¨Ø´

48 56

¤íÒ͸ԺÒÂ

µÔ´µ Í CGRAM (Move to CGRAM Address)

64 + ¤ ÒáÍ´à´ÃÊ

µÔ´µ Í DDRAM (Move to DDRAM Address)

128 + ¤ ÒáÍ´à´ÃÊ àÅ×è͹µÑǪÕéáÍ´à´ÃÊà¾×è͵Դµ Í˹ ǤÇÒÁ¨íÒáÃÁáÊ´§µÑÇÍÑ¡ÉÃã¹áÍ´à´ÃÊ·Õè¡íÒ˹´

àÅ×è͹µÑǪÕéáÍ´à´ÃÊà¾×è͵Դµ Í˹ ǤÇÒÁ¨íÒáÃÁà¡çºµÑÇÍÑ¡ÉÃã¹áÍ´à´ÃÊ·Õè¡íÒ˹´

µÒÃÒ§·Õè 3-6 µÒÃÒ§ÊÃØ»¤íÒÊÑ§è ¤Çº¤ØÁ¡Ò÷íÒ§Ò¹¢Í§âÁ´ÙÅ LCD ẺÍÑ¡¢ÃÐ '$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡ÒÃ㪠§Ò¹âÁ´ÙÅ LCD ÊÒÁÒöÊÃػ໠¹¢Ñ¹é µÍ¹Í ҧ§ ÒÂæ ä´ ´§Ñ ¹Õé (1) ˹ ǧàÇÅÒ (2) µÔ´µ ͡ѺÃÕ¨ÊÔ àµÍà ¤Òí Êѧè (instuction register) ÀÒÂã¹âÁ´ÙÅ LCD â´Â¡Ò÷íÒãË ¢Ò RS ¢Í§âÁ´ÙÅ LCD à» ¹Åͨԡ 1 áÅзíÒãË ¢Ò R/W à» ¹Åͨԡ 0 à¾×Íè àÅ×Í¡¡ÒÃà¢Õ¹¢ ÍÁÙÅä»ÂѧâÁ´ÙÅ LCD (3) à¢Õ¹¢ ÍÁÙÅä»ÂѧºÑÊ¢ ÍÁÙÅ DB4 ¶Ö§ DB7 (㹡óյ´Ô µ ÍẺ 4 ºÔµ) (4) Ê §ÊÑ­­Ò³¾ÑÅÊ ¢Íº¢Òŧä»Âѧ¢Ò E ¢Í§âÁ´ÙÅ LCD (5) ¶ ÒËÒ¡µ ͧ¡ÒÃà¢Õ¹¢ ÍÁÙÅáÊ´§¼Å µ ͧ·íÒãË ¢Ò RS à» ¹Åͨԡ 0 áÅ Ç´íÒà¹Ô¹¡ÒõÒÁ ¢Ñ¹é µÍ¹·Õè (3) áÅÐ (4) ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè LCDCMD ¤×Í¢Ñ¹é µÍ¹¡Ò÷íҧҹ㹢 Í (2) ¶Ö§ (4) l

ÊÔ§è ·Õµè Í §¡ÃзíÒà» ¹ÅíҴѺáá㹡ÒÃ㪠§Ò¹âÁ´ÙÅ LCD ¤×Í àµÃÕÂÁ¤ÇÒÁ¾Ã ÍÁ ËÃ×ÍàÃÕÂ¡Ç Ò ÍÔ¹àÔ ªÕÂÅ (initial) áµ à¹×Íè §¨Ò¡âÁ´ÙÅ LCD äÁ Á¤Õ Òí Êѧè ÍÔ¹àÔ ªÕÂÅµÃ§æ ¨Ö§µ ͧ㪠¤Òí Êѧè Í×¹è »ÃСͺà ÇÁ¡Ñ¹ÃÇÁ¶Ö§¤íÒÊѧè ˹ ǧàÇÅÒ ´ Ç ´Ñ§¹Ñ¹é ¡ÒÃÍÔ¹àÔ ªÕÂÅâÁ´ÙÅ LCD ¨Ö§µ ͧÊà ҧ¢Ö¹é à» ¹â»Ãá¡ÃÁ Í ÊÔ§è ·Õµè Í §·ÃÒºÍÕ¡»ÃСÒÃË¹Ö§è ¤×Í àÁ×Íè àÃÔÁè µ ¹¨ ÒÂä¿à¾×Íè 㪠§Ò¹âÁ´ÙÅ LCD »¡µÔáŠǵÑǤǺ¤ØÁËÃ×ͤ͹â·ÃÅàÅÍà ¨Ð¶Ù¡¡íÒ˹´ãË µ´Ô µ ÍẺ 8 ºÔµàÊÁÍ áµ à¹×Íè §¨Ò¡¤íÒÊÑ§è µÔ´µ ͡ѺâÁ´ÙÅ LCD ¢Í§ i-Stamp2P24 㪠¡ÒõԴµ ÍẺ 4 ºÔµ ´Ñ§¹Ñ¹é ¡ÒÃÍÔ¹àÔ ªÕÂŨ֧¨íÒà» ¹ Í ҧÁÒ¡ à¾ÃÒй͡¨Ò¡àµÃÕÂÁ¤ÇÒÁ¾Ã ÍÁ·ÑÇè æ ä» áÅ Ç Âѧµ ͧàµÃÕÂÁãË âÁ´ÙÅ LCD ·íÒ§Ò¹ã¹âËÁ´ 4 ºÔµ´ Ç ´Ñ§ÁÕâ»Ãá¡ÃÁµÑÇÍ ҧ¢Í§¡ÒÃÍÔ¹àÔ ªÕÂÅâÁ´ÙÅ LCD áÊ´§µ Í仹Õé l

InitLCD: PAUSE 1000 LCDCMD 1, 48 PAUSE 10 LCDCMD 1, 48 PAUSE 1 LCDCMD 1, 48 PAUSE 1 LCDCMD 1, 32 LCDCMD 1, 40 LCDCMD 1, 8 LCDCMD 1, 12 LCDCMD 1, 6 LCDCMD 1, 1

' ˹ ǧàÇÅÒà¾×Íè ãË âÁ´ÙÅ LCD ¾Ã ÍÁ·íÒ§Ò¹ ' ÍÔ¹àÔ ªÕÂÅâÁ´ÙÅ LCD ¡ ͹¡íÒ˹´ãË âÁ´ÙÅ LCD µÔ´µ ÍẺ 4 ºÔµ (Ê § 3 ¤Ãѧé )

' ¡íÒ˹´ãË âÁ´ÙÅ LCd µÔ´µ ÍẺ 4 ºÔµ ' àÅ×Í¡ãË áÊ´§¼ÅÁÒ¡¡Ç Ò 1 ºÃ÷Ѵ´ ǤÇÒÁÅÐàÍÕ´ 5x8 ¨Ø´µ ͵ÑÇÍÑ¡¢ÃÐ ' » ´¡ÒÃáÊ´§¼Å ' à» ´¡ÒÃáÊ´§¼Å ' àÅ×Íè ¹à¤Íà à«Íà â´ÂµÑÇÍÑ¡ÉÃäÁ àÅ×Íè ¹ ' à¤ÅÕÂà ¨ÍáÊ´§¼Å

Ê Ç¹·ÕÊè Òí ¤Ñ­·ÕÊè ´Ø ¢Í§â»Ãá¡ÃÁÍÔ¹àÔ ªÕÂŹդé Í× 8 ºÃ÷Ѵáá µÑ§é áµ ¤Òí Êѧè PAUSE 1000 ¨¹¶Ö§ LCDCMD 1, 32 µ ͧà¢Õ¹â»Ãá¡ÃÁµÒÁ¢Ñ鹵͹¹Õé·Ø¡»ÃСÒà ·Õè¨ÐÊÒÁÒöà»ÅÕè¹á»Å§ä´ ÁÕà¾Õ§¢ ÍÁÙÅ·Õè㪠àÅ×Í¡¢Ò ¾Íà µà· Ò¹Ñ¹é ¹Ñ¹è ¤×Í ÊÒÁÒöà»ÅÕÂè ¹à» ¹ 0, 1, 8 ËÃ×Í 9 Ê Ç¹¤ Ò˹ ǧàÇÅÒ㹤íÒÊѧè PAUSE ÍÒ¨Å´Å§ä´ ¶§Ö 700 ÁÔÅÅÔÇ¹Ô Ò·Õ (¡íÒ˹´¤ Ò෠ҡѺ 700) ã¹â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õàé » ¹â»Ãá¡ÃÁ Í¢ͧ¡ÒÃÍÔ¹àÔ ªÕÂÅâÁ´ÙÅ LCD ¢¹Ò´ 16 µÑÇÍÑ¡Éà 2 ºÃ÷Ѵ «Öè§ÊÒÁÒö¹íÒä»ãª §Ò¹ä´ ¨Ãԧ͠§ÊÁºÙó â´Â¼Ù 㪠§Ò¹Âѧ¤§ÊÒÁÒöà»ÅÕè¹á»Å§µíÒá˹ §¢Ò ª×è͵ÑÇá»Ã áÅÐ ¤ Ò˹ ǧàÇÅÒä´ µÒÁ¤ÇÒÁàËÁÒÐÊÁ Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'%


' Program: LCDINIT.BSP ' This program demonstrates initialization and printing on a 2 x 16 character LCD display. ' {$STAMP BS2p} ' àÅ×͡㪠àºÊÔ¡áʵÁ» 2P ' Define LCD constants LCDpin CON 1 ' ¡íÒ˹´¢Ò¾Íà µàª×Íè Áµ ÍâÁ´ÙÅ LCD ´ Ǥ Ò 1 WakeUp CON %00110000 ' ¤ Ò·Õãè ª 㹡ÒÃÍÔ¹àÔ ªÕÂÅâÁ´ÙÅ LCD FourBitMode CON %00100000 ' ¢ ÍÁÙŤíÒÊѧè ÊíÒËÃѺàÅ×Í¡âËÁ´µÔ´µ ÍẺ 4 ºÔµ OneLine5x8Font CON %00100000 ' àÅ×Í¡¡ÒÃáÊ´§¼Å 1 ºÃ÷Ѵ ¤ÇÒÁÅÐàÍÕ´ 5x8 ¨Ø´µ ÍÍÑ¡¢ÃÐ OneLine5x10Font CON %00100100 ' àÅ×Í¡¡ÒÃáÊ´§¼Å 1 ºÃ÷Ѵ ¤ÇÒÁÅÐàÍÕ´ 5x10 ¨Ø´µ ÍÍÑ¡¢ÃÐ TwoLine5x8Font CON %00101000 ' àÅ×Í¡¡ÒÃáÊ´§¼Å 2 ºÃ÷Ѵ ¤ÇÒÁÅÐàÍÕ´ 5x8 ¨Ø´µ ÍÍÑ¡¢ÃÐ TwoLine5x10Font CON %00101100 ' àÅ×Í¡¡ÒÃáÊ´§¼Å 2 ºÃ÷Ѵ ¤ÇÒÁÅÐàÍÕ´ 5x10 ¨Ø´µ ÍÍÑ¡¢ÃÐ DisplayOff CON %00001000 ' » ´¡ÒÃáÊ´§¼Å áµ ¢Í ÁÙÅáÊ´§¼ÅÂѧÍÂÙ DisplayOn CON %00001100 ' à» ´¡ÒÃáÊ´§¼ÅẺäÁ ÁàÕ ¤Íà à«Íà DisplayOnULCrsr CON %00001110 ' à» ´¡ÒÃáÊ´§¼Å áÅÐáÊ´§à¤Íà à«Íà Ẻ¢Õ´Å Ò§ DisplayOnBLCrsr CON %00001101 ' à» ´¡ÒÃáÊ´§¼Å áÅÐà¤Íà à«Íà ¡Ð¾ÃÔº IncCrsr CON %00000110 ' àÅ×Íè ¹µíÒá˹ §à¤Íà à«Íà 价ҧ¢ÇÒ â´ÂµÑÇÍÑ¡¢ÃÐäÁ àÅ×Íè ¹ IncCrsrShift CON %00000111 ' àÅ×Íè ¹µíÒá˹ §à¤Íà à«Íà 价ҧ¢ÇÒ â´ÂµÑÇÍÑ¡¢ÃÐàÅ×Íè ¹ä»·Ò§« Ò DecCrsr CON %00000100 ' àÅ×Íè ¹µíÒá˹ §à¤Íà à«Íà 价ҧ« Ò â´ÂµÑÇÍÑ¡¢ÃÐäÁ àÅ×Íè ¹ DecCrsrShift CON %00000101 ' àÅ×Íè ¹µíÒá˹ §à¤Íà à«Íà 价ҧ« Ò â´ÂµÑÇÍÑ¡¢ÃÐàÅ×Íè ¹ä»·Ò§¢ÇÒ ClearDisplay CON %00000001 ' à¤ÅÕÂà ¡ÒÃáÊ´§¼Å HomeDisplay CON %00000010 ' àÅ×Íè ¹µíÒá˹ §à¤Íà à«Íà ä»ÂѧµíÒá˹ §àÃÔÁè µ ¹ ScrollLeft CON %00011000 ' àÅ×Íè ¹µÑÇÍÑ¡¢ÃÐä»·Ò§« Ò ScrollRight CON %00011100 ' àÅ×Íè ¹µÑÇÍÑ¡¢ÃÐä»·Ò§¢ÇÒ CrsrLeft CON %00010000 ' àÅ×Íè ¹à¤Íà à«Íà 价ҧ« Ò CrsrRight CON %00010100 ' àÅ×Íè ¹à¤Íà à«Íà 价ҧ¢ÇÒ MoveCrsr CON %10000000 ' ¡íÒ˹´µíÒá˹ §¢Í§à¤Íà à«Íà (µ ͧ¡íÒ˹´¤ ÒááÍ´à´ÃÊ´ ÇÂ) MoveToCGRAM CON %01000000 ' ¡íÒ˹´µíÒá˹ §¢Í§ CGRAM (µ ͧ¡íÒ˹´¤ ÒááÍ´à´ÃÊ´ ÇÂ) ' Main Routines Init: PAUSE 1000 GOSUB InitLCD Start: LCDOUT LCDpin, ClearDisplay, ["Hello World!"] LCDOUT LCDpin, MoveCrsr+64, ["How are you?"] STOP ' Subroutines InitLCD: LCDCMD LCDpin, WakeUp ' àµÃÕÂÁ¡ÒÃÍÔ¹àÔ ªÕÂÅâÁ´ÙÅ LCD PAUSE 10 LCDCMD LCDpin, WakeUp PAUSE 1 LCDCMD LCDpin, WakeUp

'&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


µíÒá˹ §¢Í§¡ÒÃáÊ´§¼Åº¹Ë¹ Ҩͧ͢âÁ´ÙÅ LCD ¢¹Ò´ 16 µÑÇÍÑ¡Éà 2 ºÃ÷Ѵ ºÃ÷Ѵ·Õè 1

ºÃ÷Ѵ·Õè 2

$"

$#

$$

!

"

#

$

%

&

'

!

"

#

$%

$&

$'

%

%

%

%!

%"

%#

%$

%%

%&

%'

µíÒá˹ §¢Í§¡ÒÃáÊ´§¼Åº¹Ë¹ Ҩͧ͢âÁ´ÙÅ LCD ¢¹Ò´ 20 µÑÇÍÑ¡Éà 4 ºÃ÷Ѵ ºÃ÷Ѵ·Õè 1

ºÃ÷Ѵ·Õè 2

$"

$#

ºÃ÷Ѵ·Õè 3

ºÃ÷Ѵ·Õè 4

&"

&#

$$

&$

!

"

#

$

%

&

'

!

"

#

$

%

&

'

$%

$&

$'

%

%

%

%!

%"

%#

%$

%%

%&

%'

&

&

&

&!

!

"

#

$

%

'

!

!

!

!!

!"

!#

!$

!%

!&

!'

&%

&&

&'

'

'

'!

'"

'#

'$

'%

'&

''

!

& '

ÃÙ»·Õè 3-12 áÊ´§µíÒá˹ §¢Í§Ë¹ ǤÇÒÁ¨íÒáÃÁáÊ´§¼ÅËÃ×Í DDRAM ã¹âÁ´ÙÅ LCD ¢¹Ò´ 16 µÑÇÍÑ¡Éà 2 ºÃ÷Ѵ áÅÐ 20 µÑÇÍÑ¡Éà 4 ºÃ÷Ѵ (¤ ҢͧáÍ´à´ÃÊáÊ´§ã¹ÃÙ»¢Í§àÅ¢°Ò¹ÊÔº) PAUSE 1 LCDCMD LCDpin, FourBitMode LCDCMD LCDpin, TwoLine5x8Font LCDCMD LCDpin, DisplayOff LCDCMD LCDpin, DisplayOn LCDCMD LCDpin, IncCrsr LCDCMD LCDpin, ClearDisplay RETURN

' àÅ×Í¡¡ÒõԴµ ÍẺ 4 ºÔµ ' àÅ×Í¡áÊ´§¼Å 2 ºÃ÷Ѵ´ ǤÇÒÁÅÐàÍÕ´ 5x8 ¨Ø´µ ͵ÑÇ¢ÃÐ ' » ´¡ÒÃáÊ´§¼Å ' à» ´¡ÒÃáÊ´§¼ÅáÅÐà¤Íà à«Íà ¡Ð¾ÃÔº ' àÅ×Íè ¹µíÒá˹ §à¤Íà à«Îà ÁÒ·Ò§¢ÇÒ â´ÂµÑÇÍÑ¡¢ÃÐäÁ àÅ×Íè ¹ ' à¤ÅÕÂà ¨ÍáÊ´§¼Å

µíÒá˹ §¢Í§ÃÕ¨ÊÔ àµÍà ËÃ×Í˹ ǤÇÒÁ¨íÒáÃÁ·Õãè ª áÊ´§¼Åº¹âÁ´ÙÅ LCD ËÃ×Í DDRAM ¨Ðᵡµ Ò§ ¡Ñ¹ä»µÒÁ¢¹Ò´¢Í§âÁ´ÙÅ LCD ´Ñ§áÊ´§ã¹ÃÙ»·Õè 3-12 ´Ñ§¹Ñ¹é ËÒ¡µ ͧ¡ÒÃà¢Õ¹¢ ÍÁÙÅä»áÊ´§¼ÅÂѧµíÒá˹ § ã´µ ͧ¨´¨íÒÃٻẺã¹ÃÙ»·Õè 3-12 à¾×Íè ¨Ðä´ ¡Òí ˹´µíÒá˹ §ä´ Í ҧ¶Ù¡µ ͧ ÊíÒËÃѺµÑÇÍ ҧ¡Ò÷´Åͧ¨Ð¹íÒàʹÍà ÇÁ¡Ñ¹¡Ñº¤íÒÊѧè LCDIN áÅÐ LCDOUT

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

''


LCDIN ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè LCDIN Pin, Command, [InputData]

à» ¹¤íÒÊѧè ÊíÒËÃÑºÍ Ò¹¢ ÍÁÙŨҡâÁ´ÙÅ LCD ¾ÒÃÒÁÔàµÍà Pin à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ËÃ×Í 1 ËÃ×Í 8 ËÃ×Í 9 à¾×Íè 㪠àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 㹡ÒõԴµ ͡ѺâÁ´ÙÅ LCD ẺÍÑ¡¢ÃÐ (Character LCD module) ¡ÒõԴµ Íà» ¹áºº 4 ºÔµ ÁÕÃÒÂÅÐàÍÕ´´Ñ§¹Õé ¡Ã³Õ¡Òí ˹´ Pin à» ¹ 0 ËÃ×Í 1 ¢Ò¾Íà µ 0 ËÃ×Í 1 (ãª ä´ ·§Ñé P0 ¡Ñº P1) µ ͡Ѻ¢ÒàÍç¹àÍàºÔÅËÃ×Í E ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 2 (P2) µ ͡Ѻ¢Ò R/W ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 3 (P3) µ ͡Ѻ¢Ò RS ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 4 ¶Ö§ 7 (P4 ¶Ö§ P7) µ ͡Ѻ¢Ò¢ ÍÁÙÅ D4 ¶Ö§ D7 ¢Í§âÁ´ÙÅ LCD ¡Ã³Õ¡Òí ˹´ Pin à» ¹ 8 ËÃ×Í 9 ¢Ò¾Íà µ 8 ËÃ×Í 9 ( ãª ä´ ·§Ñé P8 ¡Ñº P9) µ ͡Ѻ¢ÒàÍç¹àÍàºÔÅËÃ×Í E ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 10 (P10) µ ͡Ѻ¢Ò R/W ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 11 (P11) µ ͡Ѻ¢Ò RS ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 12 ¶Ö§ 15 (P12 ¶Ö§ P15) µ ͡Ѻ¢Ò¢ ÍÁÙÅ D4 ¶Ö§ D7 ¢Í§âÁ´ÙÅ LCD Command à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 255 㪠áÊ´§¤íÒÊÑ§è ·ÕÊè § ä»ÂѧâÁ´ÙÅ LCD InputData à» ¹¾×¹é ·ÕÊè Òí ËÃѺà¡çº¢ ÍÁÙÅ·ÕÍè Ò ¹ÁÒä´ ¨Ò¡âÁ´ÙÅ LCD â´ÂÊÒÁÒöà¯çºäÇ ä´ ã¹ËÅÒÂÃٻẺ ·Ñ§é ÃËÑÊáÍÊ¡Õ,é àÅ¢°Ò¹Êͧ, àÅ¢°Ò¹ÊÔº, àÅ¢°Ò¹ÊԺˡ ËÃ×ÍÃٻẺ¢Í§µÑÇÍÑ¡Éà (string) ã¹µÒÃÒ§·Õè 3-7 áÊ´§ÃÙ» Ẻ¢Í§¢ ÍÁÙÅ·Õàè ¡çºä´ ¢Í§µÑÇá»Ã InputData ¹Õé ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè LCDIN ¹Õ¤é Í× (1) Ê §¤íÒÊѧè ä»ÂѧâÁ´ÙÅ LCD (´Ù¢Í ÁÙÅà¾ÔÁè àµÔÁã¹µÒÃÒ§·Õè 3-6 ã¹ËÑÇ¢ ͤíÒÊѧè LCDCMD) (2) ÃÍÃѺ¢ ÍÁÙÅ¢¹Ò´ 1 亵 ¡ÅѺ¨Ò¡Ë¹ ǤÇÒÁ¨íÒà¡çºµÑÇÍÑ¡Éà (CGRAM) ËÃ×Í˹ ǤÇÒÁ ¨íÒáÃÁà¡çº¢ ÍÁÙÅáÊ´§¼Å (DDRAM) µÑÇÍ ҧ¡ÒÃ㪠§Ò¹

CHAR VAR BYTE MAIN: LCDIN 1, 128, [CHAR] STOP

â»Ãá¡ÃÁ¢ Ò§µ ¹à» ¹¡ÒáíÒ˹´ãË i-Stamp2P24 Í Ò¹¢ ÍÁÙŵÑÇÍÑ¡ÉèҡµíÒá˹ § 0 ¢Í§Ë¹ ǤÇÒÁ¨íÒ áÃÁáÊ´§¼ÅËÃ×Í DDRAM (´ÙµÒí á˹ §¢Í§µÑÇÍÑ¡ÉÃã¹ÃÙ»·Õè 3-12 ã¹ËÑÇ¢ ͤíÒÊѧè LCDCMD)

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


µÑÇ¡íÒ˹´¡ÒÃá»Å§¢ ÍÁÙÅ »ÃÐàÀ·¢Í§¢ ÍÁÙÅ ¢ ÍÁÙÅ·ÕÃè ºÑ ä´ 0 ¶Ö§ 9 àÅ¢°Ò¹ÊÔº ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-5) µ Í· ÒÂËÁÒ¶֧ DEC {1...5} ¨íҹǹËÅÑ¡·ÕèáÊ´§ -, 0 ¶Ö§ 9 àÅ¢°Ò¹ÊԺẺ¤Ô´à¤Ã×èͧËÁÒ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-5) SDEC {1...5} µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ 0 ¶Ö§ 9 áÅÐ àÅ¢°Ò¹ÊԺˡ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· Ò HEX {1...4} ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ A ¶Ö§ F SHEX {1...4} àÅ¢°Ò¹ÊԺˡẺ¤Ô´à¤Ã×èͧËÁÒ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-5) -, 0 ¶Ö§ 9 áÅÐ µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ A ¶Ö§ F IHEX {1...4} $, 0 ¶Ö§ 9 áÅÐ àÅ¢°Ò¹ÊԺˡâ´ÂáÊ´§ÊÑ­Åѡɳ $ ¹íÒ˹ Ò àª ¹ $37A à» ¹µ ¹ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· ÒÂËÁÒ¶֧ A ¶Ö§ F ¨íҹǹËÅÑ¡·ÕèáÊ´§

ËÁÒÂà赯 1

ISHEX {1...4}

àÅ¢°Ò¹ÊԺˡẺ¤Ô´à¤Ã×èͧËÁÒ â´ÂáÊ´§ÊÑ­Åѡɳ $ ¹íÒ˹ Ò ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· ÒÂËÁÒ¶֧ ¨íҹǹËÅÑ¡·ÕèáÊ´§

-, $, 0 ¶Ö§ 9 áÅÐ A ¶Ö§ F

1, 2, 3, 4

BIN {1...16}

àÅ¢°Ò¹Êͧ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· Ò ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ àÅ¢°Ò¹ÊͧẺ¤Ô´à¤Ã×èͧËÁÒ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-16) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ àÅ¢°Ò¹Êͧâ´ÂáÊ´§ÊÑ­Åѡɳ % ¹íÒ˹ Ò àª ¹ %10111000 à» ¹µ ¹ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-16) µ Í· Ò ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§

0, 1

1

-, 0, 1

1, 2

%, 0, 1

1, 4

-,%, 0, 1

1, 2, 4

SBIN {1...16} IBIN {1...16}

ISBIN {1...16}

àÅ¢°Ò¹ÊͧẺ¤Ô´à¤Ã×èͧËÁÒ â´ÂáÊ´§ÊÑ­Åѡɳ % ¹íÒ˹ Ò ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· Ò ËÁÒ¶֧ ¨íҹǹËÅÑ¡·ÕèáÊ´§

1, 2 1, 3 1, 2, 3 1, 3, 4

ËÁÒÂà赯 (1) ¡ÒÃá»Å§¢ ÍÁÙŵÑÇàÅ¢¨Ð¡ÃзíÒÍ ҧµ Íà¹×èͧ ¨¹¡Ç Ò¨Ðä´ ¨íҹǹ¤ÃºµÒÁ·Õè¡íÒ˹´ (2) 㹡óÕ㪠à¤Ã×èͧËÁÒÂź (-) ¨Ðµ ͧµÒÁ´ ǵÑÇàÅ¢àÊÁÍ ÁԩйÑ鹨Ðà¡Ô´¡ÒõդÇÒÁÇ Òà» ¹µÑÇÍÑ¡Éà (3) ¢ ÍÁÙŵÑÇàÅ¢°Ò¹ÊԺˡäÁ ʹã¨Ç Ò¨Ðà» ¹µÑǾÔÁ¾ àÅç¡ËÃ×͵ÑǾÔÁ¾ ãË­ ¹Ñ蹤×Í a ¡Ñº A ÁÕ¤ÇÒÁËÁÒÂàËÁ×͹¡Ñ¹ (4) ¨ÐäÁ ʹ㨢 ÍÁÙÅ·ÕèÁÕ¡ÒüÊÁ¡ÑºµÑÇÍÑ¡É÷ÕèäÁ 㪠µÑÇàÅ¢ â´Âµ ͧÁÕ¡ÒÃãÊ à¤Ã×èͧËÁÒ $ ÊíÒËÃѺàÅ¢°Ò¹ÊԺˡ áÅÐ % ÊíÒËÃѺ àÅ¢°Ò¹Êͧ

µÒÃÒ§·Õè 3-7 ÃÒÂÅÐàÍÕ´ÃٻẺ¢Í§¢ ÍÁÙÅ·ÕÊè ÒÁÒÃ¶ãª ä´ ã¹µÑÇá»Ã InputData ¢Í§¤íÒÊѧè LCDIN

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ Í·Õè 15 ¡ÒÃ㪠§Ò¹¤íÒÊѧè LCDIN (1) µ Íǧ¨ÃµÒÁÃÙ»·Õè 3-13 (2) à¢Õ¹â»Ãá¡ÃÁ·´Åͧµ Í仹Õé '****PRELAB2P24-15.BSP : LCDIN command demonstrate **** ' {$STAMP BS2P} LCDpin CON 1 ' ¡íÒ˹´ÅѡɳСÒõ Í¢Ò¾Íà µ¢Í§ i-Stamp2P24 ¡ÑºâÁ´ÙÅ LCD char VAR Byte(16) ' ¡íÒ˹´µÑÇá»ÃÊíÒËÃѺà¡çº¤ Ò·ÕÍè Ò ¹íÒä´ ¨Ò¡âÁ´ÙÅ LCD Init: LCDCMD LCDpin, 48 ' ÍÔ¹àÔ ªÕÂÅâÁ´ÙÅ LCD PAUSE 10 LCDCMD LCDpin, 48 PAUSE 1 LCDCMD LCDpin, 48 PAUSE 1 LCDCMD LCDpin, 32 ' àÅ×Í¡âË·Á´µÔ´µ ÍẺ 4 ºÔµ LCDCMD LCDpin, 40 ' àÅ×Í¡áÊ´§¼Å 2 ºÃ÷Ѵ´ ǤÇÒÁÅÐàÍÕ´ 5x8 ¨Ø´ LCDCMD LCDpin, 8 ' » ´¡ÒÃáÊ´§¼Å LCDCMD LCDpin, 12 ' à» ´¡ÒÃáÊ´§¼ÅáÅÐà¤Íà à«Íà ¡Ð¾ÃÔº LCDCMD LCDpin, 6 ' àÅ×Íè ¹µíÒá˹ §à¤Íà à«Îà ÁÒ·Ò§¢ÇÒ â´ÂµÑÇÍÑ¡¢ÃÐäÁ àÅ×Íè ¹ Start: LCDOUT LCDpin,1,["Hello!"] ' áÊ´§¢ ͤÇÒÁ·Õâè Á´ÙÅ LCD GOSUB ReadLCDScreen ' ¡ÃÐâ´´ä»Âѧâ»Ãá¡ÃÁ Í ReadLCDScreen PAUSE 3000 LCDOUT LCDpin, 1, ["I m a 2x16 LCD!"] ' áÊ´§¢ ͤÇÒÁ·Õâè Á´ÙÅ LCD GOSUB ReadLCDScreen ' ¡ÃÐâ´´ä»Âѧâ»Ãá¡ÃÁ Í ReadLCDScreen +5V

P3

RS

P2

R/W E D7 D6 D5 D4 D3 D2 D1 D0

P1

LCD 16x2 LCD 20x4

+Vcc Vo GND

2 3 1

VR1 10k BRIGHTNESS

i-Stamp2P P7 P6 P5 P4

ÃÙ»·Õè 3-13 ǧ¨Ã·´Åͧ㪠§Ò¹¤íÒÊÑ§è µÔ´µ ÍáÅФǺ¤ØÁâÁ´ÙÅ LCD ¢Í§ i-Stamp2P24

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


PAUSE 3000 GOTO Start ReadLCDScreen: DEBUG "LCD Now Says: " LCDIN LCDpin, 128, [STR char\16] DEBUG STR char\16, CR, CR RETURN

' áÊ´§¢ ͤÇÒÁ·ÕËè ¹ Òµ Ò§ Debug Terminal ' Í Ò¹¤ Ò¨Ò¡âÁ´ÙÅ LCD ' áÊ´§¢ ͤÇÒÁ·ÕÍè Ò ¹ä´ ¨Ò¡âÁ´ÙÅ LCD ·ÕËè ¹ Òµ Ò§ Debug Terminal

(3) ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ Êѧࡵ¡ÒÃáÊ´§¼Å¢Í§âÁ´ÙÅ LCD áÅÐ˹ Òµ Ò§ Debug terminal àÁ×Íè Ãѹâ»Ãá¡ÃÁ ·ÕËè ¹ ¨Í¢Í§âÁ´ÙÅ LCD ¨ÐáÊ´§¢ ͤÇÒÁ Hello! ÊÅѺ¡Ñº I m LCD! ã¹¢³Ð·ÕË è ¹ Òµ Ò§ Debug Terminal ¡ç¨ÐáÊ´§¢ ͤÇÒÁàËÁ×͹¡Ñ¹

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

a

2x16

!


LCDOUT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè LCDOUT Pin, Command, [OutputData]

à» ¹¤íÒÊѧè ÊíÒËÃѺà¢Õ¹¢ ÍÁÙÅä»ÂѧâÁ´ÙÅ LCD ¾ÒÃÒÁÔàµÍà Pin à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ËÃ×Í 1 ËÃ×Í 8 ËÃ×Í 9 à¾×Íè 㪠àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 㹡ÒõԴµ ͡ѺâÁ´ÙÅ LCD ẺÍÑ¡¢ÃÐ (Character LCD module) ¡ÒõԴµ Íà» ¹áºº 4 ºÔµ ÁÕÃÒÂÅÐàÍÕ´´Ñ§¹Õé ¡Ã³Õ¡Òí ˹´ Pin à» ¹ 0 ËÃ×Í 1 ¢Ò¾Íà µ 0 ËÃ×Í 1 (ãª ä´ ·§Ñé P0 ¡Ñº P1) µ ͡Ѻ¢ÒàÍç¹àÍàºÔÅËÃ×Í E ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 2 (P2) µ ͡Ѻ¢Ò R/W ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 3 (P3) µ ͡Ѻ¢Ò RS ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 4 ¶Ö§ 7 (P4 ¶Ö§ P7) µ ͡Ѻ¢Ò¢ ÍÁÙÅ D4 ¶Ö§ D7 ¢Í§âÁ´ÙÅ LCD ¡Ã³Õ¡Òí ˹´ Pin à» ¹ 8 ËÃ×Í 9 ¢Ò¾Íà µ 8 ËÃ×Í 9 ( ãª ä´ ·§Ñé P8 ¡Ñº P9) µ ͡Ѻ¢ÒàÍç¹àÍàºÔÅËÃ×Í E ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 10 (P10) µ ͡Ѻ¢Ò R/W ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 11 (P11) µ ͡Ѻ¢Ò RS ¢Í§âÁ´ÙÅ LCD ¢Ò¾Íà µ 12 ¶Ö§ 15 (P12 ¶Ö§ P15) µ ͡Ѻ¢Ò¢ ÍÁÙÅ D4 ¶Ö§ D7 ¢Í§âÁ´ÙÅ LCD Command à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 255 㪠áÊ´§¤íÒÊÑ§è ·ÕÊè § ä»ÂѧâÁ´ÙÅ LCD OutputData à» ¹µÑÇá»ÃÊíÒËÃѺà¡çº¢ ÍÁÙÅ·Õµè Í §¡ÒÃÊ §ä»ÂѧâÁ´ÙÅ LCD ÁÕû٠Ẻ¢Í§¢ ÍÁÙÅáÊ´§ã¹µÒÃÒ§ ·Õè 3-5 àËÁ×͹¡Ñº·Õãè ª 㹤íÒÊѧè I2COUT ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè LCDOUT ÁÕ´§Ñ ¹Õé (1) Ê §¤íÒÊѧè ä»ÂѧâÁ´ÙÅ LCD (´Ù¢Í ÁÙÅà¾ÔÁè àµÔÁ¨Ò¡µÒÃÒ§¤íÒÊÑ§è ¢Í§âÁ´ÙÅ LCD ã¹µÒÃÒ§·Õè 36 ã¹ËÑÇ¢ ͤíÒÊѧè LCDCMD) (2) à¢Õ¹¢ ÍÁÙÅ·Õèµ Í§¡ÒÃáÊ´§¼Åä»Âѧ˹ ǤÇÒÁ¨íÒà¡çºµÑÇÍÑ¡Éà (CGRAM) ËÃ×Í˹ Ç ¤ÇÒÁ¨íÒáÃÁà¡çº¢ ÍÁÙÅáÊ´§¼Å (DDRAM) µÑÇÍ ҧ¡ÒÃ㪠§Ò¹¤íÒÊÑè§Áմѧ¹Õé LCDOUT 1, 1, [ Hello World! ]

à» ¹¤íÒÊѧè à¤ÅÕÂà ¨ÍáÊ´§¼Å¢Í§âÁ´ÙÅ LCD ¨Ò¡¹Ñ¹é Ê §¢ ͤÇÒÁ Hello World! ä»áÊ´§·Õâè Á´ÙÅ LCD.

"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡ÒÃÊà ҧµÑÇÍÑ¡ÉÃËÃ×ÍÊÑ­Åѡɳ º¹âÁ´ÙÅ LCD âÁ´ÙÅ LCD ẺÍÑ¡¢Ãйըé ÐÁÕ¾¹×é ·Õ¢è ͧ˹ ǤÇÒÁ¨íÒáÃÁÊíÒËÃѺà¡çº¢ ÍÁÙŵÑÇÍÑ¡ÉÃËÃ×Í CGRAM ·Õµè Í § ¡ÒÃáÊ´§¼Å੾ÒÐÍÂÙ 8 亵 µ ͵ÑÇÍÑ¡ÉÃËÃ×ÍÊÑ­Åѡɳ 1 µÑÇÊíÒÃͧäÇ ãË ¼ãÙ ª §Ò¹Êà ҧÊÑ­Åѡɳ ¾àÔ ÈÉ੾ÒеÑÇ ã¹ÃÙ»·Õè 3-14 áÊ´§µÑÇÍ ҧ¡ÒÃÊà ҧÊÑ­Åѡɳ ¾àÔ ÈÉáÅТ ÍÁÙÅ·Õàè ¡Ô´¢Ö¹é àÁ×Íè ä´ ¢Í ÁÙÅ·Õµè Í §¡ÒÃáÅ ÇÊÒÁÒöà¢Õ¹ â»Ãá¡ÃÁà¾×Íè ¹íÒ¢ ÍÁÙÅàËŠҹѹé ŧä»à¡çºã¹âÁ´ÙÅ LCD ´Ñ§¹Õé

àÊÁÍ

LCDOUT 1, 64+0, [00, 10, 10, 00, 17, 14, 06, 00] LCDOUT 1, 128+0, ["Custom Char: ", 0] µÑÇàÅ¢ 64 à» ¹¢ ÍÁÙŤíÒÊÑ§è µÔ´µ ÍáÍ´à´Ãʢͧ CGRAM µÑÇàÅ¢ 0 à» ¹¡ÒáíÒ˹´áÍ´à´ÃÊàÃÔÁè µ ¹ ÊÔ§è ·Õµè Í §äÁ ÅÁ× ã¹¡ÒÃ㪠§Ò¹ i-Stamp2P24 ¢ÑºâÁ´ÙÅ LCD ¤×Í µ ͧÍÔ¹àÔ ªÕÂÅâÁ´ÙÅ LCD ¡ ͹㪠§Ò¹

亵 0 亵 1 亵 2 亵 3 亵 4 亵 5 亵 6 亵 7

ºÔµ 4 3 2 1 0

¢ ÍÁÙÅàÅ¢°Ò¹Êͧ

¢ ÍÁÙÅàÅ¢°Ò¹ÊÔº

N N N

N N N

N N N

N N N

"

N N N

%

N N N

"

N N N

N N N

ÃÙ»·Õè 3-14 áÊ´§µÑÇÍ ҧ¡ÒáíÒ˹´¢ ÍÁÙÅà¾×Íè Êà ҧµÑÇÍÑ¡ÉÃËÃ×ÍÊÑ­Åѡɳ º¹âÁ´ÙÅ LCD

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#


¡Ò÷´Åͧ Í·Õè 16 ¡ÒÃ㪠§Ò¹¤íÒÊѧè LCDOUT (1) 㪠ǧ¨ÃµÒÁÃÙ»·Õè 3-13 㹡Ò÷´Åͧ (2) à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁÊ» àÍ´ÔàµÍà à¾×Íè à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '****PRELAB2P24-16.BSP : LCDOUT command demonstrate **** ' {$STAMP BS2p} ' {PBASIC2.5} LCDpin CON 1 ' LCD connnection WakeUp CON %00110000 ' Wake-up FourBitMode CON %00100000 ' Set to 4-bit mode TwoLine5x8FontCON %00101000 ' Set to 2 display lines, 5x8 font DisplayOff CON %00001000 ' Turn off display, data is retained DisplayOn CON %00001100 ' Turn on display, no cursor IncCrsr CON %00000110 ' Auto-increment cursor, no display shift ClearDisplay CON %00000001 ' Clear the display MoveCrsr CON %10000000 ' Move cursor to position (must add address) ' Main Routines Init: PAUSE 1000 GOSUB InitLCD Start: LCDOUT LCDpin, ClearDisplay, ["Hello my friend."] PAUSE 1000 LCDOUT LCDpin, MoveCrsr+64, ["How are you?"] PAUSE 3000 LCDCMD LCDpin, ClearDisplay LCDOUT LCDpin, MoveCrsr+1, ["I m doing just"] LCDOUT LCDpin, MoveCrsr+70, ["fine!"] PAUSE 3000 GOTO Start ' Subroutines InitLCD: LCDCMD LCDpin, WakeUp PAUSE 10 LCDCMD LCDpin, WakeUp PAUSE 1 LCDCMD LCDpin, WakeUp PAUSE 1 LCDCMD LCDpin, FourBitMode

$

' Send wakeup sequence to LCD

' Set buss to 4-bit mode

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


LCDCMD LCDpin, TwoLine5x8Font LCDCMD LCDpin, DisplayOff LCDCMD LCDpin, DisplayOn LCDCMD LCDpin, IncCrsr LCDCMD LCDpin, ClearDisplay RETURN

' Set to 2-line mode with 5x8 font ' Turn display off ' Turn display on with blinking cursor ' Set to auto-increment cursor (no display shift) ' Clear the display

(3) ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ Êѧࡵ¡ÒÃáÊ´§¼Å¢Í§âÁ´ÙÅ LCD àÁ×Íè Ãѹâ»Ãá¡ÃÁ âÁ´ÙÅ LCD ¨ÐáÊ´§¢ ͤÇÒÁ Hello my friend. ·º Õè Ã÷Ѵº¹ ¨Ò¡¹Ñ¹é áÊ´§¢ ͤÇÒÁ How are you? ·Õº è Ã÷ѴŠҧ áÅ Çà¤ÅÕÂà ˹ Ò¨Íà¾×Íè áÊ´§¢ ͤÇÒÁ I m doing

just

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

fine!

%


LOOKDOWN ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè LOOKDOWN value,{ComparisonOp,}[value0, value1,...valueN],resultVariable

à» ¹¤íÒÊÑ§è ·Õãè ª ÊÒí ËÃѺà¡çº¤ ÒµÑǪբé ͧµÑÇàÅ¢·Õ¹è Òí ÁÒà»ÃÕºà·ÕºáŠǼšÒÃà»ÃÕºà·Õº໠¹¨ÃÔ§ ¾ÒÃÒÁÔàµÍà value à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÊè Òí ËÃѺà»ÃÕºà·Õº¡Ñº¤ Ò·ÕÍè ÂÙã ¹ value0 valueN ComparisonOp à» ¹¡ÒáíÒ˹´à§×è͹ä¢ã¹¡ÒÃà»ÃÕºà·Õºà¾ÔèÁàµÔÁ «Ö觨Ð㪠ËÃ×ÍäÁ ¡çä´ â´Â¤ Ò·Õè ÃкØã¹ Comparison Op à» ¹¤ Ҵѧµ Í仹Õé = ෠ҡѺ <> äÁ ෠ҡѺ > ÁÒ¡¡Ç Ò < ¹ ÍÂ¡Ç Ò >= ÁÒ¡¡Ç ÒËÃ×Í෠ҡѺ <= ¹ ÍÂ¡Ç ÒËÃ×Í෠ҡѺ ¶ ÒäÁ Á¡Õ ÒÃÃÐºØ¤Ò ComparisonOp àºÊÔ¡áʵÁ» 2P ¨Ðá»Å¤ÇÒÁËÁÒÂà» ¹à¤Ã×Íè §ËÁÒÂ෠ҡѺ (=) value0, value1... Êà ҧºÑ­ªÕÃÒª×Íè ¢Í§¤ Ò¢ ÍÁÙÅâ´Â¤ Ò·Õ¡è Òí ˹´¹Õàé » ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õ¡è äç ´ ÁÕ¢¹Ò´ ÊÙ§ÊØ´ 16 ºÔµ ResultVariable à» ¹µÑÇá»ÃÊíÒËÃѺà¡çº¤ ÒµÑǪÕé ¶ ÒËÒ¡¡ÒÃà»ÃÕºà·Õº¾º¤ Ò·Õµè ç¡Ñ¹ ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊѧè LOOKDOWN ·íÒ§Ò¹àËÁ×͹ÊÒúѭã¹Ë¹Ñ§Ê×Í ¼Ùã ª §Ò¹ÊÒÁÒö¤ ¹ËÒàÃ×Íè §ÃÒÇ·Õµè Í §¡ÒÃã¹Ë¹Ñ§Ê×Í ¨Ò¡Ë¹ ÒÊÒúѭ â´Â¤íÒÊѧè LOOKDOWN ¨Ð·íÒ¡ÒÃà»ÃÕºà·Õº¡ÅØÁ ¢ ÍÁÙÅã¹ÃÒ¡Òà ¨Ò¡¹Ñ¹é à¡çº¤ ÒµÑÇàÅ¢·Õªè äÕé » ÂѧÃÒ¡Ò÷յè ÃǨÊͺ¾ºÇ Ò ÁÕ¤Ò µÃ§µÒÁà§×Íè ¹ä¢¢Í§¡ÒÃà»ÃÕºà·Õº ´Ñ§â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' {$STAMP BS2p} ' STAMP directive (specifies a BS2p) VALUE VAR BYTE RESULT VAR NIB VALUE = 17 RESULT = 15 LOOKDOWN VALUE,[26,177,13,1,0,17,99],RESULT DEBUG "Value matches item ",DEC RESULT," in list"

àÁ×Íè Ãѹâ»Ãá¡ÃÁ¹Õé ˹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¢ ͤÇÒÁ Value matches item 5 in list à¹×Íè § ¨Ò¡¤ Ò VALUE (17) ÁÕ¤Ò µÃ§¡Ñº¢ ÍÁÙŵÑÇ·Õè 5 ¢Í§¡ÅØÁ ¢ ÍÁÙÅ [26,177,13,1,0,17,99] (¤ ÒµÑÇàÅ¢¹Ñº¨Ò¡ 0 à» ¹µ ¹ ä» äÁ ä´ ¹ºÑ ¨Ò¡ 1) 㹡óշ¤Õè Ò VALUE äÁ ÁÍÕ ÂÙã ¹ÃÒ¡Òà ઠ¹ ¶ Òà»ÅÕÂè ¹ VALUE = 17 à» ¹ VALUE = 2 µÑÇàÅ¢ 2 äÁ ÍÂÙã ¹ÃÒ¡Òà ´Ñ§¹Ñ¹é ¼ÅÅѾ¸ ·äÕè ´ ¨Ðà» ¹¤ Ò 15 «Ö§è ¡ç¤Í× ¤ Òà´ÔÁ¡ ͹·íÒ¤íÒÊѧè LOOKDOWN ¹Ñ¹è àͧ

&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


LOOKUP ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè LOOKUP index, [value0, value1,...valueN], resultVariable

à» ¹¤íÒÊÑ§è ·Õãè ª 㹡ÒÃà» ´µÒÃÒ§¢ ÍÁÙÅ â´Â¤íÒÊѧè LOOKUP ¨ÐÁͧËÒ¤ Ò·Õªè âÕé ´Â index áÅйíÒ¤ Ò·Õäè ´ ä»à¡çºã¹ ResultVariable ¶ Ò¤ Ò index ÁÕ¤Ò ÁÒ¡¡Ç Ò¤ Ò·ÕÍè ÂÙã ¹ÃÒ¡Òâͧ Value ¤ Ò ResultVariable ¨ÐäÁ Á¡Õ ÒÃà»ÅÕÂè ¹á»Å§ ¾ÒÃÒÁÔàµÍà index à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õàè ¾×Íè ¡íÒ˹´à» ¹µÑǪդé Ò µÑÇàÅ¢¨Ò¡ÃÒ¡Òà value0, value1... à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕèÊíÒËÃѺÊà ҧÃÒ¡Òâ ÍÁÙÅ â´Â¤ ÒµÑÇàÅ¢ÁÕ¢¹Ò´ÊÙ§ÊØ´ ä´ ¶§Ö 16 ºÔµ ResultVariable à» ¹µÑÇá»Ã·Õãè ª à¡çº¤ Ò¢ ÍÁÙŶ ÒÁÕ¡ÒõÃǨ¾º µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè INDEX VAR NIB RESULT VAR BYTE INDEX = 3 RESULT = 255 LOOKUP INDEX,[26,177,13,1,0,17,99],RESULT DEBUG "Item ", dec INDEX," is: ", DEC RESULT

àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§¢Í§ Debug Terminal ¨ÐáÊ´§ Item 3 is: 1. (¤ Ò INDEX àÃÔÁè ¨Ò¡¤ Ò 0) ¶ Ò¤ Ò INDEX ÁÕ¤Ò à¡Ô¹¤ ÒµÑÇàÅ¢·ÕÁè ãÕ ¹ÃÒ¡Òä Ò RESULT ¨ÐäÁ à»ÅÕÂè ¹á»Å§ ã¹â»Ãá¡ÃÁµÑÇÍ ҧ ¶ Ò¡íÒ˹´ãË INDEX ÁÕ¤Ò ÁÒ¡¡Ç Ò 6 ¤ Ò RESULT ¨Ð෠ҡѺ 255 à¹×Íè §¨Ò¡¤ Ò 255 à» ¹¤ Ò¡ ͹·íÒ¤íÒÊѧè LOOKUP

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'


LOW ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè LOW pin

㪠㹡ÒáíÒ˹´ãË ¢Ò¾Íà µ·Õàè » ¹àÍÒµ ¾µØ ÁÕÅͨԡ໠¹ 0 ¾ÒÃÒÁÔàµÍà pin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò µÑ§é áµ 0 ¶Ö§ 15 à¾×Íè àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2p24 ·Õµè Í §¡Òà ¤íÒ͸ԺÒÂà¾ÔÁè àµÔÁ 㹡ÒÃÊ §¤ ÒÅͨԡ 0 ä»Âѧ¢ÒàÍÒµ ¾µØ ¢Í§ i-Stamp2P24 ÁÕ 2 ¢Ñ¹é µÍ¹¤×Í (1) ¡íÒ˹´ãË ºµÔ ã¹ÃÕ¨ÊÔ àµÍà DIRS ã¹µíÒá˹ §·Õµè Í §¡ÒÃÊ §¤ ÒÁÕÅͨԡ 1 (2) ¡íÒ˹´ãË ºµÔ ã¹ÃÕ¨ÊÔ àµÍà OUTS ã¹µíÒá˹ §·Õµè Í §¡ÒÃÊ §¤ ÒÁÕÅͨԡ 0 ¤íÒÊѧè LOW ¹Ñ¹é ¨ÐÃÇÁÊͧ¢Ñ¹é µÍ¹¹Õàé ÍÒäÇ ã¹¤íÒÊѧè à´ÕÂÇà¾Õ§ÃкصÒí á˹ §¢Ò·Õµè Í §¡ÒÃãË ÁÅÕ Í¨Ô¡ 0 ෠ҹѹé

¡Ò÷´Åͧ Í·Õè 17 ¡ÒÃ㪠§Ò¹¤íÒÊѧè LOW (1) 㪠ǧ¨ÃÃÙ»·Õè 3-15 㹡Ò÷´Åͧ (2) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé ' {$STAMP BS2p} HIGH 4 PAUSE 2500 LOW 4

(3) Ãѹâ»Ãá¡ÃÁ áÅ ÇÊѧࡵ¡ÒÃáÊ´§¼Å¢Í§ LED LED ·Õµè Í ¡Ñº¢Ò P4 ¨ÐµÔ´ÊÇ Ò§¹Ò¹ 2.5 ÇÔ¹Ò·Õ áŠǴѺ

i-Stamp2P24

P4

510

LED

ÃÙ»·Õè 3-15 ǧ¨Ã·´Åͧ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè LOW

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


(4) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2P24-17.BSP : LOW command demonstration***** ' {$STAMP BS2P} DIRS = % 10000 ' ¡íÒ˹´ãË P4 à» ¹ 1 OUTS = %10000 DEBUG "Before: ",CR ' áÊ´§¢ ͤÇÒÁ·ÕËè ¹ Òµ Ò§ Debug Terminal DEBUG BIN16 ? DIRS,BIN16 ? OUTS,CR,CR ' áÊ´§¤ Ңͧ P4 ·ÕËè ¹ Òµ Ò§ Debug Terminal PAUSE 2500 LOW 4 DEBUG "After: ",CR ' áÊ´§¢ ͤÇÒÁ·ÕËè ¹ Òµ Ò§ Debug Terminal DEBUG BIN16 ? DIRS,BIN16 ? OUTS ' áÊ´§¤ Ңͧ P4 ËÅѧ¨Ò¡¡ÃзíÒ¤íÒÊѧè LOW ·ÕËè ¹ Òµ Ò§ Debug Terminal

(5) Ãѹâ»Ãá¡ÃÁ ¨Ð»ÃÒ¡¯Ë¹ Òµ Ò§ Debug Terminal áÊ´§¤ ҢͧÃÕ¨ÊÔ àµÍà DIRS áÅÐ OUTS Êѧࡵ·Õºè µÔ 4 ¢Í§ÃÕ¨ÊÔ àµÍà ·Ñ§é ÊͧµÑÇ â´Â㹺Ã÷Ѵáá໠¹¤ ҢͧÃÕ¨ÊÔ àµÍà ¡Í ¹¡ÃзíÒ¤íÒÊѧè LOW 4 Ê Ç¹ºÃ÷ѴŠҧ໠¹¤ ҢͧÃÕ¨ÊÔ àµÍà ËÅѧ¡ÃзíÒ¤íÒÊѧè LOW 4

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


MAINIO ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè MAINIO

¤íÒÊѧè à»ÅÕÂè ¹¡ÒõԴµ ;Íà µ¨Ò¡¡ÅØÁ ¾Íà µàÊÃÔÁ A0 ¶Ö§ A15 à» ¹¡ÅØÁ ¾Íà µËÅÑ¡ P0 ¶Ö§ P15 µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ AUXIO HIGH 0 MAINIO LOW 0

¨Ò¡â»Ãá¡ÃÁµÑÇÍ ҧ¢ Ò§µ ¹ 㹺Ã÷Ѵáá໠¹¡ÒÃàÅ×Í¡µÔ´µ ͡Ѻ¾Íà µàÊÃÔÁ A0 ¶Ö§ A15 áŠǤǺ¤ØÁ ãË ¢Ò¾Íà µ 0 «Ö§è 㹡óչ¤Õé Í× ¢Ò A0 ÁÕÅͨԡ 1 Ê §ÍÍ¡ÁÒ ¨Ò¡¹Ñ¹é àÅ×͡㪠¤Òí Êѧè MAINIO ·íÒãË à»ÅÕÂè ¹¡ÒõԴµ Íä» Âѧ¢Ò¾Íà µËÅÑ¡ P0 ¶Ö§ P15 á·¹ â´Â·ÕèʶҹÐÅͨԡ¢Í§¢Ò¾Íà µàÊÃÔÁÂѧ¤§äÁ à»ÅÕè¹á»Å§ 㹺Ã÷ѴÊØ´· ÒÂà» ¹ ¡ÒáíÒ˹´ãË ¢Ò¾Íà µ 0 «Ö§è 㹤ÃÒǹÕàé » ¹¢Ò P0 ÁÕʶҹÐÅͨԡ໠¹ 0 ¹Ñ¹è ¤×ÍàÁ×Íè i-Stamp2p24 ·íÒ§Ò¹µÒÁâ»Ãá¡ÃÁ¹Õé ¢Ò¾Íà µ A0 ¨ÐÁÕÅͨԡ 1 ã¹¢³Ð·Õ¢è Ò P0 ÁÕÅͨԡ໠¹ 0

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


NAP ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè NAP period

à» ¹¤íÒÊÑè§ÊíÒËÃѺ¡íÒ˹´ãË i-Stamp2p24 ࢠÒÊÙ âËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹ã¹ª ǧàÇÅÒÊÑé¹æ ·íÒãË àºÊÔ¡áʵÁ» 2P ¡Ô¹¡ÃÐáÊŴŧàËÅ×Íà¾Õ§»ÃÐÁÒ³ 60PA ã¹¢³Ð·Õäè Á Á¡Õ ÒâѺâËÅ´ã´æ ¾ÒÃÒÁÔàµÍà period à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÊè Òí ËÃѺ¡íÒ˹´¤ÒºàÇÅÒ·Õàè ¢ ÒÊÙâ ËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹ ¤ Ò¤ÒºàÇÅÒ¨ÐÁÕ period ¤ Ò෠ҡѺ (2 ) x 18 ÁÔÅÅÔÇ¹Ô Ò·Õ ¤ Ò period ¡íÒ˹´ä´ µ§Ñé áµ 0 ¶Ö§ 7 â´Â¤ Ò·Õ¡è Òí ˹´·íÒãË ä´ ªÇ §àÇÅҴѧ¹Õé ¤ Ò Period 2 Period ª ǧàÇÅÒ 0 1 18 ÁÔÅÅÔÇ¹Ô Ò·Õ 1 2 36 ÁÔÅÅÔÇ¹Ô Ò·Õ 2 4 72 ÁÔÅÅÔÇ¹Ô Ò·Õ 3 8 144 ÁÔÅÅÔÇ¹Ô Ò·Õ 4 16 288 ÁÔÅÅÔÇ¹Ô Ò·Õ 5 32 576 ÁÔÅÅÔÇ¹Ô Ò·Õ 6 64 1152 ÁÔÅÅÔÇ¹Ô Ò·Õ (1.152 ÇÔ¹Ò·Õ) 7 128 2304 ÁÔÅÅÔÇ¹Ô Ò·Õ (2.304 ÇÔ¹Ò·Õ) ¶ ÒÁÕ¡ÒÃ㪠¤íÒÊÑè§ NAP ã¹¢³Ð·ÕèÁÕ¡ÒâѺâËÅ´ÍÂÙ ¡ÃÐáÊ·ÕèäËż Ò¹âËÅ´¨ÐËÂØ´ªÐ§Ñ¡´ Ǫ ǧ àÇÅÒÊѹé æ »ÃÐÁÒ³ 18 ÁÔÅÅÔÇ¹Ô Ò·Õ

¡Ã·´Åͧ Í·Õè 18 ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè NAP (1) 㪠ǧ¨ÃÃÙ»·Õè 3-15 (¨Ò¡ÃÙ»ã¹ËÑÇ¢ ͤíÒÊѧè LOW) 㹡Ò÷´Åͧ (2) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2P24-18.BSP : NAP command demonstration***** ' {$STAMP BS2P} HIGH 0 ' Turn LED on. SNOOZE: NAP 5 ' NAP FOR 576 ms. GOTO SNOOZE

(3) Ãѹâ»Ãá¡ÃÁ Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED ¨Ð¾ºÇ Ò ¢³ÐÍÂÙã ¹¤íÒÊѧè NAP µÑÇ LED Âѧ¤§µÔ´ÊÇ Ò§ áµ ¨ÐÁÕ¡ÒáоÃÔº´ Ǫ ǧàÇÅÒÊѹé æ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


ON...GOSUB ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè ON offset GOSUB Target0 {, Target1, Target2, ...TargetN }

à» ¹¤íÒÊѧè àÅ×Í¡â»Ãá¡ÃÁ Í·ըè СÃÐâ´´ä»·íÒ§Ò¹ ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊÑ§è ¹Õ¤é Å Ò¡Ѻ¤íÒÊѧè BRANCH áµ á·¹·Õ¨è ÐãË ¢Í ÁÙÅ¡ÅѺÁÒàËÁ×͹¡Ñº¤íÒÊѧè BRANCH ᵠ㹤íÒÊÑ§è ¹Õàé Á×Íè ¤ Ңͧ offset ෠ҡѺ 0 ¡ç¨Ð¡ÃÐâ´´ä»·íÒ§Ò¹·Õâè »Ãá¡ÃÁ ÍÂ«Ö§è ¡íÒ˹´â´Â Target0 ¨Ò¡¹Ñ¹é ¨Ð¡ÅѺÁÒ µÃǨÊͺ¤ Ңͧ offset Ç Òà» ¹à· Òã´ ËÒ¡à» ¹ 1 ¨Ð¡ÃÐâ´´ä»·íÒ§Ò¹·Õâè »Ãá¡ÃÁ ÍÂ«Ö§è ¡íÒ˹´â´Â Target1 ¹Í¡¨Ò¡¹Ñ¹é ËÒ¡¤ Ңͧ Target ÁÕÁÒ¡¨¹äÁ àËÁÒзըè Ðà¢Õ¹ŧ㹺Ã÷Ѵà´ÕÂÇ ¼Ùã ª §Ò¹ÊÒÁÒö㪠¨ÅØ ÀÒ¤ ËÃ×ͤÍÁÁ Ò㹡ÒÃàª×èÍÁµ ÍàÁ×èͨíÒà» ¹µ ͧà¢Õ¹â»Ãá¡ÃÁ¢Ö鹺Ã÷ѴãËÁ ¤ Ңͧ offset ÊÒÁÒö໠¹¤ Ò¤§·ÕËè Ã×͵ÑÇá»Ã ÁÕ¤Ò 0 ¶Ö§ 255 µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè DO

ON task GOSUB Update_Motors, Read_IR, Read_Light, Read_Temp task = task + 1 // NumTasks LOOP

ã¹â»Ãá¡ÃÁ¹Õé i-Stamp2P24 ¨Ð¡ÃÐâ´´ä»·íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í Update_Motors àÁ×Íè ¤ Ңͧ task = 0 ËÅѧ¨Ò¡¹Ñ鹨ÐÁÕ¡ÒÃà¾ÔèÁ¤ Ò task ¢Öé¹ ·íÒãË ÊÒÁÒö¡ÃÐâ´´ä»·íÒ§Ò¹·Õèâ»Ãá¡ÃÁ ÍÂÍ×è¹æ µ Íä»ä´ áÅÐà¹×èͧ¨Ò¡ÁÕ â»Ãá¡ÃÁ Í·ѧé ËÁ´ 4 â»Ãá¡ÃÁ ¨Ö§µ ͧ¡íÒ˹´¤ Ңͧ NumTasks äÇ à· Ò¡Ñº 4 ¹Ñ¹è ¤×ͤ Ңͧ task ¨Ð෠ҡѺ 0 ¶Ö§ 3 àÁ×Íè task = 0 ¨Ð·íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í Update_Motors àÁ×Íè task = 1 ¨Ð·íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í Read_IR àÁ×Íè task = 2 ¨Ð·íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í Read_Light àÁ×Íè task = 3 ¨Ð·íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í Read_Temp ¨Ò¡¹Ñ¹é ¤ Ңͧ taks ¨Ð¡ÅѺä»à» ¹ 0 ·íÒãË Ç¹¡ÅѺ价íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í Update_Motors ã¹â»Ãá¡ÃÁ ÍÂáµ ÅеÑǵ ͧÁÕ¤Òí Êѧè RETURN àÁ×Íè ¡íÒ˹´¨Ø´ÊÔ¹é Êش㹡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁ Í¹ѹé æ ´ ÇÂ

"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


ON...GOTO ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè ON offset GOTO Target0 {, Target1, Target2, ...TargetN }

à» ¹¤íÒÊѧè àÅ×Í¡µíÒá˹ §¢Í§â»Ãá¡ÃÁ·Õ¨è СÃÐâ´´ä»·íÒ§Ò¹ ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊÑ§è ¹Õ¤é Å Ò¡Ѻ¤íÒÊѧè ON...GOSUB á·¹·Õ¨è СÃÐâ´´ä»·íÒ§Ò¹·Õâè »Ãá¡ÃÁ ÍÂáÅ Ç¡ÅѺÁÒ áµã¹¤íÒÊÑ§è ¹Õàé Á×Íè ¡ÃÐâ´´ä»áŠǨÐäÁ ¡ÅѺÁÒ àÇ ¹áµ Á¡Õ ÒÃà¢Õ¹¤íÒÊѧè ãË ¡ÃÐâ´´¡ÅѺÁÒä´ ËÒ¡ Target ÁÕ¨Òí ¹Ç¹ÁÒ¡ÊÒÁÒö㪠¨ÅØ ÀҤ㹡ÒÃàª×Íè Áµ ÍàÁ×Íè µ ͧà¢Õ¹â»Ãá¡ÃÁ¢Ö¹é ºÃ÷ѴãËÁ ¤ Ңͧ offset ÊÒÁÒö໠¹¤ Ò¤§·ÕËè Ã×͵ÑÇá»Ã ÁÕ¤Ò 0 ¶Ö§ 255 µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè

' {$STAMP BS2P} ' {$PBASIC 2.5} idx VAR Byte Main: DEBUG "INDEX: ", DEC idx, " " ON idx GOTO Case_0, Case_1 DEBUG "ON..GOTO target error.", CR Update: idx = idx + 1 // 3 PAUSE 1000 GOTO Main Case_0: DEBUG "Running Case_0 routine", CR GOTO Update Case_1: DEBUG "Running Case_1 routine", CR GOTO Update

' ¡ÃÐâ´´ä»·íÒ§Ò¹·Õâè »Ãá¡ÃÁ ÍÂàÁ×Íè idx = 0 ËÃ×Í 1 ' ᨠ§¤ÇÒÁ¼Ô´¾ÅҴ㹡óշÕè idx = 2 ' à¾ÔÁè ¤ ÒµÑÇá»Ã áµ ¤Çº¤ØÁãË Á¤Õ Ò 0 ¶Ö§ 2 ' ¡ÃÐâ´´¡ÅѺä»Âѧâ»Ãáá¡ÃÁËÅÑ¡ ' â»Ãá¡ÃÁ Í 0 (¶Ù¡·íÒ§Ò¹àÁ×Íè idx = 0) ' ¡ÃÐâ´´¡ÅѺä»Âѧâ»Ãáá¡ÃÁ Í Update ' â»Ãá¡ÃÁ Í 1 (¶Ù¡·íÒ§Ò¹àÁ×Íè idx = 1) ' ¡ÃÐâ´´¡ÅѺä»Âѧâ»Ãáá¡ÃÁ Í Update

ã¹â»Ãá¡ÃÁ¹Õé i-Stamp2P24 ¨Ð¡ÃÐâ´´ä»·íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í Case_0 ¶Ö§ Case_1 àÁ×Íè ¤ Ңͧ idx = 0 áÅÐ 1 µÒÁÅíҴѺ ã¹·Õ¡è Òí ˹´ãË idx à» ¹µÑÇá»Ã·Õãè ª ªµÕé Òí á˹ §â»Ãá¡ÃÁ ÍÂÁÕ¤Ò ä´ 0 ¶Ö§ 2 àÁ×Íè idx ෠ҡѺ 2 ¨Ð·íÒãË ¡ÒêÕéµíÒá˹ §à¡Ô´¤ÇÒÁ¼Ô´¾ÅÒ´à¹×èͧ¨Ò¡ÁÕ¡ÒÃÃкصíÒá˹ §â»Ãá¡ÃÁ Í·Õèµ Í§¡ÃÐâ´´ä»·íÒ§Ò¹äÇ à¾Õ§ 2 µíÒá˹ § (0 ¡Ñº 1) ¨Ö§ÁÕ¡ÒÃà¢Õ¹â»Ãá¡ÃÁà¾×Íè ᨠ§¤ÇÒÁ¼Ô´¾ÅÒ´¹Õ¼é Ò ¹·Ò§Ë¹ Òµ Ò§ Debug Terminal ¨ÐàËç¹Ç Ò·Ø¡â»Ãá¡ÃÁ Í¨ÐÁÕ¡ÒÃà¢Õ¹¤íÒÊÑè§ GOTO Update à¾×èÍãË ¡ÃÐâ´´¡ÅѺÁÒÂѧâ»Ãá¡ÃÁ Í Update àÁ×Íè ·íÒ§Ò¹ã¹â»Ãá¡ÃÁ ÍºÍ×¹è æ àÊÃç¨ÊÔ¹é ŧ áÅзÕâè »Ãá¡ÃÁ Í Update ËÅѧ¨Ò¡à¾ÔÁè ¤ ÒµÑÇá»ÃáÅ Ç¡ç¨Ð ¡ÅѺ价íÒ§Ò¹·Õèâ»Ãá¡ÃÁËÅÑ¡ ´Ñ§¹Ñ¹é ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè ON...GOTO ã¹µÑÇÍ ҧ¹Õ¨é §Ö àËÁ×͹¡Ñº¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè ON...GOSUB

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#


OUTPUT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè OUTPUT pin

¡íÒ˹´ãË ¢Ò·Õµè Í §¡ÒõԴµ Íà» ¹àÍÒµ ¾µØ ¾ÒÃÒÁÔàµÍà pin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò µÑ§é áµ 0 ¶Ö§ 15 㪠àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õµè Í §¡Òà ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ËÅѧ¨Ò¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õµè Í §¡ÒÃ㪠§Ò¹¶Ù¡¡íÒ˹´ãË à» ¹¢ÒàÍÒµ ¾µØ ¼Ùã ª §Ò¹ÊÒÁÒöà¢Õ¹ â»Ãá¡ÃÁà¾×Íè ¡íÒ˹´ãË ¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õµè ´Ô µ ÍÍÂÙÁ ÊÕ ¶Ò¹ÐÅͨԡ໠¹ 1 ËÃ×Í 0 ¡çä´ µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè

OUTPUT 4 OUT4 = 1 ' ·íÒãË ¢Ò¾Íà µ 4 à» ¹ÅͨԡÊÙ§ (1)

¤íÒÊÑè§áá¨Ð·íÒ¡ÒÃà»ÅÕè¹¢Ò¾Íà µ P4 ¨Ò¡ÍÔ¹¾Øµà» ¹àÍÒµ ¾Øµ ¨Ò¡¹Ñ鹤íÒÊÑ觶ѴÁÒ¨Ðà» ¹¡Ò÷íÒãË ¢Ò P4 ÁÕʶҹÐà» ¹ 1 â»Ãá¡ÃÁµÑÇÍ ҧ â»Ãá¡ÃÁ¹Õ¨é Ðà» ¹¡ÒáíÒ˹´·ÔÈ·Ò§¢Ò¾Íà µ¢Í§ i-Stamp2P24 â´Âãª Ã¨Õ ÊÔ àµÍà DIRS áÅФíÒÊѧè OUTPUT {$STAMP BS2p} INPUT 7 ' ¡íÒ˹´ãË ¢Ò¾Íà µ 7 à» ¹ÍÔ¹¾Øµ DEBUG State of pin 7: ,BIN IN7,CR ' áÊ´§¢ ͤÇÒÁáÅФ Ңͧ¾Íà µ 7 ·ÕËè ¹ Òµ Ò§ Debug Terminal OUT7 = 0 ' Ê §¤ Ò 0 ä»ÂѧÃÕ¨ÊÔ àµÍà ¾¡Ñ ¢ ÍÁÙÅàÍÒµ ¾µØ DEBUG After 0 written to OUT7: ,BIN IN7,CR OUTPUT 7 ' ¡íÒ˹´ãË ¢Ò¾Íà µ 7 à» ¹àÍÒµ ¾µØ DEBUG After pin 7 changed to output: ,BIN IN7 ' áÊ´§¢ ͤÇÒÁáÅФ Ңͧ¾Íà µ 7 ·ÕËè ¹ Òµ Ò§ Debug Terminal ËÅѧ¨Ò¡ÁÕ¡ÒáÃзíÒ¤íÒÊѧè

$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


OWIN ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè OWIN Pin, Mode, [InputData]

à» ¹¤íÒÊѧè ÃѺ¢ ÍÁÙÅࢠҨҡÍØ»¡Ã³ ÃкººÑÊ 1 ÊÒ (1-Wire) ¢Í§´ÑÅÅÑÊà«ÁԤ͹´Ñ¡àµÍà ¾ÒÃÒÁÔàµÍà Pin à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ¶Ö§ 15 à¾×Íè 㪠㹡ÒÃàÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2p24 㹡ÒõԴµ ͡ѺÍØ»¡Ã³ ¼Ò ¹ÃкººÑÊ 1 ÊÒ ÁÕ굄 ÃÒàÃçÇ㹡Òö Ò·ʹ¢ ÍÁÙÅ 20 ¡ÔâźԵµ ÍÇÔ¹Ò·Õ (äÁ ÃÇÁÊÑ­­Ò³ µÍºÊ¹Í§µ Ò§æ) ã¹ÃÐËÇ Ò§¡ÃзФíÒÊÑ§è ¹Õé ¢Ò¾Íà µ¢Í§ i-Stamp2p24 ¨Ð·íÒ§Ò¹ÊÅѺ¡Ñ¹ÃÐËÇ Ò§¡ÒÃà» ¹àÍÒµ ¾µØ áÅÐ ÍÔ¹¾Øµ ¨¹¡ÃзÑ觡Ò÷íÒ§Ò¹àÊÃç¨ÊÔé¹Å§ ¢Ò¾Íà µ¹Õé¨Ð¶Ù¡¡íÒ˹´à» ¹¢ÒÍÔ¹¾Øµ 㹡Òõ Íǧ¨Ã·Ò§ÎÒà ´áÇà µ ͧµ ͵ÑÇ µ Ò¹·Ò¹¤ Ò 4.7k: ¾ÙÅÍÑ»¢Ò·Õãè ª §Ò¹¹Õ´é Ç Â Mode à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË ÁÕ¤ Ò෠ҡѺ 0 ¶Ö§ 15 㪠¡íÒ˹´âËÁ´¢Í§¡Òö Ò·ʹ¢ ÍÁÙÅ ´Ñ§áÊ´§ÃÒÂÅÐàÍÕ´㹵ÒÃÒ§·Õè 3-8 InputData à» ¹¾×¹é ·ÕÊè Òí ËÃѺà¡çº¢ ÍÁÙÅ·ÕÍè Ò ¹ÁÒä´ ¨Ò¡ÍØ»¡Ã³ ÃкººÑÊ 1 ÊÒÂ·Õµè ´Ô µ Í´ Ç â´ÂÊÒÁÒö à¡çºäÇ ä´ ã¹ËÅÒÂÃٻẺ ·Ñ§é ÃËÑÊáÍÊ¡Õ,é àÅ¢°Ò¹Êͧ, àÅ¢°Ò¹ÊÔº, àÅ¢°Ò¹ÊԺˡ ËÃ×ÍÃٻẺ¢Í§µÑÇÍÑ¡Éà (string) ã¹µÒÃÒ§·Õè 3-9 áÊ´§ÃٻẺ¢Í§¢ ÍÁÙÅ·Õàè ¡çºä´ ¢Í§µÑÇá»Ã InputData ¹Õé àÅ×Í¡ÃٻẺ¡ÒÃÊ §¼ Ò¹¢ ÍÁÙÅ "0" : Ẻ亵 "1" : ẺºÔµ

àÅ×Í¡¨Ñ§ËÇСÒÃÊ §ÊÑ­­Ò³ÃÕ૵ "0" : äÁ ÁÕ¡ÒÃÊ §ÊÑ­­Ò³ÃÕ૵ "1" : Ê §ÊÑ­­Ò³ÃÕ૵µ ͨҡ¢ ÍÁÙÅ

àÅ×Í¡¤ÇÒÁàÃçÇ㹡Òö Ò·ʹ¢ ÍÁÙÅ "0" : ¤ÇÒÁàÃçǵíèÒ "1" : ¤ÇÒÁàÃçÇÊÙ§

àÅ×Í¡¨Ñ§ËÇСÒÃÊ §ÊÑ­­Ò³ÃÕ૵ "0" : äÁ ÁÕ¡ÒÃÊ §ÊÑ­­Ò³ÃÕ૵ "1" : Ê §ÊÑ­­Ò³ÃÕ૵¡ Í¹Ê §¢ ÍÁÙÅ ! Low/Hi

âËÁ´ (Mode) 0

Byte/Bit

BERes

FERes

¡Ò÷íÒ§Ò¹ äÁ ÁÕ¡ÒÃÊ §ÊÑ­­Ò³ÃÕ૵ ¶ Ò·ʹ¢ ÍÁÙÅẺ亵 ´ ǤÇÒÁàÃçǵíèÒ

1

Ê §ÊÑ­­Ò³ÃÕ૵¡ ͹¢ ÍÁÙÅ ¶ Ò·ʹ¢ ÍÁÙÅẺ亵 ´ ǤÇÒÁàÃçǵíèÒ

2

Ê §ÊÑ­­Ò³ÃÕ૵µ ͨҡ¢ ÍÁÙÅ ¶ Ò·ʹ¢ ÍÁÙÅẺ亵 ´ ǤÇÒÁàÃçǵíèÒ

3

Ê §ÊÑ­­Ò³ÃÕ૵·Ñ駡 ͹áÅÐËÅѧ¢ ÍÁÙÅ ¶ Ò·ʹ¢ ÍÁÙÅẺ亵 ´ ǤÇÒÁàÃçǵíèÒ

4

äÁ ÁÕ¡ÒÃÊ §ÊÑ­­Ò³ÃÕ૵ ¶ Ò·ʹ¢ ÍÁÙÅẺºÔµ´ ǤÇÒÁàÃçǵíèÒ

5

Ê §ÊÑ­­Ò³ÃÕ૵¡ ͹¢ ÍÁÙÅ ¶ Ò·ʹ¢ ÍÁÙÅẺºÔµ´ ǤÇÒÁàÃçǵíèÒ

8

äÁ ÁÕ¡ÒÃÊ §ÊÑ­­Ò³ÃÕ૵ ¶ Ò·ʹ¢ ÍÁÙÅẺ亵 ´ ǤÇÒÁàÃçÇÊÙ§

9

Ê §ÊÑ­­Ò³ÃÕ૵¡ ͹¢ ÍÁÙÅ ¶ Ò·ʹ¢ ÍÁÙÅẺºÔµ´ ǤÇÒÁàÃçÇÊÙ§

µÒÃÒ§·Õè 3-8 ÃÒÂÅÐàÍÕ´㹡ÒÃàÅ×Í¡âËÁ´ã¹¡ÒõԴµ ÍÍØ»¡Ã³ ÃкººÑÊ 1 ÊÒ¢ͧ¤íÒÊѧè OWIN áÅÐ OWOUT Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%


µÑÇ¡íÒ˹´¡ÒÃá»Å§¢ ÍÁÙÅ »ÃÐàÀ·¢Í§¢ ÍÁÙÅ ¢ ÍÁÙÅ·ÕÃè ºÑ ä´ 0 ¶Ö§ 9 àÅ¢°Ò¹ÊÔº ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-5) µ Í· ÒÂËÁÒ¶֧ DEC {1...5} ¨íҹǹËÅÑ¡·ÕèáÊ´§ -, 0 ¶Ö§ 9 àÅ¢°Ò¹ÊԺẺ¤Ô´à¤Ã×èͧËÁÒ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-5) SDEC {1...5} µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ 0 ¶Ö§ 9 áÅÐ àÅ¢°Ò¹ÊԺˡ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· Ò HEX {1...4} ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ A ¶Ö§ F SHEX {1...4} àÅ¢°Ò¹ÊԺˡẺ¤Ô´à¤Ã×èͧËÁÒ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-5) -, 0 ¶Ö§ 9 áÅÐ µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ A ¶Ö§ F IHEX {1...4} $, 0 ¶Ö§ 9 áÅÐ àÅ¢°Ò¹ÊԺˡâ´ÂáÊ´§ÊÑ­Åѡɳ $ ¹íÒ˹ Ò àª ¹ $37A à» ¹µ ¹ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· ÒÂËÁÒ¶֧ A ¶Ö§ F ¨íҹǹËÅÑ¡·ÕèáÊ´§

ËÁÒÂà赯 1

ISHEX {1...4}

àÅ¢°Ò¹ÊԺˡẺ¤Ô´à¤Ã×èͧËÁÒ â´ÂáÊ´§ÊÑ­Åѡɳ $ ¹íÒ˹ Ò ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· ÒÂËÁÒ¶֧ ¨íҹǹËÅÑ¡·ÕèáÊ´§

-, $, 0 ¶Ö§ 9 áÅÐ A ¶Ö§ F

1, 2, 3, 4

BIN {1...16}

àÅ¢°Ò¹Êͧ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· Ò ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ àÅ¢°Ò¹ÊͧẺ¤Ô´à¤Ã×èͧËÁÒ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-16) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ àÅ¢°Ò¹Êͧâ´ÂáÊ´§ÊÑ­Åѡɳ % ¹íÒ˹ Ò àª ¹ %10111000 à» ¹µ ¹ ¶ Ò¡íÒ˹´µÑÇàÅ¢ (1-16) µ Í· Ò ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§

0, 1

1

-, 0, 1

1, 2

%, 0, 1

1, 4

-,%, 0, 1

1, 2, 4

SBIN {1...16} IBIN {1...16}

1, 2 1, 3 1, 2, 3 1, 3, 4

ISBIN {1...16}

àÅ¢°Ò¹ÊͧẺ¤Ô´à¤Ã×èͧËÁÒ â´ÂáÊ´§ÊÑ­Åѡɳ % ¹íÒ˹ Ò ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· Ò ËÁÒ¶֧ ¨íҹǹËÅÑ¡·ÕèáÊ´§

ÃٻẺ¡ÒÃÃѺ¢ ÍÁÙÅ STR ByteArray \L {\E}

ÃÒÂÅÐàÍÕ´ ÃѺ¢ ÍÁÙŵÑÇÍÑ¡ÉÃÁÕ¤ÇÒÁÂÒÇ෠ҡѺ·Õè¡íÒ˹´äÇ ã¹ µÑÇá»Ã L à¡çºÅ§ä»ã¹áÍà ààÊÒÁÒö¡íÒ˹´ÍÑ¡Éû ´· ÒÂŧ㹵ÑÇá»Ã E ä´ â´ÂäÁ ¨íÒà» ¹µ ͧÃѺ¢ ÍÁÙÅãË ¤ÃºµÒÁ¨íҹǹ ·Õè¡íÒ˹´äÇ ã¹µÑÇá»Ã L ¶ ÒËÒ¡¢ ÍÁÙÅ·ÕèࢠÒÁÒäÁ ¤ÃºµÒÁ·Õè¡íÒ˹´ ·ÕèàËÅ×ͨÐä´ ÃѺ¡ÒáíÒ˹´ ãË à» ¹ "0"

WAITSTR ByteArray {\L}

ÃͤÍ¢ ÍÁÙŵÑÇÍÑ¡É÷Õèµ Í§¡ÒÃáÅ Çà¡çºÅ§ã¹áÍà ààÊÒÁÒö¡íÒ˹´¤ÇÒÁÂÒǢͧµÑÇÍÑ¡ÉÃ ä´ ·ÕèµÑÇá»Ã L áµ ¶ ÒËÒ¡äÁ ÁÕ¡ÒáíÒ˹´ ¨Ðµ ͧ¡íÒ˹´¨Ø´ÊÔé¹ÊØ´¢Í§áÍà áഠǢ ÍÁÙÅ "0" äÁ ʹ㨤ÇÒÁÂÒǢͧ¢ ÍÁÙÅ

SKIP Length

ËÁÒÂà赯 (1) ¡ÒÃá»Å§¢ ÍÁÙŵÑÇàÅ¢¨Ð¡ÃзíÒÍ ҧµ Íà¹×èͧ ¨¹¡Ç Ò¨Ðä´ ¨íҹǹ¤ÃºµÒÁ·Õè¡íÒ˹´ (2) 㹡óÕ㪠à¤Ã×èͧËÁÒÂź (-) ¨Ðµ ͧµÒÁ´ ǵÑÇàÅ¢àÊÁÍ ÁԩйÑ鹨Ðà¡Ô´¡ÒõդÇÒÁÇ Òà» ¹µÑÇÍÑ¡Éà (3) ¢ ÍÁÙŵÑÇàÅ¢°Ò¹ÊԺˡäÁ ʹã¨Ç Ò¨Ðà» ¹µÑǾÔÁ¾ àÅç¡ËÃ×͵ÑǾÔÁ¾ ãË­ ¹Ñ蹤×Í a ¡Ñº A ÁÕ¤ÇÒÁËÁÒÂàËÁ×͹¡Ñ¹ (4) ¨ÐäÁ ʹ㨢 ÍÁÙÅ·ÕèÁÕ¡ÒüÊÁ¡ÑºµÑÇÍÑ¡É÷ÕèäÁ 㪠µÑÇàÅ¢ â´Âµ ͧÁÕ¡ÒÃãÊ à¤Ã×èͧËÁÒ $ ÊíÒËÃѺàÅ¢°Ò¹ÊԺˡ áÅÐ % ÊíÒËÃѺ àÅ¢°Ò¹Êͧ

µÒÃÒ§·Õè 3-9ÃÒÂÅÐàÍÕ´ÃٻẺ¢Í§¢ ÍÁÙÅ·ÕÊè ÒÁÒÃ¶ãª ä´ ã¹µÑÇá»Ã InputData ¢Í§¤íÒÊѧè OWIN &

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ #1

RESULT VAR BYTE MAIN: OWIN 0, 1, [RESULT] STOP

¨Ò¡â»Ãá¡ÃÁµÑÇÍ ҧ¢ Ò§µ ¹ i-Stamp2P24 ¨ÐÊ §¾ÑÅÊ ÃàÕ «µä»ÂѧÍØ»¡Ã³ ÃкººÑÊ 1 ÊÒ·յè Í ÍÂÙ¡ ºÑ ¾Íà µ 0 (P0) ¨Ò¡¹Ñ¹é ¨ÐµÃǨÊͺÊÑ­­Ò³¾ÑÅÊ µÍºÊ¹Í§¡ÅѺ¨Ò¡µÑÇÍØ»¡Ã³ ËÒ¡·Ø¡Í ҧ¶Ù¡µ ͧ¡ç¨ÐÊÒÁÒÃ¶Í Ò¹¢ ÍÁÙÅ 1 亵 ¡ÅѺÁÒ¨Ò¡ÍØ»¡Ã³ à¡çºäÇ ã¹µÑÇá»Ã RESULT µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ #2 㹡óշàÕè Å×Í¡¡Òö Ò·ʹ¢ ÍÁÙÅà» ¹ºÔµ µÑÇá»Ã·Õãè ª à¡çº¢ ÍÁÙÅ¡ç¤ÇèСíÒ˹´ãË à» ¹ºÔµµÒÁ´ Ç ´Ñ§µÑÇÍ ҧ FIRSTBIT VAR BIT SECONDBIT VAR BIT MAIN: OWIN 0, 6, [FIRSTBIT, SECONDBIT] STOP

¨Ò¡â»Ãá¡ÃÁàÅ×Í¡âËÁ´¡ÒõԴµ Íã¹ÃËÑÊ 6 ¹Ñ¹è ¤×Í àÅ×Í¡¡Òö Ò·ʹ¢ ÍÁÙÅẺºÔµáÅÐÁÕ¡ÒÃÃÕ૵» ´ · Ò ´Ñ§¹Ñ¹é ¢ ÍÁÙÅ·ÕÍè Ò ¹ä´ ¨ÐÍ Ò¹ÁÒà¾Õ§ºÔµà´ÕÂÇ àÃÔÁè ¨Ò¡ºÔµ LSB ¨Ò¡¹Ñ¹é ¨Ö§Í Ò¹ºÔµ·ÕÊè §Ù ¢Ö¹é ä» 1 ºÔµã¹ÅíҴѺ¶Ñ´ä» ¨Ò¡µÑÇÍ ҧºÔµáá¨Ðà¡çºäÇ ·µÕè ÇÑ á»Ã FIRSTBIT Ê Ç¹ºÔµ¶Ñ´ÁÒà¡çºäÇ ·Õè SECONDBIT

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'


¡Ãͺá¡·Õè 3-2 ÃкºÊ×Íè ÊÒâ ÍÁÙÅ͹ءÃÁẺ˹֧è ÊÒ (1-WireTM Serial Bus) Ãкº¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅẺ¹Õ¼é ¤Ù ¹ ¤Ô´¤×Í ´ÑÅÅÑÊà«ÁԤ͹´Ñ¡àµÍà ´Ñ§¹Ñ¹é 㹺ҧ¤ÃÑ§é ¨Ö§àÃÕ¡ÃкºÊ×Íè ÊÒâ ÍÁÙÅẺ¹ÕÇé Ò ÃкºÊ×Íè ÊÒâ ÍÁÙÅ´ÑÅÅÑÊ˹֧è ÊÒ (The Dallas 1-Wire Bus) ÃкºÊ×Íè ÊÒâ ÍÁÙÅẺ ¹ÕÁé ¤Õ ÇÒÁªÒ­©ÅÒ´áÅÐ㪠ÊÒÂÊÑ­­Ò³à¾Õ§ 1 àÊ ¹à· ҹѹé äÁ µÍ §ÁÕÊÒÂÊÑ­­Ò³¹ÒÌ ¡Ò¤Çº¤ØÁ¨Ñ§ËÇСÒà ¶ Ò·ʹ¢ ÍÁÙÅàËÁ×͹¡ÑºÃкºÊ×èÍÊÒÃ͹ءÃÁẺÍ×è¹æ à¹×èͧ¨Ò¡ÊÒÂÊÑ­­Ò³¹Ñ鹨зíÒ˹ Ò·Õèà» ¹ÊÒ ÊÑ­­Ò³¹ÒÌ ¡Òã¹µÑÇ Ê Ç¹¤ Ңͧ¢ ÍÁÙžԨÒóҨҡÅѡɳТͧÃÙ»ÊÑ­­Ò³·Õ»è ÃÒ¡¯º¹ÊÒÂã¹áµ ÅЪ ͧ ¢Í§àÇÅÒËÃ×ÍàÃÕÂ¡Ç Ò ä·Á ÊÅç͵ (time-slot) ¡Òö Ò·ʹ¢ ÍÁÙŨÐà¡Ô´¢Ö¹é ã¹áµ ÅÐä·Á ÊÅç͵¹Ñ¹é áÅСÒö Ò ·Í´¢ ÍÁÙÅà» ¹áººÍЫԧâ¤Ã¹ÑÊã¹ÃдѺºÔµ ¤Ø³ÊÁºÑµ·Ô ҧ෤¹Ô¤¢Í§ÃкººÑÊ˹֧è ÊÒ ÊÒÂÊÑ­­Ò³º¹ÃкººÑʹÕàé » ¹ÊÒÂÊÑ­­Ò³áººÊͧ·ÔÈ·Ò§ áµ ¢Í ÁÙÅÊÒÁÒöà´Ô¹·Ò§ä´ ã¹·ÔÈ·Ò§ à´ÕÂÇÀÒÂ㹪 ǧàÇÅÒ˹֧è æ ÍØ»¡Ã³ º¹ÃкººÑʵ ͧÁÕ¡ÒÃÃкØÍ ҧªÑ´à¨¹Ç ÒµÑÇã´à» ¹ÁÒÊàµÍà µÑÇã´à» ¹ÊàÅ¿ â´ÂÊ Ç¹ãË­ Í»Ø ¡Ã³ ÁÒÊàµÍà ¤Í× äÁâ¤Ã¤Í¹â·ÃÅàÅÍÃ Ê Ç¹ÍØ»¡Ã³ ÊàÅ¿ä´ á¡ äÍ«ÕÇ´Ñ ÍسËÀÙÁ,Ô Ë¹ ǤÇÒÁ¨íÒ áÃÁ à» ¹µ ¹ ÍØ»¡Ã³ ÁÒÊàµÍà ໠¹µÑǨѴàµÃÕÂÁ¤ÇÒÁ¾Ã ÍÁáÅФǺ¤ØÁ¡Òö Ò·ʹ¢ ÍÁÙź¹ÊÒÂÊÑ­­Ò³¹Ñ¹é ¢ ÍÁÙŷѧé ËÁ´¨Ð¶Ù¡Ê §Å§º¹ÊÒÂÊÑ­­Ò³·ÕÁè ÍÕ ÂÙà ¾Õ§àÊ ¹à´ÕÂÇ¹Õ·é §Ñé ËÁ´ ã¹ÃÐËÇ Ò§¡Ò÷íÒ§Ò¹ÍØ»¡Ã³ ÁÒÊàµÍà áÅÐÊàÅ¿ÊÒÁÒö໠¹ä´ ·§Ñé µÑÇÊ §áÅеÑÇÃѺ ¢Ö¹é ÍÂÙ¡ ºÑ à§×Íè ¹ä¢¢Í§¡Ò÷íҧҹ㹢³Ð¹Ñ¹é ¡µÑÇÍ ҧ ¶ ÒËÒ¡ÁÕ¡Òà à¢Õ¹¢ ÍÁÙŨҡÍØ»¡Ã³ ÁÒÊàµÍà ä»ÂѧÍØ»¡Ã³ ÊàÅ¿ µÑÇÊ §¤×ÍÍØ»¡Ã³ ÁÒÊàµÍà µÑÇÃѺ¤×ÍÍØ»¡Ã³ ÊàÅ¿ ã¹·Ò§ µÃ§¢ ÒÁ ËÒ¡à» ¹¡ÒÃÍ Ò¹¢ ÍÁÙŨҡÍØ»¡Ã³ ÊàÅ¿ µÑÇÊ §¨Ð¡ÅÒÂà» ¹ÍØ»¡Ã³ ÊàÅ¿ áÅеÑÇÃѺ¤×ÍÍØ»¡Ã³ ÁÒÊàµÍà ã¹ÃкººÑÊ 1 Ãкºµ ͧÁÕÍ»Ø ¡Ã³ ÁÒÊàµÍà à¾Õ§µÑÇà´ÕÂÇ෠ҹѹé ÊÒÂÊÑ­­Ò³¢Í§ÃкººÑʹյé Í §¡íÒ˹´ÊÀÒÇл¡µÔäÇ ·ÅÕè ͨԡÊÙ§ ·íÒä´ â´Â¡Òõ ͵Ñǵ Ò¹·Ò¹¤ Ò 1 ¶Ö§ 4.7k: ¾ÙÅÍÑ»¡Ñºä¿àÅÕé§ +5V ´Ñ§¹Ñé¹ÍØ»¡Ã³ ·Õè¹íÒࢠÒÁÒµ ͺ¹ÃкººÑʹÕé¨Ö§µ ͧÍ͡ẺãË àÍÒµ ¾Øµ ·Õµè Í §µ ͡ѺÊÒÂÊÑ­­Ò³ÁÕÅ¡Ñ É³Ðà» ¹¤ÍÅàÅç¡àµÍà ໠´ËÃÔÍà´Ã¹à» ´ ã¹ÃÙ»·Õè A3-6 áÊ´§ä´ÍÐá¡ÃÁ¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅẺ˹֧è ÊÒÂàº×Íé §µ ¹ ¤Ø³ÊÁºÑµ¢Ô ͧä·Á ÊÅç͵ ÍØ»¡Ã³ ÁÒÊàµÍà ໠¹ÍØ»¡Ã³ à¾Õ§µÑÇà´ÕÂǺ¹ÃкººÑÊ·ÕèÊÒÁÒöÍÔ¹ÔàªÕÂÅÊÒÂÊÑ­­Ò³ä´ â´Â¨Ð ¡íÒà¹Ô´¨Ø´àÃÔÁè µ ¹¢Í§ä·Á ÊÅç͵´ Ç¡Ò÷íÒãË ÊÒÂÊÑ­­Ò³à» ¹ÅͨԡµèÒí 㹪 ǧàÇÅÒË¹Ö§è ¨Ò¡¹Ñ¹é ·íÒãË ¡ÅѺÁÒ à» ¹ÅͨԡÊÙ§ ¶ ÒËÒ¡ÍØ»¡Ã³ ÊàÅ¿µ ͧ¡ÒÃÊ §¢ ÍÁÙÅ¡ÅѺÁÒÂѧÁÒÊàµÍà ÍØ»¡Ã³ ÊàÅ¿¨Ðà» ¹µÑǤǺ¤ØÁÊÀÒÇÐ ¢Í§ÊÒÂÊÑ­­Ò³µ Í仨¹àÊÃç¨ÊÔ鹡Ãкǹ¡Òà ᵠ¶ ÒËÒ¡ÍØ»¡Ã³ ÁÒÊàµÍà µ ͧ¡ÒÃÊ §¢ ÍÁÙÅ¡ç¨ÐÊÒÁÒö ´íÒà¹Ô¹¡Òõ Íä»ä´ àÅ ¿ §¡ ª¹Ñè ¢Í§ä·Á ÊÅç͵·Õ¡è Òí ˹´â´ÂÍØ»¡Ã³ ÁÒÊàµÍà Á´Õ Ç Â¡Ñ¹ 4 ¿ §¡ ª¹Ñè ¤×Í ä·Á ÊÅç͵¢Í§¡ÒÃÃÕ૵ (RESET), ¡ÒÃÍ Ò¹¢ ÍÁÙÅ (READ DATA), ¡ÒÃà¢Õ¹¢ ÍÁÙÅ 1 (WRITE ONE) áÅСÒÃà¢Õ¹¢ ÍÁÙÅ 0 (WRITE ZERO) ä·Á ÊÅç͵ÃÕ૵㪠㹡ÒÃàÃÔÁè µ ¹µÔ´µ ͡ѺÍØ»¡Ã³ ÊàÅ¿ ã¹¢³Ð·Õäè ·Á ÊÅç͵¡ÒÃÍ Ò¹¨Ð ÊíÒËÃÑºÍ Ò¹¢ ÍÁÙÅ·ÕÊè § ÁÒ¨Ò¡ÍØ»¡Ã³ ÊàÅ¿ Ê Ç¹ä·Á ÊÅç͵¡ÒÃà¢Õ¹¢ ÍÁÙÅ 1 áÅÐ 0 㪠ÊÒí ËÃѺà¢Õ¹¢ ÍÁÙÅ ä»ÂѧÍØ»¡Ã³ ÊàÅ¿¼ Ò¹ÊÒÂÊÑ­­Ò³¢Í§Ãкº

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


+5V

4k7

ÍØ»¡Ã³ ÁÒÊàµÍÃ

ÍØ»¡Ã³ ÊàÅ¿ #1

ÍØ»¡Ã³ ÊàÅ¿ #2

ÍØ»¡Ã³ ÊàÅ¿ #n

ÃÙ»·Õè A3-6 ¡ÒÃàª×Íè Áµ ͺ¹ÃкººÑÊ˹֧è ÊÒ 480 ¶Ö§ 960 äÁâ¤ÃÇÔ¹Ò·Õ ÍØ»¡Ã³ ÁÒÊàµÍà ·Òí ãË à» ¹ÅͨԡµíÒè

60 ¶Ö§ 120 äÁâ¤ÃÇÔ¹Ò·Õ ÍØ»¡Ã³ ÁÒÊàµÍà ·Òí ãË à» ¹ÅͨԡÊÙ§

ÃÕ૵

µÍºÃѺ 15 ¶Ö§ 60 äÁâ¤ÃÇÔ¹Ò·Õ ÍØ»¡Ã³ ÊàÅ¿ ·íÒãË à» ¹ÅͨԡµíÒè

ÍØ»¡Ã³ ÊàÅ¿ ·íÒãË à» ¹ÅͨԡÊÙ§

ÃÙ»·Õè A3-7 ä·Á ÊÅç͵¡ÒÃÃÕ૵áÅСÒõͺÃѺ¢Í§ÍØ»¡Ã³ º¹ÃкººÑÊ˹֧è ÊÒ ·Ò§´ Ò¹ÍØ»¡Ã³ ÊàÅ¿ÁÕ¿§ ¡ ª¹Ñè ·Ñ§é ÊÔ¹é 3 ¿ §¡ ª¹Ñè ¤×Í ä·Á ÊÅç͵¢Í§¡Òõͺʹͧ (PRESENCE), ¡ÒÃà¢Õ¹¢ ÍÁÙÅ 1 (WRITE ONE) áÅСÒÃà¢Õ¹¢ ÍÁÙÅ 0 (WRITE ZERO) ä·Á ÊÅç͵¢Í§¡Òõͺʹͧ 㪠ÊÒí ËÃѺµÍºÊ¹Í§¡ÒõԴµ ͨҡÍØ»¡Ã³ ÁÒÊàµÍà â´ÂÍØ»¡Ã³ ÊàÅ¿µÑÇ·Õ¶è ¡Ù àÅ×Í¡¨Ðµ Í§Ê §ÊÑ­­Ò³µÍºÊ¹Í§ ŧº¹ÊÒÂÊÑ­­Ò³à¾×Íè ᨠ§ãË Í»Ø ¡Ã³ ÁÒÊàµÍà ·ÃÒºÇ Ò ¢³Ð¹Õµé ´Ô µ Í¡Ñ¹ä´ áÅ Ç Ê Ç¹ä·Á ÊÅç͵¡ÒÃà¢Õ¹¢ ÍÁÙÅ 1 áÅÐ 0 㪠ʧ ¢ ÍÁÙÅä»ÂѧÍØ»¡Ã³ ÁÒÊàµÍà ¼Ò ¹ÊÒÂÊÑ­­Ò³¢Í§Ãкº «Ö§è ¨ÐÊÑÁ¾Ñ¹¸ ¡ºÑ ä·Á ÊÅç͵¡ÒÃÍ Ò¹ ¢ ÍÁÙŢͧÍØ»¡Ã³ ÁÒÊàµÍà ¡ÒÃá¡áÂп §¡ ª¹Ñè ¢Í§áµ ÅÐä·Á ÊÅç͵¨Ð㪠¤ÇÒÁÂÒǢͧ¤ÒºàÇÅÒáÅÐÅѡɳР¢Í§ÃÙ»ÊÑ­­Ò³à» ¹µÑÇ¡íÒ˹´ áÅзء¤ÃÑ§é ·ÕÁè ¡Õ ÒÃà»ÅÕÂè ¹á»Å§¿ §¡ ª¹Ñè µ ͧ·íÒãË ÊÒÂÊÑ­­Ò³ÍÂÙã ¹ÊÀÒÇÐÇ Ò§ àÊÁÍ «Ö§è ¡ç¤Í× ¡Ò÷íÒãË ÊÒÂÊÑ­­Ò³à» ¹ÅͨԡÊ٧͠ҧ¹ Í 1 äÁâ¤ÃÇÔ¹Ò·Õ ä·Á ÊÅç͵¡ÒÃÃÕ૵áÅеͺʹͧ ÍØ»¡Ã³ ÁÒÊàµÍà ·íÒãË à¡Ô´¡ÒÃÃÕ૵º¹ÊÒÂÊÑ­­Ò³à¾×èÍᨠ§á¡ ÍØ»¡Ã³ ÊàÅ¿ â´Â¡Ò÷íÒãË ÊÒ ÊÑ­­Ò³à» ¹ÅͨԡµèÒí µ Íà¹×Íè §Í ҧ¹ Í 480 äÁâ¤ÃÇÔ¹Ò·Õ áÅШе ͧ·íÒãË ÊÒÂÊÑ­­Ò³¡ÅѺÁÒà» ¹Åͨԡ ÊÙ§ÀÒÂã¹ 480 äÁâ¤ÃÇÔ¹Ò·ÕËÅѧ¨Ò¡¹Ñ¹é ¶ ÒËÒ¡ÁÕÍ»Ø ¡Ã³ ÊàÅ¿µ ÍÍÂÙº ¹ÊÒÂÊÑ­­Ò³ ¨ÐÁÕ¡Òõͺʹͧ ÊÑ­­Ò³ÃÕ૵¹Ñ¹é ´ ÇÂÊÑ­­Ò³µÍºÊ¹Í§ (PRESENCE) â´Â¡Ò÷íÒãË ÊÒÂÊÑ­­Ò³à» ¹ÅͨԡµèÒí µ Íà¹×Íè § ¹Ò¹»ÃÐÁÒ³ 60 ¶Ö§ 240 äÁâ¤ÃÇÔ¹Ò·Õ ËÅѧ¨Ò¡ÊÑ­­Ò³ÃÕ૵»ÃÒ¡¯»ÃÐÁÒ³ 15 ¶Ö§ 60 äÁâ¤ÃÇÔ¹Ò·Õ ÃÙ»·Õè A3-7 áÊ´§ä·Á ÊÅç͵¢Í§¡ÒÃÃÕ૵áÅСÒõͺʹͧ Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


60 ¶Ö§ 120 äÁâ¤ÃÇÔ¹Ò·Õ ÍØ»¡Ã³ ÁÒÊàµÍà ·Òí ãË à» ¹ÅͨԡµíÒè ÍØ»¡Ã³ ÁÒÊàµÍà ·Òí ãË à» ¹ÅͨԡÊÙ§

ÍØ»¡Ã³ ÁÒÊàµÍà ¨Ð·íÒ¡ÒÃÍ Ò¹ã¹ª ǧàÇÅÒ¹Õé 1 ¶Ö§ 15 äÁâ¤ÃÇÔ¹Ò·Õ

ÍØ»¡Ã³ ÊàÅ¿µ ͧ·íÒãË à» ¹ ÅͨԡÊÙ§ËÅѧ¨Ò¡Ê §¢ ÍÁÙÅ ¤ÃºáÅ Ç

45 äÁâ¤ÃÇÔ¹Ò·Õ à» ¹ÅͨԡµíÒè ¶ ÒÍØ»¡Ã³ ÊàÅ¿Ê §¢ ÍÁÙÅ "0" à» ¹ÅͨԡÊÙ§ ¶ ÒÍØ»¡Ã³ ÊàÅ¿Ê §¢ ÍÁÙÅ "1"

ÃÙ»·Õè A3-8 ä·Á ÊÅç͵¡ÒÃÍ Ò¹¢ ÍÁÙŢͧÍØ»¡Ã³ ÁÒÊàµÍà «Ö觵ç¡Ñºä·Á ÊÅç͵¡ÒÃà¢Õ¹¢ ÍÁÙÅ ¢Í§ÍØ»¡Ã³ ÊàÅ¿ 60 ¶Ö§ 120 äÁâ¤ÃÇÔ¹Ò·Õ ÍØ»¡Ã³ ÁÒÊàµÍà ·Òí ãË à» ¹ÅͨԡµíÒè ÍØ»¡Ã³ ÁÒÊàµÍà ·Òí ãË à» ¹ÅͨԡÊÙ§

ÍØ»¡Ã³ ÊàÅ¿¨Ð·íÒ¡ÒÃÍ Ò¹ã¹ª ǧàÇÅÒ¹Õé 1 ¶Ö§ 15 äÁâ¤ÃÇÔ¹Ò·Õ

45 äÁâ¤ÃÇÔ¹Ò·Õ

ÃÙ»·Õè A3-9 ä·Á ÊÅç͵¡ÒÃà¢Õ¹ ¢ ÍÁÙÅ 1 ¢Í§ÍØ»¡Ã³ ÁÒÊàµÍà «Öè § µÃ§¡Ñ º ä·Á Ê Åç Í µ¡ÒÃÍ Ò ¹ ¢ ÍÁÙŢͧÍØ»¡Ã³ ÊàÅ¿

60 ¶Ö§ 120 äÁâ¤ÃÇÔ¹Ò·Õ ÍØ»¡Ã³ ÁÒÊàµÍà ·Òí ãË à» ¹ÅͨԡµíÒè ÍØ»¡Ã³ ÁÒÊàµÍà ·Òí ãË à» ¹ÅͨԡÊÙ§

15 äÁâ¤ÃÇÔ¹Ò·Õ

45 äÁâ¤ÃÇÔ¹Ò·Õ

ÍØ»¡Ã³ ÊàÅ¿¨Ð·íÒ¡ÒÃÍ Ò¹ã¹ª ǧàÇÅÒ¹Õé

ÃÙ»·Õè A3-10 ä·Á ÊÅç͵¡ÒÃà¢Õ¹ ¢ ÍÁÙÅ 0 ¢Í§ÍØ»¡Ã³ ÁÒÊàµÍÃ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


ä·Á ÊÅç͵¡ÒÃÍ Ò¹¢ ÍÁÙŢͧÍØ»¡Ã³ ÁÒÊàµÍà áÅСÒÃà¢Õ¹¢ ÍÁÙŢͧÍØ»¡Ã³ ÊàÅ¿ àÁ×è͵ ͧ¡ÒÃÍ Ò¹¢ ÍÁÙŨҡÍØ»¡Ã³ ÊàÅ¿ ÍØ»¡Ã³ ÁÒÊàµÍà ¨Ð·íÒãË ÊÒÂÊÑ­­Ò³à» ¹ÅͨԡµèíÒà» ¹ àÇÅÒ¹Ò¹»ÃÐÁÒ³ 1 ¶Ö§ 15 äÁâ¤ÃÇÔ¹Ò·Õ ¨Ò¡¹Ñ¹é µ ͧ·íÒãË Ê¶Ò¹Ð¢Í§ÊÒ¡ÅѺÁÒà» ¹ÅͨԡÊÙ§ ÍØ»¡Ã³ ÊàÅ¿¨Ð Ê §¢ ÍÁÙÅÁÒãË Í»Ø ¡Ã³ ÁÒÊàµÍà â´Â¶ Ò¢ ÍÁÙÅà» ¹ 0 ÍØ»¡Ã³ ÊàÅ¿¨Ð·íÒãË ÊÒÂÊÑ­­Ò³à» ¹ÅͨԡµèÒí à» ¹ àÇÅÒ¹Ò¹»ÃÐÁÒ³ 45 äÁâ¤ÃÇÔ¹Ò·Õ áÅ Ç·íÒãË ¡ÅѺÁÒÊÙÊ ÀÒÇÐÅͨԡÊÙ§ÍÕ¡¤Ãѧé áµ ¶Ò à» ¹¢ ÍÁÙÅ 1 ÍØ»¡Ã³ ÊàÅ¿ ¨Ð·íÒãË ÊÒÂÊÑ­­Ò³à» ¹ÅͨԡÊÙ§µ Íà¹×Íè §ä»ÍÕ¡ 45 äÁâ¤ÃÇÔ¹Ò·Õ ÃÇÁàÇÅҷѧé ËÁ´ã¹ä·Á ÊÅç͵¹Õ»é ÃÐÁÒ³ 60 ¶Ö§ 120 äÁâ¤ÃÇÔ¹Ò·Õ ¹Ñ¹è ¤×Íã¹ä·Á ÊÅç͵¹Õãé ª àÇÅÒÃÇÁäÁ à¡Ô¹ 120 äÁâ¤ÃÇÔ¹Ò·Õ ã¹¢³Ð·ÕÍè »Ø ¡Ã³ ÁÒÊàµÍà ¨Ð㪠àÇÅÒ㹡ÒÃÍ Ò¹¢ ÍÁÙÅÍÂÙà ÐËÇ Ò§ 15 áÅÐ 60 äÁâ¤ÃÇÔ¹Ò·ÕËÅѧ¨Ò¡àÃÔÁè µ ¹ä·Á ÊÅç͵¹Õé ã¹ÃÙ»·Õè A3-8 áÊ´§ÃÙ» ÊÑ­­Ò³¢Í§ä·Á ÊÅç͵¡ÒÃÍ Ò¹¢ ÍÁÙŢͧÍØ»¡Ã³ ÁÒÊàµÍà «§Öè àËÁ×͹¡Ñº¡ÒÃà¢Õ¹¢ ÍÁÙŢͧÍØ»¡Ã³ ÊàÅ¿ áÅÐ ä·Á ÊÅç͵·Ñ§é Êͧ¨Ðà¡Ô´¢Ö¹é ã¹àÇÅÒà´ÕÂǡѹ ¡Å ÒǤ×Í àÁ×Íè ÍØ»¡Ã³ ÁÒÊàµÍà ÍÒ ¹ ÍØ»¡Ã³ ÊàÅ¿¡çµÍ §à¢Õ¹ ä·Á ÊÅç͵¡ÒÃà¢Õ¹¢ ÍÁÙŢͧÍØ»¡Ã³ ÁÒÊàµÍà àÁ×èÍÍØ»¡Ã³ ÁÒÊàµÍà µ ͧ¡ÒÃà¢Õ¹¢ ÍÁÙÅ ÍØ»¡Ã³ ÁÒÊàµÍà ¨Ð·íÒãË ÊÒÂÊÑ­­Ò³à» ¹ÅͨԡµèíÒ¹Ò¹ »ÃÐÁÒ³ 1 ¶Ö§ 15 äÁâ¤ÃÇÔ¹Ò·Õ ¨Ò¡¹Ñ¹é µ ͧ·íÒãË Ê¶Ò¹Ð¢Í§ÊÒ¡ÅѺÁÒà» ¹ÅͨԡÊÙ§ áÅ Çà¢Õ¹¢ ÍÁÙÅä´ ã¹ ·Ñ¹·Õ ¶ Ò¢ ÍÁÙÅ·Õµè Í §¡ÒÃà¢Õ¹ä»ÂѧÍØ»¡Ã³ ÊàÅ¿à» ¹ 0 ÍØ»¡Ã³ ÁÒÊàµÍà ¨Ð·íÒãË ÊÒÂÊÑ­­Ò³à» ¹Åͨԡ µèÒí ¹Ò¹»ÃÐÁÒ³ 45 äÁâ¤ÃÇÔ¹Ò·Õ áÅ Ç·íÒãË ÊÒÂÊÑ­­Ò³¡ÅѺÁÒÊÙÊ ÀÒÇÐÅͨԡÊÙ§ÍÕ¡¤Ãѧé áµ ¶Ò µ ͧ¡ÒÃà¢Õ¹ ¢ ÍÁÙÅ 1 ÍØ»¡Ã³ ÁÒÊàµÍà ¨Ð·íÒãË ÊÒÂÊÑ­­Ò³à» ¹ÅͨԡÊÙ§µ Íà¹×Íè §ä»ÍÕ¡ 45 äÁâ¤ÃÇÔ¹Ò·Õ ÃÇÁàÇÅҷѧé ËÁ´ã¹ä·Á ÊÅç͵¹Õ»é ÃÐÁÒ³ 60 ¶Ö§ 120 äÁâ¤ÃÇÔ¹Ò·Õ ã¹ÃÙ»·Õè A3-9 áÅÐ A3-10 áÊ´§ÃÙ»ÊÑ­­Ò³¢Í§ä·Á ÊÅç͵¡ÒÃà¢Õ¹¢ ÍÁÙŢͧÍØ»¡Ã³ ÁÒÊàµÍà «§Öè ÁÕÅ¡Ñ É³ÐàËÁ×͹¡Ñº¡ÒÃÍ Ò¹¢ ÍÁÙŢͧÍØ»¡Ã³ ÊàÅ¿ áÅÐä·Á ÊÅç͵·Ñ§é Êͧ¨Ðà¡Ô´¢Ö¹é 㹪 ǧàÇÅÒà´ÕÂǡѹ ¡Å ÒǤ×Í àÁ×Íè ÍØ»¡Ã³ ÁÒÊàµÍà à¢Õ¹ ÍØ»¡Ã³ ÊàÅ¿¡çµÍ §Í Ò¹¢ ÍÁÙÅ ÃٻẺ¢Í§¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅẺ˹էè ÊÒ (1-WireTM communication protocol) 㹡ÒÃÊ×Íè ÊÒâ ÍÁÙÅÃкººÑÊ˹֧è ÊÒÂÍØ»¡Ã³ ÁÒÊàµÍà ÊÒÁÒöµÔ´µ ÍÍØ»¡Ã³ ÊàÅ¿ä´ ¤Ãѧé ÅÐ 1 µÑÇà· Ò ¹Ñ¹é ÍØ»¡Ã³ ÊàÅ¿áµ ÅеÑǨ֧µ ͧÁÕ¢Í ÁÙÅ¡íÒ˹´áÍ´à´ÃÊ੾ÒеÑÇ â´Âà¡çºäÇ ã¹Ë¹ ǤÇÒÁ¨íÒÃÍÁÀÒÂã¹ ÍØ»¡Ã³ ÊàÅ¿µÑǹѹé æ â´Â»¡µÔÍ»Ø ¡Ã³ ÊàÅ¿ã¹ÃкººÑÊẺ¹Õ¨é ÐÁÕ˹ ǤÇÒÁ¨íÒ¢¹Ò´ 64 ºÔµËÃ×Í 8 亵 ÊíÒËÃѺà¡çº¢ ÍÁÙŵ Ò§æ ·ÕÊè Òí ¤Ñ­¢Í§ÍØ»¡Ã³ áµ ÅеÑÇ «Ö§è »ÃСͺ´ Ç 1. ÃËÑʢͧµÃСÙÅ ¨íҹǹ 8 ºÔµ 2. àÅ¢ËÁÒ»ÃШíÒµÑÇ (serial number) ¨íҹǹ 48 ºÔµ 3. ÃËÑʵÃǨÊͺ¤ÇÒÁ¼Ô´¾ÅÒ´ (CRC : Cyclical Redundancy Check) ¨íҹǹ 8 ºÔµ ¼Ù 㪠§Ò¹ÊÒÁÒÃ¶Í Ò¹¢ ÍÁÙÅ»ÃШíÒµÑǢͧÍØ»¡Ã³ ÊàÅ¿ä´ ´ Ç¡ÒÃ㪠¤íÒÊÑè§Í ҹ˹ ǤÇÒÁ¨íÒÃÍÁ (Read ROM : $33) 㹡óշºÕè ¹ºÑÊÁÕÍ»Ø ¡Ã³ ÊàÅ¿µÑÇà´ÕÂÇäÁ ¨Òí à» ¹µ Í§Í Ò§áÍ´à´ÃÊ㹡ÒõԴµ Í ¡ÒõԴµ ͺ¹ÃкººÑÊ˹֧è ÊÒ¨ÐàÃÔÁè µ ¹¢Ö¹é àÁ×Íè ÍØ»¡Ã³ ÁÒÊàµÍà ·Òí ¡ÒÃÃÕ૵áÅСíÒ˹´áÍ´à´Ãʢͧ ÍØ»¡Ã³ ··Õè Òí ¡ÒõԴµ Í ¶ ÒËÒ¡ÁÕÍ»Ø ¡Ã³ ÊàÅ¿à¾Õ§µÑÇà´ÕÂÇÊÒÁÒö¢ ÒÁ¢Ñ¹é µÍ¹¡ÒõԴµ ͡Ѻ˹ ǤÇÒÁ¨íÒÃÍÁ ã¹ÍØ»¡Ã³ ÊàÅ¿ä´ ¨ÐàÃÕ¡ÇÔ¸¡Õ Òôѧ¡Å ÒÇ ¡ÒÃäÁ µ´Ô µ Í˹ ǤÇÒÁ¨íÒÃÍÁ ËÃ×Í Ê¤Ô»ÃÍÁ (Skip ROM : $CC) ¨Ò¡¹Ñ¹é ÃÍ¡ÒõͺÃѺ¨Ò¡ÍØ»¡Ã³ ÊàÅ¿ àÁ×Íè ¡ÒõͺÃѺÊÁºÙó ¡¨ç ÐÊÒÁÒöàÃÔÁè µ ¹¢Ñ¹é µÍ¹¡ÒÃÍ Ò¹ËÃ×Í à¢Õ¹¢ ÍÁÙÅä´ µÍ ä» Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


OWOUT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè OWOUT Pin, Mode, [OutputData]

à» ¹¤íÒÊѧè Ê §¢ ÍÁÙÅä»ÂѧÍØ»¡Ã³ ·ãÕè ª ¡ÒÃàª×Íè Áµ ͼ Ò¹ÃкººÑÊ 1 ÊÒ¢ͧ´ÑÅÅÑÊà«ÁԤ͹´Ñ¡àµÍà ¾ÒÃÒÁÔàµÍà Pin à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ¶Ö§ 15 à¾×Íè 㪠㹡ÒÃàÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 㹡ÒõԴµ ͡ѺÍØ»¡Ã³ ¼Ò ¹ÃкººÑÊ 1 ÊÒ ÁÕ굄 ÃÒàÃçÇ㹡Òö Ò·ʹ¢ ÍÁÙÅ 20 ¡ÔâźԵµ ÍÇÔ¹Ò·Õ (äÁ ÃÇÁÊÑ­­Ò³ µÍºÊ¹Í§µ Ò§æ) ã¹ÃÐËÇ Ò§¡ÃзФíÒÊÑ§è ¹Õé ¢Ò¾Íà µ¢Í§ i-Stamp2P24 ¨Ð·íÒ§Ò¹ÊÅѺ¡Ñ¹ÃÐËÇ Ò§¡ÒÃà» ¹àÍÒµ ¾µØ áÅÐ ÍÔ¹¾Øµ ¨¹¡ÃзÑ觡Ò÷íÒ§Ò¹àÊÃç¨ÊÔé¹Å§ ¢Ò¾Íà µ¹Õé¨Ð¶Ù¡¡íÒ˹´à» ¹¢ÒÍÔ¹¾Øµ 㹡Òõ Íǧ¨Ã·Ò§ÎÒà ´áÇà µ ͧµ ͵ÑÇ µ Ò¹·Ò¹¤ Ò 1.8 ¶Ö§ 4.7k: ¾ÙÅÍÑ»¢Ò·Õãè ª §Ò¹¹Õ´é Ç Â Mode à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ¶Ö§ 15 㪠¡Òí ˹´âËÁ´¢Í§¡Òö Ò·ʹ¢ ÍÁÙÅ ´Ñ§áÊ´§ÃÒÂÅÐàÍÕ´㹵ÒÃÒ§·Õè 3-8 OutputData à» ¹¾×¹é ·ÕÊè Òí ËÃѺà¡çº¢ ÍÁÙÅ·Õµè Í §¡ÒÃà¢Õ¹ËÃ×ÍÊ §ä»ÂѧÍØ»¡Ã³ ÃкººÑÊ 1 ÊÒÂ·Õµè ´Ô µ Í´ Ç â´ÂÃٻẺ¢Í§¢ ÍÁÙÅÁÕä´ ËÅÒÂÃٻẺ ·Ñ§é ÃËÑÊáÍÊ¡Õ,é àÅ¢°Ò¹Êͧ, àÅ¢°Ò¹ÊÔº, àÅ¢°Ò¹ÊԺˡ ËÃ×ÍÃٻẺ¢Í§µÑÇ ÍÑ¡Éà (string) ã¹µÒÃÒ§·Õè 3-10 áÊ´§ÃٻẺ¢Í§¢ ÍÁÙÅ·ÕÊè ÒÁÒÃ¶Ê §ä»ã¹µÑÇá»Ã OutputData µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ OWOUT 0, 1, [$4E]

㹤íÒÊÑ§è ¹Õé i-Stamp2P24 ¨ÐÊ §¾ÑÅÊ ÃàÕ «µä»ÂѧÍØ»¡Ã³ ÃкººÑÊ 1 ÊÒ·յè Í ÍÂÙ¡ ºÑ ¢Ò¾Íà µ 0 â´Â¡íÒ˹´ âËÁ´¡Òö Ò·ʹ¢ ÍÁÙÅà» ¹âËÁ´ 1 ¨Ò¡¹Ñ¹é ¨ÐµÃǨÊͺÊÑ­­Ò³¾ÑÅÊ µÍºÊ¹Í§¡ÅѺ¨Ò¡µÑÇÍØ»¡Ã³ ËÒ¡·Ø¡Í ҧ ¶Ù¡µ ͧ¡ç¨ÐÊ §¢ ÍÁÙÅ 1 亵 ä»ÂѧÍØ»¡Ã³ ¨Ò¡µÑÇÍ ҧ¹Õ¤é Í× $4E

"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


µÑÇ¡íÒ˹´¡ÒÃà»ÅÕÂè ¹á»Å§ ¼Å¡ÒÃà»ÅÕÂè ¹á»Å§ áÊ´§ª×èͧ͢µÑÇá»Ã ("variablename = 'character'") ASC? µÒÁ´ Ç carriage return â´Â character µ ͧ໠¹¢ ÍÁÙÅ ÃËÑÊáÍÊ¡Õé DEC {1...5} SDEC {1...5} HEX {1...4} SHEX {1...4} IHEX {1...4}

áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊÔº ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-5) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊԺẺ¤Ô´à¤Ã×èͧËÁÒ ¶ ÒÁÕ¡Òà ¡íÒ˹´¤ ÒµÑÇàÅ¢ (1-5) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊԺˡ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊԺˡẺ¤Ô´à¤Ã×èͧËÁÒ ¶ ÒÁÕ¡Òà ¡íÒ˹´¤ ÒµÑÇàÅ¢ (1-5) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊԺˡâ´ÂáÊ´§ÊÑ­Åѡɳ ($)¹íÒ˹ Ò àª ¹ $37A à» ¹µ ¹ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· Ò ËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§

ËÁÒÂà赯 1

1, 2 1 1, 2 1

ISHEX {1...4}

áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊԺˡẺ¤Ô´à¤Ã×èͧËÁÒÂâ´ÂáÊ´§ ÊÑ­Åѡɳ ($)¹íÒ˹ Ò ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-4) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§

1, 2

BIN {1...16}

áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹Êͧ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊͧẺ¤Ô´à¤Ã×èͧËÁÒ ¶ ÒÁÕ¡Òà ¡íÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§ áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹Êͧâ´ÂáÊ´§ÊÑ­Åѡɳ (%) ¹íÒ˹ Ò àª ¹ %10111000 à» ¹µ ¹ ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§

1

SBIN {1...16} IBIN {1...16}

ISBIN {1...16}

áÊ´§¢ ͤÇÒÁàÅ¢°Ò¹ÊͧẺ¤Ô´à¤Ã×èͧËÁÒ â´ÂáÊ´§ ÊÑ­Åѡɳ (%) ¹íÒ˹ Ò ¶ ÒÁÕ¡ÒáíÒ˹´¤ ÒµÑÇàÅ¢ (1-16) µ Í· ÒÂËÁÒ¶֧¨íҹǹËÅÑ¡·ÕèáÊ´§

STR bytearray STR bytearray\n REP bytearray\n

áÊ´§µÑÇÍÑ¡ÉÃáÍÊ¡Õé¨Ò¡ bytearray ¨¹¡ÃзÑè§äºµ ෠ҡѺ 0 áÊ´§µÑÇÍÑ¡ÉÃáÍÊ¡Õé¨íҹǹ n 亵 ¨Ò¡ bytearray áÊ´§µÑÇÍÑ¡ÉÃáÍÊ¡Õé¢Í§ byte ¨íҹǹ n ¤ÃÑé§ àª ¹ REP "X"/10 ¼ÅÅѾ¸ ·Õèä´ ¤×Í XXXXXXXXXX

1, 2 1, 2

1, 2

ËÁÒÂà赯 (1) ¡ÒáíÒ˹´¨íҹǹËÅÑ¡·ÕèáÊ´§ ઠ¹ DEC4 ¶ Ò¤ Ò·ÕèáÊ´§ÁÕäÁ ¶Ö§ 4 ËÅѡ˹ ҨͨÐáÊ´§àÅ¢ "0" ¹íÒ˹ Ò Â¡µÑÇÍ ҧ DEC4 65 ˹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§ 0065 ¶ Ò¤ ÒµÑÇàÅ¢ÁÕ¨íҹǹËÅÑ¡ÁÒ¡¡Ç Ò·Õè¡íÒ˹´ äÇ Ë¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¢ ÍÁÙŢͧËÅÑ¡´ Ò¹µíèÒà· Ò¹Ñé¹ àª ¹ DEC4 56422 ¤ Ò·ÕèáÊ´§·Õè˹ Òµ Ò§ Debug Terminal ¤×Í 6422 (2) ¡ÒáíÒ˹´¤ Òà¤Ã×èͧËÁÒ ¨Ð㪠¡¯·Ù¤ÍÁ¾ÅÕàÁ¹µ ¤ Ò¢ ÍÁÙŨе ͧÁÕ¢¹Ò´äÁ à¡Ô¹¤ ÒµÑÇá»Ã Word

µÒÃÒ§·Õè 3-10 ÃÒÂÅÐàÍÕ´ÃٻẺ¢Í§¢ ÍÁÙÅ·ÕÊè ÒÁÒÃ¶ãª ä´ ã¹µÑÇá»Ã OutputData ¢Í§¤íÒÊѧè OWOUT Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#


¡Ò÷´Åͧ Í·Õè 19 ¡ÒÃ㪠§Ò¹¤íÒÊѧè OWIN áÅÐ OWOUT (1) 㪠ǧ¨ÃÃÙ»·Õè 3-16 㹡Ò÷´Åͧ (2) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2P24-19.BSP : OWIN amd OWOUT command demonstration***** ' {$STAMP BS2p} ' {$PBASIC 2.5} temp VAR Word ' ¡íÒ˹´µÑÇá»Ãà¡çº¤ ÒÍسËÀÙÁÔ Point VAR Byte ' ¡íÒ˹´µÑÇá»Ãà¡çº¤ ҷȹÔÂÁ¢Í§ÍسËÀÙÁãÔ ¹Ë¹ ÇÂͧÈÒà«Åà«ÕÂÊ tempF VAR Word ' ¡íÒ˹´µÑÇá»Ãà¡çº¤ ÒÍسËÀÙÁãÔ ¹Ë¹ ÇÂͧÈÒ¿Òàùäε PointF VAR Byte ' ¡íÒ˹´µÑÇá»Ãà¡çº¤ ҷȹÔÂÁ¢Í§ÍسËÀÙÁãÔ ¹Ë¹ ÇÂͧÈÒ¿Òàùäε Start: OWOUT 0, 1,[$CC, $44] ' Ê §¤íÒÊѧè á»Å§¤ ÒÍسËÀÙÁÔ CheckForDone: ' Ãͨ¹¡ÃÐ·Ñ§è ¡ÒÃá»Å§¤ ÒàÊÃç¨ÊÔ¹é PAUSE 25 OWIN 0,4,[temp] ' Í Ò¹¤ ÒʶҹШҡÍØ»¡Ã³ IF temp = 0 THEN CheckForDone ' µÃǨÊͺʶҹСÒ÷íÒ§Ò¹àÊÃç¨ÊÔ¹é ¢Í§ÍØ»¡Ã³ ¶ ÒÂѧäÁ àÊÃç¨ãË Ç¹¤ ÒʶҹРOWOUT 0,1,[$CC, $BE] ' ¶ ÒËÒ¡ÍØ»¡Ã³ ·Òí ¡ÒÃá»Å§¤ ÒàÊÃç¨ÊÔ¹é ãË Ê§ ¤íÒÊѧè Í Ò¹¤ Ò¢ ÍÁÙŨҡÍØ»¡Ã³ OWIN 0, 2,[temp.LOWBYTE,temp.HIGHBYTE] ' Í Ò¹¢ ÍÁÙŨҡÍØ»¡Ã³ ÁÒà¡çºäÇ ã¹µÑÇá»Ã ' á»Å§¢ ÍÁÙŴԺ໠¹¤ ÒÍسËÀÙÁãÔ ¹Ë¹ ÇÂͧÈÒà«Åà«ÕÂÊ temp = temp & $0FFF Point = (temp<<4)& $00ff Point = 10000 */ Point DEBUG HOME, DEC temp/16, ".", DEC1 Point, " C", CR ' á»Å§¢ ÍÁÙŴԺ໠¹¤ ÒÍسËÀÙÁãÔ ¹Ë¹ ÇÂͧÈÒ¿Òàùäε tempF = temp * 9 / 5 PointF = temp * 9 // 5 DEBUG DEC tempF/16, ".", DEC1 10000 */ PointF, " F" GOTO Start

' µÑ´ºÔµà¤Ã×Íè §ËÁÒÂÍÍ¡ ' á»Å§¤ Ңͧ·È¹ÔÂÁ ' áÊ´§¤ ÒÍسËÀÙÁ·Ô ËÕè ¹ Òµ Ò§ Debug Terminal ' á»Å§¤ Òà» ¹Ë¹ ÇÂͧÈÒ¿Òàùäε ' ¤íҹdzËÒ¤ ҷȹÔÂÁ¢Í§Ë¹ ÇÂͧÈÒ¿Òàùäε ' áÊ´§¤ ÒÍسËÀÙÁ·Ô ËÕè ¹ Òµ Ò§ Debug Terminal

+5V

4k7

i-Stamp2P24

,5 &* ,5 &*

P0

+5V

GND DQ

+Vcc

ÃÙ»·Õè 3-16 ǧ¨Ã·´Åͧà¾×Íè 㪠§Ò¹¤íÒÊѧè OWIN áÅÐ OWOUT $

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


(3) Ãѹâ»Ãá¡ÃÁ ¨Ð»ÃÒ¡¯Ë¹ Òµ Ò§ Debug Terminal ¢Ö¹é ¾Ã ÍÁ¡ÑºáÊ´§¤ ҢͧÍسËÀÙÁ·Ô Õè DS18B20 ÇÑ´ä´ â´ÂáÊ´§ ·Ñ§é ã¹Ë¹ ÇÂͧÈÒÊÒà«Åà«ÕÂÊáÅпÒàùäε ´Ñ§ÃÙ»

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%


PAUSE ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè PAUSE milliseconds

¤íÒÊÑ§è ¹Õ¨é ÐËÂØ´¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁªÑÇè ¤ÃÒǵÒÁª ǧàÇÅÒ·ÕÃè кØã¹ milliseconds ¾ÒÃÒÁÔàµÍà milliseconds à» ¹¤ ÒµÑ Çá»ÃËÃ× Í¤ Ò¤§·Õè à ¾×è Í ãª ¡íÒ˹´¤ Ңͧª ǧàÇÅÒËÂØ ´¾Ñ ¡ (pause) ÁÕ Ë¹ Ç ໠¹ÁÔÅÅÔÇ¹Ô Ò·Õ ¤ Ò PAUSE ÊÒÁÒö¡íÒ˹´ª ǧàÇÅÒä´ ¹Ò¹·ÕÊè ´Ø à· Ò¡Ñº 65,535 ÁÔÅÅÔÇ¹Ô Ò·Õ µÑÇÍ ҧ¡ÒÃ㪠§Ò¹¤íÒÊÑ§è ¤íÒÊѧè PAUSE 㪠à¾×Íè ˹ ǧàÇÅÒªÑÇè ¤ÃÒÇ¡ ͹¨Ð·íҧҹ㹤íÒÊÑ§è ¶Ñ´ä» Â¡µÑÇÍ ҧ FLASH: LOW 0 PAUSE 100 HIGH 0 PAUSE 100 GOTO FLASH

¨Ò¡â»Ãá¡ÃÁµÑÇÍ ҧ¹Õ¢é Ò P0 ¨ÐÁÕʶҹÐÅͨԡ 0 100 ÁÔÅÅÔÇ¹Ô Ò·Õ ¨Ò¡¹Ñ¹é ¨ÐÁÕʶҹÐÅͨԡ 1 ÍÕ¡ 100 ÁÔÅÅÔÇ¹Ô Ò·Õ

&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


PIN ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè PIN type

à» ¹¤íÒÊÑ§è ¡íÒ˹´ª×Íè µÑÇá»ÃãË á¡ ¢Ò¾Íà µ·Õµè Í §¡ÒõԴµ Í´ Ç µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè #1 SDA PIN 8 SCL PIN 9

¨ÐàËç¹ä´ ÇÒ ´ Ç¡ÒÃ㪠¤Òí Êѧè PIN ¨Ðà» ¹¡ÒáíÒ˹´Í ҧªÑ´à¨¹Ç Ò µÑÇá»Ã SDA áÅÐ SCL ¹Õãé ª á·¹¢Ò ¾Íà µ 8 áÅÐ 9 ¢Í§àºÊÔ¡áʵÁ» «Ö§è ¨Ðᵡµ Ò§¨Ò¡à´ÔÁ·Õãè ª ¤Òí Êѧè CON à¹×Íè §¨Ò¡ã¹¡ÒÃ㪠¤Òí Êѧè CON ¼Ùã ª §Ò¹¨Ð ·ÃÒºà¾ÕÂ§Ç Ò µÑÇá»Ã¹Õãé ª ¤Ò ¤§·Õàè · Òã´ â´ÂäÁ ·ÃÒºÇ Ò ¤ Ò¤§·Õ¹è ¤Õé Í× ¤ Ò¤§·Õ¨è ÃÔ§æ ËÃ×ÍËÁÒÂàÅ¢¢Í§¢Ò¾Íà µ µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè #2 ¨Ò¡µÑÇÍ ҧ #1 àÁ×Íè ¡íÒ˹´¢Ò¾Íà µ´ ǵÑÇá»Ãä´ ¡çÊÒÁÒö¹íÒµÑÇá»Ã¹Ñ¹é 仵ÃǨÊͺà§×Íè ¹ä¢µ Ò§æ ä´ Í ҧ ÍÔÊÃÐ Ê §¼ÅãË ÊÒÁÒöµÃǨÊͺʶҹТͧ¢Ò¾Íà µËÃ×Í¡íÒ˹´Ê¶Ò¹Ð¢Í§¢Ò¾Íà µä´ §Ò Â¢Ö¹é ´Ñ§µÑÇÍ ҧ I2C_Start: INPUT SDA INPUT SCL LOW SDA Clock_Hold: DO : LOOP WHILE (SCL = 0) RETURN

' ¡íÒ˹´ãË ¢Ò¾Íà µ·Õáè ·¹´ ǵÑÇá»Ã SDA à» ¹ÍÔ¹¾Øµ ' ¡íÒ˹´ãË ¢Ò¾Íà µ·Õáè ·¹´ ǵÑÇá»Ã SCL à» ¹ÍÔ¹¾Øµ ' ¡íÒ˹´ãË ¢Ò¾Íà µ·Õáè ·¹´ ǵÑÇá»Ã SDA ÁÕÅͨԡ 0 à¡Ô´¢Ö¹é ' ãË ·Òí §Ò¹Ç¹¨¹¡Ç ÒʶҹТͧ¢Ò¾Íà µ·Õáè ·¹´ ǵÑÇá»Ã SCL à» ¹ 0

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'


POLLIN ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè POLLIN Pin, State

à» ¹¤íÒÊѧè ǹÃÍ¡ÒÃà»ÅÕÂè ¹á»Å§¢Í§ÊÑ­­Ò³·Õ¢è Ò¾Íà µ¢Í§ i-Stamp2P24 ¾ÒÃÒÁÔàµÍà Pin à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ¶Ö§ 15 à¾×Íè 㪠㹡ÒÃàÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 â´ÂàÁ×Íè ¡ÃзíÒ¤íÒÊÑ§è ¹Õ¢é Ò¾Íà µ¢Í§ i-Stamp2P24 ¨Ð·íҧҹ໠¹¢ÒÍÔ¹¾Øµ State à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ËÃ×Í 1 㪠㹡ÒÃàÅ×͡ʶҹÐÅͨԡ·Õµè Í §¡ÒõÃǨ ¨Ñº¶ Òµ ͧ¡ÒõÃǨÊͺÅͨԡ 0 ãË ¡íÒ˹´µÑÇá»Ã¹Õé෠ҡѺ 0 ËÃ×Ͷ Òµ ͧ¡ÒõÃǨ¨ÑºÅͨԡ 1 µ ͧ¡íÒ˹´¤ Ò ¢Í§µÑÇá»Ã෠ҡѺ 1 ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊÑè§ POLLIN ¹Õé¨ÐÊÑÁ¾Ñ¹¸ ¡Ñº¤íÒÊÑè§ POLLMODE, POLLOUT áÅÐ POLLWAIT â´ÂàÁ×Íè i-Stamp2P24 ¡ÃзíÒ¤íÒÊѧè POLLIN Áѹ¨ÐµÃǨÊͺʶҹÐÅͨԡ¢Í§¢Ò¾Íà µ·Õ¡è Òí ˹´ËÅѧ¨Ò¡àÊÃç¨ ÊÔ¹é ¡ÒáÃзíÒ¤íÒÊѧè Í×¹è ·Ø¡¤Ãѧé àÊÁ×͹¡ÑºÇ ÒÁÕ¡ÒÃá·Ã¡¤íÒÊѧè POLLIN ¹Õµé Í · Ò·ء¤íÒÊѧè ã¹â»Ãá¡ÃÁ áÅÐàÁ×Íè à§×Íè ¹ä¢¡ÒõÃǨÊͺ໠¹¨ÃÔ§ i-Stamp2P24 ¨Ð¶Ù¡¢Ñ´¨Ñ§ËÇСÒ÷íÒ§Ò¹à¾×Íè 仵ͺʹͧ¼Å¡ÒõÃǨÊͺ·Õàè ¡Ô´ ¢Ö¹é àËÁ×͹¡Ñº¡Òõͺʹͧ¡ÒÃà¡Ô´ÍÔ¹àµÍÃ Ã»Ñ µ ¢¹Öé áµ ¡Ãкǹ·Ñ§é ËÁ´¹Õäé Á 㪠¡ÒÃà¡Ô´ÍÔ¹àµÍÃ Ã»Ñ µ ¨ÃÔ§æ à¹×Íè § ¨Ò¡àºÊÔ¡áʵÁ» äÁ ÃͧÃѺ¡Ò÷íҧҹẺÍÔ¹àµÍà ÃÑ»µ µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè #1 àÁ×èÍ¡ÒõÃǨÊͺà§×è͹ä¢à» ¹¨ÃÔ§ i-Stamp2P24 ¨Ð¡ÃÐâ´´ä»·íÒ§Ò¹µÒÁ·Õè¤íÒÊÑè§ POLLMODE ¡íÒ˹´ ´Ñ§µÑÇÍ ҧµ Í仹Õé POLLIN 0, 0 POLLMODE 2

㹺Ã÷Ѵáá໠¹¡ÒáíÒ˹´ãË i-Stamp2P24 ǹµÃǨÊͺ¡ÒÃà»ÅÕÂè ¹á»Å§Åͨԡ໠¹ 0 ·Õ¢è Ò¾Íà µ 0 àÁ×Íè à§×Íè ¹ä¢¡ÒõÃǨÊͺ໠¹¨ÃÔ§ ¡ç¨Ðä»·Ò§µÒÁ·Õ¡è Òí ˹´äÇ ã¹¤íÒÊѧè POLLMODE «Öè§ã¹µÑÇÍ ҧ¹Õé¤×Í ·íҧҹ㹠âËÁ´ 2 ËÁÒ¤ÇÒÁÇ Ò ãË áÊ´§¼Å¡Ò÷íÒ§Ò¹¼ Ò¹·Ò§¢Ò¾Íà µ·Õ¡è Òí ˹´ã¹¤íÒÊѧè POLLOUT áµ à¹×Íè §¨Ò¡ã¹â»Ãá¡ÃÁ µÑÇÍ ҧ¢ Ò§µ ¹ÂѧäÁ Á¡Õ ÒÃ㪠¤Òí Êѧè POLLOUT ¨Ö§·íÒãË äÁ Á¼Õ Å¡Ò÷íÒ§Ò¹ã´æ à¡Ô´¢Ö¹é µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè #2 ¨Ò¡µÑÇÍ ҧ #1 ËÒ¡µ ͧ¡ÒÃãË à¡Ô´¼Å¡Ò÷íÒ§Ò¹¢Ö¹é µ ͧá·Ã¡¤íÒÊѧè POLLOUT ŧä»ã¹â»Ãá¡ÃÁ´Ñ§¹Õé POLLIN 0, 0 POLLOUT 1, 1 POLLMODE 2 Loop: DEBUG Looping... , CR GOTO Loop

!

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¨Ò¡µÑÇÍ ҧ¹Õé i-Stamp2P24 ǹµÃǨÊͺ¡ÒÃà»ÅÕÂè ¹á»Å§Åͨԡ໠¹ 0 ·Õ¢è Ò¾Íà µ 0 àÁ×Íè à§×Íè ¹ä¢¡Òà µÃǨÊͺ໠¹¨ÃÔ§ ¡ç¨Ð·íÒãË ¢Ò¾Íà µ 1 à» ¹Åͨԡ 1 áµ ã¹¢³Ð·ÕÇè ¹µÃǨÊͺ¹Ñ¹é i-Stamp2P24 ¡ç¨Ð¹íÒ¢ ͤÇÒÁ Looping... ä»áÊ´§·ÕËè ¹ Òµ Ò§ Debug Terminal µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè #3 ¹Í¡¨Ò¡¹Ñ¹é ¡ÒÃ㪠¤Òí Êѧè POLLIN ÊÒÁÒÃ¶ãª ä´ ÁÒ¡¡Ç Ò 1 ¤Ãѧé ã¹â»Ãá¡ÃÁ ´Ñ§µÑÇÍ ҧ POLLIN 0, 0 POLLIN 1, 0 POLLOUT 2, 1 POLLOUT 3, 1 POLLMODE 2 Loop1: DEBUG Looping... , CR GOTO Loop1

¨Ò¡â»Ãá¡ÃÁµÑÇÍ ҧ i-Stamp2P24 ¨ÐµÃǨÊͺ¢Ò¾Íà µ 0 ¡ ͹ ËÒ¡à» ¹¨ÃÔ§ ¡ç¨Ð·íÒ§Ò¹µÒÁ·Õ¡è Òí ˹´ 㹤íÒÊѧè POLLMODE «Öè§ã¹·Õè¹Õé¤×ÍâËÁ´ 2 «Ö觡íÒ˹´ãË áÊ´§¤ Ò·Ò§àÍÒµ ¾ØµµÒÁ·Õè¡íÒ˹´ã¹¤íÒÊÑè§ POLLOUT ·Ñé§ ËÁ´·ÕÁè ãÕ ¹â»Ãá¡ÃÁ ¨Ò¡¹Ñ¹é ¨Ð¡ÅѺä»ÊÙâ »Ãá¡ÃÁ Í Loop1 àÁ×Íè ¡ÃзíÒ¤íÒÊѧè 㹺Ã÷Ѵ DEBUG Looping... , CR àÊÃç¨ ¡ç¨Ð¡ÅѺ仵ÃǨÊͺ¢Ò¾Íà µ´ ǤíÒÊѧè POLLIN ¡ ͹ ËÒ¡à§×Íè ¹ä¢ÂѧäÁ à» ¹¨ÃÔ§¡ç¨Ð·íҧҹǹÅÙ»Ê §¢ ͤÇÒÁ Looping... ÍÍ¡ä»áÊ´§¼Å·ÕËè ¹ Òµ Ò§ Debug Terminal Í ҧµ Íà¹×Íè §

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


POLLMODE ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè POLLMODE Mode

à» ¹¤íÒÊÑ§è ¡íÒ˹´âËÁ´¡Ò÷íÒ§Ò¹¢Í§¡ÅØÁ ¤íÒÊѧè ǹÃÍà¾×Íè µÃǨÊͺ (POLL command) ¾ÒÃÒÁÔàµÍà Mode à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò à· Ò¡Ñº 0 ¶Ö§ 15 㪠áÊ´§ÃËÑʢͧâËÁ´¡Ò÷íÒ§Ò¹´Ñ§ã¹µÒÃÒ§·Õè 3-11 ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè POLLMODE ¹Õ¨é ÐÊÑÁ¾Ñ¹¸ ¡ºÑ ¤íÒÊѧè POLLIN, POLLOUT, POLLWAIT áÅÐ POLLRUN â´Â¤íÒÊÑ§è ¹Õãé ª 㹡ÒáíÒ˹´ÅѡɳСÒ÷íÒ§Ò¹ËÅѧ¨Ò¡·Õàè §×Íà ¹ä¢¢Í§¡ÒÃâ¾ÅÅÔ§è à» ¹¨ÃÔ§ áµ ¶Ò ËÒ¡ ã¹â»Ãá¡ÃÁÁÕáµ ¤Òí Êѧè POLLIN áÅÐ POLLOUT â´ÂäÁ Á¡Õ ÒÃ㪠¤Òí Êѧè POLLMODE äÁâ¤Ã¤Í¹â·ÃÅàÅÍà iStamp2p24 ¡ç¨Ð¡ÃзíÒ¤íÒÊѧè POLLIN áÅÐ POLLOUT µÒÁÅíҴѺ áÅÐäÁ Á¡Õ ÒÃǹ¤ÍµÃǨÊͺËÅѧ¨Ò¡ ¡ÃзíÒ¤íÒÊѧè ã´æ àÊÃç¨ÊÔ¹é ·Ø¡¤íÒÊѧè ËÃ×ÍÍÒ¨¡Å ÒÇÇ Ò¶ ÒäÁ Á¡Õ ÒÃ㪠§Ò¹¤íÒÊѧè POLLMODE ã¹â»Ãá¡ÃÁ ¡ÒÃâ¾ ÅÅÔè§à¾×èÍÊà ҧ¡ÒÃÍÔ¹àµÍà ÃÑ»µ àÊÁ×͹¨ÐäÁ ÁÕ·Ò§à¡Ô´¢Öé¹ Í ҧäáçµÒÁ ã¹â»Ãá¡ÃÁ˹֧è æ ÊÒÁÒöÂÍÁãË Á¡Õ ÒÃ㪠¤Òí Êѧè POLLMODE ä´ ËÅÒ¤Ãѧé áÅÐáµ ÅÐ ¤Ãѧé äÁ ¨Òí à» ¹µ ͧ㪠âËÁ´à´ÔÁ ÊÒÁÒöà»ÅÕÂè ¹á»Å§ä´ µÒÁµ ͧ¡Òà âËÁ´ (Mode) 0

¡Ò÷íÒ§Ò¹ äÁ ÁÕ¡ÒÃâ¾ÅÅÔ觾à ÍÁ·Ñé§à¤ÅÕÂà ʶҹТͧ¾Íà µ·Õèà¡ÕèÂÇ¢ ͧ

1 2

äÁ ÁÕ¡ÒÃâ¾ÅÅÔè§ áµ Âѧ¤§ÃÑ¡ÉÒ¤ Ңͧ¾Íà µ·Õèà¡ÕèÂÇ¢ ͧäÇ áÍ¡µÕ¿¡ÒÃâ¾ÅÅÔè§ ¾Ã ÍÁ·Ñé§áÊ´§¼Å·Ò§àÍÒµ ¾ØµáÅеͺʹͧ¤íÒÊÑè§ POLLWAIT à· Ò¹Ñé¹

3*

áÍ¡µÕ¿¡ÒÃâ¾ÅÅÔè§áÅеͺʹͧ¤íÒÊÑè§ POLLRUN à· Ò¹Ñé¹

4 **

áÍ¡µÕ¿¡ÒÃâ¾ÅÅÔè§ ¾Ã ÍÁ·Ñé§áÊ´§¼Å·Ò§àÍÒµ ¾Øµ,µÍºÊ¹Í§¤íÒÊÑè§ POLLRUN áÅÐ POLLWAIT

5 ***

à¤ÅÕÂà ¡ÒáíÒ˹´Ê¶Ò¹Ð¢Í§¾Íà µ·Õè·íÒ§Ò¹¡Ñº¤íÒÊÑè§ POLLIN

6 *** 7 ***

à¤ÅÕÂà ¡ÒáíÒ˹´Ê¶Ò¹Ð¢Í§¾Íà µ·Õè·íÒ§Ò¹¡Ñº¤íÒÊÑè§ POLLOUT à¤ÅÕÂà ¡ÒáíÒ˹´Ê¶Ò¹Ð¢Í§¾Íà µ·Õè·íÒ§Ò¹¡Ñº¤íÒÊÑè§ POOLIN áÅÐ POLLOUT

8-15

àËÁ×͹¡ÑºâËÁ´ 0-7 ᵠʶҹТͧ¾Íà µ·Õè·íÒ§Ò¹¡Ñº POLLOUT ¨Ð¶Ù¡áŵª äÇ

ËÁÒÂà赯 * àÁ×èÍ¡ÃÐâ´´ä»·íÒ§Ò¹ã¹à¾¨¢Í§Ë¹ ǤÇÒÁ¨íÒ·Õè¡íÒ˹´ã¹¤íÒÊÑè§ POLLRUN áÅ Ç ¨Ðà»ÅÕè¹âËÁ´ä»ÂѧâËÁ´ 1 â´ÂÍѵâ¹ÁÑµÔ ** àÁ×èÍ¡ÃÐâ´´ä»·íÒ§Ò¹ã¹à¾¨¢Í§Ë¹ ǤÇÒÁ¨íÒ·Õè¡íÒ˹´ã¹¤íÒÊÑè§ POLLRUN áÅ Ç ¨Ðà»ÅÕè¹âËÁ´ä»ÂѧâËÁ´ 2 â´ÂÍѵâ¹ÁÑµÔ *** ¡ÒÃà¤ÅÕÂà ¤ Òã¹âËÁ´¹Õé¨ÐäÁ Ê §¼Åµ ÍʶҹзҧÎÒà ´áÇà ¢Í§¾Íà µ

µÒÃÒ§·Õè 3-11ÃÒÂÅÐàÍÕ´㹡ÒÃàÅ×Í¡âËÁ´¢Í§¤íÒÊѧè POLLMODE !

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ #1

POLLIN 0, 1 POLLOUT 1, 0 POLLMODE 2 Loop1: DEBUG Looping... , CR GOTO Loop1

¨Ò¡â»Ãá¡ÃÁµÑÇÍ ҧ¢ Ò§µ ¹ ÊͧºÃ÷Ѵáá໠¹¡ÒáíÒ˹´à§×Íè ¹ä¢áÅмŷÕàè ¡Ô´¢Ö¹é ËÅѧ¨Ò¡à§×Íè ¹ä¢¢Í§ ¡ÒÃâ¾ÅÅÔ§è ËÃ×Í¡ÒÃǹµÃǨÊͺ໠¹¨ÃÔ§ ¶Ñ´ÁÒ㹺Ã÷Ѵ·ÕÊè ÒÁ㪠¤Òí Êѧè POLLMODE 2 Íѹ໠¹¡ÒáíÒ˹´âËÁ´ 2 ¢Í§¡ÒÃâ¾ÅÅÔ§è ã¹âËÁ´¹Õ¨é ÐáÍ¡µÕ¿¡ÒÃâ¾ÅÅÔ§è à¾×Íè Êà ҧ¡ÒÃÍÔ¹àµÍÃ Ã»Ñ µ àÊÁ×͹áÅÐàÁ×Íè à§×Íè ¹ä¢¡ÒÃâ¾ÅÅÔ§è à» ¹¨ÃÔ§¡ç ¨ÐáÊ´§¼ÅàÍÒµ ¾µØ µÒÁ·Õ¤è Òí Êѧè POLLOUT ¡íÒ˹´äÇ µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ #2 POLLIN 0, 0 POLLOUT 1, 1 POLLMODE 2 DEBUG Polling configured , CR Main: POLLMODE 1 DEBUG No polling allowed here... , CR PAUSE 1000 POLLMODE 2 Loop1: DEBUG Polling now... , CR GOTO Loop1

ã¹µÑÇÍ ҧ¹Õàé ÃÔÁè µ ¹´ Ç¡ÒáíÒ˹´¡ÒÃâ¾ÅÅÔ§è â´Â¡íÒ˹´ãË ¢Ò¾Íà µ 0 µÃǨÊͺÅͨԡ 0 àÁ×Íè à§×Íè ¹ä¢ à» ¹¨ÃÔ§¨ÐÁÕÅͨԡ 1 Ê §ÍÍ¡¨Ò¡¢Ò¾Íà µ 1 ¨Ò¡¹Ñ¹é ·íÒ¡ÒÃáÊ´§¢ ͤÇÒÁ Polling configured º¹Ë¹ Òµ Ò§ Debug terminal ¨Ò¡¹Ñ¹é à»ÅÕÂè ¹âËÁ´à» ¹ âËÁ´ 1 Íѹ໠¹¡ÒáàÅÔ¡¡ÒÃâ¾ÅÅÔ§è áÅ ÇãË áÊ´§¢ ͤÇÒÁ No polling allowed here...¶Ñ´¨Ò¡¹Ñ¹é ˹ ǧàÇÅÒáÅ Çà»ÅÕÂè ¹âËÁ´à» ¹ âËÁ´ 2 ¹Ñ¹è ËÁÒ¤ÇÒÁÇ Ò ã¹ÃÐËÇ Ò§·ÕËè ¹ ǧàÇÅÒ 1 ÇÔ¹Ò·Õ¹¹Ñé ¨ÐäÁ Á ¡Õ ÒÃâ¾ÅÅÔ§è à¡Ô´¢Ö¹é ¨¹¡Ãзѧè i-Stamp2p24 ¡ÃзíÒ¤íÒÊѧè POLLMODE 2 à¾×Íè à»ÅÕÂè ¹âËÁ´¢Í§¡ÒÃâ¾ÅÅÔ§è à» ¹âËÁ´ 2 ¨Ö§¨Ð¡ÅѺÁÒµÃǨÊͺʶҹТͧ¾Íà µ 0 µÒÁà´ÔÁ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!!


µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ #3 ã¹µÑÇÍ ҧ¹Õàé » ¹¡ÒÃáÊ´§ãË àË繶֧¡ÒáÃÐâ´´ä»·íÒ§Ò¹ã¹à¾¨ 1 ËÃ×ÍÊÅç͵ 1 (»¡µÔ¨Ðà¢Õ¹â»Ãá¡ÃÁ㪠§Ò¹ i-Stamp2p24 ·Õàè ¾¨ 0 ËÃ×ÍÊÅç͵ 0) àÁ×Íè ¡ÒõÃǨÊͺà§×Íè ¹ä¢¢Í§¤íÒÊѧè POLLIN à» ¹¨ÃÔ§ â´Âµ ͧ¡íÒ˹´âËÁ´¢Í§ ¤íÒÊѧè POLLMODE ãË à· Ò¡Ñº 3 ËÃ×Í 4 â»Ãá¡ÃÁµÑÇÍ ҧÁÕ´§Ñ ¹Õé à¢Õ¹â»Ãá¡ÃÁ Program #1 ŧã¹à¾¨ 0 ' Program #1 (Slot 0) ' {$STAMP BS2p, POLL1.BSP} POLLIN 0, 1 POLLOUT 1, 1 POLLRUN 1 POLLMODE 4 Loop1: DEBUG "Program 1", CR GOTO Loop1

à¢Õ¹â»Ãá¡ÃÁ Program #2 ŧã¹à¾¨ 1 áÅ ÇµÑ§é ª×Íè ä¿Å à» ¹ POLL1.BSP ' Program #2 (Slot 1) ' {$STAMP BS2p} DEBUG "Switching...", CR Loop1: DEBUG "Program 2", CR GOTO Loop1

àÁ×Íè Ãѹâ»Ãá¡ÃÁ i-Stamp2p24 ¨Ð·íÒ§Ò¹·Õàè ¾¨ 0 ¡ ͹ â´Â¨ÐµÃǨÊͺà§×Íè ¹ä¢¢Í§¡ÒÃâ¾ÅÅÔ§è ·Õ¢è Ò¾Íà µ 0 Ç Òà» ¹¨ÃÔ§ËÃ×ÍäÁ ËÒ¡Âѧ ¨ÐáÊ´§¢ ͤÇÒÁ Program 1 ·ÕËè ¹ Òµ Ò§ Debug Terminal ¨¹¡Ç Òà§×Íè ¹ä¢¢Í§¡ÒõÃǨ Êͺ¨Ðà» ¹¨ÃÔ§ ·ÕËè ¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¢ ͤÇÒÁ Switching... áÅ Çà»ÅÕÂè ¹à» ¹ Program 2 ¨Ò¡â»Ãá¡ÃÁ ÁÕ¡ÒÃ㪠¤Òí Êѧè POLLRUN à¾×Íè ¡íÒ˹´ãË i-Stamp2p24 ¡ÃÐâ´´ä»Âѧྨ 0 ËÃ×ÍÊÅç͵ 0 àÁ×Íè à§×Íè ¹ä¢¢Í§¡ÒÃâ¾ÅÅÔ§è à» ¹¨ÃÔ§ áÅÐÁÕ¡ÒáíÒ˹´âËÁ´¢Í§¡ÒÃâ¾ÅÅÔ§è ´ ǤíÒÊѧè POLLMODE ä»·Õâè ËÁ´ 4

!"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


POLLOUT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè POLLOUT Pin, State

à» ¹¤íÒÊѧè áÊ´§¼Å¢Í§¡Ò÷íÒ§Ò¹àÁ×Íè à§×Íè ¹ä¢¢Í§¡ÒÃǹµÃǨÊͺ໠¹¨ÃÔ§ ¾ÒÃÒÁÔàµÍà Pin à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ¶Ö§ 15 à¾×Íè 㪠㹡ÒÃàÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2p24 â´ÂàÁ×Íè ¡ÃзíÒ¤íÒÊÑ§è ¹Õ¢é Ò¾Íà µ¢Í§ i-Stamp2p24 ¨Ð·íҧҹ໠¹¢ÒàÍÒµ ¾µØ State à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ËÃ×Í 1 㪠㹡ÒÃàÅ×͡ʶҹÐÅͨԡ·Õµè Í §¡ÒÃãË à¡Ô´¢Ö¹é àÁ×Íè à§×Íè ¹ä¢¢Í§¡ÒÃǹµÃǨÊͺ´ ǤíÒÊѧè POLLIN à» ¹¨ÃÔ§ ¶ Òµ ͧ¡ÒÃãË à¡Ô´Åͨԡ 0 ãË ¡Òí ˹´µÑÇá»Ã¹Õé ෠ҡѺ 0 ËÃ×Ͷ Òµ ͧ¡ÒÃãË à¡Ô´Åͨԡ 1 µ ͧ¡íÒ˹´¤ ҢͧµÑÇá»Ã෠ҡѺ 1 ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊÑ§è ¹Õàé » ¹Ë¹Ö§è 㹡ÅØÁ ¢Í§¤íÒÊѧè à¡ÕÂè ǡѺ¡ÒÃÍÔ¹àµÍÃ Ã»Ñ µ àÊÁ×͹ẺǹÃÍËÃ×Íâ¾ÅÅÔ§è (polling) â´Â µ ͧ㪠§Ò¹Ã ÇÁ¡Ñº¤íÒÊѧè POLLIN áÅÐ POLLMODE áÅÐÂѧÁÕ¡Ò÷íÒ§Ò¹·ÕÊè ÁÑ ¾Ñ¹¸ ¡ºÑ ¤íÒÊѧè POLLRUN ´ Ç â´Â¶ ÒËÒ¡ÁÕ¡ÒáíÒ˹´ã¹¤íÒÊѧè POLLMODE ãË µÍºÊ¹Í§à§×Íè ¹ä¢¢Í§¡ÒÃâ¾ÅÅÔ§è ·Õàè » ¹¨ÃÔ§´ Ç¡ÒÃáÊ´§¼Å ·Ò§àÍÒµ ¾µØ ´ ǤíÒÊѧè POLLOUT áÅСÃÐâ´´ä»·íÒ§Ò¹Âѧâ»Ãá¡ÃÁã¹à¾¨Í×¹è ´ ǤíÒÊѧè POLLRUN (âËÁ´ 4) àºÊÔ¡áʵÁ» 2P ¨ÐàÅ×Í¡ãË µÍºÊ¹Í§¤íÒÊѧè POLLOUT ¡ ͹ µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ #1

POLLIN 0, 1 POLLOUT 1, 0 POLLMODE 2 Loop1: DEBUG Looping... , CR GOTO Loop1

ã¹µÑÇÍ ҧ¹Õàé Á×Íè à§×Íè ¹ä¢¢Í§¡ÒÃâ¾ÅÅÔ§è ·Õ¢è Ò¾Íà µ 0 ¢Í§ i-Stamp2p24 à» ¹¨ÃÔ§ ¢Ò¾Íà µ 1 ¨Ð¡ÅÒ ໠¹¢ÒàÍÒµ ¾µØ áÅ ÇáÊ´§¤ ÒÅͨԡ 0 ÍÍ¡ÁÒ áµ ¶Ò à§×Íè ¹ä¢ÂѧäÁ à» ¹¨ÃÔ§¢Ò¾Íà µ 1 ¡ç¨ÐÁÕÊ­ Ñ ­Ò³Åͨԡ 1 á·¹ ¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁµÑÇÍ ҧ¹Õé¨ÐàËÁ×͹¡Ñºâ»Ãá¡ÃÁµ Í仹Õé INPUT 0 OUTPUT 1 Loop1: OUT1 = ~IN0 DEBUG Looping... , CR OUT1 = ~IN0 GOTO Loop1

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!#


µÑÇÍ ҧ¡ÒÃ㪠§Ò¹ #2 ઠ¹à´ÕÂǡѺ¤íÒÊѧè POLLIN ¼Ùã ª §Ò¹ÊÒÁÒö㪠¤Òí Êѧè POLLOUT ä´ ÁÒ¡¡Ç Ò 1 ¤Ãѧé ã¹áµ ÅÐâ»Ãá¡ÃÁ ¾Ô¨ÒÃ³Ò â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé POLLIN 0, 1 POLLOUT 1, 0 POLLOUT 2, 1 POLLOUT 3, 1 POLLMODE 2 Loop1: DEBUG Looping.... , CR GOTO Loop1

àÁ×Íè à§×Íè ¹ä¢¢Í§¡ÒÃâ¾ÅÅÔ§è ·Õ¢è Ò¾Íà µ 0 à» ¹¨ÃÔ§ (¾Íà µ 0 ෠ҡѺ 1 ) áÅÐÁÕ¡ÒáíÒ˹´âËÁ´¢Í§¡Òà â¾ÅÅÔ§è äÇ ·âÕè ËÁ´ 2 (㹤íÒÊѧè POLLMODE) i-Stamp2p24 ¨ÐãË àÍÒµ ¾µØ ÍÍ¡¾Ã ÍÁ¡Ñ¹·Ñ§é ÊÒÁ¢Ò¤×Í·Õè ¾Íà µ 1, 2 áÅÐ 3 â´Â¾Íà µ 1 ãË Åͨԡ 0 Ê Ç¹¾Íà µ 2 áÅÐ 3 ãË Åͨԡ 1 ËÒ¡à§×Íè ¹ä¢¡ÒõÃǨÊͺÂѧäÁ à» ¹¨ÃÔ§ ¡ç¨ÐÊ §¢ ͤÇÒÁ Looping.... ä»áÊ´§Âѧ˹ Òµ Ò§ Debug Terminal

!$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


POLLRUN ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè POLLRUN ProgramSlot

à» ¹¤íÒÊÑ§è ¡íÒ˹´â»Ãá¡ÃÁ·Õè i-Stamp2P24 ¨Ðµ ͧ¡ÃÐâ´´ä»·íÒ§Ò¹ àÁ×Íè à§×Íè ¹ä¢¢Í§¡ÒÃǹÃÍËÃ×Í â¾ÅÅÔ§è à» ¹¨ÃÔ§ ¾ÒÃÒÁÔàµÍà ProgramSlot à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ¶Ö§ 7 㪠áÊ´§µíÒá˹ §¢Í§à¾¨ËÃ×ÍÊÅç͵ ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁÀÒÂã¹ i-Stamp2p24 ·Õµè Í §¡ÒÃãË ¡ÃÐâ´´ä»·íÒ§Ò¹ ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ à¹×Íè §¨Ò¡Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ·Õãè ª à» ¹Ë¹ ǤÇÒÁ¨íÒâ»Ãá¡ÃÁ¢Í§ i-Stamp2p24 ÁÕ¢¹Ò´ 16 ¡ÔâŠ亵 áµ àºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍà ¨ÐÊÒÁÒöµÔ´µ ͡Ѻ˹ ǤÇÒÁ¨íÒä´ äÁ à¡Ô¹ 2 ¡ÔâÅ亵 ´Ñ§¹Ñ¹é ã¹ ¡Ò÷íÒ§Ò¹¡Ñºâ»Ãá¡ÃÁ¢¹Ò´ 16 ¡ÔâÅ亵 ¨§Ö ¨íÒà» ¹µ ͧá¡â»Ãá¡ÃÁÍÍ¡à» ¹ 8 â»Ãá¡ÃÁ¤×Í â»Ãá¡ÃÁ 0 ¶Ö§ 7 ¨ÐàÃÕ¡¾×¹é ·Õ¢è ͧâ»Ãá¡ÃÁ¢¹Ò´ 2 ¡ÔâÅ亵 ¹ÇÕé Ò à¾¨ (page) ËÃ×Í ÊÅç͵ (slot) 㹡ÒÃ㪠§Ò¹¤íÒÊÑ§è ¹Õ¨é Ð ÊÑÁ¾Ñ¹¸ ¡ºÑ ¤íÒÊѧè POLLIN, POLLOUT áÅÐ POLLMODE â´Â¨Ðµ ͧ¡íÒ˹´·Õè POLLMODE ãË i-Stamp2p24 µÍºÊ¹Í§¡ÒÃâ¾ÅÅÔ§è ´ Ç¡ÒáíÒ˹´ãË ¡ÃÐâ´´ä»·íÒ§Ò¹ÂѧÊÅç͵Í×¹è ËÃ×Í¡íÒ˹´ãË ·Òí §Ò¹ã¹âËÁ´ 3 ËÃ×Í 4 (´ÙÃÒÂÅÐàÍÕ´㹤íÒÊѧè POLLMODE) àÁ×Íè i-Stamp2p24 ·íÒ§Ò¹ÍÂÙ· ÊÕè Åç͵¡ç¨Ð¤§ÍÂÙ· âÕè »Ãá¡ÃÁã¹ÊÅç͵¹Ñ¹é ¨¹¡Ç Ò¨ÐÁÕ¡ÒÃà»ÅÕÂè ¹á»Å§´ ǤíÒÊѧè RUN ËÃ×Í POLLRUN áŠǵÒÁ´ ÇÂàÅ¢ËÁÒ¢ͧÊÅç͵¢Í§â»Ãá¡ÃÁ ãËÁ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!%


POLLWAIT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè POLLWAIT Period

à» ¹¤íÒÊѧè ˹ ǧàÇÅÒà¾×Íè ÃÍãË à§×Íè ¹ä¢¢Í§¡ÒÃǹÃÍËÃ×Íâ¾ÅÅÔ§è à» ¹¨ÃÔ§ â´Â㹪 ǧàÇÅÒ¹Õé i-Stamp2p24 ¨Ð·íÒ§Ò¹ã¹âËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹ ¾ÒÃÒÁÔàµÍà Period à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ¶Ö§ 8 㪠¡Òí ˹´ª ǧàÇÅҢͧʶҹлÃÐËÂÑ´¾Åѧ§Ò¹ â´ÂÊÒÁÒö¤íÒ¹Ç³ä´ ¨Ò¡ 2Period x 18 ÁÔÅÅÔÇ¹Ô Ò·Õ ã¹¡Ã³Õ·¡Õè Òí ˹´ãË Á¤Õ Ò à· Ò¡Ñº 8 i-Stamp2p24 ¨ÐäÁ ࢠÒÊÙÀ ÒÇÐ »ÃÐËÂÑ´¾Åѧ§Ò¹ áµ ¨Ð·íÒ§Ò¹¡Òõͺʹͧµ Í¡ÒÃâ¾ÅÅÔ§è 㹷ѹ·Õ ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊѧè POLLWAIT à» ¹Ë¹Ö§è 㹡ÅØÁ ¤íÒÊÑ§è ·Õàè ¡ÕÂè Ç¢ ͧ¡Ñº¡ÒÃâ¾ÅÅÔ§è ËÃ×Í¡ÒÃǹÃ͵ÃǨÊͺ «Ö§è ¨Ðµ ͧ·íÒ §Ò¹Ã ÇÁ¡Ñº¤íÒÊѧè POLLIN áÅÐ POLLMODE â´Â¨ÐÊÒÁÒö㪠§Ò¹ä´ àÁ×Íè ¡íÒ˹´âËÁ´¢Í§¡ÒÃâ¾ÅÅÔ§è ෠ҡѺ 2 ËÃ×Í 4 ·Õ¤è Òí Êѧè POLLMODE àÁ×Íè 㪠§Ò¹¤íÒÊÑ§è ¹Õé ã¹ÃÐËÇ Ò§·ÕÇè ¹ÃÍãË à§×Íè ¹ä¢¢Í§¤íÒÊѧè POLLIN à» ¹¨ÃÔ§ i-Stamp2p24 ¨Ð·íÒ§Ò¹ã¹âËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹à» ¹ÃÐÂÐàÇÅÒÂÒǹҹµÒÁ·Õ¡è Òí ˹´äÇ ã¹µÑÇá»Ã Period â´Â㹪 ǧàÇÅÒ¹Õé iStamp2p24 ¨Ð㪠¾Åѧ§Ò¹Å´Å§àËÅ×Íà¾Õ§ 60PA ෠ҹѹé 㹡óշÁÕè ¡Õ ÒáíÒ˹´ãË µÍºÊ¹Í§¤íÒÊѧè POLLRUN áÅÐ POLLWAIT àÁ×Íè à§×Íè ¹ä¢·Õ¤è Òí Êѧè POLLIN à» ¹¨ÃÔ§ (POLLMODE 4) i-Stamp2p24 ¨ÐµÍºÊ¹Í§µ ͤíÒÊѧè POLLRUN 㹷ѹ·Õ µÑÇÍ ҧ¡ÒÃ㪠§Ò¹¤íÒÊѧè POLLIN 0, 1 Loop1: POLLWAIT 0 TOGGLE 1 GOTO Loop1

¨Ò¡â»Ãá¡ÃÁµÑÇÍ ҧ¤íÒÊѧè POLLIN ¨ÐǹµÃǨÊͺʶҹзբè Ò¾Íà µ 0 ¨¹¡Ç Ò¨Ðà» ¹Åͨԡ 1 ã¹ â»Ãá¡ÃÁ Í Loop ¡íÒ˹´¤ Ò Period ãË ¤Òí Êѧè POLLWAIT ෠ҡѺ 0 «Ö§è ෠ҡѺàÇÅÒ 18 ÁÔÅÅÔÇ¹Ô Ò·Õ ¹Ñ¹è ËÁÒ¤ÇÒÁ Ç Ò·Ø¡æ 18 ÁÔÅÅÔÇÔ¹Ò·Õ i-Stamp2p24 ¨ÐÍÍ¡¨Ò¡âËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹à¾×è͵ÃǨÊͺʶҹÐÅͨԡ·Õè¢Ò¾Íà µ 0 ¶ Òà§×Íè ¹ä¢ÂѧäÁ à» ¹¨ÃÔ§ i-Stamp2p24 ¨Ð¡ÅѺࢠÒÊÙâ ËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹ÍÕ¡ 18 ÁÔÅÅÔÇ¹Ô Ò·Õ áÅ Çǹ¡ÅѺÁÒµÃǨÊͺ ¢Ò¾Íà µ 0 ÍÕ¡¤Ãѧé àÁ×Íè à§×Íè ¹ä¢¡ÒõÃǨÊͺ໠¹¨ÃÔ§ i-Stamp2p24 ¨Ð¡ÃзíÒ¤íÒÊÑ§è ¶Ñ´ä»·Ñ¹·Õ ¹Ñ¹è ¤×Í TOGGLE 1 Íѹ໠¹ ¡ÒáÅѺÅͨԡ·Õ¢è Ò¾Íà µ 1 ¨Ò¡¹Ñ¹é ¨Ð¡ÅѺࢠÒÊÙÅ »Ù ¢Í§¡ÒõÃǨÊͺµ Íä»

!&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


PULSIN ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè PULSIN pin, state, resultVariable

㪠㹡ÒÃÇÑ´ÊÑ­­Ò³¾ÑÅÊ ·»Õè Í ¹à¢ ÒÁÒÂѧ¢Ò¾Íà µ¢Í§ i-Stamp2p24 ·Ø¡æ 0.75 äÁâ¤ÃÇÔ¹Ò·Õ ¾ÒÃÒÁÔàµÍà pin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò ÍÂÙà ÐËÇ Ò§ 0 ¶Ö§ 15 à¾×Íè ÃкصÒí á˹ §¢Ò¾Íà µ¢Í§ i-Stamp2p24 ·Õµè Í § ¡ÒÃ㪠ÊÒí ËÃѺ¡ÒùѺ¨íҹǹ¾ÑÅÊ â´Â¢Ò·ÕÃè кبÐࢠÒÊÙâ ËÁ´ÍÔ¹¾Øµâ´ÂÍѵâ¹ÁѵáÔ ÅÐËÅѧ¨Ò¡¡ÃзíÒ¤íÒÊѧè àÊÃç¨àÃÕºà Í ¡ç¨Ð¤×¹¡ÅѺÊ٠ʶҹÐà´ÔÁ state à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò à· Ò¡Ñº 0 ËÃ×Í 1 à¾×Íè 㪠¡Òí ˹´¤ ÒÅͨԡàÃÔÁè µ ¹ã¹¡ÒÃÇÑ´ ¶ Ò¤ Ò state=0 ¨Ðà» ¹¡ÒáíÒ˹´ãË ¹ºÑ àÁ×Íè ¾ÑÅÊ à»ÅÕÂè ¹¨Ò¡Åͨԡ 1 à» ¹ 0 ¶ Ò¤ Ò state=1 ¨Ðà» ¹¡ÒáíÒ˹´ãË ¹ºÑ àÁ×Íè ¾ÑÅÊ à»ÅÕÂè ¹ ¨Ò¡Åͨԡ 0 à» ¹ 1 resultVariable à» ¹¤ ÒµÑÇá»Ã·Õãè ª à¡çº¨íҹǹ¾ÑÅÊ ·¹Õè ºÑ ä´ ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¼Ùã ª §Ò¹ÊÒÁÒöÁͧ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè PULSIN àËÁ×͹¡Ñº¹ÒÌ ¡Ò¨ÑºàÇÅÒ àÁ×Íè ʶҹÐÅͨԡ¢Í§¢Ò¾Íà µ ·Õãè ª §Ò¹à¡Ô´¡ÒÃà»ÅÕÂè ¹á»Å§µÒÁ¤ Ò·Õ¡è Òí ˹´äÇ ã¹ state ¹ÒÌ ¡Ò¨ÑºàÇÅÒ¹Õ¨é зíÒ§Ò¹ àÁ×Íè ÁÕ¡ÒÃà»ÅÕÂè ¹Ê¶Ò¹Ð·Õ¢è Ò¹Õé ÍÕ¡¤ÃÑ§é ¹ÒÌ ¡Ò¨ÑºàÇÅÒ¹Õ¨é ÐËÂØ´·íÒ§Ò¹ ¶ ÒʶҹТͧ¢ÒäÁ Á¡Õ ÒÃà»ÅÕÂè ¹á»Å§ ¹ÒÌ ¡Ò¨ÑºàÇÅÒ¨ÐäÁ ä´ ÃºÑ ¡ÒáÃеع ¤íÒÊѧè PULSIN ¨ÐÃͨ¹¡ÃÐ·Ñ§è ¤ Ò¤ÒºàÇÅÒÊÙ§ÊØ´·Õè 49.125 ÁÔÅÅÔÇ¹Ô Ò·Õ ËÃ×Í 0.049 ÇÔ¹Ò·Õ ¨Ð·íÒ¡ÒÃÊ §¤ Ò 0 ¡ÅѺä»Âѧ resultVariable ËÃ×Ͷ Ò ¾ÑÅÊ Í¹Ô ¾ØµÁÕ¤ÇÒÁ¡Ç Ò§ÁÒ¡¡Ç Ò 0.049 ÇÔ¹Ò·Õ ¤íÒÊѧè PULSIN ¨ÐÊ §Åͨԡ 0 ä»Âѧ resultVariable ઠ¹¡Ñ¹ ¤íÒÊѧè PULSIN ÊÒÁÒöÇÑ´¤ ҢͧÊÑ­­Ò³¾ÑÅÊ ¤ÇÒÁ¶ÕÊè §Ù ÊØ´äÁ à¡Ô¹ 666.67kHz ·Õ¤è Ò ¢Í§ resultVariable ෠ҡѺ 1 áÅÐÇÑ´¤ÇÒÁ¶Õäè ´ µÒèí Êش෠ҡѺ 10.17Hz ·Õ¤è Ò resultVariable ෠ҡѺ 65535

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!'


PULSOUT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè PULSOUT pin, time

Ê §¾ÑÅÊ ÅͨԡÊÙ§·ÕÁè ¤Õ ÒºàÇÅҵѧé áµ 1.18 äÁâ¤ÃÇÔ¹Ò·Õ¶§Ö 55.479 ÁÔÅÅÔÇ¹Ô Ò·ÕÍÍ¡ä»Âѧ¢Ò¾Íà µ·Õ¡è Òí ˹´ ¾ÒÃÒÁÔàµÍà pin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò ÍÂÙã ¹ª ǧ 0 ¶Ö§ 15 à¾×Íè àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2p24 ¢Ò¾Íà µ¨Ð ¶Ù¡¡íÒ˹´ãË à» ¹àÍÒµ ¾µØ à¾×Íè Ê §ÊÑ­­Ò³¾ÑÅÊ áÅСÅѺ໠¹Ê¶Ò¹Ðà´ÔÁËÅѧ¡ÃзíÒ¤íÒÊѧè PULSOUT àÃÕºà Í time à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 65,535 㪠¡Òí ˹´¤ÒºàÇÅҢͧ¾ÑÅÊ Á¤Õ Ò Ë¹ ÇÂÅÐ 0.8 äÁâ¤ÃÇÔ¹Ò·Õ ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊÑè§ PULSOUT ·íÒ§Ò¹ËÅÒÂ˹ Ò·Õè㹤ÃÒÇà´ÕÂÇ àÃÔèÁ¨Ò¡¡íÒ˹´ãË ¢Ò¾Íà µ·Õè㪠§Ò¹à» ¹àÍÒµ ¾Øµ ´ Ç¡ÒÃÊ §¤ Ò 1 ä»ÂѧÃÕ¨ÊÔ àµÍà DIRS ¨Ò¡¹Ñ¹é ¡ÅѺʶҹТͧºÔµ·Õãè ª §Ò¹ã¹ÃÕ¨ÊÔ àµÍà OUTS ¤§Ê¶Ò¹Ð¹Õé äÇ à» ¹àÇÅÒ෠ҡѺ 1.18 äÁâ¤ÃÇÔ¹Ò·Õ¤³ Ù ¡Ñº¤ ҢͧµÑÇá»Ã time ¨Ò¡¹Ñ¹é ¡ÅѺʶҹТͧºÔµã¹ÃÕ¨ÊÔ àµÍà OUTS ÍÕ¡¤ÃÑ§é ¢Ñ¹é µÍ¹ÊØ´· Ò¤×Í ¤×¹Ê¶Ò¹Ðà´ÔÁ¢Í§¢Ò¾Íà µ·Õ¹è Òí ÁÒ㪠§Ò¹ µÑÇÍ ҧ¡ÒÃ㪠§Ò¹¤íÒÊÑ§è ¹ÕÁé ´Õ §Ñ ¹Õé PULSOUT 5,85 ¡íÒà¹Ô´ÊÑ­­Ò³¾ÑÅÊ 100 äÁâ¤ÃÇÔ¹Ò·Õʧ ÍÍ¡ä»·Ò§¢Ò P5 ·ÔÈ·Ò§¢Í§¾ÑÅÊ ¨Ðà» ¹ºÇ¡ËÃ×Íà» ¹Åº¢Öé¹ÍÂÙ ¡ÑºÊ¶Ò¹Ð¢Í§¢Ò¾Íà µ¡ ͹¡ÃзíÒ¤íÒÊÑè§ PULSOUT

¡Ò÷´Åͧ Í·Õè 20 ¡ÒáíÒà¹Ô´ÊÑ­­Ò³¾ÑÅÊ ´Ç ¤íÒÊѧè PULSOUT (1) 㪠ǧ¨ÃÃÙ»·Õè 3-16 㹡Ò÷´Åͧ áÅ Çà¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2P24-20.BSP : PULSOUT command demonstrate to pulse generator***** ' {$STAMP BS2p} LOW 0 ' P0 = 0 (LED ´Ñº) AGAIN: PAUSE 1000 ' ˹ ǧàÇÅÒ 1 ÇÔ¹Ò·Õ PULSOUT 0,20000 ' ¢Ñº LED ¡Ð¾ÃÔº´ ǾÑÅÊ ¡Ç Ò§ 23.6 ÁÔÅÅÔÇ¹Ô Ò·Õ GOTO AGAIN ' ǹ·íÒ«éÒí

(2) Ãѹâ»Ãá¡ÃÁ Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED

i-Stamp2P24

P4

510

LED

ÃÙ»·Õè 3-17 ǧ¨Ã·´Åͧ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè PULSOUT "

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


PUT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè PUT

location, value

à» ¹¤íÒÊѧè ÊíÒËÃѺ¹íÒ¢ ÍÁÙÅã¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õäè »à¡çºäÇ ã¹Ë¹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´áÃÁ ¾ÒÃÒÁÔàµÍà location à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õáè Ê´§µíÒá˹ §¢Í§Ë¹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´áÃÁÀÒÂã¹ i-Stamp2p24 ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 126 value à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè·Õèµ Í§¡ÒÃà¡çºäÇ ã¹Ë¹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´áÃÁ ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊÑ觹Õé¨ÐàÃÕ¡㪠àÁ×è͵ ͧ¡ÒÃà¡çº¤ Ò¢ ÍÁÙÅËÃ×͵ÑÇá»ÃäÇ ã¹Ë¹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´áÃÁ ã¹¡Ã³Õ ·Õè˹ ǤÇÒÁ¨íÒáÃÁ»¡µÔäÁ à¾Õ§¾Í ËÃ×Í㪠㹡óշÕèµ Í§¡ÒÃÃÑ¡ÉÒ¢ ÍÁÙŢͧµÑÇá»ÃäÇ ¡ ͹·Õè¨Ð¡ÃÐâ´´ä» ·íÒ§Ò¹·Õâè »Ãá¡ÃÁÍ×¹è à¹×Íè §¨Ò¡ i-Stamp2p24 ÊÒÁÒö·íÒ§Ò¹¡Ñºâ»Ãá¡ÃÁä´ ÁÒ¡¶Ö§ 8 â»Ãá¡ÃÁ 㹡ÒáÃÐâ´´ ä»·íÒ§Ò¹Âѧâ»Ãá¡ÃÁÍ×è¹æ ÁÕ¤ÇÒÁ¨íÒà» ¹µ ͧÃÑ¡ÉÒ¢ ÍÁÙŢͧµÑÇá»Ãà´ÔÁ¡ ͹·Õè¨ÐàÃÔèÁ·íÒ§Ò¹â»Ãá¡ÃÁãËÁ â´Â¤íÒÊÑ§è ¹Õ¨é СÃзíҡѺ¢ ÍÁÙÅã¹ÃдѺ亵 à· Ò¹Ñ¹é ¤íÒÊѧè ÁÕÅ¡Ñ É³Ð¤Å Ò¡Ѻ¤íÒÊѧè PUSH ã¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà àºÍà ͹×è æ ¡ÒÃàÃÕ¡ËÃ×ÍÍ Ò¹¢ ÍÁÙÅÍÍ¡¨Ò¡Ë¹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´áÃÁµ ͧ㪠¤Òí Êѧè GET «Ö§è ¨Ðä´ ¡Å ÒÇ ¶Ö§µ Íä» ¨íҹǹáÍ´à´Ãʢͧ˹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´·ÕÊè ÒÁÒö㪠¤Òí Êѧè PUT à¾×Íè à¡çº¤ ҹѹé ÁÕ·§Ñé ÊÔ¹é 127 µíÒá˹ § µÑ§é áµ 0 ¶Ö§ 126 áµ ¶Ò à» ¹¡ÒÃÍ Ò¹¤ ÒÍÍ¡ÁÒ´ ǤíÒÊѧè GET ¨ÐÊÒÁÒö·íÒä´ ·§Ñé 128 µíÒá˹ §ËÃ×Í 128 亵 à¹×Íè §¨Ò¡ã¹äºµ Ê´Ø · ÒÂà» ¹µíÒá˹ §ÊíÒËÃѺà¡çºàÅ¢ËÁÒÂâ»Ãá¡ÃÁ «Ö§è 㪠㹡ÒõÃǨÊÍºÇ Ò¢³Ð¹Õé àºÊÔ¡áʵÁ» 2P ·íÒ§Ò¹ÍÂÙ· âÕè »Ãá¡ÃÁã´ÃÐËÇ Ò§â»Ãá¡ÃÁ 0 ¶Ö§ 7

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"


PWM ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè PWM pin, duty, cycles

㪠ÊíÒËÃѺà»ÅÕè¹¢ ÍÁÙÅ´Ô¨ÔµÍÅà» ¹¤ ÒÊÑ­­Ò³ÍйÒÅÍ¡¼ Ò¹¡ÒÃÁÍ´ÙàŪÑè¹·Ò§¤ÇÒÁ¡Ç Ò§¢Í§¾ÑÅÊ ËÃ×Í PWM (Pulse-width Modulation) ¾ÒÃÒÁÔàµÍà pin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò µÑ§é áµ 0 ¶Ö§ 15 㪠àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2p24 ·Õãè ª §Ò¹ â´Â ¡íÒ˹´ãË à» ¹¢ÒàÍÒµ ¾Øµ¡ ͹·Õè¨ÐÊà ҧ¾ÑÅÊ áÅÐà»ÅÕè¹໠¹¢ÒÍÔ¹¾ØµàÁ×èÍ¡ÃзíÒ¤íÒÊÑè§áÅ Ç duty à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 255 㪠¡Òí ˹´ÃдѺÊÑ­­Ò³ PWM ¤ÇÒÁÅÐàÍÕ´ 8 ºÔµ cycles à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò µÑ§é áµ 0 ¶Ö§ 255 㪠¡Òí ˹´¤ Ò¤ÒºàÇÅÒâ´Â»ÃÐÁÒ³¢Í§ÊÑ­­Ò³ PWM ˹ ÇÂà» ¹ 0.652 ÁÔÅÅÔÇ¹Ô Ò·Õ ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ËÅÑ¡¡Òç ÒÂæ 㹡ÒÃÊà ҧÊÑ­­Ò³¾ÑÅÊ ÇÔ´¸ ÁÍ´ÙàÅàµÍà ËÃ×Í PWM ÊíÒËÃѺ i-Stamp2p24 ¤×Í ¶ ÒÊ §Åͨԡ 1 ä»·Õ¢è Ò¾Íà µ¨ÐÁÕáç´Ñ¹à· ҡѺ 5V ¶ ÒÊ §Åͨԡ 0 ÍÍ¡ä»·Õ¢è Ò¾Íà µ¹Ñ¹é ¨ÐÁÕáç´Ñ¹à» ¹ 0V ¶ ÒÊ §ÊÑ­­Ò³ÍÍ¡ä»à» ¹¾ÑÅÊ â´Â·Õè¤ÇÒÁ¡Ç Ò§ÊÑ­­Ò³ã¹ª ǧºÇ¡áÅÐźÁÕ¤ Ò෠ҡѹ áç´Ñ¹à©ÅÕè·Õèä´ ¨Ð෠ҡѺ 2.5V ´Ñ§¹Ñ¹é ¼Ùã ª §Ò¹ÊÒÁÒö¡íÒ˹´¤ Òáç´Ñ¹à©ÅÕÂè ·Õàè ¡Ô´¢Ö¹é ·Õàè ÍÒµ ¾µØ ä´ â´Â¡ÒáíÒ˹´¤ÇÒÁ¡Ç Ò§¢Í§ ¾ÑÅÊ ªÇ §ºÇ¡ ¶ Ò¤ÇÒÁ¡Ç Ò§¢Í§¾ÑÅÊ ªÇ §ºÇ¡ÁÒ¡¤ Òáç´Ñ¹¡ç¨ÐÁÕ¤Ò ÁÒ¡µÒÁ ¡ÒÃà»ÅÕÂè ¹¤ Ò¤ÇÒÁ¡Ç Ò§¢Í§¾ÑÅÊ ¡¤ç Í× ¡ÒÃà»ÅÕÂè ¹¤ Ò´ÔǵÕäé «à¡ÔŹѹè àͧ ÊíÒËÃѺ i-Stamp2p24 ¤ Ò´ÔǵÕäé «à¡ÔÅ ÊÒÁÒöàÅ×Í¡ä´ µ§Ñé áµ 0 ¶Ö§ 255 ¼Ùã ª §Ò¹ÊÒÁÒöËÒ¤ Òáç´Ñ¹·Õàè ¡Ô´¢Ö¹é ä´ ¨Ò¡¡ÒáíÒ˹´¤ Ò´ÔǵÕäé «à¡ÔÅä´ ¨Ò¡Êٵà Vout = (duty/255) : 5V µÑÇÍ ҧ ¶ Ò¤ Ò duty ෠ҡѺ 100 áç´Ñ¹àÍÒµ ¾Øµ Vout = (100/255) : 5V = 1.96V ÊíÒËÃѺ ¡ÒÃá»Å§¤ ÒÊÑ­­Ò³ PWM ä»à» ¹ÊÑ­­Ò³ÍйÒÅÍ¡ ¨Ðµ ͧ¹íÒÊÑ­­Ò³ PWM ࢠÒä»Âѧǧ¨Ã¡Ãͧ¤ÇÒÁ¶Õè µèÒí ¼ Ò¹ à¾×Íè ãË ä´ à©¾ÒФ Òáç´Ñ¹à©ÅÕÂè ã¹Ç§¨ÃÍÍ¡ÁÒ෠ҹѹé â´ÂäÁ Á¤Õ Ò ¤ÇÒÁ¶ÕÊè §Ù ·Õàè ¡Ô´¨Ò¡Ç§¨Ã PWM ÃÇÁ ÍÂÙÍ ¡Õ µÑÇÍ ҧǧ¨Ã¡Ãͧ¤ÇÒÁ¶Õµè Òèí ¼ Ò¹áÊ´§ã¹ÃÙ»·Õè 3-18

¢Ò¾Íà µ¢Í§ i-Stamp2P24

1k 0.1/50V

1k

áç´Ñ¹ 0 ¶Ö§ 5V

0.1/50V

ÃÙ»·Õè 3-18 ǧ¨Ã¡Ãͧ¤ÇÒÁ¶Õµè Òèí ¼ Ò¹ÊíÒËÃѺŴÊÑ­­Ò³¤ÇÒÁ¶ÕÊè §Ù ·ÕÃè ÇÁÍÂÙã ¹ÊÑ­­Ò³ PWM

"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


RANDOM ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè RANDOM variable

à» ¹¤íÒÊÑ觨íÒÅͧ¡ÒÃÊØ ÁµÑÇàÅ¢ ¾ÒÃÒÁÔàµÍà variable à» ¹µÑÇá»ÃÊíÒËÃѺ¡íÒ˹´¨íҹǹÊÙ§ÊØ´¢Í§¡ÒÃÊØ ÁµÑÇàÅ¢ µ ͧ¡íÒ˹´ãË à» ¹¢ ÍÁÙÅẺ亵 (byte) ËÃ×ÍẺàÇÔô (word) ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊѧè RANDOM ¨Ð·íÒ¡ÒèíÒÅͧ¡ÒÃÊØÁ µÑÇàÅ¢ ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 65,535 ÊÒà˵طàÕè » ¹¡ÒèíÒÅͧ à¹×Íè §¨Ò¡µÑÇàÅ¢·ÕÊè à ҧ¢Ö¹é ä´ ÁÒ¨Ò¡¡ÒáÃзíÒ·Ò§Åͨԡ «Ö§è ¨ÐãË ¼ÅÅѾ¸ àËÁ×͹¡Ñ¹·Ø¡¤Ãѧé ÊíÒËÃѺÍÔ¹¾Øµ¤ Òæ ˹֧è

¡Ò÷´Åͧ Í·Õè 21 ¡ÒÃ㪠§Ò¹¤íÒÊѧè RANDOM (1) 㪠ǧ¨Ãã¹ÃÙ»·Õè 3-19 㹡Ò÷´Åͧ +5V

10k P7

i-Stamp2P24

S1

ÃÙ»·Õè 3-19 ǧ¨Ã·´Åͧ¡ÒÃ㪠§Ò¹¤íÒÊѧè RANDOM

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"!


(2) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2P24-21.BSP : RANDOM command demonstrate to Head or Tail game***** ' {$STAMP BS2p} ' {$PBASIC 2.5} FLIP VAR Word ' ¡íÒ˹´µÑÇá»Ãà¡çº¤ ÒµÑÇàÅ¢·Õäè ´ ¨Ò¡¡ÒÃÊØÁ ¢Í§¤íÒÊѧè RANDOM COIN VAR FLIP.BIT0 ' ¡íÒ˹´µÑÇá»ÃÃдѺºÔµÊíÒËÃѺà¡çº¤ Ò¨ Ò¡¡ÒÃÊØÁ ¢Í§¤íÒÊѧè RANDOM TRIALS VAR Byte ' ¡íÒ˹´µÑÇá»Ãà¡çº¤ Ò¨íҹǹ¢Í§¡ÒÃÊØÁ HEADS VAR Byte ' ¡íÒ˹´µÑÇá»Ãà¡çº¤ Ңͧ¡ÒÃÍÍ¡ËÑÇ TAILS VAR Byte ' ¡íÒ˹´µÑÇá»Ãà¡çº¤ Ңͧ¡ÒÃÍÍ¡¡ Í BTN VAR Byte ' ¡íÒ˹´µÑÇá»Ãà¡çº¤ ÒʶҹТͧÊÇÔµª ·ãÕè ª ¡ºÑ ¤íÒÊѧè BUTTON START: DEBUG CLS,"Press button to start" ' áÊ´§¢ ͤÇÒÁᨠ§ãË àÃÔÁè ¡Ò÷íÒ§Ò¹·ÕËè ¹ Òµ Ò§ Debug Terminal FOR TRIALS = 1 TO 100 ' ¡íÒ˹´¡ÒÃàÊÕÂè §·Ò 100 ¤Ãѧé HOLD: RANDOM FLIP ' ÊØÁ ¤ ÒµÑÇàÅ¢ BUTTON 7,0,250,100,BTN,0,HOLD ' µÃǨÊͺʶҹСÒá´ÊÇÔµª BRANCH COIN,[HEAD,TAIL] ' µÃǨÊͺ¼Å¡ÒÃàÊÕÂè §·Ò ' ËÒ¡à» ¹ 0 ¤×ÍÍÍ¡ËÑÇãË ¡ÃÐâ´´ä»·íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í Head ' ËÒ¡à» ¹ 1 ¤×ÍÍÍ¡¡ ÍÂãË ¡ÃÐâ´´ä»·íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í Tail HEAD: DEBUG CR,"HEADS" ' áÊ´§¢ ͤÇÒÁ HEAD ·ÕËè ¹ Òµ Ò§ Debug Terminal HEADS = HEADS+1 ' à¾ÔÁè ¨íҹǹ¤ÃÑ§è ¢Í§¡ÒÃÍÍ¡ËÑÇ GOTO THE_NEXT ' ¡ÅѺä»ÊØÁ ¤ Òã¹ÃͺãËÁ TAIL: DEBUG CR,"TAILS" ' áÊ´§¢ ͤÇÒÁ TAILS ·ÕËè ¹ Òµ Ò§ Debug Terminal TAILS = TAILS+1 ' à¾ÔÁè ¨íҹǹ¤ÃÑ§è ¢Í§¡ÒÃÍÍ¡¡ Í THE_NEXT: ' ¡ÅѺä»ÊØÁ ¤ Òã¹ÃͺãËÁ NEXT ' àÁ×Íè ¡ÒÃÊØÁ ¤ ÒàÊÃç¨ÊÔ¹é áÊ´§¨íҹǹ¤ÃÑ§é ¢Í§¡ÒÃÍÍ¡ËÑÇáÅС Í DEBUG CR,CR,"Heads: ",DEC HEADS," Tails: ",DEC TAILS

â»Ãá¡ÃÁ¹Õ¨é зíÒ¡ÒÃÊØÁ µÑÇàÅ¢àÁ×Íè ÁÕ¡Òá´»ØÁ àËÁ×͹¡Ñº¡ÒÃâ¹àËÃÕ­ (ËÑÇËÃ×Í¡ ÍÂ) àÁ×Íè ¡´»ØÁ ¶Ö§ 100 ¤Ãѧé â»Ãá¡ÃÁ¨ÐáÊ´§¨íҹǹ¢Í§¡Òà ÍÍ¡ËÑÇ (HEADS) áÅÐ ÍÍ¡¡ Í (TAILS) ÍÍ¡ÁÒ (3) Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¢ ͤÇÒÁ Press button to start (4) ¡´ÊÇÔµª 100 ¤Ãѧé áÅ ÇÊѧࡵ¡ÒÃáÊ´§¼Å¢Í§Ë¹ Òµ Ò§ Debug Terminal

""

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


RCTIME ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè RCTIME pin, state, resultVariable

à» ¹¤íÒÊÑè§ÊíÒËÃѺ¹Ñº¤ ҢͧàÇÅÒ·Õè¢Ò¾Íà µÂѧ¤§Ê¶Ò¹Ðà´ÔÁÍÂ٠㪠㹡ÒÃÇÑ´¤ Ò¡ÒÃà¡çº»ÃШØáÅÐ ¤Ò»ÃШآͧµÑÇà¡çº»ÃШØáÅеÑǵ Ò¹·Ò¹ã¹Ç§¨Ã RC ¾ÒÃÒÁÔàµÍà pin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 15 ÊíÒËÃѺ¡íÒ˹´¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õãè ª §Ò¹ â´Â¢Ò¾Íà µ¹Ñ¹é ¨Ð¶Ù¡¡íÒ˹´ãË à» ¹ÍÔ¹¾Øµ ËÅѧ¨Ò¡¡ÃзíÒ¤íÒÊѧè áÅ Ç ¢Ò¾Íà µ·Õãè ª §Ò¹¡ç处 ¤§à» ¹ÍÔ¹¾Øµàª ¹à´ÔÁ state à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò à· Ò¡Ñº 1 ËÃ×Í 0 à¾×Íè ¡íÒ˹´ÊÀÒÇТͧ¢ÒàÁ×Íè ¡ÃзíÒ¤íÒÊѧè RCTIME resultVariable à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò à· Ò¡Ñº 0 ¶Ö§ 65,535 ÊíÒËÃѺà¡çº¤ Ò¤ÒºàÇÅÒÁÕ¤Ò Ë¹ Ç ÅÐ 0.75 äÁâ¤ÃÇÔ¹Ò·Õ (ÊíÒËÃѺ i-Stamp2P24) ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊѧè RCTIME ÊÒÁÒöÇÑ´ª ǧàÇÅҢͧ¡ÒûÃШØáÅФÒ»ÃШآͧǧ¨Ã RC (ǧ¨Ã·Õ»è ÃСͺ仴 Ç µÑǵ Ò¹·Ò¹áÅеÑÇà¡çº»ÃШص Í͹ءÃÁ¡Ñ¹) «Öè§àËÁÒÐÊíÒËÃѺ¹íÒä»ãª 㹡ÒõÃǨÊͺ¡ÒÃà»ÅÕè¹á»Å§¢Í§µÑÇ µÃǨ¨Ñº·ÕÁè ¡Õ Ò÷íÒ§Ò¹ã¹ÅѡɳÐà»ÅÕÂè ¹á»Å§¤ Ò¤ÇÒÁµ Ò¹·Ò¹ ÍÒ·Ô à·Íà ÁÊÔ àµÍà µÑǵ Ò¹·Ò¹á»Ã¤ ÒµÒÁáʧ ËÃ×ÍÍ Ò¹¤ Ò¤ÇÒÁµ Ò¹·Ò¹¢Í§µÑǵ Ò¹·Ò¹»ÃѺ¤ Òä´ ¤íÒÊѧè RCTIME ÊÒÁÒö㪠¡ºÑ ¤ ÒàÇÅҢͧǧ¨Ã RC ä´ Ê§Ù ÊØ´ 0.049151 ÇÔ¹Ò·Õ (49.151 ÁÔÅÅÔÇ¹Ô Ò·Õ) àÁ×èÍ¡ÃзíÒ¤íÒÊÑè§ RCTIME ¨ÐÁÕ¡ÒÃà¾ÔèÁ¤ ÒµÑǹѺ¢Öé¹ã¹·Ø¡æ 0.75 äÁâ¤ÃÇÔ¹Ò·Õ áÅШÐËÂØ´¹ÑºàÁ×èÍ ¢Ò¾Íà µ·Õãè ª §Ò¹ÁÕʶҹÐᵡµ ҧ仨ҡ·Õ¡è Òí ˹´â´ÂµÑÇá»Ã state 㹡óշ¶Õè Ò ¢Ò¾Íà µ·Õãè ª §Ò¹äÁ ÍÂÙ㠹ʶҹзաè Òí ˹´ àÁ×Íè àÃÔÁè ¡ÃзíÒ¤íÒÊѧè RCTIME ¨Ðä´ ¼ÅÅѾ¸ ¢Í§ ¡ÒùѺ໠¹ 1 à¡çºäÇ ã¹ä»Âѧ resultVariable ¶ ҹѺ¤ Òä´ ÁÒ¡¡Ç Ò 65,535 ¹Ñ¹è ¤×ͤ ÒàÇÅÒÁÒ¡¡Ç Ò 0.049151 ÇÔ¹Ò·Õ ¨Ðä´ ¼ÅÅѾ¸ à» ¹ 0 à¡çºäÇ ã¹ resultVariable ǧ¨Ãã¹ÃÙ»·Õè 3-20 à» ¹Ç§¨ÃÊíÒËÃѺ㪠¡ºÑ ¤íÒÊѧè RCTIME +5V

+5V 0.1PF

220

VR1

(¡)

VR1

µ Íä»Âѧ¢Ò¾Íà µ¢Í§ i-Stamp2P24

0.1PF

µ Íä»Âѧ¢Ò¾Íà µ¢Í§ i-Stamp2P24

(¢)

ÃÙ»·Õè 3-20 ǧ¨Ã RC ¾×¹é °Ò¹ÊíÒËÃѺÈÖ¡ÉÒ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè RCTIME Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"#


i-Stamp2P24 ¨Ð·íÒ¡ÒÃà»ÅÕÂè ¹á»Å§ÅͨԡàÁ×Íè áç´Ñ¹·Õ¢è Ò¾Íà µ«Ö§è 㪠§Ò¹¹Ñ¹é ÁÕáç´Ñ¹ÊÙ§ËÃ×͵èÒí ¡Ç Ò 1.5V ¨Ò¡Ç§¨Ãã¹ÃÙ»·Õè 3-20 (¡) ¡ ͹·Õ¨è СÃзíÒ¤íÒÊѧè RCTIME ¨Ðµ ͧ·íÒ¡ÒäÒ»ÃШØáç´Ñ¹ÀÒÂã¹µÑÇà¡çº»ÃШØãË ËÁ´àÊÕ¡ ͹ ·íÒãË àÁ×Íè àÃÔÁè µ ¹·íÒ§Ò¹·Õ¢è Ò¾Íà µ¢Í§ i-Stamp2P24 ¨ÐÁÕ¤Ò áç´Ñ¹ 5V àÁ×Íè àÃÔÁè ¡ÃзíÒ¤íÒÊѧè RCTIME áç´Ñ¹·Õ¢è Ò¾Íà µ¨Ð¤ ÍÂæ Ŵŧ à¹×Íè §¨Ò¡µÑÇà¡çº»ÃШØä´ ÃºÑ ¡ÒûÃШØáç´Ñ¹à¾ÔÁè ¢Ö¹é ¢³Ðà´ÕÂǡѹ i-Stamp2P24 ¡ç·Òí ¡ÒùѺ¤ ÒµÒÁ·Õ¡è Òí ˹´â´Â¤íÒÊѧè RCTIME ¨¹¡Ãзѧè áç´Ñ¹·Õ¢è Ò¾Íà µµèÒí ¡Ç Ò 1.5V ¨Ö§ËÂØ´¡ÒáÃзíÒ¤íÒÊѧè RCTIME ¤ Ò·Õºè ÃèØÍÂÙã ¹µÑÇá»Ã ResultVariable ¨Ðà» ¹¼ÅÅѾ¸ ¢Í§¡ÒáÃзíÒ¤íÒÊѧè RCTIME ¹Õé «Ö§è ¤ Ò·Õäè ´ ¨Ð ᵡµ Ò§¡Ñ¹ä»µÒÁ¤ ҢͧµÑǵ Ò¹·Ò¹áÅеÑÇà¡çº»ÃШطãÕè ª ã¹Ç§¨Ã àÁ×Íè 㪠§Ò¹¤íÒÊѧè RCTIME ¡ÑºÇ§¨Ãã¹ÃÙ»·Õè 3-20 (¡) ¨Ðä´ ÃÒÂÅÐàÍÕ´¢Í§¡ÒÃÃѺ¤ ÒÁÒ¡¡Ç Ò㪠¡ºÑ ǧ¨Ã ã¹ÃÙ»·Õè 3-20 (¢) à¹×Íè §¨Ò¡ª ǧ¢Í§áç´Ñ¹·Õàè ¡Ô´¢Ö¹é ¢Í§Ç§¨Ãã¹ÃÙ»·Õè 3-20 (¡) ¡Ç Ò§¡Ç Ò¤×Í 3.5V (ÁÒ¨Ò¡ 5-1.5V) ã¹¢³Ð·ÕÇè §¨Ãã¹ÃÙ»·Õè 3-20 (¢) ¨ÐÁÕªÇ §¢Í§áç´Ñ¹à¾Õ§ 1.5V ෠ҹѹé â»Ãá¡ÃÁµÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè RESULT VAR WORD HIGH 8 PAUSE 1 RCTIME 8,1,RESULT DEBUG ? RESULT

RCTIME

Í ҧ§ ÒÂÁÕ´§Ñ ¹Õé

' ¡íÒ˹´µÑÇá»Ãà¡çº¤ Ò¼ÅÅѾ¸ ' ¤Ò»ÃШآͧµÑÇà¡çº»ÃÐ¨Ø 1 ÁÔÅÅÔÇ¹Ô Ò·Õ ' ¡ÃзíÒ¤íÒÊѧè RCTIME ' áÊ´§¼ÅÅѾ¸ ·ËÕè ¹ Òµ Ò§ Debug Terminal

¼Å¢Í§¡ÒáÃзíÒ¤íÒÊÑè§ RCTIME ¨Ð¢Öé¹ÍÂÙ ¡Ñº¡ÒáíÒ˹´¤ ÒµÑǵ Ò¹·Ò¹áÅеÑÇà¡çº»ÃÐ¨Ø â´Â㪠¤ÇÒÁÊÑÁ¾Ñ¹¸ ·àÕè ÃÕÂ¡Ç Ò ¤ Ò¤§·Õàè ÇÅҢͧǧ¨Ã RC ËÃ×Í RC Time Constant ËÃ×Í tau (W) àÁ×Íè àÇÅÒ¼ Ò¹ä» 1 W µÑÇà¡çº»ÃШØÊÒÁÒö»ÃШØËÃ×ÍËÃ×ͤÒ»ÃШØä´ à· Ò¡Ñº 63% ¢Í§áç´Ñ¹·Õ· è Òí ¡ÒûÃШØËÃ×ͤÒ»ÃÐ¨Ø â´Â¤ Ò W ÊÒÁÒö¤íÒ¹Ç³ä´ ¨Ò¡ÊÁ¡Òà W = R N C àÁ×Íè µ ͧ¡Ò÷ÃÒº¤ ÒàÇÅÒÃÇÁ¢Í§¡ÒÃà»ÅÕÂè ¹á»Å§áç´Ñ¹¨Ò¡ÃдѺ 5V à» ¹ 1.5V ÊÒÁÒö¤íҹdz ä´ ¨Ò¡Êٵà t = -RC ln(v/Vi) â´Â·Õè t ¤×Í ¤ ÒàÇÅÒ·Õãè ª 㹡ÒÃà»ÅÕÂè ¹áç´Ñ¹¨Ò¡ 5V ÁÒà» ¹ 1.5V R ¤×Í ¤ ҢͧµÑǵ Ò¹·Ò¹·Õãè ª ã¹Ç§¨Ã RC C ¤×Í ¤ ҢͧµÑÇà¡çº»ÃШطãÕè ª ã¹Ç§¨Ã RC ln ¤×Í à¤Ã×Íè §ËÁÒ·ҧ¤³ÔµÈÒʵà ·¡Õè Òí ˹´ãË ·Òí ¡Òäíҹdz¤ Ò´ ÇÂÅÍ¡ÒÃÔ¸ÁÖè °Ò¹ ¸ÃÃÁªÒµÔËÃ×ÍàÍç¡â»à¹¹àªÕÂÅ v ¤×Í ¤ Òáç´Ñ¹·Õ·è Òí ãË à¡Ô´¡ÒÃà»ÅÕÂè ¹á»Å§Åͨԡ ã¹·Õ¹è ¤Õé Í× 1.5V Vi ¤×ͤ Òáç´Ñ¹àÃÔÁè µ ¹ ¶ ÒµÑǵ Ò¹·Ò¹ÁÕ¤ Ò 10k: áÅеÑÇà¡çº»ÃШØÁÕ¤ Ò 0.1PF ¨Ò¡ÊÁ¡ÒÃÊÒÁÒö᷹¤ Òà¾×èÍËÒ¤ ÒàÇÅÒ ä´ ´Ñ§¹Õé t = -(10 N 10 3 ) N (0.1 N 10 6- ) ln(1.5/5)

"$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¤ÒºàÇÅÒ·Õäè ´ Á¤Õ Ò à· Ò¡Ñº 1.204 ÁÔÅÅÔÇ¹Ô Ò·Õ áµ à¹×Íè §¨Ò¡¤íÒÊѧè RCTIME ¨Ð¹Ñº¤ÒºàÇÅÒ·Ø¡æ 0.75 äÁâ¤ÃÇÔ¹Ò·Õ ´Ñ§¹Ñ¹é ¤ Ò·Õäè ´ ¨§Ö ÁÕ¤Ò à· Ò¡Ñº 1,605 ã¹·Ò§»¯ÔºµÑ ¤Ô Ò ¢Í§µÑǵ Ò¹·Ò¹ 10k: áÅÐ µÑÇà¡çº»ÃÐ¨Ø 0.1PF ÍÒ¨ÁÕ¤Ò ¼Ô´¾ÅÒ´ÍÂÙº Ò § ´Ñ§¹Ñ¹é ¼ÅÅѾ¸ ·äÕè ´ ¨Ò¡¡ÒáÃзíÒ¤íÒÊѧè RCTIME ¨ÐÁÕ¤Ò »ÃÐÁÒ³ 1,500 ¶Ö§ 1,650 ¢ Íá¹Ð¹íÒ·Ò§ÎÒà ´áÇà àÁ×Íè 㪠¤Òí Êѧè RCTIME ¨Ò¡Ç§¨Ãã¹ÃÙ»·Õè 3-20 (¡) ¨ÐàËç¹Ç Ò·Õ¢è Ò¾Íà µ¢Í§ i-Stamp2P24 ¨ÐÁÕµÇÑ µ Ò¹·Ò¹ 220: µ Í Í¹Ø¡ÃÁÍÂÙ µÑǵ Ò¹·Ò¹¹ÕéÁÕ¤ÇÒÁÊíҤѭÁÒ¡àÁ×è͹íÒÁÒ㪠㹡ÒáÃзíÒ¤íÒÊÑè§ RCTIME â´Â੾ÒÐÍ ҧÂÔ觶 ÒµÑǵ Ò¹·Ò¹ã¹ ǧ¨Ã RC ¹Ñ¹é à» ¹µÑǵ Ò¹·Ò¹»ÃѺ¤ Òä´ ËÒ¡µÑǵ Ò¹·Ò¹¶Ù¡»ÃѺãË Á¤Õ Ò à· Ò¡Ñº 0 «Ö§è ¡ç¤Í× µ Í¢Ò¡ÅÒ§¢Í§µÑǵ Ò¹ ·Ò¹Å§¡ÃÒÇ´ áÅ Çà¢Õ¹¤íÒÊѧè Ê §¤ Ò 1 ÍÍ¡ä»Âѧ¢Ò¾Íà µà¾×Íè ·íÒ¡ÒäÒ»ÃШصÇÑ à¡çº»ÃÐ¨Ø ¡ç¨Ðà¡Ô´¡ÒÃÅÑ´ ǧ¨ÃÃÐËÇ Ò§áç´Ñ¹ÊÙ§¡Ñº¡ÃÒÇ´ ·¢Õè Ò¾Íà µ¢Í§ i-Stamp2P24 ·íÒãË ¢Ò¾Íà µä´ ÃºÑ ¤ÇÒÁàÊÕÂËÒÂ

¡Ò÷´Åͧ Í·Õè 22 ¡ÒÃ㪠§Ò¹¤íÒÊѧè RCTIME (1) 㪠ǧ¨ÃµÒÁÃÙ»·Õè 3-21 㹡Ò÷´Åͧ (2) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2P24-22.BSP : RCTIME command demonstration***** ' {$STAMP BS2p} ' {$PBASIC 2.5} RESULT VAR Word ' ¡íÒ˹´µÑÇá»Ãà¡çº¼Å¡Ò÷íÒ§Ò¹ AGAIN: HIGH 14 ' ¤Ò»ÃШآͧµÑÇà¡çº»ÃÐ¨Ø PAUSE 1 ' ˹ ǧàÇÅÒ 1 ÁÔÅÅÔÇ¹Ô Ò·Õ RCTIME 14,1,RESULT ' ÇÑ´¤ ÒàÇÅÒ RC DEBUG CLS,DEC RESULT ' áÊ´§¤ Ò¼ÅÅѾ¸ ·ËÕè ¹ Òµ Ò§ Debug Terminal PAUSE 100 GOTO AGAIN +5V C1 0.1PF

R1 220

P14

i-Stamp2P24

LDR1

ÃÙ»·Õè 3-21 ǧ¨ÃÊíÒËÃѺ·´Åͧ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè RCTIME Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"%


(3) Ãѹâ»Ãá¡ÃÁ ãË áʧ»¡µÔµ¡¡Ãзº LDR áÅ ÇÊѧࡵ¡ÒÃáÊ´§¼Å¢Í§Ë¹ Òµ Ò§ Debug Terminal ˹ Òµ Ò§ Debug Terminal áÊ´§¤ Ò 3150 ¶Ö§ 4481

(4) 㪠ÁÍ× ºÑ§ LDR Êѧࡵ¡ÒÃáÊ´§¼Å¢Í§ Debug Terminal ˹ Òµ Ò§ Debug Terminal áÊ´§¤ Òà¾ÔÁè ¢Ö¹é ¨¹¶Ö§ 65000

"&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


READ ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè READ location, {Word} variable {, {Word} variable, {Word} variable, ... }

㪠㹡ÒÃÍ Ò¹¤ Ңͧ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁáÅÐà¡çº¤ ÒäÇ ã¹µÑÇá»Ã·Õ¡è Òí ˹´ ¾ÒÃÒÁÔàµÍà location à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 2047 à¾×Íè 㪠¡Òí ˹´µíÒá˹ §áÍ´à´ÃÊ·Õãè ª 㹡ÒÃ Í Ò¹Ë¹ ǤÇÒÁ¨íÒÍÕÍÕ¾ÃÍÁ variable à» ¹µÑÇá»ÃÊíÒËÃѺ·Õàè ¡çº¢ ÍÁÙÅ·ÕÍè Ò ¹ä´ ¨Ò¡Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 65,535 ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ à¹×Íé ·Õ¢è ͧ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁÀÒÂã¹µÑÇ i-Stamp2P24 㪠㹡ÒÃà¡çº·Ñ§é â»Ãá¡ÃÁáÅТ ÍÁÙÅ ¤íÒÊѧè READ ¨Ð㪠㹡ÒÃÍ Ò¹¢ ÍÁÙŨҡµíÒá˹ §áÍ´à´ÃÊã´¡çä´ ÀÒÂã¹Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ ¶ ÒËÒ¡¢ ÍÁÙÅËÃ×͵ÑÇá»Ã·Õãè ª à» ¹¢ ÍÁÙÅã¹ÃдѺàÇÔô ¤íÒÊѧè READ ¨Ð¨Ñ´¡ÒáѺ¢ ÍÁÙÅã¹äºµ ÅÒ §¡ ͹ áŠǨ֧µÒÁ´ ÇÂ亵 º¹

¡Ò÷´Åͧ Í·Õè 23 ¡ÒÃ㪠§Ò¹¤íÒÊѧè READ (1) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2p24-23.BSP : READ command demonstration***** ' PUT ASCII characters into EEPROM, followed by 0, ' which will serve as the END-of-message marker. ' {$STAMP BS2P} MESSAGE DATA "BS2P EEPROM Storage!",0 STR_ADR VAR Word CHAR VAR Byte STR_ADR = MESSAGE ' ¡íÒ˹´¢ ͤÇÒÁàÃÔÁè µ ¹. STR_OUT: READ STR_ADR,CHAR ' Í Ò¹¢ ÍÁÙÅ亵 ÍÍ¡¨Ò¡Ë¹Ç ¤ÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍ¾Õ ÃÍÁ IF CHAR <> 0 THEN CONT ' ¶ ÒÂÑ§Í Ò¹äÁ ËÁ´ ãË ·Òí ¡ÒÃÍ Ò¹µ Íä» STOP ' ËÂØ´¡Ò÷íÒ§Ò¹àÁ×Íè ¡ÒÃÍ Ò¹¤ ÒàÊÃç¨ÊÁºÙó CONT: DEBUG CHAR ' áÊ´§µÑÇÍÑ¡É÷ÕËè ¹ Òµ Ò§ Debug Terminal STR_ADR = STR_ADR+1 ' àÅ×Í¡µÑÇÍÑ¡ÉõÑÇ¶Ñ´ä» GOTO STR_OUT ' ¡ÃÐâ´´ä»Í Ò¹¤ ҢͧµÑÇÍÑ¡ÉõÑǶѴä»

â»Ãá¡ÃÁ¹Õ¨é ÐÍ Ò¹µÑÇÍÑ¡Éèҡ¢ ÍÁÙÅ·Õàè ¡çºã¹ÍÕÍ¾Õ ÃÍÁ ¢ ÍÁÙÅ·ÕÍè ÂÙã ¹ÍÕÍ¾Õ ÃÍÁ¨Ð¶Ù¡´Òǹ âËŴŧÊÙ i-Stamp2P24 㹪 ǧàÇÅÒ¡ÒäÍÁä¾Å â»Ãá¡ÃÁ áÅТ ÍÁÙŹÕé¨Ð¤§ÍÂÙ ¨¹¡Ç Ò¨ÐÁÕ¡ÒÃà¢Õ¹â»Ãá¡ÃÁ·Ñºä»ãËÁ ÍÕ¡¤ÃÑé§

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"'


(2) Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal áÊ´§¢ ͤÇÒÁ BS2P EEPROM Storage! ãË ä»ÂѧàÁ¹Ù RUN ࢠÒä»·Õè Memory map ¨ÐàËç¹¢ ÍÁÙŢͧ¢ ͤÇÒÁ BS2P EEPROM Storage! ºÃèØÍÂÙã ¹Ê Ç¹¢Í§Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍ¾Õ ÃÍÁ ã¹ÃÙ»¢Í§¢ ÍÁÙÅàÅ¢°Ò¹ÊԺˡ´Ñ§ã¹ÃÙ»

ËÒ¡àÅ×Í¡ Display ASCII ¨ÐàËç¹¢ ͤÇÒÁ BS2P EEPROM Storage! ºÃèØÍÂÙ㠹˹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅ ÍÕÍ¾Õ ÃÍÁã¹ÃÙ»¢Í§ÃËÑÊáÍÊ¡Õ´é §Ñ ÃÙ» «Ö§è ¨ÐàËç¹à» ¹µÑÇÍÑ¡ÉÃáµ ÅеÑÇÍ ҧªÑ´à¨¹áµ¡µ Ò§¨Ò¡ã¹ÃÙ»¡ ͹˹ Ò¹Õé

#

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


RETURN ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè RETURN

à» ¹¤íÒÊÑ§è ¡íÒ˹´ãË i-Stamp2P24 ¡ÃÐâ´´¡ÅѺ价íÒ§Ò¹Âѧâ»Ãá¡ÃÁËÅÑ¡ËÅѧ¨Ò¡·íÒ§Ò¹·Õâè »Ãá¡ÃÁ  ÍÂàÊÃç¨ÊÔ¹é ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊÑ§è ¹Õµé Í §ãª ¤Çº¤Ù¡ ºÑ ¤íÒÊѧè GOSUB à¹×Íè §¨Ò¡àÁ×Íè i-Stamp2P24 ¡ÃзíÒ¤íÒÊѧè GOSUB áÅ Ç¡ÃÐâ´´ ÁÒ·íÒ§Ò¹ÂѧáÍ´à´Ãʢͧâ»Ãá¡ÃÁ Í·աè Òí ˹´ ¨ÐäÁ ÊÒÁÒö¡ÅѺä»Âѧâ»Ãá¡ÃÁËÅÑ¡ä´ ¨¹¡Ç Ҩоº¤íÒÊѧè RETURN

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#


REVERSE ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè REVERSE pin

㪠à»ÅÕÂè ¹¡Ò÷íÒ§Ò¹¢Í§¢Ò¾Íà µ¨Ò¡ÍÔ¹¾Øµà» ¹àÍÒµ ¾µØ ËÃ×ͨҡàÍÒµ ¾µØ à» ¹ÍÔ¹¾Øµ ¾ÒÃÒÁÔàµÍà pin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 15 à¾×Íè àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊÑ觹Õéª ÇÂà¾ÔèÁ¤ÇÒÁÊдǡ㹡ÒÃà»ÅÕ蹡Ò÷íÒ§Ò¹¢Í§¢Ò¾Íà µ â´ÂäÁ µ ͧà¢Õ¹â»Ãá¡ÃÁ´ Ç ¤íÒÊѧè DIRS, INPUT ËÃ×Í OUTPUT àÁ×èÍ¡ÃзíÒ¤íÒÊÑ觹Õé ËÒ¡¢Ò¾Íà µ·Õè㪠§Ò¹à» ¹ÍÔ¹¾ØµÍÂÙ ¨Ð¶Ù¡à»ÅÕè¹ãË à» ¹¢ÒàÍÒµ ¾µØ ã¹·Ò§¡ÅѺ¡Ñ¹¶ Ò¢Ò¾Íà µ¹Ñ¹é à» ¹àÍÒµ ¾µØ ÍÂÙ¡ ¨ç Ðà»ÅÕÂè ¹à» ¹ÍÔ¹¾Øµ

¡Ò÷´Åͧ Í·Õè 24 ¡ÒÃ㪠§Ò¹¤íÒÊѧè REVERSE (1) 㪠ǧ¨ÃµÒÁÃÙ»·Õè 3-22 㹡Ò÷´Åͧ áÅ Çà¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2P24-24.BSP : REVERSE command demonstration***** ' {$STAMP BS2P} OUT0 = 1 ' ¡íÒ˹´ãË ¢Ò¾Íà µ 0 à» ¹Åͨԡ 1 à¾×Íè ¢ÑºÍØ»¡Ã³ àÍÒµ ¾µØ AGAIN: PAUSE 200 ' ˹ ǧàÇÅÒ 200 ÁÔÅÅÔÇ¹Ô Ò·Õ REVERSE 0 ' à»ÅÕÂè ¹·ÔÈ·Ò§¢Í§¢Ò¾Íà µ DEBUG "State of P0 is : ",BIN IN1,CR ' áÊ´§Ê¶Ò¹Ð¢Í§¢Ò¾Íà µ¼ Ò¹·Ò§Ë¹ Òµ Ò§ Debug Terminal GOTO AGAIN ' ǹ·íҧҹ͠ҧµ Íà¹×Íè §

(3) Ãѹâ»Ãá¡ÃÁ Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED áÅмšÒ÷íÒ§Ò¹·ÕËè ¹ Òµ Ò§ Debug Terminal ¨Ò¡¡Ò÷´Åͧ Í¹Õé ¨ÐàËç¹Ç Ò LED ·íÒ§Ò¹ã¹ÊͧÅѡɳФ×Í µÔ´áÅдѺ â´Â㹵͹àÃÔÁè µ ¹¢Ò P0 ¶Ù¡¡íÒ˹´ãË à» ¹àÍÒµ ¾ØµÊ §Åͨԡ 1 ÍÍ¡ÁÒ·Õè¢Ò¾Íà µ·íÒãË LED µÔ´ÊÇ Ò§ àÁ×èÍ¢Ò P0 ¶Ù¡à»ÅÕè¹ãË à» ¹ÍÔ¹¾Øµ LED ¡ç¨Ð´ÑºÅ§à¹×èͧ¨Ò¡äÁ ÁÕáç´Ñ¹¨ ÒÂÍÍ¡ÁÒ¨Ò¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 ¾Ã ÍÁ¡Ñ¹¹Ñé¹ â»Ãá¡ÃÁÂѧ·íÒ¡ÒÃÍ Ò¹Ê¶Ò¹Ð¢Í§¢Ò¾Íà µÁÒáÊ´§º¹Ë¹ Òµ Ò§ Debug Terminal ´ ÇÂ

i-Stamp2P24

P0

510

LED

ÃÙ»·Õè 3-22 ǧ¨Ã·´Åͧ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè REVERSE #

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


RUN ÃٻẺ¤íÒÊѧè RUN

program

à» ¹¤íÒÊѧè ãË i-Stamp2P24 ä»·íÒ§Ò¹Âѧâ»Ãá¡ÃÁ·Õ¡è Òí ˹´ ¾ÒÃÒÁÔàµÍà program à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·ÕÊè Òí ËÃѺ¡íÒ˹´µíÒá˹ §¢Í§â»Ãá¡ÃÁ·Õµè Í §¡ÒÃãË i-Stamp2P24 ·íÒ§Ò¹ ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 7 ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ à¹×Íè §¨Ò¡Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ·Õãè ª à» ¹Ë¹ ǤÇÒÁ¨íÒâ»Ãá¡ÃÁ¢Í§ i-Stamp2P24 ÁÕ¢¹Ò´ 16 ¡ÔâŠ亵 áµ àºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍà ¨ÐÊÒÁÒöµÔ´µ ͡Ѻ˹ ǤÇÒÁ¨íÒä´ äÁ à¡Ô¹ 2 ¡ÔâÅ亵 ´Ñ§¹Ñ¹é ã¹ ¡Ò÷íÒ§Ò¹¡Ñºâ»Ãá¡ÃÁ¢¹Ò´ 16 ¡ÔâÅ亵 ¨§Ö ¨íÒà» ¹µ ͧáÂÁÍÍ¡à» ¹ 8 â»Ãá¡ÃÁ¤×Í â»Ãá¡ÃÁ 0 ¶Ö§ 7 â´Â ã¹·Ø¡¤ÃÑ§é ·Õàè ºÊÔ¡áʵÁ» 2P ÍÔ¹àµÍà ¾ÃÕµàµÍà ¡ÃÐâ´´ä»·íÒ§Ò¹Âѧâ»Ãá¡ÃÁã´ ·ÕËè ¹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾ ´áÃÁµíÒá˹ § 64 ¡ç¨Ðà¡çº¤ ÒàÅ¢ËÁÒÂâ»Ãá¡ÃÁ·Õè i-Stamp2P24 ·íÒ§Ò¹ÍÂÙä »¾Ã ÍÁ¡Ñ¹´ Ç àÁ×Íè 㪠¤Òí Êѧè RUN µÑÇ i-Stamp2P24 ¨Ð·íÒ§Ò¹µÒÁ·Õàè Å¢ËÁÒÂâ»Ãá¡ÃÁ¹Ñ¹é ¡íÒ˹´áÅФ§ÍÂÙ· âÕè »Ãá¡ÃÁ ¹Ñ¹é ¨¹¡Ç Ò¨ÐÁÕ¡ÒÃà»ÅÕÂè ¹á»Å§´ ǤíÒÊѧè RUN áŠǵÒÁ´ ÇÂàÅ¢ËÁÒÂâ»Ãá¡ÃÁãËÁ ¡ÒÃ㪠¤Òí Êѧè RUN à¾×Íè à»ÅÕÂè ¹á»Å§µíÒá˹ §â»Ãá¡ÃÁ·Õè·Òí §Ò¹¢Í§ i-Stamp2P24 µ ͧÃÐÁÑ´ÃÐÇѧã¹àÃ×Íè § ¡Ò÷íÒ§Ò¹¢Í§¾Íà µ´ Ç ÍÒ·Ô ã¹â»Ãá¡ÃÁ 0 ¡íÒ˹´ãË ¢Ò P0 à» ¹àÍÒµ ¾µØ áµ ã¹â»Ãá¡ÃÁ 1 ¡íÒ˹´ãË ¢Ò P0 à» ¹ÍÔ¹¾Øµ ËÒ¡Êѧè ãË Ã¹Ñ µ Íà¹×Íè §¡Ñ¹ä» ¨Ð·íÒãË ¢Ò¾Íà µ P0 àÊÕÂËÒÂä´ àÁ×Íè à» ¹àª ¹¹Ñ¹é ¨Ö§¤ÇèѴÊÃÃ˹ Ò·Õ¢è ͧ¢Ò ¾Íà µã¹áµ ÅÐâ»Ãá¡ÃÁãË ÊÍ´¤Å ͧä»ã¹·Ò§à´ÕÂǡѹ´ Ç ·Ñ§é ¹Õàé ¾×Íè » ͧ¡Ñ¹¤ÇÒÁàÊÕÂËÒ·ÕÍè Ò¨à¡Ô´¢Ö¹é ä´ àÁ×Íè i-Stamp2P24 à»ÅÕÂè ¹¡ÒõԴµ Íä»Âѧྨµ Ò§æ ¢Í§Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ¨Ð㪠àÇÅÒ»ÃÐÁÒ³ 250 äÁâ¤ÃÇÔ¹Ò·Õ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#!


SERIN ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè SERIN rpin{\fpin},baudmode,{plabel,}{timeout,tlabel,}[inputData]

à» ¹¤íÒÊѧè ÃѺ¢ ÍÁÙÅ͹ءÃÁẺÍЫԧâ¤Ã¹ÑÊ àª ¹ ¢ ÍÁÙŨҡ¾Íà µÍ¹Ø¡ÃÁ RS-232 â´Â i-Stamp2P24 ÊÒÁÒöÃѺ¢ ÍÁÙÅ͹ءÃÁ´ ÇÂÍѵÃÒ 608 ¶Ö§ 115,200 ºÔµµ ÍÇÔ¹Ò·Õ ¾ÒÃÒÁÔàµÍà rpin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕèÁÕ¤ ÒµÑé§áµ 0 ¶Ö§ 16 à¾×èÍ¡íÒ˹´¢Ò¾Íà µÊíÒËÃѺÃѺ¢ ÍÁÙÅÍÔ¹¾ØµÍ¹Ø¡ÃÁ àÁ×Íè µ ͧ¡ÒÃÃѺ¢ ÍÁÙÅ ¢Ò¾Íà µ¹Õ¨é ж١¡íÒ˹´ãË à» ¹¢ÒÍÔ¹¾Øµ áÅФ§Ê¶Ò¹Ð¹Õäé Ç ËÅѧ¨Ò¡·Õ·è Òí ¤íÒÊѧè àÊÃç¨àÃÕºà ÍÂáÅ Ç ¶ Ò rpin ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 16 i-Stamp2P24 ¨Ð㪠¢Ò SIN 㹡ÒÃÃѺ¢ ÍÁÙÅ «Ö§è ¢Ò¹Õ»é ¡µÔ㪠㹡ÒôÒǹ âËÅ´¢ ÍÁÙŠŧº¹ i-Stamp2P24 fpin à» ¹µÑÇàÅ×Í¡à¾ÔÁè àµÔÁ â´Â¨Ðà» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õµè §Ñé áµ 0 ¶Ö§ 15 㪠àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 ÁÒà» ¹¢Ò¤Çº¤ØÁ¡ÒÃäËŢͧ¢ ÍÁÙÅ (flow control) àÁ×èÍÁÕ¡ÒáÃзíÒ¤íÒÊÑè§ ¢Ò¾Íà µ·ÕèàÅ×Í¡¨Ð·íҧҹ໠¹¢ÒàÍÒµ ¾Øµ áÅФ§Ê¶Ò¹Ð¹ÕéäÇ ËÅѧ¨Ò¡¨º¤íÒÊÑè§áÅ Ç baudmode à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õ¢è ¹Ò´ 16 ºÔµà¾×Íè ¡íÒ˹´¤Ø³ÊÁºÑµµÔ Ò §æ ¢Í§¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅẺ ͹ءÃÁ â´Â¢ ÍÁÙÅ 13 ºÔµ´ Ò¹µèÒí (ºÔµ 0 ¶Ö§ 12) 㪠ÊÒí ËÃѺ¡ÒáíÒ˹´¤ ÒÍѵÃÒàÃçÇ㹡Òö Ò·ʹ¢ ÍÁÙÅËÃ×ÍÍѵÃҺʹ ËÃ×ͺʹàõ (baud rate) ¨Ò¡Êٵà ¤ Ò¨íҹǹàµçÁ¢Í§ (2,500,000/ºÍµàõ) - 20 ºÔµ 13 㪠¡Òí ˹´¨íҹǹ¢Í§ºÔµ¢ ÍÁÙÅáÅоÒÃÔµÕé ( 0 = 8 ºÔµ äÁ Á¾Õ ÒÃÔµ,Õé 1 = 7 ºÔµáÅоÒÃÔµ¤Õé )Ù ºÔµ 14 ¤Çº¤ØÁ¢ÑÇé ¢Í§ÊÑ­­Ò³·ÕÃè ºÑ à¢ ÒÁÒ ( 0 = äÁ ¡ÅѺ¢ÑÇé , 1 = ¡ÅѺ¢ÑÇé ) ºÔµ 15 ¨ÐäÁ ¶¡Ù 㪠´Ç ¤íÒÊѧè SERIN à¾×èͤÇÒÁÊдǡ㹡ÒáíÒ˹´¤ Ò baudmode ã¹µÒÃÒ§·Õè 3-12 ä´ ·íÒ¡ÒÃÊÃØ»¤ Ò baudmode µÒÁà§×Íè ¹ä¢µ Ò§æ àÍÒäÇ àÃÕºà ÍÂáÅ Ç ¼Ùã ª §Ò¹ÊÒÁÒö¹íÒä»ãª ä´ ·¹Ñ ·Õ â´ÂäÁ µÍ §àÊÕÂàÇÅÒÁÒ¤íҹdzãËÁè plabel à» ¹µÑÇàÅ×Í¡à¾ÔèÁàµÔÁÊíÒËÃѺ¡íÒ˹´ÅÒàºÅ·Õèâ»Ãá¡ÃÁ¨Ð¡ÃÐâ´´ä»ã¹¡Ã³Õà¡Ô´¢ ͼԴ¾ÅÒ´·Õè ¡ÒõÃǨÊͺ¾ÒÃÔµÕé ¤íÒÊÑ§è ¹Õ¨é зíÒ§Ò¹àÁ×Íè ¡íÒ˹´¤ Ò baudmode ãË ãª ¨Òí ¹Ç¹¢ ÍÁÙÅ 7 ºÔµ áÅоÒÃÔµ¤Õé Ù timeout à» ¹µÑÇàÅ×Í¡à¾ÔÁè àµÔÁ à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè 0 ¶Ö§ 65535 à¾×Íè ¡íÒ˹´àÇÅÒ㹡ÒÃÃÍÃѺ¢ ÍÁÙÅ ËÅѧ¨Ò¡¡ÃзíÒ¤íÒÊѧè ÁÕ˹ ÇÂà» ¹ 0.4 ÁÔÅÅÔÇ¹Ô Ò·Õ àÁ×Íè ¶Ö§ª ǧàÇÅÒ·Õ¡è Òí ˹´áÅ Ç ÂѧäÁ Á¢Õ Í ÁÙÅࢠÒÁÒ·Ò§¢Ò¾Íà µÍÔ¹ ¾Øµ â»Ãá¡ÃÁ¨Ð¡ÃÐâ´´ä»ÂѧáÍ´à´ÃÊ·ÕÃè кØäÇ ã¹ tlabel tlabel à» ¹µÑÇàÅ×Í¡à¾ÔèÁàµÔÁÊíÒËÃѺ¡íÒ˹´µíÒá˹ §ÅÒàºÅ·Õèâ»Ãá¡ÃÁ¨Ð¡ÃÐâ´´ä»àÁ×èÍà¡Ô´ä·Á àÍÒµ ËÃ×ÍäÁ Á¡Õ ÒÃÃѺ¢ ÍÁÙÅࢠÒÁÒàÁ×Íè ¶Ö§àÇÅÒ·Õ¡è Òí ˹´â´ÂµÑÇá»Ã timeout InputData à» ¹µÑÇá»ÃÊíÒËÃѺà¡çº¢ ÍÁÙÅ·ÕÃè ºÑ à¢ ÒÁÒ

#"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡ÒáÅѺ¢ÑÇé ¢Í§ÊÑ­­Ò³ (ºÔµ 14)

ÅѡɳТͧǧ¨ÃàÍÒµ ¾µØ (ºÔµ 15 㪠¡Ã³Õ SEROUT)

¤ Ò baudmode ÊíÒËÃѺ àºÊÔ¡áʵÁ» 2P

1200/8/N 1200/8/N 1200/8/N 1200/8/N 1200/7/E 1200/7/E 1200/7/E 1200/7/E 2400/8/N 2400/8/N 2400/8/N 2400/8/N 2400/7/E 2400/7/E 2400/7/E 2400/7/E 4800/8/N 4800/8/N 4800/8/N 4800/8/N 4800/7/E 4800/7/E 4800/7/E 4800/7/E 9600/8/N 9600/8/N 9600/8/N 9600/8/N 9600/7/E 9600/7/E 9600/7/E 9600/7/E 19200/8/N 19200/8/N 19200/8/N 19200/8/N 19200/7/E 19200/7/E 19200/7/E 19200/7/E 38400/8/N 38400/8/N 38400/8/N 38400/8/N 38400/7/E 38400/7/E 38400/7/E 38400/7/E

äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé äÁ ¡ÅѺ¢ÑÇé ¡ÅѺ¢ÑÇé

¾Øª¾ÙÅ ¾Øª¾ÙÅ ¤ÍÅàÅç¡àµÍà ໠´ ¤ÍÅàÅç¡àµÍà ໠´ ¾Øª¾ÙÅ ¾Øª¾ÙÅ ¤ÍÅàÅç¡àµÍà ໠´ ¤ÍÅàÅç¡àµÍà ໠´ ¾Øª¾ÙÅ ¾Øª¾ÙÅ ¤ÍÅàÅç¡àµÍà ໠´ ¤ÍÅàÅç¡àµÍà ໠´ ¾Øª¾ÙÅ ¾Øª¾ÙÅ ¤ÍÅàÅç¡àµÍà ໠´ ¤ÍÅàÅç¡àµÍà ໠´ ¾Øª¾ÙÅ ¾Øª¾ÙÅ ¤ÍÅàÅç¡àµÍà ໠´ ¤ÍÅàÅç¡àµÍà ໠´ ¾Øª¾ÙÅ ¾Øª¾ÙÅ ¤ÍÅàÅç¡àµÍà ໠´ ¤ÍÅàÅç¡àµÍà ໠´ ¾Øª¾ÙÅ ¾Øª¾ÙÅ ¤ÍÅàÅç¡àµÍà ໠´ ¤ÍÅàÅç¡àµÍà ໠´ ¾Øª¾ÙÅ ¾Øª¾ÙÅ ¤ÍÅàÅç¡àµÍà ໠´ ¤ÍÅàÅç¡àµÍà ໠´ ¾Øª¾ÙÅ ¾Øª¾ÙÅ ¤ÍÅàÅç¡àµÍà ໠´ ¤ÍÅàÅç¡àµÍà ໠´ ¾Øª¾ÙÅ ¾Øª¾ÙÅ ¤ÍÅàÅç¡àµÍà ໠´ ¤ÍÅàÅç¡àµÍà ໠´ ¾Øª¾ÙÅ ¾Øª¾ÙÅ ¤ÍÅàÅç¡àµÍà ໠´ ¤ÍÅàÅç¡àµÍà ໠´ ¾Øª¾ÙÅ ¾Øª¾ÙÅ ¤ÍÅàÅç¡àµÍà ໠´ ¤ÍÅàÅç¡àµÍà ໠´

2063 18447 34831 51215 10255 26639 43023 59407 1021 17405 33789 50173 9213 25597 41981 58365 500 16884 33268 49652 8692 25076 41460 57844 240 16624 33008 49392 8432 24816 41200 57584 110 16494 32878 49262 8302 24686 41070 57457 45 16429 32813 49197 8237 24621 41005 57389

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

µÒÃÒ§·Õè 3-12 áÊ´§¤ Ңͧ baudmode ¢Í§¤íÒÊѧè SERIN áÅÐ SEROUT ·ÕÍè µÑ ÃҺʹµ Ò§æ â´ÂÁÕºµÔ ¢ ÍÁÙÅ෠ҡѺ 8 ºÔµáÅÐäÁ Á¡Õ ÒõÃǨÊͺ¾ÒÃÔµÕé Íѹ໠¹ÃٻẺ¢ ÍÁÙÅ·Õ¹è ÂÔ Á㪠ÁÒ¡·ÕÊè ´Ø ÊíÒËÃѺ¤ Ò baudmode ¢Í§¤íÒÊѧè SEROUT µ ͧ¾Ô¨Ò³Òª¹Ô´¢Í§Ç§¨ÃàÍÒµ ¾µØ »ÃСͺ´ ÇÂ

¾ÒÃÒÁÔàµÍà ËÅÑ¡ (ÍѵÃҺʹ/ºÔµ¢ ÍÁÙÅ/¾ÒÃÔµéÕ : ºÔµ 0-13)

##


ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ (1) ¡ÒÃàª×Íè Áµ Í·Ò§ÎÒà ´áÇà àÁ×Íè à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ¢¹Öé ÁÒ㪠§Ò¹ ¤ÍÁ¾ÔÇàµÍà ¨ÐµÔ´µ ͡Ѻ i-Stamp2P24 ¼ Ò¹·Ò§¾Íà µÍ¹Ø¡ÃÁ RS-232 «Ö§è ¨ÐàÃÕ¡ÃٻẺ¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅẺ¹ÕÇé Ò ¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅẺÍЫԧâ¤Ã¹ÑÊ «Ö§è ¤ÇÒÁËÁÒ¡ç¤Í× äÁ 㪠ʭ Ñ ­Ò³¹ÒÌ ¡Ò㹡ÒõԴµ Í¢ ÍÁÙÅ ´Ñ§¹Ñ¹é ¶ Òµ ͧ¡ÒÃÊ §ËÃ×ÍÃѺ¢ ÍÁÙÅà¾Õ§Í ҧà´ÕÂÇ ÊÒÁÒö㪠ÊÒÂÊÑ­­Ò³¡ÑºÊÒ¡ÃÒÇ´ à¾Õ§ 2 àÊ ¹à· ҹѹé Áҵðҹ RS-232 à» ¹Áҵðҹ·Ò§ä¿¿ ÒÊíÒËÃѺ¾Íà µÍ¹Ø¡ÃÁ¢Í§¤ÍÁ¾ÔÇàµÍà «Ö§è ¤ ÒÅͨԡ 1 áÅÐÅͨԡ 0 ¨ÐÁÕáç´Ñ¹äÁ ෠ҡѺÁҵðҹ·Õ·áÕ ÍÅ «Ö§è Áҵðҹ·Õ·áÕ ÍÅ¹Ñ¹é ·ÕÅè ͨԡ 1 ¨ÐÁÕáç´Ñ¹à· ҡѺ 5V Ê Ç¹Åͨԡ 0 ¨ÐÁÕáç´Ñ¹à· ҡѺ 0V ÊíÒËÃѺÁҵðҹ RS-232 ·ÕÅè ͨԡ 1 ¨ÐÁÕáç´Ñ¹ -3 ¶Ö§ -12V áÅзÕè Åͨԡ 0 ¨ÐÁÕáç´Ñ¹ +3 ¶Ö§ +12V ´Ñ§¹Ñ¹é àÁ×Íè µ ͧ¡ÒÃÍ Ò¹¤ Ҩе ͧÁÕǧ¨Ãà¾×Íè à»ÅÕÂè ¹ÃдѺáç´Ñ¹Ê ǹ¹Õ¡é Í ¹ «Ö§è ǧ¨Ãá»Å§ÃдѺÊÑ­­Ò³¹Õºé ÃèØÍÂÙã ¹ i-Stamp2P24 áŠǨ֧ÊÒÁÒö㪠§Ò¹ i-Stamp2P24 ¡Ñº¤ÍÁ¾ÔÇàµÍÃ ä´ ·§Ñé ¡Ñºà¤Ã×Íè §µÑ§é âµ ÐËÃ×Íà¤Ã×Íè §â¹ µºØ¡ i-Stamp2P24 ÊÒÁÒö㪠¢Ò¾Íà µ·Ñ§é ËÁ´ 16 ºÔµã¹¡ÒÃÃѺ¢ ÍÁÙÅ͹ءÃÁä´ à¾Õ§µ ͵Ñǵ Ò¹·Ò¹¤ Ò 22k: ͹ءÃÁࢠÒä»à¾×Íè ¨íÒ¡Ñ´¡ÃÐáÊ·Õ»è Í ¹ä»Âѧ¢Ò¾Íà µ V 12

V

ÃдѺÊÑ­­Ò³¢Í§ RS-232

8

12 8

4

ÃдѺÊÑ­­Ò³ TTL

4 0

t

0

t

-4 -8

-12

(2) ¡ÒáíÒ˹´âËÁ´¡Ò÷íÒ§Ò¹áÅФ ÒÍѵÃҺʹ㹿 §¡ ª¹Ñ baudmode 㹡ÒÃÊ×Íè ÊÒâ ÍÁÙÅẺÍЫԧâ¤Ã¹ÑÊ ÍѵÃÒàÃçÇ㹡ÒÃÃÑºÊ §¢ ÍÁÙÅ·Ñ§é µÑÇÃѺáÅеÑÇÊ §¨Ðµ ͧ෠ҡѹ ÍѵÃÒàÃçÇ㹡ÒÃÃÑºÊ §¢ ÍÁÙŹÕàé ÃÕÂ¡Ç Ò ÍѵÃҺʹ ËÃ×Í ºÍµàõ (Baudrate) ÁÕ˹ ÇÂà» ¹ ºÔµµ ÍÇÔ¹Ò·Õ (bps) ¤íÒÊѧè SERIN ¨ÐÁÕÍÍ»ªÑ¹è baudmode à¾×Íè ¡íÒ˹´ÍѵÃÒàÃçÇ㹡ÒÃÃÑºÊ §¢ ÍÁÙÅ¡íÒ˹´¨íҹǹ ºÔµ¢ ÍÁÙÅ·ÕÃè ºÑ à¢ ÒÁÒ ÁÕ¡ÒõÃǨÊͺ¾ÒÃÔµËÕé Ã×ÍäÁ áÅе ͧ¡ÒáÅѺ¢ÑÇé ¢Í§¢ ÍÁÙÅ·ÕÃè ºÑ à¢ ÒÁÒËÃ×ÍäÁ ã¹µÒÃÒ§·Õè 3-12 áÊ´§¤ Ңͧ baudmode ·ÕÍè µÑ ÃҺʹµ Ò§æ à¾×Íè ÍíҹǤÇÒÁÊдǡ㹡ÒáíÒ˹´¤ Ò â´ÂäÁ µÍ §·íÒ¡Òà ¤íҹdz ¡µÑÇÍ ҧ ÍѵÃҺʹ·Õµè Í §¡Òä×Í 2,400 ºÔµµ ÍÇÔ¹Ò·Õ¨Òí ¹Ç¹¢ ÍÁÙÅ 8 ºÔµ äÁ Á¾Õ ÒÃÔµÕé áÅÐÁÕ¡ÒáÅѺ ¢ÑÇé ¢ ÍÁÙÅ ´Ùã¹µÒÃÒ§·Õè 3-12 ¨Ð¾ºÇ Ò¤ Ңͧ baudmode ෠ҡѺ 17417 à» ¹µ ¹

#$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


(3) ¡ÒÃ㪠¤Òí Êѧè SERIN 㹡ÒÃÍ Ò¹¤ ÒÍÔ¹¾ØµÍ ҧ§ ÒÂáÅÐá»Å§¤ ÒµÑÇàÅ¢ ¡ÒÃ㪠§Ò¹¤íÒÊѧè SERIN ã¹ÃٻẺ·Õ§è Ò Â·ÕÊè ´Ø ÊÒÁÒöà¢ÕÂ¹ä´ ´§Ñ ¹Õé SERIN rpin,baudmode,[inputData] â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õàé » ¹ ¡ÒÃÃѺ¢ ÍÁÙŨҡ¢Ò P16 ·ÕÍè µÑ ÃҺʹ 9,600 ºÔµµ ÍÇÔ¹Ò·Õ ¨íҹǹ ºÔµ¢ ÍÁÙÅ 8 ºÔµ äÁ Á¾Õ ÒÃÔµÕé áÅÐÁÕ¡ÒáÅѺ¢ÑÇé ¢ ÍÁÙÅ·ÕÃè ºÑ à¢ ÒÁÒ ¨Ò¡¢ Í¡íÒ˹´ ¨Ö§·íÒãË ¤Ò baudmode «Ö§è à» ¹ ¾ÒÃÒÁÔàµÍà µÇÑ Ë¹Ö§è ·ÕÊè Òí ¤Ñ­¢Í§¤íÒÊѧè SERIN ÁÕ¤Ò à· Ò¡Ñº 16624 Ê Ç¹¢Ò P16 ¡ç¤Í× ¢Ò¾Íà µ TxD/RxD ¢Í§ i-Stamp2P24 ·Õãè ª 㹡ÒôÒǹ âËÅ´áÅÐÊ×Íè ÊÒâ ÍÁÙż Ò¹¾Íà µÍ¹Ø¡ÃÁ¢Í§¤ÍÁ¾ÔÇàµÍà ¹¹Ñè àͧ ' File : SerinExample01.bsp ' {$STAMP BS2p} ' {$PBASIC 2.5} SER_DATA VAR Byte SERIN 16,16624,[SER_DATA] DEBUG "Receive : ", SER_DATA ¤íÒÊѧè SERIN ¨Ð¤ÍÂÃѺ¢ ÍÁÙÅà¾Õ§亵 à´ÕÂǨҡ¢Ò P16 (¢Òµ ;Íà µÍ¹Ø¡ÃÁ) áÅÐà¡çº¤ Ò·ÕÍè Ò ¹ ä´ äÇ ·µÕè ÇÑ á»Ã SER_DATA ã¹¢³ÐÃѹâ»Ãá¡ÃÁ àÁ×ÍÃѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¶Ù¡à» ´¢Ö¹é ãË ¤ÅÔ¡ä»·Õè ª ͧ» ͹¢ ͤÇÒÁà¾×Íè Ê § ¨Ò¡¹Ñ¹é ¡´¤Õ a ·Õ¤è ÂÕ º Íà ´ ¤ ÒµÑÇá»Ã SER_DATA ¨ÐÁÕ¤Ò à· Ò¡Ñº 65 «Ö§è µÃ§¡ÑºÃËÑÊáÍÊ¡Õé ¢Í§µÑÇ A ¨Ò¡¹Ñ¹é ¶Ù¡¹íÒÁÒáÊ´§¼Å·ÕËè ¹ Òµ Ò§ Debug Terminal (µ ͧ¤ÅÔ¡àÅ×Í¡·Õªè Í § echo off ´ Ç à¾×Íè ¡àÅÔ¡¡Òà ·Ç¹¢ ÍÁÙÅ)

ª ͧ» ͹¢ ÍÁÙÅà¾×Íè Ê §ÍÍ¡¨Ò¡¤ÍÁ¾ÔÇàµÍÃ

¶ Òµ ͧ¡ÒÃãË ¢Í ÁÙÅ·ÕÍè ÂÙã ¹µÑÇá»Ã SER_DATA à» ¹àÅ¢°Ò¹ÊÔº ÊÒÁÒöà¢Õ¹â»Ãá¡ÃÁä´ ´§Ñ ¹Õé SER_DATA VAR BYTE SERIN 1,16624,[DEC SER_DATA]

¡ÒÃà¾ÔÁè DEC ¨Ð·íÒãË ¤Ò ·Õàè ¡çºã¹µÑÇá»Ã SER_DATA à»ÅÕÂè ¹à» ¹ 123

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#%


(4) ¡ÒÃ㪠¤Òí Êѧè SERIN ¨Ñ´¡ÒáѺ¡ÅØÁ ¢ ͤÇÒÁ ¤íÒÊѧè SERIN ÊÒÁÒö¨Ñº¢ºÇ¹¢Í§¢ ÍÁÙÅ·ÕÊè § ࢠÒÁÒ áÅ Çà¡çºäÇ ã¹µÑÇá»ÃẺÍÐàÃÂ ä´ â´Â 㪠¡ÒÃá»Å§ÃٻẺ¨Ò¡¿ §¡ ª¹Ñè STR â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õàé » ¹¡ÒÃÃѺ¢ ÍÁÙÅ 9 亵 ¨Ò¡¢Ò P16 ´ ÇÂÍѵÃҺʹ 9,600 ºÔµµ Í ÇÔ¹Ò·Õ äÁ Á¡Õ ÒõÃǨÊͺ¾ÒÃÔµÕé ¨íҹǹºÔµ¢ ÍÁÙÅ 8 ºÔµ ÁÕºµÔ » ´· Ò 1 ºÔµ ÁÕ¡ÒáÅѺ¢ÑÇé ¢Í§¢ ÍÁÙÅ áÅÐà¡çº¤ Ò ¢ ÍÁÙÅã¹µÑÇá»Ã·Õ¨è ͧäÇ 10 亵 ' File : SerinExample02.bsp ' {$STAMP BS2p} ' {$PBASIC 2.5} SER_STRING var byte(10) SER_STRING(9) = 0 SERIN 16,16624,[STR SER_STRING\9] DEBUG STR SER_STRING

' ¡íÒ˹´ÍÐàà10 亵 ' ¡íÒ˹´¤ Ò 0 ŧã¹äºµ Ê´Ø · Ò ' Í Ò¹¢ ÍÁÙŵÑÇÍÑ¡Éà 9 亵 ' áÊ´§¤ ÒµÑÇÍÑ¡ÉÃ

i-Stamp2P24 ¤ÍÂÃѺ¢ ÍÁÙÅ 9 亵 ¹íÒä»à¡çºäÇ ·µÕè ÇÑ á»ÃÍÐààSER_STRING «Ö§è ÁÕ¡Òèͧ¾×¹é ·Õäè Ç 10 亵 à¹×Íè §¨Ò¡ã¹äºµ Ê´Ø · Ò i-Stamp2P24 ÊíÒÃͧäÇ à» ¹ÊíÒËÃѺᨠ§¡ÒÃÊÔ¹é ÊØ´¢ ͤÇÒÁ (End of String) àÁ×ÍÃѹ â»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¶Ù¡à» ´¢Ö¹é ãË ¤ÅÔ¡ä»·Õªè Í §» ͹¢ ͤÇÒÁà¾×Íè Ê § ¨Ò¡¹Ñ¹é ¡´¤Õº Íà ´à¾×Íè » ͹µÑÇ ÍÑ¡ÉÃࢠÒÁÒ â´ÂàÁ×Íè ¤Õ¤ ú 9 µÑÇ µÑÇÍÑ¡É÷ѧé ËÁ´¨Ð¶Ù¡¹íÒÁÒáÊ´§·ÕËè ¹ Òµ Ò§ Debug Terminal (µ ͧ¤ÅÔ¡àÅ×Í¡·Õè ª ͧ echo off ´ Ç à¾×Íè ¡àÅÔ¡¡Ò÷ǹ¢ ÍÁÙÅ)

ª ͧ» ͹¢ ÍÁÙÅà¾×Íè Ê §ÍÍ¡¨Ò¡¤ÍÁ¾ÔÇàµÍÃ

¿ §¡ ª¹Ñè STR ·Õãè ª ã¹â»Ãá¡ÃÁµÑÇÍ ҧ¢ Ò§µ ¹ àÁ×Íè 㪠ÃÇ Á¡Ñº \9 ¡ÒÃÍ Ò¹¤ Ңͧ¤íÒÊѧè SERIN ¨ÐÍ Ò¹¢ ÍÁÙÅࢠÒÁÒ 9 亵 àÁ×Íè ¤Ãº 9 亵 ¡¨ç ÐËÂØ´¡ÒÃÍ Ò¹¢ ÍÁÙÅ ¹Í¡¨Ò¡¹ÕÂé §Ñ ÊÒÁÒö» ͹¤ ÒࢠÒä»à¾×Íè 㪠µÃǨÊͺ¢ ÍÁÙÅ·ÕÍè Ò ¹à¢ ÒÁÒ¡ ͹·Õ¡è Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè SERIN ¨ÐÊÔ¹é ÊØ´Å§ä´ Í¡Õ ´Ñ§µÑÇÍ ҧµ Í仹Õé ' File : SerinExample03.bsp ' {$STAMP BS2p} ' {$PBASIC 2.5} SER_STRING VAR BYTE(10) SER_STRING(9) = 0 SERIN 16,16624,[STR SER_STRING\9\ * ] DEBUG STR SER_STRING

#&

' ¡íÒ˹´ÍÐàà10 亵 . ' ¡íÒ˹´¤ Ò 0 ŧã¹äºµ Ê´Ø · Ò ' ËÂØ´àÁ×Íè ¾º * ËÃ×ÍÍ Ò¹¢ ÍÁÙŤú 9 亵 or 9 bytes. ' áÊ´§¤ ÒµÑÇÍÑ¡ÉÃ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


i-Stamp2P24 ¤ÍÂÃѺ¢ ÍÁÙÅ 9 亵 ¹íÒä»à¡çºäÇ ·µÕè ÇÑ á»ÃÍÐààSER_STRING «Ö§è ÁÕ¡Òèͧ¾×¹é ·Õäè Ç 10 亵 â´Â亵 Ê´Ø · ÒÂ㪠ÊÒí ËÃѺᨠ§¡ÒÃÊÔ¹é ÊØ´¢ ͤÇÒÁ ¹Í¡¨Ò¡¹Ñ¹é ÂѧµÃǨÊ꼂 ÒÁÕ¡ÒÃÃѺÍÑ¡¢ÃÐ * ࢠÒÁÒ´ ÇÂËÃ×ÍäÁ àÁ×ÍÃѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¶Ù¡à» ´¢Ö¹é ãË ¤ÅÔ¡ä»·Õªè Í §» ͹¢ ͤÇÒÁà¾×Íè Ê § ¨Ò¡¹Ñ¹é ¡´¤Õº Íà ´à¾×Íè » ͹µÑÇÍÑ¡ÉÃࢠÒÁÒ â´ÂàÁ×èͤÕ ¤Ãº 9 µÑÇ µÑÇÍÑ¡É÷Ñé§ËÁ´¨Ð¶Ù¡¹íÒÁÒáÊ´§·Õè˹ Òµ Ò§ Debug Terminal (µ ͧ¤ÅÔ ¡àÅ×Í¡·Õªè Í § echo off ´ Ç à¾×Íè ¡àÅÔ¡¡Ò÷ǹ¢ ÍÁÙÅ) ËÃ×Ͷ ÒËÒ¡ÁÕ¡Òû ͹µÑÇ¢ÃÐ * ࢠÒÁÒ¡ ͹·Õ¨è Фú 9 µÑÇ àª ¹ hello* ¡ç¨ÐÊÔ¹é ÊØ´¡ÒÃÃѺ¢ ÍÁÙÅ áŠǹíÒ¤ Ò·ÕÃè ºÑ ä´ ÁÒáÊ´§·ÕËè ¹ Òµ Ò§ Debug Terminal «Ö§è ¨ÐáÊ´§à¾Õ§¢ ͤÇÒÁ hello à¹×Íè §¨Ò¡à¤Ã×Íè §ËÁÒ * ´ Ò¹ËÅѧ¶×ÍÇ Òà» ¹µÑǺ͡ãË Ê¹Ôé ÊØ´¢ ͤÇÒÁ

ª ͧ» ͹¢ ÍÁÙÅà¾×Íè Ê §ÍÍ¡¨Ò¡¤ÍÁ¾ÔÇàµÍÃ

¤íÒÊѧè SERIN ÊÒÁÒö㪠à»ÃÕºà·Õº¢ ÍÁÙÅ·ÕÃè ºÑ à¢ ÒÁҡѺ¢ ÍÁÙÅ·Õ¡è Òí ˹´äÇ ä´ ´Ñ§µÑÇÍ ҧµ Í仹Õé ' File : SerinExample04.bsp ' {$STAMP BS2p} ' {$PBASIC 2.5} SER_DATA VAR Byte SERIN 16,16624,[WAIT ( INEX )] DEBUG Password accepted

' ÃͤÍ¢ ͤÇÒÁ INEX

i-Stamp2P24 ¨Ð¤ÍÂÃѺ¢ ͤÇÒÁ áÅШÐäÁ ·Òí §Ò¹ã¹¤íÒÊÑ§è ¶Ñ´ä»¨¹¡Ç Ò¨Ðä´ ÃºÑ ¢ ͤÇÒÁ·Õµè ç ¡Ñº¤ Ò·Õ¡è Òí ˹´ â´ÂµÑÇÍÑ¡ÉÃã¹¢ ͤÇÒÁ¨Ðµ ͧàËÁ×͹¡Ñ¹·Ñ§é µÑǾÔÁ¾ ãË­ áÅеÑǾÔÁ¾ àÅç¡ àª ¹ INEX ¨Ðà» ¹¤¹ÅТ Í ¤ÇÒÁ¡Ñº InEX áÅÐ ineX àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¶Ù¡à» ´¢Ö¹é ãË ¤ÅÔ¡ä»·Õªè Í §» ͹¢ ͤÇÒÁà¾×Íè Ê § ¨Ò¡¹Ñ¹é ¡´¤Õº Íà ´à¾×Íè » ͹µÑÇÍÑ¡ÉÃࢠÒÁÒ ¶ ÒËÒ¡¢ ͤÇÒÁà» ¹ INEX â»Ãá¡ÃÁ¨ÐµÍºÊ¹Í§´ Ç¡ÒÃáÊ´§¢ ͤÇÒÁ Password accepted ·ÕËè ¹ Òµ Ò§ Debug Terminal (µ ͧ¤ÅÔ¡àÅ×Í¡·Õªè Í § echo off ´ Ç à¾×Íè ¡àÅÔ¡¡Ò÷ǹ¢ ÍÁÙÅ)

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#'


¿ §¡ ª¹Ñ WAITSTR ·íÒ˹ Ò·Õàè »ÃÕºà·Õº¢ ÍÁÙÅ·ÕÍè ÂÙã ¹µÑÇá»Ã¡Ñº¢ ÍÁÙÅ·ÕÍè Ò ¹à¢ ÒÁÒ ¶ ÒÁÕ¤Ò µÃ§¡Ñ¹¨Ö§ä»·íҧҹ㹤íÒÊÑ§è ¶Ñ´ä» ´Ñ§â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' File : SerinExample05.bsp ' {$STAMP BS2p} ' {$PBASIC 2.5} SER_STRING VAR BYTE(10) SER_STRING(9) = 0 DEBUG Enter password ending in ! ,CR SERIN 1,16624,[STR SER_STRING \9\ ! ] DEBUG Waiting for: ,STR SER_STRING,CR SERIN 1,16624,[WAITSTR SER_STRING] DEBUG Password accepted. ,CR

' ¡íÒ˹´ÍÐàà10 亵 . ' ¡íÒ˹´¤ Ò 0 ŧã¹äºµ Ê´Ø · Ò ' ᨠ§ãË ¼ãÙ ª §Ò¹» ͹¢ ÍÁÙÅ ' Í Ò¹¢ ÍÁÙŵÑÇÍÑ¡Éà ' ᨠ§ãË ¼ãÙ ª §Ò¹ÃÍ¡ÒõÃǨÊͺ ' ·íÒ¡ÒÃÃѺáÅеÃǨÊͺ¢ ÍÁÙÅ·Õµè ç¡Ñ¹ ' ᨠ§¼Å¡ÒõÃǨÊͺ¢ ÍÁÙÅ·Õµè ç¡Ñ¹

àÁ×Íè Ãѹâ»Ãáá¡ÃÁ ˹ Òµ Ò§ Debug Terminal »ÃÒ¡¯¢Ö¹é ¾Ã ÍÁ¡ÑºáÊ´§¢ ͤÇÒÁᨠ§ãË »Í ¹ ÃËÑʼ Ò¹ i-Stamp2P24 ¨Ð¤ÍÂÃѺ¢ ͤÇÒÁ·Õ¡è Òí ˹´à» ¹ÃËÑʼ Ò¹ 9 µÑÇÍÑ¡Éà ãË ¤ÅÔ¡ä»·Õªè Í §» ͹¢ ͤÇÒÁà¾×Íè » ͹ ¤ Ò ã¹·Õ¹è ¡Õé Òí ˹´à» ¹ 012345678 â»Ãá¡ÃÁ¨ÐµÍºÊ¹Í§´ Ç¡ÒÃáÊ´§¢ ͤÇÒÁãË »Í ¹ÃËÑÊ (µ ͧ¤ÅÔ¡àÅ×Í¡·Õªè Í § echo off ´ Ç à¾×Íè ¡àÅÔ¡¡Ò÷ǹ¢ ÍÁÙÅ)

ª ͧ» ͹¢ ÍÁÙÅ

¨Ò¡¹Ñ¹é ¡´¤Õº Íà ´à¾×Íè » ͹µÑÇÍÑ¡ÉÃࢠÒÁÒÍÕ¡¤Ãѧé à» ¹ 012345678 â»Ãá¡ÃÁ¨ÐµÍºÊ¹Í§´ Ç ¡ÒÃáÊ´§¢ ͤÇÒÁ Password accepted ·ÕËè ¹ Òµ Ò§ Debug Terminal (µ ͧ¤ÅÔ¡àÅ×Í¡·Õªè Í § echo off ´ Ç à¾×Íè ¡àÅÔ¡ ¡Ò÷ǹ¢ ÍÁÙÅ)

ª ͧ» ͹¢ ÍÁÙÅ

$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¹Õé

¹Í¡¨Ò¡¹Ñ¹é ÂѧÊÒÁÒö¡íÒ˹´¤ÇÒÁÂÒǢͧ¢ ͤÇÒÁ·Õãè ª 㹿 §¡ ª¹Ñ WAITSTR ä´ ´§Ñ µÑÇÍ ҧµ Íä» ' File : SerinExample06.bsp ' {$STAMP BS2p} ' {$PBASIC 2.5} SER_STRING VAR Byte(4) ' ¡íÒ˹´µÑÇá»ÃÍÐàà4 亵 DEBUG "Enter 4-character password",CR SERIN 16,17405,[STR SER_STRING \4] ' ÃѺµÑÇÍÑ¡Éà 4 亵 DEBUG "Waiting for: ",STR SER_STRING\4,CR SERIN 16,17405,[WAITSTR SER_STRING \4] ' Ãͤ͵ÑÇÍ¡É÷յè ç¡Ñ¹ DEBUG "Password accepted.",CR

ã¹µÑÇÍ ҧ¹Õ¡é Òí ˹´ãË ÃÍ¢ ÍÁÙÅ 4 亵 ¨Ò¡¹Ñ¹é ¨Ö§·íÒ§Ò¹µ Íä» àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¶Ù¡à» ´¢Ö¹é ãË ¤ÅÔ¡ä»·Õªè Í §» ͹µÑÇÍÑ¡Éà 4 µÑÇà¾×Íè Ê § ¨Ò¡¹Ñ¹é ¡´¤Õº Íà ´à¾×Íè » ͹µÑÇÍÑ¡ÉÃࢠÒÁÒ ¶ ÒËÒ¡ ¢ ͤÇÒÁÁÕ¢¹Ò´ 4 亵 µÃ§¡Ñ¹ â»Ãá¡ÃÁ¨ÐµÍºÊ¹Í§´ Ç¡ÒÃáÊ´§¢ ͤÇÒÁ·Õè˹ Òµ Ò§ Debug Terminal (µ ͧ¤ÅÔ ¡àÅ×Í¡·Õªè Í § echo off ´ Ç à¾×Íè ¡àÅÔ¡¡Ò÷ǹ¢ ÍÁÙÅ)

ª ͧ» ͹¢ ÍÁÙÅ

(5) ¡ÒÃÍ Ò¹¢ ÍÁÙÅÍÔ¹¾ØµËÅÒÂÃٻẺ´ ǤíÒÊѧè SERIN ¢ ÍÁÙÅÍÔ¹¾Øµ¢Í§¤íÒÊѧè SERIN 㹺ҧ¤Ãѧé ÍҨ໠¹¢ ÍÁÙÅÂÒÇæ ·Õ»è ÃСͺ仴 ÇÂÃٻẺ¢ ÍÁÙÅ ËÅÒÂÃٻẺ ¼Ùã ª §Ò¹ÊÒÁÒöáÂ¡Ê Ç¹¢Í§¢ ÍÁÙÅàËŠҹѹé ÍÍ¡ÁÒä´ àª ¹ ¢ ÍÁÙÅ͹ءÃÁ “POS:XXXX YYYY” (â´Â·Õè XXXX áÅÐ YYYY à» ¹µÑÇàÅ¢ 4 ËÅÑ¡) ¶ Òµ ͧ¡ÒÃà¾Õ§¤ ÒµÑÇàÅ¢ 4 ËÅÑ¡ YYYY à· Ò¹Ñ¹é ¨Ðµ ͧ ·íÒµÒÁ¢Ñ鹵͹´Ñ§¹Õé ' File : SerinExample07.bsp ' {$STAMP BS2p} ' {$PBASIC 2.5} Y_OFFSET VAR Word SERIN 16,16624,[WAIT ("pos: "),SKIP 4,DEC Y_OFFSET]

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$


â»Ãá¡ÃÁ¹Õ¨é ÐÃ͵ÑÇÍÑ¡Éà pos: ¨Ò¡¹Ñ¹é ¨ÐàÇ ¹ª ǧ¢ ÍÁÙÅ XXXX â´Â㪠¤Òí Êѧè SKIP 4 áÅÐàÅ×Í¡ àÍÒ੾ÒТ ÍÁÙÅ YYYY ä»ãª â´Â ¡ÒÃ㪠¤Òí Êѧè ÃٻẺ¹Õ¨é зíÒä´ ¡µç Í àÁ×Íè ¤ Ңͧ XXXX ÁÕ 4 ËÅÑ¡¾Í´Õ෠ҹѹé â´ÂàÁ×Íè Ãѹ â»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¶Ù¡à» ´¢Ö¹é ãË ¤ÅÔ¡ä»·Õªè Í §» ͹¢ ͤÇÒÁ pos: áŠǵÒÁ´ ǵÑÇÍÑ¡ÉÃËÃ×͵ÑÇàÅ¢ 8 µÑÇ áÅ Ç¡´ Enter ·ÕËè ¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¢ ͤÇÒÁ pos: áŠǵÒÁ´ ǵÑÇÍÑ¡ÉÃËÃ×͵ÑÇàÅ¢ 4 µÑÇ· ÒÂ

ª ͧ» ͹¢ ÍÁÙÅ

(6) ¡ÒÃ㪠¾ÒÃÔµáÕé ÅСÒèѴ¡ÒáѺ¡Ã³Õ¼´Ô ¾ÅÒ´·Õ¾ è ÒÃÔµ´Õé Ç Â¤íÒÊѧè SERIN ¾ÒÃÔµàÕé » ¹ÃÙ»áººË¹Ö§è ¢Í§¡ÒõÃǨÊͺ¤ÇÒÁ¼Ô´¾ÅҴ㹡ÒÃÃѺáÅÐÊ §¢ ÍÁÙÅ àÁ×Íè ¡íÒ˹´ãË Á¡Õ Òà µÃǨÊͺ¾ÒÃÔµáÕé ÅоÒÃÔµàÕé » ¹áºº¤Ù i-Stamp2P24 ¨ÐµÃǨÊͺ¨íҹǹ¢Í§ºÔµ·Õàè » ¹ 1 ¹íÒ仺ǡ¡ÑººÔµ¾ÒÃÔµÕé ¤ Ò·Õäè ´ µÍ §à» ¹àÅ¢¤Ù ¡µÑÇÍ ҧ ¢ ÍÁÙÅ %0011010 ÁÕºµÔ ·Õàè » ¹ 1 3 ºÔµ à¾×Íè ãË ä´ ¾ÒÃÔµàÕé » ¹¤Ù µ ͧ¡íÒ˹´ãË ºÔµ¾ÒÃÔµàÕé » ¹ 1 àÁ×Íè ÀÒ¤ÃѺµÃǨÊͺ¢ ÍÁÙÅ¹Õ¹é ºÑ ¨íҹǹºÔµ·Õàè » ¹ 1 ä´ à» ¹àÅ¢¤Ùá Ê´§Ç Ò ¡ÒÃÃѺ¢ ÍÁÙŶ١µ ͧ ¡ÒõÃǨÊͺâ´Â¡ÒÃ㪠¾ÒÃÔµÍÕé Ò¨äÁ ¶¡Ù µ ͧ㹺ҧ¡Ã³Õ àÁ×Íè ¢ ÍÁÙÅ·ÕÍè Ò ¹ÁÒà¡Ô´¤ÇÒÁ¼Ô´¾ÅÒ´ 2 ºÔµ ·íÒãË ÍÒ¨ÁÕ¨Òí ¹Ç¹ºÔµ·Õàè » ¹Åͨԡ 1 ÃÇÁà» ¹àÅ¢¤Ù¡ äç ´ ¡µÑÇÍ ҧ ¢ ÍÁÙÅ·ÕÊè § ÁÒà» ¹ %1001001 ºÔµ¾ÒÃÔµàÕé » ¹ 1 ·íÒãË ä´ ¾ÒÃÔµ¤Õé Ù àÁ×Íè ÃѺ¢ ÍÁÙÅä´ à» ¹ %0000001 ºÔµ¾ÒÃÔµàÕé » ¹ 1 ´Ñ§¹Ñ¹é ¡ÒõÃǨÊͺ ¾ÒÃÔµ¢Õé ͧ¢ ÍÁÙÅ·ÕÃè ºÑ ä´ ¡àç » ¹¾ÒÃÔµ¤Õé àÙ ª ¹à´ÕÂǡѹ ¨Ö§äÁ Á¡Õ ÒÃᨠ§¤ÇÒÁ¼Ô´¾ÅÒ´ ·Ñ§é ·ÕÁè ¢Õ Í ÁÙżԴ件֧ 2 ºÔµ â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õàé » ¹¡ÒáíÒ˹´ãË ÃºÑ ¢ ÍÁÙÅ·Õ¢è Ò P1 ´ ÇÂÍѵÃҺʹ 2,400 ºÔµµ Í ÇÔ¹Ò·Õ ¨íҹǹºÔµ¢ ÍÁÙÅ 7 ºÔµáÅоÒÃÔµàÕé » ¹¤Ù SER_DATA VAR BYTE SERIN 1,25597,[SER_DATA]

â»Ãá¡ÃÁ¢ Ò§µ ¹·íÒ§Ò¹ä´ áµ àÁ×Íè à¡Ô´¼Ô´¾ÅÒ´·Õ¾è ÒÃÔµÕé ¡ç¨ÐäÁ ·Òí ¡ÒÃã´æ ËÒ¡µ ͧ¡ÒÃãË Á¡Õ ÒÃᨠ§¤ÇÒÁ¼Ô´¾ÅҴ㹡ÒÃÃѺ¢ ÍÁÙÅ ÊÒÁÒöᡠä¢â»Ãá¡ÃÁä´ ´§Ñ ¹Õé SER_DATA VAR BYTE SERIN 1,25597,BAD_DATA,[SER_DATA] DEBUG ? SER_DATA STOP BAD_DATA: DEBUG parity error

àÁ×Íè Ãѹâ»Ãá¡ÃÁ¹Õé áÅ ÇÃѺ¢ ÍÁÙÅࢠÒÁÒ ¶ ÒµÃǨÊͺ¾ÒÃÔµ¶Õé ¡Ù µ ͧ ¨ÐÊ §¢ ÍÁÙÅä»áÊ´§·ÕËè ¹ Òµ Ò§ Debug Terminal ¶ Òà¡Ô´¼Ô´¾ÅÒ´·Õ¾è ÒÃÔµÕé ¨Ð¡ÃÐâ´´ä»·ÕÅè ÒàºÅ BAD_DATA áÅÐáÊ´§¢ ͤÇÒÁ parity error

$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


(7) ¡íÒ˹´¤ ÒàÇÅÒ¡ÒÃÃÍÃѺ¢ ÍÁÙÅËÃ×Í¡ÒáíÒ˹´¤ Òä·Á àÍÒµ àÁ×Íè â»Ãá¡ÃÁ¾ÕàºÊÔ¡¡ÃзíÒ¤íÒÊѧè SERIN áÅÐäÁ Á¢Õ Í ÁÙÅã´æ » ͹ࢠÒÁÒ â»Ãá¡ÃÁ¨ÐǹÃÍ ¢ ÍÁÙÅÍÂÙ· ¤Õè Òí ÊÑ§è ¹Õé äÁ ÊÒÁÒö·íҧҹ㹤íÒÊÑ§è ¶Ñ´ä»ä´ ¨Ö§µ ͧÁÕ¡ÒáíÒ˹´àÇÅÒÊíÒËÃѺÃÍ¢ ÍÁÙÅ ¶ ÒäÁ Á¢Õ Í ÁÙÅ ã´æ » ͹ࢠÒÁÒã¹àÇÅÒ·Õ¡è Òí ˹´ ¡çãË ä»·íÒ§Ò¹Í×è¹ â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õàé » ¹¡ÒÃÃÍÃѺ¢ ÍÁÙÅ͹ءÃÁ·Õ¢è Ò P1 ´ ÇÂÍѵÃҺʹ 2,400 ºÔµµ ÍÇÔ¹Ò·Õ ¨íҹǹ¢ ÍÁÙÅ 8 ºÔµ äÁ Á¡Õ ÒõÃǨÊͺ¾ÒÃÔµÕé áÅж ÒäÁ Á¢Õ Í ÁÙÅ» Í¹à¢ Ò ÁÒÀÒÂã¹ 2 ÇÔ¹Ò·Õ â»Ãá¡ÃÁ¨Ð¡ÃÐâ´´ä»·íÒ§Ò¹ÂѧµíÒá˹ § NO_DATA SERIN 1,17405,5000,NO_DATA,[DEC W1] DEBUG CLS, ? W1 STOP NO_DATA: DEBUG CLS, timed out

(8) ¡Ò÷íҧҹà ÇÁ¡Ñ¹ÃÐËÇ Ò§ä·Á àÍÒµ áÅСÒõÃǨÊͺ¾ÒÃÔµÕé ¼Ùã ª §Ò¹ÊÒÁÒöµÃǨÊͺ¾ÒÃÔµáÕé ÅÐÃÍ¡ÒÃà¡Ô´ä·Á àÍÒµ ¾Ã ÍÁæ ¡Ñ¹ä´ â»Ãá¡ÃÁµÑÇÍ ҧµ Íä» ¹Õàé » ¹¡ÒáíÒ˹´ãË ÃºÑ µÑÇàÅ¢°Ò¹ÊÔº·Õ¢è Ò P1 ´ ÇÂÍѵÃҺʹ 2,400 ºÔµµ ÍÇÔ¹Ò·Õ ¨íҹǹºÔµ¢ ÍÁÙÅ 7 ºÔµ ¾ÒÃÔµ¤Õé Ù áÅШÐà¡Ô´ä·Á àÍÒµ àÁ×Íè äÁ Á¢Õ Í ÁÙÅࢠÒÁÒÀÒÂã¹ 10 ÇÔ¹Ò·Õ AGAIN: SERIN 1,25597,BAD_DATA,25000,NO_DATA,[DEC W1] DEBUG CLS, ? W1 GOTO AGAIN NO_DATA: DEBUG CLS, timed out GOTO AGAIN BAD_DATA: DEBUG CLS, parity error GOTO AGAIN

(9) ¡ÒäǺ¤ØÁ¡ÒÃäËŢͧ¢ ÍÁÙÅ (flow control) àÁ×Íè ¡ÃзíÒ¤íÒÊѧè SERIN 㹡ÒÃÊ×Íè ÊÒâ ÍÁÙÅ͹ءÃÁ àºÊÔ¡áʵÁ» 2P ÁÕ¢Í ¨íҡѴ㹡Ò÷íÒ§Ò¹´Ñ§¹Õé 1. àÁ×Íè i-Stamp2P24 ÃѺËÃ×ÍÊ §¢ ÍÁÙÅÍÂÙ ¨ÐäÁ ÊÒÁÒö·íҧҹ㹤íÒÊѧè Í×¹è æ ä´ 2. àÁ×Íè i-Stamp2P24 ·íҧҹ㹤íÒÊѧè Í×¹è æ ¡ç¨ÐäÁ ÊÒÁÒöÃѺËÃ×ÍÊ §¢ ÍÁÙÅä´ 3. i-Stamp2P24 äÁ ÁºÕ ¿Ñ à¿Íà ÊÒí ËÃѺà¡çº¢ ÍÁÙÅ͹ءÃÁàËÁ×͹¡Ñºã¹¤ÍÁ¾ÔÇàµÍà ¨Ö§äÁ ÊÒÁÒöÃѺ¢ ÍÁÙŷѧé ËÁ´¼ Ò¹¤íÒÊѧè SERIN ä´ ¤íÒÊѧè SERIN ÊÒÁÒÃ¶Í Ò¹¢ ÍÁÙÅä´ à» ¹ª ǧæ à· Ò¹Ñ¹é ¢ ͨíÒ¡Ñ´µ Ò§æ ´Ñ§¡Å ÒÇÊÒÁÒöᡠä¢ä´ ´ Ç¡ÒäǺ¤ØÁ¡ÒÃäËŢͧ¢ ÍÁÙŨҡ¿ §¡ ªÑ¹ fpin «Ö§è ¤íÒÊѧè SERIN ÊÒÁÒöºÍ¡ãË i-Stamp2P24 Ê §ÊÑ­­Ò³á¨ §¤ÇÒÁ¾Ã ÍÁ㹡ÒÃÃѺ¢ ÍÁÙÅ â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õàé » ¹¡ÒäǺ¤ØÁ¡ÒÃäËŢͧ¢ ÍÁÙÅÊíÒËÃѺ¤íÒÊѧè SERIN â´Â¡íÒ˹´ ãË ÃºÑ ¢ ÍÁÙż Ò¹·Ò§¢Ò P1 ¢Ò¾Íà µ·Õ·è Òí ˹ Ò·Õ¤è Ǻ¤ØÁ¡ÒÃäËŢͧ¢ ÍÁÙŤ×Í¢Ò P0 ÍѵÃҺʹ 9,600 ºÔµµ Í ÇÔ¹Ò·Õ ¢¹Ò´¢ ÍÁÙÅ 8 ºÔµ äÁ 㪠¾ÒÃÔµÕé áÅÐäÁ Á¡Õ ÒáÅѺʶҹТ ÍÁÙÅ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$!


SER_DATA VAR BYTE SERIN 1\0,240,[SER_DATA]

àÁ×Íè ¡ÃзíÒ¤íÒÊѧè SERIN ·íÒ§Ò¹ ¢Ò P1 ¨Ð㪠ÊÒí ËÃѺÃѺ¢ ÍÁÙÅÍÔ¹¾Øµ Ê Ç¹¢Ò P0 ¡íÒ˹´ãË à» ¹ ¢ÒàÍÒµ ¾µØ â´Â¨ÐÁÕÅͨԡ໠¹ 0 àÁ×Íè µ ͧ¡ÒÃãË Á¡Õ ÒÃÊ §¢ ÍÁÙÅÁÒ àÁ×Íè ÃѺ¢ ÍÁÙÅàÃÕºà Í ¢Ò P0 ¨ÐÁÕÅͨԡ໠¹ 1 à¾×Íè ãË µÇÑ Ê §ËÂØ´Ê §¢ ÍÁÙŠ㹡óշ¿Õè § ¡ ª¹Ñ baudmode ÁÕ¡ÒáíÒ˹´ãË ¡ÅѺʶҹзբè ÒÃѺ¢ ÍÁÙÅ ¢Ò¾Íà µ·Õ·è Òí ˹ Ò·Õè à» ¹ fpin ¨Ðµ ͧ¡íÒ˹´ãË Á¡Õ ÒáÅѺʶҹд Ç µÑÇÍ ҧ¡ÒÃ㪠§Ò¹â¿ÅǤ͹â·ÃÅẺ˹Ö觤×Íàª×èÍÁµ Í i-Stamp2P24 ÊͧµÑÇࢠҴ Ç¡ѹ ´Ñ§áÊ´§Ç§¨Ãã¹ÃÙ»·Õè 3-23 Ê Ç¹â»Ãá¡ÃÁµÑÇÍ ҧÁÕ´§Ñ ¹Õé â»Ãá¡ÃÁÀÒ¤Ê § µÑÇÊ § : ¢ ÍÁÙÅÍÍ¡·Õ¢è Ò¾Íà µ 1, ¢Ò¤Çº¤ØÁ¡ÒÃäËŢͧ¢ ÍÁÙŤ×Í ¢Ò¾Íà µ 0 Baudmode : 9600 N8 ¡ÅѺÅͨԡ SEROUT 1\0,16624,[ HELLO! ] Ê §¢ ͤÇÒÁ HELLO â»Ãá¡ÃÁÀÒ¤ÃѺ µÑÇÃѺ : ¢ ÍÁÙÅࢠҷբè Ò¾Íà µ 1, ¢Ò¤Çº¤ØÁ¡ÒÃäËŢͧ¢ ÍÁÙŤ×Í ¢Ò¾Íà µ 0 Baudmode : 9600 N8 ¡ÅѺÅͨԡ LETTA VAR BYTE AGAIN: SERIN 1\0,16624,[LETTA] Í Ò¹¢ ÍÁÙÅ 1 亵 DEBUG LETTA áÊ´§¤ Ò·ÕËè ¹ Òµ Ò§ Debug Terminal PAUSE 1000 ˹ ǧàÇÅÒ 1 ÇÔ¹Ò·Õ GOTO AGAIN

㹡óշäÕè Á 㪠â¿ÅǤ͹â·ÃÅ ÀÒ¤Ê §¨ÐÊ §¢ ͤÇÒÁ HELLO! ÁÒÀÒÂã¹àÇÅÒ 6 ÁÔÅÅÔÇ¹Ô Ò·Õ Ê Ç¹ ·Ò§ÀÒ¤ÃѺ¨ÐÃÑºä´ à©¾ÒÐ亵 áá෠ҹѹé Ê Ç¹ã¹â»Ãá¡ÃÁµÑÇÍ ҧ¢ Ò§µ ¹¨Ð·íÒ¡ÒÃÃѺ¢ ÍÁÙÅ亵 áááÅ Çᨠ§ãË ÀÒ¤Ê § ËÂØ´Ê §¢ ÍÁÙÅ â´Â¨Ðà¡Ô´¡ÒÃ˹ ǧàÇÅÒ 1 ÇÔ¹Ò·Õ («Ö§è 㹪 ǧàÇÅÒ¹ÕÍé Ҩ㪠㹡ÒÃÃѹâ»Ãá¡ÃÁã¹Ê ǹÍ×¹è ä´ µÒÁµ ͧ¡ÒÃ) ¨Ò¡¹Ñ¹é ¨Ö§¡ÅѺÁÒÃѺ¢ ÍÁÙÅã¹äºµ ¶´Ñ ä» ã¹ÃÙ»·Õè 3-23 ·Õ¢è Ò P0 ¨ÐÁÕµÇÑ µ Ò¹·Ò¹µ ;ÙÅ´Òǹ àÍÒäÇ à¾×Íè µ ͧ¡ÒÃãË ÀÒ¤Ê § ÊÒÁÒöÃѺÃ٠ʶҹСÒÃᨠ§ãË ËÂØ´Ê §ÊÑ­­Ò³ä´ Í ҧáÁ ¹ÂíÒÁÒ¡¢Öé¹

ÊÒÂÊíÒËÃѺâ»Ãá¡ÃÁ BS2P

ÀÒ¤ÃѺ V55

2

2

2

2

10k

BS2P

ÀÒ¤Ê § V55

ÃÙ»·Õè 3-23 ¡ÒÃàª×Íè Áµ Í i-Stamp2P24 2 µÑÇࢠҴ Ç¡ѹ áÅ Ç㪠¡Ãкǹ¡ÒäǺ¤ØÁ¡ÒÃäËŢͧ¢ ÍÁÙÅ ¨Ñ´¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅÃÐËÇ Ò§¡Ñ¹áÅСѹ $"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


SEROUT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè SEROUT tpin,baudmode,{pace,}[outputData] SEROUT tpin\fpin,baudmode,{timeout,tlabel,}[outputData]

à» ¹¤íÒÊÑè§ÊíÒËÃÑºÊ §¢ ÍÁÙÅ͹ءÃÁẺÍЫԧâ¤Ã¹ÑÊ ÊÒÁÒÃ¶Ê §¢ ÍÁÙÅ͹ءÃÁä´ ·Õè¤ÇÒÁàÃçÇ 608 ¶Ö§ 115,200 ºÔµµ ÍÇÔ¹Ò·Õ ¾ÒÃÒÁÔàµÍà tpin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò µÑ§é áµ 0 ¶Ö§ 16 㪠àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2p24 ÊíÒËÃÑºÊ §¢ ÍÁÙÅ ¢Ò¾Íà µ·Õãè ª §Ò¹¨Ð¡íÒ˹´ãË à» ¹¢ÒàÍÒµ ¾µØ áÅФ§ÍÂÙ㠹ʶҹйÕËé Åѧ¨Ò¡Ê §¢ ÍÁÙÅàÃÕºà ÍÂáÅ Ç ã¹¡Ã³Õ·¡Õè ÒáíÒ˹´ãË tpin ÁÕ¤Ò à· Ò¡Ñº 16 i-Stamp2p24 ¨Ð㪠¢Ò SOUT 㹡ÒÃÊ §¢ ÍÁÙÅ «Ö§è ¢Ò¹Õ»é ¡µÔ¨Ð㪠㹡ÒôÒǹ âËÅ´â»Ãá¡ÃÁÃÐ ËÇ Ò§¤ÍÁ¾ÔÇàµÍà ¡ºÑ i-Stamp2p24 baudmode à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õ¢è ¹Ò´ 16 ºÔµà¾×Íè ¡íÒ˹´¤Ø³ÊÁºÑµµÔ Ò § æ ¢Í§¡ÒÃÊ×Íè ÊÒâ ÍÁÙŠẺ͹ءÃÁ ¢ ÍÁÙÅ 13 ºÔµ´ Ò¹µèÒí (ºÔµ 0-12) 㪠ÊÒí ËÃѺ¡ÒáíÒ˹´¤ Һʹàõ¨Ò¡Êٵà ¤ Ò¨íҹǹàµçÁ¢Í§ (2,500,000/ ºÍµàõ) - 20 ºÔµ 13 㪠¡Òí ˹´¨íҹǹ¢Í§ºÔµ¢ ÍÁÙÅáÅоÒÃÔµÕé (0 = 8 ºÔµ äÁ Á¾Õ ÒÃÔµÕé , 1 = 7 ºÔµáÅоÒÃÔµ¤Õé Ù ) ºÔµ 14 ¤Çº¤ØÁ¢ÑÇé ¢Í§ÊÑ­­Ò³·ÕÃè ºÑ à¢ ÒÁÒ (0 = äÁ ¡ÅѺ¢ÑÇé , 1 = ¡ÅѺ¢ÑÇé ) ºÔµ 15 àÅ×Í¡¡Ò÷íÒ§Ò¹¢Í§Ç§¨ÃàÍÒµ ¾µØ â´Â¶ Òà» ¹ 0 ¨Ðà» ¹¡ÒÃàÅ×Í¡ãË ¢ºÑ àÍÒµ ¾µØ ·Ñ§é ÊͧʶҹР¤×Í 0 ¡Ñº 1 ËÃ×ÍẺ¾Øª¾ÙÅ ¶ Òà» ¹ 1 ¨Ðà» ¹¡ÒÃàÅ×Í¡ãË ¢ºÑ à¾Õ§ʶҹÐà´ÕÂÇ áÅ ÇʶҹзÕàè ËÅ×ÍãË à» ´Ç§¨Ã ËÃ×Íà» ¹áºº¤ÍÅàÅç¡àµÍà ໠´ à¾×èÍÍíҹǤÇÒÁÊдǡ㹡ÒáíÒ˹´¤ Ò baudmode ä´ ·íÒ¡ÒÃÊÃØ»¤ Ңͧ baudmode äÇ ãË áÅ Ç µÒÁà§×Íè ¹ä¢µ Ò§æ ·Õàè ¡ÕÂè Ç¢ ͧ㹵ÒÃÒ§·Õè 3-12 pace à» ¹µÑÇàÅ×Í¡à¾ÔÁè àµÔÁÍҨ໠¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè 0 ¶Ö§ 65,535 㪠㹡ÒáíÒ˹´¤ ÒàÇÅÒ·ÕËè ÂØ´ÃÍ ÃÐËÇ Ò§¡ÒÃÊ §¢ ÍÁÙÅ ÁÕ˹ ÇÂà» ¹ÁÔÅÅÔÇ¹Ô Ò·Õ OutputData à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè¢Í§¢ ÍÁÙÅ·Õè㪠㹡ÒÃÊ § fpin à» ¹µÑÇàÅ×Í¡à¾ÔèÁàµÔÁ ÁÕ¤ ÒµÑé§áµ 0 ¶Ö§ 15 à¾×èÍàÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2p24 ·Õè¨Ð㪠໠¹¢Ò ¤Çº¤ØÁ¡ÒÃäËŢͧ¢ ÍÁÙÅ ¢Ò¾Íà µ·ÕèàÅ×Í¡¹Õé¨Ð¶Ù¡¡íÒ˹´ãË à» ¹ÍÔ¹¾ØµáÅФ§ÍÂÙ ·ÕèʶҹйÕéáÁ Ç Ò¨Ð¡ÃзíÒ¤íÒÊÑè§àÃÕº à ÍÂáÅ Ç¡çµÒÁ timeout à» ¹µÑÇàÅ×Í¡à¾ÔèÁàµÔÁ¢Í§¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕèÁÕ¤ ÒµÑé§áµ 0 ¶Ö§ 65,535 㪠¡íÒ˹´ª ǧàÇÅÒ ã¹¡ÒÃÃÍÊÑ­­Ò³â¿ÅǤ͹â·ÃŨҡÀÒ¤ÃѺ·Ò§¢Ò fpin àÁ×Íè ¾ ¹¨Ò¡àÇÅÒ·Õ¡è Òí ˹´áÅÐäÁ ÁÊÕ ­ Ñ ­Ò³â¿ÅǤ͹â·ÃÅ ¨Ò¡ÀÒ¤ÃѺ ¤íÒÊѧè SEROUT ¨Ð¡ÃÐâ´´ä»·íÒ§Ò¹·Õè tlabel ÁÕ˹ ÇÂà» ¹ 0.4 ÁÔÅÅÔÇ¹Ô Ò·Õ tlabel à» ¹µÑÇàÅ×Í¡à¾ÔÁè àµÔÁ«Ö§è 㪠¡ºÑ ¢Ò fpin áÅÐ timeout 㪠ÊÒí ËÃѺ¡íÒ˹´µíÒá˹ §·Õâè »Ãá¡ÃÁ¨Ð¡ÃÐâ´´ ä»àÁ×èÍà¡Ô´ä·Á àÍÒµ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$#


ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ (1) ¡ÒÃàª×Íè Áµ Í·Ò§ÎÒà ´áÇà i-Stamp2P24 ÊÒÁÒÃ¶Ê §¢ ÍÁÙÅ͹ءÃÁÍÍ¡·Ò§¼ Ò¹¢Ò¾Íà µã´¡çä´ ËÃ×ͼ Ò¹·Ò§¢Ò SOUT (¡íÒ˹´ tpin = 16) 㹡óշµÕè Í ¡Ñº¾Íà µÍ¹Ø¡ÃÁ¢Í§¤ÍÁ¾ÔÇàµÍà µÒÁÁҵðҹ RS-232 ¨Ðµ ͧÃÐÁÑ´ÃÐÇѧã¹àÃ×Íè §ÃдѺ áç´Ñ¹´ Ç ¤íÒÊѧè SEROUT «Ö§è 㪠¢Ò¾Íà µ»¡µÔ㹡Ò÷íÒ§Ò¹¹Ñ¹é ÃдѺáç´Ñ¹à· ҡѺ 0 áÅÐ 5V «Ö§è Áҵðҹ RS232 ÊÒÁÒöÃѺÃÙ¤ Ò áç´Ñ¹¤ Ò¹Õäé ´ â´Â¡ÒáíÒ˹´¤ Ò baudmode ¨Ðµ ͧ¡íÒ˹´ãË ¡ÅѺʶҹд Ç (2) ¡ÒáíÒ˹´âËÁ´¡Ò÷íÒ§Ò¹áÅФ ÒÍѵÃҺʹ㹿 §¡ ª¹Ñ baudmode ÊíÒËÃѺ¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅẺÍЫԧâ¤Ã¹ÑÊ ¤ÇÒÁàÃçÇ㹡ÒÃÃÑºÊ §¢ ÍÁÙÅ·Ñ§é µÑÇÃѺáÅеÑÇÊ §¨Ðµ ͧ ෠ҡѹ ÍѵÃÒ¤ÇÒÁàÃçÇ㹡ÒÃÃÑºÊ §¢ ÍÁÙŹըé ÐàÃÕÂ¡Ç Ò ºÍµàõ (baudrate) ÁÕ˹ ÇÂà» ¹ bps (ºÔµµ ÍÇÔ¹Ò·Õ) ¤íÒÊѧè SEROUT ¨ÐÁÕÍÍ»ªÑ¹è baudmode à¾×Íè ¡íÒ˹´¤ÇÒÁàÃçÇ㹡ÒÃÊ §¢ ÍÁÙÅ ¡íÒ˹´¨íҹǹºÔµ¢ ÍÁÙÅ·ÕÃè ºÑ à¢ ÒÁÒ ÁÕ ¡ÒõÃǨÊͺ¾ÒÃÔµËÕé Ã×ÍäÁ áÅе ͧ¡ÒáÅѺ¢ÑÇé ¢Í§¢ ÍÁÙÅ·ÕÃè ºÑ à¢ ÒÁÒËÃ×ÍäÁ (3) ¡ÒÃÊ §¢ ÍÁÙÅ͹ءÃÁÍ ҧ§ ÒÂáÅСÒÃá»Å§ÃٻẺ¢ ÍÁÙŢͧ¤íÒÊѧè SEROUT ÃٻẺ¢Í§¤íÒÊѧè SEROUT Í ҧ§ ÒÂÁÕ´§Ñ ¹Õé SEROUT tpin,baudmode,[outputData]

¶ Ò¡ÒÃÊ §¢ ÍÁÙÅ 1 亵 ¼Ò ¹·Ò§¢Ò P1 ´ ÇÂÍѵÃҺʹ 9,600 ºÔµµ ÍÇÔ¹Ò·Õ ¨íҹǹºÔµ¢ ÍÁÙÅ 8 ºÔµ äÁ Á¾Õ ÒÃÔµÕé ÊÑ­­Ò³àÍÒµ ¾µØ ÁÕ¡ÒáÅѺʶҹРÊÒÁÒöà¢Õ¹â»Ãá¡ÃÁä´ ´§Ñ ¹Õé SEROUT 1,16624,[65]

Ê §¢ ÍÁÙŤ Ò 65 (ÃËÑÊáÍÊ¡Õ¢é ͧÍÑ¡Éà A) ÍÍ¡·Ò§¾Íà µ P1

àÁ×èͤíÒÊÑè§ SEROUT àÃÔèÁ·íÒ§Ò¹ ¨Ð·íÒãË ¢Ò P1 à» ¹àÍÒµ ¾Øµ áÅÐÊ §¤ Ò 65 (%01000001 °Ò¹Êͧ) ¶ ÒÁÕ¡ÒÃà» ´â»Ãá¡ÃÁ»ÃÐàÀ·à·ÍÁÔ¹Íź¹¤ÍÁ¾ÔÇàµÍà ¤ Ò·Õáè Ê´§·ÕËè ¹ Ҩͤ×͵ÑÇÍÑ¡Éà A à¹×Íè §¨Ò¡Ç ÒµÑÇ ÍÑ¡Éà A ¹Ñ¹é ÁÕÃËÑÊáÍÊ¡Õàé · ҡѺ 65 ¶ Òµ ͧ¡ÒÃÊ §¤ Ò 65 Í͡仨ÃÔ§ æ ¨Ðµ ͧà¢Õ¹¤íÒÊÑ§è ´Ñ§¹Õé SEROUT 1,16624,[DEC 65] Ê §¢ ͤÇÒÁ 65 ÍÍ¡·Ò§¢Ò¾Íà µ P1

¿ §¡ ª¹Ñ DEC ¨Ðª ÇÂãË ¤Òí Êѧè SEROUT á»Å§¤ ÒµÑÇàÅ¢ãË ÍÂÙã ¹ÃÙ»¢Í§àÅ¢°Ò¹ÊÔº (4) ¡ÒÃÊ §¢ ÍÁÙÅ·Õàè » ¹µÑÇÍÑ¡ÉÃáÅСÒÃÊ §Ã ÇÁ¡Ñ¹ÃÐËÇ Ò§µÑÇÍÑ¡ÉÃáÅФ Ò¢ ÍÁÙÅ ¤íÒÊѧè SEROUT ÊÒÁÒÃ¶Ê §¢ ͤÇÒÁä´ â´ÂÁÕû٠Ẻ¡ÒÃ㪠§Ò¹´Ñ§¹Õé SEROUT 1,16624,[ A ] Send byte value 65 ( A ). SEROUT 1,16624,[ HELLO ] Send series of bytes, HELLO .

¹Í¡¨Ò¡¨Ðà» ¹¡ÒÃÊ §¢ ͤÇÒÁà¾Õ§Í ҧà´ÕÂÇáÅ Ç ¼Ùã ª §Ò¹ÊÒÁÒÃ¶Ê §¢ ͤÇÒÁáÅТ ÍÁÙÅä»ä´ ¾Ã ÍÁæ ¡Ñ¹ â´Â¤Ñ¹è ´ ÇÂà¤Ã×Íè §ËÁÒ , ´Ñ§¹Õé TEMP VAR BYTE TEMP = 96 SEROUT 1,16624,[ Temperature is , DEC TEMP, degrees F. ]

àÁ×Íè Ãѹâ»Ãá¡ÃÁ i-Stamp2P24 Ê §¢ ͤÇÒÁ Temperature is 96 degrees F. ÍÍ¡ä»

$$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


(5) ¡ÒÃÊ §¢ ͤÇÒÁã¹ÃÙ»¢Í§µÑÇá»Ã ¢ ͤÇÒÁ 1 ¢ ͤÇÒÁÊÒÁÒöà¡çºäÇ ã¹µÑÇá»Ãª¹Ô´äºµ «§Öè ÊÒÁÒöà»ÅÕÂè ¹á»Å§¢¹Ò´¨íҹǹ亵 ä´ à¾×Íè »ÃÐ⪹ 㹡ÒÃà¡çº¢ ÍÁÙŵÑÇÍÑ¡É÷ÕÁè ¢Õ ¹Ò´äÁ ෠ҡѹ à¾×Íè ãË ÃºÑ ÃÙÇ Ò ÁÕ¨Òí ¹Ç¹äºµ à· Òã´ÊíÒËÃѺ¢ ͤÇÒÁ 1 ¢ ͤÇÒÁ ¨Ðµ ͧÁÕ¢Í ÁÙÅÊíÒËÃѺ» ´· Ò«֧è àÃÕÂ¡Ç Ò End-of-String (Ê Ç¹ãË­ ¨Ð㪠ÃËÑÊáÍÊ¡Õé Null «Ö§è ·Ø¡ºÔµã¹ 亵 ¹Ñé¹ÁÕ¤ Ò෠ҡѺ 0 ) â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õéà» ¹¡ÒÃÊ §¢ ͤÇÒÁã¹ÃٻẺ¢Í§¡ÅØ Á¢ ÍÁÙÅ·ÕèÁÕ¡ÒÃÃкؤ Ò ¢Í§ Null ËÃ×Í¢ ÍÁÙÅ» ´· ÒÂäÇ ã¹äºµ ·Õè 5 MY_TEXT VAR BYTE(10) MY_TEXT(0) = H MY_TEXT(1) = E MY_TEXT(2) = L MY_TEXT (3) = L MY_TEXT (4) = 0 : MY_TEXT (5) = 0 SEROUT 1,16624,[STR MY_TEXT]

An array to hold the string. Store HELLO in 1st 5 cells...

Put null (0) after last character. Send HELLO

ÊíÒËÃѺ¢ ͤÇÒÁª¹Ô´Í×¹è ¨Ðãª Ç¸Ô ¹Õ ºÑ ¨íҹǹµÑÇÍÑ¡Éà â´ÂÁÕµÇÑ á»ÃÊíÒËÃѺà¡çº¨íҹǹµÑÇÍÑ¡É÷Õãè ª Ê Ç¹ãË­ ¡ÒÃà¡çº¤ Ò¨Ðà¡çºäÇ ·äÕè ºµ áá¢Í§µÑÇá»Ã·Õàè Å×͡㪠ᵠÊÒí ËÃѺ i-Stamp2P24 ¨Ðà¡çº¤ ÒäÇ ·äÕè ºµ Ê´Ø · Ò ¢Í§µÑÇá»Ã·Õ¨è ͧäÇ ´Ñ§áÊ´§´ ÇÂâ»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé MY_TEXT VAR BYTE(10) An array to hold the string. MY_TEXT (0) = H MY_TEXT (1) = E Store HELLO in first 5 cells... MY_TEXT (2) = L MY_TEXT (3) = L MY_TEXT (4) = 0 MY_TEXT (9) = 5 Put length (5) in last cell. SEROUT 1,16624,[STR MY_TEXT \ MY_TEXT (9)] Send HELLO

¡ÒÃ㪠¤Òí Êѧè SEROUT à¾×Íè Ê §¢ ÍÁÙŵÑÇÍÑ¡ÉÃã¹ÅѡɳйÕé ¨Ð·íÒ§Ò¹ä´ àÁ×Íè ¢ ÍÁÙÅà» ¹¢ ÍÁÙÅ·ÕÍè ÂÙã ¹ ˹ ǤÇÒÁ¨íÒáÃÁÀÒÂã¹ i-Stamp2P24 ෠ҹѹé äÁ 㪠¢Í ÁÙÅ·ÕÍè ÂÙã ¹ÍÕÍ¾Õ ÃÍÁ (6) ¡ÒêÐÅÍ¡ÒÃÊ §¢ ÍÁÙÅáÅСÒÃ㪠˹ Òµ Ò§ Debug à¾×Íè áÊ´§¡ÒÃÊ §¢ ÍÁÙÅ ¤íÒÊѧè SEROUT ÂÍÁãË ¼ãÙ ª §Ò¹ÊÒÁÒöªÐÅÍ¡ÒÃÊ §¢ ÍÁÙÅ͹ءÃÁä´ â´Â¡ÒÃà¾ÔÁè ª ǧ˹ ǧàÇÅÒ ´ Ǥ Ò 1 ¶Ö§ 65,535 ÁÔÅÅÔÇ¹Ô Ò·ÕÃÐËÇ Ò§¡ÒÃÊ §áµ ÅÐ亵 â´ÂÊÒÁÒöà¢Õ¹â»Ãá¡ÃÁä´ ´§Ñ ¹Õé SEROUT 1,16624,1000,[ Slowly ] 1-sec delay between characters.

ÊÁÁµÔÇÒ µ ͧ¡ÒÃáÊ´§¼Å¡ÒÃÊ §¢ ͤÇÒÁ¢Í§¤íÒÊѧè SEROUT â´Â˹ ǧàÇÅÒ㹡ÒÃÊ §áµ ÅР亵 ´Ç ÂàÇÅÒ 1 ÇÔ¹Ò·Õ áÅÐäÁ µÍ §¡ÒÃ㪠â»Ãá¡ÃÁ terminal ËÃ×ÍäÁ µÍ §¡Òõ ÍÊÒÂà¾ÔÁè àµÔÁ ¼Ùã ª §Ò¹ÊÒÁÒö 㪠˹ Òµ Ò§ Debug Terminal 㹡ÒÃáÊ´§¼Åä´ â´ÂãË ¤Òí Êѧè SEROUT Ê §¢ ÍÁÙÅÍÍ¡·Ò§¢Ò 16 ·Õºè Í´àõ 9,600 ºÔµµ ÍÇÔ¹Ò·Õ ´Ñ§µÑÇÍ ҧµ Í仹Õé DEBUG CLS SEROUT 16,240,1000,[ Slowly ]

Open a cleared DEBUG window Serout to DEBUG screen

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$%


+5V 1k

I/O

GND I/O BS2P

1k

GND I/O BS2P

GND BS2P

I/O

GND I/O BS2P

GND I/O BS2P

GND BS2P

ÃÙ»·Õè 3-24 áÊ´§¡Òõ Í i-Stamp2P24 ËÅÒµÑÇࢠҴ Ç¡ѹ à¾×Íè Êà ҧ໠¹Ãкºà¹çµàÇÔá â´Â㪠¤ÇÒÁÊÒÁÒö Open Baudmode ¢Í§¤íÒÊѧè SEROUT (7) ¡ÒäǺ¤ØÁ¡ÒÃäËŢͧ¢ ÍÁÙÅ㹤íÒÊѧè SEROUT ã¹µÑÇÍ ҧ¡ ͹˹ Ò¹Õàé » ¹¡ÒÃ㪠¤Òí Êѧè SEROUT Ê §¢ ÍÁÙÅâ´ÂäÁ Á¡Õ ÒõÃǨÊͺ¼Å·Õàè ¡Ô´¢Ö¹é ·ÕÀè Ò¤ÃÑºÇ ÒÀÒ¤ÃѺ¾Ã ÍÁ·Õ¨è ÐÃѺ¢ ÍÁÙÅËÃ×ÍäÁ ¶ ÒÀÒ¤ÃѺäÁ ¾Ã ÍÁ·Õ¨è ÐÃѺ¢ ÍÁÙÅ ¢ ÍÁÙÅ·ÕÊè § Í͡仡ç¨ÐÊÙ­ËÒ ÇÔ¸¡Õ ÒõÃǨÊͺ¤×Í ãª ¡ÒäǺ¤ØÁ¡ÒÃäËŢͧ¢ ÍÁÙÅËÃ×Íâ¿ÅǤ͹â·ÃÅ ÊíÒËÃѺ¡ÒÃ㪠â¿ÅǤ͹â·ÃÅ ÀÒ¤ÃѺ¢ ÍÁÙÅÊÒÁÒöᨠ§ÁÒÂѧ¤íÒÊѧè SEROUT ãË Ê§ ËÃ×ÍËÂØ´Ê § ¢ ÍÁÙŶ ÒäÁ ¾Ã ÍÁä´ â´Ââ¿ÅǤ͹â·ÃŢͧ i-Stamp2P24 ¨Ð·íÒ§Ò¹ã¹ÃٻẺ亵 µÍ 亵 ¤Í× ¡ ͹¨ÐÊ § ¢ ÍÁÙÅÍÍ¡ä» 1 亵 ¤íÒÊѧè SEROUT µÃǨÊͺ·Ò§ÀÒ¤ÃѺ¡ Í¹Ç Ò¾Ã ÍÁÃѺ¢ ÍÁÙÅËÃ×ÍäÁ ¶ ÒäÁ ¡¨ç ÐÃͨ¹¡Ç Ò·Ò§ ´ Ò¹ÀÒ¤ÃѺ¨Ð¾Ã ÍÁ àÁ×Íè ÀÒ¤ÃѺ¾Ã ÍÁáÅ Ç ¡ç¨Ð¢ ÍÁÙÅÍÍ¡ä»à¾Õ§ 1 亵 ¨Ò¡¹Ñ¹é ¨ÐµÃǨÊͺ·Ò§ÀÒ¤ÃѺÍÕ¡¤Ãѧé ÊíÒËÃѺ¡ÒõÃǨÊͺ¹Ñ¹é ¨Ð¡íÒ˹´¤ Ңͧ fpin ŧ㹤íÒÊѧè SEROUT â´ÂʶҹÐÅͨԡÊíÒËÃѺ ¡Ò÷íÒ§Ò¹¢Í§¢Ò fpin ¨Ð¢Ö¹é ÍÂÙ¡ ºÑ Ç Ò ÁÕ¡ÒáÅѺÊÑ­­Ò³ËÃ×ÍäÁ 㹿 §¡ ª¹Ñè baudMode ¡Å ÒǤ×Í ¶ ÒÍÂÙã ¹âËÁ´¡ÅѺ ÊÑ­­Ò³ ¤ Ңͧ fpin à» ¹Åͨԡ 1 ËÁÒ¶֧ãË Ê§ ¢ ÍÁÙÅ áµ ¶Ò à» ¹Åͨԡ 0 ¨Ðà» ¹¡ÒÃËÂØ´Ê §¢ ÍÁÙÅ ã¹¡Ã³Õ ·ÕÍè ÂÙã ¹âËÁ´äÁ ¡ÅѺÊÑ­­Ò³ Åͨԡ 0 ¨ÐËÁÒ¶֧ãË Ê§ ¢ ÍÁÙÅ Åͨԡ 1 ¤×ÍËÂØ´Ê §¢ ÍÁÙÅ ÊÒÁÒöà¢Õ¹â»Ãá¡ÃÁ µÑÇÍ ҧáÊ´§¡ÒÃ㪠â¿ÅǤ͹â·ÃÅä´ â´Â¹íÒ i-Stamp2P24 ¨íҹǹÊͧµÑÇÁÒµ ÍࢠҴ Ç¡ѹ´Ñ§ÃÙ»·Õè 3-24 ' SENDER: data out pin 1, flow control pin 0 ' Baudmode: 9600 N8 inverted SEROUT 1\0,16624,[ HELLO! ] ' RECEIVER: data in pin 1, flow control pin 0 ' Baudmode: 9600 N8 inverted LETTA VAR BYTE AGAIN: SERIN 1\0,16624,[LETTA] DEBUG LETTA PAUSE 1000 GOTO AGAIN

$&

' Send the greeting.

' Get 1 byte. ' Display on screen. ' Wait a second.

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


㹡óշäÕè Á 㪠â¿ÅǤ͹â·ÃÅ ¤íÒÊѧè SEROUT ¨Ð㪠àÇÅÒ㹡ÒÃÊ §¢ ͤÇÒÁ HELLO! »ÃÐÁÒ³ 6 ÁÔÅÅÔÇ¹Ô Ò·Õ áµ ÀÒ¤ÃѺ¨ÐÊÒÁÒöÃÑºä´ à¾Õ§亵 áá෠ҹѹé ËÅѧ¨Ò¡¼ Ò¹¤íÒÊѧè PAUSE ä»áÅ Ç ¢ ÍÁÙŵÑÇ Í×¹è æ ¨ÐËÒÂä»ËÁ´ áµ àÁ×Íè 㪠â¿ÅǤ͹â·ÃÅ i-Stamp2P24 ¨Ð¤Í¨¹¡Ç ÒÀÒ¤ÃѺ¨Ð¾Ã ÍÁ·Õ¨è ÐÃѺ¢ ÍÁÙÅ áÅ Ç ¨Ö§Ê §¢ ÍÁÙÅÍÍ¡ä» ·íÒãË ÊÒÁÒöÃѺ¢ ÍÁÙÅä´ ·§Ñé ËÁ´ (8) ª ǧàÇÅÒä·Á àÍÒµ ¢Í§¡ÒäǺ¤ØÁ¡ÒÃäËŢͧ¢ ÍÁÙÅ ¡ÒÃ㪠â¿ÅǤ͹â·ÃŨÐà¡Ô´» ­ËÒ¢Ö¹é ä´ ¶ Ò·Ò§ÀÒ¤ÃѺäÁ ä´ µÍ à ÇÁÍÂÙ i-Stamp2P24 ¨Ð¤Í ÍÂÙµ ÅÍ´àÇÅÒàËÁ×͹â»Ãá¡ÃÁËÂØ´·íÒ§Ò¹ ·íÒãË äÁ ÊÒÁÒö·íÒ§Ò¹Í×¹è µ Íä»ä´ à¾×Íè á¡ ä¢à˵ءÒó ´§Ñ ¡Å ÒÇ ¤íÒÊѧè SEROUT ¨Ð¡íÒ˹´ª ǧàÇÅÒ㹡ÒÃÃÍ¡Òõͺʹͧ¨Ò¡ÀÒ¤ÃÑºä´ µ§Ñé áµ 0 ¶Ö§ 163,838 ÁÔÅÅÔÇ¹Ô Ò·Õ ¶ ÒäÁ ÁÕ ¡ÒÃÊ §ÊÑ­­Ò³µÍºÊ¹Í§ÁÒÀÒÂã¹àÇÅÒ·Õ¡è Òí ˹´ â»Ãá¡ÃÁ¨Ð¡ÃÐâ´´ä»·íҧҹ㹵íÒá˹ §ÅÒàºÅ·ÕÃè кØàÍÒäÇ â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õàé » ¹¡ÒáíÒ˹´ãË i-Stamp2P24 ÃÍÊÑ­­Ò³µÍºÃѺÀÒÂã¹àÇÅÒ 2.5 ÇÔ¹Ò·Õ ¶ ÒäÁ Á¡Õ Òõͺʹͧ â»Ãá¡ÃÁ¨Ð¡ÃÐâ´´ä»·íÒ§Ò¹·ÕÅè ÒàºÅ noflow SEROUT 1\0,16624,2500,NO_FLOW [ HELLO! ] NO_FLOW: STOP

(9) ¡ÒÃàª×Íè Áµ ÍÃкºà¹çµàÇÔá ´ Ç¿ §¡ ª¹Ñè Open Baudmode ¿ §¡ ª¹Ñè Open Baudmode ÊÒÁÒö㪠à¾×Íè àª×Íè Áµ Í i-Stamp2P24 ËÅÒÂæ µÑÇࢠҡѺÊÒ¾ ǧªØ´ à´ÕÂǡѹà¾×Íè Êà ҧÃкºà¹çµàÇÔá ·Õãè ª ÊÒÂà ÇÁ¡Ñ¹ä´ ¿ §¡ ª¹Ñè Open Baudmode µ ͧ¢ÑºãË ·Òí §Ò¹ã¹Ê¶Ò¹Ðà´ÕÂÇ à· Ò¹Ñ¹é (»¡µÔÁÅÕ Í¨Ô¡ 1 ) Ê Ç¹ÍաʶҹФ×Íà» ´Ç§¨Ã ÊÒà˵طµÕè Í §·íÒઠ¹¹Õàé ¹×Íè §¨Ò¡¶ Ò¡íÒ˹´ãË ·Òí §Ò¹ÊͧʶҹР¶ ÒËÒ¡ i-Stamp2P24 µÑÇã´µÑÇ˹֧è à¡Ô´ÁÕʶҹÐÅͨԡ 0 ã¹¢³Ð·ÕÍè ¡Õ µÑÇ˹֧è ÁÕʶҹÐÅͨԡ 1 áŠǵ Íà ÇÁ¡Ñ¹ ¨ÐÁռŷíÒãË Á¡Õ ÃÐáʨíҹǹÁÒ¡äËŨҡ俺ǡ¼ Ò¹ i-Stamp2P24 ·Ñ§é ÊͧµÑÇŧ¡ÃÒÇ´ Ê §¼ÅãË i-Stamp2P24 ·Ñ§é ÊͧµÑÇàÊÕÂËÒÂä´ àÁ×Íè Open Baudmode ¶Ù¡¢ÑºãË ·Òí §Ò¹Ê¶Ò¹Ðà´ÕÂÇ ´Ñ§¹Ñ¹é ã¹Ê¶Ò¹Ð·ÕÅè ÍÂÍÂÙ¹ ¹Ñé ¨Ðµ ͧÁÕµÇÑ µ Ò¹·Ò¹µ ;ÙÅÍÑ»ËÃ×;ÙÅ´Òǹ äÇ ´§Ñ áÊ´§ã¹ÃÙ»·Õè 3-24

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$'


SHIFTIN ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè SHIFTIN dpin,cpin,mode,[result{\bits}{,result{\bits}...}]

à» ¹¡ÒÃÍ Ò¹¤ Ò¢ ÍÁÙŨҡÍØ»¡Ã³ ·ÁÕè ¡Õ ÒÃÊ×Íè ÊÒÃ͹ءÃÁẺ«Ô§â¤Ã¹ÑÊ ¾ÒÃÒÁÔàµÍà dpin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕèÁÕ¤ ÒµÑé§áµ 0 ¶Ö§ 15 㪠àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 ÊíÒËÃѺÃѺ ¢ ÍÁÙÅ«Ô§â¤Ã¹ÑÊ ËÅѧ¨Ò¡·íÒ¤íÒÊѧè àÃÕºà ÍÂáÅ Ç ¢Ò¹Õ¨é ÐÍÂÙ㠹ʶҹÐÍÔ¹¾Øµ cpin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò µÑ§é áµ 0 ¶Ö§ 15 㪠àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 ÊíÒËÃѺàª×Íè Áµ Í ¡Ñº¢ÒÍÔ¹¾ØµÊÑ­­Ò³¹ÒÌ ¡Ò¢Í§ÍØ»¡Ã³ «Ô§â¤Ã¹ÑÊ·Õèµ Í§¡ÒõԴµ Í´ Ç â´Â¢Ò¹Õé¨Ð¡íÒ˹´ãË à» ¹àÍÒµ ¾Øµ mode ÁÕ¤Ò ÍÂÙà ÐËÇ Ò§ 0 ¶Ö§ 3 à¾×Íè ¡íÒ˹´ÃٻẺ¡ÒÃÊ §ÊÑ­­Ò³¹ÒÌ ¡Ò â´ÂÁÕû٠Ẻ´Ñ§¹Õé ÊÑ­Åѡɳ ¤ Ò ¤ÇÒÁËÁÒ MSBPRE 0 ¢ ÍÁÙźԵ¹ÑÂÊíҤѭÊÙ§ÊØ´¶Ù¡Ê §ÁÒ¡ ͹ áÅТ ÍÁÙÅ¨Ð¶Ù¡Ê §ÁÒ¡ ͹·Õ¨è ÐÊ § ÊÑ­­Ò³¹ÒÌ ¡Ò LSBPRE 1 ¢ ÍÁÙźԵ¹ÑÂÊíҤѭµèÒí ÊØ´¶Ù¡Ê §ÁÒ¡ ͹ áÅТ ÍÁÙÅ¨Ð¶Ù¡Ê §ÁÒ¡ ͹·Õ¨è ÐÊ § ÊÑ­­Ò³¹ÒÌ ¡Ò MSBPOST 2 ¢ ÍÁÙźԵ¹ÑÂÊíҤѭÊÙ§ÊØ´¶Ù¡Ê §ÁÒ¡ ͹ ¢ ÍÁÙÅ¨Ð¶Ù¡Ê §ËÅѧ¨Ò¡ä´ ÃºÑ ÊÑ­­Ò³ ¹ÒÌ ¡Ò LSBPOST 3 ¢ ÍÁÙźԵ¹ÑÂÊíҤѭµèÒí ÊØ´¶Ù¡Ê §ÁÒ¡ ͹ ¢ ÍÁÙÅ¨Ð¶Ù¡Ê §ËÅѧ¨Ò¡ä´ ÃºÑ ÊÑ­­Ò³ ¹ÒÌ ¡Ò Result à» ¹µÑÇá»ÃºÔµ ,¹Ô»à» Å,亵 ËÃ×ÍàÇÔô ·Õãè ª ÊÒí ËÃѺà¡çº¢ ÍÁÙÅ·ÕÃè ºÑ à¢ ÒÁÒ bits 㪠¡Òí ˹´¨íҹǹºÔµÍÔ¹¾Øµ·ÕÃè ºÑ à¢ ÒÁÒ ÁÕ¤Ò 1 ¶Ö§ 16 ¶ ÒäÁ Á¡Õ ÒáíÒ˹´ ¤ Ò»¡µÔ¨Ð෠ҡѺ 8 ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊѧè SHIFTIN ª ÇÂÍíҹǤÇÒÁÊдǡ㹡ÒõԴµ ÍÊ×Íè ÊÒáѺÍØ»¡Ã³ ·ãÕè ª ¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅẺ«Ô§â¤Ã¹ÑÊ «Ö§è ¨Ðᵡµ Ò§¨Ò¡¤íÒÊѧè SERIN áÅÐ SEROUT ·Õãè ª ¡ºÑ ¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅẺÍЫԧâ¤Ã¹ÑÊ à¹×Íè §¨Ò¡¡ÒÃÊ×Íè ÊÒâ ÍÁÙŠẺ«Ô§â¤Ã¹ÑÊ ¢ ÍÁÙÅ·ÕÃè ºÑ ËÃ×ÍÊ §¨Ðµ ͧÊÑÁ¾Ñ¹¸ ¡ºÑ ÊÑ­­Ò³¹ÒÌ ¡Ò·ÕÊè § ÍÍ¡ä»´ Ç â´Â¢ ÍÁÙÅ¨Ð¶Ù¡Ê §ËÅѧ¨Ò¡ ÊÑ­­Ò³¹ÒÌ ¡ÒÍÂÙ· ¢Õè ͺ¢Ò¢Ö¹é ËÃ×͢ͺ¢Òŧ áÅ Çáµ ¡ÒáíÒ˹´¢Í§áµ ÅÐÍØ»¡Ã³ ÊíÒËÃѺ¤ÇÒÁ¶ÕÊè ­ Ñ ­Ò³¹ÒÌ ¡Ò ¢Í§¤íÒÊѧè SHIFTIN ¤×Í 42kHz ÍØ»¡Ã³ ·ÁÕè ÅÕ ¡Ñ ɳСÒÃÊ×Íè ÊÒâ ÍÁÙÅẺ¹Õäé ´ á¡ äÍ«Õá»Å§ÊÑ­­Ò³ÍйÒÅÍ¡à» ¹´Ô¨µÔ ÍÅàºÍà ADC0831, ADC0832, LTC1298, äÍ«ÕÇ´Ñ ÍسËÀÙÁàÔ ºÍà DS1620, äÍ«Õ¢ºÑ LED ẺàÁµÃÔ¡« àºÍà MAX7219 ËÃ×Í Ë¹ Ç ¤ÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ͹ءÃÁ 93Cxx à» ¹µ ¹

%

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¤íÒÊѧè SHIFTIN 1 ¤íÒÊÑ§è ·´á·¹¡Ò÷íÒ§Ò¹µ Ò§æ ´Ñ§¹Õé (1) ·íÒãË ¢ÒÊÑ­­Ò³¹ÒÌ ¡Ò (cpin) ÁÕʶҹÐà» ¹ 0 (2) ·íÒãË ¢Ò¢ ÍÁÙÅ (dpin) à» ¹ÍÔ¹¾Øµ (3) Í Ò¹¤ ÒʶҹТͧºÔµ¢ ÍÁÙÅࢠÒÁÒà¡çº (4) Ê §ÊÑ­­Ò³¹ÒÌ ¡ÒÍ͡仡 ͹ËÃ×ÍËÅѧ¨Ò¡¡ÒÃÃѺºÔµ¢ ÍÁÙÅ ·Ñ§é ¹Õ¢é ¹Öé ÍÂÙ¡ ºÑ ¡ÒáíÒ˹´¤ Ò mode ´ Ǫ ǧÃÐÂÐàÇÅÒÅͨԡ 1 ¹Ò¹ 18.8 äÁâ¤ÃÇÔ¹Ò·Õ (5) àÅ×Íè ¹ºÔµ¢Í§¼ÅÅѾ¸ ä»·Ò§« ÒÂËÃ×Í¢ÇÒ ¢Ö¹é ÍÂÙ¡ ºÑ ¡ÒáíÒ˹´·Õµè ÇÑ á»Ã mode ·íÒµÒÁ¢Ñ¹é µÍ¹à´ÔÁ ¨¹¨íҹǹ¢ ÍÁÙŤú·Ñ§é 8 ºÔµ ËÃ×Í෠ҡѺ¨íҹǹ·Õ¡è Òí ˹´äÇ ã¹µÑÇá»Ã bits

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%


SHIFTOUT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè SHIFTOUT dpin,cpin,mode,[data{\bits}{,data{\bits}...}]

㪠àÅ×Íè ¹¢ ÍÁÙÅÍÍ¡ä»ÂѧÍØ»¡Ã³ ÊÍ×è ÊÒâ ÍÁÙÅ͹ءÃÁẺ«Ô§â¤Ã¹ÑÊ ¾ÒÃÒÁÔàµÍà dpin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕèÁÕ¤ ÒµÑé§áµ 0 ¶Ö§ 15 㪠àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 ÊíÒËÃÑºÊ § ¢ ÍÁÙÅ«Ô§â¤Ã¹ÑÊ â´Â·íҧҹ໠¹àÍÒµ ¾µØ ËÅѧ¨Ò¡·íÒ¤íÒÊѧè àÃÕºà ÍÂáÅ Ç ¢Ò¹ÕÂé §Ñ ¤§ÍÂÙ㠹ʶҹÐàÍÒµ ¾µØ Cpin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò µÑ§é áµ 0 ¶Ö§ 15 㪠àÅ×Í¡¾Íà µ¢Í§ i-Stamp2P24 ÊíÒËÃÑºÊ §ÊÑ­­Ò³ ¹ÒÌ ¡Òä»ÂѧäÍ«Õ·ÕèÁÕ¡ÒÃÊ×èÍÊÒâ ÍÁÙÅẺ«Ô§â¤Ã¹ÑÊ ¢Ò¹Õé¨Ð¶Ù¡¡íÒ˹´ãË à» ¹¢ÒàÍÒµ ¾ØµáÅФ§Ê¶Ò¹Ð¹Ñé¹äÇ ËÅѧ¨Ò¡ ·íÒ§Ò¹àÊÃç¨ÊÔé¹àÃÕºà Í mode ÁÕ¤Ò à· Ò¡Ñº 0 ËÃ×Í 1 à¾×Íè ¡íÒ˹´ãË ¤Òí Êѧè SHIFTOUT Ê §¢ ÍÁÙÅ â´ÂÁÕÃÒÂÅÐàÍÕ´´Ñ§¹Õé ÊÑ­Åѡɳ ¤ Ò ¤ÇÒÁËÁÒ LSBFIRST 0 Ê §¢ ÍÁÙÅÍÍ¡ä»â´ÂÊ §ºÔµ¹ÑÂÊíҤѭµèíÒÊØ´Í͡仡 ͹ MSBFIRST 1 Ê §¢ ÍÁÙÅÍÍ¡ä»â´ÂÊ §ºÔµ¹ÑÂÊíҤѭÊÙ§ÊØ´Í͡仡 ͹ Data à» ¹¤ Ò¢ ÍÁÙÅ·Õµè Í §¡ÒÃÊ §ÍÍ¡ä» bits à» ¹ÍÍ»ªÑ¹à¾ÔÁè àµÔÁà¾×Íè ¡íÒ˹´¨íҹǹºÔµ¢ ÍÁÙÅ·Õµè Í §¡ÒÃÊ §ÍÍ¡ä»ÁÕ¤Ò µÑ§é áµ 1-16 ¶ ÒäÁ ä´ ¡Òí ˹´¤ Ò »¡µÔ¨ÐÁÕ¤Ò à· Ò¡Ñº 8 ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊѧè SHIFTOUT 1 ¤íÒÊѧè ÊÒÁÒö·´á·¹¡Ò÷íÒ§Ò¹µ Ò§ æ ´Ñ§µ Í仹Õé (1) ¡íÒ˹´ãË ¢ÒÊÑ­­Ò³¹ÒÌ ¡Ò(cpin) ÁÕÅͨԡ໠¹ 0 (2) ¹íÒºÔµ¢Í§¢ ÍÁÙÅ·Õ¨è ÐÊ §» ͹ä»Âѧ¢Ò¢ ÍÁÙÅ (3) ¡íÒ˹´¢Ò¢ ÍÁÙÅãË à» ¹¢ÒàÍÒµ ¾µØ (4) ãË ¢ÒÊÑ­­Ò³¹ÒÌ ¡Òà» ¹ 1 ´ Ǫ ǧàÇÅÒ 18.8 äÁâ¤ÃÇÔ¹Ò·Õ ¨Ò¡¹Ñ¹é ·íÒµÒÁ¢Ñ¹é µÍ¹à´ÔÁ ¨¹¢ ÍÁÙÅ·Õ¨è ÐÊ §Í͡令úµÒÁ¨íҹǹºÔµ·Õ¡è Òí ˹´àÍÒäÇ àª ¹à´ÕÂǡѺ¤íÒÊÑè§ SHIFTIN ¤ÇÒÁ¶Õè¢Í§ÊÑ­­Ò³¹ÒÌ ¡Ò·Õè㪠¤Çº¤ØÁ¨Ñ§ËÇСÒö Ò·ʹ¢ ÍÁÙŢͧ ¤íÒÊѧè SHIFTOUT ¤×Í 42kHz

%

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


SLEEP ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè SLEEP seconds

¡íÒ˹´ãË i-Stamp2P24 ࢠÒÊÙâ ËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹ ´ ÇÂÃÐÂÐàÇÅÒµÒÁ·Õ¡è Òí ˹´ ÁÕ˹ ÇÂà» ¹ÇÔ¹Ò·Õ ¾ÒÃÒÁÔàµÍà seconds à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò µÑ§é áµ 1 ¶Ö§ 65535 㪠¡Òí ˹´¤ÒºàÇÅÒ㹡ÒÃࢠÒÊÙâ ËÁ´»ÃÐËÂÑ´ ¾Åѧ§Ò¹ ÁÕ˹ ÇÂà» ¹ÇÔ¹Ò·Õ ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊѧè SLEEP ¨Ð·íÒãË i-Stamp2P24 ËÂØ´¡Ò÷íÒ§Ò¹´ ǵÑÇÁѹàͧ áÅСÅѺÁÒ·íÒ§Ò¹ËÅѧ¨Ò¡¼ Ò¹ ª ǧàÇÅÒ·Õè¡íÒ˹´äÇ áÅ Ç ¤ ÒàÇÅÒ·Õè¡íÒ˹´ãË ·íÒ§Ò¹ã¹âËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹¹Õé ÊÒÁÒö¡íÒ˹´ä´ µÑé§áµ 2.3 ÇÔ¹Ò·Õ仨¹¶Ö§ 18 ªÑèÇâÁ§ àÁ×èÍࢠÒÊÙ âËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹ i-Stamp2P24 ¨Ð¡Ô¹¡ÃÐáÊä¿¿ ÒàËÅ×Í à¾Õ§ 60PA ã¹¢³Ð·Õäè Á Á¡Õ ÒâѺâËÅ´ã´ æ ¤ÇÒÁÅÐàÍÕ´¢Í§¤ ÒàÇÅҢͧ¡ÒÃ㪠¤Òí Êѧè SLEEP ÁÕ¤Ò à· Ò¡Ñº 2.304 ÇÔ¹Ò·Õ àÁ×Íè ¡íÒ˹´¤ ÒàÇÅÒãË ¡ºÑ ¤íÒÊѧè SLEEP ¨Ðµ ͧ¹íÒ令ٳ¡Ñº 2.304 ¡µÑÇÍ ҧ 㪠§Ò¹¤íÒÊѧè SLEEP 5 ¤ Ò¤ÒºàÇÅÒ ¤ ÒàÇÅÒ·Õäè ´ ෠ҡѺ 11.52 ÇÔ¹Ò·Õ (5 N 2.304) ¡ÒÃ㪠¤Òí Êѧè SLEEP ¹Õé ¨ÐÁÕ¡ÒÃÍÔ¹àµÍÃ Ã»Ñ µ ·¡Ø æ 2.3 ÇÔ¹Ò·Õ à¹×Íè §¨Ò¡Ç§¨ÃÇ͵ª ´Íç ¡ä·àÁÍà ÀÒÂã¹ µÑÇäÁâ¤Ã¤Í¹â·ÃÅàÅÍà ·ÍÕè ÂÙÀ ÒÂã¹ i-Stamp2P24 ¤ÍµÃǨÊͺ¡ÒÃࢠÒÊÙâ ËÁ´ÊÅÕ»¢Í§¤íÒÊѧè SLEEP

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%!


STOP ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè STOP

ËÂØ´¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁ àÁ×Íè ¡ÃзíÒ¤íÒÊѧè STOP äÁâ¤Ã¤Í¹â·ÃÅàÅÍà i-Stamp2P24 ¨ÐËÂØ´·íÒ§Ò¹¨¹¡Ç Ò¨ÐÁÕ¡ÒÃÃÕ૵ËÃ×ÍÁÕ ¡ÒôÒǹ âËÅ´â»Ãá¡ÃÁࢠÒä»ãËÁ ¤íÒÊѧè STOP µ Ò§¨Ò¡¤íÒÊѧè END ÍÂÙ 2 »ÃСÒä×Í 1. ¤íÒÊѧè STOP ¨ÐäÁ ¡Òí ˹´ãË i-Stamp2P24 ࢠÒÊÙâ ËÁ´»ÃÐËÂÑ´¾Åѧ§Ò¹ 2. ÊÑ­­Ò³Ãº¡Ç¹·Õàè ¡Ô´¨Ò¡Çç͵´çÍ¡ä·àÁÍà ¨Ðà¡Ô´¢Ö¹é ¡Ñº¤íÒÊѧè END áµ äÁ à¡Ô´¡Ñº¤íÒÊѧè STOP

%"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


STORE ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè STORE ProgramSlot

à» ¹¤íÒÊѧè àÅ×͡˹ ǤÇÒÁ¨íÒã¹à¾¨ËÃ×ÍÊÅç͵·Õµè Í §¡ÒÃà¾×Íè ·íÒ¡ÒÃÍ Ò¹áÅÐà¢Õ¹ ¾ÒÃÒÁÔàµÍà ProgramSlot à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè ¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 0 ¶Ö§ 7 㪠áÊ´§µíÒá˹ §¢Í§à¾¨ËÃ×ÍÊÅç͵ ˹ ǤÇÒÁ¨íÒ·Õèµ Í§¡ÒõԴµ Í´ Ç ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ à¹×Íé ·Õ¢è ͧ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁÀÒÂã¹µÑÇ i-Stamp2P24 㪠㹡ÒÃà¡çº·Ñ§é â»Ãá¡ÃÁáÅТ ÍÁÙÅ µÒÁ»¡µÔ i-Stamp2P24 ¨Ð·íÒ§Ò¹¡ÑºË¹ ǤÇÒÁ¨íÒã¹à¾¨ËÃ×ÍÊÅç͵ 0 àÁ×Íè µ ͧ¡ÒÃÍ Ò¹ËÃ×Íà¢Õ¹¡ç¨Ð㪠¤Òí Êѧè READ ËÃ×Í WRITE ã¹ i-Stamp2P24 ÁÕ˹ ǤÇÒÁ¨íÒ 16 ¡ÔâÅ亵 Ạ§ÍÍ¡à» ¹ 8 ྨ 㹡ÒÃÍ Ò¹ËÃ×Íà¢Õ¹¢ ÍÁÙÅŧ㹠˹ ǤÇÒÁ¨íÒÁբͺࢵ 2 ¡ÔâÅ亵 àÁ×è͵ ͧ¡ÒÃä»Í Ò¹à¢Õ¹¡ÑºË¹ ǤÇÒÁ¨íÒã¹à¾¨ËÃ×ÍÊÅç͵Í×蹨е ͧ ¡ÃÐâ´´ä»·Õâè »Ãá¡ÃÁã¹à¾¨¹Ñ¹é æ àÊÕ¡ ͹ â´Âã¹ i-Stamp2P24 ÁÕ¡ÒûÃѺ»Ãا¤ÇÒÁÊÒÁÒöã¹Ê ǹ¹Õé â´Â ¡ÒÃà¾ÔÁè ¤íÒÊѧè STORE ࢠÒÁÒ ·íÒãË i-Stamp2P24 ÊÒÁÒöࢠҶ֧˹ ǤÇÒÁ¨íÒã¹à¾¨Í×¹è ä´ â´ÂäÁ ¨Òí à» ¹µ ͧ ¡ÃÐâ´´ä»·Õàè ¾¨¹Ñ¹é æ ª ÇÂãË i-Stamp2P24 ÊÒÁÒöµÔ´µ ͡Ѻ˹ ¤ÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁà¾×Íè 㪠໠¹Ë¹ ǤÇÒÁ¨íÒ ¢ ÍÁÙÅà¾ÔèÁä´ § Ò¢Öé¹ àÁ×Íè àÅ×͡ྨ¢Í§Ë¹ ǤÇÒÁ¨íÒ´ ǤíÒÊѧè STORE áÅ Ç i-Stamp2P24 ¨ÐµÔ´µ ÍÍÂÙ· àÕè ¾¨¹Ñ¹é ¨¹¡Ç ҨРÁÕ¡ÒáíÒ˹´ãËÁ ´Ç ¤íÒÊѧè STORE ઠ¹¡Ñ¹

¡Ò÷´Åͧ Í·Õè 25 ¡ÒÃ㪠§Ò¹¤íÒÊѧè STORE (1) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2P24-25.BSP : STORE command demonstration***** ' {$STAMP BS2p} ' {$PBASIC 2.5} idx VAR Word value VAR Word Main: DEBUG "Writing...", CR PAUSE 2000 FOR idx = 2048 TO 16383 STEP 32 ' à¢Õ¹¢ ÍÁÙÅä»Âѧ EEPROM Value = idx - 2048 * 2 ' ¡íÒ˹´¤ Ò GOSUB WriteWordToEEPROM DEBUG "Location: ", DEC5 idx, " Value: ", DEC5 value, CR NEXT

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%#


DEBUG "Reading...", CR PAUSE 2000 FOR idx = 2048 TO 16383 STEP 32 ' Í Ò¹¤ Ò¨Ò¡ EEPROM GOSUB ReadWordFromEEPROM DEBUG "Location: ", DEC5 idx, " Value: ", DEC5 value, CR NEXT STOP ' [ Subroutines ] WriteWordToEEPROM: ' â»Ãá¡ÃÁ ÍÂà¢Õ¹¢ ÍÁÙÅŧã¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍ¾Õ ÃÍÁ¤ÃÒÇÅÐ 2 亵 STORE idx >> 11 ' ¡íÒ˹´à¾¨¢Í§Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ WRITE idx, Value.LOWBYTE WRITE idx + 1, Value.HIGHBYTE RETURN ReadWordFromEEPROM: ' â»Ãá¡ÃÁ ÍÂÍ Ò¹¢ ÍÁÙÅŧã¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍ¾Õ ÃÍÁ¤ÃÒÇÅÐ 2 亵 STORE idx >> 11 ' ¡íÒ˹´à¾¨¢Í§Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ READ idx, value.LOWBYTE READ idx + 1, value.HIGHBYTE RETURN

(2) Ãѹâ»Ãá¡ÃÁ áÅ ÇÊѧࡵ¼Å¡Ò÷íÒ§Ò¹¼ ҹ˹ Òµ Ò§ Debug Terminal 㹡Ò÷´Åͧ¹Õ¨é Ðà» ¹¡Ò÷´ÅÍ§Í Ò¹à¢Õ¹¢ ÍÁÙšѺ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ¢Í§ i-Stamp2P24 â´ÂàÅ×Í¡ ྨËÃ×ÍÊÅç͵¢Í§Ë¹ ǤÇÒÁ¨íÒ´ ǤíÒÊѧè STORE ¨Ò¡¹Ñ¹é ¨Ö§·íÒ¡ÒÃà¢Õ¹áÅÐÍ Ò¹ ·íÒãË ÊÒÁÒöµÔ´µ ͡Ѻ˹ Ç ¤ÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁä´ ÁÒ¡¶Ö§ 14 ¡ÔâÅ亵 ã¹à¾¨ 1 ¶Ö§ 7 â´Âã¹â»Ãá¡ÃÁ·´Åͧ¹Õ¡é Òí ˹´ãË à¢Õ¹¢ ÍÁÙÅẺÊØÁ «Ö§è ä´ ¨Ò¡¡Òäíҹdz㹺Ã÷Ѵ Value = idx - 2048 * 2 Ê Ç¹µíÒá˹ §·Õ·è Òí ¡ÒÃà¢Õ¹¹Ñ¹é ¨Ð¡íÒ˹´â´ÂµÑÇá»Ã idx «Ö§è ä´ ÁÒ¨Ò¡â»Ãá¡ÃÁ㹺Ã÷Ѵ FOR idx = 2048 TO 16383 STEP 32 ¹Ñ¹è ¤×Í·íÒ¡ÒÃà¢Õ¹·Õµè Òí á˹ § 2048 ¶Ö§ 16383 â´Â¨Ðà»ÅÕÂè ¹µíÒá˹ §ä»·Ø¡æ 32 áÍ´à´ÃÊ

áÊ´§¼Å¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè STORE àÁ×Íè à¢Õ¹¢ ÍÁÙÅŧ㹪 ǧ 2048 ¶Ö§ 16383 %$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


ËÅѧ¨Ò¡·Õà¢Õ¹¨¹¤ÃºáÅ Ç ¡ç¨ÐàÃÔèÁµ ¹Í Ò¹¢ ÍÁÙÅ¡ÅѺÍÍ¡ÁÒ â´Â·Ñé§ã¹¨Ñ§ËÇСÒÃà¢Õ¹áÅÐÍ Ò¹¨ÐÁÕ ¡ÒÃáÊ´§¼Å¼ Ò¹·Ò§Ë¹ Òµ Ò§ Debug Terminal

áÊ´§¼Å¡ÒÃ㪠§Ò¹¤íÒÊѧè STORE 㹡ÒÃÍ Ò¹¢ ÍÁÙÅ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%%


TOGGLE ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè TOGGLE pin

à»ÅÕÂè ¹Ê¶Ò¹ÐÅͨԡ¢Í§¢Ò¾Íà µ ¾ÒÃÒÁÔàµÍà pin à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕèÁÕ¤ ÒµÑé§áµ 0 ¶Ö§ 15 㪠àÅ×Í¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õèµ Í§¡Òà 㪠§Ò¹ àÁ×Íè ¡ÃзíÒ¤íÒÊÑ§è ¹Õé ¨Ðà¡Ô´¡ÒáÅѺʶҹТͧºÔµ·Õ¡è Òí ˹´µíÒá˹ §¢Í§¢Ò¾Íà µã¹ÃÕ¨ÊÔ àµÍà OUTS áÅÐãË ¢Ò ·Õ¡è Òí ˹´ÁÕʶҹÐà» ¹àÍÒµ ¾µØ ´ Ç¡ÒÃà¢Õ¹Åͨԡ 1 ä»ÂѧÃÕ¨ÊÔ àµÍà DIRS ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ¤íÒÊѧè TOGGLE 㪠¡ÅѺʶҹТͧ¢Ò¾Íà µ ËÒ¡à´ÔÁÅͨԡ 1 ¡ÅÒÂà» ¹Åͨԡ 0 áÅШҡÅͨԡ 0 ãË ¡ÅÒÂà» ¹Åͨԡ 1 â´Â¢Ò¾Íà µ¨Ð¶Ù¡¡íÒ˹´ãË à» ¹àÍÒµ ¾µØ 㹡óշ¢Õè Ò¾Íà µ·Õãè ª §Ò¹ÍÂÙã ¹âËÁ´ ÍÔ¹¾Øµ àÁ×Íè ¡ÃзíÒ¤íÒÊÑ§è ¨Ðà¡Ô´¼Å 2 »ÃСÒä×Í ¡ÅѺʶҹÐáÅÐà»ÅÕÂè ¹âËÁ´¨Ò¡ÍÔ¹¾Øµà» ¹àÍÒµ ¾µØ 㹺ҧ¡Ã³Õ ¡ÒÃ㪠¤Òí Êѧè TOGGLE ¨ÐäÁ Á¼Õ ŵ Í¡ÒÃà»ÅÕÂè ¹á»Å§Ê¶Ò¹Ð¢Í§¢Ò¾Íà µ ¡µÑÇÍ ҧ ã¹ ÊÀÒÇл¡µÔ¡Òí ˹´ãË ¢Ò P2 à» ¹ÍÔ¹¾ØµáÅе ͵Ñǵ Ò¹·Ò¹ 10k: ¾ÙÅÍÑ»äÇ áÅ Çà¢Õ¹â»Ãá¡ÃÁµ Í仹Õé DIR2 = 0 OUT2 = 0 DEBUG ? IN2 TOGGLE 2 DEBUG ? IN2

¢Ò¾Íà µ P2 ·íҧҹ໠¹ÍÔ¹¾Øµ ¢Ò¾Íà µ P2 ·íҧҹ໠¹àÍÒµ ¾µØ áÅТѺÅͨԡ 0 áÊ´§Ê¶Ò¹Ð¢Í§¢Ò¾Íà µ P2 ¼ Ò¹·Ò§Ë¹ Òµ Ò§ Debug Terminal ¡ÅѺâËÁ´¡Ò÷íÒ§Ò¹¢Í§¢Ò¾Íà µ P2 áÊ´§Ê¶Ò¹Ð¢Í§¢Ò¾Íà µ P2 ¼ Ò¹·Ò§Ë¹ Òµ Ò§ Debug Terminal

àÁ×Íè Ãѹâ»Ãá¡ÃÁ ʶҹТͧ¢Ò P2 ¨ÐäÁ à»ÅÕÂè ¹á»Å§ Âѧ¤§ÁÕʶҹÐà» ¹ 1 ÍÂÙ ·Ñ§é ¡ ͹·Õ¨è СÃзíÒ ¤íÒÊѧè TOGGLE áÅÐËÅѧ¨Ò¡·íÒ¤íÒÊѧè TOGGLE à¹×Íè §¨Ò¡¡Ò÷íÒ¤íÒÊѧè OUT2 = 0 ÂѧäÁ Á¼Õ ÅàÁ×Íè ¡íÒ˹´ãË ¢Ò 2 à» ¹¢ÒÍÔ¹¾ØµÍÂÙ à¾×Íè ãË á¹ ã¨Ç Òâ»Ãá¡ÃÁ·íÒ§Ò¹¶Ù¡µ ͧ ¨Ðµ ͧà¢Õ¹â»Ãá¡ÃÁãËÁ ´§Ñ ¹Õé OUT2 = IN2 TOGGLE 2

%&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


VAR ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè symbol VAR size

à» ¹¤íÒÊѧè à·ÕÂÁ㪠ÊÒí ËÃѺ¡íÒ˹´¢¹Ò´ËÃ×ͪ¹Ô´¢Í§µÑÇá»Ã ¾ÒÃÒÁÔàµÍà symbol à» ¹ª×Íè ¢Í§µÑÇá»Ã·Õµè Í §¡ÒáíÒ˹´ ¨Ðµ ͧ¢Ö¹é µ ¹´ ǵÑÇÍÑ¡ÉÃàÊÁÍ ª×Íè ¢Í§µÑÇá»ÃÊÒÁÒö¼ÊÁ ¡Ñ¹ä´ ·Ñ駵ÑÇÍÑ¡Éà µÑÇàÅ¢ ËÃ×Í¢Õ´Å Ò§ (underscore : _) áµ ¨Ðµ ͧäÁ µÃ§¡Ñºª×è͵ Í§Ë ÒÁ¢Í§â»Ãá¡ÃÁÀÒÉÒ¾ÕàºÊÔ¡ áÅе ͧäÁ µÃ§ËÃ×Í«éíҡѺª×èÍÅÒàºÅ«Öè§ãª 㹡ÒáíÒ˹´áÍ´à´ÃÊÀÒÂã¹â»Ãá¡ÃÁà´ÕÂǡѹ ÁÕ¤ÇÒÁÂÒÇä´ ÊÙ§ÊØ´ 32 µÑÇÍÑ¡Éà áÅÐäÁ ʹã¨ã¹àÃ×Íè §¢Í§µÑǾÔÁ¾ àÅç¡ËÃ×͵ÑǾÔÁ¾ ãË­ size à» ¹ª×Íè ¢Í§¢¹Ò´¢Í§¢ ÍÁÙÅ·Õµè Í §¡Òà ÊÒÁÒö¡íÒ˹´ä´ 4 ¢¹Ò´¤×Í ºÔµ (bit), ¹ÔºàºÔÅËÃ×͹Ժ (nib : 4 ºÔµ), 亵 (byte : 8 ºÔµ) áÅÐàÇÔô (word : 16 ºÔµ) ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè var MOUSE VAR BIT

à» ¹¡ÒáíÒ˹´µÑÇá»ÃÃдѺºÔµª×Íè MOUSE ÁÕ¢Í ÁÙÅ 2 ¤ Ò¤×Í 0 áÅÐ 1 CAT VAR NIB

à» ¹¡ÒáíÒ˹´µÑÇá»ÃÃдѺ¹ÔºàºÔŪ×Íè CAT ÁÕ¢Í ÁÙÅ 16 ¤ ҵѧé áµ 0 ¶Ö§ 15 (°Ò¹ÊÔº) ËÃ×Í 0000 ¶Ö§ 1111 (°Ò¹Êͧ) áÅÐ $0 ¶Ö§ $F (°Ò¹ÊԺˡ) DOG VAR BYTE

(°Ò¹ÊԺˡ)

à» ¹¡ÒáíÒ˹´µÑÇá»ÃÃдѺ亵 ªÍ×è DOG ÁÕ¢Í ÁÙÅ 256 ¤ Ò¤×Í 0 ¶Ö§ 255 (°Ò¹ÊÔº) áÅÐ $00 ¶Ö§ $FF RHINO VAR WORD

à» ¹¡ÒáíÒ˹´µÑÇá»ÃÃдѺàÇÔà ´ª×èÍ RHINO ÁÕ¢ ÍÁÙÅ 65,536 ¤ Ò¤×Í 0 ¶Ö§ 65,535 (°Ò¹ÊÔº) ËÃ×Í $0000 ¶Ö§ $FFFF Í ҧäáçµÒÁÊÒÁÒö¡íÒ˹´¡ÅØ Á¢Í§µÑÇá»Ãã¹ÅѡɳÐÍÐàà(arrey) ä´ â´Â¡ÒÃãÊ ¨íҹǹ¢Í§ ¡ÅØÁ ¢ ÍÁÙÅã¹Ç§àÅ纵 ͨҡª×Íè ¢Í§¢¹Ò´µÑÇá»Ã â´ÂÁÕû٠Ẻ´Ñ§¹Õé SYMBOL VAR SIZE(n)

â´Â·Õè SYMBOL áÅÐ SIZE ÁÕ¤ÇÒÁËÁÒÂàËÁ×͹à´ÔÁ Ê Ç¹ (n) ·Õµè Í · Ò SIZE à» ¹¡íÒ˹´¨íҹǹ ¡ÅØÁ ¢ ÍÁÙÅ·Õãè ª ªÍ×è à´ÕÂǡѹ ´Ñ§µÑÇÍ ҧ MYLIST VAR BYTE(10) Create a 10-byte array.

à» ¹¡ÒáíÒ˹´µÑÇá»ÃÃдѺ亵 ªÍ×è MYLIST ¨íҹǹ 10 亵 µÍ à¹×Íè §¡Ñ¹

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%'


WRITE ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè WRITE address,byte

à¢Õ¹¢ ÍÁÙÅ 1 亵 ŧã¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍ¾Õ ÃÍÁ ¾ÒÃÒÁÔàµÍà address à» ¹µÑÇá»ÃËÃ×ͤ Ò¤§·Õè 㪠¡Òí ˹´áÍ´à´Ãʢͧ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ ÁÕ¤Ò µÑ§é áµ 0-2047 byte à» ¹¤ Ңͧ¢ ÍÁÙÅ·Õµè Í §¡ÒÃà¢Õ¹ ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁã¹ i-Stamp2P24 ·íÒ˹ Ò·Õàè ¡çº·Ñ§é â»Ãá¡ÃÁ (program storage)áÅТ ÍÁÙÅ (data storage) â´Ââ»Ãá¡ÃÁ¨Ðà¡çºã¹áÍ´à´ÃÊ ͹¡ÅѺ¨Ò¡áÍ´à´ÃÊÊØ´· Ò·յè Òí á˹ § 2047 ¶ÍÂËÅѧÁÒàÃ×Íè Âæ ã¹¢³Ð·Õ¢è Í ÁÙŨÐàÃÔÁè à¡çº¨Ò¡áÍ´à´ÃÊ 0 Í ҧäáçµÒÁ¡ÒÃà¢Õ¹¢ ÍÁÙÅŧã¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍ¾Õ ÃÍÁ´ Ç ¤íÒÊѧè WRITE ¨ÐÁÕ¤ÇÒÁᵡµ Ò§¨Ò¡¡ÒÃà¢Õ¹¢ ÍÁÙÅŧã¹Ë¹ ǤÇÒÁ¨íÒáÃÁËÃ×ÍÃÕ¨ÊÔ àµÍà ÍÂÙº Ò§»ÃСÒä×Í 1. ¡ÒÃà¢Õ¹¢ ÍÁÙÅŧã¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍ¾Õ ÃÍÁ¨Ð㪠àÇÅÒÂÒǹҹ¡Ç Ò â´ÂÍҨ㪠àÇÅÒ¹Ò¹ à» ¹ÁÔÅÅÔÇ¹Ô Ò·Õ «Ö§è ¹ÑºÇ Ò㪠àÇÅÒÁÒ¡ÊíÒËÃѺÃкº§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà 2. ¢ ͨíÒ¡Ñ´àÃ×èͧ¨íҹǹÃͺ¢Í§¡ÒÃà¢Õ¹ ˹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍÕ¾ÃÍÁã¹ i-Stamp2P24 ¨ÐÊÒÁÒöÃͧÃѺ¡ÒÃà¢Õ¹·ÕÊè ÁºÙó ä´ 100,000 Ãͺµ Í˹ ǤÇÒÁ¨íÒ 1 亵 áµ äÁ Á¢Õ Í ¨íҡѴ㹡ÒÃÍ Ò¹ 3. à¹×Íè §¨Ò¡ã¹ i-Stamp2P24 㪠¾¹×é ·Õ¢è ͧ˹ ǤÇÒÁ¨íÒâ»Ãá¡ÃÁáÅТ ÍÁÙÅà ÇÁ¡Ñ¹ÍÂÙ ´Ñ§¹Ñ¹é ã¹¢³Ð·íÒ¡ÒþѲ¹Òâ»Ãá¡ÃÁ áÅÐÁÕ¡ÒÃà¢Õ¹¢ ÍÁÙÅÅ§ã¹¾×¹é ·ÕÊè Ç ¹¢ ÍÁÙŢͧ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ µ ͧÃÐÁÑ´ÃÐÇѧ Í ÒãË ¢Í ÁÙŢͧâ»Ãá¡ÃÁáÅТ ÍÁÙŨÃÔ§æ ÁҷѺ« ͹¡Ñ¹Í ҧà´ç´¢Ò´ «Ö§è ÊÒÁÒö·íÒä´ â´Â¡ÒÃËÁÑ¹è µÃǨÊͺ¡Òà ¨Ñ´ÊÃÃ˹ ǤÇÒÁ¨íÒ â´Âä»·Õàè Á¹Ù RUN àÅ×Í¡ Memory map ˹ Òµ Ò§áÊ´§¡ÒèѴÊÃÃ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ¨Ð »ÃÒ¡¯¢Ö¹é ÁÒ

¡Ò÷´Åͧ Í·Õè 26 ¡ÒÃ㪠¤Òí Êѧè WRITE (1) 㪠ǧ¨ÃµÒÁÃÙ»·Õè 3-25 㹡Ò÷´Åͧ (2) à¢Õ¹â»Ãá¡ÃÁµ Í仹Õé '*****PRELAB2P24-26.BSP : WRITE command demonstration***** ' {$STAMP BS2p} ' {$PBASIC 2.5} RESULT VAR Word ' Word variable for RCtime result. EEADDR VAR Word ' Address of EEPROM storage locations. SAMPLES CON 10 ' Number of samples to get. LOG DATA (samples) ' Set aside EEPROM for samples. ENDLOG CON LOG+SAMPLES-1 ' End of allocated EEPROM.

&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


+5V C1 0.1PF

R1 220

P14

i-Stamp2P24

LDR1

ÃÙ»·Õè 3-25 ǧ¨ÃÊíÒËÃѺ·´Åͧ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè RCTIME FOR EEADDR = LOG TO ENDLog ' Store each sample in EEPROM. HIGH 14: PAUSE 1 ' Charge the cap. RCTIME 14,1,RESULT ' Measure resistance. RESULT = RESULT*42/100 ' Scale to fit one byte (0-255) DEBUG "Storing ",DEC RESULT,TAB," at ",DEC EEADDR,CR WRITE EEADDR,RESULT ' Store it in EEPROM PAUSE 1000 ' Wait a second. NEXT ' Do until all samples done. PAUSE 2000: DEBUG CLS ' Wait 2 seconds, then clear screen. FOR EEADDR = LOG TO ENDLOG ' Retrieve each sample from EEPROM. READ EEADDR,RESULT ' Read back a byte DEBUG "ReadingEEASR. ",DEC RESULT ," at ",DEC EEaddr,CR NEXT ' Do until all samples retrieved. STOP

â»Ãá¡ÃÁ¹ÕÁé ¨Õ ´Ø »ÃÐʧ¤ à¾×Íè à¡çº¤ Ò¤ÇÒÁµ Ò¹·Ò¹ã¹·Ø¡æ 1 ÇÔ¹Ò·Õ â´Â㪠¤ÇÒÁÊÒÁÒö¢Í§¤íÒÊѧè RCTIME ÇÑ´¤ Ò¤ÇÒÁµ Ò¹·Ò¹·Õµè Í ¡Ñº¢Ò¾Íà µ¢Í§ i-Stamp2P24 ¨Ò¡¹Ñ¹é ¹íÒ¤ ÒÁÒà¢Õ¹ŧã¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕÍ¾Õ ÃÍÁ (3) Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é ¾Ã ÍÁ¡ÑºáÊ´§¢ ͤÇÒÁ Storing (¤ Ңͧ RESULT ·Õäè ´ ¨Ò¡¤íÒÊѧè RCTIME) at (µíÒá˹ §Ë¹ ǤÇÒÁ¨íÒÍÕ; Õ ÃÍÁ ÁÕ¤Ò 0 ¶Ö§ 9) ·Ø¡ÇÔ¹Ò·Õ¨ÐÁÕ¡ÒÃà¡çº¤ Ò RCTIME ŧã¹Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ ¨¹¤Ãº 10 µíÒá˹ § ¨Ò¡¹Ñ¹é Í Ò¹¤ Ò ¡ÅѺÍÍ¡ÁÒáÊ´§·ÕËè ¹ Òµ Ò§ Debug Terminal ´ Ç¢ ͤÇÒÁ ReadingEEADDR (¤ Ңͧ RESULT ·ÕèÍ Ò¹¡ÅѺ¨Ò¡Ë¹ ǤÇÒÁ¨íÒÍÕÍÕ¾ÃÍÁ) at (µíÒá˹ §¢Í§Ë¹ ǤÇÒÁ¨íÒÍÕ; Õ ÃÍÁ ÁÕ¤Ò 0-9) (4) ·´Åͧ㪠ÁÍ× ºÑ§áʧ·Õµè ¡¡Ãзº LDR áÅ ÇÊѧࡵ¡ÒÃà»ÅÕÂè ¹á»Å§¢Í§¢ ÍÁÙÅ·Õàè ¡Ô´¢Ö¹é Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&


XOUT ÃٻẺ¡ÒÃ㪠§Ò¹¤íÒÊѧè XOUT mpin,zpin,[house\keyOrCommand{\cycles}{,house\keyOrCommand{\cycles}...}]

㪠ʧ ¤íÒÊÑ§è ¤Çº¤ØÁà¤Ã×Íè §ãª ä¿¿ Ò¼ Ò¹ÊÒÂä¿¿ ÒÊÅѺµÒÁÁҵðҹ X-10 ¨Ðµ Í§Ê §¤íÒÊÑ§è ¼ Ò¹ÍØ»¡Ã³ àª×Íè Áµ ÍÊÒÂä¿¿ ÒÊÅѺ ¾ÒÃÒÁÔàµÍà mpin à» ¹¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õãè ª ÊÒí ËÃÑºÊ §¢ ÍÁÙŤíÒÊѧè àÁ×Íè ¡ÃзíÒ¤íÒÊÑ§è ¹Õé ¢Ò¾Íà µ¨Ð·íÒ§Ò¹ à» ¹àÍÒµ ¾Øµ zpin à» ¹¢Ò¾Íà µ¢Í§ i-Stamp2P24 㪠ÊÒí ËÃѺÃѺÊÑ­­Ò³¨Ø´ª¹Ç¹·Õ¨è ´Ø Èٹ (zero-crossing) ¨Ò¡ÍØ»¡Ã³ àª×Íè Áµ ÍÊÒÂä¿¿ ÒÊÅѺ à¾×Íè ¡Ãеع à¤Ã×Íè §ãª ä¿¿ ÒãË ·Òí §Ò¹·ÕÁè ÁØ Èٹ ¾Í´Õ àÁ×Íè ¡ÃзíÒ¤íÒÊÑ§è ¹Õé ¢Ò¾Íà µ¨Ð·íҧҹ໠¹ÍÔ¹ ¾Øµ house à» ¹ÃËÑʢͧÍØ»¡Ã³ ä¿¿ Ò·Õãè ª Áҵðҹ¡ÒäǺ¤ØÁẺ X-10 ÁÕ¤Ò µÑ§é áµ 0 ¶Ö§ 15 㪠᷹µÑÇÍÑ¡Éà A ¶Ö§ P keyOrCommand à» ¹¢ ÍÁÙŤíÒÊѧè cycles à» ¹Ê ǹà¾ÔèÁàµÔÁ㪠㹡óշÕèµ Í§¡ÒáíÒ˹´Ãͺ¢Í§¡ÒÃÊ §ÃËÑÊËÃ×Í¢ ÍÁÙŤíÒÊÑè§ ËÒ¡äÁ ÁÕ ¡ÒáíÒ˹´¤ Ò cycles i-Stamp2P24 ¨Ð¡íÒ˹´ãË Á¤Õ Ò à· Ò¡Ñº 2 ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ Í ҧäáçµÒÁ ÊíÒËÃѺ¡ÒÃÊ×Íè ÊÒÃã¹Áҵðҹ X-10 ÂѧäÁ Á¡Õ ÒÃ㪠§Ò¹ã¹»ÃÐà·Èä·Â à¹×Íè §¨Ò¡¤ÇÒÁ¶Õè ¢Í§ä¿¿ Ò¡ÃÐáÊÊÅѺ·Õè㪠໠¹¤Å×è¹¾ÒË ÊíÒËÃѺ¶ Ò·ʹ¢ ÍÁÙÅã¹Áҵðҹ X-10 ¹Õé෠ҡѺ 60Hz ã¹¢³Ð·Õè ¤ÇÒÁ¶Õ¢è ͧ俿 ÒÊÅѺ㹻ÃÐà·Èä·Â¤×Í 50Hz ´Ñ§¹Ñ¹é ¨Ö§Í¸ÔºÒÂà¾Õ§ÀÒ¾¡Ç Ò§æ ¢Í§¤íÒÊѧè Xout à¾Õ§෠ҹÕé ÊíÒËÃѺÃÒÂÅÐàÍÕ´à¾ÔèÁàµÔÁ¢Í§¤íÒÊÑè§ XOUT áÅÐÁҵðҹ X-10 ÊÒÁÒö´Ùä´ ¨Ò¡¤ÙÁ Í× ©ºÑºÀÒÉÒÍѧ¡ÄÉ ¢Í§ Parallax «Ö§è ´Òǹ âËÅ´ä´ ¨Ò¡àǺ䫵 ¢Í§ Parallax ·Õè http://www.parallax.com

&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


º··Õè 4

ªØ´¤íÒÊÑ§è ·Ò§¤³ÔµÈÒʵà áÅÐÅͨԡ ¢Í§àºÊÔ¡áʵÁ» 2P ¡ÒûÃÐÁÇżŷҧ¤³ÔµÈÒʵà áÅÐÅͨԡ¢Í§äÁâ¤Ã¤Í¹â·ÃÅàÅÍà àºÊÔ¡áʵÁ» 2P ËÃ×Í i-Stamp2P24 Ạ§ÍÍ¡à» ¹ 2 ª ǧàÇÅÒ¤×Í 1. »ÃÐÁÇżÅâ´Â¡Ãкǹ¡ÒäÍÁä¾Å ã¹¢³Ð·Õ·è Òí ¡ÒÃà¢Õ¹â»Ãá¡ÃÁ 2. »ÃÐÁÇżÅâ´ÂµÑÇàºÊÔ¡áʵÁ» 2P ËÃ×Í i-Stamp2P24 àͧ㹢³Ð·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ ´Ñ§µÑÇÍ ҧµ Í仹Õé FIRST CON 3 SECOND CON FIRST*2-1 ·íÒ¡Òäíҹdz¤ Òâ´Â¡Ãкǹ¡ÒäÍÁä¾Å ·¹Ñ ·Õ (compile time) ¹íÒ¤ Ңͧ FIRST ¤Ù³´ Ç 2 áÅ Ç Åº´ Ç 1 ´Ñ§¹Ñ¹é ¤ Ңͧ SECOND àÁ×Íè ¤ÍÁä¾Å áŠǨÐ෠ҡѺ 5 THIRD CON 100+90 ·íÒ¡Òäíҹdz¤ Òâ´Â¡Ãкǹ¡ÒäÍÁä¾Å ·¹Ñ ·Õ ´Ñ§¹Ñ¹é ¤ Ңͧ THIRD àÁ×Íè ¤ÍÁä¾Å áŠǨÐ෠ҡѺ 190 B1 = SECOND ¤ Ңͧ B1 ෠ҡѺ 5 «Ö§è à» ¹¼ÅÅѾ¸ ·äÕè ´ ¨Ò¡¡Òäíҹdz㹡Ãкǹ¡ÒäÍÁä¾Å B2 = 99+B1 ¤ Ңͧ B2 ෠ҡѺ 99+5 = 104 ¤íҹdz´ Ç i-Stamp2P24 ã¹¢³ÐÃѹâ»Ãá¡ÃÁ (run time) W1 = THIRD ¤ Ңͧ W1 ෠ҡѺ 190 ä´ ÁÒ¨Ò¡¡Òäíҹdz㹡Ãкǹ¡ÒäÍÁä¾Å W2 = 100+90 ¤ Ңͧ W2 ෠ҡѺ 190 ä´ ¨Ò¡¡Òäíҹdzâ´Â i-Stamp2P24 ã¹¢³ÐÃѹâ»Ãá¡ÃÁ ¨Ò¡µÑÇÍ ҧ¨ÐàËç¹ä´ Í ҧªÑ´à¨¹Ç Ò ¡ÒûÃÐÁÇżŷҧ¤³ÔµÈÒʵà ¢Í§ i-Stamp2P24 ÊÒÁÒö¡ÃзíÒ ä´ ¨Ò¡·Ñ駡ÒäÍÁä¾Å áÅСÒÃÃѹâ»Ãá¡ÃÁâ´ÂµÃ§ ᵠ㹡Òäíҹdz¼ Ò¹¡ÒäÍÁä¾Å ¹Ñ鹨ÐÁÕ¢ ͨíÒ¡Ñ´¤×Í ÊÒÁÒö¡ÃзíÒä´ ¡ºÑ ¤ Ò¤§·Õè ËÃ×͵ÑÇá»Ã·Õ¡è Òí ˹´ãË Á¤Õ Ò ¤§·Õàè · ҹѹé

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&!


4.1 ÅíҴѺ㹡Òäíҹdz 㹡óշÕèÁÕ¡ÒäíҹdzËÅÒÂÇÔ¸ÕÃÇÁ¡Ñ¹ ઠ¹ ÁÕ·Ñ駡ÒúǡáÅÐź ËÃ×ͼÊÁ¡Ñ¹·Ñ駺ǡ,¤Ù³ áÅÐËÒà ¨Ðµ ͧ¨Ñ´ÅíҴѺ¡ÒûÃÐÁÇżÅãË ´Õ à¾×Íè » ͧ¡Ñ¹¡ÒÃà¢Õ¹â»Ãá¡ÃÁ¼Ô´¾ÅÒ´ ¶ Òà» ¹¡ÒúǡáÅÐź äÁ ÇÒ ¨Ð¡ÃзíÒ¤íÒÊѧè ã´¡ ͹ËÅѧ ¼ÅÅѾ¸ ·äÕè ´ ¨Ð෠ҡѹ áµ ¶Ò ËÒ¡ÁÕ¡ÒäٳáÅÐ ËÒÃࢠÒÁÒà ÇÁ´ Ç ¡ÒèѴÅíҴѺ㹡Òäíҹdz໠¹ÊÔè§ÊíҤѭ à¹×èͧ¨Ò¡¼ÅÅѾ¸ ¨Ðᵡµ Ò§¡Ñ¹ ¶ ÒËÒ¡¨Ñ´ÅíҴѺ ¡ÒäíҹdzäÁ àËÁ×͹¡Ñ¹ ¡µÑÇÍ ҧ 2+3*2/4 àºÊÔ¡áʵÁ» ¨Ð·íÒ¡Òúǡ 2 ¡Ñº 3 ¡ ͹ áŠǤٳ´ Ç 2 ¨Ò¡¹Ñ¹é ¨Ö§ËÒà 4 ¼ÅÅѾ¸ ¢Í§¡Òäíҹdzã¹áµ ¢¹Ñé µÍ¹à» ¹´Ñ§¹Õé 2 + 3 = 5 µ Í´ Ç 5 * 2 = 10 áÅÐ 10 / 4 = 2 ¼ÅÅѾ¸ ෠ҡѺ 2 ·Ñ§é ¹Õàé ¹×Íè §¨Ò¡ i-Stamp2P24 ÊÒÁÒö»ÃÐÁÇżÅä´ ¡ºÑ àÅ¢¨íҹǹàµçÁ෠ҹѹé ã¹¢³Ð·ÕÅè Òí ´Ñº¡Òäíҹdzã¹â»Ãá¡ÃÁÀÒÉÒàºÊÔ¡·ÑÇè ä» ¨Ð·íÒ¡ÒäٳËÃ×ÍËÒá ͹ ¨Ò¡¹Ñ¹é ¨Ö§ºÇ¡áÅРź ´ ÇÂ⨷ à´ÕÂǡѹ Ëҡ㪠â»Ãá¡ÃÁÀÒÉÒàºÊÔ¡¤íҹdzâ´Â¤Ô´à©¾ÒШíҹǹàµçÁ ¨Ðä´ ¼ÅÅѾ¸ ෠ҡѺ 13 ´Ñ§¹Ñ¹é ËÒ¡µ ͧ¡ÒÃãË i-Stamp2P24 ¤íҹdz⨷ ·ÁÕè ÇÕ ¸Ô ¡Õ ÒÃÁÒ¡¡Ç Ò˹֧è ÇÔ¸Õ ¤ÇÃãÊ à¤Ã×Íè §ËÁÒÂǧàÅçºà¾×Íè ¡íÒ˹´ÅíҴѺ¡Òäíҹdz¡ ͹ËÅѧ ËÒ¡ÁÕËÅÒÂǧàÅçº i-Stamp2P24 ¨Ð¤íҹdz¨Ò¡Ç§àÅçºã¹ÊØ´ÍÍ¡ÁÒÂѧǧàÅ纹͡ ÊØ´ â´ÂÁÕ¢Í ¨íÒ¡Ñ´¤×Í ÊÒÁÒö¤íÒ¹Ç³ä´ ÁÒ¡·ÕÊè ´Ø 8 ªÑ¹é ¡µÑÇÍ ҧ 2 + ((3*2)/4) ¨Ò¡â¨·Â ¹Õé i-Stamp2P24 ¨Ð¤Ù³ 3 ´ Ç 2 à» ¹ÅíҴѺáá ¨Ò¡¹Ñ¹é ¨Ö§ËÒüŠ¤Ù³·Õäè ´ ´Ç  4 áÅÐÊØ´· Òºǡ´ Ç 2 ¨Ðä´ ¼ÅÅѾ¸ ÍÍ¡ÁÒã¹·ÕÊè ´Ø ÊÃØ»ä´ ÇÒ i-Stamp2P24 ¨Ð»ÃÐÁÇÅ·Ò§¤³ÔµÈÒʵà àÃÕ§ÅíҴѺ¨Ò¡« ÒÂ仢ÇÒ äÁ ÇÒ ¨ÐàÃÔÁè ´ ÇÂÇÔ¸¡Õ ÒÃã´¡ ͹ ¡çµÒÁ àÇ ¹áµ ¨ÐÁÕ¡ÒÃ㪠ǧàÅçºà¾×Íè ¡íÒ˹´ÅíҴѺ㹡Òäíҹdz ¶ ÒËÒ¡ÁÕËÅÒÂǧàÅçº ¨Ð¤íҹdz¨Ò¡Ç§àÅçºã¹ÊØ´ÍÍ¡ ÁÒ¡ ͹

4.2 ¤íÒÊÑ§è ·Ò§¤³ÔµÈÒʵà ẺÂÙ¹ÒÃÕ à» ¹¤íÒÊÑ§è ·Ò§¤³ÔµÈÒʵà ·ãÕè ª ¢Í ÁÙÅà¾Õ§ 1 µÑÇ㹡ÒáÃзíÒ¤íÒÊѧè ËÃ×Í ÂÙ¹ÒÃÕâÍà»ÍàÃàµÍà (unary operator) ÁÕ´Ç Â¡Ñ¹ 6 ¤íÒÊÑ§è ¤×Í ABS à» ¹¤íÒÊÑ觷Õè¡íÒ˹´ãË »ÃÐÁÇżÅ੾ÒФ Ңͧ¢ ÍÁÙŵÑÇàŢẺäÁ ¤Ô´à¤Ã×èͧËÁÒ SQR à» ¹¤íÒÊÑ觶ʹÃÒ¡·ÕèÊͧ DCD à» ¹¤íÒÊѧè àÅ×͡૵ºÔµ·Õµè Í §¡Òâͧ¢ ÍÁÙÅ¢¹Ò´ 16 ºÔµ NCD à» ¹¤íÒÊѧè áÊ´§ºÔµ¹ÑÂÊíҤѭ¢Í§¢ ÍÁÙÅ¢¹Ò´ 16 ºÔµ ~ ËÁÒ¶֧ ¤íÒÊÑ§è ¤ÍÁ¾ÅÕàÁ¹µ ËÃ×Í¡ÅѺ¢ ÍÁÙÅã¹ÃдѺºÔµ SIN à» ¹¤íÒÊÑ§è ¤íҹdz¤ Ò SINE ·Ò§µÃÕ⡳ÁÔµÔ COS à» ¹¤íÒÊÑ§è ¤íҹdz¤ Ò COSINE ·Ò§µÃÕ⡳ÁÔµÔ ÊíÒËÃѺÃÒÂÅÐàÍÕ´áÅеÑÇÍ ҧ¡ÒÃ㪠¤íÒÊÑè§áµ ÅФíÒÊÑè§Áմѧ¹Õé

&"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


ABS 㪠㹡ÒÃá»Å§¤ ÒµÑÇàŢẺ¤Ô´à¤Ã×èͧËÁÒÂà» ¹áººäÁ ¤Ô´à¤Ã×èͧËÁÒÂËÃ×ÍàÃÕÂ¡Ç Ò ¤ ÒÊÑÁºÙó (absolute) ´Ñ§¹Ñ¹é ËÅѧ¨Ò¡¡ÃзíÒ¤íÒÊÑ§è ¹Õ¢é Í ÁÙÅ·Õäè ´ ¨Ðà» ¹¤ ҺǡàÊÁÍ ÍÒ·Ô ¤ Ò -99 àÁ×Íè ·íÒà» ¹¤ ÒÊÑÁºÙó ¨Ð ෠ҡѺ 99 ÍÒ¨¡Å ÒÇä´ ÇÒ ¤íÒÊѧè ABS 㪠㹡ÒõѴà¤Ã×Íè §ËÁÒÂźÍÍ¡¨Ò¡µÑÇàÅ¢µÔ´Åº ·íÒãË ¡ÅÒÂà» ¹ºÇ¡ Êѧࡵ¼Å¡ÒáÃзíÒ¤íÒÊѧè ABS ¨Ò¡â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = -99 DEBUG SDEC ? W1 W1 = ABS W1 DEBUG SDEC ? W1

' ¡íÒ˹´¤ Ò -99 ãË ¡ºÑ µÑÇá»Ã W1 ' áÊ´§¤ Ңͧ W1 Ẻ¤Ô´à¤Ã×Íè §ËÁÒ ' ¡ÃзíÒ¤íÒÊѧè ABS ¡Ñº¤ Ңͧ W1 ' áÊ´§¤ Ңͧ W1 Ẻ¤Ô´à¤Ã×Íè §ËÁÒ ËÅѧ¨Ò¡¡ÃзíÒ¤íÒÊѧè ABS

àÁ×Íè Ãѹâ»Ãá¡ÃÁ 㹺Ã÷Ѵáá¢Í§Ë¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¼Å¢Í§â»Ãá¡ÃÁ㹺Ã÷Ѵ·ÕÊè ͧ ¤×Í DEBUG SDEC ? W1 áÊ´§¤ Ò -99 ÍÍ¡ÁÒ áµ ËÅѧ¨Ò¡¼ Ò¹¡ÒáÃзíÒ¤íÒÊѧè ABS áÅ Ç ¨ÐáÊ´§¤ Òà» ¹ 99

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&#


SQR

à» ¹¤íÒÊÑ§è ¶Í´ÃÒ¡·ÕÊè ͧ¢Í§µÑÇàÅ¢·Õ¡è Òí ˹´µ Í· Ò¤íÒÊÑ§è ¹Õé â´ÂµÑÇàÅ¢·Õ¹è Òí ÁҶʹÃÒ¡·ÕÊè ͧ¹Ñ¹é µ ͧäÁ ÁÕ à¤Ã×Íè §ËÁÒÂËÃ×Íà» ¹àÅ¢¨íҹǹàµçÁºÇ¡à· ҹѹé áµ ¢Í ¨íҡѴ㹡Ò÷íÒ¤íÒÊÑ§è ¹Õ¢é ͧ i-Stamp2p24 ¤×Í äÁ ÊÒÁÒöáÊ´§ ¤ ҷȹÔÂÁ·Õäè ´ ¨Ò¡¡ÒöʹÃÒ¡·ÕÊè Í§ä´ ´Ñ§áÊ´§µÑÇÍ ҧ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊÑ§è ¹Õ´é Ç Ââ»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} DEBUG ? SQR 100 DEBUG ? SQR 99

ãË áÊ´§¤ Ңͧ¡ÒöʹÃÒ¡·ÕÊè ͧ¢Í§ 100 (¼ÅÅѾ¸ ෠ҡѺ 10) ãË áÊ´§¤ Ңͧ¡ÒöʹÃÒ¡·ÕÊè ͧ¢Í§ 99

¨Ò¡¡ÒÃÃѹâ»Ãá¡ÃÁ㹺Ã÷Ѵ DEBUG SQR 99 ¤ Ò·Õáè Ê´§ã¹Ë¹ Òµ Ò§ Debug Terminal ¨Ðà» ¹ 9 ·Ñ§é ·Õ¤è Òí µÍº·Õ¶è ¡Ù µ ͧ¤×Í 9.95 áµ à¹×Íè §¨Ò¡ i-Stamp2P24 äÁ ÊÒÁÒöáÊ´§¤ ҷȹÔÂÁä´ ¨Ö§áÊ´§¼Åà¾Õ§àÅ¢ 9 à· Ò ¹Ñ¹é â´ÂäÁ Á¡Õ Òû ´¤ ҷȹÔÂÁáµ Í ҧã´

DCD

à» ¹¤íÒÊÑè§ãª 㹡ÒÃ૵ºÔµ·Õèµ Í§¡Òâͧ¢ ÍÁÙÅ¢¹Ò´ 16 ºÔµ áÅкԵ·ÕèàËÅ×Í¡ÅÒÂà» ¹ 0 ·Ñé§ËÁ´ â´ÂµÑÇàÅ¢·Õãè ª ¡Òí ˹´ºÔµ·Õµè Í §¡ÒÃ૵¨ÐÁÕ´Ç Â¡Ñ¹ 16 µÑǤ×Í 0 ¶Ö§ 15 ´Ñ§â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = 10 DEBUG BIN ? W1 W1 = DCD 12 DEBUG BIN ? W1

&$

¡Ó˹´ãËé૵ºÔµ 12 ¢Í§¢éÍÁÙÅ W1 áÊ´§¤ Ңͧ W1 ã¹ÃÙ»¢Í§àÅ¢°Ò¹Êͧ¼ ҹ˹ Òµ Ò§ Debug Terminal

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


NCD à» ¹¤íÒÊѧè áÊ´§ºÔµ¹ÑÂÊíҤѭÊÙ§ÊØ´¢Í§¢ ÍÁÙÅ¢¹Ò´ 16 ºÔµ ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè ÍÒ¨¨ÐäÁ à» ¹·Õ¤è ¹Ø à¤ÂÁÒ¡¹Ñ¡ â´ÂàÁ×Íè ¡ÃзíÒ¤íÒÊÑ§è ¹Õé ¨Ð·íÒ¡ÒõÃǨÊͺ¢ ÍÁÙŵÑÇàÅ¢·Õµè Í · Ò¤íÒÊÑ§è ¹ÕÇé Ò ÁÕºµÔ ã´à» ¹ 1 ËÃ×ÍäÁ ¶ ÒÁÕºµÔ ·Õàè » ¹ 1 ºÔµã´à» ¹ºÔµ·ÕÁè ¹Õ ÂÑ ÊíҤѭÊÙ§ÊØ´ ¨Ò¡¹Ñ¹é ºÇ¡¤ Òà¾ÔÁè Íա˹֧è ¡µÑÇÍ ҧ ¢ ÍÁÙÅ 1100 ºÔµ·Õàè » ¹ 1 ÁÕ 2 ºÔµ¤×Í ºÔµ 3 áÅкԵ 2 áµ ºµÔ ·ÕÁè ¹Õ ÂÑ ÊíҤѭÊÙ§ÊØ´¤×Í ºÔµ 3 ¨Ðä´ ¤Ò 3 ÍÍ¡ÁҺǡ´ Ç 1 ¡ÅÒÂà» ¹ 4 ´Ñ§¹Ñ¹é ËÅѧ¨Ò¡¡ÃзíÒ¤íÒ ÊÑ§è ¹Õ¨é Ðä´ ¼ÅÅѾ¸ ÍÍ¡ÁÒà» ¹ 4 à» ¹¡ÒÃáÊ´§ãË ·ÃÒºÇ Ò ¢ ÍÁÙÅ¹Õºé µÔ ·Õàè » ¹ 1 ºÔµã´ÁÕ¹ÂÑ ÊíҤѭÊÙ§ÊØ´ à¾Õ§¹íÒ ¼ÅÅѾ¸ ·äÕè ´ ¹ÅÕé º´ ÇÂË¹Ö§è ¡ç¨Ð·ÃÒººÔµ·Õàè » ¹ 1 ·ÕÁè ¹Õ ÂÑ ÊíҤѭÊÙ§ÊØ´ 㹡óշàÕè » ¹ 0 ·Ñ§é ËÁ´ËÅѧ¨Ò¡¡ÃзíÒ¤íÒÊѧè NCD ¨Ðä´ ¤Ò ÍÍ¡ÁÒà» ¹ 0 â»Ãá¡ÃÁµÑÇÍ ҧáÊ´§¡Ò÷íÒ§Ò¹ÁÕ´§Ñ ¹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = %1101 ' ºÔµ¹ÑÂÊíҤѭÊÙ§ÊØ ´·Õàè «µà» ¹ 1 ¤×ͺԵ 3 DEBUG ? NCD W1 ' áÊ´§¤ Ò NCD ¢Í§ W1 »ÃÐ⪹ ¢Í§¤íÒÊÑ§è ¹Õ¤é Í× ª ÇÂãË ¡ÒõÃǨÊͺ¢¹Ò´¢Í§¢ ÍÁÙÅÊÒÁÒö·íÒä´ àÃçÇ·ÕÊè ´Ø ¨Ò¡µÑÇÍ ҧ¡ ͹˹ Ò ¹Õé ´ Ç¡ÒÃ㪠¤Òí Êѧè NCD µÃǨÊͺ¢ ÍÁÙÅ W1 ·íÒãË ·Ã񼊫 ÇÒ ¢ ÍÁÙÅã¹ W1 ÁÕ¢¹Ò´ 4 ºÔµ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&%


~ ËÁÒ¶֧ ¤íÒÊÑ§è ¤ÍÁ¾ÅÕàÁ¹µ (complement) ËÃ×ͤíÒÊÑ§è ¡ÅѺʶҹÐÅͨԡ¢Í§¢ ÍÁÙÅÃдѺºÔµ ËÒ¡¢ ÍÁÙÅ à´ÔÁÁÕ¤ Ò෠ҡѺ 00110011 àÁ×èÍ¡ÃзíÒ¤íÒÊÑ觹Õé ¢ ÍÁÙŨÐà»ÅÕè¹໠¹ 11001100 â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé áÊ´§ãË àË繶֧¡ÒÃàÃÕ¡㪠áÅмšÒ÷íÒ§Ò¹¢Í§¤íÒÊÑ觹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} B1 = % 11110001 DEBUG BIN ? B1 B1 = ~B1 DEBUG BIN ? B1

' ¡íÒ˹´¢ ÍÁÙÅ 1 亵 ã¹ÃÙ»¢Í§àÅ¢°Ò¹ÊͧãË á¡ µÇÑ á»Ã b1 ' áÊ´§¤ Ңͧ B1 ã¹ÃÙ»àÅ¢°Ò¹Êͧº¹Ë¹ Òµ Ò§ Debug ' ·íÒ¡ÒáÅѺ¢ ÍÁÙÅ B1 ËÃ×Í·íÒ¤ÍÁ¾ÅÕàÁ¹µ ' áÊ´§¼Å¡ÒáÃзíÒ¤íÒÊÑ§è ¤ÍÁ¾ÅÕàÁ¹µ µÇÑ á»Ã B1

ËÅѧ¨Ò¡Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é ¾Ã ÍÁ¡ÑºáÊ´§¤ Ңͧ B1 ¡ ͹áÅÐËÅѧ ¡Ò÷íÒ¤íÒÊÑ§è ¤ÍÁ¾ÅÕàÁ¹µ ¨Ò¡µÑÇÍ ҧ¢ ÍÁÙŢͧ B1 ËÅѧ·íÒ¤ÍÁ¾ÅÕàÁ¹µ ෠ҡѺ 00001110 (áµ áÊ´§à¾Õ§ 1110)

&&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


SIN

à» ¹ ¤íÒÊѧè ÊíÒËÃѺ¤íҹdzËÒ¤ Ò䫹 (sine) ·Ò§µÃÕ⡳ÁÔµÔ ÁÕ¢¹Ò´¢Í§¢ ÍÁÙÅ 8 ºÔµá·¹¤ ÒÁØÁµÑ§é áµ 0 ¶Ö§ 359 ͧÈÒ ´Ñ§¹Ñ¹é ¢ ÍÁÙÅ 1 ºÔµ¨Ðá·¹¤ ÒÁØÁ 1.406 ͧÈÒ ÁÕªÍ×è àÃÕÂ¡Ç Ò äº¹ÒÃÕàÃà´Õ¹ ËÃ×Í brad (binary radian) Í ҧäáçµÒÁ¤ Ò䫹 ¨Ðᵡµ Ò§¡Ñ¹ä»¢Ö¹é ÍÂÙ¡ ºÑ ÁØÁ·Õãè ª ÍÒ §¶Ö§ ´Ñ§ÁÕ¢Í ÁÙÅâ´ÂÊÃØ»µ Í仹Õé ·ÕÁè ÁØ 0 ͧÈÒ ¤ Ò䫹 ෠ҡѺ 0 ·ÕÁè ÁØ 45 ͧÈÒ ¤ Ò䫹 ෠ҡѺ 0.707 ·ÕÁè ÁØ 90 ͧÈÒ ¤ Ò䫹 ෠ҡѺ 1.000 ·ÕÁè ÁØ 180 ͧÈÒ ¤ Ò䫹 ෠ҡѺ 0 ÍÕ¡¤ÃÑ§é ·ÕÁè ÁØ 270 ͧÈÒ ¤ Ò䫹 ෠ҡѺ -1.000 ¨ÐàËç¹ä´ ÇÒ ¤ Ò䫹 Á¤Õ Ò ä´ µ§Ñé áµ -1 ¶Ö§ 1 ´Ñ§¹Ñ¹é ¢ ÍÁÙÅ·Õ¹è Òí ÁÒ¤íҹdz¨Ö§¤ÇÃà» ¹¢ ÍÁÙÅ·Õ¤è ´Ô à¤Ã×Íè §ËÁÒ â´Â㹡ÒáÃзíÒ¤íÒÊѧè SIN à» ¹¡Òäíҹdzà¾×Íè ËÒ¤ ÒÁØÁÍÍ¡ÁÒ â´Â㪠¤ÇÒÁÊÑÁ¾Ñ¹¸ ·Ò§¤³ÔµÈÒʵà áÅФ Ò ¢Í§ brad ÁÒª Ç ÊÒÁÒöÊÃØ»¤ÇÒÁÊÑÁ¾Ñ¹¸ ¢Í§¤ Ò䫹 ¡ºÑ ÁØÁ, ¤ Ңͧ brad áÅеÑÇàÅ¢·Ù¤ÍÁ¾ÅÕàÁ¹µ ä´ ´§Ñ ¹Õé ·ÕÁè ÁØ 0 ͧÈÒ ¤ Ò brad ෠ҡѺ 0 ¤ Ò䫹 ã¹ÃÙ»¢Í§·Ù¤ÍÁ¾ÅÕàÁ¹µ ෠ҡѺ 0 ·ÕÁè ÁØ 45 ͧÈÒ ¤ Ò brad ෠ҡѺ 32 ¤ Ò䫹 ã¹ÃÙ»¢Í§·Ù¤ÍÁ¾ÅÕàÁ¹µ ෠ҡѺ 90 ·ÕÁè ÁØ 90 ͧÈÒ ¤ Ò brad ෠ҡѺ 64 ¤ Ò䫹 ã¹ÃÙ»¢Í§·Ù¤ÍÁ¾ÅÕàÁ¹µ ෠ҡѺ 127 ·ÕÁè ÁØ 180 ͧÈÒ¤ Ò brad ෠ҡѺ 128 ¤ Ңͧ䫹 ã¹ÃÙ»·Ù¤ÍÁ¾ÅÕàÁ¹µ ෠ҡѺ 0 ·ÕÁè ÁØ 270 ͧÈÒ¤ Ò brad ෠ҡѺ 192 ¤ Ңͧ䫹 ã¹ÃÙ»·Ù¤ÍÁ¾ÅÕàÁ¹µ ෠ҡѺ -127 â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õàé » ¹¡ÒÃ㪠§Ò¹¤íÒÊѧè SIN áÅÐá»Å§¤ Òà» ¹¢ ÍÁÙŢͧÁØÁã¹àªÔ§µÃÕ⡳ÁÔµÔ ' {$STAMP BS2p} ' {$PBASIC 2.5} DEG VAR W1 SINE VAR W2 FOR DEG = 0 TO 359 STEP 45 SINE = SIN (DEg*128/180) DEBUG "Angle :" , DEC DEG,TAB,"Sine:",SDEC SINE,CR NEXT

àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal áÊ´§¤ ÒÁØÁáÅФ Ò䫹 ·ÁÕè ÁØ µ Ò§æ ã¹ÃÙ»µÑÇàÅ¢·Õ¤è ´Ô à¤Ã×Íè §ËÁÒÂ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&'


COS à» ¹¤íÒÊÑè§ÊíÒËÃѺËÒ¤ Òâ¤ä«¹ (cosine) ·Ò§µÃÕ⡳ÁÔµÔ ÁÕÃٻẺ¡ÒÃ㪠áÅСÒ÷íÒ§Ò¹¤Å Ò¡Ѻ ¤íÒÊѧè SIN ᵡµ Ò§¡Ñ¹à¾Õ§¼ÅÅѾ¸ ·äÕè ´ à¹×Íè §¨Ò¡¤ Òâ¤ä«¹ ·ÁÕè ÁØ µ Ò§æ ¨ÐÁÕ¤ÇÒÁᵡµ Ò§¡Ñº¤ Ò䫹 ÊÃØ»ä´ ´§Ñ ¹Õé ·ÕÁè ÁØ 0 ͧÈÒ ¤ Òâ¤ä«¹ ෠ҡѺ 1 ·ÕÁè ÁØ 45 ͧÈÒ ¤ Òâ¤ä«¹ ෠ҡѺ 0.5 ·ÕÁè ÁØ 90 ͧÈÒ ¤ Òâ¤ä«¹ ෠ҡѺ 0 ·ÕÁè ÁØ 180 ͧÈÒ ¤ Òâ¤ä«¹ ෠ҡѺ -1 ·ÕÁè ÁØ 270 ͧÈÒ ¤ Òâ¤ä«¹ ෠ҡѺ 0 ÊÒÁÒöµÃǨÊͺ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè COS ´ ÇÂâ»Ãá¡ÃÁµÑÇÍ ҧ´Ñ§¹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} DEG VAR W1 COSN VAR W2 FOR DEG = 0 TO 359 STEP 45 COSN = COS (DEG*128/180) DEBUG "Angle: ",DEC DEG,TAB,"COS: ",SDEC COSN,CR NEXT

'

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


4.3 ¤íÒÊÑ§è ·Ò§¤³ÔµÈÒʵà Ẻ亹ÒÃÕ ÁÕ´Ç Â¡Ñ¹ 16 ¤íÒÊÑ§è »ÃСͺ´ Ç + à» ¹¤íÒÊÑ觡Òúǡ à» ¹¤íÒÊÑ觡ÒÃź / à» ¹¤íÒÊÑ§è ¡ÒÃËÒà â´ÂÊ §¤ Ò¼ÅÅѾ¸ ·äÕè ´ ¨Ò¡¡ÒÃËÒáÅѺÁÒ // à» ¹¤íÒÊÑ§è ¡ÒÃËÒà â´ÂÊ §¤ ÒàÈÉ·Õàè ËÅ×ͨҡ¡ÒÃËÒáÅѺÁÒ * à» ¹¤íÒÊÑ§è ¡Òäٳ â´ÂÊ §¤ Ò¼ÅÅѾ¸ 亵 ´Ò ¹µèÒí ¡ÅѺÁÒ ** à» ¹¤íÒÊÑ§è ¡Òäٳ â´ÂÊ §¤ Ò¼ÅÅѾ¸ 亵 ´Ò ¹ÊÙ§¡ÅѺÁÒ */ à» ¹¤íÒÊÑ§è ¤Ù³àÅ¢·È¹ÔÂÁ MIN à» ¹à¡çº¤ ÒµÑÇá»Ã·ÕÁè ¤Õ Ò ÁÒ¡¡Ç ÒËÃ×Í෠ҡѺ¤ Ò¢ ÍÁÙÅ·Õ¡è Òí ˹´ËÅѧ¤íÒÊÑ§è ¹Õé MAX à» ¹à¡çº¤ ÒµÑÇá»Ã·ÕèÁÕ¤ Ò¹ ÍÂ¡Ç ÒËÃ×Í෠ҡѺ¤ Ò¢ ÍÁÙÅ·Õè¡íÒ˹´ËÅѧ¤íÒÊÑ觹Õé DIG >> à» ¹¤íÒÊѧè àÅ×Íè ¹¢ ÍÁÙÅä»·Ò§¢ÇÒ ÁÕ¤Ò à· Ò¡ÑºËÒô Ç 2 << à» ¹¤íÒÊѧè àÅ×Íè ¹¢ ÍÁÙÅä»·Ò§« Ò ÁÕ¤Ò à· Ò¡Ñº¤Ù³´ Ç 2 REV à» ¹¤íÒÊѧè ÊÅѺºÔµ¢ ÍÁÙÅ & à» ¹¤íÒÊѧè á͹´ (AND) ·Ò§Åͨԡ | à» ¹¤íÒÊѧè ÍÍà (OR) ·Ò§Åͨԡ ^ à» ¹¤íÒÊѧè àÍ硤ÅÙ«¿Õ ÍÍà (XOR) ·Ò§Åͨԡ â´Âã¹áµ ÅФíÒÊÑ§è µ ͧÍÒÈÑ¢ ÍÁÙÅ 2 µÑÇ㹡ÒáÃзíÒ¤íÒÊѧè ËÃ×Í äº¹ÒÃÕâÍà»ÍàÃàµÍà (binary operator) ´Ñ§ÁÕÃÒÂÅÐàÍÕ´áÅеÑÇÍ ҧ¡ÒÃ㪠§Ò¹´Ñ§¹Õé

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'


+

à» ¹¤íÒÊÑè§ãË ·íÒ¡Òúǡ¢ ÍÁÙÅ 2 µÑÇࢠҴ Ç¡ѹ â´Âà¡çºÍÂÙ ã¹ÃÙ»¢Í§àÅ¢ 16 ºÔµ ´Ñ§¹Ñé¹¼ÅÅѾ¸ ¨Ö§ÊÒÁÒöà¡Ô´¢Ö¹é ä´ µ§Ñé áµ 0 ¶Ö§ 65,536 㹡óշäÕè Á ¤´Ô à¤Ã×Íè §ËÁÒ 㹡óշ¼Õè ÅÅѾ¸ ÁÒ¡¡Ç Ò 65,536 ¤ Ңͧ ºÔµ·´¨ÐËÒÂä» ¼ÅÅѾ¸ ÍÒ¨à¡Ô´¤ÇÒÁäÁ ¶¡Ù µ ͧ¢Ö¹é ä´ ´Ñ§¹Ñ¹é ËÒ¡µ ͧ¡ÒÃãË ¼ÅÅѾ¸ Á¤Õ ÇÒÁ¶Ù¡µ ͧ¤Ç÷íÒ¡Òà ¤íҹdzẺ¤Ô´à¤Ã×Íè §ËÁÒ áÅСíÒ˹´¢¹Ò´¢Í§¢ ÍÁÙÅà» ¹ 16 ºÔµ ¡µÑÇÍ ҧ ãË ·Òí ¡Òäíҹdz -1575 + 976 ¼ÅÅѾ¸ ä´ à· Ò¡Ñº -599 ´Ñ§â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = -1575 W2 = 976 W1 = W1 + W2 DEBUG SDEC ? W1

àÁ×èÍÃѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö鹾à ÍÁ¡ÑºáÊ´§¤ Ò W1 = -599 «Öè§à» ¹ ¼ÅÅѾ¸ ¢Í§â¨·Â -1575 + 976 ¶ ÒËÒ¡¤íҹdzẺäÁ ¤´Ô à¤Ã×Íè §ËÁÒ ¼ÅºÇ¡à· ҡѺ 64,937 «Ö§è äÁ ¶¡Ù µ ͧ

'

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


-

à» ¹¤íÒÊѧè ź¢ ÍÁÙÅ 2 µÑÇ áÅ Çà¡çº¼ÅÅѾ¸ ¢ ÍÁÙÅ¢¹Ò´ 16 ºÔµ ¶ Òµ ͧ¡ÒÃãË ¼Å¡ÒÃź¶Ù¡µ ͧ¤Çà ¡íÒ˹´ãË ¢Í ÁÙŵÑÇàŢ໠¹áºº¤Ô´à¤Ã×Íè §ËÁÒ ´Ñ§â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = 1000 W2 = 1999 W1 = W1 - W2 DEBUG DEC ? W1

àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é ¾Ã ÍÁ¡ÑºáÊ´§¤ Ò W1 = 64,537 «Ö§è à» ¹ ¼ÅÅѾ¸ ¢Í§â¨·Â 1,000 - 1,999 ẺäÁ ¤´Ô à¤Ã×Íè §ËÁÒ ¨ÐàËç¹Ç ÒäÁ ¶¡Ù µ ͧ

´Ñ§¹Ñ¹é ¨Ö§µ ͧ·íÒ¡ÒäíҹdzẺ¤Ô´à¤Ã×Íè §ËÁÒ â´Âá¡ â»Ãá¡ÃÁ㹺Ã÷ѴÊØ´· ÒÂà» ¹ DEBUG SDEC ? W1 àÁ×Íè ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ ¨Ðä´ ¼ÅÅѾ¸ à» ¹ -999 «Ö§è ¶Ù¡µ ͧ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'!


/

à» ¹¤íÒÊѧè ËÒâ ÍÁÙÅ 2 ¨íҹǹ ãË ¼ÅÅѾ¸ à» ¹¢ ÍÁÙÅ 16 ºÔµ ¢ ͨíÒ¡Ñ´¢Í§¡ÒáÃзíÒ¤íÒÊÑ§è ¹Õ¤é Í× ¨íҹǹ ·Õè¹íÒÁÒËÒùÑé¹µ ͧ໠¹àÅ¢¨íҹǹàµçÁºÇ¡à· Ò¹Ñé¹ ÁÕâ»Ãá¡ÃÁµÑÇÍ ҧáÊ´§¡ÒÃ㪠¤íÒÊÑ觡ÒÃËÒôѧ¹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = 1000 W2 = 5 W1 = W1/W2 DEBUG DEC ? W1

' ËÒä Ңͧ W1 ´ Ç W2 áÅ Çà¡çº¼ÅËÒÃäÇ ã¹ W1 ' áÊ´§¼ÅËÒ÷ҧ˹ Òµ Ò§ Debug Terminal

ËÅѧ¨Ò¡Ãѹâ»Ãá¡ÃÁ¹Õé ¤ Ңͧ W1 ¨Ð෠ҡѺ 200

㹡óշÕèµ Í§¡ÒÃËÒä ҢͧµÑÇàÅ¢¨íҹǹàµçÁẺ¤Ô´à¤Ã×èͧËÁÒ ¤×Í ÁÕ·Ñ駨íҹǹºÇ¡áÅÐź äÁ ÊÒÁÒö㪠¤Òí Êѧè ËÒÃä´ â´ÂµÃ§ µ ͧ㪠¤Òí ÊÑ§è ¤³ÔµÈÒʵà ¹٠ÒÃÕáÅФíÒÊÑ§è ·Ò§ÅͨԡࢠҪ Ç â´Â·íÒ¡ÒõÃǨÊͺ ¡ Í¹Ç Ò µÑÇàÅ¢·Ñ§é Êͧ¨íҹǹ·Õ¹è Òí ÁÒËÒáѹ¹Ñ¹é ÁÕà¤Ã×Íè §ËÁÒÂàËÁ×͹¡Ñ¹ËÃ×ÍäÁ ¶ ÒàËÁ×͹¡Ñ¹¼ÅÅѾ¸ ·äÕè ´ ¨Ðµ ͧ à» ¹µÑÇàÅ¢¨íҹǹàµçÁºÇ¡Í ҧṠ¹Í¹ áµ ¶ ÒäÁ àËÁ×͹¡Ñ¹ ¡ç¨Ð¹íÒ੾ÒФ ÒÊÑÁºÙó ¢Í§µÑÇàÅ¢¹Ñé¹ÁÒËÒáѹ áŠǨ֧ãÊ à¤Ã×Íè §ËÁÒÂź·Õ¼è ÅÅѾ¸ ã¹¢Ñ¹é µÍ¹ÊØ´· Ò à¾×Íè ãË ¤Ò ·Õ¶è ¡Ù µ ͧÍÍ¡ÁÒ ´Ñ§â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} SIGN VAR BIT W1 = 100 W2 = -3200 SIGN = W1.BIT15 ^ W2.BIT15 W2 = ABS W2 / ABS W1 IF SIGN = 0 THEN SKIP0 W2 = -W2 SKIP0 : DEBUG SDEC ? W2

¤íÒÊÑ§è ·Ò§Åͨԡ·Õ¹è Òí ÁÒ㪠ã¹â»Ãá¡ÃÁ¹Õ¤é Í× ^ ËÁÒ¶֧ ¡ÒÃàÍ硤ÅÙ«¿Õ -ÍÍà «Ö§è ÁÕËÅÑ¡¡Ò÷íÒ§Ò¹§ ÒÂæ ¤×Í ËÒ¡¢ ÍÁÙÅ·Õ¹è Òí ÁÒàÍ硤ÅÙ«¿Õ -ÍÍà ¡¹Ñ ÁÕ¤Ò àËÁ×͹¡Ñ¹¨ÐãË àÍÒµ ¾µØ à» ¹ 0 áµ ¶Ò ÁÕ¤Ò äÁ àËÁ×͹¡Ñ¹ãË àÍÒµ ¾µØ à» ¹ 1

'"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡ÒõÃǨÊͺà¤Ã×Íè §ËÁÒÂ·Õºè µÔ 15 ¢Í§¢ ÍÁÙŹѹé à¹×Íè §¨Ò¡ã¹¡ÒþԨÒóҵÑÇàŢẺ¤Ô´à¤Ã×Íè §ËÁÒºԵº¹ÊØ´ËÃ×ͺԵ MSB ¨Ð¶Ù¡¡íÒ˹´ãË à» ¹ºÔµà¤Ã×Íè §ËÁÒ (sign bit) àÊÁÍ ´Ñ§¹Ñ¹é ¤ ҢͧµÑÇàÅ¢·ÕÊè ÒÁÒöà¡Ô´¢Ö¹é ä´ àÁ×Íè ¾Ô¨ÒóÒẺ ¤Ô´àÃ×Íè §ËÁÒ¨֧෠ҡѺ -32,767 ¶Ö§ +32,767 ·íÒ¡ÒÃàÍ硤ÅÙ«¿Õ -ÍÍà ºµÔ 15 ¢Í§¢ ÍÁÙŷѧé Êͧ à¹×Íè §¨Ò¡ºÔµ 15 à» ¹ºÔµ áÊ´§à¤Ã×èͧËÁÒ ËÒ¡ÁÕ¤ Ò෠ҡѹ áÊ´§Ç Ò¢ ÍÁÙŹÕéÁÕà¤Ã×èͧËÁÒÂàËÁ×͹¡Ñ¹ ÍҨ໠¹ºÇ¡·Ñ駤٠ËÃ×Íź·Ñ駤٠¡çä´ áµ àÁ×èÍ ·íÒ¡ÒÃàÍ硤ÅÙ«¿Õ -ÍÍà áÅ Ç ¨Ðä´ ¼Åà» ¹ 0 à¡çºäÇ ·µÕè ÇÑ á»Ã SIGN áµ ¶Ò ËÒ¡ºÔµ 15 ÁÕ¢Í ÁÙÅäÁ àËÁ×͹¡Ñ¹ ¼Å¢Í§¡Òà àÍ硤ÅÙ«¿Õ -ÍÍà ¨Ðà» ¹ 1 à¡çºäÇ ·Õè sign ઠ¹¡Ñ¹ ·Õºè Ã÷Ѵ¤íÒÊѧè W2 = ABS W2 / ABS W1 à» ¹¡ÒùíÒ¤ ÒÊÑÁºÙó ¢Í§¢ ÍÁÙŷѧé ÊͧÁÒËÒáѹ ¼ÅËÒà à¡çºäÇ ·Õè W2 ·Õºè Ã÷Ѵ¤íÒÊѧè IF SIGN = 0 THEN SKIP0à» ¹¡ÒõÃǨÊͺ¤ Òã¹ SIGN ËÒ¡à» ¹ 0 ãË ¡ÃÐâ´´ä» ·ÕÅè ÒàºÅ SKIP0 ·Õºè Ã÷Ѵ¤íÒÊѧè W2 = -W2 ¨Ð¶Ù¡¡ÃзíÒàÁ×Íè SIGN à» ¹ 1 áÊ´§Ç Ò¢ ÍÁÙÅ·Õ¹è Òí ÁÒËÒùѹé ÁÕà¤Ã×Íè §ËÁÒ äÁ àËÁ×͹¡Ñ¹ ´Ñ§¹Ñ¹é ¼ÅËÒõ ͧ໠¹¨íҹǹàµçÁź ¨Ö§µ ͧ·íÒãË ¼ÅÅѾ¸ Á¤Õ Ò à» ¹Åº â´Â¡ÒÃãÊ à¤Ã×Íè §ËÁÒ - ˹ Ò¼ÅÅѾ¸ ·ÕèºÃ÷Ѵ¤íÒÊÑè§ SKIP0 : DEBUG SDEC ? W2 à» ¹¡ÒÃáÊ´§¼ÅËÒÃ·Õ¶è ¡Ù µ ͧ¼ Ò¹·Ò§Ë¹ Òµ Ò§ Debug Termnal ¤íÒÊѧè ÂÙ¹ÒÃÕ·¹Õè Òí ÁÒ㪠¤Í× ABS à¹×Íè §¨Ò¡äÁ Á·Õ Ò§·Ã񼊫 ÇÒ ¢ ÍÁÙÅ·Õ¹è Òí ÁÒËÒáѹ¹Ñ¹é à» ¹ºÇ¡ËÃ×Íź ¨Ö§µ ͧ ¹íÒ¤ ÒÊÑÁºÙó ¢Í§¨íҹǹ·Ñ§é Êͧ¹Ñ¹é ÁÒ·íÒ¡ÒÃËÒà ¼ÅËÒÃä´ à· Òäà ãË à¡çºäÇ ¡Í ¹ ¨Ò¡¹Ñ¹é ¨Ö§·íÒ¡ÒõÃǨÊͺ¨Ò¡µÑÇá»Ã ·Õàè ¡çº¤ Òà¤Ã×Íè §ËÁÒÂäÇ «Ö§è ã¹â»Ãá¡ÃÁ¹Õ¤é Í× sign ËÒ¡¤ Òã¹ sign à» ¹ 0 áÊ´§Ç Ò¼ÅÅѾ¸ ·äÕè ´ µÍ §à» ¹¨íҹǹàµçÁºÇ¡ ¡çãË ·Òí ¡ÒÃáÊ´§¤ Ò¼ ҹ˹ Òµ Ò§ Debug Terminal ä´ ·¹Ñ ·Õ áµ ¶Ò ËÒ¡ SIGN à» ¹ 1 áÊ´§Ç Ò ¼ÅËÒõ ͧ໠¹¨íҹǹ àµçÁź ¡çµÍ §ä»¼ Ò¹¡Ãкǹ¡Ò÷íÒãË ¼ÅËÒÃà» ¹Åº¡ ͹ ¨Ò¡¹Ñ¹é ¨Ö§áÊ´§¼ÅÅѾ¸ ÍÍ¡ÁÒ·ÕËè ¹ Òµ Ò§ Debug Terminal ¨Ò¡¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁä´ ¼ÅËÒÃ෠ҡѺ -32 «Ö§è ¶Ù¡µ ͧ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'#


//

à» ¹¤íÒÊÑ§è ¡ÒÃËÒÃàËÁ×͹¡Ñº¤íÒÊѧè / áµ ¤Òí ÊÑ§è ¹Õ¨é ÐáÊ´§àÈÉàËÅ×ͨҡ¡ÒÃËÒà ¶ ÒËҡ㪠¤Òí Êѧè / ¼ÅËÒà ·Õäè ´ ¨Ðà» ¹¼ÅËÒ÷Õäè Á ¤´Ô àÈÉ Â¡µÑÇÍ ҧ 11/2 = 5 àÈÉ 1 áµ àÈÉ 1 ¨ÐäÁ ¶¡Ù áÊ´§ ¶ ÒËҡ㪠¤Òí Êѧè // ¨ÐáÊ´§ ¤ ÒàÈÉÍÍ¡ÁÒ Ê Ç¹¼ÅËÒèíҹǹàµçÁ¡ç¨ÐäÁ ¹Òí ÁÒáÊ´§àª ¹¡Ñ¹ â»Ãá¡ÃÁµÑÇÍ ҧáÊ´§¡Ò÷íÒ§Ò¹¢Í§¤íÒÊÑ§è ¹ÕÁé ´Õ §Ñ ¹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = 1000 W2 = 6 W1 = W1 //W2 DEBUG SDEC ? W1

àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal áÊ´§¤ Ò W1 = 4 «Ö§è ¡ç¤Í× ¤ ÒàÈÉ·Õàè ¡Ô´¨Ò¡¡ÒÃËÒà 1000 ´ Ç 6

¶ Òµ ͧ¡ÒÃãË áÊ´§·Ñ§é ¼ÅËÒÃáÅÐàÈÉ ÊÒÁÒö·íÒä´ ´§Ñ µÑÇÍ ҧµ Í仹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = 1000 W2 = 6 W3 = W1/W2 W4 = W1//W2 DEBUG SDEC ? W3 DEBUG SDEC ? W4

àÁ×Íè Ãѹâ»Ãá¡ÃÁ ·ÕËè ¹ Òµ Ò§ Debug Terminal áÊ´§¤ Ò W3 = 166 áÅÐ W4 = 4 «Ö§è ¡ç¤Í× ¼ÅËÒÃáÅÐ àÈÉ·Õèä´ ¨Ò¡¡ÒÃËÒÃ

'$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


*

à» ¹¤íÒÊÑ§è ¤Ù³àÅ¢ 16 ºÔµ ·Ñ§é Ẻ¤Ô´áÅÐäÁ ¤´Ô à¤Ã×Íè §ËÁÒ 㹡óշäÕè Á ¤´Ô à¤Ã×Íè §ËÁÒ ¼ÅÅѾ¸ ÊÒÁÒö à¡Ô´¢Ö¹é ä´ µ§Ñé áµ 0-65,536 ¶ Ò¤Ô´à¤Ã×Íè §ËÁÒ¼ÅÅѾ¸ à¡Ô´¢Ö¹é ä´ µ§Ñé áµ -32,767 ¶Ö§ +32,767 ÊíÒËÃÑºã¹¡Ã³Õ ·Õè¤Ù³áººäÁ ¤Ô´à¤Ã×èͧËÁÒÂËÒ¡¼ÅÅѾ¸ ·Õèä´ ÊÙ§¡Ç Ò 65,536 ¤ Ò·Õèà¡Ô¹¨ÐÊÙ­ËÒÂä» ´Ñ§¹Ñé¹ËÒ¡µ ͧ¡ÒÃãË ¼Å¤Ù³ÁÕ¤ÇÒÁ¶Ù¡µ ͧ¤Ç÷íÒ¡ÒäٳẺ¤Ô´à¤Ã×èͧËÁÒ ¡Òäٳ¨Ðᵡµ Ò§¡Ñº¡ÒÃËÒõç·ÕèÊÒÁÒÃ¶ãª ä´ ¡Ñº àÅ¢¨íҹǹàµçÁºÇ¡áÅÐźâ´ÂµÃ§ ´Ñ§â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = 1000 W2 = -19 W1 = W1 * W2 DEBUG SDEC ? W1

ËÅѧ¨Ò¡Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¼Å¤Ù³ÍÍ¡ÁÒà» ¹ W1 = -19000

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'%


**

à» ¹¤íÒÊÑ觤ٳàÅ¢ 16 ºÔµ·ÕèãË ¼ÅÅѾ¸ à» ¹¨íҹǹ·Õèà¡Ô¹ 16 ºÔµ â´Â»¡µÔËÒ¡¹íÒàÅ¢ 16 ºÔµÁÒ ¤Ù³¡Ñ¹ ¨Ðµ Í§ä´ àÅ¢ 32 ºÔµ áµ à¹×Íè §¨Ò¡àºÊÔ¡áʵÁ» 2 ÊÒÁÒöáÊ´§¢ ÍÁÙÅä´ à¾Õ§ 16 ºÔµ ´Ñ§¹Ñ¹é ¢ ÍÁÙÅã¹ 16 ºÔµº¹¨ÐÊÙ­ËÒÂä»ã¹¡Ã³Õ·Õè㪠¤íÒÊÑè§ * ¶ ÒËÒ¡µ ͧ¡Ò÷ÃÒº¤ Ò¼ÅÅѾ¸ ã¹ 16 ºÔµº¹ÊÒÁÒö·íÒä´ â´Â㪠¤Òí Êѧè ** ¹Õáé ·¹ áµ ¼ÅÅѾ¸ ·äÕè ´ ¡¨ç ÐÁÕà¾Õ§¤ Ò 16 ºÔµº¹à· Ò¹Ñ¹é ´Ñ§â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = $FBD8 W2 = W1 ** W1 DEBUG HEX ? W2

àÁ×Íè ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ ·ÕËè ¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¼ÅÅѾ¸ 16 ºÔµº¹¼ Ò¹µÑÇá»Ã W2 ã¹ÃÙ» àÅ¢°Ò¹ÊԺˡ «Ö§è ¤íҵͺ¤×Í $FBD4 Ê Ç¹¼ÅÅѾ¸ 16 ºÔµÅ Ò§¤×Í $6240 ¨ÐäÁ áÊ´§

áµ ¶ Òµ ͧ¡ÒÃãË áÊ´§ÊÒÁÒö·íÒä´ ´Ñ§â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = $FDE8 W2 = W1 * W1 W3 = W1 ** W1 DEBUG HEX ? W3 DEBUG HEX ? W2

àÁ×Íè Ãѹâ»Ãá¡ÃÁ ¼Å¤Ù³ 16 ºÔµº¹¨ÐáÊ´§´ Ǥ Ңͧ W3 Ê Ç¹¼Å¤Ù³ 16 ºÔµÅ Ò§áÊ´§´ Ç W2 ¼ Ò¹ ·Ò§Ë¹ Òµ Ò§ Debug Terminal

'&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


*/ à» ¹¤íÒÊÑ§è ¤Ù³àÅ¢·È¹ÔÂÁ¢Í§¨íҹǹàµçÁ 16 ºÔµ ¡µÑÇÍ ҧ µ ͧ¡Òäٳ 3 ¡Ñº 1.5 ¶ ÒËҡ㪠¤Òí ÊÑ§è ¡Òäٳ»¡µÔ ¨ÐäÁ ÊÒÁÒö¤Ù³µÑÇàÅ¢·È¹ÔÂÁä´ ¨Ö§µ ͧ㪠¤íÒÊÑè§ */ ¹Õé áµ ¡ ͹¨Ð㪠µ ͧÁÕ¡ÒÃá»Å§¢ ÍÁÙŵÑÇ ¤Ù³·Õàè » ¹àÅ¢·È¹ÔÂÁãË ÍÂÙà »Ù ¢Í§àÅ¢°Ò¹ÊԺˡàÊÕ¡ ͹ ¡µÑÇÍ ҧ ¨íҹǹ 1.5 àÁ×Íè ·íÒà» ¹àÅ¢ 16 ºÔµ 8 ºÔµ º¹¨Ðà¡çº¤ Ò¨íҹǹàµçÁäÇ ã¹¡Ã³Õ¹¤Õé Í× 1 Ê Ç¹ 8 ºÔµÅ Ò§¨Ðà¡çº¢ ÍÁÙÅàÅ¢·È¹ÔÂÁ 㹡óչ¤Õé Í× 0.5 ¤ Ò 0.5 ¢Í§ ¢ ÍÁÙÅ 8 ºÔµÁÕ¤Ò à· Ò¡Ñº 128 (à¡Ô´¨Ò¡¤ ÒàµçÁ¢Í§àÅ¢ 8 ºÔµ¤×Í 256 àÁ×Íè à» ¹ 0.5 ¡ç¤Í× ¤ÃÖ§è Ë¹Ö§è ¢Í§ 256 ¨Ö§à· ҡѺ 128) ¨Ò¡¹Ñ¹é á»Å§¤ Ò 128 à» ¹àÅ¢°Ò¹ÊԺˡ ¨Ð෠ҡѺ $80 àÁ×Íè ¹íÒÁÒÃÇÁ¡Ñº¢ ÍÁÙÅ 8 ºÔµº¹¡ Íè ¹Ë¹ Ò¹Õ¤é Í× 1 ¨Ðä´ µÇÑ ¤Ù³à· ҡѺ $0180 ¨Ò¡¹Ñ¹é ¨Ö§¹íÒ令ٳ´ ǤíÒÊѧè */ µ Íä» ´Ñ§µÑÇÍ ҧµ Í仹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = 100 W1 = W1 */ $0180 DEBUG ? W1

·íÒ¡Òäٳ 100 ´ Ç 1.5 «Ö§è ¤ Ò 1.5 ෠ҡѺ $0180

àÁ×èÍ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ ·Õè˹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¼ÅÅѾ¸ W1 = 150 «Öè§à» ¹¼ÅÅѾ¸ ·Õè ¶Ù¡µ ͧ ¤íÒÊÑ§è ¹Õàé ËÁÒзըè Ð㪠㹡Òäٳ¤ ÒµÑÇá»Ã´ Ǥ Ò¤§·Õ·è Ò§¿ Ê¡Ô Ê ÍÒ·Ô ¤ Ò P (ä¾¹ : Pi) «Ö§è ÁÕ¤Ò à· Ò¡Ñº 3.14159 àÁ×Íè ·íÒ¡ÒÃá¡໠¹¢ ÍÁÙÅ 8 ºÔµº¹áÅÐÅ Ò§ ¨Ðä´ ¢Í ÁÙÅ 8 ºÔµº¹à· ҡѺ 3 Ê Ç¹ 8 ºÔµÅ Ò§¨Ðä´ ¤Ò 0.14159 *256 = 36 ËÃ×Í $24 àÁ×Íè ¹íÒÁÒÃÇÁ¡Ñ¹¨Ðä´ ¤Ò P ã¹ÃÙ»¢Í§àÅ¢°Ò¹ÊԺˡ෠ҡѺ $0324 Í ҧäáçµÒÁ ¡ÒÃá»Å§¤ Ò¹ÕÍé Ò¨äÁ ÊÁºÙó Í ҧ·ÕÊè ´Ø áµ ¤Ò ¼Ô´¾ÅÒ´·Õàè ¡Ô´¢Ö¹é 㹡óչÁÕé àÕ ¾Õ§ 0.1% ෠ҹѹé

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

''


MIN à» ¹¤íÒÊѧè ÊíÒËÃѺ¡íÒ˹´¢ ÍÁÙŵèÒí ÊØ´¢Í§¡ÅØÁ ¢ ÍÁÙÅ·Õµè Í §¡ÒõÃǨÊͺ ÁÕû٠Ẻ´Ñ§¹Õé ¡ÅØÁ ¢ ÍÁÙÅ·Õµè Í §¡ÒõÃǨÊͺ MIN ¤ Ңͺࢵ ËÅÑ¡¡Òâͧ¤íÒÊÑ§è ¹Õ¤é Í× ¶ Ò¢ ÍÁÙÅ·Õ¹è Òí ÁÒµÃǨÊͺÁÕ¤Ò ¹ ÍÂ¡Ç Ò¤ Ò·Õ¡è Òí ˹´ ãË àÅ×Í¡¤ ҢͺࢵÁÒ㪠ᵠ¶ ÒËÒ¡¡ÅØÁ ¢ ÍÁÙÅ·Õ¹è Òí ÁÒµÃǨÊͺÁÕ¤Ò ÁÒ¡¡Ç Ò¤ Ңͺࢵ ãË àÅ×Í¡¢ ÍÁÙÅ·Õ¹è Òí ÁÒµÃǨÊͺ¹Ñ¹é ä»ãª ¤íÒÊÑ§è ¹Õãé ª ä´ ¡Ñº¢ ÍÁÙŨíҹǹàµçÁºÇ¡áººäÁ ¤Ô´à¤Ã×èͧËÁÒÂà· Ò¹Ñé¹ ã¹¡ÒÃ㪠¤íÒÊÑ觵 ͧÃÐÁÑ´ÃÐÇѧ㹡ÒáíÒ˹´¤ Ò ¢Íºà¢µ â´Â੾ÒСÒáíÒ˹´¤ Ңͺࢵ໠¹ 0 áÅж Ò¢ ÍÁÙÅ·Õ¹è Òí ÁÒµÃǨÊͺ໠¹¤ Ò -1 ¨Ð·íÒãË ä´ ¤Òí µÍº à» ¹ 65,535 «Ö§è äÁ ¶¡Ù µ ͧ à¹×Íè §¨Ò¡¤ Ò·Õ¹è Òí ÁÒµÃǨÊͺ໠¹ -1 «Ö§è ¹ ÍÂ¡Ç Ò 0 µÒÁËÅÑ¡¡ÒÃáŠǤíҵͺ·Õäè ´ µ ͧ໠¹ 0 áµ ¢Í ÁÙÅ -1 àÁ×Íè ¾Ô¨ÒóÒã¹ÃÙ»¢Í§¨íҹǹàŢẺäÁ ¤´Ô à¤Ã×Íè §ËÁÒ¨Ð෠ҡѺ 65,535 «Ö§è ÁÒ¡ ¡Ç Ò 0 á¹ ¹Í¹ ·íÒãË ¤Òí µÍº·Õäè ´ ¨§Ö à» ¹ 65,535 á·¹·Õ¨è Ðà» ¹ 0 â»Ãá¡ÃÁµÑÇÍ ҧ¢Í§¡ÒÃ㪠¤Òí ÊÑ§è ¹ÕÁé ´Õ §Ñ ¹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} FOR W1 = 100 to 0 STEP 10 DEBUG ? W1 MIN 50 NEXT

àÁ×èÍ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ¹Õé ¤íҵͺ·Õèä´ ¤×Í 100 áÅж ÒËÒ¡à»ÅÕ蹤 Ò¢ ÍÁÙÅ·Õè¹íÒÁÒµÃǨÊͺ໠¹µèíÒ¡Ç Ò 50 ¼ÅÅѾ¸ ¢Í§â»Ãá¡ÃÁ¹Õ¨é Ðà» ¹ 50 àÊÁÍ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


MAX à» ¹¤íÒÊÑ§è ·ÕÁè ÅÕ ¡Ñ ɳеç¢ ÒÁ¡Ñº¤íÒÊѧè MIN ¹Ñ¹è ¤×Í ¶ Ò¢ ÍÁÙÅ·Õ¹è Òí ÁÒµÃǨÊͺÁÕ¤Ò ÁÒ¡¡Ç Ò¤ Ңͺࢵ ¼ÅÅѾ¸ ¢Í§¤íÒÊÑ§è ¹Õ¨é Ð෠ҡѺ¤ Ңͺࢵ áµ ¶Ò ¢ ÍÁÙŵèÒí ¡Ç Ò¤ Ңͺࢵ ¼ÅÅѾ¸ ·äÕè ´ ¨Ð෠ҡѺ¤ Ңͧ¢ ÍÁÙŹѹé æ àÅ ¢ ͤÇÃÃÐÇѧ㹡ÒÃ㪠¤Òí ÊÑ§è ¹Õ¤é Í× ¢ ÍÁÙÅ·Õ¹è Òí µÃǨÊͺ໠¹ 65535+1 áÅФ Ңͺࢵ໠¹ 65535 á·¹·Õ¤è Òí µÍº ¨Ðà» ¹ 65,535 ¡ÅѺ໠¹ 0 à¹×Íè §¨Ò¡¢ ÍÁÙÅ·Õàè ¾ÔÁè ¨Ò¡ 65535 ¨Ð¡ÅѺ໠¹¤ Ò 0 äÁ 㪠65536 à¹×Íè §¨Ò¡¢ ÍÁÙÅ ¢¹Ò´ 16 ºÔµàÁ×Íè äÁ ¤´Ô à¤Ã×Íè §ËÁÒ ¨ÐÁÕ¤Ò ÍÂÙà ÐËÇ Ò§ 0 ¶Ö§ 65535 ´Ñ§¹Ñ¹é àÁ×Íè ¹íÒä»à»ÃÕºà·Õº¡Ñº 65535 ¤ Ңͧ¢ ÍÁÙÅ·Õ¹è Òí ÁÒµÃǨÊͺ¹ ÍÂ¡Ç Ò ¼ÅÅѾ¸ ¨§Ö ෠ҡѺ¢ ÍÁÙÅ·Õ¹è Òí ÁÒµÃǨÊͺ «Ö§è ¡ç¤Í× 0 ¹Ñ¹è àͧ â»Ãá¡ÃÁµÑÇÍ ҧ áÊ´§¡Ò÷íÒ§Ò¹¢Í§¤íÒÊÑ§è ¹ÕÁé ´Õ §Ñ ¹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} FOR W1 = 0 to 100 STEP 10 DEBUG ? W1 MAX 50 NEXT

' ¡íÒ˹´¤ Ңͧ W1 ¨Ò¡ 0 ¶Ö§ 100 ' áÊ´§¤ Ңͧ W1 áµ µÍ §äÁ à¡Ô¹ 50

àÁ×Íè ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ¹Õé àÁ×Íè ¤ Ңͧ W1 Âѧ¹ ÍÂ¡Ç Ò 50 ¨ÐáÊ´§¤ ҹѹé ÍÍ¡ÁÒ ¨¹¡ÃÐ·Ñ§è ¤ Ңͧ W1 ÁÒ¡¡Ç Ò 50 ¼ÅÅѾ¸ ·äÕè ´ ¨Ð෠ҡѺ 50 ෠ҹѹé

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


DIG à» ¹ ¤íÒÊѧè à¾×Íè àÃÕ¡¤ Ңͧ¢ ÍÁÙÅã¹ËÅÑ¡·Õ¡è Òí ˹´ã¹ÃÙ»¢Í§àÅ¢°Ò¹ÊÔº â´ÂàÃÔÁè µ ¹µÑ§é áµ ËÅÑ¡ 0 ÊÙ§ÊØ´ äÁ à¡Ô¹ËÅÑ¡ 4 ¨Ö§ÊÒÁÒö¤Ãͺ¤ÅØÁàÅ¢°Ò¹ÊÔºµÑ§é áµ 0 ¶Ö§ 65535 ´Ñ§ÁÕâ»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} FOR B0 = 0 to 4 DEBUG ? W1 DIG 2 NEXT

àÁ×Íè ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ¹Õé i-Stamp2P24 ¨Ð¹íÒ¢ ÍÁÙÅËÅÑ¡ 0 ÁÒáÊ´§º¹Ë¹ Òµ Ò§ Debug Terminal ã¹ ÃÙ»¢Í§àÅ¢°Ò¹ÊÔº µ Í´ Ç¢ ÍÁÙÅã¹ËÅÑ¡ 1, ËÅÑ¡ 2, ËÅÑ¡ 3 áÅÐËÅÑ¡ 4 ¶ ÒËÅÑ¡ã´äÁ Á¢Õ Í ÁÙÅ¡ç¨ÐáÊ´§´ Ǥ Ò 0 á·¹

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


<<

à» ¹¤íÒÊѧè àÅ×Íè ¹¢ ÍÁÙÅä»·Ò§« ÒÂË¹Ö§è ºÔµ â´Â¢ ÍÁÙÅ㹺Ե¹ÑÂÊíҤѭÊÙ§ÊØ´¨ÐËÒÂä» àÁ×Íè à¡Ô´¡ÒÃàÅ×Íè ¹ ¢ ÍÁÙÅ 1 ºÔµ ¹Í¡¨Ò¡¹Ñ鹡ÒÃàÅ×è͹¢ ÍÁÙÅä»·Ò§« ÒÂ˹Ö觺Ե¹ÕéãË ¼Åà·Õº෠ҡѺ¡ÒäٳÊͧãË á¡ ¢ ÍÁÙŹÑé¹ µÑÇÍ ҧ ¢ ÍÁÙÅàÃÔÁè µ ¹à» ¹ %1 àÁ×Íè Êѧè ãË àÅ×Íè ¹¢ ÍÁÙÅä»·Ò§« ÒÂË¹Ö§è ºÔµ ¨Ðä´ ¤Ò ෠ҡѺ %10 «Ö§è ෠ҡѺ 2 ã¹ °Ò¹ÊÔº ¶ ÒÊѧè ãË àÅ×Íè ¹« ÒÂÍÕ¡Ë¹Ö§è ºÔµ ¤ Ңͧ¢ ÍÁÙÅ¡ç¨Ð¡ÅÒÂà» ¹ %100 «Ö§è ෠ҡѺ 4 à» ¹àª ¹¹Õäé »àÃ×Íè Âæ ¨¹¡ÃÐ ·Ñ§è ¢ ÍÁÙÅ෠ҡѺ %1000000000000000 àÁ×Íè Êѧè ãË àÅ×Íè ¹¢ ÍÁÙÅÍÕ¡¤ÃÑ§é ¢ ÍÁÙÅ¡ç¨Ðǹ¡ÅѺ໠¹ 0 ÊÒÁÒöáÊ´§ ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊÑ觹Õé´ ÇÂâ»Ãá¡ÃÁµÑÇÍ ҧ´Ñ§¹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = 000000000000001 FOR B0 = 1 to 16 DEBUG BIN ? W1 << B0 NEXT

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


>>

à» ¹¤íÒÊѧè àÅ×Íè ¹¢ ÍÁÙÅä»·Ò§¢ÇÒË¹Ö§è ºÔµ â´Â¢ ÍÁÙÅ㹺Ե¹ÑÂÊíҤѭµèÒí ÊØ´¨ÐËÒÂä»àÁ×Íè à¡Ô´¡ÒÃàÅ×Íè ¹ ¢ ÍÁÙÅ 1 ºÔµ ¹Í¡¨Ò¡¹Ñ鹡ÒÃàÅ×è͹¢ ÍÁÙÅä»·Ò§¢ÇÒ˹Ö觺Ե¹ÕéãË ¼Åà·Õº෠ҡѺ¡ÒÃËÒÃÊͧãË á¡ ¢ ÍÁÙŹÑé¹ µÑÇÍ ҧ ¢ ÍÁÙÅàÃÔÁè µ ¹à» ¹ %1000 «Ö§è ෠ҡѺ 8 ã¹àÅ¢°Ò¹ÊÔº àÁ×Íè Êѧè ãË àÅ×Íè ¹¢ ÍÁÙÅä»·Ò§¢ÇÒË¹Ö§è ºÔµ ¨Ðä´ ¤ Ò෠ҡѺ %0100 «Ö§è ෠ҡѺ 4 ã¹°Ò¹ÊÔº ¶ ÒÊѧè ãË àÅ×Íè ¹« ÒÂÍÕ¡Ë¹Ö§è ºÔµ ¤ Ңͧ¢ ÍÁÙÅ¡ç¨Ð¡ÅÒÂà» ¹ %0010 «Öè§à· ҡѺ 2 à» ¹àª ¹¹Õéä»àÃ×èÍÂæ ¨¹¡ÃзÑ觢 ÍÁÙÅ෠ҡѺ %0001 àÁ×èÍÊÑè§ãË àÅ×è͹¢ ÍÁÙÅÍÕ¡¤ÃÑé§ ¢ ÍÁÙÅ¡ç¨Ðǹ ¡ÅѺ໠¹ 0 ÊÒÁÒöáÊ´§¡Ò÷íÒ§Ò¹¢Í§¤íÒÊÑ§è ¹Õ´é Ç Ââ»Ãá¡ÃÁµÑÇÍ ҧ´Ñ§¹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} W1 = 100000000000000 FOR B0 = 1 to 16 DEBUG BIN ? W1 >> B0 NEXT

"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


REV à» ¹¤íÒÊÑè§àÅ×Í¡áÊ´§¢ ÍÁÙŵÒÁ¨íҹǹºÔµ·Õè¡íÒ˹´ áÅ Ç·íÒ¡ÒèѴàÃÕ§ãËÁ â´ÂãË ºÔµ¹ÑÂÊíҤѭ µèí Ò ÊØ ´ ¡ÅÒÂà» ¹ ºÔ µ ¹Ñ  Êí Ò ¤Ñ ­ ÊÙ § ÊØ ´ äÅ à ÃÕ Â §Åí Ò ´Ñ º ¡Ñ ¹ ä» Â¡µÑ Ç ÍÂ Ò § ¢ Í ÁÙ Å ·Õè µ Í §¡Òùí Ò ÁÒÊÅÑ º â´Â 㪠¤Òí Êѧè REV ÁÕ¤Ò %10000001 ·íÒ¡ÒÃÊÅѺ¢ ÍÁÙÅà¾Õ§ 4 ºÔµ ¤íÒÊÑ§è ·Õãè ª ¨§Ö à» ¹ %10000001 REV 4 ¢ ÍÁÙÅ ·Õèä´ ¤×Í %1000 «Öè§à¡Ô´¨Ò¡¡ÒùíÒ¢ ÍÁÙÅ㹺Ե¹ÑÂÊíҤѭµèíÒÊØ´ «Ö觨ÐÍÂÙ ã¹ËÅÑ¡¢ÇÒÊØ´¢Í§¢ ÍÁÙÅàÅ¢°Ò¹Êͧ ÁҨѴàÃÕ§ãËÁ à· Ò·Õèä´ ÃѺ¡ÒáíÒ˹´ã¹¤íÒÊÑè§ REV 㹡óչÕé¢ ÍÁÙÅ·Õèµ Í§·íÒ¡ÒÃÊÅѺµíÒá˹ §áÅйíÒÁÒáÊ´§ ¼ÅÁÕà¾Õ§ 4 ºÔµ ¼ÅÅѾ¸ ·äÕè ´ ¨§Ö ෠ҡѺ %1000 â»Ãá¡ÃÁµÑÇÍ ҧáÊ´§¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè REV ÁÕ´§Ñ ¹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} DEBUG BIN ? %11001011 REV 4

àÁ×Íè ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ ¼Å·Õäè ´ ෠ҡѺ %1101 «Ö§è ä´ ¨Ò¡¡ÒùíÒ¢ ÍÁÙÅ 4 ºÔµÅ Ò§µÒÁ·Õäè ´ ÃºÑ ¡ÒáíÒ˹´ ÁÒ¨Ò¡¤íÒÊѧè REV 4 ÁҨѴàÃÕ§ ͹¡ÅѺãËÁ â´ÂºÔµ¹ÑÂÊíҤѭµèÒí ÊØ´¨Ð¡ÅÒÂà» ¹ÊÙ§ÊØ´ Ê Ç¹Ôºµµ ÍÁÒ¡ç¨ÐÁÕ¡ÒÃà»ÅÕÂè ¹ á»Å§µÒÁÅíҴѺ ¢ ÍÁÙÅ 4 ºÔµÅ Ò§·Õ¹è Òí ÁҨѴàÃÕ§ãËÁ ¤Í× %1011 àÁ×Íè ·íÒ¡ÒèѴàÃÕ§ ͹¡ÅѺâ´ÂãË ºµÔ ¹ÑÂÊíҤѭµèÒí ÊØ´ ÁÒÍÂÙà » ¹ËÅѡ˹ Ò ¨Ò¡¹Ñ¹é ¨ÐäÅ àÃÕ§仵ÒÁÅíҴѺ ºÔµ 3 ¡ç¨Ð¡ÅÒÂà» ¹ºÔµ¹ÑÂÊíҤѭµèÒí ÊØ´ä»â´Â»ÃÔÂÒÂ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#


&

à» ¹¤íÒÊÑ§è ·Ò§Åͨԡ·Õ¡è Òí ˹´ãË ·Òí ¡ÒÃá͹´ (AND) ¢ ÍÁÙÅ 2 ¨íҹǹ â´ÂÁÕËÅѡࡳ± ´§Ñ ¹Õé 0&0=0 0&1=0 1&0=0 1&1=1 â»Ãá¡ÃÁµÑÇÍ ҧ¢Í§¡ÒÃá͹´ ¢Í ÁÙÅâ´Â㪠¤Òí Êѧè & ÁÕ´§Ñ ¹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} DEBUG BIN ? %00001111 & %10101101

àÁ×Íè ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ ¼Å¡ÒÃá͹´ ¨Ð»ÃÒ¡¯¢Ö¹é ·ÕËè ¹ Òµ Ò§ Debug Terminal «Ö§è ෠ҡѺ 00001101 (áÊ´§à» ¹ %1101)

$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


| (à» ¹¤Õº ¹¢Í§»ØÁ \ äÁ 㪠I ËÃ×Í l) à» ¹¤íÒÊÑ§è ·Ò§Åͨԡ·Õ¡è Òí ˹´ãË ·Òí ¡ÒÃÍÍà (OR) ¢ ÍÁÙÅ 2 ¨íҹǹ â´ÂÁÕËÅѡࡳ± ´§Ñ ¹Õé 0|0=0 0|1=1 1|0=1 1|1=1 â»Ãá¡ÃÁµÑÇÍ ҧ¢Í§¡ÒÃÍÍà ¢Í ÁÙÅâ´Â㪠¤Òí Êѧè | ÁÕ´§Ñ ¹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} DEBUG bin ? %00001111 | %10101101

àÁ×Íè ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ ¼Å¡ÒÃÍÍà ¨Ð»ÃÒ¡¯¢Ö¹é ·ÕËè ¹ Òµ Ò§ Debug Terminal «Ö§è ෠ҡѺ 10101111

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%


^ ´Ñ§¹Õé

à» ¹¤íÒÊÑ§è ·Ò§Åͨԡ·Õ¡è Òí ˹´ãË ·Òí ¡ÒÃàÍ硤ÅÙ«¿Õ -ÍÍà (XOR) ¢ ÍÁÙÅ 2 ¨íҹǹ â´ÂÁÕËÅѡࡳ± 0^0=0 0^1=1 1^0=1 1^1=0 â»Ãá¡ÃÁµÑÇÍ ҧ¢Í§¡ÒÃàÍ硤ÅÙ«¿Õ -ÍÍà ¢Í ÁÙÅâ´Â㪠¤Òí Êѧè ^ ÁÕ´§Ñ ¹Õé ' {$STAMP BS2p} ' {$PBASIC 2.5} DEBUG BIN ? %00001111 ^ %10101101

10100010

&

àÁ×èÍ·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ ¼Å¡ÒÃàÍ硤ÅÙ«Õ¿-ÍÍà ¨Ð»ÃÒ¡¯¢Öé¹·Õè˹ Òµ Ò§ Debug Terminal «Öè§à· ҡѺ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


º··Õè 5

¡Ò÷´Åͧ㪠§Ò¹¢Ò¾Íà µ¢Í§ i-Stamp2P24 i-Stamp2P24 ÁÕ¢Ò¾Íà µãË ãª §Ò¹ÁÒ¡¶Ö§ 16 ¢Ò¤×Í P0 ¶Ö§ P15 áÅзء¢ÒÊÒÁÒö¡íÒ˹´ãË ·Òí §Ò¹à» ¹¢Ò ÍÔ¹¾Øµà¾×Íè ÃѺÊÑ­­Ò³¢ ÍÁÙŨҡÀÒ¹͡ËÃ×ÍàÍÒµ ¾µØ ÊíÒËÃÑºÊ §ÊÑ­­Ò³¢ ÍÁÙÅÍÍ¡ä»ÀÒ¹͡ 㹺·¹Õ¨é СŠÒǶ֧ ¡ÒÃ㪠§Ò¹¢Ò¾Íà µ¢Í§ i-Stamp2P24 ã¹Åѡɳе Ò§æ ·Ñ§é ¡ÒÃà» ¹¢ÒàÍÒµ ¾µØ áÅÐÍÔ¹¾Øµ ¡ÒÃà¢Õ¹ËÃ×ÍÍ Ò¹¢ ÍÁÙÅ ¡Ñº¢Ò¾Íà µ¢Í§ i-Stamp2P24 ÊÒÁÒö¡ÃзíÒä´ â´ÂµÃ§ã¹ÃдѺºÔµÍÂÙá Å Ç â´Â¡ÒáíÒ˹´ª×Íè ¢Ò¾Íà µ¹Ñ¹é æ ¡µÑÇÍ ҧ OUT3 ¤×Í¡ÒáíÒ˹´ãË ¢Ò P3 ¢Í§ i-Stamp2P24 à» ¹àÍÒµ ¾µØ 㹡óշµÕè Í §¡ÒÃÍ Ò¹¢ ÍÁÙšѺ¢Ò ¾Íà µà» ¹¡ÅØÁ ÊÒÁÒö㪠»ÃÐ⪹ ¨Ò¡¡ÒèѴ¡ÅØÁ ¢ ÍÁÙÅã¹áºº¹ÔºàºÔÅ (4 ºÔµ) 亵 (8 ºÔµ) áÅÐàÇÔô (16 ºÔµ) Íѹ໠¹¡Òê ÇÂÅ´¢¹Ò´¢Í§â»Ãá¡ÃÁãË àÅç¡Å§ ¢Ò¾Íà µ¢Í§ i-Stamp2P24 ÊÒÁÒö¨Ñ´à» ¹¡ÅØÁ ä´ ·§Ñé ã¹ÃдѺ¹ÔºàºÔŠ亵 áÅÐàÇÔô â´Â¨Ð㪠µÇÑ ÍÑ¡Éà ᷹¤ÇÒÁËÁÒ¢ͧᵠÅСÅØÁ ´Ñ§¹Õé 㹡óը´Ñ ¡ÅØÁ Ẻ¹ÔºàºÔÅ ¢Ò P0 ¶Ö§ P3 㪠µÇÑ ÍÑ¡Éà A ¢Ò P4 ¶Ö§ P7 㪠µÇÑ ÍÑ¡Éà B ¢Ò P8 ¶Ö§ P11 㪠µÇÑ ÍÑ¡Éà C ¢Ò P12 ¶Ö§ P15 㪠µÇÑ ÍÑ¡Éà D 㹡óը´Ñ ¡ÅØÁ Ẻ亵 ¢Ò P0 ¶Ö§ P7 㪠µÇÑ ÍÑ¡Éà L ¢Ò P8 ¶Ö§ P15 㪠µÇÑ ÍÑ¡Éà H 㹡óը´Ñ ¡ÅØÁ ẺàÇÔô ¢Ò P0 ¶Ö§ P15 㪠µÇÑ ÍÑ¡Éà S ÃÕ¨ÊÔ àµÍà ·àÕè ¡ÕÂè Ç¢ ͧ¡Ñº¡ÒõԴµ Í¢Ò¾Íà µáÅÐÊÒÁÒö㪠¡ÒèѴ¡ÅØÁ ¹Õäé ´ ÁÕ´Ç Â¡Ñ¹ 3 ¤íÒÊÑ§è ¤×Í DIR, IN áÅÐ OUT â´ÂáÊ´§¤ÇÒÁÊÑÁ¾Ñ¹¸ ¢Í§ÃÕ¨ÊÔ àµÍà ¡ºÑ ¡ÒèѴ¡ÅØÁ ¢Í§¢Ò¾Íà µã¹áººµ Ò§æ ã¹µÒÃÒ§·Õè 5-1 ¶Ö§ 5-3 ¡ÒèѴ¡ÅØÁ ¢Ò¾Íà µ¨Ðª ÇÂÅ´¢¹Ò´¢Í§â»Ãá¡ÃÁä´ Í ҧäà ¡µÑÇÍ ҧ µ ͧ¡ÒÃãË ¢Ò P0 à» ¹ÍÔ¹¾Øµ, P1 à» ¹àÍÒµ ¾µØ , P2 à» ¹àÍÒµ ¾µØ áÅÐ P3 à» ¹ÍÔ¹¾Øµ ËÒ¡à¢Õ¹â»Ãá¡ÃÁ¾ÕàºÊÔ¡µÒÁ»¡µÔ ¨Ðä´ â»Ãá¡ÃÁ´Ñ§¹Õé DIR0 = 0 DIR1 = 1 DIR2 = 1 DIR3 = 0 Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'


ª×èÍàÇÔà ´ (16 ºÔµ) ª×èÍ亵 (8 ºÔµ) DIRH ª×è͹ԺàºÔÅ (4 ºÔµ) DIRD DIRC ª×èͺԵ DIR15 DIR14 DIR13 DIR12 DIR11 DIR10 DIR9 ¢Ò 2 # 2 " 2 ! 2 2 2 2'

DIRS

DIR8 2&

DIR7 2%

DIRB DIR6 DIR5 2$ 2#

DIRL DIR4 2"

DIR3 2!

DIRA DIR2 DIR1 2 2

DIR0 2

µÒÃÒ§·Õè 5-1 áÊ´§¤ÇÒÁÊÑÁ¾Ñ¹¸ ¢Í§¢Ò¾Íà µ¡ÑºÃÕ¨ÊÔ àµÍà ¡Òí ˹´·ÔÈ·Ò§ DIR â´Â¨Ñ´à» ¹¡ÅØÁ µÑ§é áµ ÃдѺºÔµ, ¹ÔºàºÔÅ, 亵 áÅÐàÇÔô ª×èÍàÇÔà ´ (16 ºÔµ) OUTS ª×èÍ亵 (8 ºÔµ) OUTH OUTL ª×è͹ԺàºÔÅ (4 ºÔµ) OUTD OUTC OUTB OUTA ª×èͺԵ OUT15 OUT14 OUT13 OUT12 OUT11 OUT10 OUT9 OUT8 OUT7 OUT6 OUT5 OUT4 OUT3 OUT2 OUT1 OUT0 ¢Ò 2 # 2 " 2 ! 2 2 2 2' 2& 2% 2$ 2# 2" 2! 2 2 2

µÒÃÒ§·Õè 5-2 áÊ´§¤ÇÒÁÊÑÁ¾Ñ¹¸ ¢Í§¢Ò¾Íà µ¡ÑºÃÕ¨ÊÔ àµÍà à¡çº¢ ÍÁÙÅàÍÒµ ¾µØ OUT â´Â¨Ñ´à» ¹¡ÅØÁ µÑ§é áµ ÃдѺºÔµ, ¹ÔºàºÔÅ, 亵 áÅÐàÇÔô ª×èÍàÇÔà ´ (16 ºÔµ) ª×èÍ亵 (8 ºÔµ) ª×è͹ԺàºÔÅ (4 ºÔµ) ª×èͺԵ IN15 ¢Ò 2 #

IN14 2 "

IND

INS

INH IN13 2 !

IN12 2

IN11 2

IN10 2

INC

IN9 2'

IN8 2&

IN7 2%

IN6 2$

INB

INL IN5 2#

IN4 2"

IN3 2!

IN2 2

INA

IN1 2

IN0 2

µÒÃÒ§·Õè 5-3 áÊ´§¤ÇÒÁÊÑÁ¾Ñ¹¸ ¢Í§¢Ò¾Íà µ¡ÑºÃÕ¨ÊÔ àµÍÃ Í¹Ô ¾Øµ IN â´Â¨Ñ´à» ¹¡ÅØÁ µÑ§é áµ ÃдѺºÔµ, ¹ÔºàºÔÅ, 亵 áÅÐàÇÔô µ ͧà¢Õ¹â»Ãá¡ÃÁ¶Ö§ 4 ºÃ÷Ѵ áµ ¶Ò 㪠¡ÒèѴ¡ÅØÁ ࢠҪ Ç ¨Ðà¢Õ¹â»Ãá¡ÃÁà¾Õ§ 1 ºÃ÷Ѵ´Ñ§¹Õé DIRA = %0110

ËÃ×͵ ͧ¡ÒÃà¢Õ¹â»Ãá¡ÃÁã¹ÃÙ»¢Í§àÅ¢°Ò¹ÊÔº ¨Ðä´ DIRA = 6

áÅж Òà¢Õ¹ã¹ÃÙ»¢Í§àÅ¢°Ò¹ÊԺˡ ¨Ðä´ DIRA = $6

㹡óբͧÃдѺ亵 áÅÐàÇÔô ¡çઠ¹à´ÕÂǡѹ ÊÒÁÒöà¢Õ¹â»Ãá¡ÃÁà¾Õ§ 1 ºÃ÷Ѵ´Ñ§µÑÇÍ ҧ DIRL = %10001111

ËÁÒ¤ÇÒÁÇ Ò ¡íÒ˹´ãË ¢Ò P0-P3 áÅÐ P7 à» ¹àÍÒµ ¾µØ ã¹¢³Ð·Õ¢è Ò P4-P6 à» ¹ÍÔ¹¾Øµ DIRS = %0000111100001111

ËÁÒ¤ÇÒÁÇ Ò ¡íÒ˹´ãË ¢Ò P0-P3, P8-P11 à» ¹¢ÒàÍÒµ ¾µØ áÅÐ¢Ò P4-P7, P12-P15 à» ¹¢ÒÍÔ¹¾Øµ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ·Õè 1 ¡ÒÃ㪠§Ò¹¢Ò¾Íà µ¢Í§ i-Stamp2P24 à» ¹¢ÒàÍÒµ ¾µØ à¤Ã×ͧÁ×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. µÑǵ Ò¹·Ò¹ 1/4W 5% 510: 1 µÑÇ 5. LED ÊÕá´§ 1 µÑÇ

¡ÒáíÒ˹´ãË ¢Ò¾Íà µà» ¹àÍÒµ ¾µØ ¡ÒáíÒ˹´ãË ¢Ò¾Íà µ P0 ¶Ö§ P15 ¢Í§ i-Stamp2P24 ·íҧҹ໠¹¢ÒàÍÒµ ¾Øµ ¨Ðµ ͧ·íÒ¡ÒÃà¢Õ¹ ¢ ÍÁÙÅ 1 ä»ÂѧÃÕ¨ÊÔ àµÍà DIR ¡ ͹àÊÁÍ â´Â¶ Òµ ͧ¡ÒÃãË ¢Ò P0 à» ¹¢ÒàÍÒµ ¾µØ µ ͧà¢Õ¹â»Ãá¡ÃÁ´Ñ§¹Õé DIR0 = 1 ¨Ò¡¹Ñ¹é ·íÒ¡ÒÃà¢Õ¹¢ ÍÁÙÅ·Õµè Í §¡ÒÃÊ §ÍÍ¡ä»Âѧ¢Ò¾Íà µ¹Ñ¹é â´ÂÊÒÁÒöà¢Õ¹â»Ãá¡ÃÁä´ ´§Ñ ¹Õé OUT0 = 1 à» ¹¡ÒÃÊ §¢ ÍÁÙÅ 1 ÍÍ¡ä»Âѧ¢Ò P0 OUT0 = 0 à» ¹¡ÒÃÊ §¢ ÍÁÙÅ 0 ÍÍ¡ä»Âѧ¢Ò P0

¡Ò÷´Åͧ

1.1 ¡ÒÃÊ §¢ ÍÁÙÅÍÍ¡·Ò§àÍÒµ ¾µØ â´Â㪠¤Òí Êѧè OUT 1.1 㪠ǧ¨Ãã¹ÃÙ»·Õè L1-1 㹡ÒôÅͧ 1.2 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB0101.BSP ´Ñ§¹Õé ' LAB0101.BSP ' Flash a LED ON P0 with OUT command ' {$STAMP BS2P} ' {$PBASIC 2.5} START: DIR0 = 1 ' Define P0 as OUTPUT OUT0 = 1 ' Turn ON LED PAUSE 500 ' Delay 0.5 seCONd OUT0 = 0 ' Turn off LED PAUSE 500 GOTO START

1.3 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹µÑÇ i-Stamp2P24 1.4 »Å´ä¿àÅÕÂé §ºÍà ´·´ÅͧÍÍ¡ áŠǵ Íǧ¨ÃµÒÁÃÙ»·Õè L1-1

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


P0

510

LED

i-Stamp2P24

ÃÙ»·Õè L1-1 ǧ¨Ã·´Åͧ¡ÒÃÊ §¢ ÍÁÙÅàÍÒµ ¾µØ ´ Ç¡ÒÃà¢Õ¹¢ ÍÁÙÅä»ÂѧÃÕ¨ÊÔ àµÍà OUT 1.5 ¨ ÒÂä¿àÅÕÂé § Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED LED ·Õµè Í ÍÂÙ¡ ºÑ ¢Ò P0 ¨ÐµÔ´-´ÑºÊÅѺ¡Ñ¹ËÃ×Íà¡Ô´¡ÒáоÃÔºã¹ÍѵÃÒ 0.5 ÇÔ¹Ò·Õ 1.6 á¡ ä¢â»Ãá¡ÃÁ LAB0101.BSP â´Âà¾ÔÁè ¤ Ңͧ PAUSE 500 à» ¹ PAUSE 1000 ·Ñ§é ËÁ´ áÅ ÇÃѹâ»Ãá¡ÃÁ Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED LED µÔ´-´Ñºã¹ÍѵÃÒ·Õªè Ò Å§ ¹Ñ¹è ¤×͵ԴáÅдѺ¹Ò¹¢Ö¹é 1.7 á¡ ä¢â»Ãá¡ÃÁ LAB0101.BSP â´ÂÅ´¤ Ңͧ¤íÒÊѧè PAUSE à» ¹ PAUSE 250 ·Ñ§é ËÁ´áÅ Ç·íÒ¡ÒÃÃѹâ»Ãá¡ÃÁ Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED LED µÔ´-´Ñº ã¹ÍѵÃÒ·Õàè ÃçÇ¢Ö¹é

1.2 ¡ÒÃÊ §¢ ÍÁÙÅÍÍ¡·Ò§àÍÒµ ¾µØ â´Â㪠¤Òí Êѧè HIGH áÅÐ LOW 1.8 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB0102.BSP ' LAB0102.BSP : Flash a LED ON P0 with HIGH AND LOW command ' {$STAMP BS2P} ' {$PBASIC 2.5} OUT CON 1 ' Define OUT TO be 1 DATA DELAY_T CON 500 ' Define delay time TO be 0.5 seCONd DIR0 = OUT ' P0 as OUTPUT LOOP1: HIGH 0 ' Turn ON LED PAUSE DELAY_T ' Delay 0.5 seCONd LOW 0 ' Turn off LED PAUSE DELAY_T GOTO LOOP1

1.9 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 áÅÐÂѧ¤§ãª ǧ¨Ãã¹ÃÙ»·Õè L1-1 㹡Ò÷´Åͧ 1.10 Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED à»ÃÕºà·Õº¡Ñº¼Å·Õäè ´ ã¹¢ Í 1.4 ¾ºÇ Ò ¼Å¡Ò÷íÒ§Ò¹àËÁ×͹¡Ñ¹

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


1.3 ¡ÒÃÊ §¢ ÍÁÙÅÍÍ¡·Ò§àÍÒµ ¾µØ â´Â㪠¤Òí Êѧè à¡ÕÂè ǡѺ¡ÒÃǹÅÙ» 1.11 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB0103.BSP ' LAB0103.BSP : Flash a LED ON P0 with looping technique ' {$STAMP BS2P} ' {$PBASIC 2.5} TIMES VAR Byte ' Define times TO be Byte variable OUT CON 1 LED CON 0 DELAY_T CON 500 DIR0 = OUT FOR TIMES = 1 TO 50 HIGH LED : PAUSE DELAY_T LOW LED : PAUSE DELAY_T DEBUG ? TIMES NEXT DEBUG "DONE !" DONE: GOTO DONE

¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ ã¹â»Ãá¡ÃÁ¹Õéµ Í§¡ÒâѺ LED ·Õè¢Ò P0 ãË µÔ´´Ñºã¹ÍѵÃÒ 0.5 ÇÔ¹Ò·Õ â´Â㪠෤¹Ô¤¡ÒÃǹÅÙ» (looping) ´ ǤíÒÊѧè FOR...NEXT µÑÇá»Ã TIMES ¡íÒ˹´ãË ÁÅÕ ¡Ñ ɳТͧ¢ ÍÁÙÅà» ¹äºµ (8 ºÔµ) ¹Ñ¹è ¤×Í ¨ÐÁÕ¤Ò ä´ µ§Ñé áµ 0255 áÅÐã¹â»Ãá¡ÃÁ¹Õ¡é Òí ˹´ãË ãª Ê§Ù ÊØ´à¾Õ§ 50 ¶ Òµ ͧ¡ÒÃãË ¤Ò ¢Í§ TIMES ÊÙ§¡Ç Ò 255 ¡çÊÒÁÒö·íÒä´ â´Â¡ÒÃà¢Õ¹â»Ãá¡ÃÁ㹺Ã÷Ѵ TIMES VAR BYTE ãËÁ à» ¹ TIMES VAR WORD ¨ÐÊÒÁÒö¡íÒ˹´¤ Ңͧ TIMES ä´ µ§Ñé áµ 0-65535 ¨íҹǹ¡ÒõԴ´Ñº¢Í§ LED ¡íÒ˹´â´Â¤ Ңͧ TIMES «Ö§è ã¹·Õ¹è ¤Õé Í× 50 Ãͺ áµ ÅÐÃͺÁÕ굄 ÃÒ¡ÒõԴ´Ñº 0.5 ÇÔ¹Ò·Õ ·Ø¡¤ÃÑ§é ·Õè LED µÔ´´Ñº ¨Ðᨠ§ãË ·ÃÒº¶Ö§¨íҹǹÃͺ¢Í§¡ÒõԴ´Ñº¼ Ò¹·Ò§Ë¹ Òµ Ò§ Debug Terminal ·Ñ§é ¹Õàé » ¹¼ÅÁÒ¨Ò¡¤íÒÊѧè DEBUG ? TIMES áÅÐàÁ×Íè ¤Ãº 50 Ãͺ ¡ç¨ÐáÊ´§¢ ͤÇÒÁ DONE ! 1.12 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹µÑÇ i-Stamp2P24 áÅÐÂѧ¤§ãª ǧ¨Ãã¹ÃÙ»·Õè L1-1 㹡Ò÷´Åͧ 1.13 Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED áÅСÒÃáÊ´§¼Å¢Í§Ë¹ Òµ Ò§ DEBUG Terminal LED ¨ÐµÔ´-´Ñºã¹ÍѵÃÒ 0.5 ÇÔ¹Ò·Õ áÅзء¤ÃÑ駷ÕèÁÕ¡ÒõԴ-´Ñº ·Õè˹ Òµ Ò§ DEBUG Terminal ¨Ð áÊ´§¨íҹǹ¤ÃÑ§é ¢Í§¡ÒõԴ-´Ñº ¨¹¡ÃÐ·Ñ§è ¤Ãº 50 ¤ÃÑ§é ¨ÐáÊ´§¢ ͤÇÒÁ Done áÅ ÇËÂØ´·íÒ§Ò¹ LED ´Ñº ã¹ÃÙ» ·Õè L1-2

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


ÃÙ»·Õè L1-2 ¼Å¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁ LAB0103.BSP ·Õáè Ê´§º¹Ë¹ Òµ Ò§ Debug Terminal

1.4 Ê §¢ ÍÁÙÅÍÍ¡·Ò§àÍÒµ ¾µØ â´Â㪠â»Ãá¡ÃÁ Í 1.14 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB0104.BSP ' LAB0104.BSP Flash LED ON P0 by a subroutine technique ' {$STAMP BS2P} ' {$PBASIC 2.5} TIMES VAR Byte OUT CON 1 LED CON 0 DELAY_T CON 500 DIR0 = OUT START: FOR TIMES = 1 TO 50 GOSUB FLASH NEXT DEBUG "DONE !" DONE: GOTO DONE

"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


FLASH: HIGH LED PAUSE DELAY_T LOW LED PAUSE DELAY_T DEBUG ? TIMES RETURN

¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ à» ¹¡ÒÃ㪠â»Ãá¡ÃÁ ÍÂ㹡ÒâѺ LED ãË µ´Ô ´Ñº´ Ç¡ÒÃ㪠¤Òí Êѧè GOSUB áÅзպè Ã÷ѴÊØ´· Ò¢ͧ·Ø¡â»Ãá¡ÃÁ  Íµ ͧãÊ ¤Òí Êѧè RETURN àÁ×Íè àÃÕ¡㪠¤Òí Êѧè GOSUB ËÃ×Í¡ÃÐâ´´ä»·íÒ§Ò¹Âѧâ»Ãá¡ÃÁ Í¨ÐÁÕ¡ÒÃà¡çº¤ ÒáÍ´à´ÃÊ ¡ ͹˹ Ò·Õ¨è СÃÐâ´´ä»äÇ ã¹Êáµç¡ ËÅѧ¨Ò¡·Õ·è Òí §Ò¹ã¹â»Ãá¡ÃÁ ÍÂàÃÕºà ÍÂáÅ ÇËÃ×;º¤íÒÊѧè RETURN ¤ ÒáÍ´à´ÃÊ ·Õàè ¡çºäÇ ã¹Êáµç¡¨Ð¶Ù¡àÃÕ¡¡ÅѺÁÒ ·íÒãË i-Stamp2P24 ¡ÅѺ价íÒ§Ò¹µ ÍËÅѧ¨Ò¡¡ÃÐâ´´ÁÒ·íÒ§Ò¹·Õâè »Ãá¡ÃÁ ÍÂáÅ Ç ¤íÒÊѧè GOSUB ¨Ðᵡµ Ò§¡Ñº GOTO µÃ§·Õè GOSUB ¨Ðà» ¹¡ÒáÃÐâ´´ä»·íÒ§Ò¹·Õµè Òí á˹ §Í×¹è ªÑÇè ¤ÃÒÇ áÅÐ ¨Ð¡ÅѺÁÒàÁ×Íè ¾º¤íÒÊѧè RETURN ã¹¢³Ð·Õ¤è Òí Êѧè GOTO ¨Ðà» ¹¡ÒáíÒ˹´ãË i-Stamp2P24 ä»·íÒ§Ò¹ÂѧµíÒá˹ §·Õè ¡íÒ˹´áÅ ÇäÁ µÍ §¡ÅѺÁÒ àÇ ¹áµ ¨ÐÁÕ¡ÒÃ㪠¤Òí Êѧè GOTO à¾×Íè ¡íÒ˹´ãË ¡ÅѺÁÒ·íÒ§Ò¹µ ͨҡáÍ´à´ÃÊ·ÕÍè ÂÙ¶ ´Ñ ¨Ò¡¤íÒ Êѧè GOTO ¡ ͹˹ Ò¹Õé 1.15 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹µÑÇ i-Stamp2P â´Â¡Òá´»ØÁ RUN 1.16 Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED áÅСÒÃáÊ´§¼Å¢Í§Ë¹ Òµ Ò§ DEBUG Terminal LED ¨ÐµÔ´-´Ñºã¹ÍѵÃÒ 0.5 ÇÔ¹Ò·Õ áÅзء¤ÃÑ§é ·ÕÁè ¡Õ ÒõԴ-´Ñº ·ÕËè ¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¨íҹǹ ¤ÃÑ§é ¢Í§¡ÒõԴ-´Ñº ¨¹¤Ãº 50 ¤ÃÑ§é ¨ÐáÊ´§¢ ͤÇÒÁ Done áÅ ÇËÂØ´·íÒ§Ò¹ àËÁ×͹¡Ñº¡Ò÷´Åͧ¢ Í 1.12 i-Stamp2p24

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#


¡Ò÷´Åͧ·Õè 2 ¡ÒÃÃѺ¢ ÍÁÙÅÍÔ¹¾Øµ¨Ò¡ÊÇÔµª â´Âãª Ã¨Õ ÊÔ àµÍà IN à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 10k: 1 µÑÇ 510: 4 µÑÇ 5. ä´âÍ´à»Å §áʧÊÕá´§ 4 µÑÇ 6. ´Ô»ÊÇÔµª 8 ¨Ø´ 1 µÑÇ

¡ÒáíÒ˹´ãË ·Òí §Ò¹à» ¹¢ÒÍÔ¹¾Øµ ¡ÒáíÒ˹´ãË ¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·íҧҹ໠¹¢ÒÍÔ¹¾Øµ ¨Ðµ ͧà¢Õ¹¢ ÍÁÙÅ 0 ä»ÂѧÃÕ¨ÊÔ àµÍà DIR 㹺Ե·Õãè ª á·¹µíÒá˹ §¢Í§¢Ò¾Íà µ·Õµè Í §¡Òà 㹢³Ð·Õ·è Ò§ÎÒà ´áÇà ¤Çõ ͵Ñǵ Ò¹·Ò¹¾ÙÅÍÑ»äÇ ·¢Õè Ò¾Íà µ«Ö§è ¡íÒ˹´ãË à» ¹ÍÔ¹¾Øµ ´Ñ§¹Ñ¹é ¤ÇáíÒ˹´ãË ·Òí §Ò¹·ÕÅè ͨԡ 0 ¡Å ÒǤ×Í ¶ ÒäÁ Á¡Õ Òá´ÊÇÔµª ËÃ×ÍäÁ ÁÍÕ ¹Ô ¾Øµ ·Õ¢è Ò ¾Íà µ¹Ñ¹é ¨ÐÁÕʶҹÐÅͨԡ໠¹ 1 à¹×Íè §¨Ò¡µ ͵Ñǵ Ò¹·Ò¹¾ÙÅÍÑ»äÇ ´Ñ§ã¹ÃÙ»·Õè L2-1 àÁ×Íè ¡´ÊÇÔµª ·Òí ãË ¢Ò¾Íà µ ¶Ù¡µ Íŧ¡ÃÒÇ´ à¡Ô´à» ¹Åͨԡ 0 ·íÒãË ·ÃÒºÇ Ò ¢³Ð¹ÕÁé ÊÕ ­ Ñ ­Ò³ÍÔ¹¾Øµà¡Ô´¢Ö¹é áÅ Ç ã¹´ Ò¹¡ÒÃà¢Õ¹â»Ãá¡ÃÁÊÒÁÒö㪠¡ÒõÃǨÊͺ¤ Ò·ÕÃè ¨Õ ÊÔ àµÍà IN à¾×Íè µÃǨÊͺʶҹзբè Ò¾Íà µ¹Ñ¹é ËÃ×ͨÐ㪠¤Òí Êѧè BUTTON 㹡óշ¢Õè Ò¾Íà µ¹Ñ¹é µ ͡ѺÊÇÔµª Ẻ¡´µÔ´»Å Í´Ѻ㹡ÒÃÍ Ò¹¤ ÒÍÔ¹¾Øµ +5V

10k P8

i-Stamp2P24 S1

ÃÙ»·Õè L2-1 ¡Òõ ÍÊÇÔµª ࢠҡѺ¢Ò¾Íà µ¢Í§ i-Stamp2P24

$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¢ ͤÇÃÃÐÇѧ㹡ÒÃ㪠§Ò¹¢Ò¾Íà µ¢Í§ i-Stamp2P24 à» ¹¢ÒÍÔ¹¾Øµ àÁ×Íè ÁÕ¡ÒÃ㪠§Ò¹¢Ò¾Íà µã´¢Í§ i-Stamp2P24 à» ¹ÍÔ¹¾ØµáÅ Ç ¨Ðµ ͧÃÐÁÑ´ÃÐÇѧÍ Òà¢Õ¹¢ ÍÁÙÅ 1 ŧã¹ÃÕ ¨ÔÊàµÍà DIR ·Õµè Òí á˹ §ºÔµ¢Í§¢Ò¾Íà µ·Õ¡è Òí ˹´à» ¹ÍÔ¹¾ØµÍ ҧà´ç´¢Ò´ ¡µÑÇÍ ҧ ËÒ¡¡íÒ˹´¢Ò P0-P3 à» ¹¢Ò ÍÔ¹¾Øµ áÅÐÁÕ¡Òõ ÍÊÇÔµª ¾Ã ÍÁµÑǵ Ò¹·Ò¹¾ÙÅÍѻࢠҷբè Ò¾Íà µ·Ñ§é 3 áÅ Ç µ ͧäÁ à¢Õ¹¤íÒÊÑ§è µ Í仹ÕÍé  ҧà´ç´¢Ò´ DIRA = %1111 ¤íÒÊÑ§è ´Ñ§¡Å ÒÇà» ¹¡ÒáíÒ˹´ãË ¢Ò¾Íà µã¹¡ÅØÁ A «Ö§è ¡ç¤Í× ¢Ò P3 ¶Ö§ P0 à» ¹¢ÒàÍÒµ ¾µØ ÊíÒËÃÑºÊ §áç´Ñ¹ ÍÍ¡ ã¹¢³Ð·ÕÇè §¨Ã·Ò§ÎÒà ´áÇà ¡Òí ˹´ãË ¢Ò P3 ¶Ö§ P0 à» ¹ÍÔ¹¾ØµÊíÒËÃѺÃѺáç´Ñ¹à¢ Ò ËÒ¡ÁÕ¡Òá´ÊÇÔµª Í¹Ñ à» ¹ ¡Òõ Í¢Ò¾Íà µÅ§¡ÃÒÇ´ ·íÒãË à¡Ô´¡ÒÃÅѴǧ¨ÃàÍÒµ ¾µØ ¢Í§¢Ò¾Íà µ¹Ñ¹é ŧ¡ÃÒÇ´ ·¹Ñ ·Õ Ê §¼ÅãË ¢Ò¾Íà µ¹Ñ¹é àÊÕÂËÒÂä´

¡Ò÷´Åͧ 2.1 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB0201.BSP '***************************************************************************** ' Program : LAB0201.BSP ' Description : Control LED moving direction by a switch ' Hardware : Connect LEDs to P0-P3, Connect push button switch to P8 '***************************************************************************** ' {$STAMP BS2p} ' {$PBASIC 2.5} DIRS = %0000000011111111 DELAY CON 500 DELAY2 CON 150 CONTROL: IF (IN8 = 0) THEN RIGHTWAY LEFTWAY: OUTB = %0000 PAUSE DELAY OUT4 = 1 :PAUSE DELAY OUT5 =1 : PAUSE DELAY OUT6 = 1 : PAUSE DELAY OUT7 = 1 : PAUSE DELAY2 GOTO CONTROL RIGHTWAY: OUTB = %0000 PAUSE DELAY OUT7 = 1 PAUSE DELAY OUT6 =1 PAUSE DELAY OUT5 = 1 PAUSE DELAY OUT4 = 1 PAUSE DELAY2 GOTO CONTROL

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%


+5V

P3

10k P8

P2 i-Stamp2P24

P1

S1 P0

510

LED4

510

LED3

510

LED2

510

LED1

ÃÙ»·Õè L2-2 ǧ¨ÃÊíÒËÃѺ¡Ò÷´Åͧ·Õè 2 ¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ â»Ãá¡ÃÁ¹Õàé » ¹â»Ãá¡ÃÁä¿ÇÔ§è ·ÕÊè ÒÁÒö¤Çº¤ØÁ·ÔÈ·Ò§¡ÒÃÇÔ§è â´Â¡ÒõÃǨÊͺʶҹзբè Ò P8 ¢Í§ i-Stamp2P24 ËÒ¡äÁ Á¡Õ Òá´ÊÇÔµª LED ·Õµè Í ÍÂÙ¡ ºÑ ¢Ò P3-P0 ¨ÐÇÔ§è ä»·Ò§« Ò â´Â¡ÃÐâ´´ä»·íÒ§Ò¹·ÕÅè ÒàºÅ LEFTWAY LED ·Õµè Í ÍÂÙ¡ ºÑ ¢Ò P3-P0 ¨ÐµÔ´äÅ ·ÅÕ Ð´Ç§ µÑ§é áµ ¢Ò P0 ¨¹¶Ö§ P3 ÁÕÅ¡Ñ É³Ð¤Å ÒÂæ ¡ÑºÅÙ¡Èþا ä»·Ò§« Ò ¨Ò¡¹Ñ¹é ¨Ð¡ÃÐâ´´ ¡ÅѺ仵ÃǨÊͺʶҹзբè Ò P8 ËÒ¡ÁÕ¡Òá´ÊÇÔµª à¡Ô´¢Ö¹é ·íÒãË ¢Ò P8 à» ¹Åͨԡ 0 â»Ãá¡ÃÁ¨Ð¡ÃÐâ´´ä»ÂѧÅÒ àºÅ RIGHTWAY «Ö§è ¡íÒ˹´ãË LED ·Õ¢è Ò P3 ¶Ö§ P0 µÔ´äÅ ã¹·ÔÈ·Ò§·Õµè ç¢ ÒÁ¡Ñº LEFTWAY â´Â¨ÐàÃÔÁè ·Õè LED ·Õµè Í ÍÂÙ ¡Ñº¢Ò P3 ¡ ͹ äÅ ÂÍ ¹¡Ñºä»¨¹¶Ö§¢Ò P0 ¤Å Ò¡ѺÅÙ¡ÈÃÇÔ§è ä»·Ò§¢ÇÒ ¨Ò¡¹Ñ¹é ¨Ð¡ÃÐâ´´¡ÅѺ仵ÃǨÊͺʶҹÐÅͨԡ ·Õ¢è Ò P8 ÍÕ¡¤Ãѧé â»Ãá¡ÃÁ¨Ð·íҧҹǹÍÂÙà ª ¹¹Õé 2.2 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹µÑÇ i-Stamp2P24 2.3 »Å´ä¿àÅÕÂé §ºÍà ´·´ÅͧÍÍ¡ áŠǵ Íǧ¨ÃµÒÁÃÙ»·Õè L2-2 2.4 ¨ ÒÂä¿àÅÕÂé § Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED LED ¨ÐµÔ´äÅ ä»·ÕÅдǧ¨Ò¡ P3 ¶Ö§ P0 ¨¹¤Ãº 4 ´Ç§ ÁÕÅ¡Ñ É³Ð¤Å ÒÂÅÙ¡Èþا ä»·Ò§« Ò 2.5 ¡´ÊÇÔµª S1 Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED LED ¨ÐµÔ´äÅ ä»·ÕÅдǧ¨Ò¡ P3 ¶Ö§ P0 ¨¹¤Ãº 4 ´Ç§ ÁÕÅ¡Ñ É³Ð¤Å ÒÂÅÙ¡Èþا ä»·Ò§¢ÇÒ «Ö§è ¨ÐµÃ§ ¢ ÒÁ¡Ñº¡Ò÷´Åͧ㹢 Í 2.4 2.6 »Å ÍÂÊÇÔµª S1 Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED ÍÕ¡¤Ãѧé i-Stamp2p24

&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ·Õè 3 ÃѺ¤ ҢͧÊÇÔµª ÁÒ¡¡Ç Ò 1 µÑÇ â´Âãª Ã¨Õ ÊÔ àµÍà IN à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 10k: 4 µÑÇ 510: 4 µÑÇ 5. ÊÇÔµª ¡´µÔ´»Å Í´Ѻ 4 µÑÇ 6. ä´âÍ´à»Å §áʧÊÕá´§ 4 µÑÇ

¡Ò÷´Åͧ 3.1 㪠ǧ¨Ãã¹ÃÙ»·Õè L3-1 㹡Ò÷´Åͧ +5V

10k

10k

10k

10k P11

P3

P10

P2

P9 P8

S4

S3

S2

i-Stamp2P24

P1 P0

510

LED4

510

LED3

510

LED2

510

LED1

S1

ÃÙ»·Õè L3-1 ǧ¨ÃÊíÒËÃѺ¡Ò÷´Åͧ·Õè 3

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'


3.2 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB0301.BSP '**************************************************************************************************** ' Program : LAB0301.BSP ' Description : READ switch s DATA AND display complement logic from switch pressing) ' Hardware : Connect LEDs TO P0-P3, connect 4 push switch TO P8-P11 '**************************************************************************************************** ' {$STAMP BS2p} ' {$PBASIC 2.5} DIRS = %0000000011111111 ' P0-P7 as outputs AND P8-P15 as inputs SHOW VAR Byte B1=15 MAIN: SHOW=INC ' Receive binary from switch GOTO DISPLAY DISPLAY: B0=B1-SHOW ' Invert binary from switch LOOKUP B0,[00,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15],OUTA GOTO MAIN

¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ àÃÔÁè µ ¹´ Ç¡ÒáíÒ˹´ãË ¢Ò P0 ¶Ö§ P7 à» ¹¢ÒàÍÒµ ¾µØ ã¹¢³Ð·Õè P8 ¶Ö§ P15 à» ¹¢ÒÍÔ¹¾Øµ µÑÇá»ÃÊíÒËÃѺ ÃѺ¤ Ò¨Ò¡¡Òá´ÊÇÔµª ¤Í× SHOW â´Â¡íÒ˹´ãË à» ¹µÑÇá»Ãã¹ÃдѺ亵 àÁ×Íè ·íÒ¡ÒÃÍ Ò¹¤ Ò¨Ò¡¢ÒÍÔ¹¾Øµã¹¡ÅØÁ C ¤×Í¢Ò P11 ¶Ö§ P8 ¡ç¨Ð¡ÃÐâ´´ä»Âѧâ»Ãá¡ÃÁáÊ´§¼Å DISPLAY à¾×Íè á»Å§¤ ҢͧÊÇÔµª ·¶Õè ¡Ù ¡´à» ¹µÑÇàÅ¢°Ò¹ Êͧ¢Ñº LED áµ à¹×Íè §¨Ò¡ÊÇÔµ¢ ·µÕè Í ÍÂÙ¶ ¡Ù ¡íÒ˹´ãË ·Òí §Ò¹ã¹ÅѡɳÐËÒ¡à¡Ô´¡Òá´ÊÇÔµª ¨Ðà¡Ô´Åͨԡ 0 » ͹ ࢠÒÊÙ i-Stamp2P ¡µÑÇÍ ҧ ¡´ÊÇÔµª S1 à¾Õ§µÑÇà´ÕÂÇ ·Õ¢è Ò¾Íà µ¡ÅØÁ C ¨Ðà¡Ô´¤ Ò %0111 ¢Ö¹é áµ à¹×Íè §¨Ò¡¡íÒ˹´ãË ¡Òà ¡´ÊÇÔµª ¤Í× ¡Òû ͹¢ ÍÁÙÅ ´Ñ§¹Ñ¹é àÁ×Íè ¡´ÊÇÔµª S1 à¾Õ§µÑÇà´ÕÂÇ ¨Ðµ Í§ä´ ¼ÅÅѾ¸ ¤Í× %1000 ¨Ö§µ ͧÁÕ¡ÒÃá»Å§ ¤ Òâ´Â㪠¡Ãкǹ¡Ò÷ҧ«Í¿µ áÇà ¹Ñ¹è ¤×Íà¢Õ¹â»Ãá¡ÃÁ㹺Ã÷Ѵ B0=B1-SHOW â´Â¡íÒ˹´ãË ¤Ò B1=15 Ê Ç¹¤ Ò SHOW ä´ ÁÒ¨Ò¡¡ÒÃÍ Ò¹¤ ÒÊÇÔµª ࢠÒÁÒ ¨Ò¡¹Ñ¹é ¨Ö§¹íҼšÒÃá»Å§«Ö§è à¡çºÍÂÙã ¹ B0 ä»·íÒ¡ÒÃà» ´µÒÃÒ§¢ ÍÁÙÅ´ Ç ¤íÒÊѧè LOOKUP áŠǨ֧áÊ´§¼Å·Õè LED µ Íä» ´Ñ§¹Ñ¹é àÁ×Íè äÁ Á¡Õ Òá´ÊÇÔµª ·Õè LED ¨Ð´ÑºËÁ´µÅÍ´àÇÅÒ 3.3 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stqmp2P24 Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED 3.4 ·´Åͧ¡´ÊÇÔµª à¾×Íè » ͹¤ ÒàÅ¢°Ò¹Êͧ¤ Òµ Ò§æ ÊÑ¡ 10 ¤ Ò áÅ ÇÊѧࡵ¡ÒÃáÊ´§¼Å¢Í§ LED LED ¨ÐáÊ´§¤ ÒµÒÁ¡Òû ͹¤ ҢͧÊÇÔµª i-Stamp2p24

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ·Õè 4 ÃÙàÅçµµ áʵÁ» à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 510: 8 µÑÇ 10k: 1 µÑÇ 5. ÊÇÔµª ¡´µÔ´»Å Í´Ѻ 1 µÑÇ 6. ä´âÍ´à»Å §áʧÊÕá´§ 8 µÑÇ

¡Ò÷´Åͧ 4.1 㪠ǧ¨Ãã¹ÃÙ»·Õè L4-1 㹡Ò÷´Åͧ â´Âµ Íǧ¨Ãŧº¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´

P7 +5V P6 P5

10k

P4

P8 i-Stamp2P24

P3

S1 P2 P1 P0

510

LED8

510

LED7

510

LED6

510

LED5

510

LED4

510

LED3

510

LED2

510

LED1

% $ # " !

ÃÙ»·Õè L4-1 ǧ¨Ã·´ÅͧÃÙàÅçµµ áʵÁ»

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


4.2 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB0401.BSX '***************************************************************************************** ' Program : LAB0401.BSP ' Hardware : Connect 8 OUTPUT LEDs TO P0-P7 AND connect active LOW INPUT switch TO P8 '***************************************************************************************** ' {$STAMP BS2P} ' {$PBASIC 2.5} DRAW VAR Bit ' Define Bit TO keep draw status DELAY_LOOP VAR Byte ' Define Byte variable TO keep delay LOOP DIRL=$FF ' Define P0-P7 as outputs DRAW=0 ' Clear draw status OUTL=128 ' Define first state OUTPUT (%10000000) LOOP1: IF IN8=0 THEN SHIFT_OP ' Receive INPUT from BUTTON, Shift OUTPUT IF pressed IF DRAW=0 THEN LOOP1 ' Check draw status, back to loop if not drawn FOR DELAY_LOOP=0 TO 39 ' Shift LED with delay PAUSE DELAY_LOOP*5 MIN 20 ' Multiple delay dycle, start from 20 ms. GOSUB SHIFT_LED ' GOTO subroutine Shift LED NEXT ' END of LOOP DRAW=0 ' Clear draw status PAUSE 1000 ' Delay 1 sec. GOTO LOOP1 ' Goto loop SHIFT_OP: DRAW=1 ' Set draw status GOSUB SHIFT_LED ' GOTO subroutine Shift LED PAUSE 20 ' Delay 20 ms. GOTO LOOP1 ' Goto loop SHIFT_LED: IF OUTL=1 THEN RELOAD ' Check last OUTPUT already? reload IF last. (%00000001) OUTL=OUTL/2 ' Shift TO NEXT OUTPUT GOTO SHIFT_EXIT ' RETURN RELOAD: OUTL=128 ' Define first state OUTPUT (%10000000) SHIFT_EXIT: RETURN ' RETURN

4.3 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 ·íÒ¡Òá´ÊÇÔµª áŠǻŠÍÂÊѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED àÁ×Íè àÃÔÁè µ ¹·íÒ§Ò¹ LED µíÒá˹ § 0 µÔ´ àÁ×Íè ¡´ÊÇÔµª LED ·Ñ§é á»´µÑǨеԴÊÇ Ò§àËÁ×͹ä¿ÇÔ§è áÅÐàÁ×Íè »Å ÍÂÊÇÔµª LED ¨ÐÇÔ§è ª Òŧ ¨¹¡Ãзѧè ËÂØ´ÇÔ§è ÁÕ LED µÔ´à¾Õ§µÑÇã´µÑÇ˹֧è áÊ´§¼Å¡ÒÃàÊÕÂè §·ÒÂÍÍ¡ÁÒ i-Stamp2p24

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ·Õè 5 ǧ¨ÃàÅ×Í¡ÊÑ­­Ò³Í ҧ§ Ò à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 510: 8 µÑÇ 10k: 1 µÑÇ 5. ÊÇÔµª ¡´µÔ´»Å Í´Ѻ 1 µÑÇ 6. ä´âÍ´à»Å §áʧÊÕá´§ 8 µÑÇ

¡ÒÃÃѺ¤ ÒÍÔ¹¾Øµâ´Â㪠¤Òí Êѧè BUTTON àÁ×è͵ ÍÊÇÔµª ¡´µÔ´»Å Í´ѺࢠҡѺ¢Ò¾Íà µ¢Í§ i-Stamp2p24 àÁ×èÍ·íÒ¡Òá´ÊÇÔµª ÊÔ觷Õèà¡Ô´¢Öé¹ ¤×Í ¡ ͹·ÕËè ¹ ÒÊÑÁ¼ÑʢͧÊÇÔµª ¨Ðµ Ͷ֧¡Ñ¹Í ҧÊÁºÙó ¨Ðà¡Ô´ÊÑ­­Ò³Ãº¡Ç¹¢Ö¹é àÃÕÂ¡Ç Ò àºÒ« (bounce) ´Ñ§ áÊ´§ã¹ÃÙ»·Õè L5-1 ·íÒãË ¡ÒÃÍ Ò¹¤ ÒÊÇÔµª ´Ç ¤íÒÊѧè IN Í񬊫 ¤Ò ·Õäè Á á¹ ¹Í¹ ´Ñ§¹Ñ¹é à¾×Íè ãË ÊÒÁÒÃ¶Í Ò¹¤ Ңͧ ÊÇÔµª ä´ Í ҧáÁ ¹ÂíÒ¨Ö§¤ÇÃ㪠¤íÒÊÑè§ BUTTON áÅСíÒ˹´¤ Ò˹ ǧàÇÅÒÊíÒËÃѺ¡ÒÃÍ Ò¹¤ ÒãË àËÁÒÐÊÁ ¡ç¨Ðä´ ¤Ò ¢Í§ÊÇÔµª ·ÊÕè ÁºÙó ÍÍ¡ÁÒ ÃдѺáç´Ñ¹¡ ͹¡´ÊÇÔµª

ÊÑ­­Ò³Ãº¡Ç¹·Õèà¡Ô´¢Öé¹ ÃдѺáç´Ñ¹ËÅѧ¡´ÊÇÔµª (à¹×èͧ¨Ò¡ÊÇÔµª µ Íŧ¡ÃÒÇ´ äÇ )

ÃÙ»·Õè L5-1 ÊÑ­­Ò³Ãº¡Ç¹·Õàè ¡Ô´¢Ö¹é ¨Ò¡¡Òá´ÊÇÔµª ËÃ×Í·Õàè ÃÕÂ¡Ç Ò àºÒ« (bounce)

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


ÃٻẺ¡ÒÃ㪠¤Òí Êѧè BUTTON ÁÕ´§Ñ ¹Õé BUTTON pin, downstate, DELAY, rate, bytevariable, targetstate, address

â´Â·Õè

pin à» ¹¡ÒáíÒ˹´¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õµè Í ÊÇÔµª ÍÂÙ ¡íÒ˹´ä´ µ§Ñé áµ 0 ¶Ö§ 15 downstate à» ¹¡ÒáíÒ˹´Ê¶Ò¹ÐÅͨԡàÁ×Íè ÊÇÔµª ¶¡Ù ¡´ ¶ ÒËÒ¡µ Íǧ¨Ã¢Í§ÊÇÔµª µÒÁÃÙ»·Õè L52 (¡) µ ͧ¡íÒ˹´ãË ¤Ò downtate ¹Õàé » ¹ 0 㹡óշµÕè Í ÊÇÔµª µÒÁÃÙ»·Õè L5-2 (¢) µ ͧ¡íÒ˹´ãË ¤Ò downtate ¹Õé à» ¹ 1 áµ ·¹Õè ÂÔ ÁáÅТÍá¹Ð¹íÒãË ãª ¤Í× ¡Òõ Íǧ¨ÃÊÇÔµª µÒÁÃÙ»·Õè L5-2 (¡) DELAY 㪠¡Òí ˹´¤ Ò˹ ǧàÇÅÒà¾×Íè á¡ »­ ËÒ¡ÒÃàºÒ« ¢Í§ÊÇÔµª ÊÒÁÒöàÅ×Í¡¤ Òä´ µ§Ñé áµ 0 ¶Ö§ 255 ÁÕ˹ ÇÂà» ¹ÁÔÅÅÔÇ¹Ô Ò·Õ ¶ Ò¡íÒ˹´¤ Ò DELAY à» ¹ 0 ¨ÐäÁ à¡Ô´¡ÒÃá¡ àºÒ« ¢Í§ÊÇÔµª 㹡óշ¡Õè Òí ˹´¤ Ò DELAY ෠ҡѺ 255 ¡ÒÃá¡ àºÒ« ¢Í§ÊÇÔµª ¨Ðà¡Ô´¢Ö¹é Í ҧÊÁºÙ³ äÁ Á¡Õ ÒÃÃѺ¤ ҢͧÊÇÔµª à¾ÔÁè àµÔÁÍÕ¡ 㹡óշ¡Õè ´ ÊÇÔµª ¤Ò § áÅж ÒËÒ¡¡íÒ˹´¤ Ò DELAY ã¹Â Ò¹ 50-200 i-Stamp2p24 ¨ÐÁÕ¡ÒÃàºÒ« ¢Í§ÊÇÔµª ÃÐ´ÑºË¹Ö§è ¾Ã ÍÁ¡Ñ¹ ¹Ñ¹é Âѧ·íÒ¡ÒÃÍ Ò¹¤ ҢͧÊÇÔµª Í ҧµ Íà¹×Íè §´ Ç ËÒ¡ÁÕ¡Òá´ÊÇÔµª ¤Ò § ¤ ҢͧÊÇÔµª ¹¹Ñé Âѧ¤§¶Ù¡Í ҹࢠÒÁÒÍ ҧµ Í à¹×Íè § µÒÁÃͺ¢Í§¡ÒÃÍ Ò¹·Õ¡è Òí ˹´´ ǵÑÇá»Ã rate «Ö§è ¨Ð¤Å Ò¡Ѻ¡ÒäÕ¤ Ò §º¹¤Õº Íà ´¢Í§à¤Ã×Íè §¤ÍÁ¾ÔÇàµÍà rate 㪠¡Òí ˹´¤ ÒàÇÅҢͧÃͺ㹡ÒÃÍ Ò¹¤ ÒÊÇÔµª «Òéí 㹡óշàÕè ¡Ô´¡Òá´ÊÇÔµª ¤Ò § ÊÒÁÒöàÅ×Í¡ ä´ µ§Ñé áµ 0-255 ÁÕ˹ ÇÂà» ¹ÁÔÅÅÔÇ¹Ô Ò·Õ »¡µÔ¤Ò rate ¨Ð¡íÒ˹´äÇ äÁ ʧ٠ÁÒ¡¹Ñ¡ ·Ñ§é ¹Õàé ¾×Íè ãË ÊÒÁÒÃ¶Í Ò¹¤ Ңͧ¡Òô ÊÇÔµª ¤Ò §ä´ ·¹Ñ áµ ¶Ò ËÒ¡¡íÒ˹´äÇ µÒèí ÁÒ¡à¡Ô¹ä» ã¹¢³Ð·Õ¡è ÒÃ˹ ǧàÇÅÒà¾×Íè á¡ ¡ÒÃàºÒ« äÁ àËÁÒÐÊÁ ¤ ҢͧÊÇÔµª ·ÕÍè Ò ¹ä´ ¡¨ç ÐäÁ á¹ ¹Í¹ 㹡óշ¤Õè Ò DELAY ¡íÒ˹´à· ҡѺ 255 áÊ´§Ç Ò¼Ùã ª §Ò¹äÁ µÍ §¡ÒÃãË à¡Ô´¡ÒÃÍ Ò¹¤ ÒÊÇÔµª «Òéí ´Ñ§¹Ñ¹é ¤ Ò rate ¨Ö§¤ÇáíÒ˹´ãË à» ¹ 0 +5V

+5V

S1

10k P8

P8

i-Stamp2P24

i-Stamp2P24 10k

S1

(¡)

(¢)

ÃÙ»·Õè L5-2 ǧ¨Ã¢Í§¡Òõ ÍÊÇÔµª ࢠҷբè Ò¾Íà µ¢Í§ i-Stamp2P24 à¾×Íè 㪠㹡ÒáíÒ˹´¤ Ò downstate ¢Í§¤íÒÊѧè BUTTON

"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


bytevariable ¡íÒ˹´¾×¹é ·ÕËè ¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÊíÒËÃѺ¡ÃзíÒ¤íÒÊÑ§è ¹Õé »¡µÔà» ¹ B0 ËÃ×Í B1 targetstate ¡íÒ˹´ÊÀÒÇТͧÊÇÔµª ¶ Òà» ¹ 0 ËÁÒ¶֧ ãË ¡ÃÐâ´´ä»·íÒ§Ò¹ÂѧáÍ´à´ÃÊ·Õ¡è Òí ˹´ã¹ address ËÒ¡äÁ Á¡Õ Òá´ÊÇÔµª 㹡óշàÕè » ¹ 1 ËÁÒ¶֧ ãË ¡ÃÐâ´´ä»·íÒ§Ò¹ÂѧáÍ´à´ÃÊ·Õ¡è Òí ˹´ã¹ address ËÒ¡ÁÕ¡Òá´ÊÇÔµª address ¡íÒ˹´µíÒá˹ §ãË i-Stamp2P24 ¡ÃÐâ´´ä»·íÒ§Ò¹ àÁ×Íè à§×Íè ¹ä¢¢Í§ targetstate à» ¹¨ÃÔ§

µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè BUTTON BUTTON 8,0,0,0,B0,0,NO_PRESS

ËÁÒ¤ÇÒÁÇ Ò ·íÒ¡ÒÃÍ Ò¹¤ ÒÊÇÔµª ·µÕè Í ÍÂÙ¡ ºÑ ¢Ò P8 ËÒ¡ÊÇÔµª ¶¡Ù ¡´¨Ðä´ ¤Ò Åͨԡ 0 ·Õ¢è Ò P8 ¹Õé äÁ ÁÕ ¡ÒÃá¡ àºÒ« ¢Í§ÊÇÔµª äÁ Á¡Õ ÒÃÍ Ò¹¤ ÒÊÇÔµª «Òéí 㪠B0 㹡ÒáÃзíÒ¤íÒÊÑ§è ¹Õé áÅÐËÒ¡äÁ Á¡Õ Òá´ÊÇÔµª ¨Ð¡ÃÐâ´´ä» ·íÒ§Ò¹·ÕÅè ÒàºÅ NO_PRESS BUTTON 8,0,200,60,B1,1,PRESS

ÊíÒËÃѺµÑÇÍ ҧ¹Õé ¨Ð¡íÒ˹´ãË i-Stamp2P24 Í Ò¹¤ ҢͧÊÇÔµª ·µÕè Í ÍÂÙ¡ ºÑ ¢Ò P8 àÁ×Íè ÊÇÔµª ¶¡Ù ¡´¨Ðä´ ¤ Òà» ¹Åͨԡ 0 ÁÕ¡ÒÃá¡ àºÒ« ´Ç ¡ÒÃ˹ ǧàÇÅÒ 200 ÁÔÅÅÔÇ¹Ô Ò·Õ ÁÕ¡ÒÃÍ Ò¹¤ ÒÊÇÔµª «Òéí â´Â¡íÒ˹´¤ ÒàÇÅÒ㹡ÒÃ Í Ò¹¤ ÒÊÇÔµª «Òéí ã¹áµ ÅÐÃͺ෠ҡѺ 60 ÁÔÅÅÔÇ¹Ô Ò·Õ ãª B1 㹡Ò÷íÒ§Ò¹ áÅÐàÁ×Íè ÁÕ¡Òá´ÊÇÔµª ¨Ð¡ÃÐâ´´ä»·íÒ§Ò¹Âѧ ÅÒàºÅ PRESS

¡Ò÷´Åͧ 5.1 㪠ǧ¨Ãã¹ÃÙ»·Õè L5-1 㹡Ò÷´Åͧ â´Âµ Íǧ¨Ãŧº¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ P7 +5V P6 P5

10k P8

P4 i-Stamp2P24

P3

S1 P2 P1 P0

510

LED8

510

LED7

510

LED6

510

LED5

510

LED4

510

LED3

510

LED2

510

LED1

% $ # " !

ÃÙ»·Õè L5-3 ǧ¨Ã·´Åͧ¡ÒÃàÅ×Í¡ÊÑ­­Ò³â´Â㪠¤Òí Êѧè BUTTON à» ¹¤íÒÊѧè ËÅÑ¡

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#


5.2 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB0501.BSP '****************************************************************************************************** ' Program : LAB0501.BSP ' Description : OUTPUT Selector ' Hardware : Connect 8 OUTPUT LEDs TO P0-P7 AND connect active LOW INPUT switch TO P8 '****************************************************************************************************** ' {$STAMP BS2P} ' {$PBASIC 2.5} SW_VAR VAR Byte ' Define Byte variable TO use with BUTTON DIRL=$FF ' Define P0-P7 as outputs RELOAD: OUTL=128 ' Define first state OUTPUT (%10000000) LOOP1: BUTTON 8,0,255,0,SW_VAR,1,SHIFT_OP ' Receive INPUT from BUTTON GOTO LOOP1 ' Goto loop SHIFT_OP: IF OUTL=1 THEN RELOAD ' Check last OUTPUT already? reload IF last. (%00000001) OUTL=OUTL/2 ' Shift TO NEXT OUTPUT GOTO LOOP1 ' Goto loop

5.3 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 5.4 ·íÒ¡Òá´ÊÇÔµª áŠǻŠÍÂÊѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED àÁ×Íè àÃÔÁè ·íÒ§Ò¹ LED µíÒá˹ § 7 ¨ÐµÔ´ àÁ×Íè àÃÔÁè ¡´ÊÇÔµª LED ¨ÐµÔ´àÅ×Íè ¹µíÒá˹ §¨Ò¡ 7 ä» 6 ¨¹¶Ö§ 0 áÅ Çǹ¡ÅѺÁÒ·Õè 7 ÍÕ¡¤ÃÑ§é µÒÁ¡Òá´ÊÇÔµª

i-Stamp2p24

$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ·Õè 6 ¡íÒà¹Ô´ÊÑ­­Ò³àÊÕ§⹠µ´¹µÃÕ à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. ÅíÒ⾧ 1 µÑÇ ¤ÇÒÁÊÒÁÒöÍÕ¡»ÃСÒÃË¹Ö§è ·Õè i-Stamp2P24 ÁÕà˹×ÍäÁâ¤Ã¤Í¹â·ÃÅÅàÍà µÇÑ Í×¹è æ ¤×Í ÊÒÁÒö¡íÒà¹Ô´ ÊÑ­³Ò³ä«¹ ä´ â´Â㪠à¾Õ§ 1 ¤íÒÊÑ§è ¾Ã ÍÁ¡Ñ¹¹Ñ¹é ÂѧÊÒÁÒö¼ÊÁÊÑ­­Ò³ à¾×Íè ãË à¡Ô´ÊÑ­­Ò³ä«¹ ËÅÒ¤ÇÒÁ¶Õè ·íÒãË Ê­ Ñ ­Ò³àÊÕ§·Õäè ´ Á¤Õ ÇÒÁËÅÒ¡ËÅÒ áÅйíÒä»ãª §Ò¹Í ҧ¡Ç Ò§¢ÇÒ§ ¤íÒÊÑ觷ÕèÁÕº·ºÒ·ÊíҤѭ´Ñ§¡Å ÒǤ×Í FREQOUT ¤íÒÊÑ觹Õé㪠ÊíÒËÃѺ¡íÒà¹Ô´ÊÑ­­Ò³ä«¹ ˹Öè§ËÃ×Í ÊͧÊÑ­­Ò³ã¹ª ǧÃÐÂÐàÇÅÒ·Õ¡è Òí ˹´ µÑÇÍ ҧ¡ÒÃ㪠¤Òí Êѧè FREQOUT ÁÕ´§Ñ ¹Õé FREQOUT 0,1000,663

¤íÒÊÑ§è ¹Õ¨é СíÒà¹Ô´ÊÑ­­Ò³ä«¹ ¤ÇÒÁ¶Õè 2,500 Hz ´ Ǫ ǧàÇÅÒ 265 ÁÔÅÅÔÇ¹Ô Ò·Õ ¼ Ò¹·Ò§¢Ò P0

â¹ µ´¹µÃÕ

ª×Íè â¹ µ´¹µÃÕ

C

â´

C#/Db D

àÃ

D#/Eb E F

ÁÕ ¿Ò

F#/Gb G

«ÍÅ

G#/Ab A

ÅÒ

A#/Bb B C1

·Õ â´ÊÙ§

¤ÇÒÁ¶Õè (Hz) Í͡ൻ·Õè 1 Í͡ൻ·Õè 2 Í͡ൻ·Õè 3 Í͡ൻ·Õè 4 Í͡ൻ·Õè 5 Í͡ൻ·Õè 6 65.41 130.82 261.63 523.26 1046.52 2093.04 69.30 138.60 277.19 554.38 1108.76 2217.52 73.42 146.84 293.67 587.34 1174.68 2349.36 77.78 82.41 87.31 92.5 98 103.83 110 116.54 123.47 130.82

155.57 164.82 174.62 185 196 207.66 220 233.09 246.95 261.63

311.13 329.63 349.23 370 392 415.31 440 466.17 493.89 523.26

622.26 659.26 698.46 740 784 830.62 880 932.34 987.78 1046.52

1244.52 1318.52 1396.92 1480 1568 1661.24 1760 1864.68 1975.56 2093.04

2489.04 2637.04 2793.84 2960 3136 3322.48 3520 3729.36 3951.12 4186.08

µÒÃÒ§·Õè L6-1 µÒÃÒ§¤ÇÒÁ¶Õ¢è ͧ⹠µ´¹µÃÕ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%


¶ Òµ ͧ¡ÒÃãË Êà ҧ¤ÇÒÁ¶Õè 2 ¤ÇÒÁ¶ÕÊè ÒÁÒöà¢Õ¹â»Ãá¡ÃÁä´ ´§Ñ ¹Õé FREQOUT 0,1000,663,1000

¤ÇÒÁ¶ÕèÊͧ¤ÇÒÁ¶Õè¤×Í 2,500 áÅÐ 3,770 Hz ¨Ð¼ÊÁࢠҴ Ç¡ѹáÅÐãË àÊÕ§àËÁ×͹¡ÑºàÊÕ§´¹µÃÕ ËÃ×ÍàÊÕ§¡Ãдԧè ÊíÒËÃѺ¡ÒÃËÂØ´¡íÒà¹Ô´àÊÕ§·íÒä´ â´Â¡íÒ˹´ãË ¤Ò ¤ÇÒÁ¶Õàè · ҡѺ 0

¤ÇÒÁ¶Õ¢è ͧ⹠µ´¹µÃÕ à¹×Íè §¨Ò¡ i-Stamp2P24 ÊÒÁÒö¡íÒà¹Ô´ÊÑ­­Ò³ä«¹ ä´ ¨Ö§ÊÒÁÒö¹íÒ»ÃÐ⪹ ¹äÕé »ãª ã¹¡ÒáíÒà¹Ô´ ÊÑ­­Ò³¤ÇÒÁ¶Õèâ¹ µ´¹µÃÕä´ äÁ ÂÒ¡ áµ ¡ ͹Í×蹨е ͧ·ÃÒº¶Ö§¤ Ò¤ÇÒÁ¶Õè¢Í§µÑÇâ¹ µ´¹µÃÕ¾×鹰ҹᵠÅеÑÇ àÊÕ¡ ͹ â´ÂµÑÇâ¹ µËÅÑ¡·Õàè » ¹¾×¹é °Ò¹ÁÕ 8 µÑǤ×Í â´, àÃ, ÁÕ, ¿Ò, «ÍÅ, ÅÒ, ·Õ áÅÐâ´ÊÙ§ «Ö§è áµ ÅеÑǨÐÁÕ¤Ò ¤ÇÒÁ ¶Õàè ©¾ÒÐ ´Ñ§áÊ´§ã¹µÒÃÒ§·Õè L6-1

¡Ò÷´Åͧ 6.1 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB0701.BSP '********************************************************** ' Program : LAB0601.BSP ' Description : Make melody sounds ON speaker ' Hardware : Connect Speaker TO P0 '********************************************************** ' {$STAMP BS2P} ' {$PBASIC 2.5} FREQ VAR Word ' Define Byte variable TO keep frequency I VAR Byte ' Define Byte variable TO keep LOOP counter C CON 278 ' Note C Frequency D CON 312 ' Note D Frequency E CON 350 ' Note E Frequency F CON 370 ' Note F Frequency G CON 416 ' Note G Frequency A CON 467 ' Note A Frequency B CON 524 ' Note B Frequency C1 CON 555 ' Note C1 Frequency OUTPUT 0 LOOP1: FOR I=0 TO 7 LOOKUP I,[C,D,E,F,G,A,B,C1],FREQ ' READ table 8 notes FREQOUT 0,1887,FREQ ' Make melody with duration 0.5 sec PAUSE 100 ' Delay 100 ms. NEXT PAUSE 1000 GOTO LOOP1 ' Goto loop

&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


i-Stamp2P24

P0 + -

SP1 PIEZO

ÃÙ»·Õè L6-1 ǧ¨ÃÊíÒËÃѺ·´Åͧ¡ÒáíÒà¹Ô´ÊÑ­­Ò³àÊÕ§¢Í§ i-Stamp2P24 ¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ àÃÔÁè µ ¹´ Ç¡ÒÃÊà ҧ¢ ÍÁÙŢͧ⹠µ´¹µÃÕ ¨Ò¡µÒÃÒ§¤ÇÒÁ¶Õ¢è ͧ⹠µ´¹µÃÕ (µÒÃÒ§·Õè L6-1) ¹íÒÁÒ¤íҹdz໠¹ ¤ Ò¢ ÍÁÙŤÇÒÁ¶ÕÊè Òí ËÃѺ¤íÒÊѧè FREQOUT à¹×Íè §¨Ò¡¤íÒÊѧè FREQOUT ¢Í§ i-Stamp2P24 ¹Ñ¹é ¤ Ò¤ÇÒÁ¶ÕÁè ËÕ ¹ Ç ໠¹ 2.5Hz ¨Ö§µ ͧ¹íÒ¤ Ò¤ÇÒÁ¶Õ¢è ͧµÑÇâ¹ µ´¹µÃÕ·ÁÕè ËÕ ¹ ÇÂà» ¹ Hz ÁÒËÒô Ç 2.5 ¨Ö§¨Ðä´ ¤Ò ¢ ÍÁÙÅ·Õàè ËÁÒÐÊÁ ã¹â»Ãá¡ÃÁàÅ×Í¡¤ÇÒÁ¶Õâè ¹ µ´¹µÃÕã¹Í͡ൻ·Õè 5 ·Õàè ÊÕ§ⴠËÃ×͵ÑÇâ¹ µ C ÁÕ¤ÇÒÁ¶Õè 1046.52 Hz ¹íÒÁÒËÒô Ç 2.5 ¨Ðä´ ¤Ò ෠ҡѺ 418.61 áµ à¹×Íè §¨Ò¡ i-Stamp2P24 äÁ ÊÒÁÒö»ÃÐÁÇŨíҹǹ·È¹ÔÂÁä´ ¨Ö§µ ͧ» ´ãË à» ¹µÑÇ àÅ¢¨íҹǹàµçÁ ¨Ö§ä´ ¤Ò ෠ҡѺ 419 Ê Ç¹µÑÇâ¹ µÍ×¹è æ ¡çãª Ç¸Ô ¡Õ ÒäíҹdzàËÁ×͹¡Ñ¹ µÒÁâ»Ãá¡ÃÁ¨Ð¡íÒ˹´ãË ¡Òí à¹Ô´ àÊÕ§⹠µ´¹µÃÕáµ ÅеÑǹҹ 0.5 ÇÔ¹Ò·Õ 6.2 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹µÑÇ i-Stamp2P24 â´Â¡Òá´»ØÁ RUN 6.3 »Å´ä¿àÅÕÂé §ºÍà ´·´ÅͧÍÍ¡ áŠǵ Íǧ¨ÃµÒÁÃÙ»·Õè L6-1 6.4 ¨ ÒÂä¿àÅÕÂé § ¿ §àÊÕ§·Õàè ¡Ô´¢Ö¹é àÁ×Íè Ãѹâ»Ãá¡ÃÁ ¨Ðä´ Â¹Ô àÊÕ§µÑÇâ¹ µ´¹µÃÕ´§Ñ ¢Ö¹é àÃÕ§ÅíҴѺ¨Ò¡ ¤×Í â´, àÃ, ÁÕ, ¿Ò, «ÍÅ, ÅÒ, ·Õ áÅÐâ´ ÊÙ§ áÅ Çǹ¡ÅѺÁÒÂѧ â´, àÃ, ÁÕ ãËÁ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'


!

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


º··Õè 6

¡ÒÃ㪠§Ò¹Ë¹ ǤÇÒÁ¨íÒÍÕÍÕ¾ÃÍÁ ÀÒÂã¹ i-Stamp2p24 i-Stamp2P24 ÁÕ˹ ǤÇÒÁ¨íÒÁÕ¢¹Ò´ 16 ¡ÔâÅ亵 à» ¹Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ·ÕÊè ÒÁÒöźáÅÐà¢Õ¹ ãËÁ ä´ ¶§Ö 100,000 Ãͺ ºÃèؤÒí Êѧè ÀÒÉÒ¾ÕàºÊÔ¡ä´ ÁÒ¡¶Ö§ 4,000 ¤íÒÊѧè Ê Ç¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÁÕ´Ç Â¡Ñ¹ 2 Ê Ç¹¤×Í Ë¹ ǤÇÒÁ¨íÒáÃÁ«Ö觺ÃèØÍÂÙ ã¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà SX48BD «Öè§à» ¹àºÊÔ¡ÍÔ¹àµÍà ¾ÃÕµàµÍà â´Â˹ ǤÇÒÁ¨íÒã¹Ê ǹ¹Õ¨é ÐàÃÕÂ¡Ç Ò ÃÕ¨ÊÔ àµÍà (register) ÁÕ¢¹Ò´ 32 亵 ËÃ×Í 16 àÇÔô (1 àÇÔô ෠ҡѺ 16 ºÔµ ËÃ×Í 2 亵 ) ˹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÍÕ¡Ê Ç¹Ë¹Ö§è ¤×Í Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ «Ö§è 㪠¾¹×é ·ÕÃè Ç Á¡ÑºË¹ ǤÇÒÁ¨íÒ â»Ãá¡ÃÁ â´Â㹡ÒÃáÂ¡Ê Ç¹¹Ñ¹é ¨Ðãª Ç¸Ô ¡Õ ÒÃࢠҶ֧㹷ÔÈ·Ò§·ÕÊè ǹ¡Ñ¹ ¡Å ÒǤ×Í ¢ ÍÁÙŢͧâ»Ãá¡ÃÁ¨Ð¶Ù¡à¡çº ŧµÑ§é áµ áÍ´à´ÃÊ $7FF Å´¶ÍÂŧÁÒàÃ×Íè Âæ ã¹¢³Ð·Õ¢è Í ÁÙŢͧ˹ ǤÇÒÁ¨íÒ¢ ÍÁÙŨÐàÃÔÁè à¡çº¨Ò¡áÍ´à´ÃÊ $000 ã¹ÃÙ»·Õè 6-1 áÊ´§¡ÒèѴÊÃÃ¾×¹é ·Õ¢è ͧ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ 1 ྨÀÒÂã¹ i-Stamp2P24

6.1 ¡ÒôÙÃÒÂÅÐàÍÕ´¢Í§Ë¹ ǤÇÒÁ¨íҷѧé ËÁ´ÀÒÂã¹ i-Stamp2P24 àÃÔÁè µ ¹´ Ç¡ÒÃàª×Íè Áµ Í i-Stamp2P24 ¡Ñº¤ÍÁ¾ÔÇàµÍà ¼Ò ¹·Ò§¾Íà µÍ¹Ø¡ÃÁ ¨Ò¡¹Ñ¹é àÃÕ¡â»Ãá¡ÃÁ ¹ÒÁÊ¡ØÅ .BSP ¢Ö¹é ÁÒ µÒÁ´ Ç´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 ¨Ò¡¹Ñ¹é ¡´»ØÁ Memory map ËÃ×Í àÅ×Í¡àÁ¹Ù RUN ä»·Õè Memory Map ËÃ×Í¡´¤Õ Ctrl + M ¨Ð»ÃÒ¡¯Ë¹ Òµ Ò§¢Í§¡ÒèѴÊÃÃ˹ ǤÇÒÁ¨íÒÀÒ 㹠i-Stamp2P24 »ÃÒ¡¯¢Ö¹é ÁÒµÒÁÃÙ»·Õè 6-1 ã¹ÃÙ»·Õè 6-1 (¡) áÊ´§¢ ÍÁÙÅ·Õºè ÃèØÍÂÙ㠹˹ ǤÇÒÁ¨íҢͧ i-Stamp2P24 ¨ÐàËç¹ä´ ÇÒ ¢ ÍÁÙŢͧ â»Ãá¡ÃÁ¨Ðä´ ÃºÑ ¡ÒÃà¢Õ¹ŧã¹áÍ´à´ÃʨҡµíÒá˹ §ÊØ´· Ò¤×Í $7FF  ͹¢Ö¹é ÁÒ â´ÂáÊ´§´ ÇÂ¾×¹é ·ÕÊè áÕ ´§ Ê Ç¹ºÃÔàdzÊÕà·Ò¤×Í¾×¹é ·Õ·è ÂÕè §Ñ äÁ Á¡Õ ÒÃ㪠§Ò¹ ã¹¾×¹é ·ÕÊè ¿Õ Ò à¢ Áã¹Ê ǹ¢Í§Ë¹ ǤÇÒÁ¨íÒáÃÁáÊ´§¶Ö§¾×¹é ·Õ¢è ͧÃÕ ¨ÔÊàµÍà ·ÁÕè ¡Õ ÒÃ㪠§Ò¹áÅ Ç â´Â㹺Åç͡ ͧ͢˹ ǤÇÒÁ¨íÒ¨ÐÁÕ¢¹Ò´ 1 àÇÔô ËÃ×Í 2 亵 ËÃ×Í 16 ºÔµ ã¹ÃÙ»·Õè 6-1 (¢) áÊ´§ãË àË繶֧¾×é¹·Õè¢Í§Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅ·Õèä´ ÃѺ¡ÒèѴÊÃÃã¹¾×é¹·Õè¢Í§Ë¹ Ç ¤ÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ â´Âãª Ê¿Õ Ò Í Í¹áÊ´§¢Íºà¢µ¢Í§Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÊ Ç¹¹Õé Í ҧäáçµÒÁ¡ÒÃ´Ù¢Í ÁÙÅã¹Ë¹ Òµ Ò§ Memory map ¢Í§â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ¨ÐÊÒÁÒö´Ù ä´ à¾Õ§¤ÃÒÇÅÐ 1 ྨ ´Ñ§¹Ñ¹é ËÒ¡ÁÕ¡ÒÃà¢Õ¹â»Ãá¡ÃÁà¡çºäÇ ËÅÒÂྨ 㹡ÒõÃǨÊͺ¨Ö§µ ͧÃкØãË ¶¡Ù µ ͧ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


¾×¹é ·Õ¢è ͧÃÕ¨ÊÔ àµÍà ¤Çº¤ØÁ·Ñ§é 3 µÑÇ

(¡)

¾×é¹·Õè˹ ǤÇÒÁ¨íÒ·ÕèÂѧäÁ ä´ ãª §Ò¹ ¾×é¹·Õè¢Í§Ë¹ ǤÇÒÁ¨íÒâ»Ãá¡ÃÁ ¾×é¹·Õè¢Í§Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅ

¾×é¹·Õè¢Í§Ë¹ ǤÇÒÁ¨íÒáÃÁ ËÃ×ÍÃÕ¨ÊÔ àµÍÃ

(¢)

ÃÙ»·Õè 6-1 áÊ´§Ê ǹ»ÃСͺµ Ò§æ ¢Í§Ë¹ Òµ Ò§áÊ´§¡ÒèѴÊÃÃ˹ ǤÇÒÁ¨íÒÍÕÍÕ¾ÃÍÁ¢Í§ i-Stamp2P24 ËÃ×ÍàºÊÔ¡áʵÁ» 2P ã¹ 1 ྨ !

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


6.2 ÃÕ¨ÊÔ àµÍà ÀÒÂã¹ i-Stamp2P24 ÃÕ¨ÊÔ àµÍà ÀÒÂã¹ i-Stamp2P24 ¡ç¤Í× Ë¹ ǤÇÒÁ¨íÒáÃÁ¹Ñ¹è àͧ â´ÂẠ§ÍÍ¡à» ¹ 2 ¡ÅØÁ ¤×Í ÃÕ¨ÊÔ àµÍà ¤Çº¤ØÁ·ÔÈ·Ò§ÍÔ¹¾ØµàÍÒµ ¾µØ áÅÐÃÕ¨ÊÔ àµÍà 㪠§Ò¹·ÑÇè ä» ÊíÒËÃѺÃÕ¨ÊÔ àµÍà ¤Çº¤ØÁ·ÔÈ·Ò§ÍÔ¹¾ØµàÍÒµ ¾µØ ÁÕ 3 µÑǤ×Í DIR 㪠¡Òí ˹´âËÁ´¡Ò÷íÒ§Ò¹¢Í§¢Ò¾Íà µ¢Í§ i-Stamp2P24 ¶ ÒºÔµã´à» ¹ 0 ËÁÒ¤ÇÒÁÇ Ò ºÔµ¹Ñ¹é à» ¹ ÍÔ¹¾Øµ ã¹¢³Ð·Õ¶è Ò à» ¹ 1 ºÔµ¹Ñ¹é ¨Ðà» ¹àÍÒµ ¾µØ ÃÕ¨ÊÔ àµÍà µÇÑ ¶Ñ´ÁÒ¤×Í IN 㪠à¡çº¢ ÍÁÙÅ·ÕÍè Ò ¹à¢ ÒÁҢͧ¢Ò ¾Íà µ·Õàè » ¹ÍÔ¹¾Øµ áÅÐ ÊØ´· Ò¤×Í OUT 㪠à¡çº¢ ÍÁÙÅ·Õµè Í §¡ÒÃÊ §ÍÍ¡ä»Âѧ¢Ò¾Íà µ¢Í§ i-Stamp2P24 ´Ñ§¹Ñ¹é i-Stamp2P24 ¨Ö§ÁÕÃ¨Õ ÊÔ àµÍà ·ÊÕè ÒÁÒö㪠§Ò¹·ÑÇè ä»ä´ 13 àÇÔô ËÃ×Í 26 亵 â´Â¢ ÍÁÙÅã¹ÃÕ¨ÊÔ àµÍà ÊÒÁÒö¡íÒ˹´ãË ÍÂÙã ¹ÃÙ»¢Í§ºÔµ, ¹ÔºàºÔÅ, 亵 áÅÐàÇÔô ä´ ¹Ñ¹è ËÁÒ¤ÇÒÁÇ Ò ¼Ùã ª §Ò¹ÊÒÁÒö¡íÒ˹´µÑÇá»Ã ÃдѺ亵 ÊÒí ËÃѺà¡çº¢ ÍÁÙÅä´ ¶§Ö 26 µÑǤ×Í b0 ¶Ö§ b25 áÅеÑÇá»ÃÃдѺàÇÔô 13 µÑǤ×Í W0 ¶Ö§ W12 â´ÂàÁ×Íè 㪠§Ò¹ W0 ¨Ðà» ¹¡ÒÃ㪠§Ò¹¾×¹é ·Õ¢è ͧ B0 ¡Ñº B1 â´Â B0 à¡çº¢ ÍÁÙÅã¹ 8 ºÔµº¹ËÃ×Í亵 º¹ Ê Ç¹ B1 à¡çº¢ ÍÁÙÅ ¢Í§ 8 ºÔµÅ Ò§ËÃ×Í亵 ÅÒ § ã¹¢³Ð·Õè W1 ¨Ð㪠B2 áÅÐ B3 à ÇÁ¡Ñ¹ à» ¹µ ¹ ·´Åͧà¢Õ¹â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' Memory map testing demo program ' consists of 2 words, 2 bytes, 4 nibbles and 3 bits ' {$STAMP BS2p} WORD_A BYTE_A NIBBLE_A BYTE_B NIBBLE_B BIT_A NIBBLE_C NIBBLE_D WORD_B BIT_B BIT_C

VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR

WORD BYTE NIB BYTE NIB BIT NIB NIB WORD BIT BIT

WORD_A = $0123 WORD_B = $4567 BYTE_A = $89 BYTE_B = $AB NIBBLE_A = $C NIBBLE_B = $D NIBBLE_C = $E NIBBLE_D = $F BIT_A = 1 BIT_B = 0 BIT_C = 1 Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!!


¨Ò¡¹Ñ¹é ´Òǹ âËŴŧº¹ i-Stamp2P24 â´Â¡ ͹˹ Ò·Õ¨è Ðà¢Õ¹â»Ãá¡ÃÁáÅдÒǹ âËÅ´ µ ͧ» ´áÅÐ à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà ãËÁ à¾×Íè Å Ò§¢ ÍÁÙÅà´ÔÁÀÒÂã¹Ë¹ ǤÇÒÁ¨íÒáÃÁ¢Í§ i-Stamp2P24 àÁ×Íè ´Òǹ âËÅ´àÃÕºà ÍÂáÅ Ç ãË à¡Ô´Ë¹ Òµ Ò§ Memory Map ¢Ö¹é ÁÒ â´Â¡Òá´»ØÁ Memory map ËÃ×Í àÅ×Í¡àÁ¹Ù RUN ä»·Õè Memory Map ËÃ×Í¡´¤Õ Ctrl + M ¨Ð»ÃÒ¡¯Ë¹ Òµ Ò§´Ñ§ÃÙ»·Õè 6-2 ãË ¾¨Ô ÒóҡÒèѴÊÃà ¾×¹é ·Õ¢è ͧ˹ ǤÇÒÁ¨íÒáÃÁ ·Õè REG0 áÅÐ REG1 «Ö§è áÊ´§´ ÇÂ¾×¹é ·ÕÊè ¹Õ Òéí à§Ô¹à¢ Á ËÁÒ¤ÇÒÁÇ Ò ¾×¹é ·Õ¢è ͧ˹ Ç ¤ÇÒÁ¨íÒã¹Ê ǹ¹Õãé ª ÊÒí ËÃѺà¡çº¢ ÍÁÙÅÃдѺàÇÔô «Ö§è ¨Ò¡â»Ãá¡ÃÁµÑÇÍ ҧÁÕ 2 µÑǤ×Í WORD_A áÅÐ WORD_B ¶Ñ´ÁÒ·Õè REG2 áÊ´§´ ÇÂ¾×¹é ·ÕÊè ¿Õ Ò à¢ Á㪠ÊÒí ËÃѺà¡çº¢ ÍÁÙÅã¹ÃдѺ亵 «Ö§è ÁÕ´Ç Â¡Ñ¹ 2 µÑǤ×Í BYTE_A áÅÐ BYTE_B ·Õµè Òí á˹ §¢Í§ REG3 áÊ´§´ ÇÂ¾×¹é ·ÕÊè àÕ ËÅ×ͧᡠ㪠ÊÒí ËÃѺà¡çº¢ ÍÁÙÅÃдѺ¹ÔºàºÔÅ «Ö§è ÁÕ 4 µÑǤ×Í NIBBLE_A, NIBBLE_B, NIBBLE_C áÅÐ NIBBLE_D µíÒá˹ §ÊØ´· Ò¤×Í REG4 áÊ´§´ ÇÂ¾×¹é ·ÕÊè ÁÕ Ç §ãª ÊíÒËÃѺà¡çº¢ ÍÁÙÅÃдѺºÔµ ã¹·Õ¹è ãÕé ª 3 µíÒá˹ §ÊíÒËÃѺà¡çº¢ ÍÁÙŢͧ BIT_A, BIT_B áÅÐ BIT_C ¨Ò¡â»Ãá¡ÃÁµÑÇÍ ҧ¹Õé 㪠ÃÕ¨ÔÊàµÍà ÃдѺàÇÔà ´ä»·Ñé§ÊÔé¹ 4 µÑÇ (REG0-REG3) ¡ÑºÍÕ¡ 3 ºÔµ¢Í§ REG4 ¶ Òµ ͧ¡ÒÃãË áÊ´§¤ Ңͧ¢ ÍÁÙÅã¹ÃÕ¨ÊÔ àµÍà ᵠÅеÑÇ ÊÒÁÒö·íÒä´ â´Â㪠¤Òí Êѧè DEBUG ´Ñ§¹Õé DEBUG IHEX ? W3

ÃÕ¨ÔÊàµÍà ÃдѺàÇÔà ´á·¹´ ÇÂÊÕ¹éíÒà§Ô¹ ÃÕ¨ÔÊàµÍà ÃдѺ亵 á·¹´ ÇÂÊÕ¿ Ò ÃÕ¨ÔÊàµÍà ÃдѺ¹ÔºàºÔÅá·¹´ ÇÂÊÕàËÅ×ͧ ÃÕ¨ÔÊàµÍà ÃдѺºÔµá·¹´ ÇÂÊÕÁ ǧ

ÃÙ»·Õè 6-2 áÊ´§¡ÒÃà¡çº¢ ÍÁÙÅŧã¹Ë¹ ǤÇÒÁ¨íÒáÃÁËÃ×ÍÃÕ¨ÊÔ àµÍà ¢Í§ i-Stamp2P24 !"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


â´ÂãË à¢Õ¹¤íÒÊÑ觹Õéµ Í¨Ò¡ºÃ÷ѴÊØ´· Ò¢ͧâ»Ãá¡ÃÁµÑÇÍ ҧ àÁ×èÍÃѹâ»Ãá¡ÃÁ ¨Ð»ÃÒ¡¯Ë¹ Òµ Ò§ Debug Terminal ¢Ö¹é ¾Ã ÍÁ·Ñ§é áÊ´§¢ ÍÁÙŢͧ W3 «Ö§è ¡ç¤Í× ¢ ÍÁÙÅ·Õàè ¡çºÍÂÙã ¹ REG3 ¢Í§Ë¹ ǤÇÒÁ¨íÒáÃÁ ¹Ñ¹è àͧ â´Â¢ ÍÁÙÅ·Õáè Ê´§¤×Í W3 = $FEDC 㹡óշµÕè Í §¡ÒÃᡠ䢢 ÍÁÙÅÀÒÂã¹Ë¹ ǤÇÒÁ¨íÒáÃÁ ÊÒÁÒö¡ÃзíÒä´ ´Ñ§â»Ãá¡ÃÁµÑÇÍ ҧµ Í仹Õé ' Memory Map testing demo program II ' {$STAMP BS2p} WORD_A VAR WORD BYTE_A VAR BYTE NIBBLE_A VAR NIB BYTE_B VAR BYTE NIBBLE_B VAR NIB BIT_A VAR BIT NIBBLE_C VAR NIB NIBBLE_D VAR NIB WORD_B VAR WORD BIT_B VAR BIT BIT_C VAR BIT '****** Defind value to variable ****** WORD_A = $0123 WORD_B = $4567 BYTE_A = $89 BYTE_B = $AB NIBBLE_A = $C NIBBLE_B = $D NIBBLE_C = $E NIBBLE_D = $F '***** Display WordA, change it and display again ***** DEBUG IHEX4 ? WORD_A ' Display contents of WordA B0 = $FF ' Directly change the lower byte in WordA DEBUG IHEX4 ? WORD_A ' Display again

àÁ×Íè Ãѹâ»Ãá¡ÃÁ ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é ¾Ã ÍÁ·Ñ§é áÊ´§¤ Ңͧ WORD_A ·Ñ§é ¡ ͹ áÅÐËÅѧ¨Ò¡ÁÕ¡ÒÃà»ÅÕÂè ¹á»Å§¢ ÍÁÙÅãËÁ ´Ñ§¹Õé WORD_A = $0123à» ¹¢ ÍÁÙŢͧ WORD_A à´ÔÁ WORD_A = $01FF à» ¹¢ ÍÁÙŢͧ WORD_A ËÅѧ¨Ò¡·ÕÁè ¡Õ ÒÃá¡ ä¢áÅ Ç ¡ÒÃà·Õºà¤Õ§µíÒá˹ §¢Í§ REGx ã¹Ë¹ Òµ Ò§ Memory Map ¡Ñºª×Íè ¢Í§µÑÇá»Ã Wx ÁÕÅ¡Ñ É³Ð·Õµè ç ¡Ñ¹ ¡Å ÒǤ×Í µíÒá˹ § REG0 ¨Ð㪠à¡çº¢ ÍÁÙŢͧµÑÇá»Ã W0 äŠ仵ÒÁÅíҴѺ¨¹¶Ö§ REG12 㪠à¡çº¢ ÍÁÙŢͧ W12 ¶ ÒËÒ¡à·Õºà¤Õ§¡ÑºµÑÇá»Ãã¹ÃдѺ亵 µíÒá˹ § REG0 ¨Ð㪠à¡çº¢ ÍÁÙŢͧ B0 áÅÐ B1

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!#


6.3 ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁÀÒÂã¹ i-Stamp2P24 à» ¹·Õè·ÃÒºÍÂÙ áÅ ÇÇ Ò ¢ ÍÁÙŢͧâ»Ãá¡ÃÁ·Ñé§ËÁ´¢Í§ i-Stamp2P24 ¨Ð¶Ù¡à¡çºäÇ ã¹Ë¹ ǤÇÒÁ¨íÒ â»Ãá¡ÃÁª¹Ô´ÍÕÍ¾Õ ÃÍÁ «Ö§è à» ¹Ë¹ ǤÇÒÁ¨íÒẺ¹Í¹âÇÅÒä·Å (non-volatile) áÁ ÇÒ äÁ Á¡Õ Òè ÒÂä¿àÅÕÂé § ¢ ÍÁÙÅ ¡ç¨ÐÂѧ¤§ÍÂÙä Á Ê­ Ù ËÒ 㹠i-Stamp2P24 㪠˹ ǤÇÒÁ¨íÒàºÍà 24LC128 ¢¹Ò´ 16 ¡ÔâÅ亵 ÁÕáÍ´à´ÃÊ µÑ§é áµ $0000 ¶Ö§ $3FFF ÊÒÁÒöà¡çºÃÑ¡ÉÒ¢ ÍÁÙÅä´ ¹Ò¹ 10 » ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁÀÒÂã¹ i-Stamp2P24 Ạ§à» ¹ 8 ྨ ྨÅÐ 2¡ÔâÅ亵 ã¹áµ ÅÐà¾¨ä´ ÃºÑ ¡Òà ¨Ñ´ÊÃÃà» ¹ 2 Ê Ç¹ ¤×Í Ê Ç¹Ë¹Ö§è («Ö§è à» ¹Ê ǹãË­ ´Ç Â) 㪠à¡çº¢ ÍÁÙŢͧâ»Ãá¡ÃÁ áÅÐÍÕ¡Ê Ç¹Ë¹Ö§è 㪠à¡çº¢ Í ÁÙÅ·ÑÇè ä» Ê Ç¹ãË­ ¨Ðà» ¹µÒÃÒ§¢ ÍÁÙÅ (data table) ¢ ÍÁÙŷѧé ÊÍ§Ê Ç¹¹Õäé Á Á¡Õ ÒÃẠ§á¡´ Ç¢ͺࢵËÃ×Í¢¹Ò´ áµ Í ҧ㴠à¾ÕÂ§áµ ãª Ç¸Ô ¡Õ ÒáíÒ˹´áÍ´à´ÃÊ㹡ÒúÃÃ¨Ø¢Í ÁÙÅŧä»ã¹·ÔÈ·Ò§·ÕÊè ǹ¡Ñ¹

6.3.1 ¡ÒÃÍ Ò¹áÅÐà¢Õ¹¢ ÍÁÙÅÀÒÂã¹Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ ¤íÒÊѧè ÊíÒËÃÑºÍ Ò¹ËÃ×ÍàÃÕ¡¢ ÍÁÙÅÍÍ¡¨Ò¡Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ¤×Í ¤íÒÊѧè READ ÁÕû٠Ẻ´Ñ§¹Õé READ Location,Variable

â´Â·Õè Location à» ¹¤ ÒáÍ´à´Ãʢͧ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ·Õµè Í §¡ÒÃÍ Ò¹ Variable à» ¹·Õàè ¡çº¢ ÍÁÙÅ·ÕÍè Ò ¹ä´ ¨Ò¡ÍÕÍ¾Õ ÃÍÁ à» ¹µÑÇá»Ãã¹ÃдѺ亵 â´Â¤íÒÊѧè READ ÊÒÁÒÃ¶Í Ò¹¢ ÍÁÙŨҡ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁä´ ·§Ñé ËÁ´ ·Ø¡µíÒá˹ § äÁ ÇÒ ¨Ðã¹Ê ǹ ¢Í§Ë¹ ǤÇÒÁ¨íÒâ»Ãá¡ÃÁËÃ×Í˹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅ Ê Ç¹¡ÒÃà¢Õ¹¢ ÍÁÙÅŧã¹Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ 㪠¤Òí Êѧè WRITE «Ö§è ÁÕû٠Ẻ´Ñ§¹Õé WRITE Location, Byte

â´Â·Õè Location ¤×ͤ ÒáÍ´à´Ãʢͧ˹ ǤÇÒÁ¨íÒÍÕÍÕ¾ÃÍÁ·Õèµ Í§¡ÒÃà¢Õ¹¢ ÍÁÙÅ Byte ¤×Í ¤ Ңͧ¢ ÍÁÙÅ·Õµè Í §¡ÒÃà¢Õ¹ »ÃÐ⪹ ¢Í§¡ÒÃÍ Ò¹áÅÐà¢Õ¹¢ ÍÁÙÅã¹Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ¤×Í ãª à¡çº¢ ÍÁÙÅ·Õäè ´ ¨Ò¡µÑǵÃǨ¨ÑºËÃ×Í ¨Ò¡¡Ãкǹ¡ÒÃá»Å§ÊÑ­­Ò³ÍйÒÅÍ¡à» ¹´Ô¨µÔ ÍÅ àÁ×Íè µÑǵÃǨ¨ÑºÊ §¢ ÍÁÙÅ´Ô¨µÔ ÍÅ·Õäè ´ ¨Ò¡¡Ò÷íÒ§Ò¹ãË ·Òí ¡ÒÃà¢Õ¹¢ ÍÁÙÅ·Õèä´ ¹Ñé¹à¡çºÅ§ã¹Ë¹ ǤÇÒÁ¨íÒà¾×èÍàµÃÕÂÁäÇ ÊíÒËÃѺ¡ÒûÃÐÁÇŵ Íä» áÁ Ç Ò¨Ðà¡Ô´ä¿¿ ҴѺ ¢ ÍÁÙŨÐÂѧ¤§ÍÂÙ äÁ Ê­ Ù ËÒ «Ö§è ᵡµ Ò§¨Ò¡¡ÒÃà¡çºäÇ Ë¹ ǤÇÒÁ¨íÒáÃÁËÃ×Íã¹ÃÕ¨ÊÔ àµÍà «Ö§è ËÒ¡äÁ ÁäÕ ¿àÅÕÂé § ¢ ÍÁÙŨÐÊÙ­ËÒÂä» áÅÐàÁ×Íè µ ͧ¡ÒùíÒ¤ Ò·Õäè ´ ¨Ò¡µÑǵÃǨ¨ÑºÍÍ¡ÁÒ㪠§Ò¹ ãË ãª ¤Òí Êѧè READ Í Ò¹¢ ÍÁÙÅÍÍ¡ÁÒ â´Â·Õ¢è Í ÁÙŹաé Âç §Ñ ¤§ÍÂÙ ¨¹¡Ç Ò¨Ðà¡Ô´¡ÒÃà¢Õ¹¢ ÍÁÙÅãËÁ ŧä»ã¹áÍ´à´ÃÊà´ÔÁ

!$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ·Õè 7 ¡ÒÃÍ Ò¹áÅÐà¢Õ¹¢ ÍÁÙÅã¹Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³

1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍÃ

¡Ò÷´Åͧ 7.1 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB0701.BSP '*************************************************************** ' Program : LAB0701.BSP ' Description : Show how to write to and read from BS2P s EEPROM '*************************************************************** ' {$STAMP BS2p} ' {$PBASIC 2.5} READING VAR Byte VAL VAR Byte EE_PTR VAR Word EE_PTR = $0000 READING = 0 FOR EE_PTR = 0 TO $1FF GOSUB GET_DATA WRITE EE_PTR, READING NEXT FOR EE_PTR = 0 TO $1FF READ EE_PTR, VAL DEBUG HEX2 VAL, " " IF ((EE_PTR = 0) | ((EE_PTR +1) // 8 <> 0)) THEN SKIP_CR DEBUG CR SKIP_CR: NEXT DONE: GOTO DONE GET_DATA: READING = READING + 5 RETURN

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!%


7.2 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é áÅ ÇÊÑ¡¤ÃÙË ¹Ö§è ¨ÐáÊ´§¢ ÍÁÙÅ·Õ·è Òí ¡ÒÃÊà ҧ¢Ö¹é ¨Ò¡â»Ãá¡ÃÁ  Í GET_DATA «Ö§è ¡ç¤Í× ¡ÅØÁ ¢Í§¢ ÍÁÙÅ·Õàè ¾ÔÁè ¤ Ò¢Ö¹é ¤ÃÒÇÅÐ 5 â´Â¨ÐáÊ´§¨¹¤Ãº 512 ¤ Ò â´Â¡Òäíҹdz ¤ Òà¾×Íè Êà ҧ¢ ÍÁÙŨÐà» ¹¡ÒäíҹdzẺäÁ ¤´Ô à¤Ã×Íè §ËÁÒ áÅÐ㪠¼ÅÅѾ¸ à¾Õ§ 8 ºÔµÅ ҧ෠ҹѹé

!&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


º··Õè 7

¡ÒÃ㪠§Ò¹ i-Stamp2P24 ¢Ñº LED µÑÇàÅ¢ 7 Ê Ç¹ LED µÑÇàÅ¢ 7 Ê Ç¹»ÃСͺ¢Ö¹é ¨Ò¡ LED ¨íҹǹ 7 µÑÇ·Õºè ÃèØÍÂÙã ¹µÑǶѧà´ÕÂǡѹáÅШѴàÃÕ§໠¹ÃÙ» µÑÇàÅ¢ LED áµ ÅеÑÇàÃÕÂ¡Ç Ò Ê Ç¹ ËÃ×Í à«¡àÁ¹µ (segment) áµ ÅÐà«¡àÁ¹µ ÁªÕ Í×è àÃÕ¡ᵡµ Ò§¡Ñ¹µÒÁµíÒá˹ § ·Õäè ´ ÃºÑ ¡ÒèѴÇÒ§¤×Í a, b, c, d, e, f áÅÐ g ´Ñ§áÊ´§ã¹ÃÙ»·Õè 7-1 Ê Ç¹ dp à» ¹ LED ÍÕ¡ 1 µÑÇ·Õºè ÃèØÍÂÙã ¹ LED µÑÇàÅ¢ 7 Ê Ç¹¹Õãé ª à» ¹µÑÇáÊ´§¨Ø´·È¹ÔÂÁ㹡óշÁÕè ¡Õ ÒÃáÊ´§¼Åã¹ÅѡɳÐàÅ¢·ÕÁè ·Õ È¹ÔÂÁ LED ·Ø¡µÑÇ·Õºè ÃèØÍÂÙã ¹ LED µÑÇàÅ¢¹ÕÁé ¢Õ Òµ Íà ÇÁ¡Ñ¹ «Ö§è ¡çÁ·Õ §Ñé Ẻµ Í¢Òá¤â·´Ã ÇÁ¡Ñ¹àÃÕÂ¡Ç Ò áºº á¤â·´Ã ÇÁ (common cathode) áÅÐẺµ Í¢ÒáÍâ¹´Ã ÇÁ¡Ñ¹àÃÕÂ¡Ç Ò áººáÍâ¹´Ã ÇÁ (common anode) ¡ÒâѺ ãË LED µÑÇàÅ¢ 7 Ê Ç¹áººá¤â·´Ã ÇÁÊÇ Ò§¨Ðµ ͧ¨ ÒÂä¿Åºà¢ Ò·Õ¢è Òà ÇÁ áŠǨ ÒÂ俺ǡࢠҷբè ÒáÍâ¹´ «Ö§è ¡ç ¤×͢ҢͧᵠÅÐà«¡àÁ¹µ ¹¹Ñè àͧ ´Ñ§áÊ´§ã¹ÃÙ»·Õè 7-2(¡) ã¹¢³Ð·Õè LED µÑÇàÅ¢ 7 Ê Ç¹áººáÍâ¹´Ã ÇÁ¨Ðµ ͧ ¨ ÒÂ俺ǡࢠҷբè Òà ÇÁ áŠǨ ÒÂä¿Åºà¢ Ò·Õ¢è Òá¤â·´ «Ö§è à» ¹¢Ò¢Í§áµ ÅÐà«¡àÁ¹µ ´Ñ§áÊ´§ã¹ÃÙ»·Õè 7-2(¢) LED µÑÇàÅ¢ 7 Ê Ç¹ÁÕ¨íÒ˹ Ò·Ñé§áººµÑÇà´ÕèÂÇ, µÑǤ٠áÅÐẺ·ÕèÁÕÁÒ¡¡Ç Ò 2 ËÅÑ¡ áµ ·Õè¹ÔÂÁ㪠§Ò¹ áÅÐËÒä´ §Ò ÂÁÕ 2 Ẻ¤×Í áººµÑÇà´ÕÂè ÇáÅÐẺµÑǤ٠â´ÂÁÕ¡ÒèѴ¢Ò´Ñ§ã¹ÃÙ»·Õè 8-3 ¨ÐàËç¹ä´ ÇÒ LED µÑÇàÅ¢ 7 Ê Ç¹áººµÑÇà´ÕÂè ÇÁÕ¢Òµ Í㪠§Ò¹ 10 ¢Ò¤×Í ¢Ò a, b, c, d, e, f, g, dp áÅТÒà ÇÁ (common) «Ö§è ÁÕ 2 ¢Ò ¶ Òà» ¹ LED µÑÇàÅ¢ 7 Ê Ç¹áººµÑǤÙÁ ¢Õ Òµ Í㪠§Ò¹ 20 ¢Ò Ạ§à» ¹¢Ò a, b, c, d, e, f, g áÅÐ dp Í ҧÅÐ 2 ¢ÒÃÇÁ 16 ¢Ò áÅТÒà ÇÁÍÕ¡ËÅÑ¡ÅÐ 2 ¢Ò ¡Òõ Í¢Òà ÇÁ¢Í§áµ ÅÐËÅÑ¡·Ñ§é 2 ¢Ò¹Ñ¹é ÊÒÁÒöµ Í㪠§Ò¹à¾Õ§¢Òà´ÕÂÇä´ à¹×Íè §¨Ò¡ã¹â¤Ã§Êà ҧÀÒÂ㹢ͧ LED µÑÇàÅ¢ 7 Ê Ç¹ ¢Òà ÇÁ¹Õµé Í ¶Ö§¡Ñ¹ÍÂÙá Å Ç

C

=

B

> ?

A

@F @

a b

a b

c d e

c d e

f g dp

f g dp

common (¡) á¤â·´Ã ÇÁ

common (¢) áÍâ¹´Ã ÇÁ

ÃÙ»·Õè 7-1 Ãٻà ҧáÅСÒáíÒ˹´ª×èÍà«¡àÁ¹µ ÃÙ»·Õè 7-2 ǧ¨ÃÀÒÂ㹢ͧ LED µÑÇàÅ¢ 7 Ê Ç¹ µ Ò§æ ¢Í§ LED µÑÇàÅ¢ 7 Ê Ç¹ ·Ñ§é Ẻá¤â·´Ã ÇÁáÅÐáÍâ¹´Ã ÇÁ Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!'


g f com a b

f2 g2 com2 a2 b2 f1 g1 com1 a1 b1

e d com c dp

e2 d2 com2 c2 dp2 e1 d1 com1 c1 dp1

ÃÙ»·Õè 7-3 áÊ´§¡ÒèѴ¢Ò¢Í§ LED µÑÇàÅ¢ 7 Ê Ç¹·Ñ§é ẺµÑÇà´ÕÂè ÇáÅеÑǤÙ

7.1 ¡ÒâѺ LED µÑÇàÅ¢ 7 Ê Ç¹áººËÅÑ¡à´ÕÂè Ç i-Stamp2P24 ÊÒÁÒö¢Ñº LED 7 Ê Ç¹â´ÂµÃ§ à¹×Íè §¨Ò¡¤ÇÒÁÊÒÁÒö㹡Òè Ò¡ÃÐáÊàÍÒµ ¾µØ ÊÙ§à¾Õ§ ¾Í äÁ ¨Òí à» ¹µ ͧÍÒÈÑÂäÍ«Õº¿Ñ à¿Íà ÁÒª ÇÂ㹡ÒâѺ LED áÅзÕàè ÍÒµ ¾µØ ¢Í§ i-Stamp2P24 ·Õµè Í ¡Ñº LED µÑÇàÅ¢ 7 Ê Ç¹µ ͧÁÕµÇÑ µ Ò¹·Ò¹¨íÒ¡Ñ´¡ÃÐáÊãË á¡ LED ã¹·Ø¡à«¡àÁ¹µ ¡ÒáíÒ˹´ãË LED µÑÇàÅ¢ 7 Ê Ç¹áÊ´§¢ ÍÁÙÅ à» ¹µÑÇàÅ¢ËÃ×Íà» ¹ÊÑ­Åѡɳ ã´æ ¡çµÒÁ µ ͧÁÕ¡ÒáíÒ˹´ÃٻẺ¡ÒÃáÊ´§¼Å¢Í§à«¡àÁ¹µ µÒ §æ ´ Ç¢ ÍÁÙÅáµ ÅкԵ¢Í§ i-Stamp2P24 áÅ Çãª Ç¸Ô ¡Õ ÒÃà» ´µÒÃÒ§ËÃ×Í look up table ´Ñ§áÊ´§µÑÇÍ ҧµÒÃÒ§¢ ÍÁÙŢͧ¡ÒÃáÊ´§¼Å µÑÇàÅ¢°Ò¹ÊԺˡ¢Í§ LED µÑÇàÅ¢ 7 Ê Ç¹ã¹µÒÃÒ§·Õè 7-1 ¡ÒÃà¢Õ¹â»Ãá¡ÃÁà¾×Íè ¢Ñº LED µÑÇàÅ¢ 7 Ê Ç¹¤ÇÃ㪠¡ÒÃà» ´µÒÃÒ§¢ ÍÁÙÅ (look up table) ª Ç «Ö§è ã¹ iStamp2P24 ¡çÁ¤Õ Òí Êѧè LOOKUP ÍíҹǤÇÒÁÊдǡÍÂÙá Å Ç ¨Ò¡¹Ñ¹é ˹ ǧàÇÅÒà¾×Íè ãË LED ã¹à«¡àÁ¹µ ··Õè Òí §Ò¹ ¹Ñ¹é µÔ´ÊÇ Ò§¹Ò¹¾Í·Õ¼è ãÙ ª §Ò¹àËç¹¢ ÍÁÙÅ·Õ¹è Òí ÁÒáÊ´§¼Å

7.2 ¡ÒâѺ LED µÑÇàÅ¢ 7 Ê Ç¹áººÁÑŵÔà¾Åç¡« 㹡óշÕèµ Í§¡ÒÃãË i-Stamp2P24 ¢Ñº LED µÑÇàÅ¢ÁÒ¡¡Ç Ò 1 ËÅÑ¡ µ ͧ㪠෤¹Ô¤ ¡ÒÃáÊ´§¼Å ẺÁÑŵÔà¾Åç¡« (multiplex) Íѹ໠¹ÇÔ¸Õ¡ÒâѺãË LED ÊÇ Ò§·ÕÅÐËÅÑ¡´ ÇÂÍѵÃÒàÃçÇ·ÕèµÒ¢Í§Á¹ØÉ äÁ ÊÒÁÒö µÃǨ¨Ñºä´ ·Ñ¹ ¨Ö§´ÙàËÁ×Í¹Ç Ò LED µÑÇàÅ¢ 7 Ê Ç¹·Ø¡ËÅÑ¡µÔ´ÊÇ Ò§ã¹àÇÅÒà´ÕÂǡѹ ¡ÒÃáÊ´§¼ÅẺÁÑŵÔà¾Åç¡« ¹ÕéÁÕ»ÃÐ⪹ µ ÍäÁâ¤Ã¤Í¹â·ÃÅàÅÍà áÅÐÃкºËÅÒ»ÃСÒôѧ¹Õé 1. Å´¾Åѧ§Ò¹ä¿¿ Ò·Õãè ª ·íÒãË ¢¹Ò´¢Í§áËÅ §¨ ÒÂä¿àÅç¡Å§ Ê §¼ÅãË ¢¹Ò´¢Í§ÃкºàÅç¡Å§´ Ç 2. ÊÒÁÒö¢Ñº LED µÑÇàÅ¢ä´ ËÅÒÂËÅÑ¡ â´Â㪠¾Íà µà¾ÔÁè àµÔÁ੾ÒСÒõԴµ ͡Ѻ¢Òà ÇÁ෠ҹѹé 3. Å´¨íҹǹµÑǵ Ò¹·Ò¹·Õè㪠¨íÒ¡Ñ´¡ÃÐáʢͧ LED ã¹áµ ÅÐà«¡àÁ¹µ â´ÂÂѧ¤§ãª µÑǵ Ò¹·Ò¹ à¾×èͨíÒ¡Ñ´¡ÃÐáÊãË LED ã¹áµ ÅÐà«¡àÁ¹µ à¾Õ§ 8 µÑÇäÁ Ç Ò¨Ð¢Ñº LED µÑÇàÅ¢ 7 Ê Ç¹¡ÕèËÅÑ¡¡çµÒÁ

"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


D7

D6

D5

D4

D3

D2

D1

D0

¤ ÒàÅ¢°Ò¹ÊԺˡ·Õãè ª ¡ÑºàºÊÔ¡áʵÁ» 2P 㹡óÕ㪠LED Ẻá¤â·´Ã ÇÁ

0

0

1

1

1

1

1

1

$3F

0

0

0

0

0

1

1

0

$06

0

1

0

1

1

0

1

1

$5B

0

1

0

0

1

1

1

1

$4F

0

1

1

0

0

1

1

0

$66

0

1

1

0

1

1

0

1

$6D

0

1

1

1

1

1

0

1

$7D

0

0

0

0

0

1

1

1

$07

0

1

1

1

1

1

1

1

$7F

0

1

1

0

1

1

1

1

$6F

0

1

1

1

0

1

1

1

$77

0

1

1

1

1

1

0

0

$7C

0

0

1

1

1

0

0

1

$39

0

1

0

1

1

1

1

0

$5E

0

1

1

1

1

0

0

1

$79

0

1

1

1

0

0

0

1

$71

1

1

1

1

1

1

1

1

$FF

¢ ÍÁÙÅ´Ô¨ÔµÍÅàÍÒµ ¾ØµÊíÒËÃѺ¢Ñº LED µÑÇàÅ¢ 7 Ê Ç¹

¤ ÒµÑÇàÅ¢·ÕèáÊ´§ º¹µÑÇ LED

µÒÃÒ§·Õè 7-1 µÒÃÒ§¢ ÍÁÙŢͧ¡ÒÃáÊ´§¼ÅµÑÇàÅ¢ 0 ¶Ö§ F ¢Í§ LED µÑÇàÅ¢ 7 Ê Ç¹áººá¤â·´Ã ÇÁ áÅСíÒ˹´à«¡àÁ¹µ a ¤×Í D0 äŠ仵ÒÁÅíҴѺ¨¹¶Ö§ dp ¤×Í D7 ¡ÒâѺ LED µÑÇàŢẺÁÑŵÔà¾Åç¡« ¨Ðµ ͢ҢͧᵠÅÐà«¡àÁ¹µ ÃÇ Á¡Ñ¹¤×Í à«¡àÁ¹µ a ¢Í§·Ø¡ËÅÑ¡ ¨Ðµ Ͷ֧¡Ñ¹äŠ仨¹¶Ö§à«¡àÁ¹µ g 㹺ҧ§Ò¹·Õµè Í §ãª ¨´Ø dp ¡çµÍ §µ ͢Ңͧ¨Ø´ dp ÃÇÁ¡Ñ¹´ Ç ¡ÒäǺ¤ØÁ ãË LED ËÅÑ¡ã´µÔ´ÊÇ Ò§ ·íÒä´ â´Â¡Òè ÒÂä¿à¢ Ò·Õ¢è Òà ÇÁ¢Í§ LED ËÅÑ¡¹Ñ¹é æ ઠ¹ ã¹ LED Ẻá¤â·´Ã ÇÁ ËÒ¡µ ͧ¡ÒÃãË ËÅÑ¡·Õè 3 µÔ´ÊÇ Ò§¡çãË µÍ ¢Òà ÇÁ¢Í§ËÅÑ¡·Õè 3 ŧ¡ÃÒÇ´ LED ã¹ËÅÑ¡·Õè 3 ¡ç¨ÐµÔ´ÊÇ Ò§µÒÁ¢ ÍÁÙÅ ·ÕèÊ §à¢ ÒÁÒÂѧ¢Ò¢Í§áµ ÅÐà«¡àÁ¹µ Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"


i-Stamp2P24

P0 P1 P2 P3 P4 P5 P6 P7 P15

510 x8

DSP3 (DIGIT3)

DSP4 (DIGIT4)

DSP2 (DIGIT2)

DSP1 (DIGIT1)

a b c d e f g

a b c d e f g

a b c d e f g

a b c d e f g

dp

dp

dp

dp

COM

COM

COM

COM

P14 P13 P12

ÃÙ»·Õè 7-4 ǧ¨Ã¢Ñº LED µÑÇàÅ¢ 7 Ê Ç¹ 4 ËÅѡẺÁÑŵÔà¾Åç¡« ¢Í§ i-Stamp2P24 ¡ÒÃ㪠i-Stamp2P24 ࢠÒÁҤǺ¤ØÁ¡ÒÃáÊ´§¼Åã¹ÅѡɳйÕé¨Ö§à» ¹¡ÒÃࢠÒÁҤǺ¤ØÁ¡Òè ÒÂä¿à¢ Ò ·Õè¢Òà ÇÁ¢Í§ LED µÑÇàŢᵠÅÐËÅÑ¡¹Ñè¹àͧ â´Â i-Stamp2P24 ¨Ð¨ ÒÂä¿ãË á¡ ¢Òà ÇÁ¢Í§ LED µÑÇàÅ¢ ·ÕÅÐ ËÅÑ¡äŠ仵ÒÁÅíҴѺ´ ǤÇÒÁàÃçÇ ã¹ÃÙ»·Õè 7-4 áÊ´§¡ÒâѺ LED ẺÁÑŵÔà¾Åç¡« â´Â㪠i-Stmap2P24 ¡Ãкǹ¡ÒÃàÃÔÁè µ ¹â´Â i-Stamp2P24 Ê §¢ ÍÁÙÅÍÍ¡ä»ÂѧૡàÁ¹µ a-g áÅÐ dp (㹡óշµÕè Í §¡ÒÃ㪠dp) ¢Í§ LED µÑÇàÅ¢ 7 Ê Ç¹¡ ͹ ¨Ò¡¹Ñé¹¨Ö§Ê §¢ ÍÁÙÅ 0 ä»Âѧ¢Òà ÇÁ¢Í§ LED µÑÇàÅ¢ 7 Ê Ç¹ã¹ËÅÑ¡·Õè µ ͧ¡ÒÃãË áÊ´§¼Å ¡µÑÇÍ ҧ µ ͧ¡ÒÃáÊ´§µÑÇàÅ¢ 12 i-Stamp2P24 µ Í§Ê §¢ ÍÁÙŢͧàÅ¢ 1 仡 ͹áŠǨ֧ Ê §¢ ÍÁÙÅ 0 ä»Âѧ¢Òà ÇÁ¢Í§ DSP2 ¨Ò¡¹Ñé¹¨Ö§Ê §¢ ÍÁÙÅàÅ¢ 2 áÅ ÇÊ §¢ ÍÁÙÅ 0 ä»Âѧ¢Òà ÇÁ¢Í§ DSP1 µÒÁÅíҴѺ´ ǤÇÒÁàÃçÇÊÙ§ã¹ÍѵÃÒ·ÕèµÒ¢Í§Á¹ØÉ äÁ ÊÒÁÒöÊѧࡵàË繤ÇÒÁà»ÅÕè¹á»Å§´Ñ§¡Å ÒÇ ÀÒ¾·ÕèàËç¹ ¨Ö§¡ÅÒÂà» ¹Ç Ò LED µÑÇàÅ¢ 7 Ê Ç¹·Ñ§é 2 ËÅÑ¡áÊ´§µÑÇàÅ¢ 12 ¾Ã ÍÁ¡Ñ¹ ¨ÐàËç¹ä´ ÇÒ ´ Ç¡Ãкǹ¡ÒùÕé LED µÑÇàÅ¢ 7 Ê Ç¹¨Ð·íÒ§Ò¹äÁ ¾Ã ÍÁ¡Ñ¹ ¡ÒáԹ¡ÃÐáÊä¿¿ Ò¨Ö§ÁÕ¤Ò ÊÙ§Êش෠ҡѺ LED ·Ø¡à«¡àÁ¹µ ã¹Ë¹Ö§è ËÅÑ¡µÔ´ ÊÇ Ò§¾Ã ÍÁ¡Ñ¹à· ҹѹé ËÒ¡ LED ã¹áµ ÅÐà«¡àÁ¹µ µÍ §¡ÒáÃÐáÊä¿¿ Ò 10 mA ¡ÒâѺ LED µÑÇàÅ¢ 7 Ê Ç¹ ẺÁÑŵÔà¾Åç¡« ¨ÐÁÕ¤ÇÒÁµ ͧ¡ÒáÃÐáÊä¿¿ ÒÊÙ§ÊØ´à¾Õ§ 80 mA ෠ҹѹé äÁ ÇÒ ¨Ð¢Ñº LED µÑÇàÅ¢ 7 Ê Ç¹à» ¹ ¨íҹǹ෠Òã´¡çµÒÁ ¡ÒÃà¢Õ¹â»Ãá¡ÃÁà¾×Íè ¢Ñº LED µÑÇàÅ¢ 7 Ê Ç¹áººÁÑŵÔà¾Åç¡« ¹¨Õé §Ö ÁÕ¤ÇÒÁ«Ñº« ͹ÁÒ¡¡Ç Ò¡ÒâѺẺ ËÅÑ¡à´ÕÂè Ç ¨Ò¡Ç§¨Ãã¹ÃÙ»·Õè 7-4 µ ͧ㪠¢Ò¾Íà µà¾ÔÁè àµÔÁ¨Ò¡·Õãè ª 㹡ÒâѺᵠÅÐà«¡àÁ¹µ Í¡Õ 4 ¢Ò Í ҧäáçµÒÁ ¡ÒÃ㪠i-Stamp2P24 ¢Ñº LED µÑÇàÅ¢ 7 Ê Ç¹â´ÂµÃ§ µ ͧ㪠¢Ò¾Íà µ¨íҹǹÁÒ¡ ¡Ã³Õ·¢Õè ºÑ LED µÑÇàÅ¢ 7 Ê Ç¹ 4 ËÅÑ¡ µ ͧ㪠¢Ò¾Íà µÁÒ¡¶Ö§ 12 ¢Ò ã¹¢³Ð·Õàè ºÊÔ¡áʵÁ» 2P ÁÕ¢Ò¾Íà µãª §Ò¹ 16 ¢Ò ·íÒãË Á¢Õ ÒÇ Ò§ÊíÒËÃѺ㪠§Ò¹Í×¹è à¾Õ§ 4 ¢Ò ã¹Ç§¨Ã·Õµè Í §ãª ¢Ò¾Íà µÁÒ¡ áÅе ͧ¡ÒÃãË Á¡Õ ÒÃáÊ´§¼Å´ Ç LED µÑÇàÅ¢ 7 Ê Ç¹ ¢Íá¹Ð¹íÒ ãË ãª äÍ«Õ¢ºÑ LED µÑÇàÅ¢ 7 Ê Ç¹«Ö§è ÊÒÁÒöÃѺ¢ ÍÁÙÅ¡ÒÃáÊ´§¼ÅẺ͹ءÃÁ ÍÒ·Ô àºÍà MAX7219 á·¹ ¨Ðª Ç ãË ¡ÒúÃÔËÒâҾÍà µ¢Í§ i-Stamp2P24 ·íÒä´ Í ҧÁÕ»ÃÐÊÔ·¸ÔÀÒ¾ÁÒ¡¢Ö¹é

"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ·Õè 8 ¢Ñº LED µÑÇàÅ¢ 7 Ê Ç¹Í ҧ§ Ò à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 510: 8 µÑÇ 5. LED µÑÇàÅ¢ 7 Ê Ç¹ÊÕá´§ Ẻá¤â·´Ã ÇÁ 1 µÑÇ

¡Ò÷´Åͧ 8.1 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB0801.BSP '******************************************************************* ' Program : LAB0801.BSP ' Description : Single 7 Segment display ' Hardware : Connect A-DP TO P0-P7 and connect DIGIT 1 common TO GND '******************************************************************* ' {$STAMP BS2P} ' {$PBASIC 2.5} I VAR Byte ' Define Byte variable TO keep LOOP counter DIRL=$FF ' Define P0-P7 as OUTPUT LOOP1: FOR I=0 TO 9 ' Display number 0 TO 9 LOOKUP I,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F],OUTL PAUSE 1000 ' Delay 1 sec. NEXT GOTO LOOP1 ' Goto loop

¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ àÃÔÁè µ ¹´ Ç¡ÒáíÒ˹´ãË ¢Ò¾Íà µ·Õãè ª §Ò¹·Ñ§é ËÁ´à» ¹¢ÒàÍÒµ ¾µØ ¨Ò¡¹Ñ¹é ¡íÒ˹´Ãͺ¢Í§¡ÒÃáÊ´§¼Å à¹×Íè § ¨Ò¡¢ ÍÁÙÅ·Õ¹è Òí ÁÒáÊ´§·Ò§ LED ÁÕ 10 µÑǤ×Í 0 ¶Ö§ 9 ¨Ö§µ ͧ¡íÒ˹´¨íҹǹÃͺ¢Í§¡ÒÃà» ´µÒÃÒ§¢ ÍÁÙÅ 10 Ãͺ ¨Ò¡¹Ñ¹é Ê §¢ ÍÁÙÅÍÍ¡ä»áÊ´§¼Åâ´Â¡ÒÃà» ´µÒÃÒ§¢ ÍÁÙÅ´ ǤíÒÊѧè LOOKUP áÅ Ç·íÒ¡ÒÃ˹ ǧàÇÅÒà¾×Íè ãË ÊÒÁÒö àË繡ÒÃáÊ´§¼Åä´ Í ҧªÑ´à¨¹ 8.2 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 8.3 㪠ǧ¨Ãã¹ÃÙ»·Õè L8-1 㹡Ò÷´Åͧ â´Âµ Íǧ¨Ãŧº¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"!


P0

i-Stamp2P

510 x7

DSP1 (DIGIT1) a

P1

b

P2

c

P3

d

P4

e

P5

f g

P6

COM

ÃÙ»·Õè L8-1 ǧ¨Ã·´Åͧ¢Ñº LED µÑÇàÅ¢7 Ê Ç¹ 9.4 ¨ ÒÂä¿àÅÕÂé § Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED µÑÇàÅ¢ 7 Ê Ç¹ LED ¨ÐàÃÔÁè µ ¹áÊ´§µÑÇàÅ¢ 0 ¡ ͹áŠǵÒÁ´ Ç 1,2 仨¹¶Ö§ 9 áÅ Çǹ¡ÅѺÁÒ·Õè 0 ãËÁ ·íҧҹǹÍÂ٠ઠ¹¹Õé仵ÅÍ´

i-Stamp2p24

""

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ·Õè 9 ¢Ñº LED µÑÇàÅ¢ 7 Ê Ç¹ 4 ËÅѡẺÁÑŵÔà¾Åç¡« à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 510: 7 µÑÇ 5. LED µÑÇàÅ¢ 7 Ê Ç¹ 4 ËÅѡẺá¤â·´Ã ÇÁ (àºÍà LTC-4727JF ËÃ×Íà·Õº෠Ò) 1 µÑÇ

à¡ÕÂè ǡѺ LED µÑÇàÅ¢ 7 Ê Ç¹àºÍà LTC4727JF

16

NC

NC

Segment f

NC

Segment c

Segment a

Segment g

Segment b

ÊíÒËÃѺ LED µÑÇàÅ¢ 7 Ê Ç¹·Õ¹è Òí ÁÒá¹ÐйíÒãË ãª ã¹¡Ò÷´Åͧ¹Õé à» ¹áººá¤â·Ã´Ã ÇÁ 4 ËÅÑ¡ ÁÕ¡Òà àª×Íè Áµ ÍÀÒÂã¹à» ¹áººÁÑŵÔà¾Åç¡« áÅÐÁÕ LED áÊ´§¨Ø´¾ÔàÈÉ 3 ¨Ø´ ¤×Í L1 ¶Ö§ L3 «Ö§è ä´ ÃºÑ ¡ÒáíÒ˹´µíÒá˹ § ãË à» ¹¨Ø´¤Ñ¹è ÃÐËÇ Ò§ LED µÑÇàÅ¢ËÅÑ¡·Õè 2 áÅÐ 3 ¨íҹǹ 2 ¨Ø´ à¾×Íè 㪠»ÃÐ⪹ 㹡ÒÃà» ¹¨Ø´¤Ñ¹è ËÅÑ¡àÇÅÒ áÅÐ ÍÕ¡ 1 ¨Ø´¤×Í ÍÂÙà ÐËÇ Ò§ËÅÑ¡·Õè 1 áÅÐ 2 ªÔ´ä»·Ò§´ Ò¹º¹ ·íÒãË ÊÒÁÒö㪠LED ¨Ø´¹Õáé Ê´§¨Ø´Í§ÈÒ㹡ÒÃáÊ´§ ¤ ÒÍسËÀÙÁäÔ ´ ¡ÒèѴ¢Ò¢Í§ LED µÑÇàÅ¢ 7 Ê Ç¹Ãع ¹Õàé » ¹´Ñ§¹Õé

9 L3

L1

L2

DIGIT4

Segment dp

DIGIT3

Segment e

DIGIT-L

Segment d

8 DIGIT2

DIGIT1

1

â´Â¡ÒäǺ¤ØÁ LED ·Õµè Òí á˹ § L1 ¶Ö§ L3 ¨ÐÁÕ¢Òà ÇÁà¾ÔÁè ÁÒÍÕ¡Ë¹Ö§è ¢Ò¤×Í DIGIT-L ·íÒ§Ò¹´ ÇÂÅͨԡ 1 ઠ¹à´ÕÂǡѺ LED µÑÇàÅ¢ 7 Ê Ç¹·Ñ§é 4 ËÅÑ¡ ¨Ö§ÍÒ¨¡Å ÒÇä´ ÇÒ LED ¾ÔàÈÉ¹Õ¡é ¤ç Í× LED ÍÕ¡ 1 ËÅÑ¡·Õàè ¾ÔÁè ¢Ö¹é ÁÒ ¹Ñ¹è àͧ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"#


P0 P1

i-Stamp2P24

510 x7

DSP1 : LTC4727JF a b

P2

c

P3

d

P4

e

P5

f g

P6 P15

DIGIT4

DIGIT3

DIGIT2

DIGIT1

P14 P13 P12

ÃÙ»·Õè L9-1 ǧ¨Ã·´Åͧ¢Ñº LED µÑÇàÅ¢ 7 Ê Ç¹ 4 ËÅѡẺÁÑŵÔà¾Åç¡« ¢Í§ i-Stamp2P24

¡Ò÷´Åͧ

9.1 㪠ǧ¨Ãã¹ÃÙ»·Õè L9-1 㹡Ò÷´Åͧ â´Âµ Íǧ¨ÃµÒÁÃÙ»·Õè L9-1 º¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ 9.2 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB0901.BSP '********************************************************** ' Program : LAB0901.BSP ' Description : Drive LED 4 digit in multiplex connection ' Hardware : Connect A TO P0 ' Connect B TO P1 ' Connect C TO P2 ' Connect D TO P3 ' Connect E TO P4 ' Connect F TO P5 ' Connect G TO P6 ' Connect DP TO P7 ' Connect DIGIT1 TO P12, Connect DIGIT2 TO P13 ' Connect DIGIT3 TO P14, Connect DIGIT4 TO P15 '********************************************************** ' {$STAMP BS2P} ' {$PBASIC 2.5} DIRS = %1111111111111111 DELAY CON 500 DELAY2 CON 1 DISPLAY: OUTH = %11111111 PAUSE DELAY2 OUTL = 06

"$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


OUTD = %1110 PAUSE DELAY OUTH = %11111111 PAUSE DELAY2 OUTL = 91 OUTD = %1101 PAUSE DELAY OUTH = %11111111 PAUSE DELAY2 OUTL = 125 OUTD = %1011 PAUSE DELAY OUTH = %11111111 PAUSE DELAY2 OUTL = 127 OUTD = %0111 PAUSE DELAY GOTO DISPLAY

¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ â»Ãá¡ÃÁ¹Õàé » ¹¡ÒÃáÊ´§ãË àË繶֧¡ÒâѺ LED µÑÇàŢẺÁÑŵÔà¾Åç¡« àÃÔÁè µ ¹´ Ç¡ÒáíÒ˹´ãË ¢Ò¾Íà µ·Õè 㪠§Ò¹à» ¹àÍÒµ ¾µØ µÒÁ´ Ç¡ÒáíÒ˹´¤ ҢͧµÑÇá»Ã·Õãè ª 㹡ÒÃ˹ ǧàÇÅÒ â´ÂµÑÇá»Ã˹ ǧàÇÅÒµÑÇáá DELAY 㪠˹ ǧàÇÅÒ¡ÒÃáÊ´§¼Å¢Í§ LED Ê Ç¹ DELAY2 㪠˹ ǧàÇÅÒ¡ÒôѺ¢Í§ LED ã¹áµ ÅÐËÅÑ¡à¾×Íè á¡ »­ ËÒ¡ÒáоÃÔº 㹡ÒÃáÊ´§¼Å¢Í§ LED àÁ×Íè ÁÕ¡ÒÃà»ÅÕÂè ¹ËÅÑ¡¢Í§¡ÒÃáÊ´§¼Å àÁ×Íè àÃÔÁè µ ¹áÊ´§¼Åµ ͧà¤ÅÕÂà LED ãË äÁ Á¡Õ ÒÃáÊ´§¼Å¤ Ò§¨Ò¡¢ ÍÁÙÅà´ÔÁ â´Â¡ÒÃà¢Õ¹¢ ÍÁÙÅ 1 ä»Âѧ¢Ò¤ÍÁ Á͹¢Í§ LED ·Ø¡ËÅÑ¡ ¨Ò¡¹Ñ¹é ˹ ǧàÇÅÒ ¢Ñ¹é µÍ¹µ Íä»à» ¹¡ÒÃÊ §¢ ÍÁÙÅ·Õµè Í §¡ÒÃáÊ´§¼Åä»Âѧ LED ã¹ËÅÑ¡¢ÇÒÊØ´ ¡ ͹ â´Â¢ ÍÁÙÅÁÕ¤Ò à· Ò¡Ñº 06 «Ö§è ¡ç¤Í× àÅ¢ 1 ¨Ò¡¹Ñ¹é àÍç¹àÍàºÔÅ¢Ò¤ÍÁÁ͹¢Í§ËÅÑ¡·Õµè Í §¡ÒÃãË áÊ´§¼Å «Ö§è ¡ç¤Í× ËÅÑ¡¢ÇÒÊØ´ â´Â¡ÒÃà¢Õ¹¢ ÍÁÙÅ 1110 ä»Âѧ¢Ò¾Íà µ¡ÅØÁ C (¢Ò P15 ¶Ö§ P12) ¶Ö§µÍ¹¹Õé LED ¨ÐáÊ´§ àÅ¢ 1 ËÅѧ¨Ò¡¹Ñ¹é ¨Ðà» ¹¡ÒÃáÊ´§¼Åã¹ËÅÑ¡¶Ñ´ÁÒ «Ö§è ¢ ÍÁÙÅ·Õ¹è Òí ÁÒáÊ´§¤×Í 91 «Ö§è ¡ç¤Í× ¢ ÍÁÙŢͧ àÅ¢ 2 ¡ ͹·Õ¨è ÐáÊ´§ ¼Å àÅ¢ 2 ã¹ËÅÑ¡¶Ñ´ÁÒ·Ò§« Ò µ ͧ´Ñº¨ÍáÊ´§¼Å¡ ͹ áÅ Ç¨Ö§Ê §¢ ÍÁÙÅ·Õµè Í §¡ÒÃáÊ´§¼ÅÍÍ¡ÁÒ·Ò§¢Ò¾Íà µ P0 ¶Ö§ P7 µÒÁ´ Ç¡ÒÃàÍç¹àÍàºÔÅËÅÑ¡·Õµè Í §¡ÒÃáÊ´§¼ÅµÒÁ´ Ç¡ÒÃ˹ ǧàÇÅÒà¾×Íè áÊ´§¼Å ¡ç¨ÐàËç¹ àÅ¢ 2 »ÃÒ¡¯¢Ö¹é ·ÕËè ÅÑ¡·ÕÊè ͧ·Ò§¢ÇÒÁ×Í ã¹¡ÒÃáÊ´§¼Å¢Í§ËÅÑ¡·ÕÊè ÒÁáÅÐËÅÑ¡« ÒÂÁ×ÍÊØ´ ¡çÁ¢Õ ¹Ñé µÍ¹àª ¹à´ÕÂǡѹ àÁ×Íè Ãѹâ»Ãá¡ÃÁ ´ Ǥ Ңͧ DELAY «Ö§è ¡íÒ˹´äÇ à· Ò¡Ñº 500 ·íÒãË ÁͧàË繡ÒÃáÊ´§¼Å¢Í§ LED ã¹áµ ÅÐËÅÑ¡Í ҧªÑ´à¨¹ ¶ ÒËÒ¡Å´¤ Ò DELAY ŧÁÒ¡æ ¡ç¨ÐàËç¹µÑÇàÅ¢ 8621 áÊ´§º¹¨ÍáÊ´§ LED ·Ñ§é 4 ËÅÑ¡ ¾Ã ÍÁ¡Ñ¹ ·Ñ§é ¹Õàé ¹×Íè §¨Ò¡ÍѵÃÒ¡ÒÃǹà¾×Íè ¢Ñº LED ã¹áµ ÅÐËÅÑ¡ÊÙ§¢Ö¹é (à¹×Íè §¨Ò¡Ë¹ ǧàÇÅÒ¹ ÍÂŧ) ¨¹·íÒãË µÒ¢Í§ Á¹ØÉ äÁ ÊÒÁÒöÁͧàË繡ÒÃà»ÅÕÂè ¹á»Å§ä´ ·¹Ñ ¨Ö§´ÙàÊÁ×Í¹Ç Ò LED ·Ø¡ËÅÑ¡·íÒ§Ò¹¾Ã ÍÁ¡Ñ¹ 9.3 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 áÅ ÇÃѹâ»Ãá¡ÃÁ Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED 9.4 Å´¤ Ңͧ DELAY ŧàËÅ×Í 100, 50, 10 áÅÐ 5 µÒÁÅíҴѺ Êѧࡵ¡ÒÃáÊ´§¼Å¢Í§ LED ã¹·Ø¡¤ÃÑ§é ·ÕÁè ¡Õ ÒÃà»ÅÕÂè ¹¤ Ңͧ DELAY i-Stamp2p24

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"%


¡Ò÷´Åͧ·Õè 10 ǧ¨Ã¹Ñº 4 ËÅÑ¡ à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 510: 7 µÑÇ 10k: 1 µÑÇ 5. LED µÑÇàÅ¢ 7 Ê Ç¹ 4 ËÅѡẺá¤â·´Ã ÇÁ (àºÍà LTC-4727JF ËÃ×Íà·Õº෠Ò) 1 µÑÇ 6. ÊÇÔµª ¡´µÔ´»Å Í´Ѻ 1 µÑÇ

¡Ò÷´Åͧ 10.1 㪠ǧ¨Ãã¹ÃÙ»·Õè L10-1 㹡Ò÷´Åͧ â´Âµ Íǧ¨ÃµÒÁÃÙ»·Õè L9-1 º¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ 10.2 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB1001.BSP '********************************************************** ' Program : LAB1001.BSP ' Description : 4-digit counter (0000-9999) ' Hardware : Refer figure L10-1 '********************************************************** ' {$STAMP BS2P} ' {$PBASIC 2.5} VALUE VAR Word ' Define Word variable to keep LOOP counter SW_VAR VAR Byte ' Define Byte variable to use with BUTTON command J VAR Byte ' Define Byte variable to keep LOOP counter DIRL=$FF ' Define P0 to P7 as segment outputs DIRD=$FF ' Define P12 to P15 as common outputs VALUE=0 ' Clear VALUE GOSUB SHOW LOOP1: BUTTON 8,0,255,0,SW_VAR,1,INC_VALUE ' Receive INPUT from BUTTON GOSUB SHOW ' GOTO subroutine Shift LED GOTO LOOP1 ' Goto loop INC_VALUE: VALUE=VALUE+1//10000 ' Loop counter 0000-9999 GOTO LOOP1 ' Goto loop

"&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


P0 P1 +5V 10k P8 S1

i-Stamp2P24

510 x7

DSP1 : LTC4727JF a b

P2

c

P3

d

P4

e

P5

f g

P6 P15

DIGIT4

DIGIT3

DIGIT2

DIGIT1

P14 P13 P12

ÃÙ»·Õè L10-1 ǧ¨ÃÊíÒËÃѺ·´ÅͧÊà ҧǧ¨Ã¹Ñº 4 ËÅÑ¡ÃкºµÑÇàź¤Çº¤ØÁ´ Ç i-Stamp2P24 SHOW: OUTD=$FF ' Clear all FOR J=0 TO 3 LOOKUP VALUE DIG J,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F],OUTL LOOKUP J,[%1110,%1101,%1011,%0111],OUTD PAUSE 2 ' Delay display MPX time OUTD=$FF ' Cleat all NEXT RETURN ' Return

¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ ¨ÐàÃÔÁè µ ¹´ Ç¡ÒÃÃÍÃѺ¡Òá´ÊÇÔµª ·ºÕè Ã÷Ѵ BUTTON 8,0,255,0,SW_VAR,1,INC_VALUE àÁ×Íè ÁÕ¡Òà ¡´ÊÇÔµª ¨Ðà¾ÔÁè ¤ Ңͧ¡ÒùѺ¢Ö¹é à¡çºäÇ ã¹µÑÇá»Ã INC_VALUE ¨Ò¡¹Ñ¹é ¹íÒ¤ Òä»áÊ´§¼Å·Õè LED ·Ñ§é 4 ËÅÑ¡ µÑÇá»Ã ·Õãè ª à¡çº¤ Ò¡ÒÃáÊ´§¼Å¤×Í VALUE Ê Ç¹µÑÇá»Ã·Õãè ª 㹡ÒÃÊ᡹ LED áÊ´§¼Å¤×Í J Êѧࡵ·Õâè »Ãá¡ÃÁ Í SHOW ¨ÐàËç¹Ç Ò¡íÒ˹´Ãͺ¡ÒÃáÊ´§¼ÅäÇ à· Ò¡Ñº 4 Ãͺ¤×Í ¨Ò¡ 0 ¶Ö§ 3 â´Â㹡ÒÃ˹ ǧàÇÅҢͧ¡ÒÃáÊ´§¼Åáµ ÅÐ ËÅÑ¡¨Ð෠ҡѺ 2 ÁÔÅÅÔÇ¹Ô Ò·Õ 10.3 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 áÅ ÇÃѹâ»Ãá¡ÃÁ Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED 10.4 ¨Ò¡¹Ñ¹é ·´Åͧ¡´ÊÇÔµª Êѧࡵ¡ÒÃà»ÅÕÂè ¹á»Å§·Õàè ¡Ô´¢Ö¹é ¢Í§ LED áÊ´§¼Å àÁ×èÍàÃÔèÁµ ¹·íÒ§Ò¹ LED ¨ÐáÊ´§¤ Ò 0000 ¨Ò¡¹Ñé¹àÁ×èÍ¡´ÊÇÔµª 1 ¤ÃÑé§ LED ¨ÐáÊ´§¤ Ò·Õèà¾ÔèÁ¢Öé¹ ¹Ñ蹤×Íà¡Ô´¡ÒùѺ¤ Ò¢Öé¹·Ø¡¤ÃÑ駷ÕèÁÕ¡Òá´ÊÇÔµª ¤ ÒÊÙ§ÊØ´·ÕèÊÒÁÒö¹Ñºä´ ¤×Í 9999 ¨Ò¡¹Ñ鹨Ðǹ¡ÅѺÁÒ·Õè 0000 ãËÁ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

"'


#

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


º··Õè 8

¡ÒÃãªÑ§Ò¹¤íÒÊѧè RCTIME ¢Í§ i-Stamp2p24 8.1 á¹Ç¤Ô´¢Í§¤íÒÊѧè RCTIME á¹Ç¤Ô´¢Í§¤íÒÊÑè§ RCTIME ÁÒ¨Ò¡¡ÒûÃШØáÅФÒ»ÃШآͧµÑÇà¡çº»ÃÐ¨Ø â´Â»¡µÔ¨Ð㪠ǧ¨Ã RC µ Íࢠҷբè Ò¾Íà µ¢Í§ i-Stamp2P24 ´Ñ§áÊ´§ã¹ÃÙ»·Õè 8-1 àÃÔÁè µ ¹¡Ãкǹ¡Òô Ç¡Òû ͹áç´Ñ¹ +5V ÍÍ¡ ¨Ò¡¢Ò¾Íà µ¢Í§ i-Stamp2P24 ä»ÂѧµÑÇà¡çº»ÃШØ㹪 ǧàÇÅÒË¹Ö§è ¨¹¡ÃÐ·Ñ§è µÑÇà¡çº»ÃШØÊÒÁÒöà¡çºáç´Ñ¹äÇ ä´ ¨¹àµçÁ ·íÒãË áç´Ñ¹µ¡¤Ã ÍÁµÑÇà¡çº»ÃШب§Ö ෠ҡѺ +5V ¨Ò¡¹Ñ¹é ¨Ö§¡íÒ˹´ãË ¢Ò¾Íà µ·Õµè Í ÍÂÙ¡ ºÑ ǧ¨Ã RC ¹Ñ¹é ¡ÅÒÂà» ¹¢ÒÍÔ¹¾Øµ ·íÒãË ·¢Õè Ò¾Íà µÁÕʶҹÐÍÔÁ¾Õá´¹« ʧ٠µÑÇà¡çº»ÃШب§Ö µ ͧ¤Ò»ÃШØÍÍ¡ÁÒ¼ Ò¹·Ò§µÑÇ µ Ò¹·Ò¹ RCAL áÅÐ Rx â´Â RCAL áÅÐ Rx ÊÒÁÒöàÃÕ¡ÃÇÁ¡Ñ¹Ç Ò REQ àÁ×è͵ÑÇà¡çº»ÃШؤÒ»ÃШØÍÍ¡ÁÒ ·íÒãË áç´Ñ¹µ¡¤Ã ÍÁµÑÇà¡çº»ÃШØà¡Ô´¡ÒÃà»ÅÕè¹á»Å§µÒÁ¤ÇÒÁ ÊÑÁ¾Ñ¹¸ ·Ò§¤³ÔµÈÒʵà µ Í仹Õé VC

¨ · t ©© ¸ Re qvC ¸¹ ª Vcc v e

àÁ×Íè ¡ÃзíÒ¤íÒÊѧè RCTIME i-Stamp2P24 ¨ÐµÕ¤ÇÒÁʶҹзҧÅͨԡ¢Í§¢Ò¾Íà µ·Õãè ª ¡ÃзíÒ¤íÒÊÑ§è ¹Õé à» ¹ 1 áÅ ÇàÃÔÁè µ ¹¡ÒùѺ¤ ÒàÇÅҷѹ·Õ ¡ÒäÒ»ÃШآͧµÑÇà¡çº»ÃШبе ͧ㪠àÇÅÒª Ç§Ë¹Ö§è «Ö§è ÊÒÁÒö¡íÒ˹´ ä´ â´Â¤ ҢͧµÑÇà¡çº»ÃШØàͧáÅеÑǵ Ò¹·Ò¹·Õµè Í Ã ÇÁÍÂÙ ¨Ò¡Ç§¨Ãã¹ÃÙ»·Õè 8-1 ¹Õé µÑǵ Ò¹·Ò¹´Ñ§¡Å ÒǤ×Í RCAL áÅÐ Rx ¹Ñ¹è àͧ àÁ×Íè à¡Ô´¡ÒäÒ»ÃÐ¨Ø áç´Ñ¹µ¡¤Ã ÍÁµÑÇà¡çº»ÃШبФ ÍÂæ Ŵŧ ¨¹¶Ö§¤ Òáç´Ñ¹à·ÃªâÎÅ´ àÁ×Íè ¡ÃзíÒ¤íÒÊѧè RCTIME áŠǢҾÍà µ¢Í§ àºÊÔ¡áʵÁ» 2 ¨Ð¡ÅÒÂà» ¹ÍÔ¹¾Øµ ·íÒãË ¨´Ø ¹Õàé ¡Ô´ÊÀÒ¾ÍÔÁ¾Õá´¹« ʧ٠àÊÁ×͹໠´Ç§¨Ã

+5V

¡ ͹㪠¤Òí Êѧè RCTIME µ ͧ·íÒ¡ÒûÃШصÇÑ à¡çº»ÃÐ¨Ø C ´ Ç¡ÒÃÊ §¢ ÍÁÙÅ "1" ÁÒÂѧ¢Ò¾Íà µ ¢Ò¾Íà µ¢Í§ BS2-IC

àºÊÔ¡áʵÁ» 2 4CAL

RCAL REQ = RCAL+RX

+

C

RX

4X

ÃÙ»·Õè 8-1 ¡Ãкǹ¡Ò÷íÒ§Ò¹¢Í§¤íÒÊѧè RCTIME ·ÕÊè ÁÑ ¾Ñ¹¸ ¡ºÑ ǧ¨Ã RC Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#


(threshold voltage : VTH) ÊíÒËÃѺ i-Stamp2P24 ¤×ͤ Òáç´Ñ¹ 1.5V i-Stamp2P24 ¨ÐµÕ¤ÇÒÁÇ Ò à¡Ô´Åͨԡ 0 ¢Ö¹é áÅ Ç ¡ç¨ÐËÂØ´¹Ñº¤ ÒàÇÅÒ áÅ ÇÍ Ò¹¢ ÍÁÙŢͧ¡ÒäÒ»ÃШع¹Ñé ÍÍ¡ÁÒ â´Â¤ Ò·Õäè ´ ¨ÐÁÕ˹ ÇÂà» ¹ 0.75 äÁâ¤ÃÇÔ¹Ò·Õ ´Ñ§¹Ñé¹ËÒ¡µ ͧ¡Ò÷ÃÒº¤ ÒàÇÅÒ·Õèá· ¨ÃÔ§ã¹Ë¹ ÇÂäÁâ¤ÃÇÔ¹Ò·Õ ¨Ö§µ ͧ¹íÒ¤ Ò·Õèä´ ä»¤Ù³¡Ñº 0.75 äÁâ¤ÃÇÔ¹Ò·Õ ¡ç¨Ðä´ ¤Ò àÇÅÒ·Õãè ª 㹡ÒäÒ»ÃШØÍÍ¡ ´Ñ§¹Ñ¹é ¤ ÒàÇÅÒÊÙ§ÊØ´·Õè i-Stamp2P24 ÊÒÁÒÃ¶Í Ò¹ä´ ¨Ò¡ ¡ÒÃ㪠¤Òí Êѧè RCTIME ¤×Í 65,535 : 0.75 äÁâ¤ÃÇÔ¹Ò·Õ à· Ò¡Ñº 49.151 ÁÔÅÅÔÇ¹Ô Ò·Õ Í ҧäáçµÒÁ ÊÒÁÒö¤íҹdzËÒ¤ ÒàÇÅÒ㹡ÒäÒ»ÃШØä´ ¨Ò¡¤ÇÒÁÊÑÁ¾Ñ¹¸ ·Ò§¤³ÔµÈÒʵà µ Í仹Õé t DIS

¨V · R EQ v C v ln© cc ¸...............(1) © VTH ¸ ª ¹

â´Â·Õè REQ = RCAL + Rx (¨Ò¡Ç§¨Ãã¹ÃÙ»·Õè 8-1) ln ¤×Í ÅÍ¡ÒÃÔ¸ÁÖè °Ò¹¸ÃÃÁªÒµÔ Vcc = 5V VTH = 1.5V ËÒ¡¡íÒ˹´¤ Ңͧ REQ = 110k:, C = 0.1PF ¤ ÒàÇÅÒ tDIS ¨ÐÁÕ¤Ò à· Ò¡Ñº 13,244 äÁâ¤ÃÇÔ¹Ò·Õ áµ i-Stamp2P24 ¨ÐãË ¤Ò ÍÍ¡ÁÒ෠ҡѺ 17,658 ¢Í§Ë¹ ǹѺ 0.75 äÁâ¤ÃÇÔ¹Ò·Õ

8.2 »ÃÐ⪹ ¢Í§¤íÒÊѧè RCTIME ¨Ò¡á¹Ç¤Ô´´Ñ§¡Å ÒÇ ·íÒãË ÊÒÁÒö»ÃÐÂØ¡µ ¤Òí Êѧè RCTIME ÁÒ㪠ËÒ¤ ÒµÑǵ Ò¹·Ò¹·Õäè Á ·ÃÒº¤ Òä´ ¹Ñ¹è ¤×Í ¶ Ò¡íÒ˹´¤ Ò tDIS áÅÐ C äÇ ¤Ò ˹֧è áÅÐ㪠¼Å¡ÒùѺ·Õäè ´ ¨Ò¡¤íÒÊѧè RCTIME ÁÒ¤íҹdz¡ç¨ÐÊÒÁÒöËÒ¤ ÒµÑÇ µ Ò¹·Ò¹ REQ ÍÍ¡ÁÒä´ áÅж ÒËÒ¡¡íÒ˹´¤ Ò RCAL äÇ áÅ Ç ¡ç¨ÐÊÒÁÒöËÒ¤ Ңͧ Rx «Ö§è äÁ ·ÃÒº¤ Òä´ â´Â·ÑÇè ä» Rx ÁÑ¡à» ¹µÑǵ Ò¹·Ò¹¾ÔàÈÉ·ÕÁè Ò¨Ò¡¡Ò÷íÒ§Ò¹¢Í§µÑǵÃǨ¨Ñº ÍÒ·Ô LDR ËÃ×͵Ñǵ Ò¹·Ò¹á»Ã ¤ ÒµÒÁáʧ àÁ×Íè äÁ ÁáÕ Ê§ÁÒµ¡¡Ãзº¤ Ò¤ÇÒÁµ Ò¹·Ò¹¢Í§ LDR ¨ÐÊÙ§ÁÒ¡áÅÐŴŧàÁ×Íè ÁÕáʧÁÒµ¡¡Ãзº ÂÔ§è áʧÁÕ¤ÇÒÁࢠÁÁÒ¡ ¤ Ò¤ÇÒÁµ Ò¹·Ò¹¡ç¨ÐŴŧÁÒ¡ áµ ¡Áç ¾Õ ¡Ô ´Ñ ¤ ÒµèÒí ÊØ´áÅÐÊÙ§ÊØ´¨íÒ¡Ñ´ÍÂÙ ËÃ×ÍÍҨ໠¹à·Íà ÁÊÔ àµÍà ËÃ×͵Ñǵ Ò¹·Ò¹á»Ã¤ ÒµÒÁÍسËÀÙÁáÔ ºº NTC (Negative Temperature Co-efficient) ËÁÒ¶֧໠¹µÑǵ Ò¹·Ò¹ á»Ã¤ ÒµÒÁÍسËÀÙÁáÔ ºº¼¡¼Ñ¹ ¶ ÒÍسËÀÙÁÊÔ §Ù ¤ Ò¤ÇÒÁµ Ò¹·Ò¹¨ÐµèÒí áÅж ÒÍسËÀÙÁµÔ Òèí ¤ Ò¤ÇÒÁµ Ò¹·Ò¹¨ÐÊÙ§ ¨Ò¡¤ÇÒÁÊÑÁ¾Ñ¹¸ ·Ò§¤³ÔµÈÒʵà ¢Í§¤ ÒàÇÅÒ tDIS ÊÒÁÒö¹íÒÁÒ㪠ËÒ¤ Ò¤ÇÒÁµ Ò¹·Ò¹ REQ ä´ ´§Ñ ¹Õé R EQ

t DIS ...................(2) ¨ Vcc · ¸ C v ln© © VTH ¸ ª ¹

㹡óշãÕè ª µÇÑ à¡çº»ÃÐ¨Ø 0.1PF ¤ Ò REQ ¨Ð෠ҡѺ R EQ

Tcount v

0.75 v10 6 ............(3) ¨ Vcc · 6 ¸ 0.1v10 v ln© © VTH ¸ ª ¹

â´Â·Õè Tcount ¤×Í ¤ Ò¡ÒùѺàÇÅҢͧ i-Stamp2P24 ã¹Ë¹ Ç 0.75 äÁâ¤ÃÇÔ¹Ò·Õ

#

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¨Ò¡¹Ñ¹é ·íÒ¡ÒèѴÃٻẺãËÁ ¨Ðä´ R EQ

Tcount v k............(4)

â´Â·Õè

k

0 . 75 v 10 6 .......... ..(5) ¨ V cc · © ¸ C v ln © V TH ¸ ª ¹

¶ ÒµÑÇà¡çº»ÃШØ෠ҡѺ 0.1PF áç´Ñ¹ Vcc = 5V áÅÐ VTH = 1.5V ¤ Ò k ¨Ð෠ҡѺ 6.23 ¨Ò¡Ç§¨Ãã¹ÃÙ»·Õè 8-1 ¤ Ò RCAL ¡íÒ˹´ãË à· Ò¡Ñº 1k: ´Ñ§¹Ñ¹é Rx «Ö§è äÁ ·ÃÒº¤ Ò ¨ÐÊÒÁÒö¤íҹdz ËÒ¤ Òä´ ¨Ò¡ RX

Tcount v 6.23 R CAL

8.3 ¡ÒÃ㪠¤Òí Êѧè RCTIME ÁÕÃٻẺ¡ÒÃ㪠§Ò¹´Ñ§¹Õé RCTIME Pin, State, ResultVariable

â´Â·Õè Pin à» ¹µíÒá˹ §¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õãè ª §Ò¹ àÁ×Íè ¡ÃзíÒ¤íÒÊÑ§è ¹Õé ¢Ò¾Íà µ¨Ð¶Ù¡ ¡íÒ˹´ãË ÍÂÙã ¹âËÁ´ÍÔ¹¾Øµ áÅÐËÅѧ¨Ò¡¨º¤íÒÊÑ§è ¡ç处 ¤§ÍÂÙã ¹âËÁ´ÍÔ¹¾Øµ State à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·ÕÁè ¤Õ Ò à· Ò¡Ñº 1 ËÃ×Í 0 à¾×Íè ¡íÒ˹´ÊÀÒÇТͧ¢Ò¾Íà µàÁ×Íè ·íÒ¤íÒÊѧè RCTIME ResultVariable à» ¹¤ ÒµÑÇá»ÃËÃ×ͤ Ò¤§·Õè ÁÕ¤Ò à· Ò¡Ñº 0 ¶Ö§ 65535 ÊíÒËÃѺ¡ÒÃà¡çº¤ Ò ¡ÒùѺ¢Í§àÇÅÒã¹Ë¹ Ç 0.75 äÁâ¤ÃÇÔ¹Ò·Õ µÑÇÍ ҧ RCTIME 1, 1, Tcount

ËÁÒ¤ÇÒÁÇ Ò ¡íÒ˹´ãË ¢Ò¾Íà µ P1 à» ¹¢ÒÍÔ¹¾ØµÊíÒËÃѺµÃǨ¨Ñºáç´Ñ¹¢Í§µÑÇà¡çº»ÃÐ¨Ø â´Â¡íÒ˹´ ãË ÁÊÕ ÀÒÇÐàÃÔÁè µ ¹à» ¹ 1 Ê Ç¹¤ Ңͧ¡ÒùѺ¨Ðà¡çºäÇ ã¹µÑÇá»Ã Tcount ¡ ͹˹ Ò·Õ¨è Ð㪠§Ò¹¤íÒÊѧè RCTIME ¨Ðµ ͧ·íÒ¡ÒûÃШصÇÑ à¡çº»ÃШطµÕè Í ÍÂÙ¡ ºÑ ¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õµè Í §¡ÒÃ㪠§Ò¹¡ ͹àÊÁÍ ¨Ò¡¹Ñ¹é ¨Ö§àÃÕ¡㪠¤Òí Êѧè RCTIME â´Â¡ÒûÃШطÒí ä´ §Ò Âæ ¤×Í Ê §¢ ÍÁÙÅ 1 ÍÍ¡ä» Âѧ¢Ò¾Íà µ·Õµè Í ÍÂÙ¡ ºÑ µÑÇà¡çº»ÃÐ¨Ø à» ¹àÇÅÒÍ ҧ¹ Í 10 ÁÔÅÅÔÇ¹Ô Ò·Õ㹡óշãÕè ª µÇÑ à¡çº»ÃÐ¨Ø 0.1PF ´Ñ§â»Ãá¡ÃÁ µÑÇÍ ҧµ Í仹Õé DIR4 = 1 ' P4 as output OUT4 = 1 ' Charge the capacitor which connect at P4 of BS2P PAUSE 100 RCTIME 4,1,T_COUNT

ÊíÒËÃѺ㹺·¹Õ¨é ÐÁÕ¡Ò÷´Åͧà¾×Íè ãË ¼ãÙ ª §Ò¹ i-Stamp2P24 ä´ ·ÃÒºáÅÐࢠÒ㨶֧¡Åä¡ã¹¡Ò÷íÒ§Ò¹¢Í§ ¤íÒÊѧè RCTIME ¹Õàé ¾ÔÁè ¢Ö¹é â´Â¨ÐàÃÔÁè ¨Ò¡¡ÒÃ㪠§Ò¹àº×Íé §µ ¹ «Ö§è ¨ÐÁÕ¡ÒûÃÐÂØ¡µ 㪠ÃÇ Á¡ÑºµÑǵ Ò¹·Ò¹á»Ã¤ Ò µÒÁáʧ´ Ç Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#!


¡Ò÷´Åͧ·Õè 11 ¡ÒÃ㪠§Ò¹¤íÒÊѧè RCTIME àº×Íé §µ ¹ à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. ä¿©Ò 5. µÑǵ Ò¹·Ò¹¢¹Ò´ 1/4 W 5% ¤ Ò 1k: 1 µÑÇ 10k: 1 µÑÇ 6. µÑǵ Ò¹·Ò¹á»Ã¤ ÒµÒÁáʧËÃ×Í LDR 1 µÑÇ 7. µÑÇà¡çº»ÃÐ¨Ø 0.1PF 50V Ẻà«ÃÒÁÔ¡ 1 µÑÇ

¡Ò÷´Åͧ 11.1 㪠ǧ¨Ãã¹ÃÙ»·Õè L11-1 㹡Ò÷´Åͧ â´Âµ Íǧ¨Ãŧº¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ 11.2 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB1101.BSP '******************************************************************** ' Program : LAB1101.BSP ' Description : Demonstrate the basic RCTIME command operation ' with measure AND display the value of Rx in RC network ON P9 '******************************************************************** ' {$STAMP BS2P} ' {$PBASIC 2.5} R_EQ VAR Word RX VAR Word T_COUNT VAR Word DIRS = $FF MAIN: DIR9 =1 ' P9 as OUTPUT OUT9 = 1 ' Charge the capacitor PAUSE 100 ' Give its time TO charge RCTIME 9, 1, T_COUNT R_EQ = (7* T_COUNT) + (T_COUNT * 7/100) ' Caculated R_EQ = 7.07* T_COUNT RX = R_EQ - 1000 ' Subtract 1k resistor in serie connection DEBUG ? RX PAUSE 1000 GOTO MAIN

#"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


i-Stamp2P24

P9 1k 0.1/50V 10k

ÃÙ»·Õè L11-1 ǧ¨Ã·´Åͧ¡ÒÃ㪠§Ò¹¤íÒÊѧè RCTIME à¾×Íè ÇÑ´¤ Ò¤ÇÒÁµ Ò¹·Ò¹ ¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ ¨Ø´ÊíҤѭ¢Í§â»Ãá¡ÃÁ¹Õ¤é Í× ¡Òäíҹdz¤ Ò REQ «Ö§è 㪠ÊÁ¡Òà R_EQ = 6.23 * T_COUNT à¹×Íè §¨Ò¡àºÊÔ¡ áʵÁ» 2P äÁ ÊÒÁÒö¤íҹdz¨íҹǹ·ÕÁè ·Õ §Ñé àÅ¢¨íҹǹàµçÁáÅÐàÅ¢·È¹ÔÂÁä´ â´ÂµÃ§ ¨Ö§µ ͧ㪠෤¹Ô¤¡ÒáÃШÒ µÑÇàÅ¢ 7.07 ÍÍ¡ÁÒà» ¹Ê Ç¹æ ´Ñ§¹Õé 6.23 = 6 + (2/10) + (3/100) ¨Ò¡¹Ñé ¹ ¨Ö § ¹í Ò ¤ Ò T_COUNT à¢ Ò ä»¤í Ò ¹Ç³ã¹Ê Ç ¹»ÃСͺ¢Í§¤ Ò 6.23 áÅ Ç ¹í Ò ¼Å¤Ù ³ ·Ñé § ËÁ´ ÁÒÃÇÁ¡Ñ¹ ¡ç¨Ðä´ ¼ÅÅѾ¸ ·ÊÕè ÁºÙó ÍÍ¡ÁÒ â»Ãá¡ÃÁ¹Õàé ÃÔÁè µ ¹´ Ç¡ÒûÃШØáç´Ñ¹ãË µÇÑ à¡çº»ÃÐ¨Ø¡Í ¹ â´Â¡ÒÃÊ §¤ Ò 1 ÍÍ¡ä»Âѧ¢Ò P9 ¨Ò¡¹Ñ¹é ˹ ǧ àÇÅÒàÅ硹 ÍÂà¾×Íè ãË µÇÑ à¡çº»ÃШØä´ ÊÐÊÁáç´Ñ¹ ¨Ò¡¹Ñ¹é ¨Ö§¡ÃзíÒ¤íÒÊѧè RCTIME Ê §¼ÅãË à¡Ô´¡ÒäÒ»ÃШآͧµÑÇ à¡çº»ÃШآ¹Öé ¨Ö§àÃÔÁè ·íÒ¡ÒùѺ¤ ÒàÇÅÒ áÅ Ç·íÒ¡Òäíҹdz à¾×Íè ãË ä´ ¤Ò ¤ÇÒÁµ Ò¹·Ò¹·Õµè Í §¡Ò÷ÃÒº¤ Ò ¨Ò¡¹Ñ¹é áÊ´§ ¤ Ò¤ÇÒÁµ Ò¹·Ò¹·Õäè ´ ¼Ò ¹·Ò§Ë¹ Òµ Ò§ Debug Terminal 11.3 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 áÅ ÇÃѹâ»Ãá¡ÃÁ Êѧࡵ¡ÒÃáÊ´§¼Å¢Í§Ë¹ Òµ Ò§ Debug Terminal ¾ºÇ Ò Ë¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¤ ҢͧµÑǵ Ò¹·Ò¹ Rx ·Õµè Í §¡Ò÷ÃÒº¤ Ò ¤ Ò·Õáè Ê´§¤×Í 9603 ¶Ö§ 9650 «Ö§è ¡ç¤Í× ¤ Ò 10k: â´Â»ÃÐÁÒ³ ¶×ÍÇ Òã¡Å à¤Õ§¡Ñº¤ ÒµÑǵ Ò¹·Ò¹·Õãè ª 㹡Ò÷´Åͧ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

##


11.4 ãË ·Òí ¡Ò÷´Åͧà¾ÔÁè àµÔÁ â´Âà»ÅÕÂè ¹µÑǵ Ò¹·Ò¹ 10k: à» ¹ LDR 11.5 㪠ÁÍ× » ´Ë¹ Òµ Ò§¢Í§ LDR Êѧࡵ¤ Ò·Õàè ¡Ô´¢Ö¹é º¹Ë¹ Òµ Ò§ Debug Terminal 11.6 ¨Ò¡¹Ñ¹é àÍÒÁ×ÍÍÍ¡¨Ò¡Ë¹ Òµ Ò§¢Í§ LDR ãË LDR ä´ ÃºÑ áʧ¨Ò¡ÀÒÂã¹Ë ͧ Êѧࡵ¤ Ò·Õàè ¡Ô´¢Ö¹é º¹Ë¹ Òµ Ò§ Debug Terminal 11.7 ¹íÒä¿©ÒÂÊ Í§ä»Âѧ˹ Òµ Ò§¢Í§ LDR Êѧࡵ¤ Ò·Õàè ¡Ô´¢Ö¹é º¹Ë¹ Òµ Ò§ Debug Terminal 11.8 à»ÃÕºà·Õº¼Å¡Ò÷´Åͧ·Õàè ¡Ô´¢Ö¹é ã¹¢ Í 11.6 ¶Ö§ 11.8 ¼Å¡ÒÃà»ÃÕºà·Õº¾ºÇ Ò àÁ×Íè LDR äÁ ä´ ÃºÑ áʧ ¤ Ò¤ÇÒÁµ Ò¹·Ò¹·ÕÇè ´Ñ ä´ ¨ÐÊÙ§ÊØ´ ¤ Ò¤ÇÒÁµ Ò¹·Ò¹ ¨ÐŴŧàÁ×Íè ä´ ÃºÑ áʧÊÇ Ò§»¡µÔ áÅÐŴŧÁÒ¡¢Ö¹é àÁ×Íè ä´ ÃºÑ áʧ¨Ò¡·ÕÁè ¤Õ ÇÒÁࢠÁÁÒ¡¡Ç Òáʧ»¡µÔ

¤ Ò·Õäè ´ àÁ×Íè ºÑ§áʧäÁ ãË µ¡¡Ãзº LDR ¤ Ò·Õäè ´ àÁ×Íè áʧ»¡µÔµ¡¡Ãзº LDR

¤ Ò·Õäè ´ àÁ×Íè LDR ä´ ÃºÑ áʧÁÒ¡

#$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


º··Õè 9

i-Stamp2p24 ¡Ñº¡ÒÃÁÍ´ÙàÅªÑ¹è ·Ò§ ¤ÇÒÁ¡Ç Ò§¢Í§¾ÑÅÊ (PWM) ¾ÑÅÊ ÇÔ´¸ ÁÍ´ÙàŪÑè¹ ËÃ×Í ¡ÒÃÁÍ´Ùàŵ·Ò§¤ÇÒÁ¡Ç Ò§¢Í§¾ÑÅÊ à» ¹¡Ãкǹ¡Ò÷íÒãË à¡Ô´Åͨԡ ÊÙ§ËÃ×ÍÅͨԡ 1 ã¹ÃÐÂÐàÇÅÒ·ÕèÊÒÁÒö¤Çº¤ØÁä´ à¾×èÍ¡íÒ˹´¤ Òáç´Ñ¹·Ò§ÍйÒÅÍ¡â´Â㪠¡Ãкǹ¡Òà ·Ò§´Ô¨µÔ ÍÅ »ÃÐ⪹ ·àÕè Ëç¹ä´ Í ҧªÑ´à¨¹¢Í§¡Ãкǹ¡Òà PWM ¤×Í ¡ÒäǺ¤ØÁ¤ÇÒÁàÃçÇÁÍàµÍà 俵ç «Ö§è ã¹ Í´Õµµ ͧ㪠ǧ¨Ã¢ÂÒÂàªÔ§àÊ ¹·ÕÁè ÃÕ Ò¤Òᾧà¾×Íè ¨ ÒÂáç´Ñ¹ãË á¡ ¢´ÅÇ´¢Í§ÁÍàµÍà ᵠàÁ×Íè ¹íÒÁÒ㪠¡Ãкǹ¡Òà PWM ¨Ðà¡Ô´¡ÒáÃеع ãË Ç§¨Ã¢Ñº«Ö§è ÀÒÂã¹ÍҨ໠¹·ÃÒ¹«ÔÊàµÍà ËÃ×ÍÁÍÊ࿵·íҧҹ໠¹ª ǧàÇÅÒÍ ҧÁÕÊ´Ñ Ê Ç¹ ¡µÑÇÍ ҧ ËÒ¡» ͹áç´Ñ¹ +12V ãË á¡ Ç§¨Ã¢ÑºÁÍàµÍà «Ö§è ¤Çº¤ØÁãË ·Òí §Ò¹´ Ç PWM ·ÃÒ¹«ÔÊàµÍà ¨Ð·íÒ §Ò¹ã¹ÍѵÃÒ 25, 50 ËÃ×Í 75% ¢Í§¤ÒºàÇÅÒÃÇÁ ·íÒãË à¡Ô´áç´Ñ¹µ¡¤Ã ÍÁ·Õâè ËÅ´ 3, 6 áÅÐ 9V µÒÁÅíҴѺ ã¹ÃÙ»·Õè 9-1 áÊ´§¤ÇÒÁÊÑÁ¾Ñ¹¸ ¢Í§¤ÇÒÁ¡Ç Ò§¾ÑÅÊ ËÃ×ͤ Ò´ÔǵÕäé «à¡ÔÅ·ÕÁè µÕ Í ¤ Òáç´Ñ¹ ¶ ÒËÒ¡¤ Ò´ÔǵÕäé «à¡ÔÅ ËÃ×ͤҺàÇÅÒ·Õàè ¡Ô´ÃдѺáç´Ñ¹ÊÙ§ÁÕ¤Ò ÁÒ¡ áç´Ñ¹àÍÒµ ¾µØ ¢Í§Ç§¨Ã PWM ¡ç¨ÐÊÙ§ ã¹·Ò§µÃ§¢ ÒÁ¶ Ò¤ Ò´ÔǵÕäé «à¡ÔŵèÒí áç´Ñ¹àÍÒµ ¾µØ ¡ç¨ÐÁÕ¤Ò ¹ ͵ÒÁ ¹Ñ¹è ËÁÒ¤ÇÒÁÇ Ò ¡Ãкǹ¡Òà PWM à» ¹¡ÒÃÊà ҧáç´Ñ¹â´Â¡ÒûÃѺ¤ Ò´ÔǵÕé ä«à¡ÔŢͧÊÑ­­Ò³¾ÑÅÊ áÅзÕàè ÍÒµ ¾µØ ¢Í§Ç§¨Ã PWM ÁÑ¡¨Ðµ Íǧ¨Ã¡Ãͧ¤ÇÒÁ¶Õµè Òèí ¼ Ò¹à¾×Íè Å´ÊÑ­­Ò³Ãº¡Ç¹ ¤ÇÒÁ¶ÕÊè §Ù áÅзíÒãË áç´Ñ¹ÍйÒÅÍ¡·Õàè ÍÒµ ¾µØ ¹Ñ¹é ÁÕ¤Ò ·Õ¤è §·Õáè ¹ ¹Í¹ÁÒ¡¢Ö¹é ´ Ç ÊíÒËÃѺǧ¨Ã¡Ãͧ¶ÇÒÁ¶Õµè Òèí ¼ Ò¹ ÁÕµÇÑ Í ҧǧ¨ÃáÊ´§ã¹ÃÙ»·Õè 9-2

(¡)

Vout = 20% x 5V = 1.0V

(¢) #

Vout = 50% x 5V = 2.5V

(¤) &

Vout = 80% x 5V = 4.0V

ÃÙ»·Õè 9-1 áÊ´§¤ÇÒÁÊÑÁ¾Ñ¹¸ ¢Í§¤ÇÒÁ¡Ç Ò§¢Í§¾ÑÅÊ ¡ºÑ áç´Ñ¹àÍÒµ ¾µØ Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#%


¢Ò¾Íà µ¢Í§ àºÊÔ¡áʵÁ» 2SX

1k

1k

àÍÒµ ¾Øµ 0.1/50V

0.1/50V

ÃÙ»·Õè 9-2 ǧ¨Ã¡Ãͧ¤ÇÒÁ¶Õµè Òèí ¼ Ò¹·Õãè ª 㹡ÒÃÅ´ÊÑ­­Ò³¤ÇÒÁ¶ÕÊè §Ù ·Õàè ¡Ô´¨Ò¡¡Ãкǹ¡Òà PWM

9.1 á¹Ç¤Ô´¢Í§ PWM ¡Ãкǹ¡ÒÃà¡Ô´ÊÑ­­Ò³ PWM ¨ÐÍÒÈÑ¡ÒÃà¡Ô´âÍàÇÍà â¿ÅǢͧµÑǹѺ¢¹Ò´ 8 ºÔµ »¡µÔµÇÑ ¹Ñº¨ÐÁÕ ¤ Ңͧ¢ ÍÁÙŷѧé ËÁ´ 256 ¤ Ò¤×Í 0-255 àÁ×Íè ¤ ҢͧµÑǹѺà»ÅÕÂè ¹¨Ò¡ 255 ËÃ×Í $FF ÁÒà» ¹ 00 ¹Ñ¹è ¤×Í¡ÒÃà¡Ô´ âÍàÇÍà â¿ÅÇ ·íÒãË à¡Ô´Åͨԡ 1 ¢Ö¹é ¶ ÒËÒ¡¡ÒÃà¡Ô´âÍàÇÍà â¿ÅÇÁÕÁÒ¡áÅÐàÃçÇ¢Ö¹é à· Òã´ ¡ç¨Ð·íÒãË à¡Ô´Åͨԡ 1 Í ҧµ Íà¹×Íè §ÁÒ¡¢Ö¹é ෠ҹѹé â´ÂÍѵÃÒ¡ÒÃà¡Ô´âÍàÇÍà â¿ÅǨТֹé ÍÂÙ¡ ºÑ µÑÇá»Ã¢¹Ò´ 8 ºÔµÍÕ¡µÑÇË¹Ö§è ´Ñ§¹Ñ¹é µÑÇá»Ã¹Õ¨é §Ö ¹íÒÁÒ㪠㹡ÒáíÒ˹´¤ Ò´ÔǵÕäé «à¡ÔŢͧÊÑ­­Ò³¾ÑÅÊ â´Âã¹·Õ¹è ¤Õé Í× DUTY ¶ Ò¤ Ò DUTY à» ¹ 0 ·íÒãË äÁ à¡Ô´¡ÒÃâÍàÇÍà â¿ÅÇ àÍÒµ ¾µØ ¨Ö§à» ¹ÅͨԡµèÒí áç´Ñ¹àÍÒµ ¾µØ ෠ҡѺ 0V ¶ ÒËÒ¡¡íÒ˹´¤ Ò DUTY = 1 ·íÒãË à¡Ô´âÍàÇÍà â¿ÅÇ 1 ¤ÃÑ§é ¨Ò¡¨íҹǹ·Ñ§é ËÁ´ 256 ¤Ãѧé à¹×Íè §¨Ò¡ µÑÇá»Ã·Õè㪠㹡ÒáíÒ˹´¡ÒÃà¡Ô´âÍàÇÍà â¿ÅÇ («Ö觡ç¤×Í DUTY) ÁÕ¢¹Ò´ 8 ºÔµ ¤ Ò´ÔǵÕéä«à¡ÔŨ֧෠ҡѺ 1/256 N 100% = 0.39% áç´Ñ¹àÍÒµ ¾µØ ¨Ö§ÁÕ¤Ò à· Ò¡Ñº 0.39% N 5V = 0.0195V ËÃ×Ͷ ÒËÒ¡¡íÒ˹´ãË DUTY = 255 à¡Ô´¡ÒÃâÍàÇÍà â¿ÅÇÊÙ§¶Ö§ 255 ¤ÃÑ§é ¤ Ò´ÔǵÕäé «à¡ÔŨ֧à¾ÔÁè ¢Ö¹é à» ¹ 255/256 N 100% = 99.6% áç´Ñ¹àÍÒµ ¾µØ ¨Ö§à· ҡѺ 99.6% N 5V = 4.98V ¡ÒÃà¢Õ¹â»Ãá¡ÃÁ¾ÕàºÊÔ¡à¾×Íè Êà ҧÊÑ­­Ò³ PWM ÊÒÁÒö㪠¡ÒÃà¡Ô´âÍàÇÍà â¿ÅǢͧµÑǹѺ¢¹Ò´ 8 ºÔµ â´ÂÁÕµÇÑ á»Ã¢¹Ò´ 8 ºÔµÍÕ¡µÑÇË¹Ö§è ·íÒ¡ÒäǺ¤ØÁ «Ö§è ÇÔ¸¡Õ Òùըé зíÒãË ¢¹Ò´¢Í§â»Ãá¡ÃÁÍÒ¨ÂÒǾÍÊÁ¤Çà ᵠáÊ´§ãË àË繶֧¡Ãкǹ¡ÒÃà¡Ô´¢Ö¹é ¢Í§ÊÑ­­Ò³ PWM Í ҧªÑ´à¨¹ Í ҧäáç´Õ i-Stamp2P24 ÁÕ¤Òí Êѧè PWM ÊíÒËÃѺÊà ҧÊÑ­­Ò³ PWM ÍÂÙá Å Ç ·íÒãË ÊÒÁÒöÊà ҧÊÑ­­Ò³ PWM ä´ Í ҧ§ Ò´ÒÂ

9.2 ¤íÒÊѧè PWM i-Stamp2P24 ÁÕ¤Òí Êѧè PWM ÊíÒËÃѺÊà ҧÊÑ­­Ò³ PWM â´Â੾ÒÐ â´ÂÁÕû٠Ẻ¢Í§¤íÒÊÑ§è ´Ñ§¹Õé PWM pin, duty, cycles

â´Â·Õè pin ¤×Í ¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õµè Í §¡ÒÃãË Ê­ Ñ ­Ò³ PWM ¶Ù¡Ê §ÍÍ¡ÁÒ duty ¤×Í ¤ ҢͧµÑÇá»ÃÁÕ¤Ò 0 ¶Ö§ 255 à» ¹µÑÇ¡íÒ˹´¤ Ò´ÔǵÕäé «à¡ÅԢͧÊÑ­­Ò³ PWM cycles ¤×Í ¤ ҢͧµÑÇá»Ã¡íÒ˹´¤ÒºàÇÅҢͧÊÑ­­Ò³ PWM ÁÕ˹ ÇÂà» ¹ 650 äÁâ¤ÃÇÔ¹Ò·Õ àÁ×Íè 㪠¤Òí Êѧè PWM ¨Ð·íÒãË â»Ãá¡ÃÁÊíÒËÃѺÊà ҧÊÑ­­Ò³ PWM ÁÕ¢¹Ò´àÅç¡Å§Í ҧÁÒ¡

#&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ·Õè 12 ¡ÒÃ㪠§Ò¹¤íÒÊѧè PWM à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 510: 1 µÑÇ 5. LED ÊÕá´§ 1 µÑÇ

¡Ò÷´Åͧ

¡Ò÷´Åͧ㪠¤Òí Êѧè PWM ¤Çº¤ØÁ¤ÇÒÁÊÇ Ò§¢Í§ LED 12.1 㪠ǧ¨Ãã¹ÃÙ»·Õè L12-1 㹡Ò÷´Åͧ â´Âµ Íǧ¨Ãŧº¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ 12.2 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB1201.BSP '********************************************************** ' Program : LAB1201.BSP ' Description : Twinkle Light with PWM command ' FOR : i-Stamp2P24 ' Hardware : Connect LED TO P0 '********************************************************** ' {$STAMP BS2p} ' {$PBASIC 2.5} DUTY VAR Byte CYCLES VAR Byte DIRS = $00FF CYCLES = 100 MAIN: DEBUG "." FOR DUTY = 0 TO 20 STEP 2 PWM 0,DUTY,CYCLES NEXT FOR DUTY = 20 TO 0 STEP 2 PWM 0,DUTY,CYCLES NEXT GOTO MAIN

' Increase the brightness ' Decrease the brightness

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

#'


P0

510

LED

i-Stamp2P24

ÃÙ»·Õè L12-1 ǧ¨Ã·´ÅͧÊà ҧÊÑ­­Ò³ PWM 12.3 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 áÅ ÇÃѹâ»Ãá¡ÃÁ Êѧࡵ¡ÒÃáÊ´§¼Å¢Í§Ë¹ Òµ Ò§ Debug Terminal áÅСÒ÷íÒ§Ò¹¢Í§ LED ¾ºÇ Ò ·ÕËè ¹ Òµ Ò§ Debug Terminal ¨ÐáÊ´§¨Ø´ à¾×Íè á·¹¨íҹǹÃͺ¡Ò÷íÒ§Ò¹¢Í§ PWM ã¹¢³Ð·Õè LED ¡ç¨ÐÊÇ Ò§-ËÃÕ-è ´Ñº-ËÃÕ-è ÊÇ Ò§ ǹÍÂÙà ª ¹¹Õäé »µÅÍ´

¡Ò÷´Åͧ¢Ñº¤ÇÒÁÊÇ Ò§¢Í§ LED ´ Ç PWM â´Â¡Òá´ÊÇÔµª 12.3 㪠ǧ¨Ãã¹ÃÙ»·Õè L12-2 㹡Ò÷´Åͧ â´Âµ Íǧ¨Ãŧº¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ 12.4 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB1202.BSP +5V

R1 10k

R2 10k P8 P9

S1 DEC

P0

510

LED

i-Stamp2P24

S2 INC

ÃÙ»·Õè L12-2 ǧ¨Ã·´Åͧ¤Çº¤ØÁ¤ÇÒÁÊÇ Ò§¢Í§ LED ´ Ç¡Ãкǹ¡Òà PWM â´Â㪠ÊÇÔµª

$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


'******************************************************************************************************************* ' Program : LAB1202.BSP ' Description : Light Dimmer ' Hardware : Connect LED TO P0, Connect active LOW switch "INC" TO P9 and connect switch "DEC" TO P8 '******************************************************************************************************************** ' {$STAMP BS2P} ' {$PBASIC 2.5} LED_STEP VAR Byte ' Define Byte variable TO keep current STEP SW_VAR1 VAR Byte ' Define Byte variable TO use with BUTTON SW_VAR2 VAR Byte ' Define Byte variable TO use with BUTTON INPUT 8 ' Make P8 as INPUT INPUT 9 ' Make P9 as INPUT OUTPUT 0 ' Make P0 as OUTPUT LED_STEP=0 ' Clear state TO 0 LOOP1: PWM 0,LED_STEP,5 BUTTON 8,0,50,10,SW_VAR1,1,DEC_LIGHT BUTTON 9,0,50,10,SW_VAR2,1,INC_LIGHT GOTO LOOP1 DEC_LIGHT: IF LED_STEP=0 THEN LOOP1 ' Check MIN value LED_STEP=LED_STEP-1 ' Decrease brightness GOTO LOOP1 ' GOTO LOOP1 INC_LIGHT: IF LED_STEP=255 THEN LOOP1 ' Check MAX value LED_STEP=LED_STEP+1 ' Increase brightness GOTO LOOP1 ' GOTO LOOP1

¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ ã¹â»Ãá¡ÃÁ¹Õ¡é Òí ˹´¾ÒÃÒÁÔàµÍà ¢Í§¤íÒÊѧè PWM ´ Ç¡Òá´ÊÇÔµª 2 µÑÇ «Ö§è µ ͡Ѻ P8 áÅÐ P9 ¤ Ò·Õàè ¡Ô´ ¨Ò¡¡Òá´ÊÇÔµª ¨Ðà¡çºäÇ ã¹µÑÇá»Ã LED_STEP ¤ ҢͧµÑÇá»Ã LED_STEP ¨Ðà»ÅÕè¹á»Å§´ ÇÂâ»Ãá¡ÃÁ Í DEC_LIGHT áÅÐ INC_LIGHT àÁ×Íè ¡´ÊÇÔµª ·Õè P8 i-Stamp2P24 ¨Ð¡ÃÐâ´´ÁÒ·íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í DEC_LIGHT à¾×èÍÅ´¤ Ò´ÔǵÕéä«à¡ÔŢͧÊÑ­­Ò³ PWM ·íÒãË ¤ÇÒÁÊÇ Ò§¢Í§ LED Ŵŧ áµ ¶ Ò¡´ÊÇÔµª ·Õè P9 i-Stamp2P24 ¨Ð¡ÃÐâ´´ÁÒ·íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í INC_LIGHT à¾×Íè à¾ÔÁè ¤ Ò´ÔǵÕäé «à¡ÔÅ ·íÒãË ¤ÇÒÁÊÇ Ò§¢Í§ LED à¾ÔÁè ¢Ö¹é 12.5 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 áÅ ÇÃѹâ»Ãá¡ÃÁ Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED 12.6 ¡´ÊÇÔµª S1 áÅÐ S2 áÅ ÇÊѧࡵ¡Ò÷íÒ§Ò¹ LED àÁ×Íè ¡´ÊÇÔµª ·§Ñé ÊͧµÑÇ Á×Íè ¡´ÊÇÔµª S2 LED ¨ÐÊÇ Ò§à¾ÔÁè ÁÒ¡¢Ö¹é ã¹·Ò§µÃ§¢ ÒÁËÒ¡¡´ÊÇÔµª S1 LED ¨ÐËÃÕÅè § áÅж Ò¡´ ÊÇÔµª ¤Ò §äÇ ¡¨ç зíÒ§Ò¹µ Íà¹×Íè § ઠ¹ ¶ Ò¡´ S1 ¤ Ò§äÇ LED ¡ç¨ÐËÃÕÅè §Í ҧµ Íà¹×Íè §¨¹´Ñº ËÃ×Í¡´ÊÇÔµª S2 ¤ Ò§äÇ LED ¡ç¨ÐÊÇ Ò§à¾ÔÁè ¢Ö¹é ¨¹ÊÇ Ò§àµçÁ·Õè

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$


$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


º··Õè 10

i-Stamp2p24 ¡Ñº¡ÒâѺà«Íà âÇÁÍàµÍà à«Íà âÇÁÍàµÍà (servo motor) à» ¹ÁÍàµÍÃ ä¿µÃ§áººË¹Ö§è ·Õ·è Òí §Ò¹´ ÇÂÊÑ­­Ò³¾ÑÅÊ ÁÕÊÒµ Í 3 àÊ ¹ ¤× Í ä¿àÅÕé§ ¡ÃÒÇ´ áÅÐÊÒÂÃѺÊÑ­­Ò³ ÀÒÂã¹à«Íà â ÇÁÍàµÍà ¨ ÐÁÕ Ç §¨ÃÍÔ à Åç ¡ ·ÃÍ¹Ô ¡ Ê º ÃÃ¨Ø Í ÂÙ à¾×Íè ¤Çº¤ØÁ¡Ò÷íÒ§Ò¹ ¡ÒäǺ¤ØÁ¤ÇÒÁàÃçǨÐÁÒ¨Ò¡ÅѡɳТͧÊÑ­­Ò³¾ÑÅÊ ·»Õè Í ¹à¢ Òä»ÂѧÊÒÂÃѺÊÑ­­Ò³ ã¹ÃÙ»·Õè 10-1 áÊ´§Ë¹ ÒµÒáÅÐÊ Ç¹»ÃСͺ¢Í§à«Íà âÇÁÍàµÍà à«Íà âÇÁÍàµÍà ໠¹ÍØ»¡Ã³ áÁ àËÅç¡ä¿¿ ÒẺ˹Ö觷Õè㪠㹡ÒÃËÁعµÑǢѺ (actuator) ä»ÂѧµíÒá˹ § µ Ò§æ ´ ǤÇÒÁáÁ ¹ÂíÒ â´Â㪠ʭ Ñ ­Ò³¾ÑÅÊ à¾×Íè ¡íÒ˹´µíÒá˹ §ã¹¡ÒÃËÁع ÁÑ¡¹ÔÂÁ㪠öºÑ§¤ÑºÇÔ·ÂØ à¤Ã×Íè § ºÔ¹ºÑ§¤ÑºÇÔ·ÂØ ËÃ×Í㪠¤Çº¤ØÁᢹ¢Ò¢Í§Ëع ¹µ ã¹ÂؤáÃ¡æ ¢Í§¡ÒþѲ¹Òà«Íà âÇÁÍàµÍà ¨Ð¶Ù¡¹íÒÁÒ㪠㹠§Ò¹ÇÔ·Âغ§Ñ ¤Ñºà» ¹ËÅÑ¡ ¨Ö§àÃÕ¡à«Íà âÇÁÍàµÍà Ẻ¹ÕÇé Ò R/C à«Íà âÇÁÍàµÍà »¡µÔáÅ Çà«Íà âÇÁÍàµÍà ·ÕèÂѧäÁ ä´ ÃѺ¡ÒûÃѺᵠ§ã´æ ¹Ñ鹨Ð㪠§Ò¹¡Ñ¹ÍÂÙ ã¹Ã¶, àÃ×Í ËÃ×Íà¤Ã×èͧºÔ¹ ºÑ§¤ÑºÇÔ·ÂØ à¾×Íè ·íÒ˹ Ò·Õ¤è Ǻ¤ØÁµíÒá˹ §¢Í§ÍØ»¡Ã³ ઠ¹ ¡Òúѧ¤ÑºàÅÕÂé ǢͧöºÑ§¤ÑºÇÔ·ÂØ ËÃ×Í㪠ÊÒí ËÃѺ»ÃѺ ËÒ§àÊ×ͧ͢àÃ×ÍËÃ×Íà¤Ã×Íè §ºÔ¹ «Ö§è §Ò¹àËÅ Ò¹Õµé Í §¡ÒÃáçºÔ´¢Í§ÁÍàµÍà ·ÊÕè §Ù ¾ÍÊÁ¤Çà ´Ñ§¹Ñ¹é à«Íà âÇÁÍàµÍà ¨Ö§ÁÕÍѵÃÒ·´·ÕèÁÒ¡¾ÍÊÁ¤ÇÃà¾×èÍãË ÊÒÁÒöÃͧÃѺ§Ò¹´Ñ§¡Å ÒÇä´ à«Íà âÇÁÍàµÍà ÁÁÕ ÁØ ã¹¡ÒÃËÁعµÑ§é áµ 0 ¶Ö§ 90 ͧÈÒ ¨¹¶Ö§ 0 ¶Ö§ 180 ͧÈÒ ¢Ö¹é ÍÂÙ¡ ºÑ ¼Ù¼ ÅÔµ » ¨¨Øº¹Ñ ¹ÔÂÁẺ 0 ¶Ö§ 180 ͧÈÒ «Ö§è ÊÒÁÒö´Ñ´á»Å§ãË ËÁØ¹ä´ ¤Ãº 360 ͧÈÒ´ ÇÂ

10.1 â¤Ã§Êà ҧ¢Í§à«Íà âÇÁÍàµÍà ÀÒÂã¹à«Íà âÇÁÍàµÍà »ÃСͺ´ Ç ÁÍàµÍà ¡ÃÐáʵç ªØ´à¿ ͧ¢ÑºÁÍàµÍà áÅÐǧ¨Ã¢ÑºÁÍàµÍà ·Õè ÁÕǧ¨Ã» ͹¡ÅѺ à¾×Íè ãË à«Íà âÇÁÍàµÍÃ ÃºÑ ÃÙµ Òí á˹ §¢Í§µÑÇàÍ§ä´ â´Â¼Ùã ª §Ò¹à¾ÕÂ§Ê §ÊÑ­­Ò³¾ÑÅÊ ÍÍ¡ä» ¤Çº¤ØÁà· Ò¹Ñ¹é ´Ñ§áÊ´§ä´ÍÐá¡ÃÁ¡Ò÷íÒ§Ò¹¢Í§à«Íà âÇÁÍàµÍà ã¹ÃÙ»·Õè 10-2

(¡)

(¢)

(¤)

ÃÙ»·Õè 10-1 áÊ´§Ãٻà ҧáÅÐÊ Ç¹»ÃСͺ¢Í§à«Íà âÇÁÍàµÍà (¡) Ãٻà ҧÀÒ¹͡ (¢) Ãкºà¿ ͧ·´ÀÒÂã¹ (¤) ἧǧ¨ÃÍÔàÅç¡·ÃÍ¹Ô¡Ê ·ãÕè ª ¤Çº¤ØÁ Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$!


ÊÑ­­Ò³¤Çº¤ØÁ

+error

+ ǧ¨Ã¢Ñº ÁÍàµÍÃ

à»ÃÕºà·Õº ¼Åµ Ò§

-error

M o to r

-

ǧ¨ÃÊà ҧ¾ÑÅÊ Í Ò§ÍÔ§ ࿠ͧ¢ÑºÁÍàµÍÃ

ÃÙ»·Õè 10-2 áÊ´§ä´ÍÐá¡ÃÁ¡Ò÷íÒ§Ò¹¢Í§à«Íà âÇÁÍàµÍà à«Íà âÇÁÍàµÍà ·¹Õè Òí ÁÒ㪠§Ò¹ã¹º·¹Õàé » ¹ R/C à«Íà âÇÁÍàµÍà ·¹Õè ÂÔ Á㪠ã¹Ëع ¹µ ¢¹Ò´àÅç¡ ÁÕÊÒµ Í ãª §Ò¹ 3 àÊ ¹¤×Í ÊÒÂÊÑ­­Ò³ (S : SIGNAL) ÊÒÂä¿àÅÕÂé § (+V) áÅСÃÒÇ´ (G) ´Ñ§ã¹ÃÙ»·Õè 10-3 ÊÒÂÊÑ­­Ò³ »¡µÔ¨ÐÁÕÊ¢Õ ÒÇ ÊÒÂä¿àÅÕÂé §«Ö§è ÁÕÃдѺáç´Ñ¹µÑ§é áµ 4.8 ¶Ö§ 6V »¡µÔ¨Ðà» ¹ÊÒÂÊÕá´§ áÅÐÊÒ¡ÃÒÇ´ »¡µÔ¨Ðà» ¹ ÊÒÂÊÕ´Òí Ê Ç¹ã¹ÃÙ»·Õè 10-4 áÊ´§ÅѡɳТͧ¤Í¹à¹ç¡àµÍà ·ãÕè ª 㹡ÒÃàª×Íè Áµ ͧ͢à«Íà âÇÁÍàµÍà ÁÕ´Ç Â¡Ñ¹ 2 Áҵðҹ¤×Í áºº S áÅÐẺ J ¡ÒèѴ¢Ò¨ÐàËÁ×͹¡Ñ¹ ¤ÇÒÁᵡµ Ò§¤×Í ÅѡɳТͧ¤Í¹à¹ç¡àµÍà áÅСÒáíÒ˹´ ÊբͧÊÒÂÊÑ­­Ò³ ÊíÒËÃѺÂÕËè Í Futaba ¢Í§­Õ»è ¹Ø ¡íÒ˹´ãË áºº J ÁÕ»¡ Â×¹è ÍÍ¡ÁÒà¾ÔÁè ¢Ö¹é ã¹´ Ò¹à´ÕÂǡѺÊÒÂÊÑ­­Ò³ áÅСíÒ˹´ãË ÊÒÂÊÑ­­Ò³ÁÕÊ¢Õ ÒÇ Ê Ç¹áºº S ÊÒÂÊÑ­­Ò³¨Ðà» ¹ÊÕàËÅ×ͧáÅФ͹à¹ç¡àµÍà ¨ÐàÃÕºàËÁ×͹¡Ñ¹ ·Ñ§é Êͧ´ Ò¹¢Í§ÊÒÂàª×Íè Áµ Í Ê Ç¹ÊÒÂä¿àÅÕÂé §à» ¹ÊÕá´§ áÅÐÊÒ¡ÃÒÇ´ à» ¹ÊÕ´Òí àËÁ×͹¡Ñ¹·Ñ§é ÊͧẺ Í ҧäáçµÒÁ ÁÕ¤ÇÒÁà» ¹ä»ä´ ·Õè¼Ù ¼ÅÔµÍ×è¹æ ÍÒ¨¡íÒ˹´ÃٻẺáÅÐÊբͧÊÒÂÊÑ­­Ò³áµ¡µ Ò§ÍÍ¡ ä» áµ ¡ÒèѴàÃÕ§µíÒá˹ §ÊÑ­­Ò³àËÁ×͹¡Ñ¹

10.2 ÃٻẺÊÑ­­Ò³·Õãè ª ¤Çº¤ØÁà«Íà âÇÁÍàµÍà ¡ÒäǺ¤ØÁà«Íà âÇÁÍàµÍà ·Òí ä´ â´ÂÊà ҧÊÑ­­Ò³¾ÑÅÊ »Í ¹ãË ¡ºÑ ǧ¨Ã¤Çº¤ØÁÀÒÂã¹à«Íà âÇÁÍàµÍà ´Ñ§ÃÙ» ·Õè 10-5 àÃÔÁè µ ¹ãË Êà ҧ¾ÑÅÊ ·ÁÕè ¤Õ ÒºàÇÅÒ෠ҡѺ 20 ÁÔÅÅÔÇ¹Ô Ò·Õ áÅ Ç»ÃѺ¤ÇÒÁ¡Ç Ò§¢Í§¾ÑÅÊ ªÇ §ºÇ¡ â´Â¾ÑÅÊ ¡Ç Ò§ 1 ÁÔÅÅÔÇ¹Ô Ò·Õ ÁÍàµÍà ¨ÐËÁع仵íÒá˹ §« ÒÂÁ×ÍÊØ´ ¶ ÒÊ §¾ÑÅÊ ¡Ç Ò§ 1.5 ÁÔÅÅÔÇ¹Ô Ò·Õ á¡¹ËÁع¢Í§ÁÍàµÍà ¨Ðà¤Å×Íè ¹ ·Õäè »ÂѧµíÒá˹ §¡Ö§è ¡ÅÒ§ áÅж ÒÊ §¾ÑÅÊ 2 ÁÔÅÅÔÇ¹Ô Ò·Õ á¡¹ËÁع¢Í§ÁÍàµÍà ¨Ðà¤Å×Íè ¹·Õäè »ÂѧµíÒá˹ §¢ÇÒÁ×ÍÊØ´

(¡) ¤Í¹à¹ç¡àµÍà Ẻ S (¢) ¤Í¹à¹ç¡àµÍà Ẻ J

ÃÙ»·Õè 10-3 ÅѡɳÐÊÒÂÊÑ­­Ò³¢Í§à«Íà âÇÁÍàµÍà ÃÙ»·Õè 10-4 ÅѡɳФ͹à¹ç¡àµÍà ¢Í§à«Íà âÇÁÍàµÍà $"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Òû ͹ÊÑ­­Ò³¾ÑÅÊ ·ÁÕè ¤Õ ÒºàÇÅÒª ǧºÇ¡µÑ§é áµ 1.5 ¶Ö§ 2 ÁÔÅÅÔÇ¹Ô Ò·Õ¨Ð·íÒãË à«Íà âÇÁÍàµÍà ËÁع·Ç¹ à¢çÁ¹ÒÌ ¡Ò â´Â¶ Ò¤ Ò¤ÇÒÁ¡Ç Ò§¾ÑÅÊ Â§Ôè Ë Ò§¨Ò¡ 1.5 ÁÔÅÅÔÇ¹Ô Ò·ÕÁÒ¡à· Òã´ ¤ÇÒÁàÃçÇ㹡ÒÃËÁع¡ç¨ÐÁÒ¡¢Ö¹é à· Ò¹Ñ¹é ¹Ñ¹è ¤×Í ¤ÇÒÁàÃçÇÊÙ§ÊØ´¢Í§¡ÒÃËÁع·Ç¹à¢çÁ¹ÒÌ ¡Ò¨Ðà¡Ô´¢Ö¹é àÁ×Íè ÊÑ­­Ò³¾ÑÅÊ ¤Çº¤ØÁ·Õ¤è ÇÒÁ¡Ç Ò§ 2 ÁÔÅÅÔÇ¹Ô Ò·Õ ¡Òû ͹ÊÑ­­Ò³¾ÑÅÊ ·ÁÕè ¤Õ ÒºàÇÅÒª ǧºÇ¡µÑ§é áµ 1 仨¹¶Ö§ 1.5 ÁÔÅÅÔÇ¹Ô Ò·Õ ·íÒãË à«Íà âÇÁÍàµÍà ËÁع µÒÁà¢çÁ¹ÒÌ ¡Ò «Ö§è ¶ Ò¤ Ò¤ÇÒÁ¡Ç Ò§¾ÑÅÊ à¢ Òã¡Å 1 ÁÔÅÅÔÇ¹Ô Ò·Õ¤ÇÒÁàÃçÇ㹡ÒÃËÁع¢Í§à«Íà âÇÁÍàµÍà ¡¨ç ÐÁÒ¡ ¹Ñ¹è ¤×Í ¤ÇÒÁàÃçÇÊÙ§ÊØ´¢Í§¡ÒÃËÁعµÒÁà¢çÁ¹ÒÌ ¡Ò¨Ðà¡Ô´¢Ö¹é àÁ×Íè ÊÑ­­Ò³¾ÑÅÊ ¤Çº¤ØÁ·Õ¤è ÇÒÁ¡Ç Ò§ 1 ÁÔÅÅÔÇ¹Ô Ò·Õ ¾ÑÅÊ ¡Ç Ò§ 1 ¶Ö§ 2 ÁÔÅÅÔÇ¹Ô Ò·Õ

¤ÒºàÇÅÒ 20 ÁÔÅÅÔÇ¹Ô Ò·Õ

(¡) ÅѡɳТͧÊÑ­­Ò³¾ÑÅÊ ·Õè㪠㹡ÒäǺ¤ØÁà«Íà âÇÁÍàµÍÃ

¾ÑÅÊ ¡Ç Ò§ 1 ÁÔÅÅÔÇ¹Ô Ò·Õ

(¢) ÊÑ­­Ò³¾ÑÅÊ ¡Ç Ò§ 1 ÁÔÅÅÔÇÔ¹Ò·Õ ·íÒãË ÁÍàµÍà ¢ºÑ ᡹ËÁعä»Âѧ µíÒá˹ §« ÒÂÊØ´

SERVO MOTOR 6Vdc

¾ÑÅÊ ¡Ç Ò§ 1.5 ÁÔÅÅÔÇ¹Ô Ò·Õ

(¤) ÊÑ­­Ò³¾ÑÅÊ ¡Ç Ò§ 1.5 ÁÔÅÅÔÇÔ¹Ò·Õ ·íÒãË ÁÍàµÍà ¢ºÑ ᡹ËÁع仡Ö觡ÅÒ§

SERVO MOTOR 6Vdc

¾ÑÅÊ ¡Ç Ò§ 2 ÁÔÅÅÔÇ¹Ô Ò·Õ

(§) ÊÑ­­Ò³¾ÑÅÊ ¡Ç Ò§ 2 ÁÔÅÅÔÇÔ¹Ò·Õ ·íÒãË ÁÍàµÍà ¢ºÑ ᡹ËÁعä»Âѧ µíÒá˹ §¢ÇÒÊØ´

SERVO MOTOR 6Vdc

ÃÙ»·Õè 10-5 áÊ´§¾ÑÅÊ ·ãÕè ª ¤Çº¤ØÁà«Íà âÇÁÍàµÍà Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$#


10.3 ¤Ø³ÊÁºÑµ·Ô ҧ෤¹Ô¤·ÕÊè Òí ¤Ñ­¢Í§à«Íà âÇÁÍàµÍà ÁÕ 2 ¤ Ò¤×Í ¤ÇÒÁàÃçÇ (speed) áÅÐ áçºÔ´ËÃ×Í·Íà ¤ (torque) ¤ÇÒÁàÃçÇËÁÒ¶֧ ÃÐÂÐàÇÅÒ·Õ·è Òí ãË á¡¹ ËÁع¢Í§ÁÍàµÍà à¤Å×Íè ¹·ÕÊè µÙ Òí á˹ §ÁØÁ·Õ¡è Òí ˹´ ÍÒ·Ô à«Íà âÇÁÍàµÍà Á¤Õ ÇÒÁàÃçÇ 0.15 ÇÔ¹Ò·ÕÊÒí ËÃѺ 60 ͧÈÒ ËÁÒ¶֧ à«Íà âÇÁÍàµÍà µÇÑ ¹ÕÊé ÒÁÒö¢ÑºãË á¡¹ËÁعà¤Å×Íè ¹·Õäè »ÂѧµíÒá˹ §ÁØÁ 60 ͧÈÒÀÒÂã¹àÇÅÒ 0.15 ÇÔ¹Ò·Õ Ê Ç¹áçºÔ´ÁÑ¡¨Ð»ÃÒ¡¯ã¹Ë¹ Ç¢ͧÍ͹« -¹ÔÇé (ounce-inches : oz-in) ËÃ×Í ¡ÔâÅ¡ÃÑÁ-ૹµÔàÁµÃ (kgcm) à» ¹¤Ø³ÊÁºÑµ·Ô ¨Õè к͡µ ͼÙã ª §Ò¹Ç Ò à«Íà âÇÁÍàµÍà µÇÑ ¹ÕÁé áÕ Ã§ã¹¡ÒâѺâËÅ´·ÕÁè ¹Õ Òéí ˹ѡã¹Ë¹ ÇÂÍ͹« ãË ÊÒÁÒöà¤Å×Íè ¹·Õäè »ä´ 1 ¹ÔÇé ËÃ×͹éÒí ˹ѡã¹Ë¹ Ç¡ÔâÅ¡ÃÑÁãË à¤Å×Íè ¹·Õäè »ä´ 1 ૹµÔàÁµÃ (¹éÒí ˹ѡ 1 Í͹« ෠ҡѺ 0.028 ¡ÔâÅ¡ÃÑÁâ´Â»ÃÐÁÒ³ ËÃ×Í 1 ¡ÔâÅ¡ÃÑÁ෠ҡѺ 35.274 Í͹« ) Í ҧäáçµÒÁ ¤ Ңͧ¤ÇÒÁàÃçÇáÅÐáçºÔ´µ ͧÊÑÁ¾Ñ¹¸ ¡ºÑ áç´Ñ¹ä¿àÅÕÂé §·Õ¨è Ò ÂãË á¡ à«Íà âÇÁÍàµÍà ´Ç  «Ö§è ÁÑ¡¨Ðáç´Ñ¹ 4.8 ËÃ×Í 6V ¹Í¡¨Ò¡¹Ñ¹é ÂѧÁÕ»¨ ¨ÑÂà¡ÕÂè ǡѺáçàÊÕ´·Ò¹ã¹Ãкºà¿ ͧÀÒÂã¹à«Íà âÇÁÍàµÍà ¡ÒÃËÅ ÍÅ×¹è ¡ÒÃàª×Íè Áâ§ÃÐËÇ Ò§à¿ Í§µ Í࿠ͧ㹪ش࿠ͧ·´·ÕÊè § ¼ÅãË ¤ÇÒÁàÃçÇáÅÐáçºÔ´¢Í§à«Íà âÇÁÍàµÍà à»ÅÕè¹á»Å§ä»ä´é

10.4 ¡ÒâѺà«Íà âÇÁÍàµÍà ¢Í§ i-Stamp2P24 ÊíÒËÃѺ¡ÒùíÒ i-Stamp2P24 令Ǻ¤ØÁ¡ÒÃËÁع¢Í§à«Íà âÇÁÍàµÍà ÊÒÁÒö·íÒä´ §Ò ÂÁÒ¡ à¾Õ§µ Í¢Ò ¾Íà µ¢Í§ i-Stamp2P24 ࢠҡѺÊÒÂÃѺÊÑ­­Ò³¢Í§à«Íà âÇÁÍàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁ ¤íÒÊÑ§è ·Õãè ª 㹡ÒÃÊ §¾ÑÅÊ à¾×Íè ¤Çº¤ØÁ¡ÒÃËÁع¢Í§à«Íà âÇÁÍàµÍà ¤Í× PULSOUT â´Â¾ÑÅÊ ·àÕè ¡Ô´¢Ö¹é ¨Ò¡¤íÒÊÑ§è ¹Õ¨é ÐÁÕ¤ÇÒÁ¡Ç Ò§ã¹Ë¹ Ç 0.8 äÁâ¤ÃÇÔ¹Ò·Õ ã¹ÃÙ»·Õè 10-6 áÊ´§¡Òõ Íǧ¨Ã¢Í§ i-Stamp2P24 à¾×Íè ¢Ñºà«Íà âÇÁÍàµÍà µÑÇà¡çº»ÃÐ¨Ø 2200PF µ ÍäÇ à¾×Íè ª ÇÂà¾ÔÁè »ÃÐÊÔ·¸ÔÀÒ¾¢Í§áËÅ §¨ ÒÂä¿ÊíÒËÃѺà«Íà âÇÁÍàµÍà áÅЪ ÇÂãË äÁâ¤Ã¤Í¹â·ÃÅàÅÍà äÁ ä´ ÃºÑ ¼Å ¡Ãзº¨Ò¡¡Ò÷íÒ§Ò¹¢Í§âËÅ´»ÃÐàÀ·ÁÍàµÍà +Vm

2200PF 10V i-Stamp2P24

P8

+V S

-

STA N D A RD SERV O M O TO R

RC à«Íà âÇÁÍàµÍà ẺÁҵðҹ

ÃÙ»·Õè 10-6 ǧ¨Ã¢Ñºà«Íà âÇÁÍàµÍà ¢Í§ i-Stamp2P24 $$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ·Õè 13 ¢Ñºà«Íà âÇÁÍàµÍà Í ҧ§ Ò´ Ç i-Stamp2P24 à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. RC à«Íà âÇÁÍàµÍà ẺÁҵðҹ 1 µÑÇ 5. ẵàµÍÃÕè 4.8 ¶Ö§ 6V 1000mAH à» ¹Í ҧ¹ Í 1 ªØ´

¡Ò÷´Åͧ 13.1 㪠ǧ¨ÃÃÙ»·Õè L13-1 㹡Ò÷´Åͧ ÁÕû٠Ẻ¡Òõ Íǧ¨Ãâ´Â㪠ºÍà ´ JX-2SX plus II ´Ñ§ÃÙ»·Õè L13-2 13.2 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB1301.BSP '********************************************************** ' Program : LAB1301.BSP ' Description : Basic servo motor driving ' Hardware : Connect a servo motor to P8 '********************************************************** ' {$STAMP BS2p} ' {$PBASIC 2.5} X VAR Word OUTPUT 8 HERE : FOR X = 1 TO 100 PULSOUT 8,1250 ' Send pulse for driving motor to left end PAUSE 10 NEXT FOR X = 1 TO 100 PULSOUT 8,2500 PAUSE 10 NEXT

' Send pulse for driving motot to another end

GOTO HERE

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$%


+Vm

2200PF 10V

+V

P8

S

STA N D A RD SERV O M O TO R

AA

AA

AA Vs

SERVO PORT

i-Stamp2P24

4.8 to 6V for SERVO

POWER

+Vs P10

P9

P8

P

Vin

RS-232

6-12Vdc

¡ÐºÐ¶ Ò¹¢¹Ò´ AA 4 ËÃ×Í 5 ¡ ͹ áç´Ñ¹ +Vm 4.8 ¶Ö§ 7.5V ÊÒÁÒö㪠ẵàµÍÃÕèẺ»ÃШØä´ (1.2V) ËÃ×ÍẺÍÑŤÒäŹ (1.5V)

RC à«Íà âÇÁÍàµÍà ẺÁҵðҹ

AA

-

AA

i-Stamp2P24

RESET

ON

STANDARD SERVO MOTOR

+Vs

Microcontroller port (P15-P0) +5V # " ! 9 8 7 6 5 4 3 2 1 0 GND

GND

+Vs

JX-2SXplusII

RC à«Íà âÇÁÍàµÍà ẺÁҵðҹ

- 2% +

- 2$ +

- 2# +

- 2" +

- 2! +

- 2 +

- 2 +

- 2 +

ÃÙ»·Õè L13-1 ǧ¨ÃáÅСÒõ Íǧ¨Ãà¾×Íè ·´Åͧ¢Ñºà«Íà âÇÁÍàµÍà ¢Í§ i-Stamp2P24

$&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ ã¹â»Ãá¡ÃÁ¹Õ¨é зíÒ¡ÒÃÊà ҧ¢ºÇ¹¢Í§ÊÑ­­Ò³¾ÑÅÊ ¨Òí ¹Ç¹ 100 ÅÙ¡ÊíÒËÃѺ¢Ñºà«Íà âÇÁÍàµÍà 价ҧ« Ò áÅÐÍÕ¡ 100 ÅÙ¡ÊíÒËÃѺ¢Ñºä»·Ò§¢ÇÒ â´Â㹡ÒâѺ价ҧ« Ò¨Ð㪠¾ÅÑ Ê ·ÁÕè ¤Õ ÒºàÇÅÒ 1 ÁÔÅÅÔÇ¹Ô Ò·Õ «Ö§è ã¹â»Ãá¡ÃÁ 㪠¢Í ÁÙÅ 1250 ÁÕ˹ ÇÂà» ¹ 0.8 äÁâ¤ÃÇÔ¹Ò·Õ àÁ×Íè ¹íÒÁÒ¤Ù³¡Ñ¹¨Ö§ä´ ¤Ò àÇÅÒ෠ҡѺ 1 ÁÔÅÅÔÇ¹Ô Ò·Õ Ê Ç¹¢ ÍÁÙÅÊíÒËÃѺ Êà ҧ¾ÑÅÊ ¢ºÑ à«Íà âÇÁÍàµÍà 价ҧ¢ÇÒ෠ҡѺ 2500 ã¹Ë¹ Ç¢ͧ 0.8 äÁâ¤ÃÇÔ¹Ò·Õ ¨Ö§ÊÒÁÒöÊà ҧÊÑ­­Ò³¾ÑÅÊ ·ÕÁè ¤Õ Ò àÇÅÒ෠ҡѺ 2 ÁÔÅÅÔÇ¹Ô Ò·Õ (2500 x 0.8 x 10- 6) Í ҧäáçµÒÁ¤ Ò¤ÇÒÁ¡Ç Ò§¢Í§ÊÑ­­Ò³¾ÑÅÊ ·ãÕè ª 㹡ÒâѺ à«Íà âÇÁÍàµÍà ᵠÅеÑÇ áµ ÅÐÂÕËè Í ÍÒ¨ÁÕ¤ÇÒÁᵡµ Ò§¡Ñ¹ä´ 13.3 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 áÅ ÇÃѹâ»Ãá¡ÃÁ 13.4 à» ´ÊÇÔµª à¾×Íè ¨ ÒÂä¿àÅÕÂé §á¡ à«Íà âÇÁÍàµÍà Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§à«Íà âÇÁÍàµÍà àÁ×Íè àÃÔÁè ·íÒ§Ò¹ ᡹¢Í§ÁÍàµÍà ¨Ð¶Ù¡¢ÑºãË ËÁع价ҧ« Ò ¨Ò¡¹Ñ¹é ¨ÐËÁع¡ÅѺÁÒ·Ò§¢ÇÒ áÅ Ç¡ÅѺ ä»·Ò§« ÒÂÍÕ¡¤Ãѧé ÊÅѺä»ÁÒઠ¹¹Õµé ÅÍ´àÇÅÒ Ëҡ᡹ËÁع¢Í§ÁÍàµÍà äÁ ä´ à¤Å×Íè ¹·ÕÂè §Ñ µíÒá˹ §¢ÇÒËÃ×Í« ÒÂÊØ´ ÍÒ¨ÊÒÁÒö»ÃѺᵠ§¤ Ò¤ÇÒÁ¡Ç Ò§ ¢Í§ÊÑ­­Ò³¾ÑÅÊ ä´ â´Â»ÃѺ¤ Ò·Õ¾è ÒÃÒÁÔàµÍà DURATION ¢Í§¤íÒÊѧè PULSOUT ËÒ¡µ ͧ¡ÒÃà¾ÔÁè ËÃ×ÍÅ´¤ÇÒÁàÃçÇ㹡ÒÃËÁع¢Í§á¡¹à«Íà âÇÁÍàµÍà ÊÒÁÒö»ÃÑºä´ ´Ç ¡ÒÃà¾ÔÁè ËÃ×ÍÅ´ ¨íҹǹ¾ÑÅÊ ·ÊÕè § ä»Âѧà«Íà âÇÁÍàµÍà â´Â¶ ÒËÒ¡¨íҹǹ¾ÑÅÊ ·ÊÕè § 仢ͧᵠÅФ Ò¹ ÍÂ᡹¨ÐËÁعàÃçÇ ¹Ñ¹è ¤×Íà¡Ô´ ¡ÒÃà»ÅÕÂè ¹µíÒá˹ §á¡¹ËÁع¢Í§à«Íà âÇÁÍàµÍà àÃçÇ¢Ö¹é ¹Ñ¹è àͧ áµ Á¢Õ Í àÊÕ¤×Í áçºÔ´¤ ͹¢ Ò§µèÒí

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

$'


%

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


º··Õè 11

¢ÑºâÁ´ÙÅ LCD ẺÍÑ¡¢ÃÐâ´Â㪠i-Stamp2p24

âÁ´ÙÅ LCD (Liquid Crystal Display module) à» ¹ÍØ»¡Ã³ áÊ´§¼ÅáººË¹Ö§è ·ÕÊè ÒÁÒö㪠áÊ´§µÑÇ ÍÑ¡Éà µÑÇàÅ¢ áÅÐÊÑ­Åѡɳ ¾àÔ ÈÉä´ ã¹º·¹Õ¨é Ð͸ԺÒ¶֧¡ÒÃ㪠i-Stamp2P24 ¢ÑºâÁ´ÙÅ LCD ã¹áºº¢¹Ò¹ à¾×Íè áÊ´§¢ ͤÇÒÁµÒÁ·Õµè Í §¡Òà â´ÂâÁ´ÙÅ LCD ·Õãè ª §Ò¹¹Õ¨é Ð㪠µÇÑ ¤Çº¤ØÁàºÍà HD44780 ¢Í§ HITACHI ËÃ×͵ÑÇÍ×¹è ·Õàè ¢ Ò¡Ñ¹ä´ ÁÕ¢¹Ò´ 16 µÑÇÍÑ¡Éà 2 ºÃ÷Ѵ âÁ´ÙÅ LCD ÁÕ¢Òµ Í㪠§Ò¹ 14 ¢Ò ´Ñ§áÊ´§ÃÒÂÅÐàÍÕ´¡ÒèѴ¢Òã¹ÃÙ»·Õè 11-1 Ê Ç¹Ë¹ Ò·Õ¢è ͧ¢Ò㪠§Ò¹ âÁ´ÙÅ LCD ÁÕÃÒÂÅÐàÍÕ´´Ñ§¹Õé ¢Ò GND (¢Ò 1) µ ͡Ѻ¡ÃÒÇ´ ¢Í§Ç§¨Ã ¢Ò +VDD (¢Ò 2) µ Íä¿àÅÕÂé § +5V ¢Ò Vo (¢Ò 3) à» ¹¢ÒÊíÒËÃѺ» ͹áç´Ñ¹à¾×Íè »ÃѺ¤ÇÒÁÊÇ Ò§¢Í§Ë¹ Ò¨ÍáÊ´§¼Å ¢Ò RS (Register Select : ¢Ò 4) à» ¹¢ÒàÅ×Í¡¡ÒõԴµ ͡ѺÃÕ¨ÊÔ àµÍà ¤Òí Êѧè ËÃ×ÍÃÕ¨ÊÔ àµÍà ¢Í ÁÙÅ â´Â ¶ Òà» ¹ 0 ¨ÐµÔ´µ ͡ѺÃÕ¨ÊÔ àµÍà ¤Òí Êѧè áÅж Òà» ¹ 1 ¨ÐµÔ´µ ͡ѺÃÕ¨ÊÔ àµÍà ¢Í ÁÙÅà¾×Íè ¹íÒ¢ ÍÁÙÅä»áÊ´§¼Å ¢Ò R/W (Read/Write control : ¢Ò 5) à» ¹¢ÒàÅ×Í¡¡ÒÃÍ Ò¹ËÃ×Íà¢Õ¹¢ ÍÁÙšѺâÁ´ÙÅ LCD »¡µÔ¢Ò ¹Õ¨é е Íŧ¡ÃÒÇ´ à¾×Íè ¡íÒ˹´ãË à¢Õ¹¢ ÍÁÙÅä»ÂѧâÁ´ÙÅ LCD à¾Õ§·Ò§à´ÕÂÇ à¾×Íè Å´¨íҹǹ¢Ò㹡ÒõԴµ Í ¢Ò E (Enable : ¢Ò 6) à» ¹¢ÒÊíÒËÃѺ» ͹ÊÑ­­Ò³¾ÑÅÊ àÍç¹àÍàºÔÅãË âÁ´ÙÅ LCD ·íÒ§Ò¹ ¢Ò D0 ¶Ö§ D7 (Data : ¢Ò 7 ¶Ö§ 14) à» ¹¢Ò¢ ÍÁÙÅ 8 ºÔµ â´Â¢Ò 7 ¤×Í D0 äŠ仵ÒÁÅíҴѺ¨¹¶Ö§¢Ò 14 ¤×Í D7 ¤íÒÊÑ§è ¤Çº¤ØÁâÁ´ÙÅ LCD ÊÃØ»ÃÇÁäÇ áÊ´§ã¹¡Ãͺá¡·Õè 11-1

"

LCD Module 16x2

LCD Module 16x1 "

¢Ò 1 : GND ¢Ò 2 : +Vcc ¢Ò 3 : Vo (»ÃѺ¤ÇÒÁÊÇ Ò§) ¢Ò 4 : RS ¢Ò 5 : R/W ¢Ò 6 : E ¢Ò 7-14 : DATA (D0-D7)

ÃÙ»·Õè 11-1 áÊ´§¡ÒèѴ¢Ò¢Í§âÁ´ÙÅ LCD ¢¹Ò´ 16 µÑÇÍÑ¡Éà 1 áÅÐ 2 ºÃ÷Ѵ Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%


¡Ãͺá¡·Õè 11-1 ¤íÒÊÑ§è ¤Çº¤ØÁâÁ´ÙÅ LCD Ẻ¢¹Ò¹·ÕÊè Òí ¤Ñ­ 1. ¤íÒÊѧè à¤ÅÕÂà ¨ÍáÊ´§¼Å ÁÕ¢Í ÁÙŤíÒÊѧè à» ¹ $1 à» ¹¤íÒÊѧè à¢Õ¹¢ ÍÁÙŪ Í§Ç Ò§ËÃ×Í space ࢠÒä»ã¹Ë¹ ǤÇÒÁ¨íÒ¢ ÍÁÙÅÊíÒËÃѺáÊ´§¼ÅËÃ×Í DDRAM ÀÒÂã¹âÁ ´ÙÅ LCD àÁ×Íè à¤ÅÕÂà ¨ÍáÊ´§¼ÅáÅ Ç ¨Ð¡íÒ˹´ãË à¤Íà à«Íà (cursor : ÊÑ­Åѡɳ ¾àÔ ÈÉ·Õãè ª 㹡ÒÃáÊ´§µíÒá˹ §ÊíÒËÃѺáÊ´§µÑÇÍÑ¡ÉâͧâÁ ´ÙÅ LCD ºÒ§¤Ãѧé ÁÕÅ¡Ñ É³Ðà» ¹ÃÙ»ÊÕàè ËÅÕÂè Á¼×¹¼ Ò¢¹Ò´ 5x 7 ¨Ø´ËÃ×Í à» ¹¢Õ´ ÊÒÁÒöÊѧè ãË ¡Ð¾ÃÔºËÃ×ÍäÁ ¡äç ´ ) ¡ÅѺä»ÍÂÙ· µÕè Òí á˹ §« ÒÂÁ×Í ÊØ´¢Í§¨ÍáÊ´§¼Å 2. ¤íÒÊѧè Return Home ÁÕ¤Ò ¢Í§¢ ÍÁÙÅ෠ҡѺ $2 ËÃ×Í $3 ¡çä´ (á¹Ð¹íÒãË ãª $2) à» ¹ ¡ÒáíÒ˹´ãË à¤Íà à«Íà ä»áÊ´§ÂѧµíÒá˹ §« ÒÂÊØ´¢Í§¨ÍáÊ´§¼Å â´Â ¢ ÍÁÙÅ·ÕèáÊ´§ÍÂ٠㹺¹¨ÍáÊ´§¼Å¨ÐäÁ ÁÕ¡ÒÃà»ÅÕè¹á»Å§ 3. ¤íÒÊѧè àÅ×Í¡âËÁ´¡Òû ͹¢ ÍÁÙÅ (Entry mode set) ÁÕÃٻẺ¤íÒÊÑ觴ѧ¹Õé

ºÔµ 7 ºÔµ 6 ºÔµ 5 ºÔµ 4 ºÔµ 3 ºÔµ 2 ºÔµ 1 ºÔµ 0 0

0

0

0

0

1

I/D

S

ºÔµ I/D 㪠㹡ÒáíÒ˹´Ç Ò àÁ×Íè à¢Õ¹ËÃ×ÍÍ Ò¹¢ ÍÁÙÅáÅ Ç ·íÒãË áÍ´ à´Ãʢͧ˹ ǤÇÒÁ¨íÒáÊ´§¼Å (DDRAM) à¾ÔÁè ËÃ×ÍŴŧ 0 áÍ´à´ÃÊŴŧ 1 áÍ´à´ÃÊ 1 áÍ´à´ÃÊà¾ÔÁè ¢Ö¹é 1 áÍ´à´ÃÊ ºÔµ S 㪠¡Òí ˹´ÅѡɳСÒÃáÊ´§¼Å 0 àÁ×Íè à¡Ô´µÑÇÍÑ¡ÉÃãËÁ à¤Íà à«Íà àÅ×Íè ¹ä»·Ò§¢ÇÒÁ×Í 1 àÁ×Íè à¡Ô´µÑÇÍÑ¡ÉÃãËÁ à¤Íà à«Íà ÍÂÙ· àÕè ´ÔÁ áµ µÇÑ ÍÑ¡Éà àÅ×è͹价ҧ« Ò ·Õè¹ÔÂÁ㪠ÁÒ¡·ÕèÊØ´¤×Í ¢ ÍÁÙŤíÒÊÑè§ $6 ËÁÒ¶֧ ¡íÒ˹´ãË àÁ×èÍà¡Ô´ ¢ ÍÁÙÅãËÁ à¤Íà à«Íà ¨ÐàÅ×è͹价ҧ¢ÇÒÁ×Í áÅÐáÍ´à´Ãʢͧ˹ Ç ¤ÇÒÁ¨íÒÊíÒËÃѺáÊ´§¼Å¨Ðà¾ÔèÁ¢Öé¹ 4. ¤íÒÊÑ§è ¤Çº¤ØÁ¡ÒÃáÊ´§¼Å ÁÕÃٻẺ¤íÒÊÑ觴ѧ¹Õé

ºÔµ 7 ºÔµ 6 ºÔµ 5 ºÔµ 4 ºÔµ 3 ºÔµ 2 ºÔµ 1 ºÔµ 0 0

0

0

0

1

D

C

B

ºÔµ D 㪠¤Çº¤ØÁ¡ÒÃà» ´» ´¨ÍáÊ´§¼Å ¶ Òà» ¹ 0 à» ¹¡Òû ´¨Í áÊ´§¼Å ¶ Òà» ¹ 1 à» ¹¡ÒÃà» ´¨ÍáÊ´§¼Å ºÔµ C 㪠¤Çº¤ØÁ¡ÒÃáÊ´§µÑÇà¤Íà à«Íà º¹¨ÍáÊ´§¼Å ¶ Òà» ¹ 0 à» ¹ ¡Òû ´µÑÇà¤Íà à«Íà ËÃ×ÍäÁ áÊ´§à¤Íà à«Íà ¶ Òà» ¹ 1 à» ¹¡ÒÃáÊ´§µÑÇ à¤Íà à«Íà ºÔµ B 㪠¤Çº¤ØÁ¡ÒáоÃÔº¢Í§à¤Íà à«Íà ¶ Òµ ͧ¡ÒÃãË à¤Íà à«Íà ¡Ð ¾ÃÔº µ ͧ¡íÒ˹´ãË à» ¹ 1 ¤íÒÊÑ觷Õè㪠º ͤ×Í $0C à» ¹¡ÒÃÊÑè§ãË à» ´¨ÍáÊ´§¼Å áµ äÁ áÊ´§ à¤Íà à«Íà áÅÐ $0F à» ¹¡ÒÃÊѧè ãË à» ´¨ÍáÊ´§¼Å áÊ´§à¤Íà à«Íà áÅÐ Êѧè ãË à¤Íà à«Íà ¡Ð¾ÃÔº

%

5. ¤íÒÊÑ§è ¤Çº¤ØÁ¡ÒÃàÅ×Íè ¹à¤Íà à«Íà áÅеÑÇÍÑ¡Éà ÁÕÃٻẺ´Ñ§¹Õé

ºÔµ 7 ºÔµ 6 ºÔµ 5 ºÔµ 4 ºÔµ 3 ºÔµ 2 ºÔµ 1 ºÔµ 0 0

0

0

1

S/C

R/L

*

*

¡ÒÃàÅ×Íè ¹à¤Íà à«Íà áÅеÑÇÍÑ¡Éâֹé ÍÂÙ¡ ºÑ ¡ÒáíÒ˹´ºÔµ S/C áÅÐ R/ L «Ö§è ÊÒÁÒöÊÃØ»ä´ ´§Ñ ¹Õé S/C R/L ÅѡɳСÒÃàÅ×è͹ ¢ ÍÁÙŤíÒÊѧè 0 0 àÅ×Íè ¹à¤Íà à«Íà 价ҧ« Ò $10-$13 0 1 àÅ×è͹à¤Íà à«Íà 价ҧ¢ÇÒ $14-$17 1 0 àÅ×è͹µÑÇÍÑ¡ÉÃãËÁ ä»·Ò§« Ò $18-$1B 1 1 àÅ×è͹µÑÇÍÑ¡ÉÃãËÁ ä»·Ò§¢ÇÒ $1C-$1F 6. ¤íÒÊÑ§è ¡íÒ˹´¿ §¡ ª¹Ñè ¡Ò÷íÒ§Ò¹ à» ¹¤íÒÊÑ§è ·ÕÁè ¤Õ ÇÒÁÊíҤѭÁÒ¡·ÕÊè ´Ø ÍÕ¡¤íÒÊѧè ˹֧è ÁÕû٠Ẻ¢Í§¢ ÍÁÙÅ ¤íÒÊÑ觴ѧ¹Õé

ºÔµ 7 ºÔµ 6 ºÔµ 5 ºÔµ 4 ºÔµ 3 ºÔµ 2 ºÔµ 1 ºÔµ 0 0

0

1

DL

N

F

*

*

ºÔµ DL 㪠㹡ÒáíÒ˹´¨íҹǹºÔµã¹¡ÒõԴµ ͡ѺâÁ´ÙÅ LCD 0 ¡íÒ˹´ãË ·Òí §Ò¹ã¹âËÁ´ 4 ºÔµ 1 ¡íÒ˹´ãË ·Òí §Ò¹ã¹âËÁ´ 8 ºÔµ ºÔµ N 㪠¡Òí ˹´¨íҹǹºÃ÷Ѵ·Õµè Í §¡ÒÃãË áÊ´§¼Å 0 áÊ´§¼Å 1 ºÃ÷Ѵ 1 áÊ´§¼Å 2 ºÃ÷ѴËÃ×ÍÁÒ¡¡Ç Ò áµ ÊÒí ËÃѺâÁ´ÙÅ LCD ¢¹Ò´ 16 µÑÇÍÑ¡Éà 1 ºÃ÷Ѵ·ÕÁè ¨Õ Òí ˹ ÒÂã¹ »ÃÐà·Èä·Â µ ͧ¡íÒ˹´ãË ºÔµ¹Õéà» ¹ 1 à¹×èͧ¨Ò¡Ë¹ ǤÇÒÁ¨íÒ ÊíÒËÃѺà¡çº¢ ÍÁÙÅà¾×Íè ¡ÒÃáÊ´§¼ÅäÁ ä´ ÍÂÙµ Í à¹×Íè §¡Ñ¹ ¡Å ÒǤ×Í áº §à» ¹ 2 ª ǧ¤×Í ·Õáè Í´à´ÃÊ $00-$07 áÅÐ $40-$47 â´Â·Õáè Í´à´ÃÊ $40 ¨Ðà» ¹ áÍ´à´ÃÊàÃÔÁè µ ¹¢Í§Ë¹ ǤÇÒÁ¨íÒÊíÒËÃѺ¡ÒÃáÊ´§¼Å㹺Ã÷Ѵ·ÕÊè ͧ ¢Í§âÁ´ÙÅ LCD ·ÕÁè ÁÕ Ò¡¡Ç Ò 1 ºÃ÷Ѵ ¨Ö§·íÒãË àÁ×Íè µ ͧ¡ÒõԴµ ͡Ѻ âÁ´ÙÅ LCD 1 ºÃ÷Ѵ¨Ö§¨íÒà» ¹µ ͧ¡íÒ˹´ãË à» ¹ 1 ºÔµ F 㪠àÅ×Í¡¤ÇÒÁÅÐàÍÕ´¢Í§µÑÇÍÑ¡ÉÃ㹡ÒÃáÊ´§¼Å 0 áÊ´§¼ÅẺ 5x7 ¨Ø´ 1 áÊ´§¼ÅẺ 5x10 ¨Ø´

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


11.1 ¡ÒõԴµ ͡ѺâÁ´ÙÅ LCD 16 µÑÇÍÑ¡Éà 2 ºÃ÷Ѵ¢Í§ i-Stamp2P24 ÁÕ´Ç Â¡Ñ¹ 2 Ẻ¤×Í áºº 8 ºÔµ áÅÐ 4 ºÔµ â´Â»¡µÔÁ¡Ñ ¨Ð㪠Ẻáá áµ ÊÒí ËÃѺ i-Stamp2P24 «Ö§è ÁÕ¤Òí Êѧè ÊíÒËÃѺµÔ´µ ͡ѺâÁ´ÙÅ LCD â´Â੾ÒÐ ¨Ö§àËÁÒзըè Ð㪠¡ÒõԴµ ÍẺ 4 ºÔµÁÒ¡¡Ç Ò ´Ñ§ÃÙ»·Õè 11-2 ¢Ò¢ ÍÁÙÅ ·Õãè ª ÁàÕ ¾Õ§ 4 àÊ ¹¤×Í D4 ¶Ö§ D7 «Ö§è µ ÍࢠҡѺ P12 ¶Ö§ P15 ¢Í§ i-Stamp2P24 Ê Ç¹¢Ò RS µ ÍࢠҡѺ P11, R/W µ ͡Ѻ¢Ò P10 ËÃ×͵ Íŧ¡ÃÒÇ´ ¡äç ´ (áµ ¢Íá¹Ð¹íÒãË µÍ ¾Íà µ ËÒ¡äÁ Á¤Õ ÇÒÁ¨íÒà» ¹µ ͧ㪠§Ò¹Í×¹è ) áÅÐ E µ ÍࢠҡѺ P9 ¢Ò¾Íà µ¢Í§ i-Stamp2P24 ·Õãè ª àª×Íè Áµ ͡ѺâÁ´ÙÅ LCD ¹Õ¨é ж١¡íÒ˹´ÁÒ੾ÒÐà¨ÒШ§ ËÒ¡µ ͧ¡ÒÃ㪠¤Òí ÊÑ§è ¤Çº¤ØÁâÁ´ÙÅ LCD ¨Ðµ ͧµ Í¢ÒµÒÁ·Õ¡è Òí ˹´¹ÕËé Ã×Íà»ÅÕÂè ¹á»Å§ä´ µÒÁ¢ Í¡íÒ˹´«Ö§è ÁÕÃÒÂÅÐàÍÕ´㹺··Õè 3 ã¹ËÑÇ¢ ͤíÒÊѧè LCDCMD, LCDIN áÅÐ LCDOUT ¡ÒÃ㪠§Ò¹ i-Stamp2P24 ¡ÑºâÁ´ÙÅâÁ´ÙÅ LCD¹Ñ¹é ÊÒÁÒö·íÒä´ §Ò Âæ â´Â㪠¤Òí ÊÑ§è µÔ´µ ÍâÁ´ÙÅ LCD ·Ñ§é 3 ¤íÒÊÑ§è ¤×Í LCDCMD, LCDIN áÅÐ LCDOUT «Ö§è ¡ÒõԴµ ÍÃÐËÇ Ò§ i-Stamp2P24 ¡ÑºâÁ´ÙÅ LCD ¹Ñ¹é ¨Ðà» ¹¡ÒõԴµ ÍẺ 4 ºÔµ 㪠ÊÒÂÊÑ­­Ò³·Ñ§é ËÁ´ 7 àÊ ¹´ Ç¡ѹ â´ÂÁÕâËÁ´ã¹¡ÒÃàÅ×Í¡µ ÍÊÒÂÍÂÙ 4 âËÁ´ ·Õáè µ¡µ Ò§¡Ñ¹ ´Ñ§ä´ ¡Å ÒÇä»áÅ Çã¹Ê ǹ¢Í§¤íÒÊѧè LCDCMD 㹺··Õè 3 ÊÔè§ÊíҤѭ㹡ÒÃàÃÔèÁµ ¹ãª §Ò¹¤×Í ¡ÒÃÍÔ¹ÔàªÕÂÅâÁ´ÙÅ LCD ãË ÍÂÙ ã¹âËÁ´¡ÒõԴµ ÍẺ 4 ºÔµ ËÅѧ ¨Ò¡¹Ñ¹é ¨Ö§¨ÐÊÒÁÒöÊÑ§è §Ò¹´ ǤíÒÊѧè Í×¹è ä´ Í ҧ¶Ù¡µ ͧµ Íä» ·Ñ§é ¹Õàé ¹×Íè §¨Ò¡ËÅѧ¨Ò¡·Õàè ÃÔÁè ¨ ÒÂä¿àÅÕÂé §ãË á¡ âÁ´ÙÅ LCD áÅ Ç Ç§¨Ãà¾ÒàÇÍà Í͹ÃÕ૵ÀÒÂã¹ ¨Ð·íÒ¡ÒÃÍÔ¹àÔ ªÕÂÅãË µÇÑ ÁѹàͧµÔ´µ Íã¹âËÁ´ 8 ºÔµ ´Ñ§¹Ñ¹é ¼Ùã ª §Ò¹ ¨Ðµ ͧ·íÒ¡ÒÃà»ÅÕÂè ¹¨Ò¡âËÁ´ 8 ºÔµãË à» ¹âËÁ´ 4 ºÔµ¡ ͹ ÇÔ¸¡Õ Ò÷շè Ò§¼Ù¼ ÅÔµ á¹Ð¹íÒ¤×Í ãË Ê§ ¢ ÍÁÙÅ 3, 3, 3 áÅÐ 2 ÍÍ¡ä»ÂѧÊÒ¢ ÍÁÙÅ 4 ºÔµº¹ (D7 ¶Ö§ D4) µÒÁÅíҴѺ¡ ͹ (4 ºÔµÅ Ò§¤×Í D3 ¶Ö§ D0 äÁ µÍ §Ê¹ã¨) ¨Ò¡¹Ñ¹é ¨Ö§µÒÁ´ ǤíÒÊѧè 㪠§Ò¹»¡µÔ ¤ÇÒÁËÁÒ¢ͧ ¡ÒÃÊ §¤ Ò¤§·Õè·Ñé§ÊÕèÍÍ¡ä»Áմѧ¹Õé ¢ ÍÁÙÅ 3 µÑÇáá㪠㹡ÒÃᡠ䢤ÇÒÁ¼Ô´¾ÅÒ´·Õàè ¡Ô´¨Ò¡¡ÒÃÍÔ¹àÔ ªÕÂŢͧǧ¨Ãà¾ÒàÇÍà Í͹ÃÕ૵ÀÒÂã¹ âÁ´ÙÅ LCD «Ö§è Ê §¼ÅãË âÁ´ÙÅ LCD äÁ ·ÃÒºÇ Ò ¢³Ð¹Õ¡é Òí ÅѧµÔ´µ Íã¹âËÁ´ã´ÍÂÙ ¤ÇÒÁ¼Ô´¾ÅÒ´´Ñ§¡Å ÒǹÕÁé ÊÕ Òà赯 ÁÒ¨Ò¡àʶÕÂÃÀÒ¾¢Í§áËÅ §¨ ÒÂä¿ Ê Ç¹¢ ÍÁÙŵÑÇÊØ´· Ò (2) ¨Ðà» ¹¢ ÍÁÙÅ·Õãè ª ¡Òí ˹´ãË âÁ´ÙÅ LCD ·íÒ¡ÒõԴµ Í ã¹âËÁ´ 4 ºÔµ ´Ñ§¹Ñ¹é ¡Ò÷íҧҹẺ 4 ºÔµ·Õ¶è ¡Ù µ ͧ¨Ðà¡Ô´¢Ö¹é ËÅѧ¨Ò¡·ÕÊè § ¤ Ò 2 Í͡仹ѹè àͧ +5V

P11 P10 P9

i-Stamp2P24

P12

DSP1 LCD 16x2

4 RS 5 R/W 6 E

2 3 ," ,# ,$ ,%

11 12 13 14

VR1 10k

1

P13 P14 P15

ÃÙ»·Õè 11-2 ǧ¨Ãàª×Íè Áµ Í i-Stamp2P24 ¡ÑºâÁ´ÙÅ LCD Ẻ 4 ºÔµ Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%!


µÑÇÍ ҧ¢Í§â»Ãá¡ÃÁ Í¡ÒÃÍÔ¹àÔ ªÕÂÅãË ·Òí §Ò¹áººâËÁ´ 4 ºÔµ áÊ´§ä´ ´§Ñ â»Ãá¡ÃÁ´ ҹŠҧ¹Õé '***** SUBROUTINES ***** INITLCD: PAUSE 50 ' ˹ ǧàÇÅÒ 50 ÁÔÅÅÔÇ¹Ô Ò·Õ ËÅѧ¨Ò¡ VCC ÊÙ§¡Ç Ò 4.5V LCDCMD 9,$30 ' á¡ ä¢ ¤ÃÑ§é ·Õè 1 PAUSE 5 ' ˹ ǧàÇÅÒ Í ҧµèÒí 4.1 ÁÔÅÅÔÇ¹Ô Ò·Õ LCDCMD 9,$30 ' ᡠ䢤ÃÑ§é ·Õè 2 PAUSE 1 ' ˹ ǧàÇÅÒ Í ҧµèÒí 100 äÁâ¤ÃÇÔ¹Ò·Õ LCDCMD 9,$30 ' ᡠ䢤ÃÑ§é ·Õè 3 PAUSE 1 ' ˹ ǧàÇÅÒ Í ҧµèÒí 100 äÁâ¤ÃÇÔ¹Ò·Õ LCDCMD 9,$20 ' âËÁ´ 4 ºÔµ àÃÔÁè ¢Ö¹é ËÅѧ¨Ò¡·ÕÊè § ¤íÒÊÑ§è ¹ÕÍé Í¡ä» LCDCMD 9,$28 ' Êѧè ãË áÊ´§¼Å Ẻ 2 ºÃ÷Ѵ, ¢¹Ò´µÑÇÍÑ¡Éà 5x8 ¨Ø´ LCDCMD 9,$06 ' Êѧè ãË à¤Íà à«Íà àÅ×Íè ¹¢ÇÒàÁ×Íè à¢Õ¹¢ ÍÁÙÅàÊÃç¨ LCDCMD 9,$0E ' Êѧè ãË áÊ´§µÑÇÍÑ¡ÉÃáÅÐà¤Íà à«Íà LCDCMD 9,$01 ' à¤ÅÕÂà ˹ Ò¨Í RETURN

¨Ò¡µÑÇÍ ҧ¢ Ò§µ ¹ ¤ Ò˹ ǧàÇÅÒ·Õãè ª à» ¹¤ Ò·Õ·è Ò§¼Ù¼ ÅÔµÃкØÁÒ ´Ñ§¹Ñ¹é ¼Ùã ª §Ò¹¤ÇÃ㪠¤Ò µÒÁ¹Õé (ã¹·Õ¹è Õé Í Ò§ÍÔ§¨Ò¡ªÔ»àºÍà HD44780 ËÃ×Íà·Õº෠Ò) Ê Ç¹¤íÒÊÑ§è ¶Ñ´Áҷѧé 4 ¤íÒÊѧè à» ¹¤íÒÊÑ§è ·Õ¼è ãÙ ª §Ò¹ÊÒÁÒö¡íÒ˹´ ¢Öé¹ä´ àͧµÒÁ¤ÇÒÁµ ͧ¡ÒÃ

11.2 ¡ÒÃÊà ҧµÑÇÍÑ¡Éâֹé àͧã¹âÁ´ÙÅ LCD

*See note

ã¹âÁ´ÙÅ LCD âÁ´ÙÅ·Õãè ª ª»Ô ¢Í§ÎÔµÒªÔàºÍà HD44780 ËÃ×ÍàºÍà à·Õºà¤Õ§¹Í¡¨Ò¡¨ÐÊÒÁÒöáÊ´§ µÑÇàÅ¢áÅеÑÇÍÑ¡Éôѧã¹ÃÙ»·Õè 11-3 áÅ Ç ÂѧÊÒÁÒöÊà ҧµÑÇÍÑ¡Éâֹé ä´ àͧÍÕ¡ 8 µÑÇÍÑ¡Éô Ç¡ѹ «Ö§è ÍҨ໠¹ µÑÇÍÑ¡Éà ÃÙ»ÀÒ¾ËÃ×ÍÊÑ­Åѡɳ ·Ò§ä¿¿ Òµ Ò§æ ¡çä´ â´Â¨Ðµ ͧÊà ҧä»à¡çºã¹Ê ǹ¢Í§ CGRAM ¡ ͹ «Ö§è ¨Ò¡ ÃÙ»·Õè 11-3 Ê Ç¹¢Í§ CGRAM ¨Ð¶Ù¡áº §ÍÍ¡à» ¹ 2 ª ǧ¤×Í ª ǧáÍ´à´ÃÊ $00 ¶Ö§ $07 áÅЪ ǧáÍ´à´ÃÊ

ÃÙ»·Õè 11-3 áÊ´§¢ ÍÁÙŢͧµÑÇÍÑ¡ÉÃáÅÐÊÑ­Åѡɳ Áҵðҹ·Õºè ÃèØÍÂÙã ¹âÁ´ÙÅ LCD ·Õãè ª µÇÑ ¤Çº¤ØÁ àºÍà HD44780 ¢Í§ Hitachi ËÃ×ÍàºÍà à·Õºà¤Õ§ %"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¢ ÍÁÙÅ 5 ºÔµÅ Ò§ ºÔµ 4 ºÔµ 3 ºÔµ 2 ºÔµ 1 ºÔµ 0

áÍ´à´ÃÊ 0 ¢ ÍÁÙÅ෠ҡѺ 0000 0000 = $00 áÍ´à´ÃÊ 1 ¢ ÍÁÙÅ෠ҡѺ 0000 0000 = $00 áÍ´à´ÃÊ 2 ¢ ÍÁÙÅ෠ҡѺ 0000 0000 = $00 áÍ´à´ÃÊ 3 ¢ ÍÁÙÅ෠ҡѺ 0001 1001 = $19 áÍ´à´ÃÊ 4 ¢ ÍÁÙÅ෠ҡѺ 0001 1001 = $19 áÍ´à´ÃÊ 5 ¢ ÍÁÙÅ෠ҡѺ 0000 1001 = $09 áÍ´à´ÃÊ 6 ¢ ÍÁÙÅ෠ҡѺ 0001 1111 = $1F áÍ´à´ÃÊ 7 ¢ ÍÁÙÅ෠ҡѺ 0001 1001 = $19

ÃÙ»·Õè 11-4 áÊ´§¡ÒáíÒ˹´¢ ÍÁÙŢͧµÑÇÍÑ¡ÉÃËÃ×ÍÊÑ­Åѡɳ ·µÕè Í §¡ÒÃÊà ҧ¢Ö¹é àͧ¢Í§âÁ´ÙÅ LCD $08 ¶Ö§ $0F ᵠ㹡ÒÃ㪠§Ò¹¨Ðµ ͧ㪠§Ò¹ã¹ª ǧ㴪 ǧ˹֧è à¹×Íè §¨Ò¡·Õáè Í´à´Ãʷѧé 2 ª ǧ¹Õ¢é Í ÁÙŨзѺ« ͹ ¡Ñ¹ÍÂÙ «Ö§è ¢ ÍÁÙÅã¹ CGRAM ¹Õ¨é ÐÂѧ¤§ÍÂÙà Á×Íè ÂѧÁÕä¿àÅÕÂé § áÅШÐËÒÂä»àÁ×Íè ËÂØ´¨ ÒÂä¿àÅÕÂé § â´Â¡ÒÃÊà ҧµÑÇ ÍÑ¡ÉùÕé ¨Ð㪠¤Òí Êѧè LCDOUT áŠǵÒÁ´ ǤíÒÊѧè 㹡ÒÃà¢Õ¹ CGRAM «Ö§è ¤×ͤ Ò %01AAAAAA â´Â·Õè AAAAAA ¤×ÍáÍ´à´ÃʢͧµÑÇÍÑ¡É÷յè Í §¡ÒÃÊà ҧ«Ö§è ÁÕä´ ·§Ñé ËÁ´ 64 áÍ´à´ÃÊ â´Â·Õµè ÇÑ ÍÑ¡Éà 1 µÑÇ ¨ÐÁÕ 8 áÍ´à´ÃÊ «Ö§è ¢ ÍÁÙÅ·Õ¨è Ðà¢Õ¹ŧã¹áÍ´à´Ãʷѧé 8 ¢Í§µÑÇÍÑ¡ÉÃË¹Ö§è µÑǨÐÁÕÇ¸Ô ËÕ Ò¤ ҴѧÃÙ»·Õè 11-4 ¨Ò¡ÃÙ»·Õè 11-4 ª ͧÊÕàè ËÅÕÂè Áã´·Õàè » ¹¨Ø´ÊÕ´Òí ¨ÐÁÕ¤Ò à» ¹ 1 Ê Ç¹·Õàè » ¹ÊÕ¢ÒǨÐÁÕ¤Ò à» ¹ 0 «Ö§è ¤ Ò·Õè à¡Ô´¢Ö¹é ¨Ðà» ¹¤ ҢͧáÍ´à´ÃÊáµ ÅÐàÊ ¹ ·Õ¨è е ͧ¹íÒä»à¢Õ¹ŧ CGRAM ¹Ñ¹è àͧ 㹡ÒÃÊà ҧµÑÇÍÑ¡ÉùÕâé ´Â»¡µÔ¼ãÙ ª §Ò¹¨Ðµ ͧËÒ¤ Ò·Õ¨è ÐãÊ ã¹ CGRAM ã¹áµ ÅÐáÍ´à´ÃÊàͧ à¾×Íè ¤ÇÒÁ ÊдǡáÅЪ ÇÂÅ´àÇÅÒ㹡ÒÃËÒ¤ Ҵѧ¡Å ÒÇ ¼Ù 㪠§Ò¹ÊÒÁÒö´Òǹ âËÅ´â»Ãá¡ÃÁ·Õèª×èÍÇ Ò LCD Character Creator ä´ ¿ÃÕ·àÕè Ǻ䫵 www.parallax.com ËÃ×Í www.inex.co.th ËÃ×ÍÊÒÁÒöËÒä´ ¨Ò¡á¼ ¹«Õ´ÃÕ ÍÁ«Ö§è ¨Ñ´ ÁҾà ÍÁ¡ÑºªØ´·´Åͧ·Õàè ¡ÕÂè Ç¢ ͧ¡Ñº i-Stamp2P24

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%#


¡Ò÷´Åͧ·Õè 14 ¡ÒÃ㪠§Ò¹âÁ´ÙÅ LCD à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. âÁ´ÙÅ LCD 16 µÑÇÍÑ¡Éà 2 ºÃ÷Ѵ 5. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 1k 1 µÑÇ

¡Ò÷´Åͧ

¡ÒÃàµÃÕÂÁ¡ÒÃâÁ´ÙÅ LCD ÊíÒËÃѺ㪠㹡Ò÷´Åͧ¡ÑººÍà ´ JX-2SX plus II 14.1 㹡ÒùíÒâÁ´ÙÅ LCD 16 µÑÇÍÑ¡Éà 2 ºÃ÷ѴÁÒ㪠¡ºÑ ἧµ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´à¾×Íè ·´Åͧà ÇÁ¡ÑººÍà ´ JX-2SX plus II áÅÐ i-Stamp2P24 ¨Ðµ ͧÁÕ¡ÒÃàµÃÕÂÁ¡ÒÃàÅ硹 Í ´Ñ§¹Õé (1) ¤Í¹à¹ç¡àµÍà IDC µÑǼ٠á¶Çà´ÕÂè Ç 14 ¢Ò (ä´ ÁҨҡẺ 40 ¢Ò µÑ´ãË àËÅ×Í 14 ¢Ò) âÁ´ÙÅ LCD (2) ¹íÒâÁ´ÙÅ LCD àÊÕºŧº¹¤Í¹à¹ç¡àµÍà IDC µÑǼ٠á¶Çà´ÕÂè Ç 14 ¢Ò âÁ´ÙÅ LCD

¨Ò¡¹Ñ¹é ÊÒÁÒö¹íÒâÁ´ÙÅ LCD ·Õºè ´Ñ ¡ÃÕ¡ºÑ ¤Í¹à¹ç¡àµÍà 仵ԴµÑ§é ŧº¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´à¾×Íè ·íÒ ¡Ò÷´ÅÍ§ä´ áÅ Ç

¡Ò÷´Åͧ㪠§Ò¹àº×éͧµ ¹ 14.2 㪠ǧ¨Ãã¹ÃÙ»·Õè L14-1 㹡Ò÷´Åͧ â´Âµ Íǧ¨Ãŧº¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ ÊíÒËÃѺâÁ´ÙÅ LCD ¤Ç÷íÒ¡ÒúѴ¡Ãդ͹à¹ç¡àµÍà IDC ´Ñ§·Õáè ¹Ð¹íÒã¹¢Ñ¹é µÍ¹·Õè 14.1 ãË àÃÕºà Í ÊíÒËÃѺ¡Òõ ͵Ñǵ Ò¹·Ò¹ 1kW ·Õ¢è Ò Vo à¾×Íè ¡íÒ˹´¤ÇÒÁªÑ´à¨¹¢Í§¡ÒÃáÊ´§¼ÅÍ ҧ¤§·Õè ·Ñ§é ¹Õàé ¾×Íè Å´¤ÇÒÁÂا Âҡ㹡Òõ Íǧ¨Ã¨Ò¡¡ÒÃ㪠µÑǵ Ò¹·Ò¹»ÃѺ¤ Òä´ à¾×Íè »ÃѺ¤ÇÒÁªÑ´à¨¹ã¹¡ÒÃáÊ´§¼Å¢Í§âÁ´ÙÅ LCD 14.3 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB1401.BSP

%$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


DSP1 LCD 16x2 P11 P10 P9

i-Stamp2P24

P12

4 RS 5 R/W 6 E

+5V 2 3 D4 D5 D6 D7 11 12 13 14

1

R1 1k

P13 P14 P15

ÃÙ»·Õè L14-1 ǧ¨Ãàª×Íè Áµ Í i-Stamp2P24 ¡ÑºâÁ´ÙÅ LCD Ẻ 4 ºÔµ '********************************************************************* ' Program : LAB1401.BSP ' Description : Basic LCD interfacing ' Hardware : Connect P12-P15 TO D4-D7 of LCD module ' Connect P11 TO RS PIN of LCD module ' Connect P10 TO R/W PIN of LCD module ' Connect P9 TO E PIN of LCD module '********************************************************************* ' {$STAMP BS2P} ' {$PBASIC 2.5} GOSUB INITLCD ' INITIAL BEFORE USE LCDOUT OR LCDIN COMMAND LOOP1: LCDCMD 9,$0C ' TURN DISPLAY ON LCDOUT 9,$80+0,["^_^ Hello,I am"] LCDOUT 9,$C0+0,["BASIC STAMP 2p"] PAUSE 500 LCDCMD 9,$08 ' Turn display off PAUSE 500 GOTO LOOP1 INITLCD: PAUSE 50 ' Delay 50 mS after VCC rise TO 4.5V LCDCMD 9,$30 ' Send wakeup sequence TO LCD PAUSE 5 ' These pauses are necessary TO meet the LCD specs LCDCMD 9,$30 PAUSE 1 ' Delay 1 millisecond LCDCMD 9,$30 PAUSE 1 ' Delay 1 millisecond LCDCMD 9,$20 ' Set buss TO 4-Bit mode LCDCMD 9,$28 ' Set TO 2-line mode with 5x8 font LCDCMD 9,$06 ' Set TO auto-increment cursor (no shift) LCDCMD 9,$01 ' Clear the display RETURN

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%%


14.4 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 áÅ ÇÃѹâ»Ãá¡ÃÁ Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§âÁ´ÙÅ LCD ·Õè˹ Ò¨ÍáÊ´§¼Å»ÃÒ¡¯¢ ͤÇÒÁ ^_^

Hello,I

BASIC

STAMP

am 2p

¾Ã ÍÁ¡Ñº¡Ð¾ÃÔº

¡Ò÷´ÅͧÊà ҧµÑÇÍÑ¡ÉõÒÁµ ͧ¡ÒÃŧº¹âÁ´ÙÅ LCD 14.5 Âѧ¤§ãª ǧ¨ÃÃÙ»·Õè L14-1 㹡Ò÷´Åͧ à¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB1402.BSP '********************************************************************* ' Program : LAB1402.BSP ' Description : Create character ON LCD module ' FOR : i-Stamp2P24 ' Hardware : Connect P12-P15 TO D4-D7 of LCD module ' Connect P11 TO RS PIN of LCD module ' Connect P10 TO R/W PIN of LCD module ' Connect P9 TO E PIN of LCD module '********************************************************************* ' {$STAMP BS2P} ' {$PBASIC 2.5} WakeUp CON %00110000 ' Wake-up FourBitMode CON %00100000 ' Set TO 4-Bit mode TwoLine5x8Font CON %00101000 ' Set TO 2 display lines, 5x8 font DisplayOff CON %00001000 ' Turn off display, DATA is retained DisplayOn CON %00001100 ' Turn ON display, no cursor IncCrsr CON %00000110 ' Auto-increment cursor,no display shif ClearDisplay CON %00000001 ' Clear the display MoveCrsr CON %10000000 ' Move cursor to position (must add address) INIT: GOSUB InitLCD START: LCDOUT 9,$40+(8*0),[$00,$00,$00,$12,$12,$12,$1B,$1B] ' Write character 0 @ADDR $00-$07 LCDOUT 9,$40+(8*1),[$00,$00,$01,$1F,$01,$0D,$13,$19] ' Write character 1 @ADDR $08-$0F LCDOUT 9,$40+(8*2),[$00,$00,$00,$0B,$15,$11,$15,$1D] ' Write character 2 @ADDR $10-$17 LCDOUT 9,$40+(8*3),[$00,$00,$00,$19,$19,$09,$1F,$19] ' Write character 3 @ADDR $18-$1F LCDOUT 9,$40+(8*4),[$0F,$0C,$01,$19,$19,$09,$09,$0F] ' Write character 4 @ADDR $20-$27 LCDOUT 9,$80+4,[0,1,2,3,4," 2p"] ' Show character 0-4 on LCD PAUSE 3000 ' LCDOUT 9,$40+(8*0),[$00,$00,$0A,$1F,$1F,$1F,$0E,$04] ' Write character 0 @ADDR $00-$07 STOP

%&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


INITLCD: PAUSE 100 LCDCMD 9,WakeUp PAUSE 10 LCDCMD 9,WakeUp PAUSE 1 LCDCMD 9,WakeUp PAUSE 1 LCDCMD 9,FourBitMode LCDCMD 9,TwoLine5x8Font LCDCMD 9,DisplayOff LCDCMD 9,DisplayOn LCDCMD 9,IncCrsr LCDCMD 9,ClearDisplay RETURN

' Send wakeup sequence to LCD ' These pauses are necessary to meet the LCD specs

' Set buss TO 4-Bit mode ' Set TO 2-line mode with 5x8 font ' Turn display off ' Turn display ON with blinking cursor ' Set TO auto-increment cursor (no display shift) ' Clear the display

14.6 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 áÅ ÇÃѹâ»Ãá¡ÃÁ Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§âÁ´ÙÅ LCD ·ÕËè ¹ Ò¨ÍáÊ´§¼Å»ÃÒ¡¯¢ ͤÇÒÁ áʵÁ» 2p 14.7 ·´Åͧ¹íÒà¤Ã×Íè §ËÁÒ ¢Í§ºÃ÷Ѵ¹ÕÍé Í¡ LCDOUT 9,$40+(8*0),[$00,$00,$0A,$1F,$1F,$1F,$0E,$04]

14.8 ¨Ò¡¹Ñ¹é ´Òǹ âËÅ´ãËÁ Í¡Õ ¤ÃÑ§é ¨ÐàËç¹Ç Ò ·ÕËè ¹ ҨͨÐáÊ´§¤íÒÇ Ò áʵÁ» 2p »ÃÐÁÒ³ 3 ÇÔ¹Ò·Õ ¨Ò¡¹Ñ¹é ¨ÐÁÕû٠ËÑÇã¨¢Ö¹é ·Õµè Òí á˹ § ¢Í§ÊÃÐáÍ ·Ñ§é æ ·Õãè ¹â»Ãá¡ÃÁäÁ ä´ Ê§Ñè ãË à¢Õ¹ÃÙ»ËÑÇã¨¹Õ·é ºÑ ·Õàè » ¹àª ¹¹Õàé ¹×Íè §¨Ò¡·Ø¡¤ÃÑ§é ·ÕÁè ¡Õ ÒÃà»ÅÕÂè ¹µÑÇÍÑ¡Éà ᷹·Õµè ÇÑ ÍÑ¡ÉÃà´ÔÁ ·Ø¡æµíÒá˹ §ã¹Ë¹ Ҩͷըè Ðà¤ÂáÊ´§µÑÇÍÑ¡Éá ͹˹ Ò¨Ðà»ÅÕÂè ¹ä»áÊ´§µÑÇÍÑ¡ÉÃãËÁ â´Â Íѵâ¹ÁÑµÔ à¹×Íè §¨Ò¡µÑǤǺ¤ØÁã¹âÁ´ÙÅ LCD ¨Ð·íÒ¡ÒÃÃÕà¿ÃªµÑÇàͧÍÂÙµ ÅÍ´àÇÅҹѹè àͧ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

%'


&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


º··Õè 12 ¡ÒÃ㪠§Ò¹ i-Stamp2p24 ¡ÑºÍØ»¡Ã³ ÃкººÑÊ I2C 㹺·¹Õ¹é Òí àʹÍÃÒÂÅÐàÍÕ´áÅÐà·¤¹Ô¤ÇÔ¸¡Õ ÒÃ㪠§Ò¹äÍ«Õ˹ Ò·Õ¾è àÔ ÈÉ·Õãè ª ¡ÒõԴµ ͼ Ò¹ÃкººÑÊ I2C ´ ǤÇÒÁÊÒÁÒö¾ÔàÈɢͧ i-Stamp2P24 ·ÕÁè ªÕ ´Ø ¤íÒÊÑ§è ¾ÔàÈÉÊíÒËÃѺ¡ÒõԴµ ͡ѺÍØ»¡Ã³ àËÅ Ò¹Õâé ´Â੾ÒÐ ·íÒãË ¡ÒÃ㪠§Ò¹äÍ«Õ˹ Ò·Õ¾è àÔ ÈÉàËÅ Ò¹Õ§é Ò ÂáÅÐÊдǡ¢Ö¹é Í ҧÁÒ¡ äÍ«Õ¾àÔ ÈÉ㹡ÅØÁ ¹Õ»é ÃСͺ´ Ç PCF8574A äÍ«Õ ¢ÂÒ¾Íà µÍÔ¹¾ØµàÍÒµ ¾µØ ¼ Ò¹ÃкººÑÊ I2C, DS1307 äÍ«ÕÊà ҧÊÑ­­Ò³¹ÒÌ ¡Ò°Ò¹àÇÅÒ¨ÃÔ§ËÃ×Í RTC (RealTime Clock) áÅÐ DS1621 äÍ«ÕÇ´Ñ ÍسËÀÙÁÔ

12.1 ¢ÂÒ¾Íà µÍÔ¹¾ØµàÍÒµ ¾µØ ¼ Ò¹ÃкººÑÊ I2C ´ ÇÂäÍ«Õ PCF8574A ¡ÒõԴµ ͡ѺäÍ«Õ˹ Ò·Õè¾ÔàÈÉ㹺·¹Õé·Ñé§ËÁ´¨Ð㪠¡ÒõԴµ ͼ Ò¹ÃкººÑʾÔàÈÉ·Õèª×èÍ I2C Íѹ໠¹ Áҵðҹ¢Í§Ê×èÍÊÒâ ÍÁÙÅã¹ÅѡɳÐ͹ءÃÁẺ˹Ö觷Õè㪠ÊÒÂÊÑ­­Ò³à¾Õ§ÊͧàÊ ¹¤×Í ÊÒÂÊÑ­­Ò³¹ÒÌ ¡Ò áÅÐÊÒ¢ ÍÁÙÅ áÅк¹ÃкººÑʹÕÊé ÒÁÒö¹íÒÍØ»¡Ã³ ࢠÒÁÒµÔ´µ Íä´ Í ҧÁÒ¡ÁÒ â´ÂÂѧ¤§ãª ÊÒÂÊÑ­­Ò³à¾Õ§ 2 àÊ ¹ ÊíÒËÃѺ·ÄɮաÒ÷íÒ§Ò¹¢Í§ÃкººÑÊ I2C Í ҧÊÃØ»´Ùä´ ã¹º··Õè 3 ËÑÇ¢ ͤíÒÊѧè I2CIN ª×Íè

µíÒá˹ §¢Ò

A0

1

ÍÔ¹¾ØµáÍ´à´ÃʵÑÇ·Õè 1

A1

2

ÍÔ¹¾ØµáÍ´à´ÃʵÑÇ·Õè 2

A2

3

ÍÔ¹¾ØµáÍ´à´ÃʵÑÇ·Õè 3

13 INT

P0

4

¾Íà µÍÔ¹¾ØµàÍÒµ ¾Øµ 2 ·ÔÈ·Ò§ºÔµ 0

5

12 P7

P1

5

¾Íà µÍÔ¹¾ØµàÍÒµ ¾Øµ 2 ·ÔÈ·Ò§ºÔµ 1

P2

6

11 P6

P2

6

¾Íà µÍÔ¹¾ØµàÍÒµ ¾Øµ 2 ·ÔÈ·Ò§ºÔµ 2

P3

7

10 P5

P3

7

¾Íà µÍÔ¹¾ØµàÍÒµ ¾Øµ 2 ·ÔÈ·Ò§ºÔµ 3

9

V55

8

¡ÃÒÇ´

P4

9

¾Íà µÍÔ¹¾ØµàÍÒµ ¾Øµ 2 ·ÔÈ·Ò§ºÔµ 4

P5

10

¾Íà µÍÔ¹¾ØµàÍÒµ ¾Øµ 2 ·ÔÈ·Ò§ºÔµ 5

P6

11

¾Íà µÍÔ¹¾ØµàÍÒµ ¾Øµ 2 ·ÔÈ·Ò§ºÔµ 6

P7

12

¾Íà µÍÔ¹¾ØµàÍÒµ ¾Øµ 2 ·ÔÈ·Ò§ºÔµ 7

INT

13

¢ÒàÍÒµ ¾ØµÍÔ¹àµÍà ÃÑ»µ (·íÒ§Ò¹·ÕèÅͨԡ 0)

SCL

14

¢ÒÊÑ­­Ò³¹ÒÌÔ¡ÒÊíÒËÃѺ I C ºÑÊ

SDA

15

¢Ò¢ ÍÁÙÅÊíÒËÃѺ I C ºÑÊ

V,,

16

ä¿àÅÕé§

A0

1

16 V++

A1

2

15 SDA

A2

3

14 SCL

P0

4

P1

GND 8

PCF8574A

P4

˹ Ò·Õè

ÃÙ»·Õè 12-1 ¡ÒèѴ¢ÒáÅÐ˹ Ò·Õ¡è Ò÷íÒ§Ò¹¢Í§äÍ«Õ PCF8574A Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&


12.1.1 ¢ ÍÁÙÅàº×Íé §µ ¹¢Í§ PCF8574A äÍ«Õ PCF8574A ÁÕ¤³ Ø ÊÁºÑµ´Ô §Ñ ¹Õé l ·íÒ§Ò¹·Õà è дѺáç´Ñ¹µÑ§é áµ 2.5V ¶Ö§ 6V l ¡Ô¹¡ÃÐáÊã¹ÊÀÒÇÐÊáµ¹´ ºÒµèÒí à¾Õ§ 10 mA l 㪠¡ÒÃàª×Í è Áµ ÍẺºÑÊ I2C l ÁÕàÍÒµ ¾µ Ø ÍÔ¹àµÍÃ Ã»Ñ µ Ẻà´Ã¹à» ´ l ÊÒÁÒöáŵª ËÃ×ͤ§¤ ÒàÍÒµ ¾µ Ø áŵª äÇ ä´ l ¢Ñº LED ä´ â´Âµ Íǧ¨Ãã¹ÅѡɳСÃÐáÊ«Ô§¡ ËÃ×Í·íÒ§Ò¹´ ÇÂÅͨԡ 0 l ¡íÒ˹´áÍ´à´ÃʢͧäÍ«Õáµ ÅеÑÇä´ ·Ò§ÎÒà ´áÇà ´Ç Â¢Ò A0 ¶Ö§ A2 ·íÒãË µÍ ¾ ǧ¡Ñ¹ä´ ¶§Ö 8 µÑÇ ¡ÒèѴ¢ÒáÅСÒ÷íÒ§Ò¹¢Í§áµ ÅТҢͧäÍ«Õ PCF8574A áÊ´§ã¹ÃÙ»·Õè 12-1 ¢Ò¾Íà µ¢Í§ PCF8574A ÊÒÁÒö¡íÒ˹´ãË à» ¹ÍÔ¹¾ØµËÃ×ÍàÍÒµ ¾µØ ä´ â´ÂÍÔÊÃÐâ´ÂäÁ ¨Òí à» ¹µ ͧ㪠¤íÒÊÑ§è ¤Çº¤ØÁ àÁ×Íè ¨ ÒÂä¿ãË ¡ºÑ PCF8574A ¤Ãѧé áá ¢Ò¾Íà µ·Ñ§é ËÁ´¨ÐÁÕÅͨԡ໠¹ 1 Íѹ໠¹¼Å¨Ò¡¡Òà ¨ Ò¡ÃÐáʢͧáËÅ §¨ Ò¡ÃÐáʤ§·ÕèÀÒÂã¹µÑÇäÍ«Õ ·íÒãË ÁÕ¡ÃÐáÊã¹¢³ÐÅͨԡ 1 ¹Õéà¾Õ§ 100 PA ¨Ö§äÁ àËÁÒзըè Ð㪠äÍ«Õ PCF8574A 㹡ÒâѺ¡ÃÐáÊ«ÍÃ Ê áµ ¨ÐàËÁÒСѺ¡ÒùíÒ仢Ѻ¡ÃÐáÊ«Ô§¡ ÁÒ¡¡Ç Ò àÁ×Íè µ ͧ¡ÒÃãË ¢Ò¾Íà µàËÅ Ò¹Õ·é Òí ˹ Ò·Õàè » ¹ÍÔ¹¾Øµ¨Ðµ Í§Ê §ÊÑ­­Ò³ãË ¢ÒàËÅ Ò¹ÕÁé ÅÕ Í¨Ô¡ 1 àÊÕ¡ ͹ àÁ×Íè ¢ÒÍÔ¹¾Øµä´ ÃºÑ ÊÑ­­Ò³¨Ò¡ÀÒ¹͡» ͹ࢠÒÁÒ äÍ«Õ PCF8574A ¨ÐÊà ҧÊÑ­­Ò³ÍÔ¹àµÍÃ Ã»Ñ µ (INT) » ͹ ãË äÁâ¤Ã¤Í¹â·ÃÅàÅÍÃ ÃºÑ ÃÙá ·¹¡Òõ ͧ¤ÍµÃǨÊͺ¢ÒÍÔ¹¾ØµÍÂÙµ ÅÍ´àÇÅÒ ÊÑ­­Ò³ÍÔ¹àµÍÃÃÑ»µ ¹¨Õé ж١ÃÕ à«µàÁ×Íè ÁÕ¡ÒÃÍ Ò¹¤ Ò¢ ÍÁÙÅËÃ×ÍÁÕ¡ÒÃà»ÅÕÂè ¹¤ ҢͧÍÔ¹¾Øµä»ÊÙ¤ Ò à´ÔÁ +5V

16 IC1 PCF8574A SDA SCL

R1 2k2

R2 2k2

5

P0

6

P1

i-Stamp2P24

8

ÃÙ»·Õè 12-2 ¡ÒÃàª×Íè Áµ Í i-Stamp2P24 ¡Ñº PCF8574A Ẻ¾×¹é °Ò¹ &

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


12.1.2 ¡ÒõԴµ ͡Ѻ PCF8574A ¢Í§ i-Stamp2P24 ÁÕµÇÑ Í ҧǧ¨ÃáÊ´§ã¹ÃÙ»·Õè 12-2 ¨Ø´à´ ¹¢Í§ i-Stamp2P24 ¤×ÍÊÒÁÒöàª×Íè Áµ ÍÍØ»¡Ã³ ÃкººÑÊ I2C ä´ â´ÂµÃ§·Ñ§é ÂѧÁÕª´Ø ¤íÒÊѧè ÃͧÃѺ´ Ç ¡ÒÃàª×Íè Áµ ͵ ͧ㪠¢Ò¾Íà µ·Õ¡è Òí ˹´¨Ö§ÊÒÁÒö㪠§Ò¹¤íÒÊÑ§è ¾ÔàÈÉ·ÕÁè äÕ ´ ÊíÒËÃѺ¡ÒõԴµ ͡Ѻ PCF8574A àÃÔÁè ´ Ç¡íÒ˹´¢Ò¾Íà µ·Õµè Í §¡Òà ¨Ò¡¹Ñ¹é à¢Õ¹â»Ãá¡ÃÁà¾×Íè ¡íÒ˹´ ¢ ÍÁÙÅáÍ´à´ÃÊãË ¶¡Ù µ ͧ µÒÁ´ ÇÂÃкØâËÁ´¡Ò÷íÒ§Ò¹Ç Òµ ͧ¡ÒÃÍ Ò¹ËÃ×Íà¢Õ¹¡Ñº PCF8574A â´Â¢ ÍÁÙÅ áÍ´à´ÃÊÁÕÃÒÂÅÐàÍÕ´´Ñ§¹Õé ºÔµ 7 ºÔµ 6 ºÔµ 5 ºÔµ 4 ºÔµ 3 ºÔµ 2 ºÔµ 1 ºÔµ 0 0

1

0

0

A2

A1

A0

R/W

ºÔµ A0, A1, A2 㪠ÃÐºØ PCF8574A µÑÇ·Õµè Í §¡ÒõԴµ Í â´Â¤ Ңͧ A0-A2 ¨Ð¡íÒ˹´·Ò§ ÎÒà ´áÇÃ Ê Ç¹ºÔµ R/W 㪠¡Òí ˹´Ç Òµ ͧ¡ÒÃÍ Ò¹ËÃ×Íà¢Õ¹¢ ÍÁÙšѺäÍ«Õ PCF8574A

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&!


¡Ò÷´Åͧ·Õè 15 ¢ÂÒ¾Íà µÍÔ¹¾ØµàÍÒµ ¾µØ ¼ Ò¹ÃкººÑÊ I2C ´ Ç PCF8574A à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³

1. i-Stamp2P 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. ÊÒµ Íǧ¨Ã 5. µÑǵ Ò¹·Ò¹à¹çµàÇÔá 10k: x4 (5 ¢Ò) 1 µÑÇ 6. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 220: 4 µÑÇ 7. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 2.2k: 2 µÑÇ 8. LED ÊÕá´§ 3 ÁÁ. 4 µÑÇ 9. ´Ô»ÊÇÔµª 4 ¨Ø´ 1 µÑÇ 10. äÍ«Õ PCF8574A 1 µÑÇ +5V

R1 2k2

i-Stamp2P24

16

R2 2k2

P0

5

P1

6

P3

SDA

P2

SCL

P1 P0

7 6

R6

5

R5

4

R4

1+ 2+.&#%") 3 2 1

A2

P7

A1

P6

A0

P5 P4

R4-R7 220 R7

LED4 "D3" LED3 "D2" LED2 "D1" LED1 "D0" +5V R3 10k x4

12

D3

11

D2

10

D1

9

D0 S1 DIP SW. x4

8

ÃÙ»·Õè L15-1 ǧ¨Ã·´Åͧ¡ÒâÂÒ¾Íà µãË á¡ i-Stamp2P24 ¼ Ò¹ÃкººÑÊ I2C â´Â㪠äÍ«Õ PCF8574A

&"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ 15.1 㪠ǧ¨Ãã¹ÃÙ»·Õè L15-1 㹡Ò÷´Åͧ â´Âµ Íǧ¨Ãŧº¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ 15.2 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB15.1.BSP '********************************************************** ' Program : LAB1501.BSP ' Description : PCF8574A demonstration ' Hardware : See schematic in figure L15-1 '********************************************************** ' {$STAMP BS2P} ' {$PBASIC 2.5} ID_READ CON %01110001 ' SLAVE ID , R/W Bit = 1 <READ> ID_WRITE CON %01110000 ' SLAVE ID , R/W Bit = 0 <WRITE> BUFFER VAR Byte ' For data input and output IN: I2COUT 0,ID_WRITE,[$FF] ' Turn off LED & clear latch I2CIN 0,ID_READ,[BUFFER] ' Read input OUT: BUFFER.NIB1 = BUFFER.NIB0 ' Swap nibble high & low I2COUT 0,ID_WRITE,[BUFFER] ' Write output GOTO IN

15.3 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 15.4 àÅ×Íè ¹´Ô»ÊÇÔµª ãË ÍÂÙã ¹µíÒá˹ § OFF ·Ñ§é ËÁ´ Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED ¨Ò¡¹Ñ¹é à»ÅÕÂè ¹¤ Ңͧ´Ô»ÊÇÔµª áÅ ÇÊѧࡵ¡Ò÷íÒ§Ò¹¢Í§ LED ÍÕ¡¤Ãѧé àÁ×Íè Ãѹâ»Ãá¡ÃÁ LED ·Ñ§é 4 ´Ç§´ÑºËÁ´ àÁ×Íè àÅ×Íè ¹ÊÇÔµª µÇÑ ã´ÁÒÂѧµíÒá˹ § ON ¨Ð·íÒãË LED ã¹ µíÒá˹ §·Õµè ç¡ÑºÊÇÔµª µ´Ô ÊÇ Ò§ 㹤ÇÒÁà» ¹¨ÃÔ§ ¡Òà ON ¢Í§ÊÇÔµª ¤Í× ¡Òõ ÍÊÇÔµª ŧ¡ÃÒÇ´ ·íÒãË à¡Ô´Åͨԡ 0 à¹×Íè §¨Ò¡ LED ·Ñ§é 4 ´Ç§µ ͡Ѻ PCF8574A ã¹ÅѡɳТѺ´ Ç¡ÃÐáÊ«Ô§¡ ¨Ö§·íÒãË LED µÔ´¢Ö¹é à¹×Íè §¨Ò¡ÁÕ Åͨԡ 0 ¨Ò¡ÊÇÔµª ʧ ä»ÂѧàÍÒµ ¾µØ ¢Í§ PCF8574A ¹Ñ¹è àͧ ã¹·Ò§µÃ§¢ ÒÁÊÇÔµª ·àÕè » ´Ç§¨ÃÍÂÙ¨ ÐÁÕ¤Ò à» ¹ 1 ·íÒãË LED ´Ñº ¡Ò÷´Åͧ¹Õàé » ¹¡ÒÃáÊ´§ãË àË繶֧¡ÒÃ㪠§Ò¹ PCF8574A à¾×Íè à¾ÔÁè ¾Íà µÍÔ¹¾ØµáÅÐàÍÒµ ¾µØ Í ҧÅÐ 4 ºÔµ ãË á¡ i-Stamp2P24 ¤íÒÊѧè I2CIN áÅÐ I2COUT ¢Í§ i-Stamp2P24 ¹Ñ¹é ¹Í¡¨Ð㪠§Ò¹ä´ §Ò ÂáÅ Ç ÂѧÁÕ¢Í ´ÕÍ¡Õ ¢ ÍË¹Ö§è ¤×Í ÊÒÁÒö¡íÒ˹´ºÔµ R/W ä´ ÍµÑ â¹ÁÑµÔ ¡Å ÒǤ×Í ¶ Ò㪠¤Òí Êѧè I2CIN i-Stamp2P24 ¨Ð¡íÒ˹´ãË ºµÔ ¹Õàé » ¹ 1 à¾×Íè Í Ò¹¢ ÍÁÙŨҡÍØ»¡Ã³ ÊàÅ¿ áÅж Òà» ¹¤íÒÊѧè I2COUT ¨Ð¡íÒ˹´ºÔµ¹Õãé Ë à» ¹ 0 à¾×Íè à¢Õ¹¢ ÍÁÙÅä»ÂѧÍØ»¡Ã³ ÊàÅ¿ ÊÒÁÒö·´ÅÍ§ä´ â´Â¡ÒÃà»ÅÕÂè ¹â»Ãá¡ÃÁ¨Ò¡¤ Ò ID_WRITE à» ¹ ID_READ áÅШҡ ID_READ à» ¹ ID_WRITE ¨Ò¡¹Ñ¹é ´Òǹ âËÅ´ áÅ Ç·´ÅͧãËÁ Í¡Õ ¤ÃÑ§é ¨Ð¾ºÇ Ò ä´ ¼Å¡Ò÷íÒ§Ò¹·Õàè ËÁ×͹¡Ñ¹ i-Stamp2p24

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&#


12.2 DS1307 äÍ«ÕÊà ҧ°Ò¹àÇÅÒ¨ÃÔ§ËÃ×ÍÃÕÅä·Á ¤ÅçÍ¡ (RTC) ¼Ù¼ ÅÔµ¤×Í ´ÑÅÅÑÊà«ÁԤ͹´Ñ¡àµÍà (Dallas semiconductor) ÁÕ˹ Ò·ÕÊè à ҧ°Ò¹àÇÅÒ¨ÃÔ§ãË á¡ ÃкºäÁâ¤Ã ¤Í¹â·ÃÅàÅÍà â´Â DS1307 ¨ÐãË ¢Í ÁÙÅà¡ÕÂè ǡѺàÇÅҷѧé ËÁ´ äÁ ÇÒ ¨Ðà» ¹¤ ҢͧàÇÅÒ·ÕÅÐàÍÕ´¶Ö§ËÅÑ¡ÇÔ¹Ò·Õ, ¹Ò·Õ, ªÑÇè âÁ§, Çѹ·Õè (date), Çѹã¹ÊÑ»´ÒË (day), à´×͹ áÅл â´ÂÊÒÁÒö»ÃѺÇѹà´×͹» ãË µÃ§µÒÁ»¯Ô·¹Ô ä´ Í ҧ¶Ù¡µ ͧ ÃÇÁ¶Ö§¡ÒáíÒ˹´Çѹ㹻 ͸ԡÊØ÷Թ´ Ç ¤Ø³ÊÁºÑµ·Ô ҧ෤¹Ô¤·ÕÊè Òí ¤Ñ­ÁÕ´§Ñ ¹Õé l à» ¹äÍ«ÕÃÅ Õ ä·Á ¤ÅçÍ¡ãË ¢Í ÁÙŵѧé áµ Ç¹Ô Ò·Õ¨¹¶Ö§» ÃÇÁ¶Ö§¡ÒûÃѺÇѹ㹻 ͸ԡÊØ÷Թ´ Ç ÊÒÁÒö ãË ¢Í ÁÙÅàÇÅÒä´ Í ҧà·ÕÂè §µÃ§¶Ö§» ¤ÃÔʵÈÑ¡ÃÒª 2100 l ÁÕ˹ ǤÇÒÁ¨íҹ͹âÇÅÒä·Å áÃÁ 56 亵 ÍÂÙÀ ÒÂã¹ ÊÒÁÒö㪠à¡çº¢ ÍÁÙÅ·ÑÇè ä»ä´ l 㪠¡ÒÃàª×Í è Áµ ÍẺÃкººÑÊ I2C l ÁÕǧ¨ÃµÃǨ¨Ñºä¿àÅÕÂ é §µèÒí ËÃ×ÍËÒÂä»Í ҧÍѵâ¹ÁÑµÔ ÃÑ¡ÉÒ¢ ÍÁÙÅàÇÅÒäÇ ä´ áÁ äÁ ÁäÕ ¿àÅÕÂé §äÍ«Õ ã¹ÃÙ»·Õè 12-3 áÊ´§¡ÒèѴ¢Ò¢Í§ DS1307 áÅÐ˹ Ò·Õáè ÅСÒÃ㪠§Ò¹

12.2.1 ¡Ò÷íÒ§Ò¹¢Í§ DS1307

äÍ«Õ DS1307 ¨Ñ´¡ÒÃàª×Íè Áµ Íã¹áºººÑÊ I2C â´Â¨Ð·íҧҹ໠¹ÍØ»¡Ã³ ÊàÅ¿àÊÁÍ ã¹ÃÙ»·Õè 12-4 áÊ´§ Ê Ç¹»ÃСͺËÅÑ¡·ÕèÊíҤѭáÅÐä´ÍÐá¡ÃÁ¡Ò÷íÒ§Ò¹¢Í§ DS1307 ǧ¨ÃÍÍÊ«ÔÅàÅàµÍà ¶×Íà» ¹ËÑÇã¨ËÅÑ¡¢Í§ äÍ«Õ à¹×Íè §¨Ò¡à» ¹¨Ø´àÃÔÁè µ ¹¢Í§¡ÒÃÊà ҧ¢ ÍÁÙÅàÇÅÒ¨ÃÔ§ ã¹¢³Ð·Õè DS1307 ·íÒ§Ò¹·Õ¢è Ò SQW OUT ¨ÐÁÕÊ­ Ñ ­Ò³ ¾ÑÅÊ ÊàÕè ËÅÕÂè ÁÊ §ÍÍ¡ÁÒ㹡óշÁÕè ¡Õ ÒÃàÍç¹àÍàºÔÅǧ¨Ã¡íÒà¹Ô´ÊÑ­­Ò³¾ÑÅÊ ·ÃÕè ¨Õ ÊÔ àµÍà ¤Çº¤ØÁ ¾Ã ÍÁ¡Ñ¹¹Ñ¹é ¡ç¨Ð ÁÕ¡ÒÃà¡çº¤ ҢͧàÇÅÒäÇ ã¹Ë¹ ǤÇÒÁ¨íҹ͹âÇÅÒä·Å áÃÁ 64 亵 ¨Ñ´ÊÃÃãË ãª à¡çº¢ ÍÁÙÅàÇÅÒ 8 亵 áÅÐ à» ¹Ë¹ ǤÇÒÁ¨íÒÊíÒËÃѺà¡çº¢ ÍÁÙÅ·ÑÇè ä»ÊíÒËÃѺ¼Ùã ª §Ò¹ÍÕ¡ 56 亵 X1

1

X2

2

V*)6

3

GND 4

DS1307

8

Vcc

7 6

SQW OUT SCL

5

SDA

VCC, GND (¢Ò 8, 4) µ ͡Ѻä¿àÅÕÂé § +5V VBAT (¢Ò 3) 㪠µ ͡ѺẵàµÍÃÕè 3V à¾×èÍãË Ç§¨ÃÊà ҧ°Ò¹àÇÅҢͧ DS1307 ·íÒ§Ò¹µ Íä» áÁ ÇÒ äÁ ÁäÕ ¿àÅÕÂé §¨ ÒÂãË á¡ DS1307 ª¹Ô´¢Í§ ẵàµÍÃÕè·ÕèàËÁÒÐÊÁ¤×Í áºµàµÍÃÕèẺÅÔà¸ÕÂÁ «Öè§ÁÕ¤ÇÒÁ¨Ø 40mAH ËÃ×ÍÁÒ¡¡Ç Ò ÃÑ¡ÉÒ¢ ÍÁÙÅä´ ¹Ò¹ 10 » ·ÍÕè ³ Ø ËÀÙÁÔ 25 ͧÈÒà«Åà«ÕÂÊ SDA, SCL (¢Ò 5 áÅÐ 6) à» ¹¢Òàª×Íè Áµ ͡ѺÃкººÑÊ I2C SQW OUT (¢Ò 7) ·Õè¢Ò¹Õé¨ÐÁÕÊÑ­­Ò³ÃÙ»ÊÕèàËÅÕèÂÁÊ §ÍÍ¡ÁÒ â´Â ÊÒÁÒöàÅ×Í¡¤ÇÒÁ¶Õäè ´ 1Hz, 4.096kHz, 8.192kHz áÅÐ 32kHz ã¹ ¡ÒÃ㪠§Ò¹µ ͧµ ͵Ñǵ Ò¹·Ò¹ 1k ¾ÙÅÍÑ»·Õ¢è Ò¹Õ´é Ç Â X1, X2 (¢Ò 1 áÅÐ 2) 㪠µÍ ¡Ñº¤ÃÔʵÍŤÇÒÁ¶ÕÁè ҵðҹ 32.768kHz à¾×èÍ㪠໠¹°Ò¹àÇÅÒ㹡ÒÃÊà ҧ¤ ÒàÇÅÒ¨ÃÔ§ ·Õèáµ ÅТҵ ͧµ ͵ÑÇà¡çº »ÃÐ¨Ø¤Ò µèÒí æ »ÃÐÁÒ³ 15pF ¤Ã ÍÁ¡Ñº¢Ò¡ÃÒÇ´ ´Ç Â

ÃÙ»·Õè 12-3 ¡ÒèѴ¢Ò¢Í§äÍ«Õ DS1307 &$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


ǧ¨ÃÍÍÊ«ÔÅàÅàµÍà áÅÐǧ¨ÃËÒäÇÒÁ¶Õè

46+

SQW/ OUT

ǧ¨Ã¤Çº¤ØÁ ÊÑ­­Ò³ÊÕàè ËÅÕÂè Á

Vcc Vss VBAT

ǧ¨Ã¤Çº¤ØÁ ¾Åѧ§Ò¹

Ê Ç¹¤Çº¤ØÁÅͨԡ

SCL SDA

ǧ¨ÃÊ×Íè ÊÒà Ẻ͹ءÃÁ

µÑǪÕáé Í´à´ÃÊ

˹ ǤÇÒÁ¨íÒáÃÁ 56 亵 ÊíÒËÃѺ㪠§Ò¹·ÑÇè ä»

ÃÙ»·Õè 12-4 â¤Ã§Êà ҧÀÒÂ㹢ͧäÍ«ÕÃÅÕ ä·Á ¤ÅçÍ¡àºÍà DS1307 ǧ¨Ã¤Çº¤ØÁ¾Åѧ§Ò¹ä¿¿ ҨФ͵ÃǨÊͺÊÀÒÇТͧä¿àÅÕÂé §äÍ«Õ ËÒ¡µèÒí ¡Ç Ò 1.25 N VBAT ¨Ð¤Çº¤ØÁãË DS1307 ËÂØ´·íÒ§Ò¹ ÃÕ૵¤ ÒµÑǹѺáÍ´à´ÃÊÀÒÂã¹ ·íÒãË µ´Ô µ ͡Ѻ DS1307 äÁ ä´ ´Ñ§¹Ñ¹é µ ͧÃÐÁÑ´ÃÐÇѧÍ ÒãË ä¿àÅÕÂé §µèÒí ¡Ç Ò 1.25 N VBAT ËÃ×Í»ÃÐÁÒ³ 3.75V 㹡óշãÕè ª VBAT ෠ҡѺ 3V ¶ ÒËÒ¡ä¿àÅÕÂé §ÁÕ¤Ò µèÒí ¡Ç Ò VBAT äÍ«Õ DS1307 ¨ÐࢠÒÊÙâ ËÁ´ÊíÒÃͧ¢ ÍÁÙŷѹ·Õ äÁ Á¡Õ ÒÃÊ §ÊÑ­­Ò³¾ÑÅÊ ÍÍ¡ÁÒ·Õ¢è Ò SQW OUT ᵠǧ¨ÃÊà ҧ°Ò¹àÇÅÒ Âѧ·íÒ§Ò¹à¾×Íè ãË ¤Ò àÇÅÒà´Ô¹µ Íä» àÁ×Íè ä¿àÅÕÂé §»ÃÒ¡¯¢Ö¹é ÍÕ¡¤Ãѧé DS1307 ¡ç¨ÐãË ¤Ò ¢Í§àÇÅÒá¡ ¼ãÙ ª §Ò¹ä´ µÍ ä» Ç§¨ÃÊ×Íè ÊÒÃ͹ءÃÁÀÒÂã¹ DS1307 ä´ ÃºÑ ¡ÒáíÒ˹´ãË ·Òí §Ò¹µÒÁÃٻẺ¢Í§ºÑÊ I2C à» ¹ª ͧ·Ò§ ¡ÒÃÊ×Íè ÊÒÃÃÐËÇ Ò§ DS1307 ¡ÑºÍØ»¡Ã³ ÁÒÊàµÍÃ

12.2.2 ¡ÒèѴÊÃÃ˹ ǤÇÒÁ¨íÒã¹ DS1307 ã¹ÃÙ»·Õè 12-5 (¡) áÊ´§¡ÒèѴÊÃÃ¾×¹é ·ÕËè ¹ ǤÇÒÁ¨íÒÀÒÂã¹ DS1307 ¾×¹é ·Õè 7 亵 ááµÑ§é áµ áÍ´à´ÃÊ $00 ¶Ö§ $06 à» ¹¾×¹é ·Õ¢è ͧÃÕ¨ÊÔ àµÍà ¤Ò àÇÅÒ㪠ã¹à¡çº¢ ÍÁÙÅà¡ÕÂè ǡѺàÇÅÒ äºµ µÍ ÁÒ·Õáè Í´à´ÃÊ $07 à» ¹¾×¹é ·Õè ¢Í§ÃÕ¨ÊÔ àµÍà ¤Çº¤ØÁ¡Ò÷íÒ§Ò¹¢Í§ DS1307 ã¹ÃÙ»·Õè 12-5 (¢) áÊ´§ÃÒÂÅÐàÍÕ´¢Í§ÃÕ¨ÊÔ àµÍà ¤Ò àÇÅÒáÅÐÃÕ¨ÊÔ àµÍà ¤Çº¤ØÁ¢Í§ DS1307 ´ Ç¡ÒèѴÊÃÃ¾×¹é ·Õáè ºº¹Õé ·íÒãË ÊÒÁÒöàÃÕ¡¢ ÍÁÙÅàÇÅÒÍÍ¡ÁÒä´ µÒÁ·Õµè Í §¡Òà â´ÂäÁ ¨Òí à» ¹µ Í§Í Ò¹ÍÍ¡ Áҷѧé ËÁ´¡çä´ ¤ ҢͧàÇÅҷѧé ËÁ´¨ÐÍÂÙã ¹ÃÙ»¢Í§àÅ¢°Ò¹ÊÔº ÊíÒËÃѺ¡ÒÃáÊ´§àÇÅÒã¹ÃÙ»¢Í§ªÑÇè âÁ§ ÊÒÁÒöàÅ×Í¡ ä´ ÇÒ µ ͧ¡ÒÃẺ 12 ËÃ×Í 24 ªÑÇè âÁ§ â´Â¡íÒ˹´·Õºè µÔ 6 ¢Í§áÍ´à´ÃÊ 02H áÅÐàÁ×Íè àÅ×͡Ẻ 12 ªÑÇè âÁ§ ·Õºè µÔ 5 ã¹áÍ´à´ÃÊà´ÕÂǡѹ¨Ð㪠㹡ÒÃáÊ´§¤ Ò AM/PM â´Â¶ ÒºÔµ¹Õàé » ¹ 1 ËÁÒ¶֧ ¤ ÒªÑÇè âÁ§ã¹¢³Ð¹Õàé » ¹ª ǧ àÇÅÒËÅѧà·ÕÂè §Çѹ 㹡óշàÕè » ¹áºº 24 ªÑÇè âÁ§ ºÔµ¹Õ¨é Ð㪠㹡ÒÃáÊ´§¤ Ò 2 ¢Í§ËÅÑ¡ÊÔºã¹Ë¹ ǪÑÇè âÁ§

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&%


%

ÇÔ¹Ò·Õ ¹Ò·Õ ªÑÇè âÁ§ Çѹ Çѹ·Õè à´×͹ » ÃÕ¨ÊÔ àµÍà ¤Çº¤ØÁ

ºÔµ 7

&

áÃÁ 56 亵

ºÔµ 6

ºÔµ 5

ºÔµ 4

ºÔµ 3

ºÔµ 0

¤ Ңͧ¢ ÍÁÙÅ

¢ ÍÁÙÅÇÔ¹Ò·Õ (ËÅÑ¡ÊÔº)

¢ ÍÁÙÅÇÔ¹Ò·Õ (ËÅѡ˹ ÇÂ)

00-59

x

¢ ÍÁÙÅ¹Ò·Õ (ËÅÑ¡ÊÔº)

¢ ÍÁÙÅ¹Ò·Õ (ËÅѡ˹ ÇÂ)

00-59 01-12 00-23 1-7

x

12 ªÑÇè âÁ§ 24 ªÑÇè âÁ§

ªÑÇè âÁ§ (ËÅÑ¡ÊÔº) AM/PM

¢ ÍÁÙŪÑÇè âÁ§ (ËÅÑ¡ÊÔº)

x

x

x

x

x

x

x

x

OUT

¢ ÍÁÙŪÑèÇâÁ§ (ËÅѡ˹ ÇÂ)

x

x

x

¢ ÍÁÙÅÇѹã¹ÊÑ»´ÒË

x

¢ ÍÁÙÅÇѹ·Õè (ËÅѡ˹ ÇÂ)

¢ ÍÁÙÅÇѹ·Õè (ËÅÑ¡ÊÔº) ¢ ÍÁÙÅà´×͹ (ËÅÑ¡ÊÔº) SQWE

x

01-28/29 01-30 01-31

¢ ÍÁÙÅà´×͹ (ËÅѡ˹ ÇÂ)

01-12

¢ ÍÁÙÅ» (ËÅѡ˹ ÇÂ)

00-99

x

RS1

RS0

(¢)

(¡) ÃÙ»·Õè 12-5

ºÔµ 1

CH

¢ ÍÁÙÅ» (ËÅÑ¡ÊÔº) !.

ºÔµ 2

(¡) ¡ÒèѴÊÃÃ˹ ǤÇÒÁ¨íÒáÃÁÀÒÂã¹ DS1307 (¢) ÃÒÂÅÐàÍÕ´¢Í§ÃÕ¨ÊÔ àµÍà à¡çº¤ ÒàÇÅÒáÅÐÃÕ¨ÊÔ àµÍà ¤Çº¤ØÁ¢Í§ DS1307

12.2.3 ÃÕ¨ÊÔ àµÍà ¤Çº¤ØÁ ÁÕáÍ´à´ÃÊÍÂÙ· Õè $07 ÁÕÃÒÂÅÐàÍÕ´¢Í§áµ ÅкԵ´Ñ§¹Õé OUT (Output control) : 㪠¤Çº¤ØÁÃдѺÅͨԡ·Õ¢è Ò SQW OUT 㹡óշ´Õè ÊÔ àÍàºÔÅ¡ÒáíÒà¹Ô´ ÊÑ­­Ò³ÊÕàè ËÅÕÂè Á ¶ ÒºÔµ¹Õàé » ¹ 1 ·Õ¢è Ò SQW OUT ¨Ðà» ¹ 1 ¶ Òà» ¹ 0 ·Õ¢è Ò SQW OUT ¡ç¨Ðà» ¹ 0 SQWE (Square Wave Enable) : 㪠àÍç¹àÍàºÔÅǧ¨Ã¡íÒà¹Ô´ÊÑ­­Ò³ÊÕàè ËÅÕÂè Á·Õ¢è Ò SQW OUT ¶ Òµ ͧ ¡ÒÃãË ÁÊÕ ­ Ñ ­Ò³ÊÕàè ËÅÕÂè ÁÍÍ¡ãË ¡Òí ˹´ºÔµ¹Õàé » ¹ 1 RS1, RS0 (Rate Select) : 㪠àÅ×Í¡¤ÇÒÁ¶Õ¢è ͧÊÑ­­Ò³ÊÕàè ËÅÕÂè Á·Õ¢è Ò SQW/OUT RS1 0 0 1 1

RS0 0 1 0 1

¤ Ò¤ÇÒÁ¶Õè¢Í§ÊÑ­­Ò³ÊÕèàËÅÕèÂÁ 1Hz 4.096kHz 8.192kHz 32.768kHz

12.2.4 âËÁ´¡Ò÷íÒ§Ò¹¢Í§ DS1307 ÁÕ 2 âËÁ´¤×Í âËÁ´à¢Õ¹¢ ÍÁÙÅ áÅÐ âËÁ´Í Ò¹¢ ÍÁÙŠ㹡ÒÃ㪠§Ò¹µÒÁ»¡µÔ¨Ð㪠§Ò¹à©¾ÒÐâËÁ´ Í Ò¹¢ ÍÁÙÅ෠ҹѹé à¹×Íè §¨Ò¡äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ¨ÐµÔ´µ ͡Ѻ DS1307 à¾×Íè Í Ò¹¢ ÍÁÙŢͧàÇÅÒä»ãª §Ò¹ âËÁ´ ¡ÒÃà¢Õ¹¢ ÍÁÙŨж١㪠§Ò¹¡çµ ÍàÁ×è͵ ͧ¡ÒõÑ駤 ÒàÇÅÒãËÁ áÅе ͧ¡ÒÃà¢Õ¹¢ ÍÁÙÅŧã¹Ë¹ ǤÇÒÁ¨íÒ㪠§Ò¹ ·ÑÇè ä» Í ҧäáçµÒÁàÁ×Íè àÃÔÁè µ ¹µÔ´µ ͡Ѻ DS1307 ¨íÒà» ¹Í ҧÂÔ§è ·Õ¨è е ͧࢠÒÊÙâ ËÁ´¡ÒÃà¢Õ¹¢ ÍÁÙÅ¡ ͹à¾×Íè ¡íÒ˹´áÍ´à´ÃÊ·Õèµ Í§¡ÒÃÍ Ò¹¢ ÍÁÙÅ ¨Ò¡¹Ñ鹨֧à»ÅÕè¹âËÁ´¡Ò÷íÒ§Ò¹ÁÒà» ¹âËÁ´¡ÒÃÍ Ò¹¢ ÍÁÙŵ Íä»

&&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


ÊÀÒÇÐ àÃÔÁè µ ¹

5

¢ ÍÁÙÅ¡íÒ˹´ R/W áÍ´à´ÃÊ

)

áÍ´à´ÃÊ ¢Í§áÃÁ

NNNNNNNN

¢ ÍÁÙÅ

)

NNNNNNNN

ÊÀÒÇÐ ËÂØ´

¢ ÍÁÙÅ

)

NNNNNNNN

)

2

¢ ÍÁÙÅ·Õàè ¢Õ¹ä»Âѧ DS1307 ¾Ã ÍÁÊÑ­­Ò³µÍºÃѺ

ÃÙ»·Õè 12-6 ÃٻẺ¢Í§¢ ÍÁÙÅÊíÒËÃѺµÔ´µ ͡Ѻ DS1307 ã¹âËÁ´¡ÒÃà¢Õ¹¢ ÍÁÙÅ ÊÀÒÇÐÊÔé¹ÊØ´¡ÒÃÍ Ò¹ ÊÀÒÇÐ àÃÔèÁµ ¹

5

¢ ÍÁÙÅ¡íÒ˹´ R/W áÍ´à´ÃÊ

)

¢ ÍÁÙÅ

NNNNNNNN

¢ ÍÁÙÅ

)

NNNNNNNN

ÊÀÒÇÐ ËÂØ´

¢ ÍÁÙÅ

)

NNNNNNNN

)

2

¢ ÍÁÙÅ·ÕèÍÍ¡¨Ò¡ DS1307 ¾Ã ÍÁÊÑ­­Ò³µÍºÃѺ

ÃÙ»·Õè 12-7 ÃٻẺ¢Í§¢ ÍÁÙÅÊíÒËÃѺµÔ´µ ͡Ѻ DS1307 ã¹âËÁ´¡ÒÃÍ Ò¹¢ ÍÁÙÅ 12.2.4.1 âËÁ´¡ÒÃà¢Õ¹¢ ÍÁÙÅ ÁÕû٠Ẻ´Ñ§ã¹ÃÙ»·Õè 12-6 àÃÔÁè µ ¹àÁ×Íè äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ·Òí ¡ÒáíÒ˹´ÊÀÒÇÐàÃÔÁè µ ¹ (START :S) ¨Ò¡¹Ñ¹é Ê §¢ ÍÁÙÅ¡íÒ˹´áÍ´à´ÃÊ 1101000 µÒÁ´ Ç¢ ÍÁÙÅàÅ×Í¡¡ÒÃà¢Õ¹ ¹Ñ¹è ¤×ͤ Ò 0 ¨Ò¡¹Ñ¹é ¨ÐÃÍ¡ÒõͺÃѺ¨Ò¡ DS1307 ¢Ñ¹é µÍ¹µ ÍÁÒ¤×Í Ê §¢ ÍÁÙÅà¾×Íè àÅ×Í¡áÍ´à´ÃÊ·Õµè Í §¡ÒÃà¢Õ¹ ¨Ò¡¹Ñ¹é ÃÍ¡ÒõͺÃѺ¨Ò¡ DS1307 àÁ×Íè ÁÕ¡ÒõͺÃѺÁÒàÃÕºà Í ¡çàÃÔÁè ·ÂÍÂà¢Õ¹¢ ÍÁÙÅŧ令Ãѧé ÅÐáÍ´à´ÃÊ ËÅѧ¨Ò¡à¢Õ¹¢ ÍÁÙÅã¹áµ ÅÐáÍ´à´ÃÊ ¨Ðµ ͧËÂØ´ÃÍ¡ÒõͺÃѺ¨Ò¡ DS1307 ·Ø¡¤ÃÑ§é ¨Ö§¨ÐÊÒÁÒöà¢Õ¹¢ ÍÁÙŵ Íä»ä´ àÁ×Íè à¢Õ¹àÃÕºà ÍÂáÅ ÇãË Ê§ ÊÀÒÇÐËÂØ´ (STOP : P) à» ¹ÍѹÊÔ¹é ÊØ´¡Ãкǹ¡ÒÃà¢Õ¹¢ ÍÁÙÅ

12.2.4.2 âËÁ´¡ÒÃÍ Ò¹¢ ÍÁÙÅ ÁÕû٠ẺáÊ´§ã¹ÃÙ»·Õè 12-7 àÃÔÁè µ ¹¡Ò÷íÒ§Ò¹àËÁ×͹¡ÑºâËÁ´¡ÒÃà¢Õ¹¢ ÍÁÙŤ×Í äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ¡íÒ˹´ÊÀÒÇÐàÃÔÁè µ ¹áÅ ÇÊ §¢ ÍÁÙÅ¡íÒ˹´áÍ´à´ÃʵÒÁ´ Ç¢ ÍÁÙÅàÅ×Í¡¡ÒÃÍ Ò¹ «Ö§è ෠ҡѺ 1 ¨Ò¡¹Ñ¹é ÃÍ¡Òõͺ ÃѺ¨Ò¡ DS1307 àÁ×Íè µÍºÃѺàÃÕºà Í DS1307 ¨Ð·ÂÍÂÊ §¢ ÍÁÙÅÍÍ¡ÁÒãË äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ¤ÃÒÇÅÐ 1 áÍ´à´ÃÊËÃ×Í 1 亵 â´ÂáÍ´à´ÃÊ·Õàè Å×Í¡Í Ò¹¢ ÍÁÙŨе ͧÁÕ¡ÒáíÒ˹´ÁÒ¡ ͹Šǧ˹ Ò´ ÇÂâËÁ´¡ÒÃà¢Õ¹¢ ÍÁÙÅ ÇÔ¸¡Õ Òç ÒÂæ ¤×Í à¢ ÒÊÙâ ËÁ´¡ÒÃà¢Õ¹¢ ÍÁÙÅ¡ ͹ àÁ×Íè ¶Ö§¨Ñ§ËÇзյè Í §à¢Õ¹¢ ÍÁÙÅ ãË ·Òí ¡ÒÃÊà ҧÊÀÒÇÐàÃÔÁè µ ¹áÅÐ Ê §¢ ÍÁÙÅ¡íÒ˹´áÍ´à´ÃÊãËÁ Í¡Õ ¤ÃÑ§é µÒÁ´ ÇÂàÅ×Í¡âËÁ´¡ÒÃÍ Ò¹¢ ÍÁÙÅ ¢ ÍÁÙÅ·ÕÍè Í¡ÁÒ¨Ò¡ DS1307 ¡ç¨Ðà» ¹ ¢ ÍÁÙŨҡáÍ´à´ÃÊ·Õ¡è Òí ˹´äÇ ¡Í ¹Ë¹ Ò¹Õé

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

&'


¡Ò÷´Åͧ·Õè 16 ¹ÒÌ ¡Ò´Ô¨µÔ ÍÅ©ºÑºàºÊÔ¡áʵÁ» 2P à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³

1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. âÁ´ÙÅ LCD 16 µÑÇÍÑ¡Éà 2 ºÃ÷Ѵ 5. ÊÒµ Íǧ¨Ã 6. äÍ«Õ DS1307 1 µÑÇ 2 µÑÇ 7. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 2.2k: 8. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 10k: 3 µÑÇ 1 µÑÇ 9. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 1k: 10. ¤ÃÔʵÍÅ 32.768kHz 1 µÑÇ 11. µÑÇà¡çº»ÃÐ¨Ø 15pF 50V à«ÃÒÁÔ¡ 2 µÑÇ 12. ÊÇÔµª ¡´µÔ´»Å Í´Ѻ 3 µÑÇ 13. ẵàµÍÃÕè 3V (1.5V Ẻ AA 2 ¡ ͹) 1 ªØ´ 14. ¡ÐºÐ¶ Ò¹ÊíÒËÃѺãÊ áºµàµÍÃÕè AA 2 ¡ ͹ 1 µÑÇ +5V +5V

2 P11 P10

R6 10k

R5 10k

P9

R4 10k P2 P4

P12

P5

P13

i-Stamp2P24 S3

S1

S2

SHIFT

UP

SET/ ENTER

4 RS 5 R/W 6 E

3

DSP1 LCD 16x2

D4 D5 D6 D7 1 11 12 13 14

R4 1k

P14 P15 +5V

P1 P0

R2,R3 2.2k

+5V R1 4.7k 8 6 5

SCL SDA

+VB

IC1 DS1307

1

C1 15pF

SQW

7

3 4

BATT1 3V

2 XTAL1 32.768kHz

C2 15pF

ÃÙ»·Õè L21-1 ǧ¨Ã¹ÒÌ ¡Ò´Ô¨µÔ ÍÅ·Õãè ª i-Stamp2P à ÇÁ¡Ñº DS1307 áÊ´§¼Å¼ Ò¹âÁ´ÙÅ LCD '

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ 16.1 㪠ǧ¨Ãã¹ÃÙ»·Õè L16-1 㹡Ò÷´Åͧ â´Âµ Íǧ¨Ãŧº¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ 16.2 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB1601.BSP '********************************************************** ' Program : LAB1601.BSP ' Description : Digital clock with DS1307 ' Hardware : See schematic L16-1 '********************************************************** ' {$STAMP BS2p} ' {$PBASIC 2.5} ' Define LCD constants WakeUp CON %00110000 ' Wake-up FourBitMode CON %00100000 ' Set TO 4-Bit mode TwoLine5x8Font CON %00101000 ' Set TO 2 display lines, 5x8 font DisplayOff CON %00001000 ' Turn off display, DATA is retained DisplayOn CON %00001100 ' Turn ON display, no cursor IncCrsr CON %00000110 ' Auto-increment cursor,no display shift ClearDisplay CON %00000001 ' Clear the display MoveCrsr CON %10000000 ' Move cursor to position (must add address) D_TEMP M_TEMP DELAY_SW SECONDS MINUTES HOURS DAY DATE MONTH YEAR

VAR VAR CON VAR VAR VAR VAR VAR VAR VAR

Byte(3) Byte(3) 100 Byte Byte Byte Byte Byte Byte Byte

I2COUT 0,$D0,07,[%00000001] Init: PAUSE 50 GOSUB InitLCD LOOP1: GOSUB READ_TIME GOSUB SHOWTIME IF IN2 = 0 THEN SETTIME1 GOTO LOOP1

' Enable OSC.,Disable SQW/OUT

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'


SETTIME1: PAUSE 500 IF IN2 = 1 THEN LOOP1 PAUSE 500 IF IN2 = 1 THEN LOOP1 PAUSE 500 IF IN2 = 1 THEN LOOP1 PAUSE 500 IF IN2 = 1 THEN LOOP1 SETTIME2: LCDCMD 9,$0D LCDCMD 9,$80+2 PAUSE DELAY_SW IF IN2 = 0 THEN SETTIME2 IF IN5 = 0 THEN SETTIME2 SETTIME2_2: PAUSE DELAY_SW IF IN5 = 0 THEN SHIFT1 IF IN4 = 0 THEN DAY_UP IF IN2 = 0 THEN ENTER GOTO SETTIME2_2 SHIFT1: LCDCMD 9,$0D LCDCMD 9,$80+5 IF IN5 = 0 THEN SHIFT1 PAUSE DELAY_SW SHIFT1_2: IF IN5 = 0 THEN SHIFT3 IF IN4 = 0 THEN HR_UP IF IN2 = 0 THEN ENTER GOTO SHIFT1_2 SHIFT3: LCDCMD 9,$0D LCDCMD 9,$80+$8 IF IN5 = 0 THEN SHIFT3 PAUSE DELAY_SW SHIFT3_2: IF IN5 = 0 THEN SHIFT4 IF IN4 = 0 THEN MIN_UP IF IN2 = 0 THEN ENTER GOTO SHIFT3_2

'

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


SHIFT4: LCDCMD 9,$0D LCDCMD 9,$80+11 IF IN5 = 0 THEN SHIFT4 PAUSE DELAY_SW SHIFT4_2: IF IN5 = 0 THEN SHIFT5 IF IN4 = 0 THEN SEC_UP IF IN2 = 0 THEN ENTER GOTO SHIFT4_2 SHIFT5: LCDCMD 9,$0D LCDCMD 9,$C0+5 IF IN5 = 0 THEN SHIFT5 PAUSE DELAY_SW SHIFT5_2: IF IN5 = 0 THEN SHIFT6 IF IN4 = 0 THEN DATE_UP IF IN2 = 0 THEN ENTER GOTO SHIFT5_2 SHIFT6: LCDCMD 9,$0D LCDCMD 9,$C0+9 IF IN5 = 0 THEN SHIFT6 PAUSE DELAY_SW SHIFT6_2: IF IN5 = 0 THEN SHIFT7 IF IN4 = 0 THEN MONTH_UP IF IN2 = 0 THEN ENTER GOTO SHIFT6_2 SHIFT7: LCDCMD 9,$0D LCDCMD 9,$C0+12 IF IN5 = 0 THEN SHIFT7 PAUSE DELAY_SW SHIFT7_2: IF IN5 = 0 THEN SETTIME2 IF IN4 = 0 THEN YEAR_UP IF IN2 = 0 THEN ENTER GOTO SHIFT7_2

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'!


DAY_UP: DAY = DAY + 1 IF DAY > 7 THEN DAY_UP_ADJ1 GOTO DAY_UP_ADJ2 DAY_UP_ADJ1: DAY = 1 DAY_UP_ADJ2: GOSUB SHOWTIME WAIT7: PAUSE DELAY_SW IF IN4 = 0 THEN WAIT7 GOTO SETTIME2 HR_UP: HOURS = HOURS + 1 IF HOURS.LOWNIB > 9 THEN HR_UP_ADJ1 GOTO HR_UP_ADJ2 HR_UP_ADJ1: HOURS.LOWNIB = 0 HOURS = HOURS + $10 HR_UP_ADJ2: IF HOURS > $23 THEN HR_UP_ADJ3 GOSUB SHOWTIME WAIT8: PAUSE DELAY_SW IF IN4 = 0 THEN WAIT8 GOTO SHIFT1 HR_UP_ADJ3: HOURS = $00 GOTO HR_UP_ADJ2 MIN_UP: MINUTES = MINUTES +1 IF MINUTES.LOWNIB > 9 THEN MIN_UP_ADJ1 GOTO MIN_UP_ADJ2 MIN_UP_ADJ1: MINUTES.LOWNIB = 0 MINUTES = MINUTES + $10 MIN_UP_ADJ2: IF MINUTES > $59 THEN MIN_UP_ADJ3 GOSUB SHOWTIME

'"

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


WAIT9: PAUSE DELAY_SW IF IN4 = 0 THEN WAIT9 GOTO SHIFT3 MIN_UP_ADJ3: MINUTES = $00 GOTO MIN_UP_ADJ2 SEC_UP: SECONDS = SECONDS +1 IF SECONDS.LOWNIB > 9 THEN SEC_UP_ADJ1 GOTO SEC_UP_ADJ2 SEC_UP_ADJ1: SECONDS.LOWNIB = 0 SECONDS = SECONDS + $10 SEC_UP_ADJ2: IF SECONDS > $59 THEN SEC_UP_ADJ3 GOSUB SHOWTIME WAIT10: PAUSE DELAY_SW IF IN4 = 0 THEN WAIT10 GOTO SHIFT4 SEC_UP_ADJ3: SECONDS = $00 : GOTO SEC_UP_ADJ2 DATE_UP: DATE = DATE +1 IF DATE.LOWNIB > 9 THEN DATE_UP_ADJ1 GOTO DATE_UP_ADJ2 DATE_UP_ADJ1: DATE.LOWNIB = 0 DATE = DATE + $10 DATE_UP_ADJ2: IF DATE > $31 THEN DATE_UP_ADJ3 GOSUB SHOWTIME WAIT11: PAUSE DELAY_SW IF IN4 = 0 THEN WAIT11 GOTO SHIFT5 DATE_UP_ADJ3: DATE = $01 GOTO DATE_UP_ADJ2

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'#


MONTH_UP: MONTH = MONTH +1 IF MONTH.LOWNIB > 9 THEN MONTH_UP_ADJ1 GOTO MONTH_UP_ADJ2 MONTH_UP_ADJ1: MONTH.LOWNIB = 0 MONTH = MONTH + $10 MONTH_UP_ADJ2: IF MONTH > $12 THEN MONTH_UP_ADJ3 GOSUB SHOWTIME IF MONTH = $0A THEN RETURN_OCT IF MONTH = $0B THEN RETURN_NOV IF MONTH = $0C THEN RETURN_DEC WAIT12: PAUSE DELAY_SW IF IN4 = 0 THEN WAIT12 LOOP6: GOTO SHIFT6 RETURN_OCT : MONTH = $10 GOTO LOOP6 RETURN_NOV: MONTH = $11 GOTO LOOP6 RETURN_DEC: MONTH = $12 GOTO LOOP6 MONTH_UP_ADJ3: MONTH = $01 GOTO MONTH_UP_ADJ2 YEAR_UP: YEAR = YEAR +1 IF YEAR.LOWNIB > 9 THEN YEAR_UP_ADJ1 GOTO YEAR_UP_ADJ2 YEAR_UP_ADJ1: YEAR.LOWNIB = 0 YEAR = YEAR + $10 YEAR_UP_ADJ2: IF YEAR > $99 THEN YEAR_UP_ADJ3 GOSUB SHOWTIME

'$

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


WAIT13: PAUSE DELAY_SW IF IN4 = 0 THEN WAIT13 GOTO SHIFT7 YEAR_UP_ADJ3: YEAR = $00 GOTO YEAR_UP_ADJ2 ENTER: GOSUB WRITE_TIME WAIT1: PAUSE DELAY_SW IF IN2 = 0 THEN WAIT1 GOTO LOOP1 WRITE_TIME: I2COUT 0,$D0,00,[SECONDS,MINUTES,HOURS,DAY,DATE,MONTH,YEAR] RETURN READ_TIME: I2CIN 0,$D1,00,[SECONDS,MINUTES,HOURS,DAY,DATE,MONTH,YEAR] RETURN SHOWTIME: DAY = DAY - 1 ' Offset BRANCH DAY,[MON,TUE,WED,THU,FRI,SAT,SUN] MON: D_TEMP(0) = "M": D_TEMP(1) = "O": D_TEMP(2) = "N": GOTO LOOP4 TUE: D_TEMP(0) = "T": D_TEMP(1) = "U": D_TEMP(2) = "E": GOTO LOOP4 WED: D_TEMP(0) = "W": D_TEMP(1) = "E": D_TEMP(2) = "D": GOTO LOOP4 THU: D_TEMP(0) = "T": D_TEMP(1) = "H": D_TEMP(2) = "U": GOTO LOOP4 FRI: D_TEMP(0) = "F": D_TEMP(1) = "R": D_TEMP(2) = "I": GOTO LOOP4 SAT: D_TEMP(0) = "S": D_TEMP(1) = "A": D_TEMP(2) = "T": GOTO LOOP4 SUN: D_TEMP(0) = "S": D_TEMP(1) = "U": D_TEMP(2) = "N": GOTO LOOP4 LOOP4: IF MONTH = $10 THEN OCT_ADJ IF MONTH = $11 THEN NOV_ADJ IF MONTH = $12 THEN DEC_ADJ GOTO LOOP3 OCT_ADJ: MONTH = $0A GOTO LOOP3 NOV_ADJ: MONTH = $0B GOTO LOOP3 DEC_ADJ: MONTH = $0C

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

'%


LOOP3: MONTH = MONTH - 1 ' Offset BRANCH MONTH,[JAN1,FEB2,MAR3,APR4,MAY5,JUN6,JUL7,AUG8,SEP9,OCT10,NOV11,DEC12] JAN1: M_TEMP(0) = "J" : M_TEMP(1) = "A" : M_TEMP(2) = "N" : GOTO LOOP2 FEB2: M_TEMP(0) = "F" : M_TEMP(1) = "E" : M_TEMP(2) = "B" : GOTO LOOP2 MAR3: M_TEMP(0) = "M" : M_TEMP(1) = "A" : M_TEMP(2) = "R" : GOTO LOOP2 APR4: M_TEMP(0) = "A" : M_TEMP(1) = "P" : M_TEMP(2) = "R" : GOTO LOOP2 MAY5: M_TEMP(0) = "M" : M_TEMP(1) = "A" : M_TEMP(2) = "Y" : GOTO LOOP2 JUN6: M_TEMP(0) = "J" : M_TEMP(1) = "U" : M_TEMP(2) = "N" : GOTO LOOP2 JUL7: M_TEMP(0) = "J" : M_TEMP(1) = "U" : M_TEMP(2) = "L" : GOTO LOOP2 AUG8: M_TEMP(0) = "A" : M_TEMP(1) = "U" : M_TEMP(2) = "G" : GOTO LOOP2 SEP9: M_TEMP(0) = "S" : M_TEMP(1) = "E" : M_TEMP(2) = "P" : GOTO LOOP2 OCT10: M_TEMP(0) = "O" : M_TEMP(1) = "C" : M_TEMP(2) = "T" : GOTO LOOP2 NOV11: M_TEMP(0) = "N" : M_TEMP(1) = "O" : M_TEMP(2) = "V" : GOTO LOOP2 DEC12: M_TEMP(0) = "D" : M_TEMP(1) = "E" : M_TEMP(2) = "C" LOOP2: LCDOUT 9,$80+0,[STR D_TEMP\3," ",HEX2 HOURS,":",HEX2 MINUTES,":",HEX2 SECONDS] LCDOUT 9,$C0+4,[HEX2 DATE,"-",STR M_TEMP\3,"-",HEX2 YEAR] DAY = DAY + 1 MONTH = MONTH + 1 LCDCMD 9,$0C RETURN InitLCD: LCDCMD 9,WakeUp ' Send wakeup sequence to LCD PAUSE 10 ' These pauses are necessary to meet the LCD specs LCDCMD 9,WakeUp PAUSE 1 LCDCMD 9,WakeUp PAUSE 1 LCDCMD 9,FourBitMode ' Set buss TO 4-Bit mode LCDCMD 9,TwoLine5x8Font ' Set TO 2-line mode with 5x8 font LCDCMD 9,DisplayOn ' Turn on with blinking cursor LCDCMD 9,IncCrsr ' Set to auto-increment cursor (no display shift) LCDCMD 9,ClearDisplay ' Clear the display RETURN

'&

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ â»Ãá¡ÃÁ¹ÕÁé ¤Õ ÇÒÁÂÒǾÍÊÁ¤Çà à¹×Íè §¨Ò¡¿ §¡ ª¹Ñè 㹡Ò÷íÒ§Ò¹¢Í§ DS1307 ¤ ͹¢ Ò§ÁÒ¡ àÃÔÁè µ ¹´ Ç¡Òà ¡íÒ˹´µÑÇá»Ãµ Ò§æ ¨Ò¡¹Ñ¹é ·íÒ¡ÒÃÊ §¤íÒÊѧè 仵Դµ ͡Ѻ DS1307 ´ ÇÂâ»Ãá¡ÃÁ㹺Ã÷Ѵ I2COUT 0,$D0,07,[%00000001] ¨Ò¡¹Ñ¹é DS1307 ¨ÐÊ §¤ ÒÇѹ àÇÅÒ ÍÍ¡ÁÒ i-Stamp2P24 ¨Ð·íÒ¡ÒÃÍ Ò¹¤ ÒàËŠҹѹé áŠǹíÒáÊ´§¼Å ¾Ã ÍÁ ¡Ñ¹¹Ñ¹é ¨ÐÁÕ¡ÒõÃǨÊͺ¡Òá´ÊÇÔµª S1 仾à ÍÁæ ¡Ñ¹´ Ç â´Â·Ñ§é ËÁ´¨Ð·íÒ§Ò¹ÍÂÙã ¹â»Ãá¡ÃÁ Í LOOP1 «Ö§è ÀÒÂã¹»ÃСͺ´ ÇÂâ»Ãá¡ÃÁ Í READTIME, SHOWTIME áÅеÃǨÊͺà§×Íè ¹ä¢¡Òá´ÊÇÔµª S1 ËÒ¡à» ¹¨ÃÔ§ ¡ç¨Ð¡ÃÐâ´´ä»Âѧâ»Ãá¡ÃÁ Í SETTIME à¾×Íè ·íÒ¡Òõѧé àÇÅÒµ Íä» ·Õâè »Ãá¡ÃÁ Í READTIME à» ¹Ê ǹ·Õè i-Stamp2P24 Í Ò¹¤ ÒàÇÅÒ¨Ò¡ DS1307 ´ ǤíÒÊѧè I2CIN ¨Ò¡¹Ñ¹é ¹íÒ ¢ ÍÁÙÅÁÒÂѧâ»Ãá¡ÃÁ Í SHOWTIME à¾×èÍàµÃÕÂÁáÊ´§¼ÅÍÍ¡·Ò§âÁ´ÙÅ LCD ·Õèâ»Ãá¡ÃÁ Í SHOWTIME ¨ÐẠ§Ê ǹ¢ ÍÁÙÅà¾×Íè ¹íÒä»áÊ´§¼Å 3 Ê Ç¹¤×Í Çѹ, àÇÅÒ㹺Ã÷Ѵº¹ áÅÐÇѹ·Õ-è à´×͹-» 㹺Ã÷ѴŠҧ â´Â¢ ͤÇÒÁ·Õãè ª á·¹¤ ҢͧÇѹáÅÐà´×͹¶Ù¡à¡çºäÇ ã¹ÅѡɳеÒÃÒ§¢ ÍÁÙÅ áÅ Ç㪠¤Òí Êѧè BRANCH 㹡ÒÃàÅ×Í¡¢ ͤÇÒÁÍÍ¡ÁÒáÊ´§¼Å â»Ãá¡ÃÁ Í SETTIME ¤×Í ¾×¹é ·Õ¢è ͧâ»Ãá¡ÃÁÊ Ç¹ãË­ à¹×Íè §¨Ò¡ã¹¡ÒÃµÑ§é ¤ ÒàÇÅÒ¨ÐÁÕµÇÑ á»Ã·Õàè ¡ÕÂè Ç¢ ͧáÅÐ ¢Ñ¹é µÍ¹à» ¹¨íҹǹÁÒ¡ äÁ ÇÒ ¨Ðà» ¹¡ÒÃµÑ§é ¤ ÒÇѹ µÑ§é ¤ ÒàÇÅÒ·Õáè ¡ ÍÂà» ¹ªÑÇè âÁ§ ¹Ò·Õ ÇÔ¹Ò·Õ µÑ§é ¤ ÒÇѹ·Õè à´×͹ » áÅÐ à¹×Íè §¨Ò¡µ ͧ㪠ÊÇÔµª 㹡ÒÃµÑ§é ¤ Ò¨íҹǹ¹ Í·ÕÊè ´Ø à· Ò·Õ¨è Ðà» ¹ä»ä´ ¨Ö§µ ͧẠ§Ë¹ Ò·Õ¢è ͧÊÇÔµª áµ ÅеÑÇãË ª´Ñ ਹ µÑÇáá S1 㪠àÅ×Í¡à¾×Íè ࢠÒÊÙâ ËÁ´¡Òõѧé àÇÅÒ µÑǹÕÁé ¹Õ ÂÑ ÊíҤѭÊÙ§ÊØ´ ã¹â»Ãá¡ÃÁ¤×Í ãª µÇÑ á»Ã IN2 «Ö§è ¡ç¤Í× àÅ×Í¡ÃѺ¤ Ò¨Ò¡¢Ò ¾Íà µ P2 ¢Í§ i-Stamp2P24 µÃҺ㴷աè ÒõÃǨÊͺ¢Í§â»Ãá¡ÃÁ㹺Ã÷Ѵ IF IN2 = 0 THEN SETTIME1 ÂѧäÁ à» ¹ ¨ÃÔ§ i-Stamp2P24 ¨Ð·íÒ§Ò¹à¾Õ§ᵠÍÒ ¹áÅÐáÊ´§¤ ÒàÇÅÒ෠ҹѹé àÁ×Íè ¡ÒõÃǨÊͺµÑÇá»Ã IN2 à» ¹¨ÃÔ§ i-Stamp2P ¨Ðâ´´ä»·íÒ§Ò¹·Õâè »Ãá¡ÃÁ Í SETTIME ·Ñ¹·Õ «Ö§è ¨ÐµÃǨÊͺÍÕ¡Ç Ò à§×Íè ¹ä¢Âѧ¤§à» ¹¨ÃÔ§¹Ò¹¶Ö§ 2 ÇÔ¹Ò·ÕËÃ×ÍäÁ ¶ Ò㪠¡ç¨ÐࢠÒÊÙ¢ ¹Ñé µÍ¹¡Òõѧé àÇÅÒÍ ҧÊÁºÙó ¶Ö§µÍ¹¹ÕÊé ÇÔµª Í¡Õ 2 µÑÇ·Õàè ËÅ×֧ͨ¨ÐÁÕº·ºÒ· ÊÇÔµª S3 µ ÍÍÂÙ· ¾Õè Íà µ P5 㪠㹡ÒÃàÅ×Í¡¤ Ò·Õµè Í §¡Òõѧé àÁ×Íè ¶Ù¡¡´ i-Stamp2P24 ¡ç¨Ð·íÒ¡ÒÃàÅ×Íè ¹à¤Íà à«Íà ä»ÂѧµíÒá˹ §¢Í§¤ Ò·Õèµ Í§¡ÒõÑ駺¹¨ÍáÊ´§¼Å áÅÐàÁ×è͵ ͧ¡ÒÃà»ÅÕè¹á»Å§¤ ÒãË ¡´ÊÇÔµª S2 ·Õèµ ÍÍÂÙ ¡Ñº¾Íà µ P4 ¨¹¶Ö§¤ Ò·Õµè Í §¡Òà â»Ãá¡ÃÁ Í·շè Òí ˹ Ò·Õãè ¹Ê Ç¹¹Õ»é ÃСͺ´ Ç ¡ÅØÁ ¢Í§â»Ãá¡ÃÁ Í SHIFT Ạ§à» ¹ 7 â»Ãá¡ÃÁ Í à¹×Íè §¨Ò¡ÁÕµÒí á˹ §¢Í§¤ Ò·Õµè Í §¡ÒÃµÑ§é ·Ñ§é ÊÔ¹é 7 µíÒá˹ §¤×Í ¤ ҢͧÇѹ, ªÑÇè âÁ§, ¹Ò·Õ, ÇÔ¹Ò·Õ, Çѹ·Õ,è à´×͹ áÅл ¤.È. ¡ÅØÁ ¢Í§â»Ãá¡ÃÁ ÍÂà¾ÔÁè ¤ Ò¨ÐÁÕªÍ×è ¹íÒ˹ Ò´ Ǥ ҢͧàÇÅÒ·Õµè Í §¡Òõѧé áÅе Í· Ò´ ǤíÒÇ Ò UP «Ö§è ÁÕ´Ç Â¡Ñ¹ 7 ¡ÅØÁ ઠ¹¡Ñ¹»ÃСͺ´ Ç DAY_UP 㪠à¾ÔèÁ¤ Òà¾×è͵Ñ駤 ҢͧÇѹ HR_UP 㪠à¾ÔèÁ¤ Òà¾×è͵Ñ駤 ҢͧªÑèÇâÁ§ MIN_UP 㪠à¾ÔèÁ¤ Òà¾×è͵Ñ駤 Ңͧ¹Ò·Õ SEC_UP 㪠à¾ÔèÁ¤ Òà¾×è͵Ñ駤 ҢͧÇÔ¹Ò·Õ DATE_UP 㪠à¾ÔèÁ¤ Òà¾×è͵Ñ駤 ҢͧÇѹ·Õè MONTH_UP 㪠à¾ÔèÁ¤ Òà¾×è͵Ñ駤 Ңͧà´×͹ YEAR_UP 㪠à¾ÔèÁ¤ Òà¾×è͵Ñ駤 ҢͧªÑèÇâÁ§

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

''


16.3 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 16.4 Ãѹâ»Ãá¡ÃÁ Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§âÁ´ÙÅ LCD ·Õâè Á´ÙÅ LCD ¨ÐáÊ´§¤ Ңͧ Çѹ àÇÅÒ (Ẻ 24 ªÑÇè âÁ§) Çѹ·Õè à´×͹ áÅÐ » ¤.È. ¢Ö¹é ÁÒ ¨Ò¡¹Ñ¹é ãË ·´ÅͧµÑ§é àÇÅÒ» ¨¨Øº¹Ñ µÒÁ¢Ñ¹é µÍ¹´Ñ§¹Õé ¶ Òµ ͧ¡ÒÃµÑ§é ¤ Òà» ¹ ÇѹàÊÒà ·Õè 1 ¡ØÁÀҾѹ¸ 2003 àÇÅÒ 10:00:00 16.5 ¡´ÊÇÔµª S1 ¤ Ò§äÇ 2 ÇÔ¹Ò·Õ ¨ÐàËç¹à¤Íà à«Íà ¢Öé¹·ÕèµíÒá˹ §¢Í§Çѹ ·íÒ¡ÒÃµÑ§é ¤ ҢͧÇѹâ´Â¡´ÊÇÔµª S2 ãË áÊ´§¢ ͤÇÒÁ¢Í§ ÇѹàÊÒà (SAT) 16.6 ¡´ÊÇÔµª S1 Ë¹Ö§è ¤ÃÑ§é ¨ÐàËç¹à¤Íà à«Íà àÅ×Íè ¹ä»ªÕ·é µÕè Òí á˹ §¢Í§¤ ÒªÑÇè âÁ§ ¡´ÊÇÔµª S2 à¾×Íè µÑ§é ¤ ÒªÑÇè âÁ§ (ã¹áºº 24 ªÁ.) à» ¹ 10 16.7 ¡´ÊÇÔµª S1 Ë¹Ö§è ¤Ãѧé à¤Íà à«Íà ¨ÐàÅ×Íè ¹ä»·Õµè Òí á˹ §¢Í§¤ Ò¹Ò·Õ ¡´ÊÇÔµª S2 à¾×Íè µÑ§é ¤ Ò¹Ò·Õ à» ¹ 00 ·íÒઠ¹à´ÕÂǡѹ¹Õéä»àÃ×èÍÂæ ¨¹¡ÃзÑ觶֧» ¤È. ¶ Òµ ͧ¡ÒÃᡠ䢤 Ò·ÕèµíÒá˹ §ã´æ ¡çÊÒÁÒö ¡´ÊÇÔµª S1 ãË à¤Íà à«Íà àÅ×Íè ¹ä»ÂѧµíÒá˹ §·Õµè Í §¡ÒÃä´ 16.8 àÁ×Íè µÑ§é ¤ Òà» ¹·Õàè ÃÕºà ÍÂáÅ Ç ¡´ÊÇÔµª S3 Ë¹Ö§è ¤Ãѧé áŠǻŠÍ ¨Ðà» ¹¡ÒÃÍÍ¡¨Ò¡âËÁ´¡Òõѧé àÇÅÒ ¤ Òµ Ò§æ ä´ µ§Ñé äÇ ¨Ð¶Ù¡Ê §ãË ¡ºÑ DS1307 ·ÕËè ¹ ҨͨСÅѺࢠÒÊÙâ ËÁ´»¡µÔ µÑÇà¤Íà à«Íà ¨ÐËÒÂä» ¾Ã ÍÁ¡Ñº¹ÒÌ ¡Ò¨ÐàÃÔÁè à´Ô¹¨Ò¡àÇÅÒ·ÕèµÑé§äÇ ËÁÒÂà赯 1. ¤ ÒàÇÅÒ» ¨¨Øº¹Ñ ¨ÐÂѧ¤§ÍÂÙá Á ¨Ð» ´ä¿àÅÕÂé §¡çµÒÁ áµ ·§Ñé ¹Õé ẵàµÍÃÕµè Í §äÁ àÊ×Íè ÁÊÀÒ¾´ Ç 2. äÁ ¤ÇùíÒẵàµÍÃÕÍè Í¡áÁ ¨Ð㪠§Ò¹ã¹¢³Ðà» ´ä¿àÅÕÂé §ÍÂÙ¡ µç ÒÁ à¾ÃÒШзíÒãË ¡Ò÷íÒ§Ò¹¼Ô´¾ÅÒ´ä´ i-Stamp2p24

!

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


12.3 DS1621 äÍ«ÕÇ´Ñ ÍسËÀÙÁáÔ ºº´Ô¨µÔ ÍÅ ¼Ù¼ ÅÔµ¤×Í Dallas Semiconductor à» ¹äÍ«ÕÇ´Ñ ÍسËÀÙÁ·Ô ãÕè ª ¡ÒõԴµ ͼ Ò¹ÃкººÑÊ I2C ã¹ÃÙ»·Õè 12-8 áÊ´§¡ÒèѴ¢ÒáÅÐ˹ Ò·Õ¢è ͧᵠÅТҢͧäÍ«Õ DS1621 ÊíÒËÃѺ¤Ø³ÊÁºÑµ·Ô ÊÕè Òí ¤Ñ­¢Í§ DS1621 ÁÕ´§Ñ ¹Õé l ÇÑ´ÍسËÀÙÁäÔ ´ µ§Ñé áµ -55ðC ¶Ö§ +125ðC â´ÂÁÕ¤ÇÒÁÅÐàÍÕ´㹡ÒÃÇÑ´ 0.5ðC à·Õº໠¹Ë¹ Ç ¢Í§¿Òàùäε ä´ à· Ò¡Ñº -67ðF ¶Ö§ +257ðF ¤ÇÒÁÅÐàÍÕ´ 0.9ðF â´ÂäÁ µÍ §ãª Í»Ø ¡Ã³ µÍ à ÇÁÀÒ¹͡ l ¤ÇÒÁÅÐàÍÕ´¢Í§¢ ÍÁÙÅÍسËÀÙÁ´ Ô ¨Ô µÔ ÍÅ 9 ºÔµ l 㪠ä¿àÅÕÂ é §ä´ µ§Ñé áµ 2.7 ¶Ö§ 5.5V l 㪠àÇÅÒ㹡ÒÃÇÑ´ÍسËÀÙÁá Ô Å Çá»Å§à» ¹¢ ÍÁÙÅ´Ô¨µÔ ÍÅ 1 ÇÔ¹Ò·Õ l ·íҧҹ໠¹à·Íà âÁʵѵ (thermostat) ä´ ¾Ã ÍÁàÍÒµ ¾µ Ø 1 ¢Ò ÊÒÁÒöµÑ§é ¤ ÒÍسËÀÙÁ·Ô µÕè Í §¡Òà 2 ä´ â´ÂµÔ´µ ͼ Ò¹ÃкººÑÊ I C áÅФ Ò·Õ¡è Òí ˹´¹Õ¨é Ф§ÍÂÙµ ÅÍ´ä» áÁ »Å´ä¿àÅÕÂé §áÅ Ç¡çµÒÁ ÊÒÁÒöà»ÅÕÂè ¹ á»Å§ä´ â´Â¡ÒáíÒ˹´·Ò§«Í¿µ áÇà ෠ҹÑé¹ l ÊÒÁÒöµ ; ǧ¡Ñ¹ä´ ʧ٠ÊØ´ 8 µÑÇ

12.3.1 ¡Ò÷íÒ§Ò¹¢Í§ DS1621 ã¹ÃÙ»·Õè 12-9 áÊ´§¼Ñ§¡Ò÷íÒ§Ò¹ÃÇÁ¢Í§ DS1621 ËÑÇã¨ÊíҤѭÍÂÙ· ÊÕè Ç ¹ÇÑ´ÍسËÀÙÁÔ àÁ×Íè DS1621 àÃÔÁè ·íÒ§Ò¹ ¨Ð·íÒ¡ÒÃÇÑ´ÍسËÀÙÁÔ â´ÂÀÒÂã¹äÍ«Õ¨ÐÁÕµÇÑ µÃǨ¨ÑºÍسËÀÙÁºÔ ÃèØÍÂÙ ¼Å¡ÒÃÇÑ´¨ÐÊ §µ Íä»ÂÑ§Ê Ç¹ ¨Ñ´¡ÒÃáÍ´à´ÃÊáÅФǺ¤ØÁÍÔ¹¾ØµàÍÒµ ¾µØ ã¹Ê ǹ¹Õ¹é Òí ¢ ÍÁÙÅÍسËÀÙÁ·Ô ÇÕè ´Ñ ä´ Ê§ µ Íä»ÂѧºÑʼ Ò¹·Ò§¢Ò SDA â´Âä´ ÃѺ¡ÒáíÒ˹´¨Ñ§ËÇСÒ÷íÒ§Ò¹¨Ò¡Ê ǹÃÕ¨ÔÊàµÍà ¤Çº¤ØÁáÅÐáÊ´§Ê¶Ò¹Ð ËÒ¡ÁÕ¡ÒáíÒ˹´ãË ·íÒ§Ò¹ ã¹âËÁ´à·Íà âÁʵѵ ¢ ÍÁÙÅ¡ÒÃÇÑ´¶Ù¡Ê §ä»à»ÃÕºà·Õº¡Ñº¨Ø´¡ÃÐµØ ¹·Ò§ÊÙ§áÅеèíÒ·ÕèÊ Ç¹à»ÃÕºà·Õº¢ ÍÁÙÅ ´Ô¨µÔ ÍÅ ¼Å¡ÒÃà»ÃÕºà·Õº¨ÐÊ §ÍÍ¡·Ò§¢Ò TOUT à¹×Íè §¨Ò¡ DS1621 ÁÕ¢Ò¡íÒ˹´áÍ´à´ÃÊ 3 ¢Ò¤×Í A2 ¶Ö§ A0 ¨Ö§·íÒãË ÊÒÁÒöµ ; ǧ DS1621 ä´ Ê§Ù ÊØ´ 8 µÑÇ â´Âáµ ÅеÑǵ ͧ¡íÒ˹´Ê¶Ò¹ÐÅͨԡ·Õ¢è ÒáÍ´à´Ãʷѧé ÊÒÁãË áµ¡µ Ò§¡Ñ¹ Ê Ç¹¨Ñ´¡ÒÃáÍ´à´ÃÊáÅÐ ¤Çº¤ØÁÍÔ¹¾ØµàÍÒµ ¾µØ ¢Í§ DS1621 áµ ÅеÑǨÐà» ¹µÑǨѴ¡ÒÃÊ §¢ ÍÁÙŵÒÁ·ÕÍè »Ø ¡Ã³ ÁÒÊàµÍà ÃÍ §¢Í ¢Ò·Õè ª×èÍ¢Ò SDA

1

SCL

2

TOUT 3 GND 4

8 +Vcc ,5 $ Digital Tthermometer and thermostat

7

A0

6

A1

5

A2

˹ Ò·Õè/¡Ò÷íÒ§Ò¹

1

SDA

¢Ò¢ ÍÁÙÅ͹ءÃÁÊíÒËÃѺàª×Íè Áµ ͡ѺÃкººÑÊ I C

2

SCL

¢ÒÊÑ­­Ò³¹ÒÌÔ¡ÒÊíÒËÃѺàª×Íè Áµ ͡ѺÃкººÑÊ I C

3

TOUT

"áÍ¡µÕ¿" àÁ×Íè ÍسËÀÙÁÊÔ §Ù ¶Ö§¨Ø´¡Ãеع ÊÙ§ (TH) "ÃÕ૵" àÁ×Íè ÍسËÀÙÁÅÔ ´Å§µíÒè ¡Ç Ò¨Ø´¡Ãеع µíÒè (TL)

4

GND

¢Òµ Í¡ÃÒÇ´ ¢Í§Ç§¨Ã

5-7

A2-A0

8

+Vcc

¢Òµ Íä¿àÅÕÂé § +5V

ÃÙ»·Õè 12-8 ¡ÒèѴ¢ÒáÅСÒ÷íÒ§Ò¹¢Í§ DS1621 äÍ«ÕÇ´Ñ ÍسËÀÙÁáÔ ºº´Ô¨µÔ ÍÅ Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


ÃÕ¨ÊÔ àµÍà ¤Çº¤ØÁáÅÐáÊ´§Ê¶Ò¹Ð SCL SDA

Ê Ç¹¡íÒ˹´ áÍ´à´ÃÊ áÅФǺ¤ØÁ ¢ÒÍÔ¹¾ØµàÍÒµ ¾µØ

A0 A1 A2

µÑǵÃǨÇÑ´ÍسËÀÙÁÔ ¨Ø´·ÃÔ¡ÍسËÀÙÁÊÔ §Ù (TH) ¨Ø´·ÃÔ¡ÍسËÀÙÁµÔ Òèí (TL)

Ê Ç¹à»ÃÕºà·Õº¢ ÍÁÙÅ´Ô¨µÔ ÍÅ

TOUT

ÃÙ»·Õè 12-9 ¼Ñ§¡Ò÷íÒ§Ò¹àº×Íé §µ ¹â´ÂÃÇÁ¢Í§ DS1621 äÍ«ÕÇ´Ñ ÍسËÀÙÁáÔ ºº´Ô¨µÔ ÍÅ ¤ ҢͧÍسËÀÙÁ·Ô ÇÕè ´Ñ ä´ à¡çºÍÂÙã ¹ÃÙ»¢Í§¢ ÍÁÙÅàÅ¢°Ò¹Êͧ 9 ºÔµ ´Ñ§áÊ´§µÑÇÍ ҧ㹵ÒÃÒ§·Õè 12-1 ¢ ÍÁÙÅ ´Ô¨µÔ ÍÅàÍÒµ ¾µØ ¨ÐẠ§à» ¹ 2 Ê Ç¹ 8 ºÔµº¹ËÃ×Í亵 ʧ٠¨Ðà» ¹¤ ÒÍسËÀÙÁ¨Ô Òí ¹Ç¹àµçÁ â´ÂºÔµ MSB ¨Ðà» ¹µÑÇ áÊ´§à¤Ã×Íè §ËÁÒÂÇ Ò ÍسËÀÙÁàÔ » ¹ºÇ¡ËÃ×Íź ËÒ¡ºÔµ MSB à» ¹ 1 áÊ´Ç ÒÍسËÀÙÁ·Ô ÇÕè ´Ñ ä´ Á¤Õ Ò à» ¹Åº 㹠𠢳зÕè 8 ºÔµÅ Ò§ËÃ×Í亵 ÅÒ §¨ÐÁÕ㪠§Ò¹à¾Õ§ºÔµà´ÕÂǨÐà» ¹ºÔµáÊ´§¤ Ò¤ÇÒÁÅÐàÍÕ´ «Ö§è ෠ҡѺ 0.5 C àÁ×Íè Êѧè ãË DS1621 Ê §¢ ÍÁÙÅÍسËÀÙÁÍÔ Í¡ÁÒ DS1621 ¨Ð㪠àÇÅÒäÁ à¡Ô¹ 1 ÇÔ¹Ò·Õ ¨Ö§Ê §¢ ÍÁÙÅÍÍ¡ÁÒ ´Ñ§¹Ñ¹é 㹡ÒÃ㪠§Ò¹¨Ö§µ ͧ˹ ǧàÇÅÒà¾×Íè ÃÍãË DS1621 ÇÑ´áÅÐá»Å§¤ ÒÍÍ¡ÁÒà» ¹¢ ÍÁÙÅãË àÃÕºà ÍÂàÊÕ¡ ͹ ÍسËÀÙÁÔ ð ð +25 C ð +0.5 C ð 0 C ð -0.5 C ð -25 C ð -55 C

+125 C

¢ ÍÁÙÅ´Ô¨µÔ ÍÅàÍÒµ ¾µØ (àÅ¢°Ò¹Êͧ)

¢ ÍÁÙÅ´Ô¨µÔ ÍÅàÍÒµ ¾µØ (àÅ¢°Ò¹ÊԺˡ)

01111101 00000000

7B00H

00011001 00000000

1900H

00000001 00000000

0080H

00000000 00000000

0000H

11111111 10000000

FF80H

11100111 00000000

E700H

11001001 00000000

C900H

µÒÃÒ§·Õè 12-1 áÊ´§ÃٻẺ¢ ÍÁÙÅ´Ô¨ÔµÍŵÑÇÍ ҧ¢Í§ÍسËÀÙÁÔ·ÕèÇÑ´ä´ ¨Ò¡ DS1621 ¨ÐàËç¹ä´ Ç Ò ¢ ÍÁÙÅÍسËÀÙÁÍÔ ÂÙ· Õè 8 ºÔµº¹ Ê Ç¹ 8 ºÔµÅ Ò§áÊ´§¤ Ò¤ÇÒÁÅÐàÍÕ´

!

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


12.3.2 ¡Ò÷íÒ§Ò¹ã¹âËÁ´à·Íà âÁʵѵ ¹Í¡¨Ò¡ÇÑ´ÍسËÀÙÁáÔ Å Ç DS1621 ÂѧÊÒÁÒö·íÒ§Ò¹ã¹áººà·Íà âÁʵѵËÃ×ÍãË àÍÒµ ¾µØ àÁ×Íè ÍسËÀÙÁÔ µèíÒËÃ×ÍÊÙ§¶Ö§¨Ø´·Õè¡íÒ˹´äÇ â´Â¼Ù 㪠§Ò¹ÊÒÁÒöâ»Ãá¡ÃÁä´ µÒÁµ ͧ¡ÒÃáÅФ Ò·Õèâ»Ãá¡ÃÁ¹Õé¨ÐÍÂÙ µÅÍ´ä» ¨¹¡Ç Ò¨ÐÁÕ¡ÒÃá¡ ä¢áÁ Ç Ò¨ÐµÑ´ä¿àÅÕé§ä»áÅ Ç¡çµÒÁ ¼Ù 㪠§Ò¹µ ͧ¡íÒ˹´¤ Ңͧ¨Ø´·ÃÔ¡ÍسËÀÙÁÔÊÙ§ (high temperature trigger : TH) áÅÐ ¨Ø´·ÃÔ¡ÍسËÀÙÁµÔ Òèí (low temperature trigger :TL) áÅÐàÅ×Í¡ÊÑ­­Ò³ ÅÍ¨Ô¡Ç Ò àÁ×Íè ÍسËÀÙÁÊÔ §Ù ¶Ö§¨Ø´·Õ¡è Òí ˹´¨ÐãË ¢Ò TOUT Ê §ÊÑ­­Ò³ÅͨԡẺã´ÍÍ¡ä»ÃÐËÇ Ò§ 0 ËÃ×Í 1 àÁ×Íè ¡íÒ˹´¤ ÒáÅ Ç DS1621 ¨ÐÇÑ´ÍسËÀÙÁäÔ »àÃ×Íè Âæ ¨¹¡Ãзѧè àÁ×Íè ÍسËÀÙÁÊÔ §Ù ¨¹¶Ö§¨Ø´ TH ¢Ò TOUT ¡ç¨ÐáÍ¡µÕ¿·Ñ¹·Õ áÅÐáÍ¡µÕ¿¤ Ò§ÍÂÙà ª ¹¹Ñ¹é ¨¹¡Ç ÒÍسËÀÙÁ·Ô ÇÕè ´Ñ ä´ Å´µèÒí ŧ¡Ç Ҩش TL ´Ñ§¹Ñ¹é ¡ÒáíÒ˹´¤ Ңͧ TH áÅÐ TL ¨Ö§ÊíҤѭÁÒ¡ ËÒ¡¡íÒ˹´äÇ á¤ºËÃ×ÍÁÕ¤ÇÒÁᵡµ Ò§¡Ñ¹¹ ÍÂà¡Ô¹ä» áÅÐÍسËÀÙÁ·Ô ÇÕè ´Ñ ¨ÃÔ§¹Ñ¹é ÁÕ ¡ÒÃà»ÅÕÂè ¹á»Å§ã¹ª ǧ᤺æ ËÃ×ͤ ͹¢ Ò§¤§·Õè ¨Ð·íÒãË àÍÒµ ¾µØ ·Õ¢è Ò TOUT à¡Ô´ÊÑ­­Ò³Åͨԡ·Õäè Á ¤§·Õè ¨¹¤Å Ò ¡Ñºà» ¹ÊÑ­­Ò³Ãº¡Ç¹ Ê §¼ÅãË ¡ÒùíÒÊÑ­­Ò³ä»ãª §Ò¹·íÒä´ äÁ ´Õ áµ ¶Ò ËÒ¡¡íÒ˹´äÇ ËÒ §ËÃ×ÍÁÕ¤ÇÒÁᵡµ Ò§ ÁÒ¡à¡Ô¹ä» ÍÒ¨ÁÍ§ä´ ÇÒ Ç§¨Ãà·Íà âÁʵѵ¹ÕÁé ¤Õ ÇÒÁäǵèÒí à¾ÃÒÐ¡Ç Ò¨ÐµÑ´àÍÒµ ¾µØ µ ͧÃÍãË Í³ Ø ËÀÙÁÅÔ ´¤ Ò Å§µèÒí ¡Ç Ò¨Ø´ TH ÁÒ¡æ «Ö§è ÍÒ¨Ê §¼ÅàÊÕÂËÒ¡¡ÒÃŴŧ¢Í§ÍسËÀÙÁ·Ô àÕè ¡Ô´¢Ö¹é ¨ÃÔ§äÁ ¶§Ö ¨Ø´ TL áµ Í»Ø ¡Ã³ ·µÕè Í § ¡ÒùíÒÊÑ­­Ò³¹Õéä»ãª ÊÒÁÒö·¹ÍسËÀÙÁÔ㹪 ǧÃÐËÇ Ò§ TH áÅÐ TL ä´ äÁ ¹Ò¹ ¡ç¨ÐÊ §¼ÅãË à¡Ô´¤ÇÒÁàÊÕ ËÒµ ÍÍØ»¡Ã³ ¹¹Ñé æ ä´ ã¹ÃÙ»·Õè 12-10 áÊ´§ÃٻẺ¡Ò÷íÒ§Ò¹¢Í§ DS1621 ã¹âËÁ´à·Íà âÁʵѵ¹Õé TOUT "1" t

"0"

ÍسËÀÙÁÔ

¤ ÒÇÑ´ä´ ¨Ò¡ DS1621

TH

TL t1

t2

t3

ÍسËÀÙÁÔ¨ÃÔ§à»ÅÕè¹á»Å§ã¹ª ǧ 59-60ðC (ÍÒ¨¶×Íä´ Ç Ò¤ ͹¢ Ò§¤§·Õè)

t4

t5

t

,5 $ TH=60 TL=59.5 active "1"

ÍسËÀÙÁÔ¨ÃÔ§àÃÔèÁµ ¹¨Ò¡ 0-60ðC áÅ ÇŴŧ¨Ò¡¹Ñ鹨Ðà»ÅÕè¹á»Å§ã¹ª ǧ 50-60ðC

t6

TOUT

,5 $ TH=59 TL=30 active "1"

TOUT

ÃÙ»·Õè 12-10 ÃٻẺ¡Ò÷íÒ§Ò¹ã¹âËÁ´à·Íà âÁʵѵ¢Í§ DS1621 Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

! !


12.3.3 ÃÕ¨ÊÔ àµÍà ¡Òí ˹´¡Ò÷íÒ§Ò¹¢Í§ DS1621 㹡ÒáíÒ˹´¤ Ò TH áÅÐ TL ¢Í§ DS1621 µÅÍ´¨¹¡ÒÃàÅ×Í¡ÊÑ­­Ò³áÍ¡µÕ¿ã¹âËÁ´à·Íà âÁʵѵ µ ͧ¡ÃзíÒ¼ Ò¹ ÃÕ¨ÊÔ àµÍà ¡Òí ˹´¡Ò÷íÒ§Ò¹áÅÐáÊ´§Ê¶Ò¹Ð (Configuration/Status register) «Ö§è ·íÒ˹ Ò·Õè 2 Í ҧ¤×Í ãª ¡Òí ˹´¾ÒÃÒÁÔàµÍà àÁ×Íè DS1621 ·íÒ§Ò¹ã¹âËÁ´à·Íà âÁʵѵ áÅÐ㪠áÊ´§Ê¶Ò¹Ð¡ÒÃÇÑ´áÅÐá»Å§ ¤ ÒÍسËÀÙÁÔ ÃÕ¨ÊÔ àµÍà ¹ÁÕé ¢Õ ¹Ò´ 8 ºÔµ µÔ´µ ͼ Ò¹ÃкººÑÊ I2C áµ ÅкԵ¢Í§ÃÕ¨ÊÔ àµÍà ÁÃÕ ÒÂÅÐàÍÕ´´Ñ§¹Õé

ºÔµ 7

DONE

ºÔµ 6 THF

ºÔµ 5 TLF

ºÔµ 4 NVB

ºÔµ 3 1

ºÔµ 2 0

ºÔµ 1 POL

ºÔµ 0

1SHOT

DONE (Conversion done - ºÔµ 7) : ºÔµáÊ´§Ê¶Ò¹Ð¢Í§¡ÒÃá»Å§¢ ÍÁÙÅÍسËÀÙÁÔ 0 - ÂѧÍÂÙã ¹ÃÐËÇ Ò§¡ÒÃá»Å§¢ ÍÁÙÅ 1 - ¡ÒÃá»Å§¢ ÍÁÙÅàÊÃç¨ÊÁºÙó áÅ Ç THF (Temperature High Flag - ºÔµ 6) : ºÔµá¿Å¡á¨ §Ç ÒÍسËÀÙÁ·Ô ÇÕè ´Ñ ä´ Ê§Ù ¡Ç Ҩش·ÃÔ¡ÍسËÀÙÁÊÔ §Ù ËÃ×Í TH â´ÂàÁ×Íè à¡Ô´à˵ءÒó ¹¢Õé ¹Öé ºÔµ¹Õ¨é Ð૵໠¹ 1 áÅдíÒçʶҹйÕäé Ç ¨¹¡Ç Ò¨ÐÁÕ¡ÒÃà¢Õ¹¢ ÍÁÙÅ 0 ÁÒÂѧºÔµ¹Õé ´ Ç¡Ãкǹ¡Ò÷ҧ«Í¿µ áÇà ËÃ×Íà¤ÅÕÂà ´Ç ¡ÒûŴä¿àÅÕÂé § »ÃÐ⪹ ¢Í§ºÔµ¹Õ¤é Í× ËÒ¡ºÔµ¹Õàé «µ·Ñ¹·Õ·¨Õè Ò Âä¿àÅÕÂé § ãËÁ ¡ç¨Ð·Ã񼊫 ·¹Ñ ·ÕÇè Ò ¢³Ð¹ÕÍé ³ Ø ËÀÙÁ·Ô ÇÕè ´Ñ ä´ Á¤Õ Ò ÊÙ§¡Ç Ҩش·ÃÔ¡ÍسËÀÙÁÔ TH ¼Ùã ª §Ò¹ÊÒÁÒöàÅ×Í¡ä´ ÇÒ ¨Ðá¡ ä¢ ¤ ÒÍسËÀÙÁ¢Ô ͧ¨Ø´ TH ËÃ×ÍäÁ ËÃ×Íä»á¡ ä¢ã¹Ê ǹÍ×¹è á·¹ ´Ñ§¹Ñ¹é àÁ×Íè àÃÔÁè µ ¹ãª §Ò¹ DS1621 ¨Ö§¤ÇÃÍ Ò¹ºÔµá¿Å¡¹Õé ¡ ͹à¾×è͵ÃǨÊͺ TLF (Temperature Low Flag - ºÔµ 5) : ºÔµá¿Å¡á¨ §Ç ÒÍسËÀÙÁ·Ô ÇÕè ´Ñ ä´ à· Ò¡ÑºËÃ×͵èÒí ¡Ç Ò¨Ø´·ÃÔ¡ÍسËÀÙÁÔ µèÒí ËÃ×Í TL àÁ×Íè à¡Ô´à˵ءÒó ¹¢Õé ¹Öé ºÔµ¹Õ¨é Ð૵໠¹ 1 áÅдíÒçʶҹйÕäé Ç ¨¹¡Ç Ò¨ÐÁÕ¡ÒÃà¢Õ¹¢ ÍÁÙÅ 0 ÁÒÂѧºÔµ ¹Õ´é Ç Â¡Ãкǹ¡Ò÷ҧ«Í¿µ áÇà ËÃ×Íà¤ÅÕÂà ´Ç ¡ÒûŴä¿àÅÕÂé § »ÃÐ⪹ ¢Í§ºÔµ¹Õ¨é ÐàËÁ×͹¡Ñº THF ËÒ¡áµ ¨ÐµÃǨ Êͺ·Õè¤ Ò¢Í§ÍسËÀÙÁÔ·ÕèÇÑ´ä´ ÁÕ¤ Òà· ÒËÃ×͵èíÒ¡Ç Ò¨Ø´·ÃÔ¡ÍسËÀÙÁÔµèíÒ TL NVB (Nonvolatile Memory Busy Flag - ºÔµ 4) : ºÔµá¿Å¡áÊ´§Ê¶Ò¹Ð¡ÒÃà¢Õ¹¢ ÍÁÙÅŧã¹Ë¹ Ç ¤ÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁÀÒÂã¹ DS1621 à¾×Íè à¡çº¤ Ò¾ÒÃÒÁÔàµÍà ·¨Õè Òí à» ¹ »¡µÔ㪠àÇÅÒ»ÃÐÁÒ³ 10 ÁÔÅÅÔÇ¹Ô Ò·Õ 0 - ÂѧÍÂÙà ÐËÇ Ò§¡ÒÃà¢Õ¹¢ ÍÁÙÅ 1 - ¡ÒÃà¢Õ¹¢ ÍÁÙÅàÊÃç¨ÊÁºÙó ºÔµ 3 : äÁ 㪠§Ò¹ ¡íÒ˹´ãË à» ¹ 1 ºÔµ 2 : äÁ 㪠§Ò¹ ¡íÒ˹´ãË à» ¹ 0 POL (Output Polarity Bit - ºÔµ 1) : ºÔµàÅ×͡ʶҹÐàÍÒµ ¾µØ ¢Í§¢Ò TOUT àÁ×Íè ·íÒ§Ò¹ã¹âËÁ´à·Íà âÁ ʵѵ àÁ×Íè àÅ×Í¡áŠǢ ÍÁÙŢͧºÔµ¹Õ¨é дíÒçÍÂÙä »µÅÍ´áÁ »Å´ä¿àÅÕÂé §¡çµÒÁ ºÔµ¹Õáé Í¡µÕ¿´ ÇÂÅͨԡ 0 1SHOT (One Shot Mode - ºÔµ 0) : ºÔµàÅ×Í¡ÇÔ¸¡Õ ÒÃÇÑ´áÅÐá»Å§¤ ÒÍسËÀÙÁ¢Ô ͧ DS1621 àÁ×Íè àÅ×Í¡ áŠǢ ÍÁÙŢͧºÔµ¹Õé¨Ð´íÒçÍÂ٠仵ÅÍ´áÁ »Å´ä¿àÅÕ駡çµÒÁ 0 - ¡íÒ˹´ãË DS1621 ·íÒ¡ÒÃÇÑ´áÅÐá»Å§¤ ÒÍ ҧµ Íà¹×Íè § 1 - ¡íÒ˹´ãË DS1621 àÃÔÁè ·íÒ¡ÒÃá»Å§¤ ÒÍسËÀÙÁàÔ Á×Íè ä´ ÃºÑ ÊÑ­­Ò³àÃÔÁè µ ¹ â´Â»¡µÔáŠǤÇáíÒ˹´ãË DS1621 ·íÒ¡ÒÃÇÑ´áÅÐá»Å§¤ ÒÍسËÀÙÁÍÔ Â Ò§µ Íà¹×Íè § àÇ ¹áµ µÍ §¡ÒäǺ ¤ØÁ¡ÒÃ㪠¾Åѧ§Ò¹¢Í§ DS1621 à¾ÃÒÐËÒ¡ DS1621 äÁ ä´ Ç´Ñ ÍسËÀÙÁáÔ ÅÐá»Å§¤ Ò¨Ð㪠¾Åѧ§Ò¹ä¿¿ ÒŴŧ

! "

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


12.3.4 ¤íÒÊѧè 㹡ÒÃ㪠§Ò¹ DS1621 ¡ÒÃÍ Ò¹áÅÐà¢Õ¹¢ ÍÁÙšѺ DS1621 ÁÕû٠Ẻµ Ò§æ ¡Ñ¹ä»µÒÁÅѡɳТ ÍÁÙÅáÅФíÒÊÑ§è ´Ñ§áÊ´§ã¹ÃÙ»·Õè 12-11 㹡ÒÃà¢Õ¹¢ ÍÁÙÅËÃ×ͤíÒÊѧè ä»Âѧ DS1621 ÍØ»¡Ã³ ÁÒÊàµÍà («Ö§è ã¹·Õ¹è ¤Õé Í× i-Stamp2P24) ¨Ð¡íÒ˹´ ¤ ÒáÍ´à´Ãʢͧ DS1621 µÑÇ·Õµè Í §¡ÒõԴµ Í áŠǵÒÁ´ Ç¡ÒÃ૵ºÔµ R/W ¨Ò¡¹Ñ¹é ¨ÐÃÍ¡ÒõͺÃѺ¨Ò¡ÍØ »¡Ã³ ÊàÅ¿ «Ö§è ¡ç¤Í× DS1621 àÁ×Íè ä´ ÃºÑ ¡ÒõͺÃѺáÅ Ç ÍØ»¡Ã³ ÁÒÊàµÍà ¨Ð¨Ñ´àµÃÕÂÁ¤íÒÊѧè à¾×Íè 㪠§Ò¹ DS1621 µ Íä» â´Â·Ø¡¤ÃÑ§é ·ÕÁè ¡Õ ÒÃà¢Õ¹¤íÒÊѧè ä»Âѧ DS1621 µ ͧà¤ÅÕÂà ºµÔ R/W ´ ÇÂàÊÁÍ àÁ×Íè DS1621 ä´ ÃºÑ ¤íÒÊÑ§è ¨Ò¡ÍØ»¡Ã³ ÁÒÊàµÍà ¡ç¨Ð´íÒà¹Ô¹¡ÒõÒÁ·Õè¡íÒ˹´ÁÒ¨Ò¡ÍØ»¡Ã³ ÁÒÊàµÍà áÅзء¤ÃÑ駨е Í§Ê §ÊÑ­­Ò³ÃѺÃÙ ËÃ×͵ͺÃѺ¡ÅѺä»ÂѧÍØ»¡Ã³ ÁÒÊàµÍà ÊíÒËÃѺ¤íÒÊÑ§è ·Ñ§é ËÁ´¢Í§ DS1621 ÁÕ´§Ñ ¹Õé à¢Õ¹¤íÒÊѧè 㹡ÅØÁ ·Õäè Á µÍ §¡Òâ ÍÁÙŠઠ¹ ¤íÒÊѧè àÃÔÁè µ ¹/ËÂØ´¡ÒÃá»Å§¤ ÒÍسËÀÙÁÔ SCL SDA

S 1 0 0 1 ) ) ) W A +% +$ +# +" +! + + + A

áÍ´à´ÃÊ START

P

¤íÒÊѧè DS1621 ACK

STOP

DS1621 ACK

à¢Õ¹¤íÒÊѧè 㹡ÅØÁ ·Õµè Í §¡Òâ ÍÁÙÅ 1 亵 ઠ¹ ¤íÒÊѧè ࢠҶ֧ÃÕ¨ÊÔ àµÍà ¡Òí ˹´¡Ò÷íÒ§Ò¹áÅÐáÊ´§Ê¶Ò¹Ð SCL SDA

S 1 0 0 1 ) ) ) W A +% +$ +# +" +! + + + A ,% ,$ ,# ," ,! , , , A

áÍ´à´ÃÊ START

¤íÒÊѧè DS1621 ACK

P

¢ ÍÁÙÅ DS1621 ACK

DS1621 ACK

STOP

à¢Õ¹¤íÒÊѧè 㹡ÅØÁ ·Õµè Í §¡Òâ ÍÁÙÅ 2 亵 ઠ¹ ¤íÒÊѧè ࢠҶ֧¤ Ò TH áÅÐ TL SCL SDA

S 1 0 0 1 ) ) ) W A +% +$ +# +" +! + + + A ,% ,$ ,# ," ,! , , , A ,% ,$ ,# ," ,! , , , A

áÍ´à´ÃÊ START

¤íÒÊѧè DS1621 ACK

¢ ÍÁÙÅ亵 ʧ٠DS1621 ACK

DS1621 ACK

P

¢ ÍÁÙÅ亵 µÒèí DS1621 ACK

STOP

Í Ò¹¢ ÍÁÙŨҡÃÕ¨ÊÔ àµÍà ·ÁèÕ ¢Õ ¹Ò´ 1 亵 ä´ á¡ ÃÕ¨ÊÔ àµÍà ¡Òí ˹´¡Ò÷íÒ§Ò¹áÅÐáÊ´§Ê¶Ò¹Ð, µÑǹѺ áÅеÑǹѺÊâÅ» SCL SDA

S 1 0 0 1 ) ) ) W A +% +$ +# +" +! + + + A

áÍ´à´ÃÊ START

R

1 0

¤íÒÊѧè DS1621 ACK

0 1 ) ) ) 4@ A ,% ,$ ,# ," ,! , , , N

áÍ´à´ÃÊ DS1621 ACK Repeat START

P

¢ ÍÁÙÅ STOP MASTER NACK

DS1621 ACK

Í Ò¹¢ ÍÁÙŨҡÃÕ¨ÊÔ àµÍà ·ÁèÕ ¢Õ ¹Ò´ 2 亵 ä´ á¡ ¤ Ңͧ TH, TL áÅФ ÒÍسËÀÙÁÔ SCL SDA

S 1 0 0 1 ) ) ) W A +% +$ +# +" +! + + + A

áÍ´à´ÃÊ START

R

1 0

¤íÒÊѧè DS1621 ACK

0 1 ) ) ) 4@ A ,% ,$ ,# ," ,! , , , A ,% ,$ ,# ," ,! , , , N

áÍ´à´ÃÊ DS1621 ACK Repeat START

¢ ÍÁÙÅ DS1621 ACK

P

¢ ÍÁÙÅ MASTER ACK

STOP MASTER NACK

ÃÙ»·Õè 12-11 ä´ÍÐá¡ÃÁàÇÅÒáÊ´§ÃٻẺ¡ÒõԴµ ͺ¹ÃкººÑÊ I2C ¢Í§ DS1621

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

! #


12.3.4.1 ¤íÒÊѧè Í Ò¹ÍسËÀÙÁÔ (Read Temperature : ¢ ÍÁÙŤíÒÊѧè à» ¹ AAH) à» ¹¤íÒÊѧè Í Ò¹¤ ÒÍسËÀÙÁÅÔ Ò ÊØ´·Õè DS1621 ·íÒ¡ÒÃá»Å§àÊÃç¨ÊÁºÙó â´Â DS1621 ¨ÐÊ §¢ ÍÁÙÅ¢¹Ò´ 2 亵 ·áÕè ·¹¤ ÒÍسËÀÙÁ¡Ô ÅѺÁÒ (¨ÃÔ§æ áÅ Ç㪠à¾Õ§ 9 ºÔµ)

12.3.4.2 ¤íÒÊѧè ࢠҶ֧¤ Ò TH (Access TH : ¢ ÍÁÙŤíÒÊѧè à» ¹ A1H) à» ¹¤íÒÊѧè ÊíÒËÃѺࢠҶ֧ËÃ×͵Դµ ͡Ѻ¤ Ңͧ¨Ø´·ÃÔ¡ÍسËÀÙÁÊÔ §Ù ËÃ×Í TH ¶ ÒËÒ¡ºÔµ R/W ¶Ù¡¡íÒ˹´ ãË à» ¹ 0 à» ¹¡ÒÃÃкØÇÒ µ ͧ¡ÒÃà¢Õ¹¢ ÍÁÙÅä»Âѧ DS1621 à¾×Íè ¡íÒ˹´¤ ÒËÃ×ÍµÑ§é ¤ Ò TH ãËÁ â´Â¢ ÍÁÙÅ·Õè à¢Õ¹ÁÕ¢¹Ò´ 2 亵 áµ ¶Ò ºÔµ R/W à» ¹ 1 ¨Ðà» ¹¡ÒÃࢠҶ֧à¾×Íè Í Ò¹¤ Ò TH ã¹¢³Ð¹Ñ¹é ¢Í§ DS1621 á·¹

12.3.4.3 ¤íÒÊѧè ࢠҶ֧¤ Ò TL (Access TL : ¢ ÍÁÙŤíÒÊѧè à» ¹ A2H) à» ¹¤íÒÊѧè ÊíÒËÃѺࢠҶ֧ËÃ×͵Դµ ͡Ѻ¤ Ңͧ¨Ø´·ÃÔ¡ÍسËÀÙÁµÔ Òèí ËÃ×Í TL ¶ ÒËÒ¡ºÔµ R/W ¶Ù¡¡íÒ˹´ ãË à» ¹ 0 à» ¹¡ÒÃÃкØÇÒ µ ͧ¡ÒÃà¢Õ¹¢ ÍÁÙÅä»Âѧ DS1621 à¾×Íè ¡íÒ˹´¤ ÒËÃ×ÍµÑ§é ¤ Ò TL ãËÁ â´Â¢ ÍÁÙÅ·Õè à¢Õ¹ÁÕ¢¹Ò´ 2 亵 áµ ¶Ò ºÔµ R/W à» ¹ 1 ¨Ðà» ¹¡ÒÃࢠҶ֧à¾×Íè Í Ò¹¤ Ò TL ã¹¢³Ð¹Ñ¹é ¢Í§ DS1621 á·¹

¤íÒÊÑè§

¢ ÍÁÙŤíÒÊÑè§

¡Ò÷íÒ§Ò¹ËÅÑ§Ê §¤íÒÊÑè§ ËÁÒÂà˵Ø

¤íÒÊÑè§à¡ÕèÂǡѺ¡ÒÃá»Å§¤ ÒÍسËÀÙÁÔ Í Ò¹¤ ÒÍسËÀÙÁÔ AAH Í Ò¹¤ ÒµÑǹѺ A8H Í Ò¹¤ ÒµÑǹѺÊâÅ» A9H àÃÔèÁµ ¹á»Å§¤ ÒÍسËÀÙÁÔ EEH ËÂØ´á»Å§¤ ÒÍسËÀÙÁÔ 22H

Í Ò¹¢ ÍÁÙÅ 2 亵 Í Ò¹¢ ÍÁÙÅ 1 亵 Í Ò¹¢ ÍÁÙÅ 1 亵 ËÂØ´áÅÐàµÃÕÂÁ¾Ã ÍÁàÃÔèÁµ ¹ ËÂØ´áÅÐàµÃÕÂÁ¾Ã ÍÁàÃÔèÁµ ¹

1 1

¤íÒÊѧè ã¹âËÁ´à·Íà âÁʵѵ ࢠҶ֧ TH

A1H

à¢Õ¹¢ ÍÁÙÅ 1 亵

2

ࢠҶ֧ TL ࢠҶ֧ÃÕ¨ÔÊàµÍà Config.

A2H ACH

à¢Õ¹¢ ÍÁÙÅ 1 亵 à¢Õ¹¢ ÍÁÙÅ 1 亵

2 2

ËÁÒÂà赯 1. ã¹âËÁ´¡ÒÃá»Å§¤ ÒÍ ҧµ Íà¹×èͧ àÁ×èÍ DS1621 ¡ÃзíÒ¤íÒÊÑè§ËÂØ´¡ÒÃá»Å§¤ Ò ¨Ðà» ¹¡ÒáàÅÔ¡¡Òà á»Å§¤ ÒÍ ҧµ Íà¹×èͧ·Ñ¹·Õ ËÒ¡µ ͧ¡ÒÃãË DS1621 á»Å§¤ ÒÍÕ¡¤ÃÑé§ µ ͧà¢Õ¹¤íÒÊÑè§àÃÔèÁµ ¹¡ÒÃá»Å§¤ Ò ãË á¡ DS1621 ãËÁ 2. ¡ÒÃà¢Õ¹¢ ÍÁÙÅä»ÂѧÃÕ¨ÔÊàµÍà DS1621 µ ͧ¡ÒÃàÇÅÒ 10 ÁÔÅÅÔÇÔ¹Ò·Õà» ¹Í ҧ¹ ÍÂ㹡ÒÃà¢Õ¹¢ ÍÁÙÅãË ÊÁºÙó

µÒÃÒ§·Õè 12-2 µÒÃÒ§ÊÃØ»¤íÒÊѧè ÊíÒËÃѺ㪠§Ò¹ DS1621 ! $

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


12.3.4.4 ¤íÒÊѧè ࢠҶ֧ÃÕ¨ÊÔ àµÍà ¡Òí ˹´¡Ò÷íÒ§Ò¹áÅÐáÊ´§Ê¶Ò¹Ð (Access Config : ¢ ÍÁÙŤíÒÊѧè à» ¹ ACH) à» ¹¤íÒÊѧè ÊíÒËÃѺࢠҶ֧ËÃ×͵Դµ ͡ѺÃÕ¨ÊÔ àµÍà ¡Òí ˹´¡Ò÷íÒ§Ò¹áÅÐáÊ´§Ê¶Ò¹Ð (Config) ¶ ÒËÒ¡ºÔµ R/W à» ¹ 0 áÊ´§Ç Òµ ͧ¡ÒÃà¢Õ¹¢ ÍÁÙÅ¢¹Ò´ 1 亵 à¾×Íè ¡íÒ˹´¡Ò÷íÒ§Ò¹¢Í§ DS1621 áµ ¶Ò ËÒ¡ºÔµ R/W à» ¹ 1 ¨Ðà» ¹¡ÒÃࢠҶ֧à¾×Íè Í Ò¹¤ ҢͧÃÕ¨ÊÔ àµÍà à¾×Íè µÃǨÊͺʶҹСÒ÷íÒ§Ò¹¢Í§ DS1621

12.3.4.5 ¤íÒÊѧè Í Ò¹µÑǹѺ (Read Counter : ¢ ÍÁÙŤíÒÊѧè à» ¹ A8H) à» ¹¤íÒÊѧè ÊíÒËÃÑºÍ Ò¹¤ ÒµÑǹѺ·Õãè ª 㹡ÒÃá»Å§¤ ÒÍسËÀÙÁ¢Ô ͧ DS1621 㹡ÒÃ㪠¤Òí ÊÑ§è µ ͧ¡íÒ˹´ãË ºÔµ R/W à» ¹ 1 ෠ҹѹé

12.3.4.6 ¤íÒÊѧè Í Ò¹¤ ÒµÑǹѺÅÐàÍÕ´ (Read Slope : ¢ ÍÁÙŤíÒÊѧè à» ¹ A9H) à» ¹¤íÒÊѧè ÊíÒËÃÑºÍ Ò¹¤ ÒµÑǹѺÅÐàÍÕ´ 㹡óշµÕè Í §¡ÒÃãË áÊ´§ÃÒÂÅÐàÍÕ´¤ ҢͧÍسËÀÙÁÔ «Ö§è à¡çºÍÂÙ ã¹µÑǹѺÅÐàÍÕ´ (slope counter) 㹡ÒÃ㪠§Ò¹¤íÒÊÑ§è ¹Õµé Í §¡íÒ˹´ãË ºµÔ R/W à» ¹ 1

12.3.4.7 ¤íÒÊѧè àÃÔÁè µ ¹á»Å§¤ ÒÍسËÀÙÁÔ (Start Convert T : ¢ ÍÁÙŤíÒÊѧè à» ¹ EEH) à» ¹¤íÒÊÑ§è ·Õ¡è Òí ˹´ãË DS1621 àÃÔÁè µ ¹¡ÒÃá»Å§¤ ÒÍسËÀÙÁÔ

12.3.4.8 ¤íÒÊѧè ËÂØ´¡ÒÃá»Å§¤ ÒÍسËÀÙÁÔ (Stop Convert T : ¢ ÍÁÙŤíÒÊѧè à» ¹ 22H) à» ¹¤íÒÊÑ§è ·Õ¡è Òí ˹´ãË DS1621 ËÂØ´¡ÒÃá»Å§¤ ÒÍسËÀÙÁÔ ÁÑ¡¨Ð㪠àÁ×Íè µ ͧ¡ÒÃãË DS1621 ËÂØ´ÇÑ´áÅÐá»Å§ ¤ ÒÍسËÀÙÁÍÔ Â Ò§µ Íà¹×Íè § ËÅѧ¨Ò¡·Õè DS1621 ¡ÃзíÒ¤íÒÊÑ§è ¹Õé ¤ ÒÍسËÀÙÁ·Ô áÕè »Å§ä´ ÅÒ ÊØ´¨ÐÂѧ¤§ÍÂÙ ¨¹¡Ç Ò¨ÐÁÕ¡Òà ¡ÅѺÁÒàÃÔÁè µ ¹á»Å§¤ ÒÍسËÀÙÁãÔ ËÁ ã¹µÒÃÒ§·Õè 12-2 à» ¹µÒÃÒ§ÊÃØ»¤íÒÊѧè 㪠§Ò¹ DS1621

12.3.5 ¨Ñ§ËÇСÒ÷íÒ§Ò¹¢Í§ DS1621 à¾×Íè ãË ÊÒÁÒöࢠÒ㨶֧ÅíҴѺ¡Ò÷íÒ§Ò¹ÃÇÁ¶Ö§Ê¶Ò¹Ðµ Ò§æ ¢Í§ DS1621 ¨Ö§ä´ ·Òí ¡ÒÃÊÃػʶҹТͧ ºÑÊ âËÁ´¡Ò÷íÒ§Ò¹¢Í§ DS1621 áÅЪ¹Ô´¢Í§¢ ÍÁÙÅ·Õ»è ÃÒ¡¯äÇ ã¹µÒÃÒ§·Õè 12-3

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

! %


âËÁ´¡Ò÷íÒ§Ò¹¢Í§ ÍØ»¡Ã³ ÁÒÊàµÍÃ

âËÁ´¡Ò÷íÒ§Ò¹¢Í§ DS1621

ÊÀÒÇÐáÅТ ÍÁÙÅ·Õè »ÃÒ¡¯º¹ºÑÊ

TX

RX

START

TX

RX

<ADDRESS,0>

RX

TX

ACK

TX

RX

ACH

RX

TX

ACK

TX

RX

02H

RX

TX

ACK

TX

RX

START

TX

RX

<address,0>

RX

TX

ACK

TX

RX

A1H

RX

TX

ACK

TX

RX

28H

RX

TX

ACK

TX

RX

00H

RX

TX

ACK

TX

RX

START

TX

RX

<address,0>

RX

TX

ACK

TX

RX

A2H

RX

TX

ACK

TX

RX

0AH

RX

TX

ACK

TX

RX

00H

RX

TX

ACK

TX

RX

START

TX

RX

<address,0>

RX

TX

ACK

TX

RX

EEH

RX

TX

ACK

TX

RX

STOP

ÃÒÂÅÐàÍÕ´ ¤ÍÁ¾ÔÇàµÍà ¡íÒ˹´ÊÀÒÇÐàÃÔèÁµ ¹ãË à¡Ô´¢Ö鹺¹ºÑÊ ¤ÍÁ¾ÔÇàµÍÃ Ê §¤ ÒáÍ´à´Ãʢͧ DS1621 áÅСíÒ˹´ºÔµ R/W à» ¹ "0" DS1621 Ê §ÊÑ­­Ò³ÃѺÃÙ µÍº¡ÅѺ ¤ÍÁ¾ÔÇàµÍÃ Ê §¤íÒÊÑè§à¢ Ò¶Ö§ÃÕ¨ÔÊàµÍà ¡íÒ˹´¡Ò÷íÒ§Ò¹ DS1621 Ê §ÊÑ­­Ò³ÃѺÃÙ µÍº¡ÅѺ ¤ÍÁ¾ÔÇàµÍÃ Ê §¢ ÍÁÙÅà¾×èÍ¡íÒ˹´ãË DS1621 á»Å§¤ ÒÍ ҧµ Í๠×èͧ áÅÐãË àÍÒµ ¾Øµà» ¹ÅͨԡÊÙ§àÁ×èÍÍسËÀÙÁÔ·ÕèÇÑ´ÊÙ§¶Ö§¨Ø´ TH DS1621 Ê §ÊÑ­­Ò³ÃѺÃÙ µÍº¡ÅѺ ¤ÍÁ¾ÔÇàµÍà ¡íÒ˹´ÊÀÒÇÐàÃÔèÁµ ¹ãË à¡Ô´¢Ö鹺¹ºÑÊÍÕ¡¤ÃÑé§ ¤ÍÁ¾ÔÇàµÍÃ Ê §¤ ÒáÍ´à´Ãʢͧ DS1621 áÅСíÒ˹´ºÔµ R/W à» ¹ "0" DS1621 Ê §ÊÑ­­Ò³ÃѺÃÙ µÍº¡ÅѺ ¤ÍÁ¾ÔÇàµÍÃ Ê §¤íÒÊÑè§à¢ Ò¶Ö§ TH DS1621 Ê §ÊÑ­­Ò³ÃѺÃÙ µÍº¡ÅѺ ¤ÍÁ¾ÔÇàµÍà à¢Õ¹¢ ÍÁÙÅ亵 ÊÙ§¢Í§¤ Ò TH (¡íÒ˹´ãË à· Ò¡Ñº +40ðC) DS1621 Ê §ÊÑ­­Ò³ÃѺÃÙ µÍº¡ÅѺ ¤ÍÁ¾ÔÇàµÍà à¢Õ¹¢ ÍÁÙÅ亵 µíèҢͧ¤ Ò TH DS1621 Ê §ÊÑ­­Ò³ÃѺÃÙ µÍº¡ÅѺ ¤ÍÁ¾ÔÇàµÍà ¡íÒ˹´ÊÀÒÇÐàÃÔèÁµ ¹ãË à¡Ô´¢Ö鹺¹ºÑÊÍÕ¡¤ÃÑé§ ¤ÍÁ¾ÔÇàµÍÃ Ê §¤ ÒáÍ´à´Ãʢͧ DS1621 áÅСíÒ˹´ºÔµ R/W à» ¹ "0" DS1621 Ê §ÊÑ­­Ò³ÃѺÃÙ µÍº¡ÅѺ ¤ÍÁ¾ÔÇàµÍÃ Ê §¤íÒÊÑè§à¢ Ò¶Ö§ TL DS1621 Ê §ÊÑ­­Ò³ÃѺÃÙ µÍº¡ÅѺ ¤ÍÁ¾ÔÇàµÍà à¢Õ¹¢ ÍÁÙÅ亵 ÊÙ§¢Í§¤ Ò TL (¡íÒ˹´ãË à· Ò¡Ñº +10ðC) DS1621 Ê §ÊÑ­­Ò³ÃѺÃÙ µÍº¡ÅѺ ¤ÍÁ¾ÔÇàµÍà à¢Õ¹¢ ÍÁÙÅ亵 µíèҢͧ¤ Ò TL DS1621 Ê §ÊÑ­­Ò³ÃѺÃÙ µÍº¡ÅѺ ¤ÍÁ¾ÔÇàµÍà ¡íÒ˹´ÊÀÒÇÐàÃÔèÁµ ¹ãË à¡Ô´¢Ö鹺¹ºÑÊÍÕ¡¤ÃÑé§ ¤ÍÁ¾ÔÇàµÍÃ Ê §¤ ÒáÍ´à´Ãʢͧ DS1621 áÅСíÒ˹´ºÔµ R/W à» ¹ "0" DS1621 Ê §ÊÑ­­Ò³ÃѺÃÙ µÍº¡ÅѺ ¤ÍÁ¾ÔÇàµÍÃ Ê §¤íÒÊÑè§àÃÔèÁµ ¹á»Å§¤ ÒÍسËÀÙÁÔ DS1621 Ê §ÊÑ­­Ò³ÃѺÃÙ µÍº¡ÅѺ ¤ÍÁ¾ÔÇàµÍà ¡íÒ˹´ÊÀÒÇÐËÂØ´ãË à¡Ô´¢Ö鹺¹ºÑÊ à¾×èÍËÂØ´¡Ò÷íÒ§Ò¹

ËÁÒÂà赯 6: ËÁÒ¶֧ ·íÒ˹ Ò·Õàè » ¹µÑÇÊ §, 4: ËÁÒ¶֧ ·íÒ˹ Ò·Õàè » ¹µÑÇÃѺ, 0 ·ÕÍè ÂÙË Åѧ¢ ÍÁÙÅ㪠áÊ´§Ç Ò ¢ ÍÁÙŹѹé æ à» ¹¢ ÍÁÙÅàÅ¢°Ò¹ÊԺˡ

µÒÃÒ§·Õè 12-3 áÊ´§µÑÇÍ ҧÅíҴѺ¡Ò÷íÒ§Ò¹ âËÁ´¡Ò÷íÒ§Ò¹¢Í§ÍØ»¡Ã³ ÁÒÊàµÍà («Ö§è ã¹·Õ¹è ¤Õé Í× iStamp2P) áÅÐ DS1621 µÅÍ´¨¹Ê¶Ò¹Ð¢Í§ºÑÊã¹¢³ÐµÔ´µ Í

! &

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¡Ò÷´Åͧ·Õè 17 ´Ô¨µÔ ÍÅà·Íà âÁÁÔàµÍà ©ºÑºàºÊÔ¡áʵÁ» 2P à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P24 2. ºÍà ´ JX-2SX plus II ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. ÊÒµ Íǧ¨Ã 5. äÍ«Õ DS1621 1 µÑÇ 6. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 2.2k: 2 µÑÇ 7. µÑÇà¡çº»ÃÐ¨Ø 0.1PF 50V â¾ÅÕàÍÊàµÍà 1 µÑÇ

¡Ò÷´Åͧ 17.1 㪠ǧ¨Ãã¹ÃÙ»·Õè L17-1 㹡Ò÷´Åͧ â´Âµ Íǧ¨Ãŧº¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ 17.2 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å LAB1701.BSP '********************************************************** ' Program : LAB1701.BSP ' Description : Digital thermometer with DS1621 ' Hardware : See schematic L17-1 '********************************************************** ' {$STAMP BS2p} ' {$PBASIC 2.5} RD_TEMP CON $AA ' READ temperature RD_CNT CON $A8 ' READ counter RD_SLOPE CON $A9 ' READ slope START_T CON $EE ' Start conversion STOP_T CON $22 ' STOP conversion ACCESS_TH CON $A1 ' Read/Write TH ACCESS_TL CON $A2 ' Read/Write TL CONFIG CON $AC ' Read/Write CONFIG. register ID CON $90 ' Slave ID. RESULT MSB LSB POINT SIGN

VAR VAR VAR VAR VAR

Word Byte Byte Byte Byte

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

! '


I2COUT 0,ID,CONFIG,[%00001010] ' Continuous conversion PAUSE 15 ' Delay 15 ms I2COUT 0,ID,[START_T] ' Start conversion LOOP1: I2CIN 0,ID,RD_TEMP,[MSB,LSB] GOSUB RESULT_ADJ GOTO LOOP1 RESULT_ADJ: SIGN = "-" ' Show negative temperature IF MSB.BIT7 = 1 THEN NEG_ADJ SIGN = " " ' Show positive temperature MSB = MSB << 1 MSB.BIT0 = LSB.BIT7 SHOW: POINT = "5" IF MSB.BIT0 = 1 THEN HALF POINT = "0" HALF: MSB = MSB/2 PAUSE 10 DEBUG HOME,"TEMPERATURE = ",SIGN,DEC MSB,".",POINT," C" RETURN NEG_ADJ: MSB = MSB << 1 MSB.BIT0 = LSB.BIT7 MSB = ~MSB ' 1 s complement MSB = MSB + 1 ' 2 s complement GOTO SHOW

¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ àÃÔÁè µ ¹â»Ãá¡ÃÁ´ Ç¡ÒáíÒ˹´ÃٻẺ¡Ò÷íÒ§Ò¹ãË á¡ DS1621 â´Â¡ÒÃÊ §¤íÒÊѧè I2COUT 0,ID,CONFIG,[%00001010] ´ ǤíÒÊÑ§è ¹Õ¨é СíÒ˹´ãË DS1621 ·íÒ¡ÒÃÇÑ´áÅÐá»Å§¤ ÒÍسËÀÙÁÍÔ Â Ò§µ Íà¹×Íè § ¨Ò¡¹Ñ¹é ˹ ǧàÇÅÒàÅ硹 Í áÅ ÇÊ §¤íÒÊÑè§à¾×èÍàÃÔèÁµ ¹¡ÒÃÇÑ´áÅÐá»Å§¤ ÒÍسËÀÙÁÔ´ ǤíÒÊÑè§ I2COUT 0,ID,[START_T] ¨Ò¡¹Ñ¹é ࢠÒÊÙ¡ ÒÃÍ Ò¹¤ ÒÍسËÀÙÁ¡Ô ÅѺ¨Ò¡ DS1621 ´ ǤíÒÊѧè I2CIN 0,ID,RD_TEMP,[MSB,LSB] à¾×Íè ãË ¡ÒÃáÊ´§¼Å¶Ù¡µ ͧáÅÐࢠÒ㨧 Ò i-Stamp2P24 ¨Ð¹íÒ¢ ÍÁÙÅ´Ôº·Õäè ´ ¨Ò¡ DS1621 ä»·íÒ¡ÒûÃѺ»Ãا â´Â¡ÃÐâ´´ä»·íÒ§Ò¹Âѧâ»Ãá¡ÃÁ Í RESULT_ADJ «Ö§è ¨Ðá»Å§¢ ÍÁÙÅ´Ô¨µÔ ÍÅà» ¹¢ ͤÇÒÁ·Õàè ¢ Òã¨ä´ ÃÇÁ¶Ö§á»Å§¤ Ò ÍسËÀÙÁ·Ô àÕè » ¹Åºà¾×Íè ãË ÊÒÁÒöáÊ´§¼Å¼ ҹ˹ Òµ Ò§ Debig Terminal ä´ Í ҧ¶Ù¡µ ͧ áÅÐà» ¹¢ ÍÁÙÅ·Õàè ¢ Òã¨ä´ §Ò Â

!

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


+5V

R1 2.2k P1

i-Stamp2P24 P0

C1 0.1/50V

8 V,,

R2 2.2k 2 SCL 1 SDA

GND A2 A1 A0 4 5 6 7

IC1 DS1621 Temperature Sensor

ÃÙ»·Õè L17-1 ǧ¨Ã´Ô¨µÔ ÍÅà·Íà âÁÁÔàµÍà ·ãÕè ª i-Stamp2P24 à ÇÁ¡Ñº DS1621 áÊ´§¼Å¼ Ò¹¤ÍÁ¾ÔÇàµÍà 17.3 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§Ç§¨Ã ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡®¢Ö¹é áÊ´§¢ ͤÇÒÁ TEMPERATURE = 27.5 C ´Ñ§ÃÙ»

áµ ¤Ò ÍسËÀÙÁÔ ÍÒ¨äÁ 㪠¤Ò µÒÁ¹Õé ·Ñ§é ¹Õ¨é Тֹé ÍÂÙ¡ ºÑ ÍسËÀÙÁËÔ Í §·Õ·è Òí ¡Ò÷´Åͧ ¶ Ò·ÕËè ¹ Òµ Ò§ Debug Terminal áÊ´§¢ ͤÇÒÁ·Õ¼è ´Ô 仨ҡ¹Õé ãË ·Òí ¡ÒÃµÑ§é ¤ ҺʹàõãË ¶¡Ù µ ͧ ËÃ×Í·´Åͧ㪠àÁÒÊ ¡´·Õ»è ÁØ Clear ·Õ´è Ò ¹ Å Ò§¢Í§Ë¹ Òµ Ò§ Debug Terminal ¡ç¨Ð»ÃÒ¡®¢ ͤÇÒÁ·Õ¶è ¡Ù µ ͧ 17.4 ·´Åͧ¹íÒ»ÅÒÂËÑÇáà §áª ·¨Õè Ò Âä¿äÇ áÅ Ç ÁÒÍѧ·Õµè ÇÑ ¶Ñ§¢Í§äÍ«Õ DS1621 Êѧࡵ¼Å¡Ò÷íÒ§Ò¹ ¨Ð¾ºÇ Ò ÍسËÀÙÁ¨Ô Ф ÍÂæ à¾ÔÁè ¢Ö¹é ·ÕÅÐ 0.5 ͧÈÒà«Åà«ÕÂÊ â´Ââ»Ãá¡ÃÁ·´Åͧ·Õàè ¢Õ¹¢Ö¹é ¹ÕÊé ÒÁÒö áÊ´§¼Åä´ µ§Ñé áµ -55 ¶Ö§ 125 ͧÈÒà«Åà«ÕÂÊ ÁÕ¤ÇÒÁÅÐàÍÕ´·Õè 0.5 ͧÈÒ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


!

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


º··Õè 13

㪠§Ò¹ i-Stamp2P24 ¡ÑºÍØ»¡Ã³ ÃкººÑÊ 1 ÊÒ 㹺·¹Õ¹é Òí àʹÍÃÒÂÅÐàÍÕ´áÅÐà·¤¹Ô¤ÇÔ¸¡Õ ÒÃ㪠§Ò¹ÍØ»¡Ã³ ¾àÔ ÈÉ·Õãè ª ¡ÒõԴµ ͼ Ò¹ÃкººÑÊ 1 ÊÒÂËÃ×Í 1-Wire «Ö§è ¾Ñ²¹Ò¢Ö¹é â´Â´ÑÅÅÑÊà«ÁԤ͹´Ñ¡àµÍà áÅд ǤÇÒÁÊÒÁÒö¾ÔàÈɢͧ i-Stamp2P24 ·ÕÁè ªÕ ´Ø ¤íÒÊÑ§è ¾ÔàÈÉ ÊíÒËÃѺ¡ÒõԴµ ͡ѺÍØ»¡Ã³ àËÅ Ò¹Õâé ´Â੾ÒÐ ·íÒãË ¡ÒÃ㪠§Ò¹ÍØ»¡Ã³ ¾àÔ ÈÉàËÅ Ò¹Õ§é Ò ÂáÅÐÊдǡ¢Ö¹é Í ҧÁÒ¡ ÍØ»¡Ã³ ·¹Õè Òí ÁÒà» ¹µÑÇÍ ҧ¤×Í DS18B20 äÍ«ÕÇ´Ñ ÍسËÀÙÁÔ ÊíÒËÃѺ¡Ò÷íÒ§Ò¹àº×Íé §µ ¹¢Í§ÃкººÑÊ 1 ÊÒÂÊÒÁÒÃ¶Í Ò¹ÃÒÂÅÐàÍÕ´à¾ÔÁè àµÔÁ㹺··Õè 3 ·ÕÊè Ç ¹¢Í§ ¤íÒÊѧè OWIN áÅÐ OWOUT

13.1 ¢ ÍÁÙŷҧ෤¹Ô¤â´ÂÊÃØ»¢Í§äÍ«ÕµÃǨ¨ÑºÍسËÀÙÁÔ DS18B20 DS18B20 à» ¹äÍ«ÕµÃǨ¨ÑºÍسËÀÙÁ·Ô ãÕè ª ¡ÒõԴµ ÍẺÃкººÑÊ˹֧è ÊÒ ÁÕ¢Òµ Í㪠§Ò¹ 3 ¢Ò ¤×Í DQ à» ¹ ¢Òàª×Íè Áµ ÍÃкººÑÊ, ¢Òµ Íä¿àÅÕÂé §ÀÒ¹͡ áÅТҡÃÒÇ´ ÁÕ¡ÒèѴ¢ÒáÅÐä´ÍÐá¡ÃÁ¡Ò÷íÒ§Ò¹ÀÒÂã¹áÊ´§ã¹ ÃÙ»·Õè 13-1 ãË ¼ÅÅѾ¸ à» ¹¢ ÍÁÙÅÍسËÀÙÁ·Ô àÕè Å×Í¡ÃдѺ¤ÇÒÁÅÐàÍÕÂ´ä´ µ§Ñé áµ 9, 10, 11 áÅÐ 12 ºÔµ ¨Ö§·íÒãË ÊÒÁÒöáÊ´§ ¤ÇÒÁÅÐàÍÕ´¢Í§¤ ÒÍسËÀÙÁàÔ » ¹ 0.5, 0.25, 0.125 áÅÐ 0.0625 ͧÈÒà«Åà«ÕÂÊä´ â´Â㪠àÇÅÒ㹡ÒÃá»Å§¤ ÒÍسËÀÙÁÔ ·Õ¤è ÇÒÁÅÐàÍÕ´ 12 ºÔµÊÙ§ÊØ´ 750 ÁÔÅÅÔÇ¹Ô Ò·Õ ÊíÒËÃѺÃٻẺ¢ ÍÁÙŢͧ DS18B20 à» ¹´Ñ§¹Õé ºÔµ 15 ºÔµ 14 ºÔµ 13 ºÔµ 12 ºÔµ 11 ºÔµ 10 ºÔµ 9 ºÔµ 8 ºÔµ 7 ºÔµ 6 ºÔµ 5 ºÔµ 4 ºÔµ 3 ºÔµ 2 ºÔµ 1 ºÔµ 0 5

5

5

5

5

6

5

4

3

2

1

¢ ÍÁÙÅ亵 ʧÙ

0

-1

-2

-3

-4

¢ ÍÁÙÅ亵 µÒèí

ã¹µÒÃÒ§·Õè 13-1 áÊ´§¤ÇÒÁÊÑÁ¾Ñ¹¸ ¢Í§¢ ÍÁÙÅ´Ô¨µÔ ÍÅàÍÒµ ¾µØ ·Õ¤è ÇÒÁÅÐàÍÕ´ 12 ºÔµ¡Ñº¤ ÒÍسËÀÙÁÔ Ç§¨Ã¤Çº¤ØÁÅͨԡ áÅÐ˹ ǤÇÒÁ¨íÒ

DQ

,5 &*

GND DQ

Vcc

+Vcc

ǧ¨Ã µÃǨ¨Ñºä¿àÅÕÂé §

˹ ǤÇÒÁ¨íÒÃÍÁ 64 ºÔµ áÅоÍà µÊíÒËÃѺ àª×èÍÁµ ͡Ѻ ÃкººÑÊ˹Öè§ÊÒÂ

˹ ǤÇÒÁ¨íÒ ¤ÇÒÁàÃçÇÊÙ§ ËÃ×ÍÊá¤Ãµª á¾´ (scratchpad)

CRC à¨à¹ÍàÃàµÍà ¢¹Ò´ 8 ºÔµ

µÑǵÃǨ¨ÑºÍسËÀÙÁÔ Ç§¨Ã·ÃÔ¡à¡Íà ¤ ÒÍسËÀÙÁÊÔ §Ù (TH) ǧ¨Ã·ÃÔ¡à¡Íà ¤ ÒÍسËÀÙÁµÔ Òèí (TL)

ÃÙ»·Õè 13-1 áÊ´§¡ÒèѴ¢ÒáÅÐâ¤Ã§Êà ҧ¡Ò÷íÒ§Ò¹ÀÒÂ㹢ͧäÍ«ÕµÃǨ¨ÑºÍسËÀÙÁÔ DS18B20 Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

! !


ÍسËÀÙÁÔ (ͧÈÒà«Åà«ÕÂÊ)

¢ ÍÁÙÅàÍÒµ ¾Øµ (àÅ¢°Ò¹Êͧ)

¢ ÍÁÙÅàÍÒµ ¾Øµ (àÅ¢°Ò¹ÊԺˡ)

+125

0000 0111 1101 0000

07D0H

+85

0000 0101 0101 0000

0550H

+25.0625

0000 0001 1001 0001

0191H

+10.125

0000 0000 1010 0010

00A2H

+0.5

0000 0000 0000 1000

0008H

0

0000 0000 0000 0000

0000H

-0.5

1111 1111 1111 1000

FFF8H

-10.125

1111 1111 0101 1101

FF5EH

-25.0625

1111 1101 0110 1111

FE6FH

-55

1111 1100 1001 0000

FC90H

µÒÃÒ§·Õè 13-1 ¢ ÍÁÙÅ´Ô¨µÔ ÍÅàÍÒµ ¾µØ ·Õ¤è ÇÒÁÅÐàÍÕ´ 12 ºÔµ¡Ñº¤ ÒÍسËÀÙÁ·Ô ÇÕè ´Ñ ä´ ¢Í§ DS18B20

13.2 ¡ÒèѴ˹ ǤÇÒÁ¨íÒã¹ DS18B20 ã¹ÃÙ»·Õè 13-2 áÊ´§¡ÒèѴ˹ ǤÇÒÁ¨íÒÊá¤Ã絪 á¾´ã¹ DS18B20 ¨ÐàËç¹ä´ ÇÒ ÁÕÊÇ ¹·Õàè ¾ÔÁè àµÔÁáÅÐᵡ µ Ò§¨Ò¡ DS1820 ËÃ×Í DS18S20 ¹Ñ¹è ¤×Í Ë¹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁ·Õãè ª 㹡ÒÃà¡çº¤ ҢͺࢵÍسËÀÙÁ´Ô Ò ¹ÊÙ§ (TH), ¤ Ңͺ ࢵÍسËÀÙÁ´Ô Ò ¹µèÒí (TL) áÅФ ҢͧÃÕ¨ÊÔ àµÍà ¡Òí ˹´¡Ò÷íÒ§Ò¹ (configuration register) â´ÂàÁ×Íè àÃÔÁè µ ¹¨ ÒÂä¿ãË á¡ DS18B20 ¤ Ңͧ TH, TL áÅФ ÒÃÕ¨ÊÔ àµÍà ¡Òí ˹´¡Ò÷íÒ§Ò¹¨Ð¶Ù¡Í Ò¹ÍÍ¡ÁҨҡ˹ ǤÇÒÁ¨íÒÍÕÍ¾Õ ÃÍÁâ´ÂÍѵâ¹ÁÑµÔ ¼Ùã ª §Ò¹ÊÒÁÒöᡠä¢áÅÐà¢Õ¹¡ÅѺࢠÒä»ãËÁ à¾×Íè ¡íÒ˹´¤ ÒÊíÒËÃѺ¡ÒÃàÃÔÁè µ ¹·íÒ§Ò¹ãËÁ ä´ Ë¹ ǤÇÒÁ¨íÒÊá¤Ã絪 á¾´ 亵 0 亵 1

¤ ÒÍسËÀÙÁäÔ ºµ µÒèí ¤ ÒÍسËÀÙÁäÔ ºµ ʧÙ

˹ ǤÇÒÁ¨íÒÍÕ; Õ ÃÍÁ

亵 2 亵 3 亵 4

ÃÕ¨ÊÔ àµÍà TH ËÃ×Í¢ ÍÁÙÅ亵 1

ÃÕ¨ÊÔ àµÍà TH ËÃ×Í¢ ÍÁÙÅ亵 1

ÃÕ¨ÊÔ àµÍà TL ËÃ×Í¢ ÍÁÙÅ亵 2

ÃÕ¨ÊÔ àµÍà TL ËÃ×Í¢ ÍÁÙÅ亵 2

ÃÕ¨ÊÔ àµÍà Configuration

ÃÕ¨ÊÔ àµÍà Configuration

亵 5 亵 6

ÊíÒÃͧäÇ (FFH)

亵 7 亵 8

ÊíÒÃͧäÇ (0CH) ÊíÒÃͧäÇ (10H) CRC

ÃÙ»·Õè 13-2 ¡ÒèѴÊÃÃ¾×¹é ·Õ¢è ͧ˹ ǤÇÒÁ¨íÒÀÒÂã¹ DS18B20 ! "

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


àÁ×Íè ÇÑ´ÍسËÀÙÁäÔ ´ ¡¨ç йíÒ¤ Ò·ÕÇè ´Ñ ä´ ¹ÁÕé Òà¡çºäÇ ã¹Êá¤Ãµª á¾´·Õäè ºµ 0 áÅÐ 1 ·Ñ§é ¹Õàé ¹×Íè §¨Ò¡äÍ«Õ DS18B20 ÊÒÁÒöãË ¢Í ÁÙŢͧÍسËÀÙÁäÔ ´ ÅÐàÍÕ´¶Ö§ 12 ºÔµ àÁ×Íè ¹íÒÁÒá»Å§à» ¹¢ ÍÁÙÅàÅ¢°Ò¹ÊÔº¨Ö§ÊÒÁÒöáÊ´§¤ÇÒÁ ÅÐàÍÕ´¢Í§ÍسËÀÙÁäÔ ´ ¶§Ö 0.5 ͧÈÒà«Åà«ÕÂÊáÅÐ 0.9 ͧÈÒ¿Òàùäε â´ÂÁÕÂÒ ¹ÇÑ´ÍسËÀÙÁÔ -55 ¶Ö§ +125 ͧÈÒ à«Åà«ÕÂÊËÃ×Í -67 ¶Ö§ +257 ͧÈÒ¿Òàùäε â´Â¤ ҢͧͧÈÒ¿Òàùäε µÍ §ãª ¡ÒÃá»Å§Ë¹ ÇÂࢠÒÁÒª Ç 㪠àÇÅÒ ã¹¡ÒÃá»Å§¤ ÒÍسËÀÙÁàÔ » ¹¢ ÍÁÙÅ´Ô¨µÔ ÍÅ»ÃÐÁÒ³ 200 ÁÔÅÅÔÇ¹Ô Ò·Õ ÊÒÁÒö¡íÒ˹´¢Íºà¢µ¢Í§ÍسËÀÙÁ·Ô ·Õè Òí ¡Òà ÇÑ´ä´ áÅÐãË á¨ §àµ×͹àÁ×Íè ¤ ҢͧÍسËÀÙÁÊÔ §Ù ¢Ö¹é ËÃ×ÍÅ´µèÒí ŧ¶Ö§¤ Ò·Õ¡è Òí ˹´ â´Â¤ ÒÍسËÀÙÁ·Ô ¡Õè Òí ˹´¹Õ¨é Ðà¡çºäÇ ·Õè Êá¤Ãµª á¾´ã¹äºµ 2 áÅÐ 3

13.3 Configuration register : ÃÕ¨ÊÔ àµÍà ¡Òí ˹´¡Ò÷íÒ§Ò¹ 㪠ÊÒí ËÃѺàÅ×Í¡¤ Ò¤ÇÒÁÅÐàÍÕ´¢Í§ÍسËÀÙÁ·Ô Õè DS18B20 Í Ò¹ä´ ÁÕû٠Ẻ¡ÒèѴ¢ ÍÁÙŴѧ¹Õé ºÔµ 7 ºÔµ 6 ºÔµ 5 ºÔµ 4 ºÔµ 3 ºÔµ 2 ºÔµ 1 ºÔµ 0

4

4

Ê Ç¹¡ÒÃàÅ×Í¡¤ Ò¤ÇÒÁÅÐàÍÕ´¨Ð¡ÃзíÒ¼ Ò¹ºÔµ R1 áÅÐ R0 ´Ñ§¹Õé 4

4

¤ÇÒÁÅÐàÍÕ´

¤ ÒàÇÅÒÊÙ§Êش㹡ÒÃá»Å§¤ Ò

9 ºÔµ

93.75 ÁÔÅÅÔÇÔ¹Ò·Õ (t conv/8)

10 ºÔµ

187.5 ÁÔÅÅÔÇÔ¹Ò·Õ (t conv/4)

11 ºÔµ

375 ÁÔÅÅÔÇÔ¹Ò·Õ (t conv/2)

12 ºÔµ

750 ÁÔÅÅÔÇÔ¹Ò·Õ (t conv)

13.4 ¤íÒÊѧè à¾×Íè ¤Çº¤ØÁ¡Ò÷íÒ§Ò¹¢Í§ DS18B20 ¤íÒÊÑ§è ·Õãè ª ÁÒ¡·ÕÊè ´Ø ÁÕ 3 ¤íÒÊÑ§è ´Ñ§¹Õé 1. ¤íÒÊÑè§äÁ µÔ´µ ͡Ѻ˹ ǤÇÒÁ¨íÒÃÍÁËÃ×ÍʤԻÃÍÁ (Skip ROM) à¹×èͧ¨Ò¡ã¹¡ÒÃ㪠§Ò¹ DS1820 â´Â»¡µÔáŠǨÐÁÕ DS18B20 ÍÂÙº ¹ÊÒÂÊÑ­­Ò³à¾Õ§µÑÇà´ÕÂÇ ¨Ö§äÁ ¨Òí à» ¹µ ͧµÔ´µ ͡Ѻ˹ ǤÇÒÁ¨íÒÃÍÁ ¢ ÍÁÙŢͧ¤íÒÊѧè ʤԻÃÍÁ·Õµè Í §Ê §ãË DS18B20 ¤×Í 0xCC 2. ¤íÒÊѧè á»Å§ÍسËÀÙÁÔ (Convert T) ÁÕ¤Ò à· Ò¡Ñº 0x44 àÁ×Íè Ê §¤íÒÊÑ§è ¹Õãé Ë DS18B20 ¨Ðµ ͧÃÍÍ ҧ ¹ Í 200 ÁÔÅÅÔÇ¹Ô Ò·Õ à¾×Íè ãË DS18B20 㪠àÇÅÒ¹Õãé ¹¡ÒÃá»Å§¤ ÒÍسËÀÙÁàÔ » ¹¢ ÍÁÙÅ´Ô¨µÔ ÍÅÁÒà¡çºäÇ ã¹Êá¤Ãµª á¾´ 3. ¤íÒÊѧè Í Ò¹¢ ÍÁÙŨҡ˹ ǤÇÒÁ¨íÒÊá¤Ãµª á¾´ (Read Scratchpad) ÁÕ¤Ò à· Ò¡Ñº 0xBE àÁ×Íè Ê §¤íÒÊÑ§è ¹Õé DS18B20 ¨Ð·ÂÍÂÊ §¢ ÍÁÙŤ ÒÍسËÀÙÁÍÔ Í¡Áҷѧé ËÁ´ 9 亵 ã¹µÒÃÒ§·Õè 13-2 áÊ´§¢Ñ¹é µÍ¹â´ÂÊÃØ»¢Í§¡ÒõԴµ ÍÃÐËÇ Ò§äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ¡ºÑ DS18B20

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

! #


+5V

R1 1.8k i-Stamp2P24

+5V ,5 &*

P0

R1 1.8k +5V

ÃÙ»·Õè 13-3 áÊ´§Ç§¨ÃµÔ´µ ͡ѺäÍ«Õ DS18B20 ¢Í§ i-Stamp2P24 ÁÕ¡ÒÃ㪠¢Ò¾Íà µã¹¡ÒõԴµ Í à¾Õ§ 1 ¢Ò෠ҹѹé áÅе ͧÁÕ¡Òõ ͵Ñǵ Ò¹·Ò¹ ¾ÙÅÍÑ» à¾×Íè ¡íÒ˹´ÊÀÒÇкÑÊÇ Ò§´ ÇÂ

i-Stamp2P24

,5 &*

P0

ÃÙ»·Õè 13-4 áÊ´§Ç§¨ÃµÔ´µ ͡ѺäÍ«Õ DS1820 ¢Í§ i-Stamp2P24 ã¹áºº Parasite ·íÒãË ÊÒÁÒö 㪠ÊÒÂÊÑ­­Ò³ÃÇÁ㹡ÒõԴµ Íà¾Õ§ 2 àÊ ¹ Ê §¼ÅãË ÊÒÁÒö㪠ÊÒªÕÅ´ ¸ÃÃÁ´Ò㹡ÒõԴµ Íä´

13.5 ¡ÒÃàª×Íè Áµ ͡Ѻ i-Stamp2P24 áÊ´§Ç§¨Ã¡ÒÃàª×Íè Áµ Íã¹ÃÙ»·Õè 13-3 㪠¢Ò¾Íà µà¾Õ§ 1 ¢ÒÊíÒËÃѺ¡ÒÃàª×Íè Áµ ͡Ѻ DS18B20 â´Âµ ͧÁÕ µÑǵ Ò¹·Ò¹¤ Ò 1.8k: µ ;ÙÅÍÑ»¡Ñºä¿àÅÕÂé § +5V ¨Ò¡¹Ñ¹é ¨Ö§·íÒ¡ÒÃà¢Õ¹â»Ãá¡ÃÁà¾×Íè µÔ´µ ͡ѹ â´Â㪠û٠Ẻ¡Òà µÔ´µ ͵ÒÁÁҵðҹÃкººÑÊ 1 ÊÒ¢ͧ´ÑÅÅÑÊ Í ҧäáçµÒÁà¾×Íè Å´¨íҹǹÊÒÂÊÑ­­Ò³Å§ ÊÒÁÒöàª×Íè Áµ Í DS18B20 ¡Ñº i-Stamp2P24 ´ ÇÂÊÒÂÊÑ­­Ò³ÃÇÁà¾Õ§ 2 àÊ ¹¤×Í DQ áÅСÃÒÇ´ â´Â·íÒ¡Òõ Í¢Ò VDD ¡Ñº¡ÃÒÇ´ ¢Í§ DS18B20 ࢠҴ Ç¡ѹ ¨ÐàÃÕ¡¡Òõ ÍẺ¹ÕÇé Ò Parasite ´Ñ§ã¹ÃÙ»·Õè 13-4 ¨ÐàËç¹ä´ Ç Ò ¡ÒõԴµ ͡ѺÍØ»¡Ã³ ºÑÊ˹Öè§ÊÒµ ͧ¡íÒ˹´ãË ¢Ò¾Íà µ·Õè㪠àª×èÍÁµ ͡Ѻ¢Ò DQ ·íÒ§Ò¹ ÊÅѺ໠¹ä´ ·Ñ駢ÒÍÔ¹¾ØµáÅÐàÍÒµ ¾Øµ´Ô¨ÔµÍÅà¾×èÍÃѺáÅÐÊ §¢ ÍÁÙšѺÍØ»¡Ã³

13.6 ¡ÒÃà¢Õ¹â»Ãá¡ÃÁà¾×Íè µÔ´µ ͡Ѻ DS18B20 à¹×Íè §¨Ò¡ i-Stamp2P24 ÁÕª´Ø ¤íÒÊÑ§è ¾ÔàÈÉÊíÒËÃѺµÔ´µ ͡ѺÍØ»¡Ã³ ã¹ÃкººÑÊ 1 ÊÒÂâ´Â੾ÒÐ ·íÒãË ¤ ÇÒÁÂØ §Âҡ㹡ÒÃà¢Õ¹â»Ãá¡ÃÁµÔ´µ ÍŴŧÍ ҧÁÒ¡ÁÒ â´Â੾ÒÐÍ ҧÂÔ觡Ѻ¡ÒÃà¢Õ¹â»Ãá¡ÃÁ·Õèµ Í§ ¡íÒ˹´ª ǧàÇÅÒáÅШѧËÇСÒ÷íҧҹ͠ҧáÁ ¹ÂíÒ ¤íÒÊÑ§è ¾ÔàÈɴѧ¡Å ÒǤ×Í OWIN áÅÐ OWOUT ´Ñ§¹Ñ¹é 㹡ÒÃà¢Õ¹â»Ãá¡ÃÁ¨ÐàÃÔÁè µ ¹´ Ç¡ÒÃ㪠¤Òí Êѧè OWOUT ¡ ͹ â´ÂàÁ×Íè DS1820 ÊÒÁÒöµÔ´ µ ͡Ѻ i-Stamp2P24 ä´ ¡¨ç ÐÁÕ¡ÒÃÊ §¾ÑÅÊ µÍºÊ¹Í§¡ÅѺÁÒ ¨Ò¡¹Ñ¹é ·íÒ¡ÒÃÍ Ò¹¤ ÒÍسËÀÙÁ¨Ô Ò¡ DS18B20 â´Â 㪠¤Òí Êѧè OWIN ͹֧è 㹡ÒõԴµ ͡Ѻ DS18B20 㹡Ò÷´Åͧ¹Õ¨é ÐÁÕ DS18B20 à¾Õ§µÑÇà´ÕÂǨ֧äÁ ¨Òí à» ¹µ ͧ㪠¤Òí Êѧè à¾×Íè µÔ´µ ͡Ѻ˹ ǤÇÒÁ¨íÒÃÍÁÀÒÂã¹ DS18B20 ¹Ñ¹è ¤×Í ¨ÐµÔ´µ ÍẺʤԻÃÍÁ (Skip ROM) ´Ñ§ÁÕû٠Ẻ¡ÒõԴµ ÍÊÃØ»ãË àËç¹Í ҧªÑ´à¨¹ã¹µÒÃÒ§·Õè 13-3

! $

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


¢Ñ¹é µÍ¹·Õè

¡Ò÷íÒ§Ò¹¢Í§ ÍØ»¡Ã³ ÁÒÊàµÍÃ

¢ ÍÁÙÅËÃ×ÍÊÀÒÇÐ

ÃÒÂÅÐàÍÕ´

1 2

µÑÇÊ § µÑÇÃѺ

ÃÕ૵ µÍºÃѺ

Êà ҧÊÑ­­Ò³ÃÕ૵ ÃÍ¡ÒõͺÃѺ¨Ò¡ DS18B20

3

µÑÇÊ §

$CC

¤íÒÊѧè Skip ROM

4

µÑÇÊ §

$44

¤íÒÊѧè á»Å§ÍسËÀÙÁÔ (Convert T)

5 6 7

µÑÇÃѺ µÑÇÊ § µÑÇÃѺ

¢ ÍÁÙÅ 1 亵 ÃÕ૵ µÍºÃѺ

Í Ò¹á¿Å¡ Busy 8 ¤Ãѧé Êà ҧÊÑ­­Ò³ÃÕ૵ ÃÍ¡ÒõͺÃѺ¨Ò¡ DS18B20

8 9

µÑÇÊ § µÑÇÊ §

$CC $BE

¤íÒÊѧè Skip ROM ¤íÒÊѧè Í Ò¹¤ Ò¨Ò¡Êá¤Ãµª á¾´

10

µÑÇÃѺ

¢ ÍÁÙÅ 9 亵

Í Ò¹¤ ҢͧÍسËÀÙÁ¨Ô Ò¡Êá¤Ãµª á¾´

11 12

µÑÇÊ § µÑÇÃѺ

ÃÕ૵ µÍºÃѺ

Êà ҧÊÑ­­Ò³ÃÕ૵ ÃÍ¡ÒõͺÃѺ¨Ò¡ DS18B20

13

-

-

·íÒ¡Òäíҹdz¤ Ò·Õäè ´ ¨Ò¡ DS18B20 à» ¹àÅ¢°Ò¹ÊÔºáŠǹíÒä»áÊ´§¼Å ËÃ×Í㪠§Ò¹Í×¹è µ Íä»

µÒÃÒ§·Õè 13-3 ÊÃØ»¢Ñ¹é µÍ¹¡ÒõԴµ ͡Ѻ DS18B20 â´ÂÍØ»¡Ã³ ÁÒÊàµÍà ¤Í× äÁâ¤Ã¤Í¹â·ÃÅàÅÍÃ

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

! %


¡Ò÷´Åͧ·Õè 18 àª×Íè Áµ Í DS18B20 ¡Ñº i-Stamp2P24 à¤Ã×Íè §Á×ÍáÅÐÍØ»¡Ã³ 1. i-Stamp2P 2. ºÍà ´·´Åͧ NX-BS2P ËÃ×ͺÍà ´ JX-2P ¾Ã ÍÁÊÒµ ͤÍÁ¾ÔÇàµÍà 3. ¤ÍÁ¾ÔÇàµÍà ·µÕè ´Ô µÑ§é â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà 4. äÍ«Õ DS18B20 1 µÑÇ 5. µÑǵ Ò¹·Ò¹ 1/4W 5% ¤ Ò 1.8k: 1 µÑÇ

¡Ò÷´Åͧ 㹡Ò÷´Åͧ¹Õ¨é Ðà» ¹¡ÒÃÍ Ò¹¤ ÒÍسËÀÙÁ¨Ô Ò¡äÍ«Õ DS18B20 ÁÒáÊ´§¼Å·Õ¤è ÍÁ¾ÔÇàµÍà ¼Ò ¹·Ò§Ë¹ Ò µ Ò§ Debug Terminal ÊÒÁÒöáÊ´§¼Åä´ µ§Ñé áµ -55.0 ¶Ö§ 125 ͧÈÒà«Åà«ÕÂÊ â´ÂÁÕ¤Ò ¤ÇÒÁÅÐàÍÕ´㹡ÒÃÇÑ´ ෠ҡѺ 0.5 ͧÈÒ ã¹¡Ò÷´Åͧ¹Õ¨é Ðàª×Íè Áµ Í DS18B20 ¡Ñº i-Stamp2P24 ·Ñ§é ã¹áººãª ä¿àÅÕÂé §¨Ò¡ÀÒ¹͡ (external power supply) áÅÐẺ㪠ä¿àÅÕÂé §¨Ò¡ÊÒ¢ ÍÁÙÅ (parasite power supply) 18.1 㪠ǧ¨Ãã¹ÃÙ»·Õè L18-1 㹡Ò÷´Åͧ â´Âµ Íǧ¨Ãŧº¹á¼§µ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ 18.2 à» ´â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà áÅ Çà¢Õ¹â»Ãá¡ÃÁµÒÁä¿Å L1801.BSP '********************************************************** ' Program : LAB1801.BSP ' Description : Interface DS18B20 ' FOR : i-Stamp2P24 ' Hardware : See schematic L18-1 ' Copyright Innovative Experiment Co.,Ltd. '********************************************************** ' {$STAMP BS2P} ' {$PBASIC 2.5} '******************* Byte MODE,LOW SPEED ********************** MODE0 CON 0 ' No Reset MODE1 CON 1 ' Reset before DATA MODE2 CON 2 ' Reset after DATA MODE3 CON 3 ' Reset before AND after DATA '******************* Bit MODE,LOW SPEED ********************** MODE4 CON 4 ' No Reset MODE5 CON 5 ' Reset before DATA MODE6 CON 6 ' Reset after DATA MODE7 CON 7 ' Reset before AND after DATA

! &

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


+5V

R1 1.8k i-Stamp2P24

P0

+5V ,5 &*

R1 1.8k +5V

i-Stamp2P24

,5 &*

P0

ÃÙ»·Õè L18-1 ǧ¨Ã·´ÅͧµÔ´µ ͡ѺäÍ«Õ DS18B20 ÃÙ»·Õè L18-2 ǧ¨Ã·´ÅͧµÔ´µ ͡ѺäÍ«Õ DS18B20 ¢Í§ i-Stamp2P24 Ẻ㪠ä¿àÅÕÂé §¨Ò¡ÀÒ¹͡ ¢Í§ i-Stamp2P24 Ẻ㪠ä¿àÅÕ駨ҡºÑÊËÃ×Í Parasite ' DS18B20 USE LOW SPEED ONLY (~20kbits/Sec (NOT include reset pulse)) TEMP VAR Word ' Holds the temperature value POINT VAR Byte ' For 0.5 degree SIGN VAR Byte ' For Positive or Negative temperature POWER VAR Bit ' Power supply status START: OWOUT 6,MODE1,[$CC,$B4] ' Send SKIP ROM and Read power supply OWIN 6,MODE6,[POWER] ' Read power supply IF POWER = 1 THEN SHOW2 SHOW1: DEBUG HOME,"PARASITE POWER",CR GOTO CHECK SHOW2: DEBUG HOME,"EXTERNAL POWER",CR CHECK: IF POWER = 1 THEN EXTERNAL ' Use external power supply PARASITE: OWOUT 6,MODE1,[$CC,$44] PAUSE DELAY ' Delay for parasite power GOTO DONE EXTERNAL: OWOUT 6,MODE1,[$CC,$44] ' Send SKIP ROM and CONVERT-TEMP. DONE: OWIN 6,MODE4,[TEMP] ' Get the temperature data from DS18B20 IF TEMP = 0 THEN DONE OWOUT 6,MODE1,[$CC,$BE] ' Send READ ScratchPad command OWIN 6,MODE2,[TEMP.LOWBYTE,TEMP.HIGHBYTE,SKIP 6]

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

! '


SIGN = "-" IF TEMP.HIGHBYTE.BIT0 = 1 THEN NEG SIGN = " " POS: POINT = "5" IF TEMP.LOWBYTE.BIT0 = 1 THEN HALF1 POINT = "0" HALF1: TEMP = TEMP.LOWBYTE/2 DEBUG "TEMP= ",SIGN,DEC3 TEMP,".",POINT," C" GOTO START NEG: POINT = "5" IF TEMP.LOWBYTE.BIT0 = 1 THEN HALF2 POINT = "0" HALF2: TEMP.LOWBYTE = ~TEMP.LOWBYTE + 1 ' 2 s complement TEMP = TEMP.LOWBYTE/2 DEBUG "TEMP= ",SIGN,DEC3 TEMP,".",POINT," C" GOTO START DELAY CON 1000 ' Change delay for parasite here

17.3 ´Òǹ âËÅ´â»Ãá¡ÃÁŧº¹ i-Stamp2P24 Êѧࡵ¡Ò÷íÒ§Ò¹¢Í§Ç§¨Ã ˹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢Ö¹é ÁҾà ÍÁ¡ÑºáÊ´§¢ ͤÇÒÁ EXTERNAL POWER áÅеÒÁ ´ Ǥ ÒÍسËÀÙÁãÔ ¹ºÃ÷Ѵ¶Ñ´ÁÒ 17.4 ·´Åͧ¹íÒ»ÅÒÂËÑÇáà §áª ·¨Õè Ò Âä¿áÅ ÇÁÒÍѧ·Õµè ÇÑ ¶Ñ§¢Í§äÍ«Õ DS18B20 Êѧࡵ¡ÒÃáÊ´§¼Å¢Í§Ë¹ Òµ Ò§ Debug Terminal ¨ÐàËç¹Ç Ò¤ ÒÍسËÀÙÁ¨Ô Ф ÍÂæ à¾ÔÁè ¢Ö¹é áÅÐàÁ×Íè ¹íÒ»ÅÒÂËÑÇáà §ÍÍ¡ÍسËÀÙÁ¡Ô ¨ç Ф ÍÂæ Ŵŧ 17.5 »Å´ä¿àÅÕÂé §Ç§¨Ã áŠǵ Íǧ¨ÃµÒÁÃÙ»·Õè L18-2 à¾×Íè ãË äÍ«Õ DS18B20 㪠ä¿àÅÕÂé §¨Ò¡ÊÒ¢ ÍÁÙÅá·¹ «Ö§è àÃÕ¡ ÇÔ¸¡Õ ÒÃà£×Íè Áµ ÍẺ¹ÕÇé Ò áºº Parasite 17.6 ¨ ÒÂä¿àÅÕÂé § áÅ Ç¡´ÊÇÔµª ÃàÕ «µ Êѧࡵ¡ÒÃáÊ´§¼Å·ÕËè ¹ Òµ Ò§ Debug Terminal ·ÕËè ¹ Òµ Ò§ Debug Terminal ¨Ð»ÃÒ¡¯¢ ͤÇÒÁ PARASITE POWER áŠǵÒÁ´ Ǥ ÒÍسËÀÙÁãÔ ¹ ºÃ÷Ѵ¶Ñ´ÁÒ 17.7 ·´Åͧ¹íÒ»ÅÒÂËÑÇáà §áª ·¨Õè Ò Âä¿áÅ ÇÁÒÍѧ·Õµè ÇÑ ¶Ñ§¢Í§äÍ«Õ DS18B20 Êѧࡵ¡ÒÃáÊ´§¼Å¢Í§Ë¹ Òµ Ò§ Debug Terminal ¨ÐàËç¹Ç Ò¤ ÒÍسËÀÙÁ¨Ô Ф ÍÂæ à¾ÔÁè ¢Ö¹é áÅÐàÁ×Íè ¹íÒ»ÅÒÂËÑÇáà §ÍÍ¡ÍسËÀÙÁ¡Ô ¨ç Ф ÍÂæ Ŵŧઠ¹à´ÕÂÇ ¡Ñº¢ Í 17.4

!

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


17.8 ·´Åͧà»ÅÕ蹤 Ò˹ ǧàÇÅÒ â´Âà»ÅÕèÂ¹ä´ ¨Ò¡ºÃ÷Ѵ (Å Ò§ÊØ´) DELAY CON 1000 à» ¹¤ Ò 200 ¨Ò¡¹Ñ¹é ´Òǹ âËÅ´â»Ãá¡ÃÁãËÁ Í¡Õ ¤Ãѧé Êѧࡵ¡ÒÃáÊ´§¼Å¢Í§Ë¹ Òµ Ò§ Debug Terminal ¨ÐàËç¹Ç Ò ¤ ÒÍسËÀÙÁ¨Ô ÐáÊ´§ä´ äÁ ¶¡Ù µ ͧËÃ×ÍäÁ à»ÅÕÂè ¹á»Å§àÅ ¨Ðµ ͧà»ÅÕÂè ¹¤ Ò˹ ǧàÇÅÒà¾ÔÁè ¢Ö¹é ¨¹¡Ãзѧè ÊÒÁÒÃ¶Í Ò¹¤ Òä´ Í ҧ¶Ù¡µ ͧ àÁ×Íè ¤ ÒÍسËÀÙÁáÔ Ê´§ä´ Í ҧ¶Ù¡µ ͧáÅ Ç ¨Ðä´ ¤Ò ˹ ǧàÇÅÒÍ ҧ¤Ã ÒÇæ ·Õè DS18B20 µ ͧ¡ÒÃàÁ×Íè ·íÒ§Ò¹ã¹áºº Parasite ÍÍ¡ÁÒ ÊÒà˵طàÕè » ¹àª ¹¹Õàé ¹×Íè §¨Ò¡àÁ×Íè 㪠§Ò¹ã¹áºº Parasite power supply ¨Ðµ ͧÃÍàÇÅÒª ǧ˹֧è à¾×Íè ãË µÇÑ à¡çº»ÃШØÀÒÂã¹ DS18B20 ·íÒ¡ÒûÃШØä¿·Õè ÃѺÁÒ¨Ò¡ÊÒ¢ ÍÁÙŨ¹àµçÁ¡ ͹¹Ñ¹è àͧ «Ö§è àÁ×Íè »ÃШØä¿à¾Õ§¾ÍáÅ Ç ¨Ö§ÊÒÁÒö·íÒ§Ò¹ä´ Í ҧ¶Ù¡µ ͧ ´Ñ§¹Ñ鹡ÒÃ㪠§Ò¹ã¹ÅѡɳйÕé¨Ð·íÒ§Ò¹ä´ ª Ò¡Ç ÒáÅÐÁÕ¤ÇÒÁà·Õ觵çµèíÒ¡Ç ÒẺ㪠ä¿àÅÕé§ÀÒ¹͡ áµ ÁÕ¢ Í´Õ ¤×Í Å´¨íҹǹÊÒÂÊÑ­­Ò³ÃÇÁ·Õãè ª 㹡ÒÃàª×Íè Áµ ÍÅ§ä´ Í¡Õ 1 àÊ ¹

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡

!


!

Microcontroller in Experiment : ·´ÅͧáÅÐ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ´Ç ÂÀÒÉÒàºÊÔ¡


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.