i2c.c

来自「TMS320VC5402的中断程序和AIC23的音频输出解码程序,还有DSP的H」· C语言 代码 · 共 134 行

C
134
字号
#include  <Reg52.h>

void nop5(void);
 
sbit       scl		=P3^0;
sbit       sda		=P3^1;


void s(void)
{
	 sda=0;
     nop5();
	 scl=0;
     nop5(); 
}	

void e(void)
{
	sda=0;		
    nop5();
	scl=1;
    nop5();
	sda=1;
    nop5();
}

void one_byte_write(unsigned char kk)
 {
  unsigned char i;
    for (i=0;i<8;i++)
	{
      kk=kk<<1; 
      scl=0;
      sda=CY;
      scl=1; 
      nop5();
	  scl=0;

      }
	scl=0;

    nop5(); 
	sda=1;
	while(sda);             //ack here

	scl=1;
    nop5();       
	scl=0;
    nop5();

}


void command_write(unsigned char com1,unsigned char com2)
{
     unsigned char i;
	 s();
     i=0x34;
	 one_byte_write(i); 
     i=com1;
	 one_byte_write(i);
	 i=com2;
	 one_byte_write(i);

	 e();

}


void ini_aic23(void)
{
  unsigned char i1,i2;
   
   i1=0x1e;
   i2=0x0;                           //reset
   command_write(i1,i2);

  
  
   i1=0x12;                          //   digital activity 
   i2=0x1;
   command_write(i1,i2);
   
   i1=0x1;                          // left line 
   i2=0x10;
   command_write(i1,i2);

   i1=0x3;                          // right line
   i2=0x10;
   command_write(i1,i2);

   i1=0x5;                         // left out
   i2=0x7f;
   command_write(i1,i2);


   i1=0x7;                         // right out
   i2=0x7f;
   command_write(i1,i2);

   i1=0x8;                        //  analoge control
   i2=0x3c;
   command_write(i1,i2);

   i1=0xa;                       //  digital control
   i2=0x0;
   command_write(i1,i2);

   i1=0xc;                       //  power down
   i2=0x0;
   command_write(i1,i2);

   i1=0xe;                       //  digital format
   i2=0x43;
   command_write(i1,i2);

   i1=0x10;                       //  sample rate
   i2=0x0;
   command_write(i1,i2);


}



void nop5(void)
{
  int i;
  i=i;
  i=i;
}	


⌨️ 快捷键说明

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