📄 viai2c.inc
字号:
;------------------------------------------------------------------------------;
; VIA_READ_I2C_DATA_BLOCK ;
;------------------------------------------------------------------------------;
; Input: AH = Slave address ;
; AL = device register index (command code) ;
; Output: ZF = 0 : fail ;
; ZF = 1 : success and CL = byte data read ;
; Modified: CL ;
;------------------------------------------------------------------------------;
public VIA_read_i2c_data_block
VIA_read_i2c_data_block proc near
pusha
sti
;; Don't Destory CX
;Reset Host Status Registers
call VIAClearHostStatus
;Clock Generator Address = D3h
or dx,04h
lea si,SlaveAddress
mov al,ds:[si]
or al,01h
out dx,al
jmp short $+2
jmp short $+2
; Write 00h to Host Command Register
and dl,0f0h
or dx,03h
mov al,000h
out dx,al
jmp short $+2
jmp short $+2
; Number Of Bytes to Program (06h)
and dl,0f0h
or dx,05h
mov al,80h
out dx,al
jmp short $+2
jmp short $+2
; Start Block Write Command
and dl,0f0h
or dx,02h
mov al,54h
out dx,al
jmp short $+2
jmp short $+2
and dl,0f0h
or dx,05h
in al,dx
cmp al,0
jz VIAskip_program_loopr
movzx ax,al
lea si,ReadDataRow
mov cl,ds:[si]
movzx cx,cl
VIAloop_block_row:
push cx
mov cx,16
VIAstart_block_read:
push cx
lea si,SmbusAddress
mov dx,ds:[si]
or dx,07h
in al,dx
call DisplayDataAttribute
mov al,' '
call DisplayChar
jmp $+2
jmp $+2
call WaitShortIODelay
pop cx
loop VIAstart_block_read
lea si,crlf
call DisplayString
call GetCursor
mov dl,ValueStartCol
call SetCursor
pop cx
loop VIAloop_block_row
VIAskip_program_loopr:
popa
ret
VIA_read_i2c_data_block endp
;------------------------------------------------------------------------------;
; VIA_WRITE_I2C_DATA_BLOCK ;
;------------------------------------------------------------------------------;
; Input: AH = Slave address ;
; AL = device register index (command code) ;
; Output: ZF = 0 : fail ;
; ZF = 1 : success and CL = byte data read ;
; Modified: CL ;
;------------------------------------------------------------------------------;
public VIA_write_i2c_data_block
VIA_write_i2c_data_block proc near
;Reset Host Status Registers
push cx
push si
call VIAClearHostStatus
;;; KenWang [050602] >>>>>>
lea si,SmbusTempFlag
mov al,01h
mov ds:[si],al
;;; KenWang [050602] <<<<<<
;Clock Generator Address = D2h
lea si,SmbusAddress
mov dx,ds:[si]
or dx,04h
lea si,SlaveAddress
mov al,ds:[si]
out dx,al
jmp $+2
; Write 00h to Host Command Register
and dl,0f0h
or dx,03h
mov al,000h
out dx,al
jmp short $+2
jmp short $+2
; Number Of Bytes to Program (06h)
and dl,0f0h
or dx,05h
call GetBlockSendCounts
out dx,al
jmp short $+2
jmp short $+2
; Write Byte 0 Control Register
mov dx,(ValueStartCol+ValueStartRow)
call CalaFixedCursorposn
call GetFixCursorValue
mov al,bl
lea si,SmbusAddress
mov dx,ds:[si]
and dl,0f0h
or dx,07h
out dx,al
jmp short $+2
jmp short $+2
call WaitShortIODelay
mov cx,WriteBlockRow
mov dx,(ValueStartCol+ValueStartRow)+0003h
via_post_start_block_write_row:
push cx
cmp cx,WriteBlockRow
mov cx,15
jz via_post_start_block_write
inc cx
via_post_start_block_write:
push cx
push dx
call CalaFixedCursorposn
call GetFixCursorValue
mov al,bl
lea si,SmbusAddress
mov dx,ds:[si]
and dl,0f0h
or dx,07h
out dx,al
call WaitShortIODelay
jmp $+2
jmp $+2
pop dx
add dl,3
pop cx
loop via_post_start_block_write
inc dh
mov dl,ValueStartCol
pop cx
loop via_post_start_block_write_row
; Start Block Write Command
and dl,0f0h
or dx,02h
mov al,54h
out dx,al
jmp short $+2
jmp short $+2
call VIAlWaitBytexdone
pop si
pop cx
ret
VIA_write_i2c_data_block endp
;------------------------------------------------------------------------------;
VIAlWaitBytexdone:
lea si,SmbusAddress
mov dx,ds:[si]
mov cx,500h
VIAWaitSendBolckDone:
in al,dx
out 0edh,al
out 0edh,al
out 0edh,al
out 0edh,al
test al,02
jnz short VIASendBlockDone
loop VIAWaitSendBolckDone
VIASendBlockDone:
ret
;------------------------------------------------------------------------------;
VIAClearHostStatus:
lea si,SmbusAddress
mov dx,ds:[si]
mov al,0ffh
out dx,al
mov cx,2600
VIAClearSmbusLoop:
out 0ebh,al
loop VIAClearSmbusLoop
add dl,02h
in al,dx ;reset pointer
jcxz short $+2
jcxz short $+2
ret
;------------------------------------------------------------------------------;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -