📄 main.lst
字号:
00150 endm
00151 ;----------------------------------------------------------------------------------------------
00152 ExitSleepMode macro
MPASM 5.06 MAIN.ASM 11-20-2007 13:07:25 PAGE 4
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00153
00154 _SCL_HIGH ; Set _SCL line
00155 NOP ;|
00156 NOP ; > Wait
3us
00157 NOP ;|
00158 _SDA_LOW ; Clear _SDA lin
e
00159 CALL delay_30ms ; Wait 30ms
00160 CALL delay_30ms ; Wait 30ms
00161 CALL delay_30ms ; Wait 30ms
00162 _SDA_HIGH ; Set _SDA line
00163
00164 endm
00165 ;----------------------------------------------------------------------------------------------
00166 DummyCommand macro
00167 CALL START_bit ; Start SMBus comunication
00168 MOVF SlaveAddress,W ; SlaveAddress -> W
00169 CALL TX_byte ; Send Slave address(Bit R/-W no
meaning)
00170 CALL STOP_bit ; Stop SMBus comunication
00171 endm
00172 ;----------------------------------------------------------------------------------------------
00173 MemRead macro
00174 local restart
00175 local end_transmition
00176 local start
00177 restart
00178 DECFSZ Nack_Counter,F ; If((Nack_Counter-1) == 0) stop transmition
00179 GOTO start ; Else start transmition
00180 GOTO end_transmition ;
00181 start
00182 CALL STOP_bit ; Stop SMBus comunication
00183 CALL START_bit ; Start SMBus comunication
00184
00185 MOVF SlaveAddress,W ; Send Slave address(Bit R/-W no meaning)
00186 CALL TX_byte ;
00187
00188 ANDLW 0x01 ; W & 0x01 -> W
00189 BTFSS STATUS,Z ; If Slave acknowledge,continue
00190 GOTO restart ; Else restart communication
00191
00192 MOVF command,W ; Send Command
00193 CALL TX_byte ;
00194
00195 ANDLW 0x01 ; W & 0x01 -> W
00196 BTFSS STATUS,Z ; If Slave acknowledge,continue
00197 GOTO restart ; else restart communication
00198
00199 CALL START_bit ; Send Repeated START bit
00200
00201 MOVF SlaveAddress,W ; Send Slave address again(Bit R/-W no meaning)
00202 CALL TX_byte ;
MPASM 5.06 MAIN.ASM 11-20-2007 13:07:25 PAGE 5
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00203
00204 ANDLW 0x01 ; W & 0x01 -> W
00205 BTFSS STATUS,Z ; If Slave acknowledge,continue
00206 GOTO restart ; Else restart communication
00207
00208 BCF bit_out ; Master must send acknowledge after thi
s received byte
00209 CALL RX_byte ; Receive low data byte
00210 MOVF RX_buffer,W ;
00211 MOVWF DataL ; Save it in DataL
00212
00213 BCF bit_out ; Master must send acknowledge after thi
s received byte
00214 CALL RX_byte ; Receive high data byte
00215 MOVF RX_buffer,W ;
00216 MOVWF DataH ; Save it in DataH
00217
00218 BSF bit_out ; Master mustn't send acknowledge after
this received byte
00219 CALL RX_byte ; Receive PEC byte
00220 MOVF RX_buffer,W ;
00221 MOVWF PecReg ; Save it in PecReg
00222 end_transmition
00223 CALL STOP_bit ; Stop SMBus comunication
00224
00225 endm
00226
00227 ;**********************************************************************************************
00228 ; BEGINNING OF THE PROGRAM
00229 ;**********************************************************************************************
00230
0000 00231 ORG 0x0000
0000 0025 00232 MOVWF OSCCAL ;Load OSCCAL with the calibration value
0001 0AE9 00233 GOTO main
00234
00235 ;**********************************************************************************************
00236 ; SUBROUTINES
00237 ;**********************************************************************************************
00238 #include "Init.asm"
00001
00002
00003 SUBTITLE "MCU INITIALIZATION SUBROUTINE"
00004
00005 ;***********************************************************************************************
0002 00006 MCUinit
00007 ;MCU port initialization
0002 0C0A 00008 MOVLW B'00001010'
0003 0006 00009 TRIS 6 ; GP0 and GP2 -outputs, GP1-input
0004 0CDF 00010 MOVLW b'11011111' ; <7>-Disabled Wake-up on Pin Change bit(GP0, GP1, GP3)
0005 0002 00011 OPTION ; <6>-Disabled Weak Pull-ups bit(GP0, GP1, GP3)
00012 ; <5>-Timer 0 transition on internal instruction
cycle clock, FOSC/4
MPASM 5.06 MAIN.ASM 11-20-2007 13:07:25 PAGE 6
MCU INITIALIZATION SUBROUTINE
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00013 ; <3>-Prescaler assigned to the WDT
00014 ; <2:0>-Prescaler Rate Select bits 1:128
00015
00016 ifndef PIC10F202
00017
0006 0467 00018 BCF CMCON0,CMPON ;Comparator is off(Only for PIC10F206)
00019
00020 endif
00021
00022 ;SMBus initialization
00023 _SDA_HIGH ; Set
0007 0C09 M MOVLW B'00001001'
0008 0006 M TRIS 6 ; _SDA(GP0)-input,GP1,GP2 -outpu
ts
00024 _SCL_HIGH ; SMbus in idle mode
0009 0526 M BSF _SCL ; Set _SCL line
00025
000A 006D 00026 CLRF flagreg0
000B 0C16 00027 MOVLW WDTCOUNT ;
000C 0029 00028 MOVWF WDTcounter ;Set WDTcounter
000D 0C00 00029 MOVLW SA<<1 ;Slave address occupy MSB<7:1>
000E 0032 00030 MOVWF SlaveAddress ;Set SMBus address
00031
000F 0800 00032 RETLW 0
00239 #include "SMBusSubr.asm"
00001
00002
00003 SUBTITLE "SMBus Comunication Subroutines"
00004
00005
00006 ;**********************************************************************************************
00007 ; START CONDITION ON SMBus
00008 ;**********************************************************************************************
00009 ;Name: START_bit
00010 ;Function: Generate START condition on SMBus
00011 ;Input: No
00012 ;Output: No
00013 ;Comments: Refer to "System Managment BUS(SMBus) specification Version 2.0" and
00014 ; AN "SMBus communication with MLX90614"
00015 ;**********************************************************************************************
0010 00016 START_bit
00017
00018 _SDA_HIGH ; Set _SDA line
0010 0C09 M MOVLW B'00001001'
0011 0006 M TRIS 6 ; _SDA(GP0)-input,GP1,GP2 -outpu
ts
0012 0C02 00019 MOVLW TBUF ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -