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

📄 main.c

📁 三星S3C44B0X的I2C总线功能模块测试
💻 C
字号:
 #include "44b0.h"
  void ini_io(void);
  void ini_IIC(void);
  void ini_memory(void);
  void ini_pllclock(void); //函数声明
  
//***************************************************
  void ini_io()
  {
   rPCONF=0x0a;//PF0,PF1配置为IIC bus的时钟和数据
   rPUPF=0x03;//禁止内部上拉
   rPCONC=0x54;
   }
//****************************************************
  void ini_memory()//存储体配置
  {
   rBWSCON=0x11001100;
   rBANKCON6=0x18000;
   rBANKCON7=0x18000;
   rREFRESH=(8<<20)+(4<<16)+1049;
   rBANKCON0=0x7ff0;
   rBANKCON1=0x7ff0;
   rBANKCON2=0x7ff0;
   rBANKCON3=0x7ff0;
   rBANKCON4=0x7ff0;
   rBANKCON5=0x7ff0;
   
    }
//*****************************************************
   
  void ini_pllclock()//时钟设置
  {
    rLOCKTIME=0xfff;//默认值
    rPLLCON=(88<<12)|(4<<4)|2;
    rCLKCON=0x7ff8;//Fout=40MHZ
  }
//*****************************************************
  void ini_IIC()
  {
    rIICCON=0xaf;//IIC bus时钟速率为156250Hz,禁止中断
  }
//******************************************************
  int main()
  {
   unsigned table[16];
   unsigned int i=100000;
   char buffer;
   ini_memory();
   ini_pllclock();
   ini_io();
   ini_IIC();
   rINTMSK=0x7ffffff;//屏蔽所有中断
//*****************AT24C08字节写8个字节*******************
   rIICDS=0xa0;
   rIICSTAT=0xf0;//产生起始位并发送从机地址
   while((rIICCON&0x10)==0);
   rIICDS=0x10;//准备向地址为0x10的单元写入数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x0c;//写入数据0x0c
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICSTAT=0xd0;//产生停止位
   rIICCON=0xaf;
   while(i--);
   i=100000;
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;//产生起始位并发送从机地址
   while((rIICCON&0x10)==0);
   rIICDS=0x11;//准备向地址为0x11的单元写入数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x02;//写入数据0x02
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICSTAT=0xd0;//产生停止位
   rIICCON=0xaf;
   while(i--);
   i=100000;
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;//产生起始位并发送从机地址
   while((rIICCON&0x10)==0);
   rIICDS=0x12;//准备向地址为0x12的单元写入数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x04;//写入数据0x04
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICSTAT=0xd0;//产生停止位
   rIICCON=0xaf;
   while(i--);
   i=100000;
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;//产生起始位并发送从机地址
   while((rIICCON&0x10)==0);
   rIICDS=0x13;//准备向地址为0x13的单元写入数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x06;//写入数据0x06
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICSTAT=0xd0;//产生停止位
   rIICCON=0xaf;
   while(i--);
   i=100000;
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;//产生起始位并发送从机地址
   while((rIICCON&0x10)==0);
   rIICDS=0x14;//准备向地址为0x14的单元写入数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x08;//写入数据0x08
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICSTAT=0xd0;//产生停止位
   rIICCON=0xaf;
   while(i--);
   i=100000;
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;//产生起始位并发送从机地址
   while((rIICCON&0x10)==0);
   rIICDS=0x15;//准备向地址为0x15的单元写入数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x0a;//写入数据0x0a
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICSTAT=0xd0;//产生停止位
   rIICCON=0xaf;
   while(i--);
   i=100000;
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;//产生起始位并发送从机地址
   while((rIICCON&0x10)==0);
   rIICDS=0x16;//准备向地址为0x16的单元写入数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x0c;//写入数据0x0c
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICSTAT=0xd0;//产生停止位
   rIICCON=0xaf;
   while(i--);
   i=100000;
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;//产生起始位并发送从机地址
   while((rIICCON&0x10)==0);
   rIICDS=0x17;//准备向地址为0x17的单元写入数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x0e;//写入数据0x0e
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICSTAT=0xd0;//产生停止位
   rIICCON=0xaf;
   while(i--);
  
//******************AT24C08随机读8个字节操作****************
  
   rIICDS=0xa0;
   rIICSTAT=0xf0;
   while((rIICCON&0x10)==0);
   rIICDS=0x10;//读地址0x10的数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICCON=0xaf;
   rIICDS=0xa1;
   rIICSTAT=0xb0;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICCON=0x2f;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICSTAT=0x90;
   rIICCON=0xaf;
   i=100000;
   while(i--);
   rPDATC=buffer;
   i=10000000;
   while(i--);
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;
   while((rIICCON&0x10)==0);
   rIICDS=0x11;//读地址0x11的数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICCON=0xaf;
   rIICDS=0xa1;
   rIICSTAT=0xb0;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICCON=0x2f;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICSTAT=0x90;
   rIICCON=0xaf;
   i=100000;
   while(i--);
   rPDATC=buffer;
   i=10000000;
   while(i--);
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;
   while((rIICCON&0x10)==0);
   rIICDS=0x12;//读地址0x12的数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICCON=0xaf;
   rIICDS=0xa1;
   rIICSTAT=0xb0;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICCON=0x2f;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICSTAT=0x90;
   rIICCON=0xaf;
   i=100000;
   while(i--);
   rPDATC=buffer;
   i=10000000;
   while(i--);
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;
   while((rIICCON&0x10)==0);
   rIICDS=0x13;//读地址0x13的数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICCON=0xaf;
   rIICDS=0xa1;
   rIICSTAT=0xb0;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICCON=0x2f;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICSTAT=0x90;
   rIICCON=0xaf;
   i=100000;
   while(i--);
   rPDATC=buffer;
   i=10000000;
   while(i--);
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;
   while((rIICCON&0x10)==0);
   rIICDS=0x14;//读地址0x14的数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICCON=0xaf;
   rIICDS=0xa1;
   rIICSTAT=0xb0;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICCON=0x2f;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICSTAT=0x90;
   rIICCON=0xaf;
   i=100000;
   while(i--);
   rPDATC=buffer;
   i=10000000;
   while(i--);
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;
   while((rIICCON&0x10)==0);
   rIICDS=0x15;//读地址0x15的数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICCON=0xaf;
   rIICDS=0xa1;
   rIICSTAT=0xb0;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICCON=0x2f;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICSTAT=0x90;
   rIICCON=0xaf;
   i=100000;
   while(i--);
   rPDATC=buffer;
   i=10000000;
   while(i--)
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;
   while((rIICCON&0x10)==0);
   rIICDS=0x16;//读地址0x16的数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICCON=0xaf;
   rIICDS=0xa1;
   rIICSTAT=0xb0;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICCON=0x2f;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICSTAT=0x90;
   rIICCON=0xaf;
   i=100000;
   while(i--);
   rPDATC=buffer;
   i=10000000;
   while(i--);
   
   rIICDS=0xa0;
   rIICSTAT=0xf0;
   while((rIICCON&0x10)==0);
   rIICDS=0x17;//读地址0x17的数据
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICCON=0xaf;
   rIICDS=0xa1;
   rIICSTAT=0xb0;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICCON=0x2f;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICSTAT=0x90;
   rIICCON=0xaf;
   i=100000;
   while(i--);
   rPDATC=buffer;
   i=10000000;
   while(i--); 
//*********************页写方式从地址0x1c0开始写入16个字节***************************
   rIICCON=0xaf;//恢复应答使能并清中断标志位
   rIICDS=0xa2;
   rIICSTAT=0xf0;//产生起始位并发送从机地址
   while((rIICCON&0x10)==0);
   rIICDS=0xc0;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x0c;//向地址为0x1c0的单元写入数据0x0c
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x0e;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x0a;
   rIICCON=0xa9;
   while((rIICCON&0x10)==0);
   rIICDS=0x08;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x06;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x04;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x02;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x0c;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x0e;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x06;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x0a;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x08;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x02;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x04;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x0c;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICDS=0x0e;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICSTAT=0xd0;//产生停止位
   rIICCON=0xaf;
   i=1000000;
   while(i--);
//*****************顺序读出页方式写入的16个字节***************
   rIICDS=0xa2;
   rIICSTAT=0xf0;
   while((rIICCON&0x10)==0);
   rIICDS=0xc0;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   rIICCON=0xaf;
   rIICDS=0xa3;
   rIICSTAT=0xb0;
   while((rIICCON&0x10)==0);
   buffer=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[0]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[1]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[2]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[3]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[4]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[5]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[6]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[7]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[8]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[9]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[10]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[11]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[12]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[13]=rIICDS;
   rIICCON=0xaf;
   while((rIICCON&0x10)==0);
   table[14]=rIICDS;
   rIICCON=0x2f;
   while((rIICCON&0x10)==0);
   table[15]=rIICDS;
   rIICSTAT=0x90;
   rIICCON=0xaf;
   i=100000;
   while(i--);
//***********显示页写入的数据****************
   while(1)
   {
   rPDATC=table[0];
   i=10000000;
   while(i--);
   rPDATC=table[1];
   i=10000000;
   while(i--);
   rPDATC=table[2];
   i=10000000;
   while(i--);
   rPDATC=table[3];
   i=10000000; 
   while(i--);
   rPDATC=table[4];
   i=10000000;
   while(i--);
   rPDATC=table[5];
   i=10000000;
   while(i--);
   rPDATC=table[6];
   i=10000000;
   while(i--);
   rPDATC=table[7];
   i=10000000;
   while(i--);
   rPDATC=table[8];
   i=10000000;
   while(i--);
   rPDATC=table[9];
   i=10000000;
   while(i--);
   rPDATC=table[10];
   i=10000000;
   while(i--);
   rPDATC=table[11];
   i=10000000;
   while(i--);
   rPDATC=table[12];
   i=10000000;
   while(i--);
   rPDATC=table[13];
   i=10000000;
   while(i--);
   rPDATC=table[14];
   i=10000000;
   while(i--);
   rPDATC=table[15];
   i=10000000;
   while(i--);
    }
     
     }
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   

⌨️ 快捷键说明

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