移植了一个c51驱动 tft1.8的屏的程序,但字符显示不了,哪位高手帮忙看看问题在哪
//
/***************************************************/
//#include<reg51.h>
//#include<absacc.h>
//#include<intrins.h>
#include "iom16v.h"
#include "macros.h"
#define uchar unsigned char
#define uint unsigned int
#define scl PB7 接模块CLK引脚
#define sda PB5 接模块DIN/MOSI引脚
#define bl PB0 接模块BL引脚,
#define rs PB1 接模块D/C引脚
#define cs PB2 接模块CE引脚
#define reset PB3 接模块RST引脚
//液晶屏接线
//定义常用颜色
#define RED 0xf800
#define GREEN 0x07e0
#define BLUE 0x001f
#define WHITE 0xffff
#define BLACK 0x0000
#define YELLOW 0xFFE0
#define GRAY0 0xEF7D
#define GRAY1 0x8410
#define GRAY2 0x4208
void delay(uint time)
{
uint i,j;
for(i=0;i<time;i++)
for(j=0;j<250;j++);
}
//向SPI总线传输一个8位数据
void SPI_WriteData(uchar Data)
{
unsigned char i=0;
for(i=8;i>0;i--)
{
if(Data&0x80)
PORTB|=BIT(sda);//sda=1; //输出数据
else PORTB&=~BIT(sda);//sda=0;
PORTB&=~BIT(scl);//scl=0;
PORTB|=BIT(scl);//scl=1;
Data<<=1;
}
}
//向液晶屏写一个8位指令
void Lcd_WriteIndex(uchar Data)
{
PORTB&=~BIT(cs);//cs=0;
PORTB&=~BIT(rs);//rs=0;
SPI_WriteData(Data);
PORTB|=BIT(cs);//cs=1;
}
//向液晶屏写一个8位数据
void Lcd_WriteData(uchar Data)
{
unsigned char i=0;
PORTB&=~BIT(cs);//cs=0;
PORTB|=BIT(rs);//rs=1;
SPI_WriteData(Data);
PORTB|BIT(cs);//cs=1;
}
//向液晶屏写一个16位数据
void Lcd_WriteData_16(unsigned int Data)
{
unsigned char i=0;
PORTB&=~BIT(cs);//cs=0;
PORTB|=BIT(rs);//rs=1;
SPI_WriteData(Data>>8); //写入高8位数据
SPI_WriteData(Data); //写入低8位数据
PORTB|=BIT(cs);//cs=1;
}
//LCD复位时序
void Reset()
{
PORTB&=~BIT(reset);//reset=0;
delay(100);
PORTB|=BIT(reset);//reset=1;
delay(100);
}
//////////////////////////////////////////////////////////////////////////////////////////////
//液晶屏初始化 for S6D02A1
void lcd_initial()
{ DDRB=0xff;
PORTB|=BIT(bl);
PORTB&=~BIT(reset);//reset=0;
delay(100);
PORTB|=BIT(reset);//reset=1;
delay(100);
Lcd_WriteIndex(0xf0);
Lcd_WriteData(0x5a);
Lcd_WriteData(0x5a);
Lcd_WriteIndex(0xfc);
Lcd_WriteData(0x5a);
Lcd_WriteData(0x5a);
Lcd_WriteIndex(0x26);
Lcd_WriteData(0x01);
Lcd_WriteIndex(0xfa);
Lcd_WriteData(0x02);
Lcd_WriteData(0x1f);
Lcd_WriteData(0x00);
Lcd_WriteData(0x10);
Lcd_WriteData(0x22);
Lcd_WriteData(0x30);
Lcd_WriteData(0x38);
Lcd_WriteData(0x3A);
Lcd_WriteData(0x3A);
Lcd_WriteData(0x3A);
Lcd_WriteData(0x3A);
Lcd_WriteData(0x3A);
Lcd_WriteData(0x3d);
Lcd_WriteData(0x02);
Lcd_WriteData(0x01);
Lcd_WriteIndex(0xfb);
Lcd_WriteData(0x21);
Lcd_WriteData(0x00);
Lcd_WriteData(0x02);
Lcd_WriteData(0x04);
Lcd_WriteData(0x07);
Lcd_WriteData(0x0a);
Lcd_WriteData(0x0b);
Lcd_WriteData(0x0c);
Lcd_WriteData(0x0c);
Lcd_WriteData(0x16);
Lcd_WriteData(0x1e);
Lcd_WriteData(0x30);
Lcd_WriteData(0x3f);
Lcd_WriteData(0x01);
Lcd_WriteData(0x02);
//////////////power setting sequence//////////
Lcd_WriteIndex(0xfd);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x17);
Lcd_WriteData(0x10);
Lcd_WriteData(0x00);
Lcd_WriteData(0x01);
Lcd_WriteData(0x01);
Lcd_WriteData(0x00);
Lcd_WriteData(0x1f);
Lcd_WriteData(0x1f);
Lcd_WriteIndex(0xf4);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x3f);
Lcd_WriteData(0x3f);
Lcd_WriteData(0x07);
Lcd_WriteData(0x00);
Lcd_WriteData(0x3C);
Lcd_WriteData(0x36);
Lcd_WriteData(0x00);
Lcd_WriteData(0x3C);
Lcd_WriteData(0x36);
Lcd_WriteData(0x00);
//delay_ms(80); //新增
Lcd_WriteIndex(0xf5);
Lcd_WriteData(0x00);
Lcd_WriteData(0x70);//39
Lcd_WriteData(0x66);//3a
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x6d);//38
Lcd_WriteData(0x66);//38
Lcd_WriteData(0x06);
Lcd_WriteIndex(0xf6);
Lcd_WriteData(0x02);
Lcd_WriteData(0x00);
Lcd_WriteData(0x3f);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x02);
Lcd_WriteData(0x00);
Lcd_WriteData(0x06);
Lcd_WriteData(0x01);
Lcd_WriteData(0x00);
Lcd_WriteIndex(0xf2);
Lcd_WriteData(0x00);
Lcd_WriteData(0x01);//04
Lcd_WriteData(0x03);
Lcd_WriteData(0x08);
Lcd_WriteData(0x08);
Lcd_WriteData(0x04);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x01);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x04);
Lcd_WriteData(0x08);
Lcd_WriteData(0x08);
Lcd_WriteIndex(0xf8);
Lcd_WriteData(0x11);//66
Lcd_WriteIndex(0xf7);
Lcd_WriteData(0xc8);
Lcd_WriteData(0x20);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteIndex(0xf3);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteIndex(0x11);
delay(50);
Lcd_WriteIndex(0xf3);
Lcd_WriteData(0x00);
Lcd_WriteData(0x01);
delay(50);
Lcd_WriteIndex(0xf3);
Lcd_WriteData(0x00);
Lcd_WriteData(0x03);
delay(50);
Lcd_WriteIndex(0xf3);
Lcd_WriteData(0x00);
Lcd_WriteData(0x07);
delay(50);
Lcd_WriteIndex(0xf3);
Lcd_WriteData(0x00);
Lcd_WriteData(0x0f);
delay(50);
Lcd_WriteIndex(0xf4);
Lcd_WriteData(0x00);
Lcd_WriteData(0x04);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x3f);
Lcd_WriteData(0x3f);
Lcd_WriteData(0x07);
Lcd_WriteData(0x00);
Lcd_WriteData(0x3C);
Lcd_WriteData(0x36);
Lcd_WriteData(0x00);
Lcd_WriteData(0x3C);
Lcd_WriteData(0x36);
Lcd_WriteData(0x00);
delay(50);
Lcd_WriteIndex(0xf3);
Lcd_WriteData(0x00);
Lcd_WriteData(0x1f);
delay(50);
Lcd_WriteIndex(0xf3);
Lcd_WriteData(0x00);
Lcd_WriteData(0x7f);
delay(50);
Lcd_WriteIndex(0xf3);
Lcd_WriteData(0x00);
Lcd_WriteData(0xff);
delay(50);
Lcd_WriteIndex(0xfd);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x17);
Lcd_WriteData(0x10);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x01);
Lcd_WriteData(0x00);
Lcd_WriteData(0x16);
Lcd_WriteData(0x16);
Lcd_WriteIndex(0xf4);
Lcd_WriteData(0x00);
Lcd_WriteData(0x09);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x3f);
Lcd_WriteData(0x3f);
Lcd_WriteData(0x07);
Lcd_WriteData(0x00);
Lcd_WriteData(0x3C);
Lcd_WriteData(0x36);
Lcd_WriteData(0x00);
Lcd_WriteData(0x3C);
Lcd_WriteData(0x36);
Lcd_WriteData(0x00);
/////////////initializing sequence/////////////
Lcd_WriteIndex( 0x36);
Lcd_WriteData( 0x08);
Lcd_WriteIndex(0x35);
Lcd_WriteData(0x00);
Lcd_WriteIndex(0x3a);
Lcd_WriteData(0x05);
/////////////////gamma setting sequence/////////
delay(150);
Lcd_WriteIndex(0x29);
Lcd_WriteIndex(0x2c);
}
void Lcd_SetWindow(uint starx,uint stary,uint endx,uint endy)
{
Lcd_WriteIndex(0x2A);
Lcd_WriteData(starx>>8);
Lcd_WriteData(starx);
Lcd_WriteData(endx>>8);
Lcd_WriteData(endx);
Lcd_WriteIndex(0x2B);
Lcd_WriteData(stary>>8);
Lcd_WriteData(stary);
Lcd_WriteData(endy>>8);
Lcd_WriteData(endy);
Lcd_WriteIndex(0x2c);
}
void PutPixel(uint x_start,uint y_start,uint color)
{
Lcd_SetWindow(x_start,y_start,x_start+1,y_start+1);
Lcd_WriteData_16(color);
}
//全屏填充函数
void LCD_Clear(unsigned int Color)
{
uchar i,j;
Lcd_WriteIndex(0x2C);
for (i=0;i<160;i++)
for (j=0;j<128;j++)
Lcd_WriteData_16(Color);
}
void Display_Desc()
{
Display_ASCII8X16(1,80,"123456789");
Display_ASCII8X16(1,92,"2014.04.14");
}
//显示一个英文字符
void Display_ASCII8X16(uint x0,uint y0,uchar *s)
{
int i,j,k,x,y,xx;
unsigned char qm;
long int ulOffset;
char ywbuf[32],temp[2];
for(i = 0; i<strlen((char*)s);i++)
{
if(((unsigned char)(*(s+i))) >= 161)
{
temp[0] = *(s+i);
temp[1] = '\0';
return;
}
else
{
qm = *(s+i);
ulOffset = (long int)(qm) * 16;
for (j = 0; j < 16; j ++)
{
ywbuf[j]=Zk_ASCII8X16[ulOffset+j];
}
for(y = 0;y < 16;y++)
{
for(x=0;x<8;x++)
{
k=x % 8;
if(ywbuf[y]&(0x80 >> k))
{
xx=x0+x+i*8;
PutPixel(xx,y+y0,RED);
}
}
}
}
}
}
main()
{
lcd_initial();
PORTB|=BIT(bl);//bl=1;//背光采用IO控制
delay(500);
LCD_Clear(GREEN); //绿色
delay(500);
Display_Desc();
}
|