Page 23 - The Journal of the Royal Society of Thailand
P. 23
วารสารราชบััณฑิิตยสภา
ปีีท่� ๔๙ ฉบัับัท่� ๑ มกิราคุม-เมษาย์น ๒๕๖๗
ศาสตราจารย์์กิิตติคุุณ ดร.มงคุล เดชนคุรินทร์ 13
๒. กิระบวนคุำส่�ง i2cstp (ลำดับหยุด) : อ�างอิงวงจรในภาพื่ที� ๔ และภาพื่คล่�นสัญญาณในภาพื่ที� ๗
i2cstp proc ;(I2C stop sequence)
push ax ;save ax on stack
mov al,00h ;al = 00h = 00000000b
out ppi_port2c,al ;SCL=PC1=0, SDA=PC0=0
jmp $+2 ;I/O delay
mov al,02h ;al = 02h = 00000010b
out ppi_port2c,al ;SCL=PC1=0->1, SDA=PC0=0
jmp $+2 ;I/O delay
call delay0 ;short delay during SDA=0, SCL=1
mov al,03h ;al = 03h = 00000011b
out ppi_port2c,al ;SCL=PC1=1, SDA=PC0=0->1
jmp $+2 ;I/O delay
pop ax ;retrieve ax from stack
ret ;return
i2cstp endp
๓. กิระบวนคุำส่�ง i2c_wr (เขีียนขี�อม้ล) : อ�างอิงวงจรในภาพื่ที� ๔ และภาพื่คล่�นสัญญาณในภาพื่ที� ๖
i2c_wr proc ;(send 8 bits in al, receive ACK/NACK bit in ah)
push bx ;save bx on stack
push cx ;save cx on stack
mov bl,al ;store al in bl
mov cx,8 ;count for 8 bits
lop2:
mov al,bl ;retrieve al from bl
rol al,1 ;rotate left: MS bit -> LS bit
mov bl,al ;save al in bl again
and al,01h ;get LS bit of al to send via SDA line
out ppi_port2c,al ;send LS bit via PC0=SDA line
jmp $+2 ;I/O delay
or al,02h ;add 02h=00000010b to al
out ppi_port2c,al ;send SCL=PC1=1, SDA=PC0=0/1
jmp $+2 ;I/O delay