基于STM32⾳响控制系统源代码(⼀)(⾳乐频谱显⽰)效果图:
TFT.c
#include "TFT.h"
U16 TFT_ChipID;
static void __FSMCConfig(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;
/*-- FSMC Configuration ------------------------------------------------------*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
/* FSMC_Bank1_NORSRAM4 timing configuration */
p.FSMC_AddressSetupTime = 1;
p.FSMC_AddressHoldTime = 0;
p.FSMC_DataSetupTime = 5;
p.FSMC_BusTurnAroundDuration = 0;
p.FSMC_CLKDivision = 0;
p.FSMC_DataLatency = 0;
p.FSMC_AccessMode = FSMC_AccessMode_B;
/* FSMC_Bank1_NORSRAM4 configured as follows:
- Data/Address MUX = Disable
- Memory Type = SRAM
- Data Width = 16bit
- Write Operation = Enable
- Extended Mode = Disable
-
Asynchronous Wait = Disable */
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_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);
/* Enable FSMC_Bank1_NORSRAM4 */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
}
static void __GpioConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
#ifndef FSMC_TFT
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(TFT_DATA_PIN, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = TFT_CS|TFT_RS|TFT_WR|TFT_RD|TFT_RESET;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(TFT_COTROL_PIN, &GPIO_InitStructure);
GPIO_ResetBits(TFT_COTROL_PIN, TFT_RESET);
GPIO_SetBits(TFT_COTROL_PIN, TFT_CS);
GPIO_SetBits(TFT_COTROL_PIN, TFT_RS);
GPIO_SetBits(TFT_COTROL_PIN, TFT_WR);
GPIO_SetBits(TFT_COTROL_PIN, TFT_RD);
GPIO_SetBits(TFT_COTROL_PIN, TFT_RESET);
#else
/*FSMC*/
/* Enable GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG |
RCC_APB2Periph_GPIOB |RCC_APB2Periph_AFIO, ENABLE);
/
* Set PG.15(REST), Out put*/
GPIO_InitStructure.GPIO_Pin = TFT_RESET;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(TFT_COTROL_PIN, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = TFT_LED;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14),
PD.10(D15), PD.14(D0), PD.15(D1) as alternate
function push pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 |
GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
PE.14(D11), PE.15(D12) as alternate function push pull */
GPIO_InitStructure.GPIO_Pin = 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_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* Set PF.00(A0 (RS)) as alternate function push pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOF, &GPIO_InitStructure);
/* Set PG.12(NE4 (LCD/CS)) as alternate function push pull - CE3(LCD /CS) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_SetBits(TFT_COTROL_PIN, TFT_RESET);
#endif /*FSMC_TFT*/
}
#ifndef FSMC_TFT
static void __DB_AS_InPut(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// DB15--0
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(TFT_DATA_PIN, &GPIO_InitStructure);
}
static void __DB_AS_OutPut(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// DB15--0
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(TFT_DATA_PIN, &GPIO_InitStructure);
}
#endif /*FSMC_TFT*/
static void __WriteReg(U32 tftReg,U32 tftRegValue)
{
#ifndef FSMC_TFT
/* Write 16-bit Index, then Write Reg */
GPIO_ResetBits (TFT_COTROL_PIN, TFT_CS);//ClrCs
GPIO_ResetBits (TFT_COTROL_PIN, TFT_RS);//ClrRs
GPIO_ResetBits (TFT_COTROL_PIN, TFT_WR);//ClrWr
GPIO_Write (TFT_DATA_PIN, tftReg);//LCD_Write(TFT_Reg);
GPIO_SetBits (TFT_COTROL_PIN, TFT_WR);//SetWr
/* Write 16-bit Reg */
GPIO_SetBits (TFT_COTROL_PIN, TFT_RS);//SetRs
GPIO_ResetBits (TFT_COTROL_PIN, TFT_WR);//ClrWr
GPIO_Write (TFT_DATA_PIN, tftRegValue);//LCD_Write(TFT_RegValue);
GPIO_SetBits (TFT_COTROL_PIN, TFT_WR);//SetWr
GPIO_SetBits (TFT_COTROL_PIN, TFT_CS);//SetCs
#else
/*FSMC*/
/* Write 16-bit Index, then Write Reg */
TFT->TFT_REG = tftReg;
/* Write 16-bit Reg */
TFT->TFT_RAM = tftRegValue;
#endif /*FSMC_TFT*/
}
static U32 __ReadReg(U32 tftReg)
{
#ifndef FSMC_TFT
U32 data;
U32 data;
/* Write 16-bit Index (then Read Reg) */
GPIO_ResetBits (TFT_COTROL_PIN, TFT_CS);//ClrCs
GPIO_ResetBits (TFT_COTROL_PIN, TFT_RS);//ClrRs
GPIO_ResetBits (TFT_COTROL_PIN, TFT_WR);//ClrWr
GPIO_Write (TFT_DATA_PIN, TFT_Reg);//LCD_Write(LCD_Reg); GPIO_SetBits (TFT_COTROL_PIN, TFT_WR);//SetWr
/* Read 16-bit Reg */
GPIO_SetBits (TFT_COTROL_PIN, TFT_RS);//SetRs
__DB_AS_InPut();
GPIO_ResetBits (TFT_COTROL_PIN, TFT_RD);//ClrRd
GPIO_SetBits (TFT_COTROL_PIN, TFT_RD);//SetRd
data = GPIO_ReadInputData(TFT_DATA_PIN);
GPIO_SetBits (TFT_COTROL_PIN, TFT_CS);//SetCs
__DB_AS_OutPut();
return data;
#else
/*FSMC*/
/* Write 16-bit Index (then Read Reg) */
TFT->TFT_REG = tftReg;
/
* Read 16-bit Reg */
//data = TFT->TFT_RAM;
return (TFT->TFT_RAM);
#endif /*FSMC_TFT*/
}
#if 0
static void __WriteGRAM(U16 *pRGB_Code,U32 pixelNum)
{
#ifndef FSMC_TFT
//u32 i=0;
GPIO_ResetBits(TFT_COTROL_PIN, TFT_CS);//ClrCs
GPIO_ResetBits(TFT_COTROL_PIN, TFT_RS);//ClrRs
GPIO_ResetBits(TFT_COTROL_PIN, TFT_WR);//ClrWr
GPIO_Write(TFT_DATA_PIN, 0x0022);
GPIO_SetBits(TFT_COTROL_PIN, TFT_WR);//SetWr
GPIO_SetBits(TFT_COTROL_PIN, TFT_RS);//SetRs
while(pixelNum>0)
{
GPIO_ResetBits(TFT_COTROL_PIN, TFT_WR);//ClrWr
GPIO_Write(TFT_DATA_PIN, *pRGB_Code);
GPIO_SetBits(TFT_COTROL_PIN, TFT_WR);//SetWr
pixelNum--;
pRGB_Code++;
}
GPIO_SetBits(TFT_COTROL_PIN, TFT_CS);//SetCs
#else
/*FSMC*/
/* Write 16-bit Index, then Write Reg */
TFT->TFT_REG = 0x0022;
/* Write 16-bit RGB */
while(pixelNum>0)
{
TFT->TFT_RAM = *pRGB_Code;
pixelNum--;
pRGB_Code++;
}
#endif /*FSMC_TFT*/
}
#endif
void TFT_ClearAll(U32 color)
{
U32 i=0;
__WriteReg(0x50, 0x0000); // Horizontal GRAM Start Address
__WriteReg(0x50, 0x0000); // Horizontal GRAM Start Address
__WriteReg(0x51, 0x00EF); // Horizontal GRAM End Address
__WriteReg(0x52, 0x0000); // Vertical GRAM Start Address
__WriteReg(0x53, 0x013F); // Vertical GRAM Start Address
__WriteReg(0x20, 0); // GRAM horizontal Address
__WriteReg(0x21, 0);
/* Write 16-bit Index, then Write Reg */
TFT->TFT_REG = 0x0022;
while(i<TFT_H_PIXEL*TFT_V_PIXEL)
{
/* Write 16-bit RGB */
TFT->TFT_RAM = color;
i++;
}
}
void TFT_SetBackLED(U32 data)
{
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse=data;
TIM_OC3Init(TIM3, &TIM_OCInitStructure);
}
html播放音乐代码U8 TFT_Init(void)
{
U8 statues=0;
U32 i;
__GpioConfig();
__FSMCConfig();
TFT_ChipID=__ReadReg(0);
__WriteReg(0xE5, 0x8000); // Set the internal vcore voltage
__WriteReg(0x00,0x0001);
for(i=50000;i>0;i--);
__WriteReg(0x01,0x0100); //Driver Output Contral. 0x0100
__WriteReg(0x02,0x0700); //LCD Driver Waveform Contral.
__WriteReg(0x03,0x0030); //Entry Mode Set. 0x1018 0x1030
__WriteReg(0x04,0x0000); //Scalling Contral.
__WriteReg(0x08,0x0202); //Display Contral 2.(0x0207)
__WriteReg(0x09,0x0000); //Display Contral 3.(0x0000)
__WriteReg(0x0a,0x0000); //Frame Cycle Contal.(0x0000)
__WriteReg(0x0c,0x0000); //Extern Display Interface Contral 1.(0x0000) __WriteReg(0x0d,0x0000); //Frame Maker Position.
__WriteReg(0x0f,0x0000); //Extern Display Interface Contral 2.
__WriteReg(0x2b,0x0020); //frame rate and color control(0x0000)
__WriteReg(0x10,0x0000); //Power Control 1.(0x16b0)
__WriteReg(0x11,0x0004); //Power Control 2.(0x0001)
__WriteReg(0x12,0x0000); //Power Control 3.(0x0138)
__WriteReg(0x13,0x0000); //Power Control 4.
for(i=60000;i>0;i--);
__WriteReg(0x10, 0x17B0); // SAP, BT[3:0], AP, DSTB, SLP, STB
__WriteReg(0x11, 0x0001); // DC1[2:0], DC0[2:0], VC[2:0]
for(i=60000;i>0;i--); // Delay 50ms
__WriteReg(0x12, 0x013e); // VREG1OUT voltage
for(i=60000;i>0;i--); // Delay 50ms
__WriteReg(0x13, 0x1c00); // VDV[4:0] for VCOM amplitude
__WriteReg(0x29, 0x001e); // VCM[4:0] for VCOMH
for(i=60000;i>0;i--);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论