📄 pic12i2c.sdi
字号:
,,, LIST p=12CE518 ;
,,, #include "P12CE518.INC" ; Include header file
,,, LIST
,,,; P12CE518.INC Standard Header File, Version 1.00 Microchip Technology, Inc.
,,, LIST
,,,
,,,
,,, cblock 0x10
,,, result
,,, count
,,, endc
,,,
,,, ; Vector for normal start up.
,,, org 0
0000,0A01,, goto start
,,,
,,,
,,,; Main program starts here:
0001,0C3C,start,start movlw 0x3C
0002,0006,, tris GPIO
,,,
,,,
,,,; Write a byte
0003,0C00,, movlw 0
0004,003B,, movwf EEADDR
0005,0C85,loop,loop movlw 0x85
0006,003C,, movwf EEDATA
0007,0925,, call WRITE_BYTE
0008,0030,, movwf result
,,,
0009,0916,, call serout
,,,
,,,; Wait for INT high
000A,0746,wait1,wait1 btfss GPIO,2
000B,0A0A,, goto wait1
,,,
,,,;Read it back
,,,
000C,0CFF,, movlw 0xFF
000D,003C,, movwf EEDATA
,,,
000E,0922,, call READ_CURRENT
000F,021C,, movfw EEDATA
0010,0030,, movwf result
0011,0916,, call serout
,,,
,,,; Wait for INT low
0012,0646,wait2,wait2 btfsc GPIO,2
0013,0A12,, goto wait2
,,,
0014,02BB,, incf EEADDR,F
0015,0A05,, goto loop
,,,
,,,;Serial output of result
0016,0C08,serout,serout movlw 8 ;Loop for 8 bits
0017,0031,, movwf count
0018,0CC0,loop1,loop1 movlw 0xC0 ;Start with a zero except for SDA/SCL
0019,06F0,, btfsc result,7 ;Test result bit
001A,0D01,, iorlw 0x01
001B,0026,, movwf GPIO ;Output data bit to port on GP0
001C,0526,, bsf GPIO,1 ;Generate Clock pulse on GP1
001D,0426,, bcf GPIO,1
001E,0370,, rlf result,F ;Get next result bit
001F,02F1,, decfsz count,F ;Loop for next bit
0020,0A18,, goto loop1
0021,0800,, return
,,,
,,,
,,,
,,, #include fl51xinc.asm
,,, TITLE "PIC with Flash EE data memory Interface"
,,,;
,,,; Program: FL51XINC.ASM V1.10
,,,; Revision Date:
,,,; 09-09-97 Adapted to 12C51x parts
,,,; 01-Apr-1999 Added emulation hooks
,,,;
,,,
,,,; #define EMULATED ; comment this line out for use on real part
,,,
,,,; PIC12C51X EEPROM communication code. This code should be included in
,,,; with the application. These routines provide the following functionality:
,,,; write a byte to a specified address.
,,,; read a byte from a specified address.
,,,; read a byte from the next address.
,,,;
,,,; Emulation Requires:
,,,; MPLAB-ICE
,,,; PCM16XA0 processor module
,,,; DVA12XP80 Device Adapter.
,,,; Define EMULATOR at the top of this file (#define EMULATOR)
,,,; This will set the I2C_PORT, SDA and SCL lines to communicate over
,,,; Port A, pins 0 and 1. It also assembles in the necessary TRIS
,,,; instructions to allow reading from the SDA line.
,,,;
,,,; To convert the code for the actual part, simply comment out the #define EMULATOR
,,,; line and reassemble.
,,,;
,,,; FL51XTST.ASM is also provided for linker users.
,,,;
,,,; INTRODUCTION:
,,,; The Microchip 12c51x family of microntrollers are multichip modules
,,,; which contain a PIC12C508 microcontroller and a 24LC00 EEPROM.
,,,; This application note is intended to provide users with highly compressed
,,,; assembly code for communication between the EEPROM and the Microcontroller,
,,,; which will leave the user a maximum amount of code space for the core
,,,; application.
,,,;
,,,;***************************************************************************
,,,;*************************** EEPROM Subroutines **************************
,,,;***************************************************************************
,,,; Communication for EEPROM based on I2C protocall, with Acknowledge.
,,,;
,,,; Byte_Write: Byte write routine
,,,; Inputs: EEPROM Address EEADDR
,,,; EEPROM Data EEDATA
,,,; Outputs: Return 01 in W if OK, else return 00 in W
,,,;
,,,; Read_Current: Read EEPROM at address currently held by EE device.
,,,; Inputs: NONE
,,,; Outputs: EEPROM Data EEDATA
,,,; Return 01 in W if OK, else return 00 in W
,,,;
,,,; Read_Random: Read EEPROM byte at supplied address
,,,; Inputs: EEPROM Address EEADDR
,,,; Outputs: EEPROM Data EEDATA
,,,; Return 01 in W if OK, else return 00 in W
,,,;
,,,; Note: EEPROM subroutines will set bit 7 in PC_OFFSET register if the
,,,; EEPROM acknowledged OK, else that bit will be cleared. This bit
,,,; can be checked instead of refering to the value returned in W
,,,;***************************************************************************
,,,
,,,; OPERATION:
,,,; For detailed operating information and other important information about
,,,; this code, see AN571. This code was derived from AN571, with changes
,,,; as appropriate for the specific hardware in the PIC12C51x parts.
,,,;**********************************************************************
,,,
,,,
,,,;***************************************************************************
,,,;*************************** Variable Listing ****************************
,,,;***************************************************************************
,,,OK EQU 01H
,,,NO EQU 00H
,,,
,,,#ifdef EMULATED
,,,I2C_PORT EQU 5 ; Port A control register, used for I2C
,,,SCL EQU 01H ; EEPROM Clock, SCL (I/O bit 7)
,,,SDA EQU 00H ; EEPROM Data, SDA (I/O bit 6)
,,,#else
,,,I2C_PORT EQU GPIO ; Port B control register, used for I2C
,,,SCL EQU 07H ; EEPROM Clock, SCL (I/O bit 7)
,,,SDA EQU 06H ; EEPROM Data, SDA (I/O bit 6)
,,,#endif
,,,
,,,EE_OK EQU 07H ; Bit 7 in PC_OFFSET used as OK flag for EE
,,,
,,, cblock 0x1A
,,,PC_OFFSET ; PC offset register (low order 4 bits),
,,, ; value based on operating mode of EEPROM.
,,, ; Also, bit 7 used for EE_OK flag
,,,EEADDR ; EEPROM Address
,,,EEDATA ; EEPROM Data
,,,EEBYTE ; Byte sent to or received from
,,, ; EEPROM (control, address, or data)
,,,COUNTER ; Bit counter for serial transfer
,,, endc
,,,
,,,
,,,;***************************************************************************
,,,;*************************** EEPROM Subroutines **************************
,,,;***************************************************************************
,,,; Communication for EEPROM based on I2C protocall, with Acknowledge.
,,,;
,,,; WRITE_BYTE: Byte write routine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -