msp430液晶驱动的问题
有那位大哥使用msp430驱动过400*240的TFT液晶屏,驱动芯片是ILI9327,小弟不胜感激 #define CPU_F ((double)8000000)#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
#include "msp430x16x.h"
void lcd_int(void);
void wr_com(unsigned int,unsigned int);
void wr_dat(unsigned int);
void dis_color2(unsigned int);
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
int i;
BCSCTL1 &= ~XT2OFF; // XT2= HF XTAL
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0xFF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?
BCSCTL2 |= SELM_2; // MCLK= XT2 (safe)
//---PortTFT-----//
P1DIR = 0xFF;
P2DIR = 0xFF;
P3DIR = 0xFF;
P1OUT = 0x00;
P2OUT = 0x00;
P3OUT = 0xFF;
//---ResetTFT----//
P3OUT |= 0x10;
delay_ms(5);
P3OUT &= 0xEF;
delay_ms(10);
P3OUT |= 0x10;
delay_ms(100);
//---InitializeTFT----//
lcd_int();
delay_ms(500);
dis_color2(0xffff);
while(1);
} /***********************************************************
Instruction : Write Command to ILI9327.Port 1 set Low 8 bits
***********************************************************/
void wr_comm(unsigned int index)
{
P3OUT &= 0xFE;
P3OUT &= 0xF7;
P1OUT = index;
P2OUT = index>>8;
delay_ms(1);
P3OUT &= 0xFD;
delay_ms(1);
P3OUT |= 0x02;
delay_ms(1);
P3OUT |= 0x08;
}
/***********************************************************
Instruction : Write Data to ILI9327.Port 2 set High 8 bits
***********************************************************/
void wr_dat(unsigned int dat)
{
P3OUT |= 0x01;
P3OUT &= 0xF7;
P1OUT = dat;
P2OUT = dat>>8;
delay_ms(1);
P3OUT &= 0xFD;
delay_ms(1);
P3OUT |= 0x02;
delay_ms(1);
P3OUT |= 0x08;
}
/***********************************************************
Instruction : Lcd Initial with Rest in more than 200ms
Exit sleep
Set Gamma
***********************************************************/
void lcd_int(void)
{
//************* Reset LCD Driver ****************//
P3OUT |= 0x10;
delay_ms(5); // Delay 1ms
P3OUT &= 0xEF;
delay_ms(20); // Delay 20ms // This delay time is necessary
P3OUT |= 0x10;
delay_ms(200); // Delay 200 ms
wr_comm(0xE9);
wr_dat (0x20);
wr_comm(0x11); //Exit Sleep
delay_ms(100);
wr_comm(0xD1);
wr_dat (0x00);
wr_dat (0x71);
wr_dat (0x19);
wr_comm(0xD0);
wr_dat (0x07);
wr_dat (0x01);
wr_dat (0x08);
wr_comm(0x36);
wr_dat (0x48);
wr_comm(0x3A);
wr_dat (0x05);
wr_comm(0xC1);
wr_dat (0x10);
wr_dat (0x10);
wr_dat (0x02);
wr_dat (0x02);
wr_comm(0xC0); //Set Default Gamma
wr_dat (0x00);
wr_dat (0x35);
wr_dat (0x00);
wr_dat (0x00);
wr_dat (0x01);
wr_dat (0x02);
wr_comm(0xC5); //Set frame rate
wr_dat (0x04);
wr_comm(0xD2); //power setting
wr_dat (0x01);
wr_dat (0x44);
wr_comm(0xC8); //Set Gamma
wr_dat (0x04);
wr_dat (0x67);
wr_dat (0x35);
wr_dat (0x04);
wr_dat (0x08);
wr_dat (0x06);
wr_dat (0x24);
wr_dat (0x01);
wr_dat (0x37);
wr_dat (0x40);
wr_dat (0x03);
wr_dat (0x10);
wr_dat (0x08);
wr_dat (0x80);
wr_dat (0x00);
wr_comm(0x2A);
wr_dat (0x00);
wr_dat (0x00);
wr_dat (0x00);
wr_dat (0xeF);
wr_comm(0x2B);
wr_dat (0x00);
wr_dat (0x00);
wr_dat (0x01);
wr_dat (0x8F);
wr_comm(0x29); //display on
wr_comm(0x2C); //display on
} void dis_color2(unsigned int j)
{
unsigned int i,m;
wr_comm(0x002c);
P3OUT |= 0x01;
P3OUT &= 0xF7;
for(i=0;i<400;i++)
for(m=0;m<240;m++)
{
P1OUT = j;
P2OUT = j>>8;
P3OUT &= 0xFD;
P3OUT |= 0x02;
}
P3OUT |= 0x08;
}
没办法,还得自己给出来啊,有兴趣的通知可以看看
编译环境为:IAR EWB 5.21B
连接方式:MSP430F169
P1口:DB0-DB7
P2口:DB8-DB15
P3口:依次由P3.0-P3.5为:RS、WR、RD、CS、REST
页:
[1]