本人初学STM32,想尝试点亮2.4TFT,程序是从C51转换过来的,编译没有问题,但是下载STM32中始终是一片白板,弄了一整天也没点起 {MOD},实在是解决不了,所以想请哪位前辈帮我看看我的代码!指点指点,非常感谢!
//GPIO配置
void GPIO_Configura
tion(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //定义GPIO(结构体)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC,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(GPIOA, &GPIO_InitStructure);
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_SetBits(GPIOA,GPIO_Pin_All);
GPIO_SetBits(GPIOB,GPIO_Pin_All);
GPIO_SetBits(GPIOC,GPIO_Pin_All);
}
int main()
{
RCC_Configuration();
GPIO_Configuration();
delay_init(72); //72M晶振
ILI9325_Initial(); //初始化LCD
while(1)
{
CLR_Screen(Red); //用背景 {MOD}清屏
CLR_Screen(Green); //用背景 {MOD}清屏
CLR_Screen(Blue); //用背景 {MOD}清屏
}
}
#include"9325tp.h"
/*----------------------------------------------------------------
定义硬件端口
----------------------------------------------------------------*/
#define RW PAout(12)//读写
#define RS PAout(11)//数据命令
#define RES PBout(7)//复位
#define CS PBout(8)//片选
unsigned char pic[];
/*----------------------------------------------------------------
清屏函数
输入参数:bColor 清屏所使用的背景 {MOD}
----------------------------------------------------------------*/
void CLR_Screen(unsigned int bColor)
{
unsigned int i,j;
LCD_SetPos(0,240,0,320);//320x240
for (i=0;i<320;i++)
{
for (j=0;j<240;j++)
Write_Data_U16(bColor);
}
}
/*----------------------------------------------------------------
写命令、写数据
输入参数:x 需要输入的命令 16位
y 需要输入的数据 16位
----------------------------------------------------------------*/
void Write_Cmd_Data (unsigned char x,unsigned int y)
{
unsigned char m,n;
m=y>>8;
n=y;
Write_Cmd(0x00,x);
Write_Data(m,n);
}
/*----------------------------------------------------------------
写16位数据
----------------------------------------------------------------*/
void Write_Data_U16(unsigned int y)
{
unsigned char m,n;
m=y>>8;
n=y;
Write_Data(m,n);
}
/*----------------------------------------------------------------
写命令
----------------------------------------------------------------*/
void Write_Cmd(unsigned char DH,unsigned char DL)
{
u16 temp;
CS=0;
RS=0;
temp=GPIOA->ODR&0xff00+(u16)DH;//不能改变高位的数据
GPIO_Write(GPIOA, temp);
RW=0;
RW=1;
temp=GPIOA->ODR&0xff00+(u16)DL;//不能改变高位的数据
GPIO_Write(GPIOA, temp);
RW=0;
RW=1;
CS=1;
}
/*----------------------------------------------------------------
写数据 双8位
----------------------------------------------------------------*/
void Write_Data(unsigned char DH,unsigned char DL)
{
u16 temp;
CS=0;
RS=1;
temp=GPIOA->ODR&0xff00+(u16)DH;//不能改变高位的数据
GPIO_Write(GPIOA, temp);
RW=0;
RW=1;
temp=GPIOA->ODR&0xff00+(u16)DL;//不能改变高位的数据
GPIO_Write(GPIOA, temp);
RW=0;
RW=1;
CS=1;
}
/*----------------------------------------------------------------
液晶初始化
----------------------------------------------------------------*/
void ILI9325_Initial(void)
{
CS=1;
delay_ms(5);
RES=0;
delay_ms(5);
RES=1;
delay_ms(5);
delay_ms(50);
Write_Cmd_Data(0x0001,0x0100);
Write_Cmd_Data(0x0002,0x0700);
Write_Cmd_Data(0x0003,0x1030);
Write_Cmd_Data(0x0004,0x0000);
Write_Cmd_Data(0x0008,0x0207);
Write_Cmd_Data(0x0009,0x0000);
Write_Cmd_Data(0x000A,0x0000);
Write_Cmd_Data(0x000C,0x0000);
Write_Cmd_Data(0x000D,0x0000);
Write_Cmd_Data(0x000F,0x0000);
//power on sequence VGHVGL
Write_Cmd_Data(0x0010,0x0000);
Write_Cmd_Data(0x0011,0x0007);
Write_Cmd_Data(0x0012,0x0000);
Write_Cmd_Data(0x0013,0x0000);
//vgh
Write_Cmd_Data(0x0010,0x1290);
Write_Cmd_Data(0x0011,0x0227);
//delay_ms(100);
//vregiout
Write_Cmd_Data(0x0012,0x001d); //0x001b
//delay_ms(100);
//vom amplitude
Write_Cmd_Data(0x0013,0x1500);
//delay_ms(100);
//vom H
Write_Cmd_Data(0x0029,0x0018);
Write_Cmd_Data(0x002B,0x000D);
//gamma
Write_Cmd_Data(0x0030,0x0004);
Write_Cmd_Data(0x0031,0x0307);
Write_Cmd_Data(0x0032,0x0002);// 0006
Write_Cmd_Data(0x0035,0x0206);
Write_Cmd_Data(0x0036,0x0408);
Write_Cmd_Data(0x0037,0x0507);
Write_Cmd_Data(0x0038,0x0204);//0200
Write_Cmd_Data(0x0039,0x0707);
Write_Cmd_Data(0x003C,0x0405);// 0504
Write_Cmd_Data(0x003D,0x0F02);
//ram
Write_Cmd_Data(0x0050,0x0000);
Write_Cmd_Data(0x0051,0x00EF);
Write_Cmd_Data(0x0052,0x0000);
Write_Cmd_Data(0x0053,0x013F);
Write_Cmd_Data(0x0060,0xA700);
Write_Cmd_Data(0x0061,0x0001);
Write_Cmd_Data(0x006A,0x0000);
//
Write_Cmd_Data(0x0080,0x0000);
Write_Cmd_Data(0x0081,0x0000);
Write_Cmd_Data(0x0082,0x0000);
Write_Cmd_Data(0x0083,0x0000);
Write_Cmd_Data(0x0084,0x0000);
Write_Cmd_Data(0x0085,0x0000);
//
Write_Cmd_Data(0x0090,0x0010);
Write_Cmd_Data(0x0092,0x0600);
Write_Cmd_Data(0x0093,0x0003);
Write_Cmd_Data(0x0095,0x0110);
Write_Cmd_Data(0x0097,0x0000);
Write_Cmd_Data(0x0098,0x0000);
Write_Cmd_Data(0x0007,0x0133);
// Write_Cmd_Data(0x0022);//
}
/*----------------------------------------------------------------
设置坐标
----------------------------------------------------------------*/
static void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1)
{
Write_Cmd_Data(WINDOW_XADDR_START,x0);
Write_Cmd_Data(WINDOW_XADDR_END,x1);
Write_Cmd_Data(WINDOW_YADDR_START,y0);
Write_Cmd_Data(WINDOW_YADDR_END,y1);
Write_Cmd_Data(GRAM_XADDR,x0);
Write_Cmd_Data(GRAM_YADDR,y0);
Write_Cmd (0x00,0x22);//LCD_WriteCMD(GRAMWR);
}
怎么和我一样一样的
http://bbs.elecfans.com/forum.ph ... line%26typeid%3D806
一周热门 更多>