欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: STM8S的I2C讀寫AT24C02源程序,實際可用 [打印本頁]

作者: 精選生活    時間: 2018-1-4 22:34
標題: STM8S的I2C讀寫AT24C02源程序,實際可用
實際可用。


單片機源程序如下:

  1. /******************** (C) COPYRIGHT  風馳電子嵌入式開發工作室 ********************
  2. * 文件名  :main.c
  3. * 描述    :I2C EPPROM 的讀寫     
  4. * 實驗平臺:風馳電子STM8開發板
  5. * 庫版本  :V2.0.0
  6. * 作者    :ling_guansheng   
  7. **********************************************************************************/

  8. /* Includes ------------------------------------------------------------------*/
  9. /* Includes ------------------------------------------------------------------*/
  10. #include "stm8s.h"
  11. #include "stm8s_clk.h"
  12. #include "intrinsics.h"
  13. #include "stm8s_uart1.h"
  14. #include "uart.h"
  15. #include "i2c_ee.h"


  16. extern u8 RxBuffer[RxBufferSize];
  17. extern u8 UART_RX_NUM;
  18. u8 Tx1_Buffer[] = "Hi!STM8";
  19. /* Private variables ---------------------------------------------------------*/

  20. #define BASE_ADDRESS ((u16)0x0000)
  21. #define countof(a) (sizeof(a) / sizeof(*(a)))
  22. #define BufferSize1             (countof(Tx1_Buffer)-1)
  23. u8 Rx1_Buffer[BufferSize1];

  24. /* Private function prototypes -----------------------------------------------*/
  25. /* Private functions ---------------------------------------------------------*/
  26. void Delay(u32 nCount);

  27. int main(void)
  28. {
  29.     /* Infinite loop */
  30.   /*設置內部時鐘16M為主時鐘*/
  31.     CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
  32.   /*!<Set High speed internal clock  */
  33.     I2C_DeInit();
  34.     Uart_Init();
  35.     /* Initialize the I2C */
  36.     I2C_EEInit();
  37.     I2C_EE_PageWrite(Tx1_Buffer, BASE_ADDRESS, BufferSize1 );
  38.     Delay(2000); /* To let eeprom the time to finish the write operation */
  39.     I2C_EE_BufferRead(Rx1_Buffer, BASE_ADDRESS, BufferSize1 );
  40.     UART1_SendString("What is writed into a page of AT24C02 EEPROM:",\
  41.                      sizeof("What is writed into a page of AT24C02 EEPROM:"));
  42.     Delay(0xfff);
  43.     UART1_SendString(Tx1_Buffer,BufferSize1);
  44.     Delay(0xffff);
  45.     UART1_SendString("What is read from a page of AT24C02 EEPROM:",\
  46.            sizeof("What is read from a page of AT24C02 EEPROM:"));
  47.     Delay(0xffff);
  48.     UART1_SendString(Rx1_Buffer,BufferSize1);
  49.     Delay(0xffff);
  50.    while (1)
  51.    {

  52.       UART1_SendString("What is read from a page of AT24C02 EEPROM:",\
  53.              sizeof("What is read from a page of AT24C02 EEPROM:"));
  54.       Delay(0xffff);
  55.       UART1_SendString(Rx1_Buffer,BufferSize1);
  56.       Delay(0xffff);

  57.    }
  58. }

  59. void Delay(u32 nCount)
  60. {
  61.   /* Decrement nCount value */
  62.   while (nCount != 0)
  63.   {
  64.     nCount--;
  65.   }
  66. }



  67. #ifdef USE_FULL_ASSERT

  68. /**
  69.   * @brief  Reports the name of the source file and the source line number
  70.   *   where the assert_param error has occurred.
  71.   * @param file: pointer to the source file name
  72.   * @param line: assert_param error line source number
  73.   * @retval : None
  74.   */
  75. void assert_failed(u8* file, u32 line)
  76. ……………………

  77. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
I2C總線+AT24C02.rar (256.13 KB, 下載次數: 81)









歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1