📄 main.c
字号:
#include "main.h"
/* Private define ------------------------------------------------------------*/
#define EEPROM_WriteAddress1 0x00
#define EEPROM_ReadAddress1 0x00
#define BufferSize1 (countof(Tx1_Buffer)-1)
/* Private macro -------------------------------------------------------------*/
#define countof(a) (sizeof(a) / sizeof(*(a)))
/* Private variables ---------------------------------------------------------*/
u8 Tx1_Buffer[] = "123456789abcdef";
u8 Rx1_Buffer[BufferSize1] = "";
/* Private variables ---------------------------------------------------------*/
static volatile ErrorStatus HSEStartUpStatus = SUCCESS;
static vu32 SELStatus = 0;
static vu32 TimingDelay = 0;
static vu32 I2C_Delay = 0;
volatile bool I2C_Time_out;
extern void SetupUSART(void);
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif
RCC_Configuration();
InterruptConfig();
SysTick_Config();
SetupUSART();
STM3210E_LCD_Init();
I2C_GPIO_Config();
LCD_Clear(White);
LCD_SetBackColor(White);
LCD_SetTextColor(Blue);
LCD_DisplayStringLine(Line0,"ceshi 24c02");
printf("I2C CESHI\t\t\n");
//I2C_WriteByte(Tx1_Buffer[1], 0x0000, 0xa0)
I2C_PageWrite(Tx1_Buffer,BufferSize1,EEPROM_WriteAddress1,0xa0);
Systick_Delay_1ms(10);
I2C_ReadByte(Rx1_Buffer,BufferSize1,0x00 ,0xa0);
printf(" Rx1_Buffer is:%s,\t the BufferSize1 is%d\n",Rx1_Buffer,BufferSize1);
while(1)
{
}
}
/*******************************************************************************
* Function Name : RCC_Configuration
* Description : Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RCC_Configuration(void)
{
/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* PLLCLK = 8MHz * 9 = 72 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
/* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG | RCC_APB2Periph_AFIO , ENABLE);
}
/*******************************************************************************
* Function Name : InterruptConfig
* Description : Configures the used IRQ Channels and sets their priority.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void InterruptConfig(void)
{
/* Deinitializes the NVIC */
NVIC_DeInit();
/* Set the Vector Table base address at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x00);
/* Configure the Priority Group to 2 bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* Configure the SysTick handler priority */
NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 0, 0);
}
/*******************************************************************************
* Function Name : SysTick_Config
* Description : Configure a SysTick Base time to 10 ms.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void SysTick_Config(void)
{
/* Configure HCLK clock as SysTick clock source */
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
/* SysTick interrupt each 1000 Hz with HCLK equal to 72MHz */
SysTick_SetReload(72000);
/* Enable the SysTick Interrupt */
SysTick_ITConfig(ENABLE);
/* Enable the SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Enable);
}
void systick_isr(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
if (I2C_Delay != 0x00)
{
I2C_Delay--;
}
else
{
I2C_Time_out = TRUE;
}
}
/*******************************************************************************
* Function Name : Delay
* Description : Inserts a delay time.
* Input : nCount: specifies the delay time length (time base 1 ms).
* Output : None
* Return : None
*******************************************************************************/
void Systick_Delay_1ms(u32 nCount)
{
TimingDelay = nCount;
while(TimingDelay != 0)
{}
}
void I2C_Delay_Out(u32 nCount)
{
I2C_Delay = nCount;
I2C_Time_out = FALSE;
}
#ifdef DEBUG
/*******************************************************************************
* Function Name : assert_failed
* Description: : Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* Input : - file: pointer to the source file name
* - line: assert_param error line source number
* Output : None
* Return : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -