在做毕业设计,基于stm32F103RBT6的,其中有一部分用R61505V驱动的2.4寸TFT显示温湿度采集曲线,想先驱动下TFT,按照51程序(51程序可用)翻译改来的,但是始终白屏。求高手指点。。
tft2.4.zip
(5.27 MB)
(下载次数: 116, 2012-12-29 23:20 上传)
main.c
/******************** (C) COPYRIGHT 2012 WildFire Team **************************
* 文件名 :main.c
* 描述 :
* 库版本 :ST3.5.0
*
**********************************************************************************/
#include "stm32f10x.h"
#include "LCD_driver.h"
/********************************宏定义*********************************/
#define LCD_cs(x) x ? GPIO_SetBits(GPIOA, LCD_CS) : GPIO_ResetBits(GPIOA, LCD_CS)//自己定义的位函数
/******************************** 变量定义 ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
ErrorStatus HSEStartUpStatus;
/*********************************声明函数 -----------------------------------------------*/
void RCC_Configuration(void);
void NVIC_Configuration(void);
void Delay(vu32 nCount);
/*******************************************************************************
主函数
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif
RCC_Configuration(); //系统时钟配置函数
NVIC_Configuration(); //NVIC配置函数
//启动GPIO模块时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
//把调试设置普通IO口
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; //所有GPIO为同一类型端口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //输出的最大频率为50HZ
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化GPIOA端口
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化GPIOB端口
GPIO_Write(GPIOA,0xffff); //将GPIOA 16个端口全部置为高电平
GPIO_Write(GPIOB,0xffff); //将GPIOB 16个端口全部置为高电平
LCD_Init();
Pant(colors[5]>>8 , colors[5] );
LCD_cs(0); //打开片选使能
/*
ChineseChar(14+46,10,2,colors[2],colors[7],1); //普
ChineseChar(46+46,10,2,colors[2],colors[7],2); //中
ChineseChar(78+46,10,2,colors[2],colors[7],3); //科
ChineseChar(110+46,10,2,colors[2],colors[7],4); //技
LCD_ShowString(12,60,colors[0],colors[7],"-");
ChineseChar(20,60,1,colors[0],colors[7],1); //带
ChineseChar(44,60,1,colors[0],colors[7],2); //您
ChineseChar(68,60,1,colors[0],colors[7],3); //进
ChineseChar(92,60,1,colors[0],colors[7],4); //入
ChineseChar(116,60,1,colors[0],colors[7],5); //单
ChineseChar(140,60,1,colors[0],colors[7],6); //片
ChineseChar(164,60,1,colors[0],colors[7],7); //机
ChineseChar(188,60,1,colors[0],colors[7],8); //世
ChineseChar(212,60,1,colors[0],colors[7],9); //界
LCD_ShowString(0,90,colors[0],colors[5],"
WWW.PRECHIN.com");
ChineseChar(0,120,1,colors[4],colors[7],10); //专
ChineseChar(24,120,1,colors[4],colors[7],11); //业
ChineseChar(48,120,1,colors[6],colors[7],12); //技
ChineseChar(72,120,1,colors[6],colors[7],13); //术
ChineseChar(96,120,1,colors[2],colors[7],14); //论
ChineseChar(120,120,1,colors[2],colors[7],15); //坛
// LCD_ShowString(92,120,colors[4],colors[7],":");
LCD_ShowString(0,150,colors[7],colors[2],"
www.PRECHIN.net");
LCD_ShowString(12,180,colors[0],colors[7],"TELL:");
LCD_ShowString(12,210,colors[2],colors[7],"0755-61190227");
LCD_ShowString(0,240,colors[2],colors[7],"abcdefJhiJKLMNOP");
LCD_ShowString(0,265,colors[2],colors[7],"
pqrstuvwxyz!@#$");
LCD_ShowString(0,290,colors[2],colors[7],"<>CDEF^&*()/,[]");
*/
LCD_cs(1); //关闭片选使能
while(1);
}
/*******************************************************************************
* 配置RCC
*******************************************************************************/
void RCC_Configuration(void)
{
RCC_DeInit(); //复位RCC外部设备寄存器到默认值
RCC_HSEConfig(RCC_HSE_ON);//打开外部高速晶振
HSEStartUpStatus = RCC_WaitForHSEStartUp();//等待外部高速时钟准备好
if(HSEStartUpStatus == SUCCESS)//外部高速时钟已经准别好
{
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);//开启FLASH的预取功能
FLASH_SetLatency(FLASH_Latency_2);//FLASH延迟2个周期
RCC_HCLKConfig(RCC_SYSCLK_Div1);//配置AHB(HCLK)时钟=SYSCLK
RCC_PCLK2Config(RCC_HCLK_Div1);//配置APB2(PCLK2)钟=AHB时钟
RCC_PCLK1Config(RCC_HCLK_Div2);//配置APB1(PCLK1)钟=AHB 1/2时钟
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);//配置PLL时钟 == 外部高速晶体时钟*9 PLLCLK = 8MHz * 9 = 72 MHz
RCC_PLLCmd(ENABLE);//使能PLL时钟
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)//等待PLL时钟就绪
{}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//配置系统时钟 = PLL时钟
while(RCC_GetSYSCLKSource() != 0x08)//检查PLL时钟是否作为系统时钟
{}
}
}
/*******************************************************************************
* NVIC配置函数
*******************************************************************************/
void NVIC_Configuration(void)
{
#ifdef VECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); /* Set the Vector Table base location at 0x20000000 */
#else /* VECT_TAB_FLASH */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);/* Set the Vector Table base location at 0x08000000 */
#endif
}
/*******************************************************************************
* 延时函数
*******************************************************************************/
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
#ifdef DEBUG
/*******************************************************************************
* Function Name : assert_failed
* Description : Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* Input : - file: pointer to the source file name
* - line: assert_param error line source number
* Output : None
* Return : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
lcd.c
#include "stm32f10x_lib.h"
#include"LCD_driver.h"
#include"chines.h"
#include"char.h"
/********************************宏定义*********************************/
#define LCD_rest(x) x ? GPIO_SetBits(GPIOA, LCD_RST): GPIO_ResetBits(GPIOA, LCD_RST) //自己定义位操作函数
#define LCD_rd(x) x ? GPIO_SetBits(GPIOA, LCD_RD) : GPIO_ResetBits(GPIOA, LCD_RD)
#define LCD_rs(x) x ? GPIO_SetBits(GPIOA, LCD_RS) : GPIO_ResetBits(GPIOA, LCD_RS)
#define LCD_wr(x) x ? GPIO_SetBits(GPIOA, LCD_WR) : GPIO_ResetBits(GPIOA, LCD_WR)
#define LCD_cs(x) x ? GPIO_SetBits(GPIOA, LCD_CS) : GPIO_ResetBits(GPIOA, LCD_CS)
uint colors[]=
{0xf800,0x07e0,0x001f,0xffe0,0x0000,0x07ff,0xf81f,0xffff};//颜色数据
// 红 , 绿 , 蓝 , 黄 , 黑 , ,品红 , 白
void LCD_Init(void)
{
LCD_rest(1);
delayms(5);
LCD_rest(0);
delayms(5);
LCD_rest(1);
LCD_cs(1);
LCD_rd(1);
LCD_wr(1);
delayms(5);
LCD_cs(0); //打开片选使能
Lcd_Write_Com_Data(0x00,0x0000);
Lcd_Write_Com_Data(0x00,0x0000);
Lcd_Write_Com_Data(0x00,0x0000);
Lcd_Write_Com_Data(0x00,0x0001);
Lcd_Write_Com_Data(0xA4,0x0001);
delayms(10);
Lcd_Write_Com_Data(0x60,0x2700);
Lcd_Write_Com_Data(0x08,0x0808);
Lcd_Write_Com_Data(0x30,0x0214);
Lcd_Write_Com_Data(0x31,0x3715);
Lcd_Write_Com_Data(0x32,0x0604);
Lcd_Write_Com_Data(0x33,0x0E16);
Lcd_Write_Com_Data(0x34,0x2211);
Lcd_Write_Com_Data(0x35,0x1500);
Lcd_Write_Com_Data(0x36,0x8507);
Lcd_Write_Com_Data(0x37,0x1407);
Lcd_Write_Com_Data(0x38,0x1403);
Lcd_Write_Com_Data(0x39,0x0020);
Lcd_Write_Com_Data(0x90,0x0015);
Lcd_Write_Com_Data(0x10,0x0410);
Lcd_Write_Com_Data(0x11,0x0237);
Lcd_Write_Com_Data(0x29,0x0046);
Lcd_Write_Com_Data(0x2A,0x0046);
Lcd_Write_Com_Data(0x07,0x0000);
Lcd_Write_Com_Data(0x12,0x0189);
Lcd_Write_Com_Data(0x13,0x1100);
delayms(150);
Lcd_Write_Com_Data(0x12,0x01B9);
Lcd_Write_Com_Data(0x01,0x0100);
Lcd_Write_Com_Data(0x02,0x0200);
Lcd_Write_Com_Data(0x03,0x1030);
Lcd_Write_Com_Data(0x09,0x0001);
Lcd_Write_Com_Data(0x0A,0x0000);
Lcd_Write_Com_Data(0x0D,0x0000);
Lcd_Write_Com_Data(0x0E,0x0030);
Lcd_Write_Com_Data(0x50,0x0000);
Lcd_Write_Com_Data(0x51,0x00EF);
Lcd_Write_Com_Data(0x52,0x0000);
Lcd_Write_Com_Data(0x53,0x013F);
Lcd_Write_Com_Data(0x61,0x0001);
Lcd_Write_Com_Data(0x6A,0x0000);
Lcd_Write_Com_Data(0x80,0x0000);
Lcd_Write_Com_Data(0x81,0x0000);
Lcd_Write_Com_Data(0x82,0x005F);
Lcd_Write_Com_Data(0x92,0x0100);
Lcd_Write_Com_Data(0x93,0x0701);
delayms(80);
Lcd_Write_Com_Data(0x07,0x0100);
Lcd_Write_Com_Data(0x20,0x0000);
Lcd_Write_Com_Data(0x21,0x0000);
Lcd_Write_Com(0x00,0x22);
LCD_cs(1); //关闭片选使能
}
void delayms(int count) // /* X1ms */
{
int i,j;
for(i=0;i
for(j=0;j<100;j++);
}
//TFT数据及命令函数
#ifdef Bus_16 //条件编译-16位数据模式
void LCD_Writ_Bus(uint VH , uint VL) //并行数据写入函数
{
GPIOB->BSRR = VH & 0xff00;
GPIOB->BRR = (~VH) & 0xff00;
GPIOB->BSRR = (VL)<<8 & 0x00ff;
GPIOB->BRR = ((~VL)<<8) & 0x00ff;
LCD_wr(0);
LCD_wr(1);
}
#else //条件编译-8位数据模式
void LCD_Writ_Bus(char VH,char VL) //并行数据写入函数
{
//LCD_DataPortH=VH; //八位模式都用P0口送数据
//LCD_wr(0);
//LCD_wr(1);
//LCD_DataPortH=VL; //八位模式都用P0口送数据
//LCD_wr(0);
//LCD_wr(1);
}
#endif
void Lcd_Write_Com(char VH,char VL) //发送命令-8位参数
{
LCD_rs(0);
LCD_Writ_Bus(VH,VL);
}
void Lcd_Write_Data(char VH,char VL) //发送数据-8位参数
{
LCD_rs(1);
LCD_Writ_Bus(VH,VL);
}
void Lcd_Write_Com_Data(int com,int val) //发送数据命令
{
Lcd_Write_Com(com>>8,com);
Lcd_Write_Data(val>>8,val);
}
/**********************************************************
设置坐标范围 与tft驱动IC有关
**********************************************************/
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
Lcd_Write_Com(0x00,0x50);Lcd_Write_Data(x1>>8,x1);
Lcd_Write_Com(0x00,0x51);Lcd_Write_Data(x2>>8,x2);
Lcd_Write_Com(0x00,0x52);Lcd_Write_Data(y1>>8,y1);
Lcd_Write_Com(0x00,0x53);Lcd_Write_Data(y2>>8,y2);
Lcd_Write_Com(0x00,0x20);Lcd_Write_Data(x1>>8,x1);
Lcd_Write_Com(0x00,0x21);Lcd_Write_Data(y1>>8,y1);
Lcd_Write_Com(0x00,0x22);
}
/**********************************************************
单数据 刷屏
**********************************************************/
void Pant(char VH,char VL)
{
int i,j;
LCD_cs(0); //打开片选使能
Address_set(0,0,239,319);
for(i=0;i<320;i++)
{
for (j=0;j<240;j++)
{
Lcd_Write_Data(VH,VL);
}
}
LCD_cs(1); //关闭片选使能
}
/**********************************************************
写汉字子函数
**********************************************************/
void ChineseChar(uint x,uint y,int size,uint For_color,uint Bk_color ,char c)
{
int e=0,i,j;
int ed;
uint ncols;
uint nrows;
uint nbytes;
uchar *pfont;
uchar *pchar;
uchar *fonttable[]={(uchar *)hz16,(uchar *)hz24 , (uchar *)hz32};
pfont=(uchar *)fonttable[size];
if(size==0)
{
ncols =16-1;
nrows =16-1;
nbytes =32; //每个字取模的字节数=(16*16)/8
}
else
if(size==1)
{
ncols =24-1;
nrows =24-1;
nbytes =72; //每个字取模的字节数=(24*24)/8
}
else
if(size==2)
{
ncols =32-1;
nrows =32-1;
nbytes =132; //每个字取模的字节数=(32*32)/8
}
pchar=pfont + (nbytes*(c-1));
Address_set(x, y, x+nrows,y+ncols);
for(i=0;i
{
ed=*pchar++;
if(size==0)
{
if(i%2==0)
e=8;
else
e=4;
}
else
e=8;
for(j=0;j
{
if((ed>>j)&0x01)
{
Lcd_Write_Data(For_color>>8 , For_color ); //textcolor
}
else
{
Lcd_Write_Data( Bk_color>>8 , Bk_color); //backcolor
}
}
}
}
/**********************************************************
字符显示子函数
**********************************************************/
void LCD_ShowChar(uint x,uint y,uint For_color,uint Bk_color, char ch)
{
uchar temp , Bytes;
uchar pos,t;
uint CHAR_W,CHAR_H;
CHAR_W = 16; //16*24
CHAR_H = 24;
if(x>(LCD_SIZE_X-CHAR_W)||y>(LCD_SIZE_Y-CHAR_H))
return;
Address_set(x, y, x+CHAR_W-1, y+CHAR_H-1); //设置显示地址
ch = ch-32; //按照ASCII编码顺序的到相应字母的编码
Bytes = (CHAR_W*CHAR_H)/8; //每个字母取模字节数
for(pos=0;pos
{
temp= Font16x24[ch][pos]; //16是字体的宽度
for(t=0;t<8;t++)
{
if(temp&0x80)
Lcd_Write_Data(For_color>>8 , For_color ); //textcolor
else
Lcd_Write_Data(Bk_color>>8 , Bk_color ); //backcolor
temp<<=1;
}
}
}
/**********************************************************
显示字符串子函数
x,y:起点坐标
*p:字符串起始地址
**********************************************************/
void LCD_ShowString(uint x,uint y,uint For_color,uint Bk_color,char *p)
{
while(*p!='\0')
{
LCD_ShowChar(x,y,For_color,Bk_color,*p);
x+=16; //16是字体的宽度
p++;
}
}
lcd_driver.h
#define uchar unsigned char
#define uint unsigned int
#define Bus_16 //16位数据模式,如果使用8位模式,请注释此语句,如果使用16位模式,请打开此句
#define LCD_DataPortH P1 //高8位数据口,8位模式下只使用高8位
#define LCD_DataPortL P0 //低8位数据口 ,8位模式下低8位可以不接线
#define LCD_WR GPIO_Pin_2 //WR 引脚定义
#define LCD_RS GPIO_Pin_3 //RS 引脚定义
#define LCD_CS GPIO_Pin_4 //CS 引脚定义
#define LCD_RST GPIO_Pin_0 //RST 引脚定义
#define LCD_RD GPIO_Pin_1 //RD 引脚定义
#define LCD_SIZE_X 240
#define LCD_SIZE_Y 320
extern uint colors[];
void LCD_Init(void);
void LCD_ShowString(uint x,uint y,uint For_color,uint Bk_color,char *p);
void LCD_ShowChar(uint x,uint y,uint For_color,uint Bk_color, char ch);
void ChineseChar(uint x,uint y,int size,uint For_color,uint Bk_color ,char c);
void delayms(int count) ;
//void LCD_Writ_Bus(char VH,char VL);
void LCD_Writ_Bus( uint VH, uint VL);
void Lcd_Write_Com(char VH,char VL);
void Lcd_Write_Data(char VH,char VL);
void Lcd_Write_Com_Data(int com,int val);
void Pant(char VH,char VL);
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2);
chines.h ...
char.h ...