标题:
STM8S的I2C读写AT24C02源程序,实际可用
[打印本页]
作者:
精选生活
时间:
2018-1-4 22:34
标题:
STM8S的I2C读写AT24C02源程序,实际可用
实际可用。
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
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1