(旧贴)关于青云公司LCM320240zk驱动的问题
我使用的是MSP430的cpu,P4连接LCD数据口,P5连接控制口,烧录进去后屏幕却什么都没有显示,麻烦哪位大哥帮忙看看程序哪里有问题,谢谢了。(是不是写入函数的时序有问题呢?)
//qylcd.h
//#include <msp430x14x.h>
//LCD引脚定义 P4->数据口 P5->控制口
#define LCD_DATA_IN P4IN
#define LCD_DATA_OUT P4OUT
#define LCD_DATA_DIR P4DIR
//---------------------------------------------------------------
#define LCD_RS BIT7 //LCD_DI(RS) -> P5.7
#define LCD_RS_DIR P5DIR
#define LCD_RS_LO P5OUT &= ~LCD_RS
#define LCD_RS_HI P5OUT |= LCD_RS
#define LCD_RW BIT6 //LCD_RW -> P5.6
#define LCD_RW_DIR P5DIR
#define LCD_RW_LO P5OUT &= ~LCD_RW
#define LCD_RW_HI P5OUT |= LCD_RW
#define LCD_EN BIT5 //LCD_EN -> P5.5
#define LCD_EN_DIR P5DIR
#define LCD_EN_LO P5OUT &= ~LCD_EN
#define LCD_EN_HI P5OUT |= LCD_EN
#define LCD_CS1 BIT4 //LCD_CS1 -> P5.4
#define LCD_CS1_DIR P5DIR
#define LCD_CS1_LO P5OUT &= ~LCD_CS1
#define LCD_CS1_HI P5OUT |= LCD_CS1
#define LCD_BUSY P5OUT & BIT3 //LCD_BUSY -> P5.3
#define LCD_RST BIT1 //LCD_RST -> P5.1
#define LCD_RST_DIR P5DIR
#define LCD_RST_LO P5OUT &= ~LCD_RST
#define LCD_RST_HI P5OUT |= LCD_RST
#define SCREEN_WIDTH (320) // pixels
#define SCREEN_HIGHT (240) // pixels
///////////////////////////////////////////////////////////
//使用RA8802液晶控制芯片
//mian.c
/////////////////////////////////////////////////////////////
#include "msp430x14x.h"
#include "qylcd.h"
// RA8802的寄存器
#define LCR(0x00)
#define MIR(0x08)
#define CCR(0x10)
#define CSCR (0x18)
#define AWRR (0x20)
#define DWRR (0x28)
#define AWBR (0x30)
#define DWBR (0x38)
#define AWLR (0x40)
#define DWLR (0x48)
#define AWTR (0x50)
#define DWTR (0x58)
#define CPXR (0x60)
#define CPYR (0x70)
#define BTR(0x80)
#define SCCR (0x90)
#define INTR (0xA0)
#define INTX (0xB0)
#define INTY (0xB8)
#define TPCR (0xC0)
#define TPDR (0xC8)
#define LCCR (0xD0)
#define PDR(0xE0)
#define FCR(0xF0)
// 屏幕中,每行可显示的ASC字符数
#define AP (40)
//----------------------------------------------------------------------
//外部函数
extern void IniCpu(void);
//----------------------------------------------------------------------
//函数声明
void LCD_Init(void); //初始化屏幕
void LCD_CheckBusy(void);
void LCD_WriteComm(unsigned char wdata); //写控制寄存器
void LCD_WriteData(unsigned char wdata); //写资料寄存器
void LCD_SetXY(unsigned char X, unsigned char Y); //设置光标位置
static void ClearMemory(void); //清除内存和显示
int DrawDot(unsigned int x, unsigned int y, unsigned int color);//画点程序
void Delay_ns(unsigned char nvalue); //延时
void Delay_ms(unsigned char nvalue); //延时
unsigned char LCD_RegRead(unsigned char REG_Addr);//读取控制寄存器内容
//----------------------------------------------------------------------主函数
int main( void )
{
// Stop watchdog timer to prevent time out reset
//WDTCTL = WDTPW + WDTHOLD;
IniCpu();
LCD_Init();
int a,b;
for(a=100;a<200;a++)
for(b=100;b<200;b++)
DrawDot(a,b,1);
return 0;
}
//----------------------------------------------------------------------延时函数
void Delay_ms(unsigned char nvalue) {
unsigned long count,j;
int i;
count=2667;
for(i=nvalue;i>0;i--)
for(j=count;j>0;j--);
}
void Delay_ns(unsigned char nvalue) {
unsigned int count,j;
int i;
count=3;
for(i=nvalue;i>0;i--)
for(j=count;j>0;j--);
}
//初始化LCD---------------------------------------------------------------
void LCD_Init(void) {
// int i=0;
//LCD复位
LCD_RST_DIR |= LCD_RST; //RST -> 复位输出
LCD_RST_HI;
Delay_ms(1);
LCD_RST_LO;
Delay_ms(120);
LCD_RST_HI;
LCD_CS1_DIR |= LCD_CS1; //CS1->输出方向
LCD_CS1_HI;
LCD_RS_DIR |= LCD_RS; //RS,EN,R/W置低电平
LCD_RS_LO;
LCD_RW_DIR |= LCD_RW;
LCD_RW_LO;
LCD_EN_DIR |= LCD_EN;
LCD_EN_LO;
//初始化屏幕
LCD_WriteComm(LCR); LCD_WriteComm(0xCE); // 电源设置(关键)
LCD_WriteComm(MIR); LCD_WriteComm(0x73);// 视窗设置时钟频率设置(关键)
LCD_WriteComm(CCR); LCD_WriteComm(0xEE); // 光标设置
LCD_WriteComm(CSCR); LCD_WriteComm(0x10);//光标高度CR和行距DY设定
LCD_WriteComm(AWRR); LCD_WriteComm(0x27);//工作视窗右边位置X=320/8-1=39=0x27
LCD_WriteComm(AWBR); LCD_WriteComm(0xEF);//工作视窗低边位置Y=240-1=239=0xEF
LCD_WriteComm(AWLR); LCD_WriteComm(0x00);//工作视窗左边位置SS=0
LCD_WriteComm(AWTR); LCD_WriteComm(0x00);//工作视窗顶边位置SC=0 (SS,SC)可以看作原点,(X,Y)可以看作显示区的另外一边
LCD_WriteComm(DWRR); LCD_WriteComm(0x27);//显示视窗右边位置A=320/8-1=39=0x27
LCD_WriteComm(DWBR); LCD_WriteComm(0xEF);//显示视窗低边位置B=240-1=239=0xEF
LCD_WriteComm(DWLR); LCD_WriteComm(0x00);//显示视窗左边位置C=0
LCD_WriteComm(DWTR); LCD_WriteComm(0x00);//显示视窗顶边位置D=0 可以看出显示视窗和工作视窗是重合的
LCD_WriteComm(CPXR); LCD_WriteComm(0x00); // 光标的X地址(范围:0到64 ,默认为0)
LCD_WriteComm(CPYR); LCD_WriteComm(0x00); // 光标的Y地址(范围:0到255,默认为0) 光标的坐标(X,Y)要落在工作区里
LCD_WriteComm(BTR); LCD_WriteComm(0x33); //光标闪烁时间BT=设定值/帧频
LCD_WriteComm(SCCR); LCD_WriteComm(0x0C); //液晶工作时钟周期CK=系统频率*4/(列数*行数*帧频)
LCD_WriteComm(INTX); LCD_WriteComm(0x27); //设定行中断地址,当光标位置CPXR=INTX中断发生
LCD_WriteComm(INTY); LCD_WriteComm(0xEF); //设定列中断地址,当光标位置CPXR=INTY中断发生
LCD_WriteComm(INTR); LCD_WriteComm(0x08); //命令字设置(关键)
LCD_WriteComm(TPCR); LCD_WriteComm(0xF0);// 触摸功能设置(关闭)
LCD_WriteComm(LCCR); LCD_WriteComm(0x2F); //液晶显示对比度设置(关键)低4位控制
LCD_WriteComm(PDR); LCD_WriteComm(0x00);//设置写入显示内存的数据(关键)
LCD_WriteComm(FCR); LCD_WriteComm(0xA0);//字库语言选择,内部简体字库(关键)
ClearMemory();
SetCursor(0, 0);
}
//---------------------------------------------------------------------------
void LCD_CheckBusy(void) {
unsigned char Flag;
LCD_RS_LO;
LCD_RW_HI;
LCD_DATA_DIR = 0x00;
do {
LCD_EN_HI;
Flag = LCD_DATA_IN;
LCD_EN_LO;
//检测Busy
} while(Flag & BIT3);
LCD_DATA_DIR = 0xFF;
}
void LCD_WriteComm(unsigned char wdata) {
//while(LCD_BUSY);
LCD_CheckBusy();
LCD_DATA_OUT = wdata;
LCD_RS_HI;
LCD_RW_LO;
LCD_EN_HI;
Delay_ns(10);
LCD_EN_LO;
}
void LCD_WriteData(unsigned char wdata) {
LCD_CheckBusy();//while(LCD_BUSY);
LCD_DATA_OUT = wdata;
LCD_RS_LO;
LCD_RW_LO;
LCD_EN_HI;
Delay_ns(10);
LCD_EN_LO;
}
static void ClearMemory(void)
{
unsigned int i,j;
// 光标0,0
LCD_WriteComm(CPXR); LCD_WriteComm(0x00);
LCD_WriteComm(CPYR); LCD_WriteComm(0x00);
// 显存中数据全部清零
for (i = 0; i < 64; i++)
for (j = 0;j < 30; j++)
LCD_WriteData(0x00);
}
void SetCursor(unsigned int x , unsigned int y )
{
//unsigned char low, high;
//unsigned int actualAddr;
x = x / 8;
//actualAddr = y * AP + x + GRAPHICS_BASE_ADDR;
//low = LOBYTE(actualAddr);
// high = HIBYTE(actualAddr);
LCD_WriteComm(CPXR); LCD_WriteComm(x);
LCD_WriteComm(CPYR); LCD_WriteComm(y);
}
/*
int SetXRefreshLimit(unsigned int limit)
{
if (limit > SCREEN_WIDTH || limit == 0)
{
return -1;
}
_XRefreshLimit = limit;
return 1;
}*/
int DrawDot(unsigned int x, unsigned int y, unsigned int color)
{
unsigned char newcolor,status;
unsigned char offset = 1 << (7 - (x % 8));
if (x > SCREEN_WIDTH || y > SCREEN_HIGHT)
{
return 0;
}
SetCursor(x, y);
newcolor = LCD_RegRead(PDR);
if (color)
{
newcolor |= offset;
}
else
{
newcolor &= ~offset;
}
SetCursor(x, y);
status=LCD_RegRead(FCR);status |=BIT3;
LCD_WriteComm(PDR);LCD_WriteComm(newcolor);
LCD_WriteComm(FCR);LCD_WriteComm(status);
return 1;
}
// 读数据
/*
static unsigned char ReadData(void)
{
unsigned char dat;
while(LCD_BUSY);
LCD_CS1_HI; // Clear DB0~DB7, chip select enable
LCD_RS_LO;
LCD_EN_LO; // Clear nRD
Delay_ns(70);
LCD_RW_HI;//IO0SET = BIT_nRD; // Set nRD
dat = (unsigned char)(LCD_DATA_IN & 0xff); // Get memory data
LCD_EN_HI; // Chip select disable
return dat;
}
*/
//读寄存器内容
unsigned char LCD_RegRead(unsigned char REG_Addr)
{
unsigned char REG_READ;
LCD_WriteComm(REG_Addr);
LCD_CS1_HI;
LCD_RS_HI;
LCD_EN_HI;
LCD_RW_HI;
REG_READ = LCD_DATA_IN;
Delay_ns(70);
LCD_EN_LO;
LCD_RW_HI;
return REG_READ;
} 没做过,你还是找液晶公司要源代码,然后移植。我今天就把PCM320240 cx135驱动的调好了,用的sed1335改的(兼容) 只用了几个小时。 我找了,可是他们要发票……我弄不见了……
调试的时候P5OUT对应的位也正确啊,所以P5脚的电平也应该是对的,可是为什么就是不行呢?把以前的程序烧进去却可以……
哪位大哥帮忙抽空给看看,拜托了……
我QQ:49941556
页:
[1]