新手上路
- 积分
- 33
- 金钱
- 33
- 注册时间
- 2013-7-9
- 在线时间
- 0 小时
|
发表于 2013-7-10 17:19:19
|
显示全部楼层
回复【楼主位】祥子:
---------------------------------
这个控制器可以读出ID号不呀?可以的话能给点代码不呀?我这个一直白屏,请帮我分析下哈
这是我采用你的驱动代码;
#include"stm32f10x_lib.h"
#include"stdio.h"
//定义tft屏的管脚
//
// 按实际情况修改成你自己tft屏的管脚
//
#define Rs_H() GPIO_SetBits(GPIOA,GPIO_Pin_8)
#define Rs_L() GPIO_ResetBits(GPIOA,GPIO_Pin_8)
#define Wr_H() GPIO_SetBits(GPIOA,GPIO_Pin_7)
#define Wr_L() GPIO_ResetBits(GPIOA,GPIO_Pin_7)
#define Rd_H() GPIO_SetBits(GPIOA,GPIO_Pin_6)
#define Rd_L() GPIO_ResetBits(GPIOA,GPIO_Pin_6)
#define Cs_H() GPIO_SetBits(GPIOA,GPIO_Pin_9)
#define Cs_L() GPIO_ResetBits(GPIOA,GPIO_Pin_9)
#define Rest_H() GPIO_SetBits(GPIOA,GPIO_Pin_5)
#define Rest_L() GPIO_ResetBits(GPIOA,GPIO_Pin_5)
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus; //错误状态
RCC_HSEConfig(RCC_HSE_ON); //开启外部高速时钟
HSEStartUpStatus=RCC_WaitForHSEStartUp(); //等待外部高速时钟启振
if(HSEStartUpStatus==SUCCESS) //判断启振是否成功
{
//RCC_HSICmd(ENABLE); // 如果成功,使能内部高速时钟
RCC_HCLKConfig(RCC_SYSCLK_Div1); //设置AHB时钟 等于系统时钟
RCC_PCLK1Config(RCC_HCLK_Div2); //设置低速AHB时钟 HCLK/2
RCC_PCLK2Config(RCC_HCLK_Div1); //设置高速AHB时钟 HCLK
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_4);//设置PLL时钟 HSE时钟率 *4
RCC_PLLCmd(ENABLE);//使能PLL
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);;//等待成功启振
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//选择PLL作为系统时钟
while(RCC_GetSYSCLKSource()!=0x08); //判断PLL是否是系统时钟
}
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE); //给GPIOA提供时钟
}
//管脚的初始化
void Lcd_Pin_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|
GPIO_Pin_6|
GPIO_Pin_7|
GPIO_Pin_8|
GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
/********************串口1初始化*********************************/
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1| RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;
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);
}
u8 Uart_R(void)
{
u8 RXDate;
if(USART_GetFlagStatus(USART1,USART_IT_RXNE)==1) // 等待接收数据
{
RXDate = USART_ReceiveData(USART1);
}
return RXDate;
}
void Uart_T(u8 TXData)
{
USART_SendData(USART1,(u8)TXData); //发送数据
//while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == 0); //等待数据发送
}
void delay_Ms(u16 time)
{
u16 i=0;
while(time--)
{
i=12000;//自己定义
while(i--) ;
}
}
//下面两条函数是管脚读写的切换
void LcdWriteMode()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
void LcdReadMode()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
/*写入*/
//写入指令
void Send_Lcd_Cmd(u16 cmd)
{
Uart_T(0x12);
delay_Ms(10);
//printf(" LCD ID:%x\n",id); //打印LCD ID
///
Rs_L();
GPIO_Write(GPIOB,cmd);
Wr_L();
Wr_H();
}
//写入资料
void Send_Lcd_Data(u16 ddata)
{
Uart_T(0x13);
delay_Ms(10);
Rs_H();
GPIO_Write(GPIOB,ddata);
Wr_L();
Wr_H();
}
/*读取*/
unsigned int Read_Lcd_Data()
{
int temp=0;
Rs_H();
Rd_L();
Rd_H();
temp = GPIO_ReadInputData(GPIOB);
return temp;
}
//同时发送指令和内容
//cmd:指令
//ddata:内容
void Send_Lcd_CAD(unsigned int cmd,unsigned int ddata)
{
Send_Lcd_Cmd(cmd);
Send_Lcd_Data(ddata);
}
//小延迟
void Lcd_Delay(unsigned int i)
{
while(i--);
}
//tft屏的初始化
void lcd_init(void)
{
Rest_H();
Lcd_Delay(10000);
Rest_L();
Lcd_Delay(10000);
Rest_H();
Cs_H();
Wr_H();
Rd_H();
Lcd_Delay(10000);
Cs_L();
Send_Lcd_CAD(0x0011,0x2004); //Power control 2
Send_Lcd_CAD(0x0013,0xCC00); //Power control 4
Send_Lcd_CAD(0x0015,0x2600); //Power control 6
Send_Lcd_CAD(0x0014,0x252A); //Power control 5
Send_Lcd_CAD(0x0012,0x0033); //Power control 3
Send_Lcd_CAD(0x0013,0xCC04); //Power control 4
Send_Lcd_CAD(0x0013,0xCC06); //Power control 4
Send_Lcd_CAD(0x0013,0xCC4F); //Power control 4
Send_Lcd_CAD(0x0013,0x674F); //Power control 4
Send_Lcd_CAD(0x0011,0x2003); //Power control 2
Send_Lcd_CAD(0x0030,0x2609); //Gamma control 1
Send_Lcd_CAD(0x0031,0x242C); //Gamma control 2
Send_Lcd_CAD(0x0032,0x1F23); //Gamma control 3
Send_Lcd_CAD(0x0033,0x2425); //Gamma control 4
Send_Lcd_CAD(0x0034,0x2226); //Gamma control 5
Send_Lcd_CAD(0x0035,0x2523); //Gamma control 6
Send_Lcd_CAD(0x0036,0x1C1A); //Gamma control 7
Send_Lcd_CAD(0x0037,0x131D); //Gamma control 8
Send_Lcd_CAD(0x0038,0x0B11); //Gamma control 9
Send_Lcd_CAD(0x0039,0x1210); //Gamma control 10
Send_Lcd_CAD(0x003A,0x1315); //Gamma control 11
Send_Lcd_CAD(0x003B,0x3619); //Gamma control 12
Send_Lcd_CAD(0x003C,0x0D00); //Gamma control 13
Send_Lcd_CAD(0x003D,0x000D); //Gamma control 14
Send_Lcd_CAD(0x0016,0x0007); //Power control 7
Send_Lcd_CAD(0x0002,0x0013); //LCD-Driving-waveform control
Send_Lcd_CAD(0x0003,0x0009); //Entry mode
Send_Lcd_CAD(0x0001,0x0127); //Driver output control
Lcd_Delay(10000);
Send_Lcd_CAD(0x0008,0x0303); //Blank period control 1
Send_Lcd_CAD(0x000A,0x000B); //Frame cycle control 1
Send_Lcd_CAD(0x000B,0x0003); //Frame cycle control
Send_Lcd_CAD(0x000C,0x0000); //External interface control // 18-bit RGB interface (one transfer/pixel)
Send_Lcd_CAD(0x0041,0x0000); //Vertical scroll control
Send_Lcd_CAD(0x0050,0x0000); //MDDI wake up control
Send_Lcd_CAD(0x0060,0x0005); //MTP INIT
Send_Lcd_CAD(0x0070,0x000B); //Timing of signal from GOE
Send_Lcd_CAD(0x0071,0x0000); //Gate start pulse delay timing
Send_Lcd_CAD(0x0078,0x0000); //Vcom Output Control
Send_Lcd_CAD(0x007A,0x0000); //Panel signal control2
Send_Lcd_CAD(0x0079,0x0007); //Panel signal control 1
Send_Lcd_CAD(0x0007,0x0051); //Display control
Lcd_Delay(10000);
Send_Lcd_CAD(0x0007,0x0053); //Display control
Send_Lcd_CAD(0x0079,0x0000); //Panel signal control 1
}
/**************************************************************************/
/* 函数说明:set the lcd show area(指定一个现实的区域) */
/* 函数参数:(x,y起始坐标):ss_x,ss_y,(x,y最终坐标):ss_x,ss_y */
/**************************************************************************/
void Lcd_Set_ShowArea(int ss_x ,int ss_y,int se_x, int se_y)
{
int tempsx,tempsy,tempex,tempey;
tempsx = ss_x ;
tempsy = ss_y;
tempex = se_x ;
tempey = se_y;
/*R46h HEA HSA */
Send_Lcd_Cmd(0x0046);
Send_Lcd_Data((tempex<<8)|tempsx);
/*R47h VEA */
Send_Lcd_Cmd(0x0047);
Send_Lcd_Data(tempey);
/*R48h VSA */
Send_Lcd_Cmd(0x0048);
Send_Lcd_Data(tempsy);
/*R20H AD 7~0*/
Send_Lcd_Cmd(0x0020);
Send_Lcd_Data(tempsx);
/*R21H AD 16~8*/
Send_Lcd_Cmd(0x0021);
Send_Lcd_Data(tempsy);
/*R22H AD Note 1*/
Send_Lcd_Cmd(0x0022);
}
/**************************************************************************/
/* 函数说明:clear the lcd screen (LCD清屏) */
/* 函数参数:无 */
/**************************************************************************/
void Lcd_Crr(void)
{
int i,j;
Lcd_Set_ShowArea(0,0,239,319);
for(i=0;i<240;i++)
{
for(j=0;j<320;j++)
{
Send_Lcd_Data(0xFFFF); /*0xff是全白,0x00是全黑*/
}
}
}
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;
}
int main()
{
u16 id;
RCC_Configuration();
Lcd_Pin_init();
USART1_Config();
//LcdWriteMode();
lcd_init();
//LcdReadMode();
while(1)
{
Lcd_Crr();
//GPIO_Write(GPIOB,0xf800);
//id=Read_Lcd_Data();
/*
Uart_T(id>>8);
delay_Ms(10);
Uart_T(id);
delay_Ms(10);
*/
//while(1);
// Uart_T(0x12);
//delay_Ms(10);
//printf(" LCD ID:%x\n",id); //打印LCD ID
///Uart_T(0x13);
//delay_Ms(10);
// while(1);
}
} |
|