stm32f407在lcd上显示电脑图片程序
时间: 2023-06-25 11:05:53 浏览: 57
要在STM32F407微控制器上显示电脑图片,需要连接LCD显示器,并使用相应的图形库进行编程。以下是一个简单的程序,可以将电脑图片显示在LCD上:
```c
#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_fsmc.h"
#include "stm32f4xx_dma.h"
#include "stm32f4xx_dcmi.h"
#include "stm32f4xx_syscfg.h"
#include "stm32f4xx_exti.h"
#include "stdio.h"
#define LCD_FRAME_BUFFER ((uint32_t)0x60000000)
void GPIO_Configuration(void);
void FSMC_Configuration(void);
void DCMI_Configuration(void);
void DMA_Configuration(void);
int main(void)
{
GPIO_Configuration();
FSMC_Configuration();
DCMI_Configuration();
DMA_Configuration();
while(1);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC, ENABLE);
//DCMI GPIO Configuration
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource13, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource14, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource15, GPIO_AF_DCMI);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource2, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_DCMI);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_DCMI);
//FSMC GPIO Configuration
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource0, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource1, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource2, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource3, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource4, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource13, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource14, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource15, GPIO_AF_FSMC);
}
void FSMC_Configuration(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
p.FSMC_AddressSetupTime = 0x01;
p.FSMC_AddressHoldTime = 0x00;
p.FSMC_DataSetupTime = 0x0f;
p.FSMC_BusTurnAroundDuration = 0x00;
p.FSMC_CLKDivision = 0x00;
p.FSMC_DataLatency = 0x00;
p.FSMC_AccessMode = FSMC_AccessMode_A;
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
}
void DCMI_Configuration(void)
{
DCMI_InitTypeDef DCMI_InitStructure;
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_DCMI, ENABLE);
DCMI_InitStructure.DCMI_CaptureMode = DCMI_CaptureMode_SnapShot;
DCMI_InitStructure.DCMI_SynchroMode = DCMI_SynchroMode_Hardware;
DCMI_InitStructure.DCMI_PCKPolarity = DCMI_PCKPolarity_Rising;
DCMI_InitStructure.DCMI_VSPolarity = DCMI_VSPolarity_High;
DCMI_InitStructure.DCMI_HSPolarity = DCMI_HSPolarity_Low;
DCMI_InitStructure.DCMI_CaptureRate = DCMI_CaptureRate_All_Frame;
DCMI_InitStructure.DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_8b;
DCMI_Init(&DCMI_InitStructure);
DCMI_ITConfig(DCMI_IT_FRAME,ENABLE);
NVIC_EnableIRQ(DCMI_IRQn);
DCMI_CaptureCmd(ENABLE);
}
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
DMA_InitStructure.DMA_Channel = DMA_Channel_1;
DMA_InitStructure.DMA_PeripheralBaseAddr = 0x50050028;
DMA_InitStructure.DMA_Memory0BaseAddr = LCD_FRAME_BUFFER;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = 480*272*2/4;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream1, &DMA_InitStructure);
DMA_Cmd(DMA2_Stream1, ENABLE);
}
void DCMI_IRQHandler(void)
{
if(DCMI_GetITStatus(DCMI_IT_FRAME) != RESET)
{
DMA_Cmd(DMA2_Stream1, DISABLE);
while(DMA_GetCmdStatus(DMA2_Stream1) != DISABLE);
DMA_SetCurrDataCounter(DMA2_Stream1, 480*272*2/4);
DMA_Cmd(DMA2_Stream1, ENABLE);
DCMI_ClearITPendingBit(DCMI_IT_FRAME);
}
}
```
这个程序使用了FSMC(外部静态存储器控制器)来控制LCD,并使用DCMI(直接相机接口)和DMA(直接存储器访问)来获取图像数据并将其传输到LCD帧缓冲区中。
在使用此程序之前,您需要确保您的LCD显示器与STM32F407微控制器正确连接,并且您已经安装了相应的图形库。此外,您需要将要显示的电脑图片转换为适当的格式,并将其加载到LCD帧缓冲区中。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)