小弟用F103VE 驱动一块9341 8位的液晶屏,上电十次有八次CPU运行卡死。但把程序下载到F103ZE平台上。运行却没有这一现象
以下是用JTAG调试截图,CPU卡死在红黄 {MOD}的那一条指令:
CPU卡死那条指令对应的C程序:
硬件连接:
FSMC D0~D7---------------> LCD D0~D7
FSMC A16 ---------------> LCD RS
FSMC WR ---------------> LCD WR
FSMC RD ---------------> LCD RD
PC2 ---------------> LCD 背光控制
PC2 ---------------> LCD 复位脚
以下是代码:
#define Bank1_LCD_D ((u32)0x60010000) //Disp Data ADDR
#define Bank1_LCD_C ((u32)0x60000000) //Disp Reg ADDR
/*选定LCD指定寄存器*/
#define LCD_WR_REG(index) ((*(volatile u8 *) (Bank1_LCD_C)) = ((u8)index))
/*将LCD中的index寄存器设置为val值*/
#define LCD_WR_CMD(index,val) do{(*(volatile u8 *) (Bank1_LCD_C)) = ((u8)index); (*(volatile u8 *) (Bank1_LCD_D)) = ((u8)(val));}while(0)
/*往LCD GRAM写入数据*/
#define LCD_WR_Data(val) ((*(volatile u8 *) (Bank1_LCD_D)) = ((u8)(val)))
/*从LCD GRAM读入数据*/
#define LCD_RD_Data() (*(volatile u8 *) (Bank1_LCD_D))
#define LCD_ILI9340_CMD(index) LCD_WR_REG(index) //写命令
#define LCD_ILI9340_Parameter(val) LCD_WR_Data(val) //写数据
void LCD_CtrlLinesConfig9341(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* 使能FSMC时钟*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
/* 使能FSMC对应相应管脚时钟*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE , ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
/* 配置LCD背光控制管脚*/ /* 配置LCD复位控制管脚*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* 配置FSMC相对应的数据线,FSMC-D0~D8: PD.0 PD.1 PD.14 PD.15 PE.7 PE.8 PE.9 PE.10*/
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* 配置FSMC相对应的控制线
* PD4-FSMC_NOE
CD-RD
* PD5-FSMC_NWE
CD-WR
* PD7-FSMC_NE1
CD-CS
* PD11-FSMC_A16
CD-DC
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_11;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_SetBits(GPIOC, GPIO_Pin_2); // 背光打开
}
/*******************************************************************************
* Function Name: LCD_FSMCConfig
* Description : Configures the Parallel inte**ce (FSMC) for LCD(Parallel mode)
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_FSMCConfig9341(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;
p.FSMC_AddressSetupTime = 0x02; //地址建立时间
p.FSMC_AddressHoldTime = 0x0; //地址保持时间
p.FSMC_DataSetupTime = 0x5;//0x08; //数据建立时间
p.FSMC_BusTurnAroundDuration = 0x00;
p.FSMC_CLKDivision = 0x00;
p.FSMC_DataLatency = 0x00;
p.FSMC_AccessMode = FSMC_AccessMode_B; // 一般使用模式B来控制LCD
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
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);
/* 使能 FSMC Bank1_SRAM Bank */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
}
void LCD_X_Init9431(void)
{
/* Configure the LCD Control pins --------------------------------------------*/
LCD_CtrlLinesConfig9341();
/* Configure the FSMC Parallel inte**ce -------------------------------------*/
LCD_FSMCConfig9341();
}
void LCD_ILI9341_Init()
{
LCD_X_Init9431();
GPIO_SetBits(GPIOC, GPIO_Pin_3); //低电平复位
Delay_ms(1);
GPIO_ResetBits(GPIOC, GPIO_Pin_3);
Delay_ms(10);
GPIO_SetBits(GPIOC, GPIO_Pin_3 );
Delay_ms(60);
Delay_ms(60);
//************* Start Initial Sequence **********//
LCD_ILI9340_CMD(0x11); //Exit Sleep
Delay_ms(60);
LCD_ILI9340_CMD(0xef);
LCD_ILI9340_Parameter (0x03);
LCD_ILI9340_Parameter (0x80);
LCD_ILI9340_Parameter (0x02);
LCD_ILI9340_CMD(0xcf);
LCD_ILI9340_Parameter (0x00);
LCD_ILI9340_Parameter (0xc1);
LCD_ILI9340_Parameter (0x30);
LCD_ILI9340_CMD(0xed);
LCD_ILI9340_Parameter (0x67);
LCD_ILI9340_Parameter (0x03);
LCD_ILI9340_Parameter (0x12);
LCD_ILI9340_Parameter (0x81);
LCD_ILI9340_CMD(0xcb);
LCD_ILI9340_Parameter (0x39);
LCD_ILI9340_Parameter (0x2c);
LCD_ILI9340_Parameter (0x00);
LCD_ILI9340_Parameter (0x34);
LCD_ILI9340_Parameter (0x02);
LCD_ILI9340_CMD(0xea);
LCD_ILI9340_Parameter (0x00);
LCD_ILI9340_Parameter (0x00);
LCD_ILI9340_CMD(0xe8);
LCD_ILI9340_Parameter (0x85);
LCD_ILI9340_Parameter (0x0a);
LCD_ILI9340_Parameter (0x78);
LCD_ILI9340_CMD(0xC0); //Power control
LCD_ILI9340_Parameter (0x18); //VRH[5:0]
LCD_ILI9340_CMD(0xC1); //Power control
LCD_ILI9340_Parameter (0x13); //SAP[2:0];BT[3:0]
LCD_ILI9340_CMD(0xC5); //VCM control
LCD_ILI9340_Parameter (0x31);
LCD_ILI9340_Parameter (0x3C);
LCD_ILI9340_CMD(0xc7);
LCD_ILI9340_Parameter (0xA8);
LCD_ILI9340_CMD(0x3A);
LCD_ILI9340_Parameter (0x55);
LCD_ILI9340_CMD(0x36); // Memory Access Control
LCD_ILI9340_Parameter (0x48);
LCD_ILI9340_CMD(0xB1); // Frame Rate Control
LCD_ILI9340_Parameter (0x00);
LCD_ILI9340_Parameter (0x18);
LCD_ILI9340_CMD(0xB6); // Display Function Control
LCD_ILI9340_Parameter (0x0a);
LCD_ILI9340_Parameter (0x82);
LCD_ILI9340_Parameter (0x27);
LCD_ILI9340_CMD(0xF2); // 3Gamma Function Disable
LCD_ILI9340_Parameter (0x00);
LCD_ILI9340_CMD(0xF7);
LCD_ILI9340_Parameter (0x20);
LCD_ILI9340_CMD(0x26); //Gamma curve selected
LCD_ILI9340_Parameter (0x01);
LCD_ILI9340_CMD(0xE0); //Set Gamma
LCD_ILI9340_Parameter (0x1f);
LCD_ILI9340_Parameter (0x25);
LCD_ILI9340_Parameter (0x25);
LCD_ILI9340_Parameter (0x0c);
LCD_ILI9340_Parameter (0x11);
LCD_ILI9340_Parameter (0x0a);
LCD_ILI9340_Parameter (0x4e);
LCD_ILI9340_Parameter (0xcb);
LCD_ILI9340_Parameter (0x37);
LCD_ILI9340_Parameter (0x03);
LCD_ILI9340_Parameter (0x00);
LCD_ILI9340_Parameter (0x00);
LCD_ILI9340_Parameter (0x00);
LCD_ILI9340_Parameter (0x00);
LCD_ILI9340_Parameter (0x00);
LCD_ILI9340_CMD(0XE1); //Set Gamma
LCD_ILI9340_Parameter (0x00);
LCD_ILI9340_Parameter (0x1a);
LCD_ILI9340_Parameter (0x1c);
LCD_ILI9340_Parameter (0x02);
LCD_ILI9340_Parameter (0x0e);
LCD_ILI9340_Parameter (0x06);
LCD_ILI9340_Parameter (0x31);
LCD_ILI9340_Parameter (0x36);
LCD_ILI9340_Parameter (0x48);
LCD_ILI9340_Parameter (0x0c);
LCD_ILI9340_Parameter (0x1f);
LCD_ILI9340_Parameter (0x1f);
LCD_ILI9340_Parameter (0x3f);
LCD_ILI9340_Parameter (0x3f);
LCD_ILI9340_Parameter (0x1F);
LCD_ILI9340_CMD(0x29); //display on
}
void ili9341_Clear(u16 Color)
{
u32 index=0;
unsigned char hight = (Color >> 8);
unsigned char low = Color;
LCD_ILI9341_CMD(0x2c); //写GRAM
for(index=0;index<76800;index++)
{
LCD_WR_Data(hight);
LCD_WR_Data(low);
}
}
int main(void)
{
RCC_Configuration();
NVIC_Configuration();
USART_Configuration(CONSOLE_UART);
LCD_ILI9341_Init();
while(1)
{
ili9341_Clear(RED);
delay_ms(500);
ili9341_Clear(BLUE);
delay_ms(500);
ili9341_Clear(GREEN);
delay_ms(500);
}
}
一直在这里不能出去?
---------------------------------
是的,MCU 直接死了
一般这种卡死,应该是cpu找不到中断服务函数导致的,不应该卡死在这里的。慢慢查下吧,看看你是不是还开了什么其他中断。
一周热门 更多>