📄 main.c
字号:
/****************************************Copyright (c)**************************************************
** 思 蜕 盟 豆 皮 开 发 小 组
** stmfans 论坛
**
** QQ 群: 65081316 StmFans思蜕盟 1组
** QQ 群: 68584951 StmFans思蜕盟 2组
** http://www.stmfans.com/bbs/
**
** This program was produced by the
** IAR Embedded Workbench 5.0 Kickstart 520
** Copyright 2008-2009 stmfans
** Chip type : STM32F103VB
** Program type : Application
** Clock frequency : 8.000000 MHz
** Memory model :
** External SRAM size :
** Data Stack size :
**--------------文件信息--------------------------------------------------------------------------------
**文 件 名: Main.c
**创 建 人: 陈海
**最后修改日期: 2008年10月23日
**描 述: 豆皮开发板教程
**
**--------------历史版本信息----------------------------------------------------------------------------
** 创建人: 陈海
** 版 本: v0.01
** 日 期: 2008年10月23日
** 描 述: 原始版本
**
**--------------当前版本信息----------------------------------------------------------------------------
** 创建人: 陈海
** 版 本: v0.01
** 日 期: 2008年10月23日
** 描 述: 当前版本
**
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
//计算代码运行耗费时间的计数器
vu32 ClickCounter;
static u8 filebuf[641];
/*******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif
//配置系统时钟
RCC_Configuration();
//配置 NVIC 和 Vector Table
NVIC_Configuration();
//配置LED使用的GPIO口
LED_GPIO_Configuration();
GPIO_SetBits(GPIOB, GPIO_Pin_15) ;
//配置KEY使用的GPIO口
//KEY_GPIO_Configuration();
//配置buzzer蜂鸣器使用的端口
//BUZZER_GPIO_Configuration();
SysTick_Config();
TFT_Init();
u8 drewflag=0;
if( 0 == SD_MMC_SPI_Init() )
{
// Lcd_Show_String Lcd_Show_String(0, 20, "sd mmc eror", YELLOW, YELLOW, 0);
drewflag=1;
}
Delay_Ms(10);
// open first partition
struct partition_struct* partition = partition_open(sd_raw_read,
sd_raw_read_interval,
sd_raw_write,
sd_raw_write_interval,
0
);
if(!partition)
{
Lcd_Show_String(0, 36, "partition eror", YELLOW, YELLOW, 0);
drewflag=1;
}
// open file system
struct fat16_fs_struct* fs = fat16_open(partition);
if(!fs)
{
Lcd_Show_String(0, 52, "file sysytem eror", YELLOW, YELLOW, 0);
drewflag=1;
}
// open root directory
struct fat16_dir_entry_struct directory;
fat16_get_dir_entry_of_path(fs, "/", &directory);
struct fat16_dir_struct* dd = fat16_open_dir(fs, &directory);
if(!dd)
{
Lcd_Show_String(0, 68, "root eror", YELLOW, YELLOW, 0);
drewflag=1;
}
struct fat16_file_struct* fd = open_file_in_dir(fs, dd, "ABCD.BMP");
if(!fd)
{
Lcd_Show_String(0, 84, "abcd.bmp eror", YELLOW, YELLOW, 0);
drewflag=1;
}
s32 fileseek = 0x46;
fat16_seek_file(fd, &fileseek, FAT16_SEEK_SET);
filebuf[640] = 0;
//ClickCounter=0;
//SysTick_CounterCmd(SysTick_Counter_Enable);
if(!drewflag)
{
//GPIO_ResetBits(GPIOB, GPIO_Pin_15);
for(u8 i=0;i<240;i++)
{
fat16_read_file(fd, filebuf, sizeof(filebuf)-1);
Lcd_Show_Bmp565(0, 239-i,320, 1, filebuf);
}
}
//SysTick_CounterCmd(SysTick_Counter_Disable);
//SysTick_CounterCmd(SysTick_Counter_Clear);
//ClickCounter=0;
fat16_close_file(fd);
fat16_close_dir(dd);
fat16_close(fs);
//延迟用于调试
//Delay_Ms(8000);
//主循环
while (1)
{
}
}
/*******************************************************************************
* Function Name : RCC_Configuration
* Description : Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
//将外设 RCC寄存器重设为缺省值
RCC_DeInit();
//设置外部高速晶振(HSE)
RCC_HSEConfig(RCC_HSE_ON);
//等待 HSE 起振
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
//预取指缓存使能
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
//设置代码延时值
//FLASH_Latency_2 2 延时周期
FLASH_SetLatency(FLASH_Latency_2);
//设置 AHB 时钟(HCLK)
//RCC_SYSCLK_Div1 AHB 时钟 = 系统时钟
RCC_HCLKConfig(RCC_SYSCLK_Div1);
//设置高速 AHB 时钟(PCLK2)
RCC_PCLK2Config(RCC_HCLK_Div1);
//设置低速 AHB 时钟(PCLK1)
RCC_PCLK1Config(RCC_HCLK_Div2);
/* ADCCLK = PCLK2/4 */
RCC_ADCCLKConfig(RCC_PCLK2_Div4);
// PLLCLK = 8MHz * 9 = 72 MHz
//设置 PLL 时钟源及倍频系数
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
//使能或者失能 PLL
RCC_PLLCmd(ENABLE);
//等待指定的 RCC 标志位设置成功 等待PLL初始化成功
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
//设置系统时钟(SYSCLK) 设置PLL为系统时钟源
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
//等待PLL成功用作于系统时钟的时钟源
// 0x00:HSI 作为系统时钟
// 0x04:HSE作为系统时钟
// 0x08:PLL作为系统时钟
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
}
void LED_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIO clocks */
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB , ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB , &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures NVIC and Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
//NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
}
#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 + -