#include "stm32f10x_lib.h"
#include "I2C_EE.h"
/* Private typedef -----------------------------------------------------------*/
typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus; //定义枚举变量TestStatus;
/* Private define ------------------------------------------------------------*/
#define countof(a) (sizeof(a) / sizeof(*(a)))
#define EEPROM_WriteAddress1 0x5
#define EEPROM_ReadAddress1 0x5
#define BufferSize1 (countof(Tx1_Buffer)-1)
#define BufferSize2 (countof(Tx2_Buffer)-1)
#define EEPROM_WriteAddress2 (EEPROM_WriteAddress1 + BufferSize1)
#define EEPROM_ReadAddress2 (EEPROM_ReadAddress1 + BufferSize1)
/* Private macro -------------------------------------------------------------*/
u8 Tx1_Buffer[] = "STM32F10x I2C Firmware ";
u8 Tx2_Buffer[] = "Library Example */";
u8 Rx_Buffer[BufferSize1 + BufferSize2], Rx1_Buffer[BufferSize1],
Rx2_Buffer[BufferSize2];
volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED;
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void Delay_Ms(u16 time);
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
TestStatus Buffercmp(u8* pBuffer1, u8* pBuffer2, u16 BufferLength);
extern void lcd_init (void);
extern void lcd_clear (void);
extern void lcd_putchar (char c);
extern void set_cursor (int column, int line);
extern void lcd_print (char *string);
extern void lcd_bargraph (int pos_x, int pos_y, int value); // STM32 Initialization
/* Private functions ---------------------------------------------------------*/
/******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Output : None
* Return : None
******************************************************************************* /
int main(void)
{
#ifdef DEBUG
debug();
#endif
u8 key1,key2;
u8 buf,lcd[5];
/* System Clocks Configuration */
RCC_Configuration();
/* NVIC configuration */
NVIC_Configuration();
/* Configure the GPIOs */
GPIO_Configuration();
/* Initialize the I2C EEPROM driver ----------------------------------------*/
I2C_EE_Init();
I2C_EE_BufferRead(Rx1_Buffer, EEPROM_ReadAddress1, BufferSize1);
lcd_init();
lcd_clear();
lcd_print_S("STM32_I2C !");
Delay_Ms(10);
while (1)
{
key1 = GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_8);
if(key1==0)
{
GPIO_SetBits(GPIOB,GPIO_Pin_10);
//IIC1_SCL=1;
GPIO_SetBits(GPIOF,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10);
// I2C_EE_BufferWrite(Tx1_Buffer, EEPROM_WriteAddress1, BufferSize1);
GPIO_SetBits(GPIOB,GPIO_Pin_11);
//IIC1_SDA=1;
while(key1==0)
// 按键释放;
{
key1 = GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_8);
}
}
key2 = GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0);
if(key2==0)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_10);
//IIC2_SCL=1
//IIC2_SDA=1;
GPIO_ResetBits(GPIOB,GPIO_Pin_11);
while(key2==0)
// 按键释放;
{
key2 = GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0);
}
}
set_cursor(0, 1);
lcd_print_S(Rx1_Buffer);
Delay_Ms(50);
}
}
/****************************************************************************** *
* 函数名: Delay_Ms(u16 time
* 功能: 延时配置
* 输入: 无
* 输出: 无
* 返回: 无
*******************************************************************************
/
void Delay_Ms(u16 time)
{
u16 i,j;
for(i=0;i