RT,显示器上不能显示任何东西啊!是什么地方错掉了?
#include "stm32f10x.h"
#define CS_0 GPIO_ResetBits ( GPIOC, GPIO_Pin_6 );
#define CS_1 GPIO_SetBits ( GPIOC, GPIO_Pin_6 );
#define red 0xf800
#define blue 0x001f
#define green 0x7e00
#define yellow 0xffe0
#define purple 0xf81f
#define white 0xffff
#define black 0x0000
#define cyan 0x07ff
#define grey 0x7bef
void delay ( u32 count )
{
for ( ; count > 0; count -- );
}
uint8_t CLK_Init ( void )
{
ErrorStatus HSEStartUpStatus; //不知道干嘛的
RCC_DeInit (); //将RCC恢复为默认值
RCC_HSEConfig ( RCC_HSE_ON ); //打开外部高速晶体振荡器
HSEStartUpStatus = RCC_WaitForHSEStartUp (); //等待外部高速晶振振荡器的起振
if ( HSEStartUpStatus == SUCCESS ) //判断外部高速晶体振荡器是否起振
{
delay ( 0xff ); //稍微延时一会
RCC_HCLKConfig ( RCC_SYSCLK_Div1 ); //设置AHB时钟为系统时钟频率 72MHz
RCC_PCLK2Config ( RCC_HCLK_Div1 ); //设置APB2的时钟,等于AHB时钟 72MHz
RCC_PCLK1Config ( RCC_HCLK_Div2 ); //设置APB1的时钟,等于AHB的一半 36MHz
RCC_PLLConfig ( RCC_PLLSource_HSE_Div1, RCC_PLLMul_9 ); //设置系统时钟PLL时钟的频率:8*9= 72MHz
RCC_PLLCmd ( ENABLE ); //使能PLL时钟
while ( RCC_GetFlagStatus ( RCC_FLAG_PLLRDY ) == RESET ); //等待PLL时钟初始化成功
RCC_SYSCLKConfig ( RCC_SYSCLKSource_PLLCLK ); //将系统时钟设置为PLL时钟源
while ( RCC_GetSYSCLKSource () != 0x08 ); //等待PLL时钟成功的成为系统时钟源
return 0; //跳出循环,进行下面的步骤
}
else
{
RCC_DeInit (); //不行的话,就重新初始化
return 1; //继续循环
}
}
void Pin_Init ( void )
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; //PE口为数据口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init ( GPIOE, &GPIO_InitStructure );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init ( GPIOC, &GPIO_InitStructure );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init ( GPIOD, &GPIO_InitStructure );
}
void LCD_Write_Com ( u16 com )
{
GPIO_ResetBits ( GPIOD, GPIO_Pin_13 ); // RS= 0,表示地址
GPIO_Write ( GPIOE, com ); //GPIOE,作为数据口,16位并行模式
GPIO_ResetBits ( GPIOD, GPIO_Pin_14 ); //WR = 0
GPIO_SetBits ( GPIOD, GPIO_Pin_14 ); //WR = 1
}
void LCD_Write_Data ( u16 dat )
{
GPIO_SetBits ( GPIOD, GPIO_Pin_13 ); // RS= 1,表示数据
GPIO_Write ( GPIOE, dat );
GPIO_ResetBits ( GPIOD, GPIO_Pin_14 ); //WR = 0
GPIO_SetBits ( GPIOD, GPIO_Pin_14 ); //WR = 1
}
void LCD_Init ( void )
{
//delay ( 0xffff );
CS_0; //打开片选使能
LCD_Write_Com ( 0x0000 ); LCD_Write_Data ( 0x0001 );
LCD_Write_Com ( 0x0001 ); LCD_Write_Data ( 0x333f );
LCD_Write_Com ( 0x0002 ); LCD_Write_Data ( 0x0600 );
LCD_Write_Com ( 0x000c ); LCD_Write_Data ( 0x0007 );
LCD_Write_Com ( 0x000d ); LCD_Write_Data ( 0x0006 );
LCD_Write_Com ( 0x000e ); LCD_Write_Data ( 0x3200 );
LCD_Write_Com ( 0x001e ); LCD_Write_Data ( 0x00bb );
LCD_Write_Com ( 0x0003 ); LCD_Write_Data ( 0x6a64 );
LCD_Write_Com ( 0x0010 ); LCD_Write_Data ( 0x0000 );
LCD_Write_Com ( 0x0011 ); LCD_Write_Data ( 0x4870 );
LCD_Write_Com ( 0x0007 ); LCD_Write_Data ( 0x0033 );
LCD_Write_Com ( 0x0025 ); LCD_Write_Data ( 0xe000 );
LCD_Write_Com ( 0x000b ); LCD_Write_Data ( 0x5308 );
LCD_Write_Com ( 0x000f ); LCD_Write_Data ( 0x0000 );
LCD_Write_Com ( 0x0044 ); LCD_Write_Data ( 0xef00 );
LCD_Write_Com ( 0x0045 ); LCD_Write_Data ( 0x0000 );
LCD_Write_Com ( 0x0046 ); LCD_Write_Data ( 0x013f );
LCD_Write_Com ( 0x004e ); LCD_Write_Data ( 0x0000 );
LCD_Write_Com ( 0x004f ); LCD_Write_Data ( 0x0000 );
LCD_Write_Com ( 0x0030 ); LCD_Write_Data ( 0x0000 );
LCD_Write_Com ( 0x0031 ); LCD_Write_Data ( 0x0706 );
LCD_Write_Com ( 0x0032 ); LCD_Write_Data ( 0x0206 );
LCD_Write_Com ( 0x0033 ); LCD_Write_Data ( 0x0300 );
LCD_Write_Com ( 0x0034 ); LCD_Write_Data ( 0x0002 );
LCD_Write_Com ( 0x0035 ); LCD_Write_Data ( 0x0000 );
LCD_Write_Com ( 0x0036 ); LCD_Write_Data ( 0x0707 );
LCD_Write_Com ( 0x0037 ); LCD_Write_Data ( 0x0200 );
LCD_Write_Com ( 0x003a ); LCD_Write_Data ( 0x0908 );
LCD_Write_Com ( 0x003b ); LCD_Write_Data ( 0x0f0d );
LCD_Write_Com ( 0x0028 ); LCD_Write_Data ( 0x0006 );
LCD_Write_Com ( 0x002f ); LCD_Write_Data ( 0x12eb );
LCD_Write_Com ( 0x0026 ); LCD_Write_Data ( 0x7000 );
LCD_Write_Com ( 0x0020 ); LCD_Write_Data ( 0xb0e3 );
LCD_Write_Com ( 0x0027 ); LCD_Write_Data ( 0x0044 );
LCD_Write_Com ( 0x002e ); LCD_Write_Data ( 0x7e45 );
CS_1; //关闭片选使能
}
void Address_set( u8 x1, u16 y1, u8 x2, u16 y2)
{
u16 x = ( x2 << 8 ) | x1;
LCD_Write_Com(0x004e); LCD_Write_Data (x1); //设置X坐标位置
LCD_Write_Com(0x004f); LCD_Write_Data (y1); //设置Y坐标位置
LCD_Write_Com(0x0044); LCD_Write_Data (x); //开始X与结束x
LCD_Write_Com(0x0045); LCD_Write_Data (y1); //开始Y
LCD_Write_Com(0x0046); LCD_Write_Data (y2); //结束Y
LCD_Write_Com(0x0022);
}
void Pant ( void )
{
int i, j;
CS_0; //打开片选使能
Address_set(0,0,239,319);
for(i = 0; i < 320; i++)
{
for (j = 0; j < 240; j++)
{
LCD_Write_Data ( 0xfe00 ); //红 {MOD}
}
}
CS_1; //关闭片选使能
}
int main ( void )
{
while ( CLK_Init () );
RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE, ENABLE );
Pin_Init ();
LCD_Init ();
Pant ();
while (1);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
虽然很感激。但这也是7年前的帖子了。。。
一周热门 更多>