目的是让LCD全亮.VT1335这个驱动芯片的好处在于只有四个寄存器,软件设计起来比较方便.
编程采用IO口模拟时序的方法;
用STC89C58RD+ 点亮TV1335驱动的Sharp LCD(320*240).因为手头上有个去年买的51开发板,加上办公室有一个闲置的Sharp LCD.所以就想这样做.
#include <reg52.h> //调用头文件(单片机内部的寄存器定义)
sbit LCD_RD = P0 ^ 0;
sbit LCD_WR = P0 ^ 1;
sbit LCD_CS = P0 ^ 2;
sbit LCD_A0 = P0 ^ 3;
sbit LCD_A1 = P0 ^ 4;
sbit P2_0 = P2 ^ 0;
sbit P2_1 = P2 ^ 1;
sbit P2_2 = P2 ^ 2;
sbit P2_3 = P2 ^ 3;
sbit P2_4 = P2 ^ 4;
sbit P2_5 = P2 ^ 5;
sbit P2_6 = P2 ^ 6;
sbit P2_7 = P2 ^ 7;
#define LCD_DATA P2 //LCD
/**************************************************
** 函数名称: Delay
** 入口参数:h(unsigned int型)
** 出口参数:无
** 功能描述: 短暂延时,使用11.0592晶体,约0.01MS
****************************************************/
void Delay(unsigned int h)
{
while(h--); //0.01MS
}
void lcd_W() //产生写的下沿
{
LCD_CS = 0;
LCD_WR = 1;
LCD_RD = 1;
Delay(10);
LCD_WR = 0;// write 控制
Delay(10);
LCD_WR = 1;
}
void lcd_Wdata(unsigned char i) //写数据
{
LCD_A0 = 1; //A1A0 = 11 W or R
LCD_A1 = 1;
P2=i;
lcd_W();
}
void lcd_disp_on_off(unsigned char i) //开关显示
{
LCD_A0 = 0; //A1A0 = 10 控制寄存器
LCD_A1 = 1;
if(i==0) P2_2=0; //off
else P2_2=1; //on
lcd_W();
}
void lcd_RWpage (unsigned char i) //读写页号
{
LCD_CS = 0;
LCD_A0 = 0; //A1A0 = 10 控制寄存器
LCD_A1 = 1;
if(i==0) P2_0 = 0;//读写0页 P_wr
else P2_0 = 1 ;
lcd_W();
}
void lcd_disp_page (unsigned char i) //显示页号
{
LCD_A0 = 0; //A1A0 = 10 控制寄存器
LCD_A1 = 1;
if(i==0) P2_1 = 0; //显示0页 P_wr
else P2_1 = 1;
lcd_W();
}
void lcd_inc_dir(unsigned char i) //地址自动增量方向
{
LCD_A0 = 0; //A1A0 = 10 控制寄存器
LCD_A1 = 1;
if(i==0) P2_3 = 0; //x+1
else P2_3 = 1; //y+1
lcd_W();
}
void x_addr(unsigned char i) //列地址输出
{
LCD_A0 = 0; //A1A0 = 00 X_ADDR
LCD_A1 = 0;
P2=i;
lcd_W();
}
void y_addr(unsigned char i) //行地址输出
{
LCD_A0 = 1; //A1A0 = 01 Y_ADDR
LCD_A1 = 0;
P2=i;
lcd_W();
}
void lcd_w_rang(unsigned char page,
unsigned char X1,unsigned char Y1, //x1,x2为0-39
unsigned char X2,unsigned char Y2, //yi,y2为0-239
unsigned char bright_black, //1为点亮
unsigned char inc_dir) //inc_dir=0为x加1//建议在写图片数据时,设置Inc_dir=0//在写汉字或字母时,设置Inc_dir=1。
{
unsigned char i,j;
LCD_CS = 0;
lcd_disp_on_off(1);
lcd_disp_page(page);
lcd_RWpage(page);
lcd_inc_dir(inc_dir);
if(inc_dir==0) //x+1方向
{
for ( i = Y1; i<=Y2; i++ )
{
x_addr(X1);
y_addr(i);
for( j= X1; j<=X2; j++)
{
if(bright_black==1)
lcd_Wdata(0xFF); //点亮
else lcd_Wdata(0x00);//关闭
}
}
}
else //y+1方向
{
for ( i = X1; i<=X2; i++ )
{
y_addr(Y1);
x_addr(i);
for( j= Y1; j<=Y2; j++)
{
if(bright_black==1)
lcd_Wdata(0xff); //点亮
else lcd_Wdata(0x00);
}
}
}
LCD_CS = 1;
}
main()
{
while(1)
{
lcd_w_rang(0,0,0,39,239,1,1); //显示区域
}
}
附件为:VT1335B 的资料.
tengjingshu_112148725 2009-9-27 09:04