📄 i2cslave.lis
字号:
01EE L61:
01EE 483F cpi R20,248
01F0 E0E0 ldi R30,0
01F2 5E07 cpc R21,R30
01F4 09F4 brne X18
01F6 78C0 xjmp L32
01F8 X18:
01F8 77C0 xjmp L31
01FA X1:
01FA .dbline 210
01FA ; {
01FA L34:
01FA .dbline 222
01FA ;
01FA ; /********************************************/
01FA ; // 从接收状态码
01FA ; case TW_SR_SLA_ACK: // 0x60: 自己的SLA+W 已经被接收,ACK 已返回
01FA ; case TW_SR_ARB_LOST_SLA_ACK:// 0x68: SLA+R/W 作为主机的仲裁失败;自己的SLA+W 已经被接收,ACK 已返回
01FA ; case TW_SR_GCALL_ACK: // 0x70: 接收到广播地址,ACK 已返回
01FA ; case TW_SR_ARB_LOST_GCALL_ACK: // 0x78: SLA+R/W 作为主机的仲裁失败;接收到广播地址,ACK 已返回
01FA ;
01FA ; // 被选中为从写入 (数据将从主机接收)
01FA ; // 设置状态
01FA ; //UDR=0x66;
01FA ; I2cState = I2C_SLAVE_RX;
01FA 85E0 ldi R24,5
01FC 80932C00 sts _I2cState,R24
0200 .dbline 224
0200 ; // 缓冲准备
0200 ; I2cReceiveDataIndex = 0;
0200 2224 clr R2
0202 20920700 sts _I2cReceiveDataIndex,R2
0206 .dbline 226
0206 ; // 接收数据,回应 ACK
0206 ; TWCR=TWCR&TWCR_CMD_MASK|(1<<TWINT)|(1<<TWEA);
0206 86B7 in R24,0x36
0208 8F70 andi R24,15
020A 806C ori R24,192
020C 86BF out 0x36,R24
020E .dbline 227
020E ; break;
020E 6CC0 xjmp L32
0210 L35:
0210 .dbline 233
0210 ; //----------------------------读取数据,有应答位-----------------------
0210 ; case TW_SR_DATA_ACK: // 0x80: 以前以自己的 SLA+W 被寻址;数据已经被接收,ACK 已返回
0210 ; // case TW_SR_GCALL_DATA_ACK: // 0x90: 以前以广播方式被寻址;数据已经被接收,ACK 已返回
0210 ;
0210 ;
0210 ; I2cReceiveData[I2cReceiveDataIndex++] = TWDR;
0210 20900700 lds R2,_I2cReceiveDataIndex
0214 3324 clr R3
0216 822D mov R24,R2
0218 8F5F subi R24,255 ; addi 1
021A 80930700 sts _I2cReceiveDataIndex,R24
021E 80E0 ldi R24,<_I2cReceiveData
0220 90E0 ldi R25,>_I2cReceiveData
0222 E22D mov R30,R2
0224 FF27 clr R31
0226 E80F add R30,R24
0228 F91F adc R31,R25
022A 23B0 in R2,0x3
022C 2082 std z+0,R2
022E .dbline 237
022E ; //UDR=I2cReceiveData[I2cReceiveDataIndex-1];
022E ;
022E ; //检查接收缓冲区状态 是否溢出
022E ; if(I2cReceiveDataIndex < 7)//
022E 80910700 lds R24,_I2cReceiveDataIndex
0232 8730 cpi R24,7
0234 18F4 brsh L36
0236 .dbline 238
0236 ; {
0236 .dbline 240
0236 ; // 接收数据,回应 ACK
0236 ; i2cReceiveByte(TRUE);
0236 01E0 ldi R16,1
0238 24DF xcall _i2cReceiveByte
023A .dbline 242
023A ;
023A ; }
023A 56C0 xjmp L32
023C L36:
023C .dbline 244
023C ; else
023C ; {
023C .dbline 246
023C ; // 接收数据,回应 NACK
023C ; i2cReceiveByte(FALSE);
023C 0027 clr R16
023E 21DF xcall _i2cReceiveByte
0240 .dbline 248
0240 ;
0240 ; }
0240 .dbline 249
0240 ; break;
0240 53C0 xjmp L32
0242 L38:
0242 .dbline 255
0242 ; //########################################################################
0242 ; case TW_SR_DATA_NACK: // 0x88: 以前以自己的 SLA+W 被寻址;数据已经被接收,NOT ACK 已返回
0242 ; // case TW_SR_GCALL_DATA_NACK: // 0x98: 以前以广播方式被寻址;数据已经被接收,NOT ACK 已返回
0242 ;
0242 ; // 接收数据,回应 NACK
0242 ; i2cReceiveByte(FALSE);
0242 0027 clr R16
0244 1EDF xcall _i2cReceiveByte
0246 .dbline 256
0246 ; break;
0246 50C0 xjmp L32
0248 L39:
0248 .dbline 259
0248 ; //---------------------无应答位------------------------------------------
0248 ; case TW_SR_STOP: // 0xA0: 在以从机工作时接收到STOP或重复START
0248 ; TWCR=TWCR&TWCR_CMD_MASK|(1<<TWINT)|(1<<TWEA);
0248 86B7 in R24,0x36
024A 8F70 andi R24,15
024C 806C ori R24,192
024E 86BF out 0x36,R24
0250 .dbline 264
0250 ; // i2c 接收完成
0250 ; // if(i2cSlaveReceive)
0250 ; // i2cSlaveReceive(I2cReceiveDataIndex, I2cReceiveData);
0250 ; // 设置状态
0250 ; I2cState = I2C_IDLE; //i2c接受结束,可以处理数据
0250 2224 clr R2
0252 20922C00 sts _I2cState,R2
0256 .dbline 265
0256 ; i2creceive_b=1; //i2c命令处理申请
0256 81E0 ldi R24,1
0258 80930500 sts _i2creceive_b,R24
025C .dbline 266
025C ; break;
025C 45C0 xjmp L32
025E L40:
025E .dbline 275
025E ;
025E ; // ---------------------从发送------------------------------------
025E ; case TW_ST_SLA_ACK: // 0xA8: 自己的SLA+R 已经被接收,ACK 已返回
025E ; case TW_ST_ARB_LOST_SLA_ACK:// 0xB0: SLA+R/W 作为主机的仲裁失败;自己的SLA+R 已经被接收,ACK 已返回
025E ;
025E ; // 被选中为从读出 (数据将从传回主机)
025E ; // 设置状态
025E ; //UDR=0x65;
025E ; I2cState = I2C_SLAVE_TX;
025E 84E0 ldi R24,4
0260 80932C00 sts _I2cState,R24
0264 .dbline 289
0264 ; /* if(catt[0]==catt[1])
0264 ; {
0264 ; I2cReceiveData[0]=catt[0];
0264 ; }
0264 ; else if(catt[0]==catt[2])
0264 ; {I2cReceiveData[0]=catt[0];
0264 ; }
0264 ; else if(catt[1]==catt[2])
0264 ; {I2cReceiveData[0]=catt[2];
0264 ; }*/
0264 ; // I2cSendData[0]=catt;
0264 ; // 数据请求 需要发送的字节长度
0264 ; // if(i2cSlaveTransmit) I2cSendDataLength = i2cSlaveTransmit(I2C_SEND_DATA_BUFFER_SIZE, I2cSendData); //更改发送数据长度
0264 ; I2cSendDataIndex = 0;
0264 2224 clr R2
0266 20921900 sts _I2cSendDataIndex,R2
026A .dbline 290
026A ; if(i2creadtime_b)
026A 20900400 lds R2,_i2creadtime_b
026E 2220 tst R2
0270 21F0 breq L41
0272 .dbline 291
0272 ; {
0272 .dbline 292
0272 ; i2csendmax=7; //发送时间数据7字节
0272 87E0 ldi R24,7
0274 80932A00 sts _i2csendmax,R24
0278 .dbline 293
0278 ; }
0278 03C0 xjmp L42
027A L41:
027A .dbline 294
027A ; else {
027A .dbline 295
027A ; i2csendmax=3;//正常发送3字节
027A 83E0 ldi R24,3
027C 80932A00 sts _i2csendmax,R24
0280 .dbline 296
0280 ; }
0280 L42:
0280 L43:
0280 .dbline 301
0280 ; // I2cSendData[0]=EEPROMread(0xff);
0280 ; case TW_ST_DATA_ACK: // 0xB8: TWDR 里数据已经发送,接收到ACK
0280 ;
0280 ; // 发送数据位
0280 ; TWDR=I2cSendData[I2cSendDataIndex++];
0280 20901900 lds R2,_I2cSendDataIndex
0284 3324 clr R3
0286 822D mov R24,R2
0288 8F5F subi R24,255 ; addi 1
028A 80931900 sts _I2cSendDataIndex,R24
028E 80E0 ldi R24,<_I2cSendData
0290 90E0 ldi R25,>_I2cSendData
0292 E22D mov R30,R2
0294 FF27 clr R31
0296 E80F add R30,R24
0298 F91F adc R31,R25
029A 2080 ldd R2,z+0
029C 23B8 out 0x3,R2
029E .dbline 307
029E ; // UDR=I2cSendData[I2cSendDataIndex-1];
029E ; // if(I2cSendDataIndex==1)
029E ; //{
029E ; //I2cSendData[0]=catt;
029E ; // UDR=0x55;//}
029E ; PORTA|=0x80;//PA7置高,取消申请
029E DF9A sbi 0x1b,7
02A0 .dbline 308
02A0 ; if(I2cSendDataIndex < i2csendmax) //发送字节
02A0 20902A00 lds R2,_i2csendmax
02A4 30901900 lds R3,_I2cSendDataIndex
02A8 3214 cp R3,R2
02AA 28F4 brsh L44
02AC .dbline 310
02AC ; // 回应 ACK
02AC ; TWCR=TWCR&TWCR_CMD_MASK|(1<<TWINT)|(1<<TWEA);
02AC 86B7 in R24,0x36
02AE 8F70 andi R24,15
02B0 806C ori R24,192
02B2 86BF out 0x36,R24
02B4 04C0 xjmp L45
02B6 L44:
02B6 .dbline 313
02B6 ; else
02B6 ; // 回应 NACK
02B6 ; TWCR=TWCR&TWCR_CMD_MASK|(1<<TWINT);
02B6 86B7 in R24,0x36
02B8 8F70 andi R24,15
02BA 8068 ori R24,128
02BC 86BF out 0x36,R24
02BE L45:
02BE .dbline 314
02BE ; i2creadtime_b=0;
02BE 2224 clr R2
02C0 20920400 sts _i2creadtime_b,R2
02C4 .dbline 315
02C4 ; break;
02C4 11C0 xjmp L32
02C6 L46:
02C6 .dbline 323
02C6 ; //##################################################################
02C6 ; case TW_ST_DATA_NACK: // 0xC0: TWDR 里数据已经发送接收到NOT ACK
02C6 ; case TW_ST_LAST_DATA: // 0xC8: TWDR 的一字节数据已经发送(TWAE = “0”);接收到ACK
02C6 ;
02C6 ; // 全部完成
02C6 ; // 从方式开放
02C6 ; //UDR=0xff;
02C6 ; TWCR=TWCR&TWCR_CMD_MASK|(1<<TWINT)|(1<<TWEA);
02C6 86B7 in R24,0x36
02C8 8F70 andi R24,15
02CA 806C ori R24,192
02CC 86BF out 0x36,R24
02CE .dbline 325
02CE ; // 设置状态
02CE ; I2cState = I2C_IDLE;
02CE 2224 clr R2
02D0 20922C00 sts _I2cState,R2
02D4 .dbline 328
02D4 ; //i2creceive_b=1;
02D4 ; //UDR=0x55;
02D4 ; i2creadtime_b=0;
02D4 20920400 sts _i2creadtime_b,R2
02D8 .dbline 330
02D8 ;
02D8 ; break;
02D8 07C0 xjmp L32
02DA X2:
02DA .dbline 336
02DA ;
02DA ;
02DA ; case TW_NO_INFO: // 0xF8: 没有相关的状态信息;TWINT = “0”
02DA ; // 无操作
02DA ;
02DA ; break;
02DA L48:
02DA .dbline 340
02DA ; case TW_BUS_ERROR: // 0x00: 由于非法的START 或STOP 引起的总线错误
02DA ;
02DA ; // 内部硬件复位,释放总线
02DA ; TWCR=TWCR&TWCR_CMD_MASK|(1<<TWINT)|(1<<TWSTO)|(1<<TWEA);
02DA 86B7 in R24,0x36
02DC 8F70 andi R24,15
02DE 806D ori R24,208
02E0 86BF out 0x36,R24
02E2 .dbline 342
02E2 ; // 设置状态
02E2 ; I2cState = I2C_IDLE;
02E2 2224 clr R2
02E4 20922C00 sts _I2cState,R2
02E8 .dbline 344
02E8 ; //i2creceive_b=1;
02E8 ; break;
02E8 L31:
02E8 L32:
02E8 .dbline -2
02E8 L30:
02E8 0E940000 xcall pop_gset1
02EC 0E940000 xcall pop_lset
02F0 .dbline 0 ; func end
02F0 1895 reti
02F2 .dbsym r status 20 c
02F2 .dbend
.area bss(ram, con, rel)
0000 .dbfile G:\McuControl\i2cslave.c
0000 _i2cSlaveTransmit::
0000 .blkb 2
0002 .dbsym e i2cSlaveTransmit _i2cSlaveTransmit pfc
0002 _i2cSlaveReceive::
0002 .blkb 2
0004 .dbsym e i2cSlaveReceive _i2cSlaveReceive pfV
0004 _i2creadtime_b::
0004 .blkb 1
0005 .dbsym e i2creadtime_b _i2creadtime_b c
0005 _i2creceive_b::
0005 .blkb 1
0006 .dbsym e i2creceive_b _i2creceive_b c
0006 _I2cReceiveDataLength::
0006 .blkb 1
0007 .dbsym e I2cReceiveDataLength _I2cReceiveDataLength c
0007 _I2cReceiveDataIndex::
0007 .blkb 1
0008 .dbsym e I2cReceiveDataIndex _I2cReceiveDataIndex c
0008 _I2cReceiveData::
0008 .blkb 16
0018 .dbsym e I2cReceiveData _I2cReceiveData A[16:16]c
0018 _I2cSendDataLength::
0018 .blkb 1
0019 .dbsym e I2cSendDataLength _I2cSendDataLength c
0019 _I2cSendDataIndex::
0019 .blkb 1
001A .dbsym e I2cSendDataIndex _I2cSendDataIndex c
001A _I2cSendData::
001A .blkb 16
002A .dbsym e I2cSendData _I2cSendData A[16:16]c
002A _i2csendmax::
002A .blkb 1
002B .dbsym e i2csendmax _i2csendmax c
002B _I2cDeviceAddrRW:
002B .blkb 1
002C .dbfile G:\McuControl/i2c.h
002C .dbsym s I2cDeviceAddrRW _I2cDeviceAddrRW c
002C _I2cState:
002C .blkb 1
002D .dbsym s I2cState _I2cState c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -