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

📄 i2c.lis

📁 AVR单片机C语言程序设计实例精粹
💻 LIS
📖 第 1 页 / 共 3 页
字号:
 0172                   .dbfunc e I2C_Send_String_with_SubAddress _I2C_Send_String_with_SubAddress fc
 0172           ;            cnt -> R20
 0172           ;        bLength -> R22
 0172           ;            ptr -> R10,R11
 0172           ;       bAddress -> R20
 0172           ;        bDevice -> R12
                        .even
 0172           _I2C_Send_String_with_SubAddress::
 0172 0E940000          xcall push_gset4
 0176 422F              mov R20,R18
 0178 C02E              mov R12,R16
 017A A884              ldd R10,y+8
 017C B984              ldd R11,y+9
 017E 6A85              ldd R22,y+10
 0180                   .dbline -1
 0180                   .dbline 237
 0180           ; }
 0180           ; 
 0180           ; //***************************************************************
 0180           ; // Function    : I2C_Send_String_with_SubAddress
 0180           ; // Input       : bDevice  - Slave Device with a I2C Address,
 0180           ; //               bAddress - SubAddress of the Slave,
 0180           ; //               ptr      - Pointer to the data buffter 
 0180           ; // Output      : I2C Operation Status - Success(1)/Fail(0)
 0180           ; // Description : Transmit a data to Slave with SubAddress
 0180           ; //***************************************************************
 0180           ; INT8U I2C_Send_String_with_SubAddress(INT8U bDevice,INT8U bAddress,INT8U *ptr,INT8U bLength)
 0180           ; {
 0180                   .dbline 239
 0180           ;       INT8U cnt;
 0180           ;       I2C_Start_Condition();                                                                                                                                          
 0180 55DF              xcall _I2C_Start_Condition
 0182                   .dbline 240
 0182           ;       I2C_Send_Byte(bDevice);                                                                                                                                         
 0182 0C2D              mov R16,R12
 0184 61DF              xcall _I2C_Send_Byte
 0186                   .dbline 241
 0186           ;       if(bI2C_Ack == 0)                                                                                                                                               
 0186 20900000          lds R2,_bI2C_Ack
 018A 2220              tst R2
 018C 11F4              brne L45
 018E                   .dbline 242
 018E           ;       {                                                                                                                                               
 018E                   .dbline 243
 018E           ;               return(0);                                                                                                                                              
 018E 0027              clr R16
 0190 19C0              xjmp L44
 0192           L45:
 0192                   .dbline 245
 0192           ;       }                                                                                                                                               
 0192           ;       I2C_Send_Byte(bAddress);                                                                                                                                                
 0192 042F              mov R16,R20
 0194 59DF              xcall _I2C_Send_Byte
 0196                   .dbline 246
 0196           ;       if(bI2C_Ack == 0)                                                                                                                                               
 0196 20900000          lds R2,_bI2C_Ack
 019A 2220              tst R2
 019C 11F4              brne L47
 019E                   .dbline 247
 019E           ;       {                                                                                                                                               
 019E                   .dbline 248
 019E           ;               return(0);                                                                                                                                              
 019E 0027              clr R16
 01A0 11C0              xjmp L44
 01A2           L47:
 01A2                   .dbline 250
 01A2           ;       }       
 01A2           ;       for(cnt = 0;cnt < bLength;cnt++)
 01A2 4427              clr R20
 01A4 0BC0              xjmp L52
 01A6           L49:
 01A6                   .dbline 251
 01A6           ;       {
 01A6                   .dbline 252
 01A6           ;               I2C_Send_Byte(*ptr++);
 01A6 F501              movw R30,R10
 01A8 0191              ld R16,Z+
 01AA 5F01              movw R10,R30
 01AC 4DDF              xcall _I2C_Send_Byte
 01AE                   .dbline 253
 01AE           ;               if(bI2C_Ack == 0)                                                                                                                                               
 01AE 20900000          lds R2,_bI2C_Ack
 01B2 2220              tst R2
 01B4 11F4              brne L53
 01B6                   .dbline 254
 01B6           ;               {                                                                                                                                               
 01B6                   .dbline 255
 01B6           ;                       return(0);                                                                                                                                              
 01B6 0027              clr R16
 01B8 05C0              xjmp L44
 01BA           L53:
 01BA                   .dbline 257
 01BA           L50:
 01BA                   .dbline 250
 01BA 4395              inc R20
 01BC           L52:
 01BC                   .dbline 250
 01BC 4617              cp R20,R22
 01BE 98F3              brlo L49
 01C0                   .dbline 258
 01C0           ;               }
 01C0           ;       }
 01C0           ;       I2C_Stop_Condition();
 01C0 3DDF              xcall _I2C_Stop_Condition
 01C2                   .dbline 259
 01C2           ;       return(1);
 01C2 01E0              ldi R16,1
 01C4                   .dbline -2
 01C4           L44:
 01C4 0E940000          xcall pop_gset4
 01C8                   .dbline 0 ; func end
 01C8 0895              ret
 01CA                   .dbsym r cnt 20 c
 01CA                   .dbsym r bLength 22 c
 01CA                   .dbsym r ptr 10 pc
 01CA                   .dbsym r bAddress 20 c
 01CA                   .dbsym r bDevice 12 c
 01CA                   .dbend
 01CA                   .dbfunc e I2C_Receive_Data_without_SubAddress _I2C_Receive_Data_without_SubAddress fc
 01CA           ;            ptr -> R20,R21
 01CA           ;        bDevice -> R22
                        .even
 01CA           _I2C_Receive_Data_without_SubAddress::
 01CA 0E940000          xcall push_gset2
 01CE A901              movw R20,R18
 01D0 602F              mov R22,R16
 01D2                   .dbline -1
 01D2                   .dbline 270
 01D2           ; }
 01D2           ; 
 01D2           ; //***************************************************************
 01D2           ; // Function    : I2C_Receive_Data_without_Address
 01D2           ; // Input       : bDevice  - Slave Device with a I2C Address,
 01D2           ; //               ptr      - Pointer to the receive data buffter 
 01D2           ; // Output      : I2C Operation Status - Success(1)/Fail(0)
 01D2           ; // Description : Receive N data from Slave without SubAddress
 01D2           ; //***************************************************************
 01D2           ; INT8U I2C_Receive_Data_without_SubAddress(INT8U bDevice,INT8U *ptr)
 01D2           ; {
 01D2                   .dbline 271
 01D2           ;       I2C_Start_Condition();
 01D2 2CDF              xcall _I2C_Start_Condition
 01D4                   .dbline 272
 01D4           ;       I2C_Send_Byte(bDevice | 0x01);
 01D4 062F              mov R16,R22
 01D6 0160              ori R16,1
 01D8 37DF              xcall _I2C_Send_Byte
 01DA                   .dbline 273
 01DA           ;     if(bI2C_Ack == 0)
 01DA 20900000          lds R2,_bI2C_Ack
 01DE 2220              tst R2
 01E0 11F4              brne L56
 01E2                   .dbline 274
 01E2           ;     {
 01E2                   .dbline 275
 01E2           ;       return(0);
 01E2 0027              clr R16
 01E4 07C0              xjmp L55
 01E6           L56:
 01E6                   .dbline 277
 01E6           ;     }
 01E6           ;     *ptr = I2C_Receive_Byte();
 01E6 5FDF              xcall _I2C_Receive_Byte
 01E8 FA01              movw R30,R20
 01EA 0083              std z+0,R16
 01EC                   .dbline 278
 01EC           ;     I2C_Ack(1);
 01EC 01E0              ldi R16,1
 01EE 74DF              xcall _I2C_Ack
 01F0                   .dbline 279
 01F0           ;     I2C_Stop_Condition();
 01F0 25DF              xcall _I2C_Stop_Condition
 01F2                   .dbline 280
 01F2           ;     return(1);
 01F2 01E0              ldi R16,1
 01F4                   .dbline -2
 01F4           L55:
 01F4 0E940000          xcall pop_gset2
 01F8                   .dbline 0 ; func end
 01F8 0895              ret
 01FA                   .dbsym r ptr 20 pc
 01FA                   .dbsym r bDevice 22 c
 01FA                   .dbend
 01FA                   .dbfunc e I2C_Recive_String_with_SubAddress _I2C_Recive_String_with_SubAddress fc
 01FA           ;            cnt -> R20
 01FA           ;        bLength -> R22
 01FA           ;            ptr -> R10,R11
 01FA           ;       bAddress -> R14
 01FA           ;        bDevice -> R12
                        .even
 01FA           _I2C_Recive_String_with_SubAddress::
 01FA 0E940000          xcall push_gset5
 01FE E22E              mov R14,R18
 0200 C02E              mov R12,R16
 0202 AA84              ldd R10,y+10
 0204 BB84              ldd R11,y+11
 0206 6C85              ldd R22,y+12
 0208                   .dbline -1
 0208                   .dbline 292
 0208           ; }
 0208           ; 
 0208           ; //***************************************************************
 0208           ; // Function    : I2C_Recive_String_with_AddressIRcvStr
 0208           ; // Input       : bDevice  - Slave Device with a I2C Address,
 0208           ; //               bAddress - SubAddress of the Slave,
 0208           ; //               ptr      - Pointer to the receive data buffter 
 0208           ; // Output      : I2C Operation Status - Success(1)/Fail(0)
 0208           ; // Description : Receive N data from Slave with SubAddress
 0208           ; //***************************************************************
 0208           ; INT8U I2C_Recive_String_with_SubAddress(INT8U bDevice,INT8U bAddress,INT8U *ptr,INT8U bLength)
 0208           ; {
 0208                   .dbline 293
 0208           ;       INT8U cnt = 0;
 0208 4427              clr R20
 020A                   .dbline 294
 020A           ;       I2C_Start_Condition();
 020A 10DF              xcall _I2C_Start_Condition
 020C                   .dbline 295
 020C           ;       I2C_Send_Byte(bDevice);
 020C 0C2D              mov R16,R12
 020E 1CDF              xcall _I2C_Send_Byte
 0210                   .dbline 296
 0210           ;       if(bI2C_Ack == 0)
 0210 20900000          lds R2,_bI2C_Ack
 0214 2220              tst R2
 0216 11F4              brne L59
 0218                   .dbline 297
 0218           ;       {
 0218                   .dbline 298
 0218           ;               return(0);
 0218 0027              clr R16
 021A 26C0              xjmp L58
 021C           L59:
 021C                   .dbline 300
 021C           ;       }
 021C           ;       I2C_Send_Byte(bAddress);
 021C 0E2D              mov R16,R14
 021E 14DF              xcall _I2C_Send_Byte
 0220                   .dbline 301
 0220           ;     if(bI2C_Ack == 0)
 0220 20900000          lds R2,_bI2C_Ack
 0224 2220              tst R2
 0226 11F4              brne L61
 0228                   .dbline 302
 0228           ;       {
 0228                   .dbline 303
 0228           ;               return(0);
 0228 0027              clr R16
 022A 1EC0              xjmp L58
 022C           L61:
 022C                   .dbline 305
 022C           ;       }
 022C           ;       I2C_Start_Condition();
 022C FFDE              xcall _I2C_Start_Condition
 022E                   .dbline 306
 022E           ;       I2C_Send_Byte(bDevice | 0x01);
 022E 0C2D              mov R16,R12
 0230 0160              ori R16,1
 0232 0ADF              xcall _I2C_Send_Byte
 0234                   .dbline 307
 0234           ;       if(bI2C_Ack == 0)
 0234 20900000          lds R2,_bI2C_Ack
 0238 2220              tst R2
 023A 11F4              brne L63
 023C                   .dbline 308
 023C           ;       {
 023C                   .dbline 309
 023C           ;               return(0);
 023C 0027              clr R16
 023E 14C0              xjmp L58
 0240           L63:
 0240                   .dbline 311
 0240           ;       }
 0240           ;       for(cnt = 0;cnt < bLength - 1;cnt++)
 0240 4427              clr R20
 0242 07C0              xjmp L68
 0244           L65:
 0244                   .dbline 312
 0244                   .dbline 313
 0244 30DF              xcall _I2C_Receive_Byte
 0246 F501              movw R30,R10
 0248 0193              st Z+,R16
 024A 5F01              movw R10,R30
 024C                   .dbline 314
 024C 0027              clr R16
 024E 44DF              xcall _I2C_Ack
 0250                   .dbline 315
 0250           L66:
 0250                   .dbline 311
 0250 4395              inc R20
 0252           L68:
 0252                   .dbline 311
 0252 862F              mov R24,R22
 0254 8150              subi R24,1
 0256 4817              cp R20,R24
 0258 A8F3              brlo L65
 025A                   .dbline 316
 025A           ;       {
 025A           ;               *ptr++ = I2C_Receive_Byte();
 025A           ;               I2C_Ack(0);
 025A           ;       }
 025A           ;       *ptr = I2C_Receive_Byte();
 025A 25DF              xcall _I2C_Receive_Byte
 025C F501              movw R30,R10
 025E 0083              std z+0,R16
 0260                   .dbline 317
 0260           ;       I2C_Ack(1);
 0260 01E0              ldi R16,1
 0262 3ADF              xcall _I2C_Ack
 0264                   .dbline 318
 0264           ;       I2C_Stop_Condition();
 0264 EBDE              xcall _I2C_Stop_Condition
 0266                   .dbline 319
 0266           ;       return(1);
 0266 01E0              ldi R16,1
 0268                   .dbline -2
 0268           L58:
 0268 0E940000          xcall pop_gset5
 026C                   .dbline 0 ; func end
 026C 0895              ret
 026E                   .dbsym r cnt 20 c
 026E                   .dbsym r bLength 22 c
 026E                   .dbsym r ptr 10 pc
 026E                   .dbsym r bAddress 14 c
 026E                   .dbsym r bDevice 12 c
 026E                   .dbend

⌨️ 快捷键说明

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