📄 main.lst
字号:
0013 097B 00020 CALL delay ; Wait a few us
00021 _SCL_HIGH ; Set _SCL line
0014 0526 M BSF _SCL ; Set _SCL line
00022
0015 0C02 00023 MOVLW TBUF ; Generate bus free time between Stop
0016 097B 00024 CALL delay ; and Start condition (Tbuf=4.7us min)
MPASM 5.06 MAIN.ASM 11-20-2007 13:07:25 PAGE 7
SMBus Comunication Subroutines
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00025
00026 _SDA_LOW ; Clear _SDA line
0017 0406 M BCF _SDA ; Clear _SDA bit
0018 0C08 M MOVLW B'00001000'
0019 0006 M TRIS 6 ; _SDA(GP0)-output,GP1,GP2 -outp
uts
001A 0C02 00027 MOVLW TBUF ; Hold time after (Repeated) Start
001B 097B 00028 CALL delay ; Condition. After this period, the first clock is generated.
00029 ;(Thd:sta=4.0us min)
00030 _SCL_LOW ; Clear _SCL line
001C 0426 M BCF _SCL ; Clear _SCL line
00031
001D 0C02 00032 MOVLW TBUF ;
001E 097B 00033 CALL delay ; Wait a few us
00034
001F 0800 00035 RETLW 0
00036 ;**********************************************************************************************
00037 ; STOP CONDITION ON SMBus
00038 ;**********************************************************************************************
00039 ;Name: STOPbit
00040 ;Function: Generate STOP condition on SMBus
00041 ;Input: No
00042 ;Output: No
00043 ;Comments: Refer to "System Managment BUS(SMBus) specification Version 2.0" and
00044 ; AN "SMBus communication with MLX90614"
00045 ;
00046 ; _______ ___
00047 ; SDA |_______|
00048 ;
00049 ;
00050 ; __ _______
00051 ; SCL |________|
00052 ;
00053 ;**********************************************************************************************
0020 00054 STOP_bit
00055
00056 _SCL_LOW ; Clear _SCL line
0020 0426 M BCF _SCL ; Clear _SCL line
0021 0C02 00057 MOVLW TBUF ;
0022 097B 00058 CALL delay ; Wait a few us
00059 _SDA_LOW ; Clear _SDA line
0023 0406 M BCF _SDA ; Clear _SDA bit
0024 0C08 M MOVLW B'00001000'
0025 0006 M TRIS 6 ; _SDA(GP0)-output,GP1,GP2 -outp
uts
00060
0026 0C02 00061 MOVLW TBUF ;
0027 097B 00062 CALL delay ; Wait a few us
00063
00064 _SCL_HIGH ; Set _SCL line
0028 0526 M BSF _SCL ; Set _SCL line
0029 0C02 00065 MOVLW TBUF ; Stop condition setup time
MPASM 5.06 MAIN.ASM 11-20-2007 13:07:25 PAGE 8
SMBus Comunication Subroutines
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
002A 097B 00066 CALL delay ; (Tsu:sto=4.0us min)
00067 _SDA_HIGH ; Set _SDA line
002B 0C09 M MOVLW B'00001001'
002C 0006 M TRIS 6 ; _SDA(GP0)-input,GP1,GP2 -outpu
ts
00068
00069 ; MOVLW d'1' ;
00070 ; CALL delay ; Add delay 4us@4MHz
00071
002D 0800 00072 RETLW 0
00073 ;**********************************************************************************************
00074 ; TRANSMIT DATA ON SMBus
00075 ;**********************************************************************************************
00076 ;Name: TX_byte
00077 ;Function: Send a byte on SMBus
00078 ;Input: W
00079 ;Output: W
00080 ;Comments: If slave send acknowledge W=0, else W=1
00081 ;**********************************************************************************************
002E 00082 TX_byte
002E 002A 00083 MOVWF TX_buffer
002F 002B 00084 MOVWF TX_temp ; Tx_buffer -> Tx_temp
00085
0030 00086 TX_again
0030 0C08 00087 MOVLW D'8'
0031 002C 00088 MOVWF Bit_counter ; Load Bit_counter
0032 00089 tx_loop
0032 040D 00090 BCF bit_out ; 0 -> bit_out
0033 036A 00091 RLF TX_buffer,F ; Tx_buffer<MSb> -> C
0034 0603 00092 BTFSC STATUS,C ; C is 0 or 1? If C=0 don抰 set bit_out
0035 050D 00093 BSF bit_out ; 1 -> bit_out
0036 093D 00094 CALL Send_bit ; Send bit_out on _SDA line
0037 02EC 00095 DECFSZ Bit_counter,F ; All 8th bits are sent? If not, send next bit ,else check for
00096 ; acknowledgement from the receiver
0038 0A32 00097 GOTO tx_loop ; Send next bit
0039 0964 00098 CALL Receive_bit ; Check for acknowledgement from the receiver
003A 072D 00099 BTFSS bit_in ; Receiver send ACK?
003B 0800 00100 RETLW 0 ; Yes,return 0
003C 0801 00101 RETLW 1 ; No ,return 1
00102
003D 00103 Send_bit
003D 060D 00104 BTFSC bit_out ;|
003E 0A43 00105 GOTO bit_high ;|
00106 _SDA_LOW ;|
003F 0406 M BCF _SDA ; Clear _SDA bit
0040 0C08 M MOVLW B'00001000'
0041 0006 M TRIS 6 ; _SDA(GP0)-output,GP1,GP2 -outp
uts
0042 0A46 00107 GOTO clock ; > Send bit on _SDA line
0043 00108 bit_high ;|
00109 _SDA_HIGH ;|
0043 0C09 M MOVLW B'00001001'
MPASM 5.06 MAIN.ASM 11-20-2007 13:07:25 PAGE 9
SMBus Comunication Subroutines
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
0044 0006 M TRIS 6 ; _SDA(GP0)-input,GP1,GP2 -outpu
ts
0045 0000 00110 NOP ;|
00111
0046 00112 clock
00113 _SCL_HIGH ;|
0046 0526 M BSF _SCL ; Set _SCL line
0047 0000 00114 NOP ;|
0048 0000 00115 NOP ;|
0049 0000 00116 NOP ;|
004A 0000 00117 NOP ;|
004B 0000 00118 NOP ;|
004C 0000 00119 NOP ;|
004D 0000 00120 NOP ;|
004E 0000 00121 NOP ; > Send clock pulse
004F 0000 00122 NOP ;|
0050 0000 00123 NOP ;|
0051 0000 00124 NOP ;|
0052 0000 00125 NOP ;|
0053 0000 00126 NOP ;|
00127 _SCL_LOW ;|
0054 0426 M BCF _SCL ; Clear _SCL line
0055 0000 00128 NOP ;|
0056 0000 00129 NOP ;|
0057 0800 00130 RETLW 0
00131 ;**********************************************************************************************
00132 ; RECEIVE DATA ON SMBus
00133 ;**********************************************************************************************
00134 ;Name: RX_byte
00135 ;Function: Receive a byte on SMBus
00136 ;Input: No
00137 ;Output: RX_buffer(Received byte)
00138 ;Comments:
00139 ;**********************************************************************************************
0058 00140 RX_byte
0058 006E 00141 CLRF RX_buffer ; Clear the receiving buffer
0059 0C08 00142 MOVLW D'8'
005A 002C 00143 MOVWF Bit_counter ; Load Bit_counter
005B 0403 00144 BCF STATUS,C ; C=0
005C 00145 RX_again
005C 036E 00146 RLF RX_buffer,F ; RX_buffer< MSb> -> C
005D 0964 00147 CALL Receive_bit ; Check bit on _SDA line
005E 062D 00148 BTFSC bit_in ; If received bit is
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -