《電子技術應用》
您所在的位置:首頁 > 嵌入式技術 > 解決方案 > 24C64子程序

24C64子程序

2009-01-16
關鍵詞: 源代碼 單片機

24C64子程序

/*24C64子程序 */
bit   I2C_Start(void);
void  I2C_Stop(void);
void  I2C_Ack(void);
void  I2C_Nack(void);
bit   I2C_Send_Byte( uchar);
uchar I2C_Receive_Byte(void);
void  AT24C64_R(void *mcu_address,uint AT24C64_address,uint count);
void  AT24C64_W(void *mcu_address,uint AT24C64_address,uint count);
void  Delay_10_uS(void)
{
 char i=10;
 while(i--);
}
void Delay_N_mS( uint n_milisecond)  /* n mS delay */
{
 uchar i;
 while(n_milisecond--)
 {
  i=37;
  while(i--);
 }
}
bit I2C_Start(void)
{
 Delay_10_uS();
 I2C_SDA =1;
 Delay_10_uS();
 I2C_SCK =1;
 Delay_10_uS();
 if ( I2C_SDA == 0) return 0;
 if ( I2C_SCK == 0) return 0;
 I2C_SDA = 0;
 Delay_10_uS();
 I2C_SCK = 0;
 Delay_10_uS();
 return 1;
}
void  I2C_Stop(void)
{
 Delay_10_uS();
 I2C_SDA = 0;
 Delay_10_uS();
 I2C_SCK = 1;
 Delay_10_uS();
 I2C_SDA = 1;
 Delay_10_uS();
}
void I2C_Ack(void)
{
 Delay_10_uS();
 I2C_SDA=0;
 Delay_10_uS();
 I2C_SCK=1;
 Delay_10_uS();
 I2C_SCK=0;
 Delay_10_uS();
}
void I2C_Nack(void)
{
 Delay_10_uS();
 I2C_SDA=1;
 Delay_10_uS();
 I2C_SCK=1;
 Delay_10_uS();
 I2C_SCK=0;
 Delay_10_uS();
}
bit I2C_Send_Byte( uchar d)
{
 uchar i = 8;
 bit bit_ack;
 while( i-- )
 {
  Delay_10_uS();
  if ( d &0x80 )   I2C_SDA =1;
  else             I2C_SDA =0;
  Delay_10_uS();
  I2C_SCK = 1;
  Delay_10_uS();
  I2C_SCK = 0;
  d = d << 1;
 }
 Delay_10_uS();
 I2C_SDA = 1;
 Delay_10_uS();
 I2C_SCK = 1;
 Delay_10_uS();
 bit_ack = I2C_SDA;
 I2C_SCK =0;
 Delay_10_uS();
 return bit_ack;
}
uchar I2C_Receive_Byte(void)
{
 uchar i = 8, d;
 Delay_10_uS();
 I2C_SDA = 1;
 while ( i--)
 {
  d = d << 1;
  Delay_10_uS();
  I2C_SCK =1;
  if ( I2C_SDA ) d++;
  Delay_10_uS();
  I2C_SCK =0;
 }
 return d;
}
void AT24C64_W(void *mcu_address,uint AT24C64_address,uint count)
{
 DOG_WDI=!DOG_WDI;
 DOGTIME=0;
 while(count--)
 {
  I2C_Start();
  /*I2C_Send_Byte( 0xa0 + AT24C64_address /256 *2);*/  /* 24C16  USE */
  I2C_Send_Byte( 0xa0 );
  I2C_Send_Byte(  AT24C64_address/256 );
  I2C_Send_Byte( AT24C64_address %256 );
  I2C_Send_Byte( *(uchar*)mcu_address );
  I2C_Stop();
  Delay_N_mS(10);       /* waiting for write cycle to be completed */
  ((uchar*)mcu_address)++;
  AT24C64_address++;
 }
}
void AT24C64_R(void *mcu_address,uint AT24C64_address,uint count)
{
 DOG_WDI=!DOG_WDI;
 DOGTIME=0;
 while(count--)
 {
  I2C_Start();
  /*I2C_Send_Byte( 0xa0 + AT24C64_address / 256 *2 );*/   /* 24C16 USE */
  I2C_Send_Byte( 0xa0 );
  I2C_Send_Byte( AT24C64_address/256 );
  I2C_Send_Byte( AT24C64_address % 256 );
  I2C_Start();
  /*I2C_Send_Byte( 0xa1 + AT24C64_address /256 *2 );*/
  I2C_Send_Byte( 0xa1 );
  *(uchar*)mcu_address = I2C_Receive_Byte();
  I2C_Nack();
  I2C_Stop();
  ((uchar*)mcu_address)++;
  AT24C64_address++;
 }
}

24c32/24c64中文資料

本站內容除特別聲明的原創文章之外,轉載內容只為傳遞更多信息,并不代表本網站贊同其觀點。轉載的所有的文章、圖片、音/視頻文件等資料的版權歸版權所有權人所有。本站采用的非本站原創文章及圖片等內容無法一一聯系確認版權者。如涉及作品內容、版權和其它問題,請及時通過電子郵件或電話通知我們,以便迅速采取適當措施,避免給雙方造成不必要的經濟損失。聯系電話:010-82306118;郵箱:aet@chinaaet.com。
主站蜘蛛池模板: 久久精品女人毛片国产| 女人18毛片a级毛片免费视频| 国产一区二区三区免费视频| 三级视频中文字幕| 男女性杂交内射女BBWXZ| 在线观看黄日本高清视频| 久久精品久久久| 波多野结衣乱码中文字幕| 国产一国产a一级毛片| japanese性暴力| 日本欧美特黄特色大片| 亚洲欧洲中文日产| 麻豆国产尤物AV尤物在线观看| 夜色资源网站www| 中文字幕在线免费观看| 欧美69式视频在线播放试看| 国产a三级久久精品| 青青操免费在线视频| 无码精品一区二区三区免费视频| 亚洲宅男精品一区在线观看| 精品乱人伦一区二区三区| 国产嘿嘿嘿视频在线观看| 8av国产精品爽爽ⅴa在线观看 | 模特侨依琳大尺度流出| 国产a级特黄的片子视频| k频道国产欧美日韩精品| 无人高清视频免费观看在线动漫| 亚洲久热无码av中文字幕| 狠狠色综合久久婷婷| 国产成人综合精品| 一级一毛片a级毛片| 欧美孕交videosfree黑| 国产99久久九九精品无码| 久碰人澡人澡人澡人澡人视频| 小猪视频免费网| 亚洲一区电影在线观看| 老汉色av影院| 国产成人精品久久免费动漫| 69日本xxxxxxxxx19| 大象视频在线免费观看| 中文字幕影片免费在线观看|