📄 main.c
字号:
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name : main.c
* Author : MCD Application Team
* Version : V2.0
* Date : 05/23/2008
* DescriptWHY8W-QT9DJ-P0VNX-L15PE-W4DCR-VP3FMion : Main program body
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
* FOR MORE INFORMATION PLEASE CAREFULLY READ THE LICENSE AGREEMENT FILE LOCATED
* IN THE ROOT DIRECTORY OF THIS FIRMWARE PACKAGE.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"
#include "ILI9325.c"
#include "SD_driver.c"
#include "Config.h"
#include<stdio.h>
#define RED 0xf800
#define GREEN 0x07e0
#define BLUE 0x001f
#define WHITE 0xffff
#define BLACK 0x0000
#define YELLOW 0xFFE0
void test(void);
typedef struct
{
u8 pic_head[2]; //1
u16 pic_size_l; //2
u16 pic_size_h; //3
u16 pic_nc1; //4
u16 pic_nc2; //5
u16 pic_data_address_l; //6
u16 pic_data_address_h; //7
u16 pic_message_head_len_l; //8
u16 pic_message_head_len_h; //9
u16 pic_w_l; //10
u16 pic_w_h; //11
u16 pic_h_l; //12
u16 pic_h_h; //13
u16 pic_bit; //14
u16 pic_dip; //15
u16 pic_zip_l; //16
u16 pic_zip_h; //17
u16 pic_data_size_l; //18
u16 pic_data_size_h; //19
u16 pic_dipx_l; //20
u16 pic_dipx_h; //21
u16 pic_dipy_l; //22
u16 pic_dipy_h; //23
u16 pic_color_index_l; //24
u16 pic_color_index_h; //25
u16 pic_other_l; //26
u16 pic_other_h; //27
u16 pic_color_p01; //28
u16 pic_color_p02; //29
u16 pic_color_p03; //30
u16 pic_color_p04; //31
u16 pic_color_p05; //32
u16 pic_color_p06; //33
u16 pic_color_p07; //34
u16 pic_color_p08; //35
}BMP_HEAD;
BMP_HEAD bmp;
typedef struct
{
u16 x;
u16 y;
u8 r;
u8 g;
u8 b;
}BMP_POINT;
BMP_POINT point;
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
long i;
u32 y;
u16 q;
FATFS fs; // Work area (file system object) for logical drive
FIL fsrc, fdst; // file objects
char buffer[1024]; // file copy buffer
FRESULT res; // FatFs function common result code
UINT br, bw; // File R/W count
u32 tx,ty,r_data,g_data,b_data;
FIL file;
char data[512];
ErrorStatus HSEStartUpStatus;
void RCC_Configuration(void);
void NVIC_Configuration(void);
void KEY_GPIO_Configuration(void);
void Delay(u32 nTime);
void SysTick_Configuration(void);
extern vu32 TimingDelay;
int main(void)
{
#ifdef DEBUG
debug();
#endif
/* Configure the system clocks */
RCC_Configuration();
/* NVIC Configuration */
NVIC_Configuration();
SysTick_Configuration();
/* Enable GPIOC clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_USART1, ENABLE);
/* Configure USARTx_Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USARTx_Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
KEY_GPIO_Configuration();
/* Infinite loop */
SPI_Configuration();
Lcd_Configuration();
Lcd_Initialize();
SD_Init();
// test_color();
test();
}
#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****/
/*******************************************************************************
* Function Name : RCC_Configuration
* Description : Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RCC_Configuration(void)
{
/* 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)
{
}
}
}
void KEY_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_8 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
#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
}
void SysTick_Configuration(void)
{
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick,3,0);
SysTick_SetReload(72000);
SysTick_ITConfig(ENABLE);
}
/*******************************************************************************
* Function Name : Delay
* Description : Inserts a delay time.
* Input : nCount: specifies the delay time length.
* Output : None
* Return : None
*******************************************************************************/
int fputc(int ch,FILE *f)
{
/* Write a character to the USART */
USART_SendData(USART1, (u8) ch);
/* Loop until the end of transmission */
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
{
}
return ch;
}
void Delay(u32 nTime)
{
SysTick_CounterCmd(SysTick_Counter_Enable);
TimingDelay=nTime;
while(TimingDelay!=0);
SysTick_CounterCmd(SysTick_Counter_Disable);
SysTick_CounterCmd(SysTick_Counter_Clear);
}
//24位。。变成16位图
u32 RGB888ToRGB565(u8 r,u8 g,u8 b)
{return (u32) (r & 0xF8) << 8 | (g & 0xFC) << 3 | (b & 0xF8) >> 3;} //565
//能显示320 240 。。240 320 的图片稍加修改就可以了
void test(void)
{
u8 scan_bit1; //单个按键扫描变量
u8 scan_bit2; //单个按键扫描变量
char aa[10];
int jj=1;
f_mount(0, &fs);
while(1){
scan_bit1 = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3);
scan_bit2 = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8);
if(scan_bit1==0) jj++;
if(scan_bit2==0) jj--;
jj++;
if(jj<1) jj=13;
if(jj>13) jj=1;
Delay(3000);
if(jj<10)
{
aa[0]=jj+'0';
aa[1]='.';
aa[2]='B';
aa[3]='M';
aa[4]='P';
aa[5]='\0';
}
else
{
aa[0]=jj/10+'0';
aa[1]=jj%10+'0';
aa[2]='.';
aa[3]='B';
aa[4]='M';
aa[5]='P';
aa[6]='\0';
}
res = f_open(&fsrc, aa, FA_OPEN_EXISTING | FA_READ); //打上图片文件名
res = f_read(&fsrc, &bmp, sizeof(bmp), &br);
if((bmp.pic_head[0]=='B')&&(bmp.pic_head[1]=='M'))
{
res = f_lseek(&fsrc, ((bmp.pic_data_address_h<<16)|bmp.pic_data_address_l));
for(tx=0;tx<bmp.pic_h_l;tx++){
f_read(&fsrc, buffer, (bmp.pic_w_l)*3, &br);
for(ty=0;ty<bmp.pic_w_l;ty++){
r_data = *(ty*3 +2+buffer);
g_data = *(ty*3 +1+buffer);
b_data = *(ty*3 +0+buffer);
if(tx<320){
point.x = tx;
point.y = ty;
point.r = r_data;
point.g = g_data;
point.b = b_data;
//如果用提供资料上的屏驱动。DrawPixel函数里面的X Y是u8 .要改成u16
DrawPixel(point.x ,point.y,RGB888ToRGB565(point.r,point.g,point.b));
}
}
}
f_close(&fsrc);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -