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

📄 i2c.lis

📁 nRF24L01详细编程资料
💻 LIS
📖 第 1 页 / 共 2 页
字号:
                        .module I2C.c
                        .area text(rom, con, rel)
 0000                   .dbfile D:\OLED\I2C.c
 0000                   .dbfunc e Init_I2C _Init_I2C fV
                        .even
 0000           _Init_I2C::
 0000                   .dbline -1
 0000                   .dbline 17
 0000           ; //ICC-AVR application builder : 2006-02-12 14:00:00
 0000           ; // Target : ATmega48
 0000           ; // Crystal: 1.000Mhz
 0000           ; // Author:  jackyan
 0000           ; 
 0000           ; #include "iom48v.h"
 0000           ; #include "macros.h"
 0000           ; #include "Defs.h"
 0000           ; #include "I2C.h"
 0000           ; 
 0000           ; 
 0000           ; // ******************************************** //
 0000           ; // *** This routine will setup the I2C Port *** //
 0000           ; // ******************************************** //
 0000           ; 
 0000           ; void Init_I2C(void)
 0000           ; {
 0000                   .dbline 18
 0000           ;  SETBIT(I2C_DIR,SCL);            // Set SCL to output 
 0000 3D9A              sbi 0x7,5
 0002                   .dbline 19
 0002           ;  SETBIT(I2C_DIR,SDA );           // Set SDA to output
 0002 3C9A              sbi 0x7,4
 0004                   .dbline 21
 0004           ;       
 0004           ;  SETBIT(I2C_PORT,SCL);                   // Set SCL high
 0004 459A              sbi 0x8,5
 0006                   .dbline 22
 0006           ;  SETBIT(I2C_PORT,SDA );                  // Set SDA high
 0006 449A              sbi 0x8,4
 0008                   .dbline -2
 0008           L1:
 0008                   .dbline 0 ; func end
 0008 0895              ret
 000A                   .dbend
 000A                   .dbfunc e I2C_Start _I2C_Start fV
                        .even
 000A           _I2C_Start::
 000A                   .dbline -1
 000A                   .dbline 32
 000A           ; }
 000A           ; 
 000A           ; 
 000A           ; 
 000A           ; // ************************************************ //
 000A           ; // *** This routine will send the I2C Start Bit *** //
 000A           ; // ************************************************ //
 000A           ; 
 000A           ; void I2C_Start (void)
 000A           ; {
 000A                   .dbline 33
 000A           ;  SETBIT(I2C_PORT,SCL);                                // Set SCL High
 000A 459A              sbi 0x8,5
 000C                   .dbline 34
 000C           ;  SETBIT(I2C_PORT,SDA);                                // Set SDA High
 000C 449A              sbi 0x8,4
 000E                   .dbline 36
 000E           ;  
 000E           ;  SETBIT(I2C_DIR,SDA);                    // Set SDA to output 
 000E 3C9A              sbi 0x7,4
 0010                   .dbline 37
 0010           ;  CLEARBIT(I2C_PORT,SDA);                 // Clear SDA
 0010 4498              cbi 0x8,4
 0012                   .dbline -2
 0012           L2:
 0012                   .dbline 0 ; func end
 0012 0895              ret
 0014                   .dbend
 0014                   .dbfunc e I2C_Stop _I2C_Stop fV
                        .even
 0014           _I2C_Stop::
 0014                   .dbline -1
 0014                   .dbline 46
 0014           ; }
 0014           ; 
 0014           ; 
 0014           ; // *********************************************** //
 0014           ; // *** This routine will send the I2C Stop Bit *** //
 0014           ; // *********************************************** //
 0014           ; 
 0014           ; void I2C_Stop (void)
 0014           ; {
 0014                   .dbline 48
 0014           ;  
 0014           ;  SETBIT(I2C_DIR,SDA);                    // Set SDA to output
 0014 3C9A              sbi 0x7,4
 0016                   .dbline 50
 0016           ;       
 0016           ;  CLEARBIT(I2C_PORT,SDA);                 // Clear SDA
 0016 4498              cbi 0x8,4
 0018                   .dbline 51
 0018           ;  CLEARBIT(I2C_PORT,SCL);                 // Clear SCL
 0018 4598              cbi 0x8,5
 001A                   .dbline 53
 001A           ;       
 001A           ;  SETBIT(I2C_PORT,SCL);                           // Set SCL High
 001A 459A              sbi 0x8,5
 001C                   .dbline 54
 001C           ;  SETBIT(I2C_PORT,SDA);                           // Set SDA High
 001C 449A              sbi 0x8,4
 001E                   .dbline -2
 001E           L3:
 001E                   .dbline 0 ; func end
 001E 0895              ret
 0020                   .dbend
 0020                   .dbfunc e I2C_Clock _I2C_Clock fV
                        .even
 0020           _I2C_Clock::
 0020                   .dbline -1
 0020                   .dbline 66
 0020           ; }
 0020           ; 
 0020           ; 
 0020           ; 
 0020           ; 
 0020           ; 
 0020           ; // ************************************************** //
 0020           ; // *** This routine will send the I2C clock pulse *** //
 0020           ; // ************************************************** //
 0020           ; 
 0020           ; void I2C_Clock (void)
 0020           ; {
 0020                   .dbline 67
 0020           ;  SETBIT(I2C_PORT,SCL);                                // Set SCL high
 0020 459A              sbi 0x8,5
 0022                   .dbline 70
 0022           ; // NOP();                                                             // Small Delay
 0022           ; // NOP();                                                             // Small Delay
 0022           ;  NOP();                                                               // Small Delay
 0022 0000              nop
 0024                   .dbline 71
 0024           ;  CLEARBIT(I2C_PORT,SCL);                      // Set SCL low
 0024 4598              cbi 0x8,5
 0026                   .dbline -2
 0026           L4:
 0026                   .dbline 0 ; func end
 0026 0895              ret
 0028                   .dbend
 0028                   .dbfunc e Write_I2C_Byte _Write_I2C_Byte fV
 0028           ;              i -> R20
 0028           ;           byte -> R22
                        .even
 0028           _Write_I2C_Byte::
 0028 00D0              rcall push_gset2
 002A 602F              mov R22,R16
 002C                   .dbline -1
 002C                   .dbline 82
 002C           ; }
 002C           ; 
 002C           ; 
 002C           ; 
 002C           ; 
 002C           ; // ******************************************************** //
 002C           ; // *** This routine will write a byte to the I2C device *** //
 002C           ; // ******************************************************** //
 002C           ; 
 002C           ; void Write_I2C_Byte(unsigned char byte)
 002C           ; {
 002C                   .dbline 85
 002C           ;  unsigned char i;
 002C           ; 
 002C           ;  SETBIT(I2C_DIR,SDA);                    // Set SDA to output 
 002C 3C9A              sbi 0x7,4
 002E                   .dbline 86
 002E           ;  CLEARBIT(I2C_PORT,SCL);
 002E 4598              cbi 0x8,5
 0030                   .dbline 88
 0030 4427              clr R20
 0032 0BC0              rjmp L9
 0034           L6:
 0034                   .dbline 88
 0034           ;       
 0034           ;  for (i = 0; i < 8; i++){              // Loop for our 8 bits
 0034                   .dbline 91
 0034           ;  
 0034           ;       // Set or Clear SDA pin
 0034           ;        if((byte & 0x80) == 0x80) SETBIT(I2C_PORT, SDA);       // Set I2C SDA PIN
 0034 862F              mov R24,R22
 0036 8078              andi R24,128
 0038 8038              cpi R24,128
 003A 11F4              brne L10
 003C                   .dbline 91
 003C 449A              sbi 0x8,4
 003E 01C0              rjmp L11
 0040           L10:
 0040                   .dbline 92
 0040           ;        else CLEARBIT(I2C_PORT,SDA);                                           // Clear I2C SDA PIN
 0040 4498              cbi 0x8,4
 0042           L11:
 0042                   .dbline 94
 0042 459A              sbi 0x8,5
 0044                   .dbline 96
 0044 660F              lsl R22
 0046                   .dbline 103
 0046 4598              cbi 0x8,5
 0048                   .dbline 104
 0048           L7:
 0048                   .dbline 88
 0048 4395              inc R20
 004A           L9:
 004A                   .dbline 88
 004A 4830              cpi R20,8
 004C 98F3              brlo L6
 004E                   .dbline 106
 004E           ;        
 004E           ;        SETBIT(I2C_PORT,SCL);                     // Set SCL High, Clock data
 004E           ; 
 004E           ;        byte = byte << 1;                                 // Shift data in buffer right one
 004E           ; 
 004E           ; //    NOP();
 004E           ; //    NOP();
 004E           ; //    NOP();
 004E           ; //    NOP();
 004E           ; 
 004E           ;      CLEARBIT(I2C_PORT,SCL);             // Clear SCL
 004E           ;       }
 004E           ;  
 004E           ; i=255;
 004E 4FEF              ldi R20,255
 0050 03C0              rjmp L13
 0052           L12:
 0052                   .dbline 108
 0052           ;  while(I2C_Ackn() )                              // Check for acknowledge from I2C device     
 0052           ;       {
 0052                   .dbline 109
 0052           ;       i--;
 0052 4A95              dec R20
 0054                   .dbline 110
 0054           ;       if(i==0)
 0054 09F4              brne L15
 0056                   .dbline 111
 0056           ;               break;
 0056 03C0              rjmp L14
 0058           L15:
 0058                   .dbline 112
 0058           L13:
 0058                   .dbline 107
 0058 18D0              rcall _I2C_Ackn
 005A 0023              tst R16
 005C D1F7              brne L12
 005E           L14:
 005E                   .dbline -2
 005E           L5:
 005E 00D0              rcall pop_gset2
 0060                   .dbline 0 ; func end
 0060 0895              ret
 0062                   .dbsym r i 20 c
 0062                   .dbsym r byte 22 c

⌨️ 快捷键说明

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