⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pic12i2c.lst

📁 该应用软件可以实现大多数单片机的仿真实验
💻 LST
📖 第 1 页 / 共 2 页
字号:
MPASM 03.00 Released         PIC12I2C.ASM   4-19-2002  17:00:20         PAGE  1


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00001         LIST    p=12CE518 ; 
                      00002         #include "P12CE518.INC" ; Include header file
                      00001         LIST
                      00002 ; P12CE518.INC  Standard Header File, Version 1.00    Microchip Technology, Inc.
                      00103         LIST
                      00003 
                      00004 
                      00005         cblock 0x10   
  00000010            00006         result           
  00000011            00007         count   
                      00008         endc
                      00009 
                      00010         ; Vector for normal start up.
0000                  00011         org     0
0000   0A01           00012         goto    start
                      00013 
                      00014         
                      00015 ; Main program starts here:
0001   0C3C           00016 start   movlw 0x3C
0002   0006           00017         tris  GPIO
                      00018 
                      00019                                               
                      00020 ; Write a byte
0003   0C00           00021         movlw 0
0004   003B           00022         movwf EEADDR
0005   0C85           00023 loop    movlw 0x85
0006   003C           00024         movwf EEDATA
0007   0925           00025         call WRITE_BYTE
0008   0030           00026         movwf result
                      00027 
0009   0916           00028         call serout
                      00029         
                      00030 ; Wait for INT high     
000A   0746           00031 wait1   btfss GPIO,2
000B   0A0A           00032         goto wait1
                      00033 
                      00034 ;Read it back
                      00035                      
000C   0CFF           00036         movlw 0xFF
000D   003C           00037         movwf EEDATA
                      00038         
000E   0922           00039         call READ_CURRENT
000F   021C           00040         movfw EEDATA
0010   0030           00041         movwf result
0011   0916           00042         call serout
                      00043 
                      00044 ; Wait for INT low      
0012   0646           00045 wait2   btfsc GPIO,2
0013   0A12           00046         goto wait2
                      00047         
0014   02BB           00048         incf EEADDR,F
0015   0A05           00049         goto loop       
                      00050         
MPASM 03.00 Released         PIC12I2C.ASM   4-19-2002  17:00:20         PAGE  2


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00051 ;Serial output of result
0016   0C08           00052 serout  movlw 8                 ;Loop for 8 bits
0017   0031           00053         movwf count          
0018   0CC0           00054 loop1   movlw 0xC0              ;Start with a zero except for SDA/SCL                   
0019   06F0           00055         btfsc result,7          ;Test result bit    
001A   0D01           00056         iorlw 0x01
001B   0026           00057         movwf GPIO              ;Output data bit to port on GP0
001C   0526           00058         bsf GPIO,1              ;Generate Clock pulse on GP1
001D   0426           00059         bcf GPIO,1                            
001E   0370           00060         rlf result,F            ;Get next result bit
001F   02F1           00061         decfsz count,F          ;Loop for next bit
0020   0A18           00062         goto loop1
Warning[227]: Substituting RETLW 0 for RETURN pseudo-op
0021   0800           00063         return
                      00064                         
                      00065                         
                      00066 
                      00067         #include fl51xinc.asm
                      00001         TITLE "PIC with Flash EE data memory Interface"
                      00002 ;
                      00003 ;       Program:          FL51XINC.ASM  V1.10
                      00004 ;       Revision Date:   
                      00005 ;                         09-09-97      Adapted to 12C51x parts
                      00006 ;                         01-Apr-1999   Added emulation hooks
                      00007 ;
                      00008 
                      00009 ; #define EMULATED    ; comment this line out for use on real part
                      00010 
                      00011 ; PIC12C51X EEPROM communication code.  This code should be included in
                      00012 ; with the application.  These routines provide the following functionality:
                      00013 ; write a byte to a specified address.
                      00014 ; read a byte from a specified address.
                      00015 ; read a byte from the next address.
                      00016 ;
                      00017 ; Emulation Requires:
                      00018 ;     MPLAB-ICE
                      00019 ;     PCM16XA0 processor module
                      00020 ;     DVA12XP80 Device Adapter.
                      00021 ; Define EMULATOR at the top of this file  (#define EMULATOR)
                      00022 ;     This will set the I2C_PORT, SDA and SCL lines to communicate over 
                      00023 ;     Port A, pins 0 and 1.  It also assembles in the necessary TRIS 
                      00024 ;     instructions to allow reading from the SDA line.
                      00025 ;
                      00026 ; To convert the code for the actual part, simply comment out the #define EMULATOR
                      00027 ; line and reassemble. 
                      00028 ;
                      00029 ; FL51XTST.ASM is also provided for linker users.
                      00030 ;
                      00031 ; INTRODUCTION:
                      00032 ; The Microchip 12c51x family of microntrollers are multichip modules 
                      00033 ; which contain a PIC12C508 microcontroller and a 24LC00 EEPROM.
                      00034 ; This application note is intended to provide users with highly compressed
                      00035 ; assembly code for communication between the EEPROM and the Microcontroller,
MPASM 03.00 Released         PIC12I2C.ASM   4-19-2002  17:00:20         PAGE  3
PIC with Flash EE data memory Interface

LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00036 ; which will leave the user a maximum amount of code space for the core 
                      00037 ; application.
                      00038 ;
                      00039 ;***************************************************************************
                      00040 ;***************************  EEPROM Subroutines  **************************
                      00041 ;***************************************************************************
                      00042 ; Communication for EEPROM based on I2C protocall, with Acknowledge.
                      00043 ;
                      00044 ; Byte_Write: Byte write routine
                      00045 ;       Inputs:  EEPROM Address   EEADDR
                      00046 ;                EEPROM Data      EEDATA
                      00047 ;       Outputs: Return 01 in W if OK, else return 00 in W
                      00048 ;
                      00049 ; Read_Current: Read EEPROM at address currently held by EE device. 
                      00050 ;       Inputs:  NONE
                      00051 ;       Outputs: EEPROM Data       EEDATA
                      00052 ;                Return 01 in W if OK, else return 00 in W
                      00053 ;
                      00054 ; Read_Random: Read EEPROM byte at supplied address
                      00055 ;       Inputs:  EEPROM Address    EEADDR
                      00056 ;       Outputs: EEPROM Data       EEDATA
                      00057 ;                Return 01 in W if OK, else return 00 in W
                      00058 ;
                      00059 ; Note: EEPROM subroutines will set bit 7 in PC_OFFSET register if the
                      00060 ;       EEPROM acknowledged OK, else that bit will be cleared.  This bit 
                      00061 ;       can be checked instead of refering to the value returned in W
                      00062 ;***************************************************************************
                      00063 
                      00064 ; OPERATION:
                      00065 ; For detailed operating information and other important information about 
                      00066 ; this code, see AN571.  This code was derived from AN571, with changes
                      00067 ; as appropriate for the specific hardware in the PIC12C51x parts.
                      00068 ;********************************************************************** 
                      00069 
                      00070 
                      00071 ;***************************************************************************
                      00072 ;***************************  Variable Listing  ****************************
                      00073 ;***************************************************************************
  00000001            00074 OK          EQU     01H
  00000000            00075 NO          EQU     00H
                      00076 
                      00077 #ifdef  EMULATED
                      00078 I2C_PORT    EQU     5           ; Port A control register, used for I2C
                      00079 SCL         EQU     01H         ; EEPROM Clock, SCL (I/O bit 7)
                      00080 SDA         EQU     00H         ; EEPROM Data,  SDA (I/O bit 6)
                      00081 #else
  00000006            00082 I2C_PORT    EQU     GPIO        ; Port B control register, used for I2C
  00000007            00083 SCL         EQU     07H         ; EEPROM Clock, SCL (I/O bit 7)
  00000006            00084 SDA         EQU     06H         ; EEPROM Data,  SDA (I/O bit 6)
                      00085 #endif
                      00086 
  00000007            00087 EE_OK       EQU     07H         ; Bit 7 in PC_OFFSET used as OK flag for EE
                      00088 
MPASM 03.00 Released         PIC12I2C.ASM   4-19-2002  17:00:20         PAGE  4
PIC with Flash EE data memory Interface

LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00089         cblock 0x1A
  0000001A            00090 PC_OFFSET                       ; PC offset register (low order 4 bits), 
                      00091                                 ;  value based on operating mode of EEPROM.
                      00092                                 ;  Also, bit 7 used for EE_OK flag
  0000001B            00093 EEADDR                          ; EEPROM Address
  0000001C            00094 EEDATA                          ; EEPROM Data
  0000001D            00095 EEBYTE                          ; Byte sent to or received from
                      00096                                 ; EEPROM (control, address, or data)
  0000001E            00097 COUNTER                         ; Bit counter for serial transfer
                      00098         endc
                      00099         
                      00100 
                      00101 ;***************************************************************************
                      00102 ;***************************  EEPROM Subroutines  **************************
                      00103 ;***************************************************************************
                      00104 ; Communication for EEPROM based on I2C protocall, with Acknowledge.
                      00105 ;
                      00106 ; WRITE_BYTE: Byte write routine
                      00107 ;       Inputs:  EEPROM Address   EEADDR
                      00108 ;                EEPROM Data      EEDATA
                      00109 ;       Outputs: Return 01 in W if OK, else return 00 in W
                      00110 ;
                      00111 ; READ_CURRENT: Read EEPROM at address currently held by EE device. 
                      00112 ;       Inputs:  NONE
                      00113 ;       Outputs: EEPROM Data       EEDATA
                      00114 ;                Return 01 in W if OK, else return 00 in W
                      00115 ;
                      00116 ; READ_RANDOM: Read EEPROM byte at supplied address
                      00117 ;       Inputs:  EEPROM Address    EEADDR
                      00118 ;       Outputs: EEPROM Data       EEDATA
                      00119 ;                Return 01 in W if OK, else return 00 in W
                      00120 ;
                      00121 ; Note: EEPROM subroutines will set bit 7 in PC_OFFSET register if the
                      00122 ;       EEPROM acknowledged OK, else that bit will be cleared.  This bit 
                      00123 ;       can be checked instead of refering to the value returned in W
                      00124 ;***************************************************************************
                      00125 ;********************** Set up EEPROM control bytes ************************
                      00126 ;***************************************************************************
0022                  00127 READ_CURRENT
0022   0C84           00128         MOVLW   B'10000100'   ; PC offset for read current addr.  EE_OK bit7='1'
0023   003A           00129         MOVWF   PC_OFFSET     ; Load PC offset
0024   0A52           00130         GOTO    INIT_READ_CONTROL
                      00131 
0025                  00132 WRITE_BYTE
0025   0C80           00133         MOVLW   B'10000000'   ; PC offset for write byte.  EE_OK: bit7 = '1'
0026   0A28           00134         GOTO    INIT_WRITE_CONTROL
                      00135 
0027                  00136 READ_RANDOM
0027   0C83           00137         MOVLW   B'10000011'   ; PC offset for read random.  EE_OK: bit7 = '1'
                      00138 
0028                  00139 INIT_WRITE_CONTROL
0028   003A           00140         MOVWF   PC_OFFSET     ; Load PC offset register, value preset in W
0029   0CA0           00141         MOVLW   B'10100000'   ; Control byte with write bit, bit 0 = '0'
MPASM 03.00 Released         PIC12I2C.ASM   4-19-2002  17:00:20         PAGE  5
PIC with Flash EE data memory Interface

LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00142   
002A                  00143 START_BIT
002A   04C6           00144         BCF     I2C_PORT,SDA  ; Start bit, SDA and SCL preset to '1'

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -