Page 26 - The Journal of the Royal Society of Thailand
P. 26

วารสารราชบััณฑิิตยสภา
                                          ปีที� ๔๙ ฉบับที� ๑ มกราคม-เมษายน ๒๕๖๗

             16                การต่่อประสานแผงวงจรไมโครคอนโทรลเลอร์เพื่่�อการเรียนร้�กับหน่วยความจำอีอีพื่ร็อมแบบอนุกรมต่ามเกณฑ์์วิธีี I2C



                         or al,02h           ;add 02h=00000010b to al

                         out ppi_port2c,al    ;set PC1=SCL=1, while PC0=SDA=0/1
                         jmp $+2             ;I/O delay

                         call delay0         ;short extension of clock pulse (optional)
                         and al,01h          ;let PC1=SCL=1->0, PC0=SDA=0/1

                         out ppi_portc2,al    ;finish clock pulse
                         jmp $+2             ;I/O delay

                         mov al,01h          ;make al=01h=00000001b
                         out ppi_port2c,al    ;PC1=SCL=0, PC0=SDA=1 => release SDA line

                         jmp $+2             ;I/O delay
                         mov al,bl           ;transfer received byte in bl to al

                         pop cx              ;retrieve cx from stack
                         pop bx              ;retrieve bx from stack

                         ret                 ;return with al=received byte
                      i2c_rd endp

                      หมาย์เหตุ : คำสั�ง call delay0 ที�ป็รากฏอย้่ ๒ แห่ง และคำสั�ง call wtc5hi ที�ป็รากฏอย้่ ๑ แห่ง

             ในกระบวนคำสั�งขี�างบนนี�อาจต่ัดทิ�งได�ถ�าพื่ิส้จน์ด�วยการทดลองในทางป็ฏิบัต่ิพื่บว่า อีอีพื่ร็อมสามารถต่อบสนอง
             ได�เร็วพื่อและไม่ทำให�เกิดขี�อผิดพื่ลาดในการถ่ายโอนบิต่ขี�อม้ล



                    ๕. กิระบวนคุำส่�ง prewr (เต่รียมเขีียน) : อ�างอิงผังงานในภาพื่ที� ๘ และขีั�นต่อน ๑) - ๓) ขีองเกณฑ์์วิธีี

                      prewr proc             ;(prepare for writing data; input: ax = start addr)

                         push ax             ;save ax on stack
                         call i2cstr         ;begin with start sequence
                         mov al,0A0h         ;7-bit addr ID of EEPROM + 8  (write) bit=0
                                                                     th
                         call i2c_wr         ;send al = addr ID for write

                       call chknak           ;check NACK error
                         pop ax              ;retrieve ax
                         push ax             ;save ax again

                         mov al,ah           ;hi byte of start addr to write to

                         call i2c_wr         ;send hi byte of start addr
                         call chknak         ;check NACK error
   21   22   23   24   25   26   27   28   29   30   31