📄 i2cmem.lst
字号:
MPASM 03.70.01 Released I2CMEM.ASM 2-16-2006 19:53:02 PAGE 1
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00001 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00002 ;
00003 ; I2CMEM.ASM MPB 7-1-06
00004 ;
00005 ; Test program for 24AA128 I2C 16k byte serial
00006 ; memory with P16F877A (4MHz XT)
00007 ; Demonstrates single byte write and read
00008 ; with 10-bit address.
00009 ;
00010 ; Write data from 0x20
00011 ; High address 0x21
00012 ; Low address 0x22
00013 ; Read data back to 0x23
00014 ;
00015 ; Version: Final
00016 ;
00017 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00018
00019 PROCESSOR 16F877A
2007 3FF1 00020 __CONFIG 3FF1
00021 INCLUDE "P16F877A.INC"
00001 LIST
00002 ; P16F877A.INC Standard Header File, Version 1.00 Microchip Technology, Inc.
00398 LIST
00022
00023 ; Data, address & control registers ;;;;;;;;;;;;;;;;;;;;
00024
00000020 00025 SenReg EQU 0x20 ; Send data store
00000021 00026 HiReg EQU 0x21 ; High address store
00000022 00027 LoReg EQU 0x22 ; Low address store
00000023 00028 RecReg EQU 0x23 ; Receive data store
00000024 00029 ConReg EQU 0x24 ; Control byte store
00000025 00030 Temp EQU 0x25 ; Scratchpad location
00031
00032 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00033
0000 00034 ORG 0 ; Program start address
00035
0000 01A0 00036 CLRF SenReg ; Zeroise data
0001 01A1 00037 CLRF HiReg ; Zeroise high address
0002 01A2 00038 CLRF LoReg ; Zeroise low address
0003 2872 00039 GOTO begin ; jump to main program
00040
00041 ;--------------------------------------------------------
00042 ; SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00043
00044 ; Wait for interrupt flag SSPIF for send/recive done ...
00045
0004 0000 00046 wint NOP ; BANKSEL has no address
0005 1283 1303 00047 BANKSEL PIR1 ; Select bank
0007 118C 00048 BCF PIR1,SSPIF ; reset interrupt flag
0008 0000 00049 win NOP
0009 1D8C 00050 BTFSS PIR1,SSPIF ; wait for..
MPASM 03.70.01 Released I2CMEM.ASM 2-16-2006 19:53:02 PAGE 2
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
000A 2808 00051 GOTO win ; ..transmit done
000B 0008 00052 RETURN ; done
00053
00054
00055 ; Send a byte ....................................
00056
000C 0000 00057 send NOP ; Select..
000D 1283 1303 00058 BANKSEL SSPBUF ; .. bank
000F 0093 00059 MOVWF SSPBUF ; Send address/data
0010 2004 00060 CALL wint ; Wait until sent
0011 0008 00061 RETURN ; done
00062
00063 ;--------------------------------------------------------
00064 ; Routines to send start, control, address, data, stop ..
00065 ;........................................................
00066
0012 0000 00067 sencon NOP ; GENERATE START BIT
0013 1283 1303 00068 BANKSEL PIR1
0015 118C 00069 BCF PIR1,SSPIF ; Clear interrupt flag
0016 1683 1303 00070 BANKSEL SSPCON2 ; select register page
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
0018 1711 00071 BSF SSPCON2,ACKSTAT ; Set acknowledge flag
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
0019 1411 00072 BSF SSPCON2,SEN ; Generate start bit
001A 2004 00073 CALL wint ; wait till done
001B 0824 00074 MOVF ConReg,W ; SEND CONTROL BYTE
001C 200C 00075 CALL send ; Memory ID & chip address
001D 0008 00076 RETURN ; done
00077
00078 ;........................................................
00079
001E 0000 00080 senadd NOP
001F 1283 1303 00081 BANKSEL SSPCON ; SEND ADDRESS BYTES
0021 0821 00082 MOVF HiReg,W ; load address high byte
0022 200C 00083 CALL send ; and send
0023 0822 00084 MOVF LoReg,W ; load address low byte
0024 200C 00085 CALL send ; and send
0025 0008 00086 RETURN
00087
00088 ;........................................................
00089
0026 0820 00090 sendat MOVF SenReg,W ; Load data
0027 200C 00091 CALL send ; and send
0028 0008 00092 RETURN ; done
00093
00094 ;........................................................
00095
0029 0000 00096 senstop NOP
002A 1683 1303 00097 BANKSEL SSPCON2 ; GENERATE STOP BIT
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
002C 1511 00098 BSF SSPCON2,PEN ; Generate stop bit
002D 2004 00099 CALL wint ; wait till done
002E 0008 00100 RETURN ; done
MPASM 03.70.01 Released I2CMEM.ASM 2-16-2006 19:53:02 PAGE 3
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00101
00102 ;........................................................
00103
002F 0000 00104 senack NOP
0030 1683 1303 00105 BANKSEL SSPCON2
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
0032 1691 00106 BSF SSPCON2,ACKDT ; Set ack. bit high
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
0033 1611 00107 BSF SSPCON2,ACKEN ; Initiate ack.sequence
0034 2004 00108 CALL wint ; Wait for ack. done
0035 0008 00109 RETURN ; done
00110
00111 ;........................................................
00112
0036 0000 00113 wait NOP
0037 1283 1303 00114 BANKSEL TMR0 ; WAIT FOR WRITE DONE
0039 309C 00115 MOVLW d'156' ; Set starting value
003A 0081 00116 MOVWF TMR0 ; and load into timer
003B 1283 1303 00117 BANKSEL INTCON ; 64 x 156us = 10ms
003D 110B 00118 BCF INTCON,T0IF ; Reset timer out flag
003E 1D0B 00119 wem BTFSS INTCON,T0IF ; Wait 10ms
003F 283E 00120 GOTO wem ; for timeout
0040 1283 1303 00121 BANKSEL TMR0 ; default bank
0042 0008 00122 RETURN ; Byte write done....
00123
00124 ;--------------------------------------------------------
00125 ; Initialisation sequence ..............................
00126
0043 0000 00127 init NOP
0044 1683 1303 00128 BANKSEL SSPCON2 ;
0046 3060 00129 MOVLW b'01100000' ; Set ACKSTAT,ACKDT bits
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
0047 0091 00130 MOVWF SSPCON2 ; Reset SEN,ACK bits
0048 3080 00131 MOVLW b'10000000' ;
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
0049 0094 00132 MOVWF SSPSTAT ; Speed & signal levels
004A 3013 00133 MOVLW 0x13 ; Clock = 50kHz
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
004B 0093 00134 MOVWF SSPADD ; Load baud rate count-1
004C 1283 1303 00135 BANKSEL SSPCON ;
004E 3028 00136 MOVLW b'00101000' ;
004F 0094 00137 MOVWF SSPCON ; Set mode & enable
0050 118C 00138 BCF PIR1,SSPIF ; clear interrupt flag
00139
00140 ; Initialise TIMER0 for write delay ...............
00141
0051 1683 1303 00142 BANKSEL OPTION_REG ;
0053 30C5 00143 MOVLW B'11000101' ; TIMER0 setup code
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
0054 0081 00144 MOVWF OPTION_REG ; Internal clock,1/64
0055 1283 1303 00145 BANKSEL TMR0
0057 0008 00146 RETURN
00147
MPASM 03.70.01 Released I2CMEM.ASM 2-16-2006 19:53:02 PAGE 4
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00148 ;--------------------------------------------------------
00149 ; Write a test byte to given address ................
00150
0058 30A0 00151 writeb MOVLW 0xA0 ; Control byte for WRITE
0059 00A4 00152 MOVWF ConReg ;
005A 2012 00153 CALL sencon ; Send control byte
005B 201E 00154 CALL senadd ; Send address bytes
005C 2026 00155 CALL sendat ; Send data byte
005D 2029 00156 CALL senstop ; Send stop bit
005E 2036 00157 CALL wait ; Wait 10ms for write
005F 0008 00158 RETURN
00159
00160 ;--------------------------------------------------------
00161 ; Read the byte from given address ...................
00162
0060 30A0 00163 readb MOVLW 0xA0 ; Control byte to WRITE
0061 00A4 00164 MOVWF ConReg ; address to memory
0062 2012 00165 CALL sencon ; Send control byte
0063 201E 00166 CALL senadd ; Send address bytes
0064 2029 00167 CALL senstop ; Stop
00168
0065 30A1 00169 MOVLW 0xA1 ; Control byte to READ
0066 00A4 00170 MOVWF ConReg ; data from memory
0067 2012 00171 CALL sencon ; Send control byte
0068 1683 1303 00172 BANKSEL SSPCON2
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
006A 1591 00173 BSF SSPCON2,RCEN ; Enable receive mode
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
006B 1C14 00174 war BTFSS SSPSTAT,BF ; Check ...
006C 286B 00175 GOTO war ; for read done
006D 202F 00176 CALL senack ; send NOT acknowledge
006E 2029 00177 CALL senstop ; send stop bit
00178
006F 0813 00179 MOVF SSPBUF,W ; Read receive buffer
0070 00A3 00180 MOVWF RecReg ; and store it
0071 0008 00181 RETURN
00182
00183
00184 ; MAIN PROGRAM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00185
0072 2043 00186 begin CALL init ; Initialise for I2C
0073 2058 00187 next CALL writeb ; write the test byte
0074 2060 00188 CALL readb ; and read it back
Message[305]: Using default destination of 1 (file).
0075 0AA0 00189 INCF SenReg ; next data
Message[305]: Using default destination of 1 (file).
0076 0AA2 00190 INCF LoReg ; next location
0077 1D03 00191 BTFSS STATUS,Z ; end of memory block?
0078 2873 00192 GOTO next ; no, next location
Message[305]: Using default destination of 1 (file).
0079 0AA1 00193 INCF HiReg ; next block
00194
007A 0821 00195 MOVF HiReg,W ; copy high address byte
MPASM 03.70.01 Released I2CMEM.ASM 2-16-2006 19:53:02 PAGE 5
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
007B 00A5 00196 MOVWF Temp ; store it
007C 3040 00197 MOVLW 0x40 ; Last block = 3F
Message[305]: Using default destination of 1 (file).
007D 02A5 00198 SUBWF Temp ; Compare
007E 1D03 00199 BTFSS STATUS,Z ; Finish if block = 40xx
007F 2873 00200 GOTO next ; next memory block..
0080 0063 00201 SLEEP ; .. unless done
00202
00203 END ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MPASM 03.70.01 Released I2CMEM.ASM 2-16-2006 19:53:02 PAGE 6
SYMBOL TABLE
LABEL VALUE
ACKDT 00000005
ACKEN 00000004
ACKSTAT 00000006
ADCON0 0000001F
ADCON1 0000009F
ADCS0 00000006
ADCS1 00000007
ADDEN 00000003
ADFM 00000007
ADIE 00000006
ADIF 00000006
ADON 00000000
ADRESH 0000001E
ADRESL 0000009E
BCLIE 00000003
BCLIF 00000003
BF 00000000
BRGH 00000002
C 00000000
C1INV 00000004
C1OUT 00000006
C2INV 00000005
C2OUT 00000007
CCP1CON 00000017
CCP1IE 00000002
CCP1IF 00000002
CCP1M0 00000000
CCP1M1 00000001
CCP1M2 00000002
CCP1M3 00000003
CCP1X 00000005
CCP1Y 00000004
CCP2CON 0000001D
CCP2IE 00000000
CCP2IF 00000000
CCP2M0 00000000
CCP2M1 00000001
CCP2M2 00000002
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -