📄 i2c_demo.lis
字号:
.module I2C_Demo.c
.area text(rom, con, rel)
0000 .dbfile E:\MyWorks\SOFT\I2C_E2PROM\I2C_Demo.c
0000 .dbfunc e EEPROM_Write _EEPROM_Write fV
0000 ; Data -> y+5
0000 ; M_ADD -> R10,R11
0000 ; H_ADD -> R12
.even
0000 _EEPROM_Write::
0000 0E940000 xcall push_xgset003C
0004 5901 movw R10,R18
0006 C02E mov R12,R16
0008 2197 sbiw R28,1
000A .dbline -1
000A .dbline 72
000A ; // *************** I2C driver Demo V 1.0 *************
000A ; // IO模拟方式的I2C接口操作
000A ; // *******************************************************
000A ;
000A ; #include <iom1281v.h>
000A ; #include <MACROS.h>
000A ;
000A ; #include <DC_Defines.h>
000A ;
000A ; #include "I2C.h"
000A ;
000A ;
000A ;
000A ; void EEPROM_Write(unsigned char, unsigned int, unsigned char);
000A ; unsigned char EEPROM_Read(unsigned char, unsigned int);
000A ;
000A ;
000A ; // **************************************************************** //
000A ; // *** Init_I2C(); *** //
000A ; // *** This routine will setup the I2C port direction registers *** //
000A ; // **************************************************************** //
000A ;
000A ; // ***************************************************************** //
000A ; // *** I2C_Start(); *** //
000A ; // *** This routine will set the I2C start condition on the bus, *** //
000A ; // *** All commands must be preceded by a START condition *** //
000A ; // ***************************************************************** //
000A ;
000A ; // ***************************************************************** //
000A ; // *** I2C_Stop(); *** //
000A ; // *** This routine will set the I2C stop condition on the bus, *** //
000A ; // *** All commands must end with a STOP condition *** //
000A ; // ***************************************************************** //
000A ;
000A ; // *********************************************************************** //
000A ; // *** Write_I2C_Control(0x0A,0,0); *** //
000A ; // *** This routine will write the I2C device code, the device address *** //
000A ; // *** setup on the hardware pins A0,A1 & A2, and also the W/R bit *** //
000A ; // *** So for an external EEPROM, such as the 24LC04B you would need *** //
000A ; // *** a device code of 1010 (0x0A), *** //
000A ; // *** hardware address 0 (if pins A0,A1 & A2 are left unconnected, *** //
000A ; // *** and the last parameter is R/W. Write is active low *** //
000A ; // *********************************************************************** //
000A ;
000A ; // *********************************************************************** //
000A ; // *** I2C_Ackn(); *** //
000A ; // *** This routine will clock the ACK bit from the I2C slave device *** //
000A ; // *** it will return TRUE for a fail, and FALSE for a correct ACK bit *** //
000A ; // *********************************************************************** //
000A ;
000A ; // ************************************************************** //
000A ; // *** Write_I2C_Byte(); *** //
000A ; // *** This routine will clock a byte to the slave I2C device *** //
000A ; // ************************************************************** //
000A ;
000A ; // ************************************************************************** //
000A ; // *** Read_I2C_Byte(); *** //
000A ; // *** This routine will read and return a byte from the I2C slave device *** //
000A ; // ************************************************************************** //
000A ;
000A ;
000A ;
000A ; // *********************************************************************** //
000A ; // *** Example of using Imagecraft I2C driver *** //
000A ; // *** to write to an external 8 bit address EEPROM *** //
000A ; // *** H_ADD is the hardware address set on the device A0,A1 & A2 pins *** //
000A ; // *** M_ADD is the devices internal memory address *** //
000A ; // *** Data is user data to be writen *** //
000A ; // *********************************************************************** //
000A ;
000A ; void EEPROM_Write(unsigned char H_ADD, unsigned int M_ADD, unsigned char Data)
000A ; {
000A .dbline 73
000A ; I2C_Start(); // Set I2C start condition
000A 0E940000 xcall _I2C_Start
000E .dbline 75
000E ;
000E ; Write_I2C_Control(0x0A,H_ADD,0); // Send the EEPROM control Byte
000E 2224 clr R2
0010 2882 std y+0,R2
0012 2C2D mov R18,R12
0014 0AE0 ldi R16,10
0016 0E940000 xcall _Write_I2C_Control
001A .dbline 77
001A ;
001A ; Write_I2C_Byte(M_ADD>>8); // Send the EEPROM internal Address higher byte.
001A 8501 movw R16,R10
001C 012F mov R16,R17
001E 1127 clr R17
0020 0E940000 xcall _Write_I2C_Byte
0024 .dbline 79
0024 ;
0024 ; Write_I2C_Byte(M_ADD); // Send the EEPROM internal Address lower byte.
0024 0A2D mov R16,R10
0026 0E940000 xcall _Write_I2C_Byte
002A .dbline 81
002A ;
002A ; Write_I2C_Byte(Data); // Send the EEPROM Data
002A 0D81 ldd R16,y+5
002C 0E940000 xcall _Write_I2C_Byte
0030 .dbline 83
0030 ;
0030 ; I2C_Stop(); // Set I2C Stop condition
0030 0E940000 xcall _I2C_Stop
0034 .dbline -2
0034 L1:
0034 .dbline 0 ; func end
0034 2196 adiw R28,1
0036 0C940000 xjmp pop_xgset003C
003A .dbsym l Data 5 c
003A .dbsym r M_ADD 10 i
003A .dbsym r H_ADD 12 c
003A .dbend
003A .dbfunc e EEPROM_Read _EEPROM_Read fc
003A ; Temp -> R10
003A ; M_ADD -> R12,R13
003A ; H_ADD -> R10
.even
003A _EEPROM_Read::
003A 0E940000 xcall push_xgset003C
003E 6901 movw R12,R18
0040 A02E mov R10,R16
0042 2197 sbiw R28,1
0044 .dbline -1
0044 .dbline 97
0044 ; }
0044 ;
0044 ;
0044 ;
0044 ; // *********************************************************************** //
0044 ; // *** Example of using Imagecraft I2C driver *** //
0044 ; // *** to Read an external 8 bit address EEPROM *** //
0044 ; // *** H_ADD is the hardware address set on the device A0,A1 & A2 pins *** //
0044 ; // *** M_ADD is the devices internal memory address *** //
0044 ; // *** Data is user data to be writen *** //
0044 ; // *********************************************************************** //
0044 ;
0044 ; unsigned char EEPROM_Read(unsigned char H_ADD, unsigned int M_ADD)
0044 ; {
0044 .dbline 100
0044 ; unsigned char Temp; // Temp RAM for EEPROM Read
0044 ;
0044 ; I2C_Start(); // Set I2C start condition
0044 0E940000 xcall _I2C_Start
0048 .dbline 102
0048 ;
0048 ; Write_I2C_Control(0x0A,H_ADD,0); // Send the EEPROM control Byte
0048 2224 clr R2
004A 2882 std y+0,R2
004C 2A2D mov R18,R10
004E 0AE0 ldi R16,10
0050 0E940000 xcall _Write_I2C_Control
0054 .dbline 105
0054 ; // Dummy write to set address
0054 ;
0054 ; Write_I2C_Byte(M_ADD>>8); // Send the EEPROM internal Address Higher byte.
0054 8601 movw R16,R12
0056 012F mov R16,R17
0058 1127 clr R17
005A 0E940000 xcall _Write_I2C_Byte
005E .dbline 106
005E ; Write_I2C_Byte(M_ADD); // Send the EEPROM internal Address lower byte.
005E 0C2D mov R16,R12
0060 0E940000 xcall _Write_I2C_Byte
0064 .dbline 108
0064 ;
0064 ; I2C_Start(); // Set I2C start condition
0064 0E940000 xcall _I2C_Start
0068 .dbline 110
0068 ;
0068 ; Write_I2C_Control(0x0A,H_ADD,1); // Send the EEPROM control Byte
0068 81E0 ldi R24,1
006A 8883 std y+0,R24
006C 2A2D mov R18,R10
006E 0AE0 ldi R16,10
0070 0E940000 xcall _Write_I2C_Control
0074 .dbline 112
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -