#include"reg52.h"
#define uchar unsigned char
#define uint unsigned int
void Delay100ms(uchar Counter);
void Delay10ms(uchar Counter);
void Delay1ms(uchar Counter);
void Delay100us(uchar Counter);
void Delay2us(uchar Counter);
void Chk_Busy(void);
sbit LCD_RS=P3^0;
sbit LCD_CS=P3^1;
sbit LCD_WR=P3^2;
sbit LCD_RST=P3^3;
sbit LED_EN=P3^6;
sbit LCD_RD=P3^7;
unsigned char DATA_BUS ;
//#define DATA_BUS P1
// ========== MCU Cycle ===========
void LCD_CmdWrite(uchar cmd) // Command Write
{
LCD_CS = 0;
LCD_RS = 1;
Delay10ms(1);
LCD_WR = 0;
Delay10ms(1);
P1= cmd;
LCD_WR = 0;
Delay10ms(1);
LCD_WR = 1;
Delay10ms(1);
LCD_CS = 1;
// P1 = 0xff;
}
void LCD_DataWrite(uchar Data) // Data Write
{
LCD_CS = 0;
LCD_RS = 0;
Delay10ms(1);
Delay10ms(1);
P1= Data;
LCD_WR = 0;
Delay10ms(1);
LCD_WR = 1;
Delay10ms(1);
LCD_CS = 1;
// P1 = 0xff;
}
uchar LCD_StatusRead(void) // Read Status Register
{ uchar Data;
LCD_CS = 0;
LCD_RS = 1;
LCD_WR = 1;
LCD_RD = 0;
Data = DATA_BUS;
LCD_RD = 1;
LCD_CS = 1;
DATA_BUS = 0xff;
LCD_RS = 0;
return Data;
}
// ========== RA8870 初始化 ===========
void LCD_Initial(void)
{
LCD_CmdWrite(0x01);
LCD_DataWrite(0x00); // 关闭显示
// Delay10ms(1);
P2=0X7F;
LCD_CmdWrite(0x88);
LCD_DataWrite(0x8F); // SYS_CLK=.......
// Delay10ms(1);
P2=0XFE;
LCD_CmdWrite(0x89);
LCD_DataWrite(0x03);
// Delay10ms(1);
P2=0XD;
LCD_CmdWrite(0x04);
LCD_DataWrite(0x01);// PCLK频率=SYS_CLK/((2^(0+1))*(2^n))=
// Delay10ms(1) ;
P2=0XFB;
LCD_CmdWrite(0x01);
LCD_DataWrite(0x01);
// Delay10ms(1);
P2=0XF7;
LCD_CmdWrite(0x01);
LCD_DataWrite(0x00); //进行一次软复位,使频率设置有效。
// Delay10ms(1);
P2=0XEF;
LCD_CmdWrite(0x10);
LCD_DataWrite(0x3C); //使用外部RAM,65K色,8位数据口。
// Delay10ms(1);
P2=0XDF;
LCD_CmdWrite(0x11);
LCD_DataWrite(0x00); // RGB格式LCD_CmdWrite(0x88);
// Delay10ms(1);
P2=0XBF;
LCD_CmdWrite(0x12);
LCD_DataWrite(0x00);
// Delay10ms(1);
P2=0X7F;
LCD_CmdWrite(0x13);
LCD_DataWrite(0x00);
// Delay10ms(1);
P2=0XFE;
//_______水平设置 _____
LCD_CmdWrite(0x14);
LCD_DataWrite(0x3B); //480列
// Delay10ms(1);
P2=0XFD;
LCD_CmdWrite(0x15);
LCD_DataWrite(0x04);
// Delay10ms(1);
P2=0XFB;
LCD_CmdWrite(0x16);
LCD_DataWrite(0x05); //水平非显示区域
Delay10ms(1);
P2=0XF7;
LCD_CmdWrite(0x17);
LCD_DataWrite(0x02); // HSYNC 开始位置
// Delay10ms(1);
P2=0XEF;
LCD_CmdWrite(0x18);
LCD_DataWrite(0x01); //HSYNC 脉宽
// Delay10ms(1);
P2=0XDF;
//___________ 垂直设置 ______________
LCD_CmdWrite(0x19);
LCD_DataWrite(0x0F);
// Delay10ms(1);
P2=0XBF;
LCD_CmdWrite(0x1A);
LCD_DataWrite(0x01); //272行
// Delay10ms(1);
P2=0X7F;
LCD_CmdWrite(0x1B);
LCD_DataWrite(0x09);
// Delay10ms(1);
P2=0XFE;
LCD_CmdWrite(0x1C);
LCD_DataWrite(0x00); //垂直非显示区域
// Delay10ms(1);
P2=0XFD;
LCD_CmdWrite(0x1D);
LCD_DataWrite(0x05);
// Delay10ms(1);
P2=0XFB;
LCD_CmdWrite(0x1E);
LCD_DataWrite(0x00); //VSYNC 开始位置
// Delay10ms(1);
P2=0XF7;
LCD_CmdWrite(0x1F);
LCD_DataWrite(0x02); //VSYNC 脉宽
// Delay10ms(1);
P2=0XEF;
// ___________ 有效工作窗口 ________
LCD_CmdWrite(0x30);
LCD_DataWrite(0x00);
// Delay10ms(1);
P2=0XDF;
LCD_CmdWrite(0x31);
LCD_DataWrite(0x00); //从第一列开始
// Delay10ms(1);
P2=0XBF;
LCD_CmdWrite(0x34);
LCD_DataWrite(0xDF);
// Delay10ms(1);
P2=0X7F;
LCD_CmdWrite(0x35);
LCD_DataWrite(0x01); //01DF=480。
// Delay10ms(1);
P2=0XFE;
LCD_CmdWrite(0x32);
LCD_DataWrite(0x00);
// Delay10ms(1);
P2=0XFD;
LCD_CmdWrite(0x33);
LCD_DataWrite(0x00); //从第一行开始
// Delay10ms(1);
P2=0XFB;
LCD_CmdWrite(0x36);
LCD_DataWrite(0x0F);
// Delay10ms(1);
P2=0XF7;
LCD_CmdWrite(0x37);
LCD_DataWrite(0x01); //010F =272行
// Delay10ms(1);
P2=0XEF;
LCD_CmdWrite(0x01);
LCD_DataWrite(0x80); //打开显示
// Delay100ms(1) ;
P2=0XDF;
LCD_CmdWrite(0x40);
LCD_DataWrite(0x00);
// Delay100ms(1) ;
P2=0XBF;
// Delay100ms(10) ;
P2=0X00;
}
// ========== 读忙(Check Busy )子程序 ===========
void Chk_Busy(void)
{
//uchar temp;
do
{
//temp=LCD_StatusRead();
//}while((temp&0x80)==0x80);
} while(LCD_StatusRead()&0x80);
}
// ========== 延迟(Delay )子程序 ===========
void Delay2us(uchar Counter)
{ while(--Counter);
}
void Delay100us(uchar Counter)
{ while(Counter--)
{ Delay2us(100); }
}
void Delay1ms(uchar Counter)
{ while(Counter--)
{ Delay100us(11); }
}
void Delay10ms(uchar Counter)
{ while(Counter--)
{ Delay1ms(11); }
}
void Delay100ms(uchar Counter)
{ while(Counter--)
{ Delay1ms(101); }
}
//================== main process start ==================//
void main(void)
{
// LCD_Reset(); // 对RA8870 重致
LCD_RST = 0;
Delay100ms(1);
LCD_RST = 1;
Delay100ms(1);
LCD_Initial();
while(1)
{ P2=0X0F;
// LCD_Initial();
}
}
人家用汇编在W78E516DDG上写的初始化,我把改成STC90C516RD+上的,怎么就初始化不了,数据端口和命令端口输入输出都正确,有谁能帮我分析一下原因呢?先谢谢
|