實際可用。
0.png (9.54 KB, 下載次數: 40)
下載附件
2018-1-9 02:32 上傳
單片機源程序如下:
- /******************** (C) COPYRIGHT 風馳電子嵌入式開發工作室 ********************
- * 文件名 :main.c
- * 描述 :I2C EPPROM 的讀寫
- * 實驗平臺:風馳電子STM8開發板
- * 庫版本 :V2.0.0
- * 作者 :ling_guansheng
- **********************************************************************************/
- /* Includes ------------------------------------------------------------------*/
- /* Includes ------------------------------------------------------------------*/
- #include "stm8s.h"
- #include "stm8s_clk.h"
- #include "intrinsics.h"
- #include "stm8s_uart1.h"
- #include "uart.h"
- #include "i2c_ee.h"
- extern u8 RxBuffer[RxBufferSize];
- extern u8 UART_RX_NUM;
- u8 Tx1_Buffer[] = "Hi!STM8";
- /* Private variables ---------------------------------------------------------*/
- #define BASE_ADDRESS ((u16)0x0000)
- #define countof(a) (sizeof(a) / sizeof(*(a)))
- #define BufferSize1 (countof(Tx1_Buffer)-1)
- u8 Rx1_Buffer[BufferSize1];
- /* Private function prototypes -----------------------------------------------*/
- /* Private functions ---------------------------------------------------------*/
- void Delay(u32 nCount);
- int main(void)
- {
- /* Infinite loop */
- /*設置內部時鐘16M為主時鐘*/
- CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
- /*!<Set High speed internal clock */
- I2C_DeInit();
- Uart_Init();
- /* Initialize the I2C */
- I2C_EEInit();
- I2C_EE_PageWrite(Tx1_Buffer, BASE_ADDRESS, BufferSize1 );
- Delay(2000); /* To let eeprom the time to finish the write operation */
- I2C_EE_BufferRead(Rx1_Buffer, BASE_ADDRESS, BufferSize1 );
- UART1_SendString("What is writed into a page of AT24C02 EEPROM:",\
- sizeof("What is writed into a page of AT24C02 EEPROM:"));
- Delay(0xfff);
- UART1_SendString(Tx1_Buffer,BufferSize1);
- Delay(0xffff);
- UART1_SendString("What is read from a page of AT24C02 EEPROM:",\
- sizeof("What is read from a page of AT24C02 EEPROM:"));
- Delay(0xffff);
- UART1_SendString(Rx1_Buffer,BufferSize1);
- Delay(0xffff);
- while (1)
- {
- UART1_SendString("What is read from a page of AT24C02 EEPROM:",\
- sizeof("What is read from a page of AT24C02 EEPROM:"));
- Delay(0xffff);
- UART1_SendString(Rx1_Buffer,BufferSize1);
- Delay(0xffff);
- }
- }
- void Delay(u32 nCount)
- {
- /* Decrement nCount value */
- while (nCount != 0)
- {
- nCount--;
- }
- }
- #ifdef USE_FULL_ASSERT
- /**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval : None
- */
- void assert_failed(u8* file, u32 line)
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
I2C總線+AT24C02.rar
(256.13 KB, 下載次數: 81)
2018-1-4 22:33 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|