This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
最近在用MSP430F6659调一块LCD,用的是SPI口,LCD厂家给的例程是51单片机上的,现在把它移植到430上,可是仍然无法点亮LCD(最基本的背光都不亮,用另外的51单片机),求大神帮忙看下程序。
51单片机:
sbit ZCS=P3^0;
sbit SDO=P3^1;
sbit SDI=P3^2;
sbit SCK=P3^3;
sbit che=P3^7;
sbit MCU_RST =P3^7; //L有效
//*********4W_SPI_Init()
void SPI_Init(void)
{
SCK = 1;
SDI = 1;
SDO = 1;
ZCS = 1;
}
//*********4W_SPI_Write()
void SPI_Write(unsigned char dat)
{
unsigned char t = 8;
do
{
SDI = (bit)(dat & 0x80);
dat <<= 1;
SCK = 0;
//SPI_Delay();
SCK = 1;
//SPI_Delay();
} while ( --t != 0 );
//SCK = 1;
//SDI = 1;
}
//*********4W_SPI_Read()
unsigned char SPI_Read()
{
unsigned char dat;
unsigned char t = 8;
SDO = 1;
do
{
SCK = 0;
//SPI_Delay();
dat <<= 1;
if ( SDO ) dat++;
SCK = 1;
//SPI_Delay();
} while ( --t != 0 );
return dat;
}
//*********SPI写命令
void LCD_CmdWrite(uchar cmd)
{
SCK = 1;
SDI = 1;
ZCS = 0;
//SPI_Delay();
SPI_Write(0x80);
SPI_Write(cmd);
ZCS = 1;
//SPI_Delay();
}
//*********SPI写数据
void LCD_DataWrite(uchar Data)
{
SCK = 1;
SDI = 1;
ZCS = 0;
SPI_Write(0x00);
SPI_Write(Data);
//SPI_Delay();
ZCS = 1;
}
//*********SPI读数据
uchar LCD_DataRead(void)
{
uchar Data;
SCK = 1;
SDO = 1;
ZCS = 0;
SPI_Write(0x40);
Data = SPI_Read();
//SPI_Delay();
ZCS = 1;
return Data;
}
//***********************写指令
void Write_Dir(uchar Cmd,uchar Data)
{
LCD_CmdWrite(Cmd);
LCD_DataWrite(Data);
}
//*********SPI读命令状态
uchar LCD_StatusRead(void)
{
uchar Data;
SCK = 1;
SDO = 1;
ZCS = 0;
//SPI_Delay();
SPI_Write(0xc0);
Data = SPI_Read();
//SPI_Delay();
ZCS = 1;
return Data;
}
//*********LCD复位
void LCD_Reset(void)
{
MCU_RST = 0;
Delay1ms(1);
MCU_RST = 1;
Delay1ms(1);
}
//*********测忙函数组
void Chk_Busy(void)
{
uchar temp;
do
{
temp=LCD_StatusRead();
}while((temp&0x80)==0x80);
}
void Chk_BTE_Busy(void)
{
uchar temp;
do
{
temp=LCD_StatusRead();
}while((temp&0x40)==0x40);
}
void Chk_DMA_Busy(void)
{
uchar temp;
do
{
LCD_CmdWrite(0xBF);
temp =LCD_DataRead();
}while((temp&0x01)==0x01);
}
//********倍频设置
void PLL_ini(void)
{
LCD_CmdWrite(0x88);
LCD_DataWrite(0x0a);
Delay1ms(1);
LCD_CmdWrite(0x89);
LCD_DataWrite(0x02);
Delay1ms(1);
}
//********液晶初始化
void LCD_Initial(void)
{
PLL_ini();
LCD_CmdWrite(0x10); //SYSR bit[4:3]=00 256 color bit[2:1]= 00 8bit MPU interface
LCD_DataWrite(0x0C); // 1x 64k color 1x 16bit
//Horizontal set
LCD_CmdWrite(0x14); //HDWR//Horizontal Display Width Setting Bit[6:0]
LCD_DataWrite(0x63);//Horizontal display width(pixels) = (HDWR + 1)*8
LCD_CmdWrite(0x15); //Horizontal Non-Display Period Fine Tuning Option Register (HNDFTR)
LCD_DataWrite(0x03);//Horizontal Non-Display Period Fine Tuning(HNDFT) [3:0]
LCD_CmdWrite(0x16); //HNDR//Horizontal Non-Display Period Bit[4:0]
LCD_DataWrite(0x03);//Horizontal Non-Display Period (pixels) = (HNDR + 1)*8
LCD_CmdWrite(0x17); //HSTR//HSYNC Start Position[4:0]
LCD_DataWrite(0x02);//HSYNC Start Position(PCLK) = (HSTR + 1)*8
LCD_CmdWrite(0x18); //HPWR//HSYNC Polarity ,The period width of HSYNC.
LCD_DataWrite(0x00);//HSYNC Width [4:0] HSYNC Pulse width(PCLK) = (HPWR + 1)*8
//Vertical set
LCD_CmdWrite(0x19); //VDHR0 //Vertical Display Height Bit [7:0]
LCD_DataWrite(0xdf);//Vertical pixels = VDHR + 1
LCD_CmdWrite(0x1a); //VDHR1 //Vertical Display Height Bit [8]
LCD_DataWrite(0x01);//Vertical pixels = VDHR + 1
LCD_CmdWrite(0x1b); //VNDR0 //Vertical Non-Display Period Bit [7:0]
LCD_DataWrite(0x14);//Vertical Non-Display area = (VNDR + 1)
LCD_CmdWrite(0x1c); //VNDR1 //Vertical Non-Display Period Bit [8]
LCD_DataWrite(0x00);//Vertical Non-Display area = (VNDR + 1)
LCD_CmdWrite(0x1d); //VSTR0 //VSYNC Start Position[7:0]
LCD_DataWrite(0x06);//VSYNC Start Position(PCLK) = (VSTR + 1)
LCD_CmdWrite(0x1e); //VSTR1 //VSYNC Start Position[8]
LCD_DataWrite(0x00);//VSYNC Start Position(PCLK) = (VSTR + 1)
LCD_CmdWrite(0x1f); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
LCD_DataWrite(0x01);//VSYNC Pulse Width(PCLK) = (VPWR + 1)
LCD_CmdWrite(0x04); //PCLK
LCD_DataWrite(0x81); //
LCD_CmdWrite(0x8c);//PWM控制设置
LCD_DataWrite(0x80);//开启PWM
LCD_CmdWrite(0x8c);//PWM控制设置
LCD_DataWrite(0x81);//开启PWM
LCD_CmdWrite(0x8d);//背光亮度
LCD_DataWrite(0xff);//亮度参数0xff-0x00
}
移植到430上:
#define LCD_SIMO BIT1
#define LCD_SOMI BIT2
#define LCD_CLK BIT3
#define LCD_CS BIT6
#define LCD_SEL P2SEL
#define LCD_DIR P2DIR
#define LCD_OUT P2OUT
void LCDSPI_Init(void)
{
LCD_SEL |= LCD_CLK + LCD_SOMI + LCD_SIMO;
LCD_DIR |= LCD_CLK + LCD_SIMO;
LCD_DIR &= ~LCD_SOMI;
UCB0CTL1 |= UCSWRST;
// Put state machine in reset
UCB0CTL0 = UCMSB + UCMST + UCSYNC + UCMODE_0 + UCCKPL + UCCKPH; // 8-bit SPI master
// UCB0CTL0 &= ~UCCKPH; // SPI MODE 0 设置极性和相位
// Clock polarity select - The inactive state is high
// MSB first
UCB0CTL1 = UCSSEL_2; // Use SMCLK
UCB0BR0 = 0x02; // Initial SPI clock must be <400kHz
UCB0BR1 = 0; // f_UCxCLK = 25MHz/63 = 397kHz
UCB0CTL1 &= ~UCSWRST; // Release USCI state machine
//UCB0IFG &= ~UCRXIFG;
}
void LCD_Write(uchar dat)
{
//等待发送缓冲器为空
while (!(UCB0IFG & UCTXIFG));
UCB0TXBUF = dat;
__delay_cycles(10);
}
//*********SPI写命令
void LCD_CmdWrite(uchar cmd)
{
LCD_DIR &= ~LCD_CS;
LCD_Write(0x80);
LCD_Write(cmd);
LCD_DIR |= LCD_CS;
}
//*********SPI写数据
void LCD_DataWrite(uchar Data)
{
LCD_DIR &= ~LCD_CS;
LCD_Write(0x00);
LCD_Write(Data);
LCD_DIR |= LCD_CS;
}
//***********************写指令
void Write_Dir(uchar Cmd,uchar Data)
{
LCD_CmdWrite(Cmd);
LCD_DataWrite(Data);
}
//********倍频设置
void PLL_ini(void)
{
LCD_CmdWrite(0x88);
LCD_DataWrite(0x0a);
__delay_cycles(1000);
LCD_CmdWrite(0x89);
LCD_DataWrite(0x02);
__delay_cycles(1000);
}
//********液晶初始化
void LCD_Init(void)
{
PLL_ini();
LCD_CmdWrite(0x10); //SYSR bit[4:3]=00 256 color bit[2:1]= 00 8bit MPU interface
LCD_DataWrite(0x0C); // 1x 64k color 1x 16bit
//Horizontal set
LCD_CmdWrite(0x14); //HDWR//Horizontal Display Width Setting Bit[6:0]
LCD_DataWrite(0x63);//Horizontal display width(pixels) = (HDWR + 1)*8
LCD_CmdWrite(0x15); //Horizontal Non-Display Period Fine Tuning Option Register (HNDFTR)
LCD_DataWrite(0x03);//Horizontal Non-Display Period Fine Tuning(HNDFT) [3:0]
LCD_CmdWrite(0x16); //HNDR//Horizontal Non-Display Period Bit[4:0]
LCD_DataWrite(0x03);//Horizontal Non-Display Period (pixels) = (HNDR + 1)*8
LCD_CmdWrite(0x17); //HSTR//HSYNC Start Position[4:0]
LCD_DataWrite(0x02);//HSYNC Start Position(PCLK) = (HSTR + 1)*8
LCD_CmdWrite(0x18); //HPWR//HSYNC Polarity ,The period width of HSYNC.
LCD_DataWrite(0x00);//HSYNC Width [4:0] HSYNC Pulse width(PCLK) = (HPWR + 1)*8
//Vertical set
LCD_CmdWrite(0x19); //VDHR0 //Vertical Display Height Bit [7:0]
LCD_DataWrite(0xdf);//Vertical pixels = VDHR + 1
LCD_CmdWrite(0x1a); //VDHR1 //Vertical Display Height Bit [8]
LCD_DataWrite(0x01);//Vertical pixels = VDHR + 1
LCD_CmdWrite(0x1b); //VNDR0 //Vertical Non-Display Period Bit [7:0]
LCD_DataWrite(0x14);//Vertical Non-Display area = (VNDR + 1)
LCD_CmdWrite(0x1c); //VNDR1 //Vertical Non-Display Period Bit [8]
LCD_DataWrite(0x00);//Vertical Non-Display area = (VNDR + 1)
LCD_CmdWrite(0x1d); //VSTR0 //VSYNC Start Position[7:0]
LCD_DataWrite(0x06);//VSYNC Start Position(PCLK) = (VSTR + 1)
LCD_CmdWrite(0x1e); //VSTR1 //VSYNC Start Position[8]
LCD_DataWrite(0x00);//VSYNC Start Position(PCLK) = (VSTR + 1)
LCD_CmdWrite(0x1f); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
LCD_DataWrite(0x01);//VSYNC Pulse Width(PCLK) = (VPWR + 1)
LCD_CmdWrite(0x04); //PCLK
LCD_DataWrite(0x81); //
LCD_CmdWrite(0x8c);//PWM控制设置
LCD_DataWrite(0x80);//开启PWM
LCD_CmdWrite(0x8c);//PWM控制设置
LCD_DataWrite(0x81);//开启PWM
LCD_CmdWrite(0x8d);//背光亮度
LCD_DataWrite(0xff);//亮度参数0xff-0x00
}
主程序就是最简单的初始化函数