驱动SPFD5420A的液晶显示程序,想清屏,结果屏幕毫无反应,求解啊~~~~
#ifndef LCM_H_#define LCM_H_
#include "../inc/sopc.h"
#include "system.h"
//********************LCM--GUI***************************//
//***********************徐同庆***************************//
//************底层文件,是GUI文件的基础文件*******************//
//****************2010年7月23日***************************//
//============================================================
//根据芯片资料定义
#define WINDOW_XADDR_START0x0210 // Horizontal Start Address Set
#define WINDOW_XADDR_END 0x0211 // Horizontal End Address Set
#define WINDOW_YADDR_START0x0212 // Vertical Start Address Set
#define WINDOW_YADDR_END 0x0213 // Vertical End Address Set
#define GRAM_XADDR 0x0200 // GRAM Horizontal Address Set
#define GRAM_YADDR 0x0201 // GRAM Vertical Address Set
#define GRAMWR 0x0202 // memory write
#define GUI_LCM_YMAX 399
#define GUI_LCM_XMAX 239
/*颜色数值:红色,绿色,蓝色,黄色,黑色,白色,天蓝色,紫色*/
unsigned int color[]={0xf800,0x07e0,0x001f,0xffe0,0x0000,0xffff,0x07ff,0xf81f};
//=============================================================
//函数声明
void initial();//TFT初始化
void write_command(unsigned int com);//写命令
void write_data(unsigned int dat);//写数据
void write_cmd_data (unsigned int com,unsigned int dat);//写命令数据
void setwindow(unsigned int x0,unsigned int y0,unsigned int x1,unsigned int y1);//设置窗口
void setxy(unsigned char x,unsigned int y);//设定当前显示坐标
void test();//彩条、单色自测程序
void write_command(unsigned int com)
{
RS->DATA=1;
DB_PIO->DATA=com;
usleep(5);
WR->DATA=0;
usleep(5);
WR->DATA=1;
}
void write_data(unsigned int dat)
{
RS->DATA=0;
DB_PIO->DATA=dat;
usleep(5);
WR->DATA=0;
usleep(5);
WR->DATA=1;
}
void write_cmd_data(unsigned int com,unsigned int dat)
{
write_command(com);
write_data(dat);
}
//===================setwindow============================//
void setwindow(unsigned int x0,unsigned int y0,unsigned int x1,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);//设置X坐标位置
write_cmd_data(GRAM_YADDR,y0);//设置Y坐标位置
write_command(GRAMWR);//LCD_WriteCMD(GRAMWR);
}
//说明:本函数实际上是LCD_setwindow函数的一个特例,显示窗口为最小,仅是一个像素点。
void setxy(unsigned char x,unsigned int y)
{
setwindow(x,y,x,y);
}
//彩条、单色自测程序
//入口参数: 无。
//出口参数: 无
//说明:在TFT屏上轮流显示彩条和各种颜色的单色屏幕。
void test()
{
unsigned int temp,num;
unsigned char n,c;
//显示彩条
setwindow(0,0,239,399);
for(n=0;n<8;n++)
{
temp=color;
for(num=40*240;num>0;num--)
write_data(temp);
}
usleep(100000);
//显示单色彩色
for(c=0;c<8;c++)
{
temp = color;
setwindow(0,0,239,319);
for(n=0;n<240;n++)
{
for(num=0;num<320;num++)
write_data(temp);
}
usleep(100000);
}
}
void initial()
{
write_cmd_data(0x0606,0x0000);
usleep(10);
write_cmd_data(0x0007,0x0001);
usleep(10);
write_cmd_data(0x0110,0x0001);
usleep(10);
write_cmd_data(0x0100,0x17B0);
write_cmd_data(0x0101,0x0147);
write_cmd_data(0x0102,0x019D);
write_cmd_data(0x0103,0x3600);
write_cmd_data(0x0281,0x0010);
usleep(10);
write_cmd_data(0x0102,0x01BD);
usleep(10);
write_command(0x000);write_data(0x0000);
write_command(0x001);write_data(0x0000);
write_command(0x002);write_data(0x0100);
write_command(0x003);write_data(0xD0A0);
write_command(0x008);write_data(0x0503);
write_command(0x009);write_data(0x0001);
write_command(0x00B);write_data(0x0010);
write_command(0x00C);write_data(0x0000);
write_command(0x00F);write_data(0x0000);
write_command(0x007);write_data(0x0001);
write_command(0x010);write_data(0x0013);
write_command(0x011);write_data(0x0202);
write_command(0x012);write_data(0x0300);
write_command(0x020);write_data(0x021E);
write_command(0x021);write_data(0x0202);
write_command(0x022);write_data(0x0100);
write_command(0x090);write_data(0x8000);
write_command(0x100);write_data(0x16B0);
write_command(0x101);write_data(0x0147);
write_command(0x102);write_data(0x01BD);
write_command(0x103);write_data(0x2A00);
write_command(0x107);write_data(0x0000);
write_command(0x110);write_data(0x0001);
//X,Ystart
write_command(0x210);write_data(0x0000);
write_command(0x211);write_data(0x00EF);
write_command(0x212);write_data(0x0000);
write_command(0x213);write_data(0x018F);
//X,Y end
write_command(0x280);write_data(0x0000);
write_command(0x281);write_data(0x000E);
write_command(0x282);write_data(0x0000);
write_command(0x300);write_data(0x0101);
write_command(0x301);write_data(0x0B2C);
write_command(0x302);write_data(0x1030);
write_command(0x303);write_data(0x3010);
write_command(0x304);write_data(0x2C0B);
write_command(0x305);write_data(0x0101);
write_command(0x306);write_data(0x0807);
write_command(0x307);write_data(0x0708);
write_command(0x308);write_data(0x0107);
write_command(0x309);write_data(0x0105);
write_command(0x30A);write_data(0x0F04);
write_command(0x30B);write_data(0x0F00);
write_command(0x30C);write_data(0x000F);
write_command(0x30D);write_data(0x040F);
write_command(0x30E);write_data(0x0501);
write_command(0x30F);write_data(0x0701);
write_command(0x400);write_data(0x3500);
write_command(0x401);write_data(0x0001);
write_command(0x404);write_data(0x0000);
write_command(0x500);write_data(0x0000);
write_command(0x501);write_data(0x0000);
write_command(0x502);write_data(0x0000);
write_command(0x503);write_data(0x0000);
write_command(0x504);write_data(0x0000);
write_command(0x505);write_data(0x0000);
write_command(0x606);write_data(0x0000);
write_command(0x6F0);write_data(0x0000);
//不是说下面的Register都不能用吗?怎么又有初始化了?
// write_command(0x7F0);write_data(0x5420);
// write_command(0x7F3);write_data(0x288A);
// write_command(0x7F4);write_data(0x0022);
// write_command(0x7F5);write_data(0x0041);
// write_command(0x7F0);write_data(0x0000);
//**********************************************
write_command(0x007);write_data(0x0173);
}
#endif /*LCM_H_*/ 回复【楼主位】xtqxtq111
-----------------------------------------------------------------------
//**********一个高级文件,可以引用里面各式各样的函数****************//
//徐同庆 //
//2010/7/23 //
#ifndef GUI_H_
#define GUI_H_
#include "../inc/LCM.h"
unsigned char font16x8[]={};
/*GUI函数*/
void GUI_clearscreen(unsigned int b_color);//清屏
void GUI_Point(unsigned char x, unsigned int y, unsigned int color);//画点
void GUI_HLine(unsigned char x, unsigned int y, unsigned char length, unsigned int color);//画横线
void GUI_RLine(unsigned char x, unsigned int y, unsigned inthigh, unsigned int color);//画竖线
void GUI_line(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2,unsigned int color);//画直线
void GUI_DisPicture(unsigned char x, unsigned int y, unsigned char length, unsigned int high,unsigned char pic[]);//显示图片(图标)
void GUI_sprintf_char(unsigned char x, unsigned int y,unsigned char c, unsigned int color,unsigned int b_color);//显示英文或数字字符
void GUI_sprintf_string(unsigned char x, unsigned int y,char*s, unsigned int color,unsigned int b_color);//显示英文字符串
void GUI_sprintf_HZ(unsigned char x, unsigned int y, unsigned int color,unsigned int b_color,unsigned char china_char[]);//显示预定义汉字字符串
void GUI_box(unsigned char sx,unsigned int sy,unsigned char ex,unsigned int ey,unsigned int color);//画实心矩形
void GUI_rectangle( unsigned char sx,unsigned int sy,unsigned char ex,unsigned int ey,unsigned int color);//画空心矩形
void GUI_wrul(unsigned char x, unsigned int y, unsigned long num, unsigned int color,unsigned int b_color);//以十进制形式显示无符号长整型数
void GUI_wrlval(unsigned char x, unsigned int y,unsigned long num,unsigned char bits,unsigned char dp,unsigned int color,unsigned int b_color);//以十进制形式显示长变量
unsigned int RGB(unsigned char R,unsigned char G,unsigned char B);//RGB颜色混合
/*定义常用颜色的颜色码*/
#define RED 0xf800//红
#define YELLOW 0xffe0//黄
#define GREEN0x07e0//绿
#define CYAN 0x07ff//青
#define BLUE 0x001f//蓝
#define PURPLE 0xf81f//紫
#define BLACK0x0000//黑
#define WHITE0xffff//白
#define GRAY 0x7bef//灰
/************************************
清屏
入口参数: b_color是背景颜色。
出口参数: 无
说明:使用背景颜色清除TFT模块屏幕的全部显示内容。
*************************************/
void GUI_clearscreen(unsigned int b_color)
{
unsigned int i,j;
setwindow(0,0,239,399);
for (i=0;i<400;i++)
{
for(j=0;j<240;j++)
write_data(b_color);
}
}
/*********************************************
画点
入口参数: (x,y)是点的坐标,color 是点的颜色。
出口参数: 无
说明:用指定的颜色在指定的坐标位置上画出一个点。
**********************************************/
void GUI_Point(unsigned char x, unsigned int y, unsigned int color)
{
setxy(x,y);
write_data(color);
}
/**********************************************************
画横线
入口参数: (x,y)是横线起点坐标,length是横线长度,color 是横线颜色。
出口参数: 无
说明:用指定的颜色在指定位置上画出指定长度的一条横线。
************************************************************/
void GUI_HLine(unsigned char x, unsigned int y, unsigned char length, unsigned int color)
{
setwindow(x,y,x+length-1,y);
do
{
write_data(color);//逐点显示,描出水平线
length--;
}while(length);
}
/**********************************************************
画竖线
入口参数: (x,y)是竖线起点坐标,high 竖线高度,color 是竖线颜色。
出口参数: 无
说明:用指定的颜色在指定位置上画出指定长度的一条竖线。
************************************************************/
void GUI_RLine(unsigned char x, unsigned int y, unsigned int high, unsigned int color)
{
setwindow(x,y,x,y+high-1);
do
{
write_data(color);// 逐点显示,描出垂直线
high--;
}while(high);
}
/********************************************************************
画直线(可以画任意方向直线,包括横线、竖线、斜线)。
入口参数: (x1,y1)起点, (x2,y2)终点, color颜色。
出口参数: 无
说明:用指定的颜色在指定的两点间画出一条直线。
***********************************************************************/
void GUI_line(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2,unsigned int color)
{
unsigned int t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy;
unsigned int row,col;
delta_x = x2-x1;//计算坐标增量
delta_y = y2-y1;
col=x1;
row=y1;
if(delta_x>0) incx=1;//设置单步方向
else
{
if(delta_x==0) incx=0;//垂直线
else {incx=-1;delta_x=-delta_x;}
}
if(delta_y>0)incy=1;
else
{
if(delta_y==0) incy=0;//水平线
else {incy=-1;delta_y=-delta_y;}
}
if(delta_x>delta_y) distance=delta_x;//选取基本增量坐标轴
else distance=delta_y;
for(t=0;t<=distance+1;t++)
{ //画线输出
GUI_Point(col, row, color);
xerr+=delta_x;
yerr+=delta_y;
if(xerr>distance)
{
xerr-=distance;
col+=incx;
}
if(yerr>distance)
{
yerr-=distance;
row+=incy;
}
}
}
/**********************************************************
显示图片(图标)
入口参数:(x,y)是开始点的坐标,length是图片长度,high是图片高度。//pic 图片数组的指针
出口参数: 无
说明:用指定位置上显示事先定义的图片。
要显示的图片事先定义在bmp.h中的pic[]数组中,
如果想修改图片大小、内容,请修改bmp.h中的pic[]数组,
建议用Image2Lcd软件将你要显示的图象自动转换为数组数据。
************************************************************/
//void GUI_DisPicture(uchar x, uint y, uchar length, uint high ,const uchar *pic)
void GUI_DisPicture(unsigned char x, unsigned int y, unsigned char length, unsigned int high,unsigned char pic[])
{
unsigned int temp=0,tmp=0,num=0;
setwindow(x,y,x+length-1,y+high-1);
num=length*high*2;
do
{
//temp=pic|( pic<<8);
temp=pic;
temp=temp<<8;
temp=temp|pic;
write_data(temp);//逐点显示
tmp+=2;
}while(tmp<num);
}
/*********************************************
显示英文或数字字符
入口参数:(x,y) 是显示内容的左上角坐标,c:显示的英文字符,
color:颜色,b_color:背景颜色。
出口参数: 无
说明:用指定位置上显示单个英文字符或数字字符。
**********************************************/
void GUI_sprintf_char(unsigned char x, unsigned int y,unsigned char c, unsigned int color,unsigned int b_color)
{
unsigned chars_x ,s_y, temp ;
unsigned int j;
c -= 32;
for( s_y=0 ; s_y < 16 ; s_y++ )
{
if(s_y+y<400)
{
j=c;
j=j*16+s_y;
temp=font16x8;
//temp = font16x8 ;
for( s_x=0 ; s_x<8 ; s_x++ )
{
if(x+s_x<240)
{
if((temp&(0x80>>(s_x))) == (0x80>>(s_x)))
{
GUI_Point(x+s_x, y+s_y,color) ;
}
else
{
GUI_Point(x+s_x, y+s_y,b_color) ;
}
}
}
}
}
}
/*********************************************
显示英文字符串
入口参数:(x,y) 是显示内容的左上角坐标,*s:英文字符串指针,
color:颜色,b_color:背景颜色。
出口参数: 无
说明:在指定位置上显示英文字符串。
**********************************************/
void GUI_sprintf_string(unsigned char x, unsigned int y,char*s, unsigned int color,unsigned int b_color)
{
for(s=0;*s!='\0';s++)
{
GUI_sprintf_char(x, y, *s, color,b_color);
x=x+8;
}
}
/*********************************************
显示预定义汉字字符串
入口参数:(x,y) 是显示内容的左上角坐标,color:颜色,b_color:背景颜色。
出口参数: 无
说明:在指定位置上显示预定义的中文字符串。
要显示的中文字符串事先定义在chinese.h中的china_char[]数组中,
如果想修改中文字符串长度、内容,请修改chinese.h中的
china_char[]数组,建议用字模提取软件zimoV2.2将你要显示的
中文字符串自动转换为数组数据。
**********************************************/
void GUI_sprintf_HZ(unsigned char x, unsigned int y, unsigned int color,unsigned int b_color,unsigned char china_char[] )
{
unsigned chars_x=0 ,s_y=0, temp=0 ;
unsigned char n;
unsigned int j,words;
words=sizeof(china_char)/32;
for( n=0 ; n<words ; n++ )
{
for( s_x=0 ; s_x<16 ; s_x++ )
{
if(s_x+x<240)
{
j=n;
j=j*32+s_x;
temp = china_char ;
//temp = china_char ;
for( s_y=0 ; s_y<8 ; s_y++ )
{
if(y+s_y<400)
{
if((temp&(0x80>>(s_y))) == (0x80>>(s_y)))
{
GUI_Point(x+s_x+n*16, y+s_y,color) ;
}
else
{
GUI_Point(x+s_x+n*16, y+s_y,b_color) ;
}
}
}
}
}
for( s_x=0 ; s_x<16 ; s_x++ )
{
if(s_x+x<240)
{
j=n;
j=j*32+s_x+16;
temp = china_char ;
//temp = china_char ;
for( s_y=0 ; s_y<8 ; s_y++ )
{
if(y+s_y<400)
{
if((temp&(0x80>>(s_y))) == (0x80>>(s_y)))
{
GUI_Point(x+s_x+n*16, y+s_y+8,color) ;
}
else
{
GUI_Point(x+s_x+n*16, y+s_y+8,b_color) ;
}
}
}
}
}
}
}
/*********************************************
画实心矩形
入口参数: (sx,sy)左上角顶点坐标, (ex,ey)右下角顶点坐标, color颜色
出口参数: 无
说明:在指定位置上画出实心矩形。
**********************************************/
void GUI_box(unsigned char sx,unsigned int sy,unsigned char ex,unsigned int ey,unsigned int color)
{
unsigned int temp;
setwindow(sx,sy,ex,ey);
sx=ex-sx+1;
sy=ey-sy+1;
while(sx--)
{
temp=sy;
while(temp--)
{
write_data(color);
}
}
}
/*********************************************
画空心矩形
入口参数: (sx,sy)左上角顶点坐标, (ex,ey)右下角顶点坐标, color颜色
出口参数: 无
说明:在指定位置上画出空心矩形。
**********************************************/
void GUI_rectangle( unsigned char sx,unsigned int sy,unsigned char ex,unsigned int ey,unsigned int color)
{
GUI_line(sx,sy,ex,sy,color);
GUI_line(sx,sy,sx,ey,color);
GUI_line(ex,sy,ex,ey,color);
GUI_line(sx,ey,ex,ey,color);
}
/*********************************************
以十进制形式显示无符号长整型数
入口参数:(x,y) 是显示内容的右上角坐标;
num是欲显示的无符号长整型数
num的数值范围为:0~4,294,967,295(十进制),
也就是说利用该函数,我们最多将一个10位十进制数显示在LCD屏上;
color:颜色,b_color:背景颜色。
出口参数: 无
说明:将一个无符号长整型数以十进制形式显示在TFT屏上。
注意:在使用该函数时,不论最终显示的数有几位,它都将在LCD屏幕上
占10个字符的空间(显示的多位十进制数不足10位时,
本函数会在有效显示数字前面补空格)。
**********************************************/
void GUI_wrul(unsigned char x, unsigned int y, unsigned long num, unsigned int color,unsigned int b_color)
{
unsigned long temp;
unsigned char i;
for(i=0;i<10;i++)
{
if(num!=0)
{
temp=num/10;
GUI_sprintf_char(x-7,y,num-temp*10+'0',color,b_color);
num=temp;
}
else/*往前写满10位,也就是前面都写空格*/
{
GUI_sprintf_char(x-7,y,' ',color,b_color);
}
x=x-8;/*设置光标在文字插入后自动左移*/
}
}
/*********************************************
以十进制形式显示长变量
入口参数:
x,y ----是显示内容的右上角坐标
num ----欲显示的长变量
bits ----允许显示的位数
dp ----小数点位置
color ----颜色
b_color ----背景颜色
出口参数: 无
说明:
将一个长变量的数值以十进制形式显示在TFT屏上,可以根据需要确定
是否显示小数点以及小数点位置,也可以确定在TFT屏幕上显示的位数。
注意:
1、要显示的数据比规定的显示位数多,规定的位全部写-,表示数据溢出。
2、本函数实际上相当于GUI_wrul函数的增强版,如果我们指定bits=10 dp=0,
如下所示:
GUI_wrlval(20,239,tp,10,0,WHITE,BLACK);
那么,其作用和GUI_wrul函数完全一样。
**********************************************/
void GUI_wrlval(unsigned char x, unsigned int y,unsigned long num,unsigned char bits,unsigned char dp,unsigned int color,unsigned int b_color)
{
char str;/*无符号长整型数转换为字符串是10个,所以需要10个单元存储*/
unsigned long temp;
unsigned char i;
//LCD_wrcmd(CUR_AUTO_L);/*设置光标在文字插入后自动左移*/
for(i=0;i<bits;i++)
{
if(num!=0)
{
temp=num/10;
str=num-temp*10+'0';
num=temp;
}
else/*往前写*/
{
if(i>=dp)str=0x20;/*小数点前零都变空格*/
else str='0';/*小数点后零保留*/
}
}
i=0;
if (num!=0)/*要显示的数据比规定的显示位数多,数据显示溢出*/
{
while(i<bits)/*往前写满规定的位数,也就是前面都写空格,直到规定的位数*/
{
GUI_sprintf_char(x-7,y,'-',color,b_color);/*规定的位全部写-,表示数据溢出*/
i++;
x=x-8;
if (i==dp)
{
GUI_sprintf_char(x-7,y,'.',color,b_color);/*插入小数点*/
x=x-8;
}
}
}
else
{
while(i<bits)/*显示前面的有效数字*/
{
if ((i==dp)&(str==0x20))
{
GUI_sprintf_char(x-7,y,'.',color,b_color);/*插入小数点*/
x=x-8;
GUI_sprintf_char(x-7,y,'0',color,b_color);/*小数点前为0时要补写0*/
x=x-8;
}
else
{
if ((i==dp)&(i!=0))
{
GUI_sprintf_char(x-7,y,'.',color,b_color);/*插入小数点*/
x=x-8;
}
GUI_sprintf_char(x-7,y,str,color,b_color);
x=x-8;
}
i++;
}
}
}
/*********************************************
RGB颜色混合
入口参数:R(红色分量)0-255,G(绿色分量)0-255,B(蓝色分量)0-255
出口参数: 按R5-G6-B5格式混合后的16位颜色码。
说明:将电脑上常见的R8-G8-B8格式转换成8位单片机常用的R5-G6-B5格式。
**********************************************/
unsigned int RGB(unsigned char R,unsigned char G,unsigned char B)
{
return((uint)(R&0XF8)<<8|(uint)(G&0XFC)<<3|(uint)(B&0XF8)>>3);
}
#endif /*GUI_H_*/ 回复【1楼】xtqxtq111
-----------------------------------------------------------------------
#include <stdio.h>
#include <unistd.h>
#include "../inc/sopc.h"
#include "../inc/GUI.h"
int main()
{
initial();
GUI_clearscreen(RED);
return 0;
} 很好,谢谢了 xtqxtq111 发表于 2011-7-24 09:26 static/image/common/back.gif
回复【楼主位】xtqxtq111
-----------------------------------------------------------------------
我买了一块学习板,里面的3寸液晶的控制器也是SPFD5420A,也碰到很多问题,我连一副图片都显示不出来,你可以帮帮我么? 我现在刚刚开始学,可是写了一周连图片不显示不出来,你可以教教我么,不胜感激
页:
[1]