Lacto 2 Posted October 1, 2013 Share Posted October 1, 2013 Hello, I try to write my own library for the MSP430G2553 and and the 2.2" ILI9341 display. I know RobG has made one but this project is basically for learning about LCDs and SPI. I took the code from http://www.elecfreaks.com/wiki/index.php?title=2.2S%22_TFT_LCD:_TFT01-2.2S and modified it for the MSP430G2553. It worked fine but only as solftware SPI. Now I want to use the hardware SPI. Here ist my code: #include <msp430g2553.h> #define LCD_MISO BIT1 #define LCD_CLK BIT4 #define LCD_MOSI BIT2 #define LCD_DC BIT0 #define LCD_CS BIT3 #define LCD_REST BIT5 void LCD_Writ_Bus(char data) { P1OUT &= ~LCD_CS; UCA0TXBUF = data; //while(UCA0TXBUF); //while(UCA0TXIFG & UC0IFG); while (UCA0STAT & UCBUSY); //_delay_cycles(120000); P1OUT |= LCD_CS; } void LCD_Write_COM(char VL) { P1OUT &= ~LCD_DC; LCD_Writ_Bus(VL); } void LCD_Write_DATA(char VL) { P1OUT |= LCD_DC; LCD_Writ_Bus(VL); } void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2) { LCD_Write_COM(0x2a); LCD_Write_DATA(x1>>8); LCD_Write_DATA(x1); LCD_Write_DATA(x2>>8); LCD_Write_DATA(x2); LCD_Write_COM(0x2b); LCD_Write_DATA(y1>>8); LCD_Write_DATA(y1); LCD_Write_DATA(y2>>8); LCD_Write_DATA(y2); LCD_Write_COM(0x2C); } void LCD_Init(void) { P1OUT &= ~LCD_REST; _delay_cycles(120000); P1OUT |= LCD_REST; _delay_cycles(120000); LCD_Write_COM(0xCB);//Power control A LCD_Write_DATA(0x39); LCD_Write_DATA(0x2C); LCD_Write_DATA(0x00); LCD_Write_DATA(0x34); LCD_Write_DATA(0x02); LCD_Write_COM(0xCF);//Power control B LCD_Write_DATA(0x00); LCD_Write_DATA(0XC1); LCD_Write_DATA(0X30); LCD_Write_COM(0xE8);//Driver timing control A LCD_Write_DATA(0x85); LCD_Write_DATA(0x00); LCD_Write_DATA(0x78); LCD_Write_COM(0xEA);//Driver timing control B LCD_Write_DATA(0x00); LCD_Write_DATA(0x00); LCD_Write_COM(0xED);//Power on sequence control LCD_Write_DATA(0x64); LCD_Write_DATA(0x03); LCD_Write_DATA(0X12); LCD_Write_DATA(0X81); LCD_Write_COM(0xF7);//Enable 3G LCD_Write_DATA(0x20); LCD_Write_COM(0xC0); //Power control LCD_Write_DATA(0x23); //VRH[5:0] LCD_Write_COM(0xC1); //Power control LCD_Write_DATA(0x10); //SAP[2:0];BT[3:0] LCD_Write_COM(0xC5); //VCM control LCD_Write_DATA(0x3e); //Contrast LCD_Write_DATA(0x28); LCD_Write_COM(0xC7); //VCM control2 LCD_Write_DATA(0x86); //-- LCD_Write_COM(0x36); // Memory Access Control LCD_Write_DATA(0x48); //C8 LCD_Write_COM(0x3A);//COLMOD: Pixel Format Set LCD_Write_DATA(0x55); LCD_Write_COM(0xB1);//Frame Rate Control (In Normal Mode/Full Colors) LCD_Write_DATA(0x00); LCD_Write_DATA(0x18); LCD_Write_COM(0xB6); // Display Function Control LCD_Write_DATA(0x08); LCD_Write_DATA(0x82); LCD_Write_DATA(0x27); LCD_Write_COM(0x11); //Exit Sleep _delay_cycles(120000); LCD_Write_COM(0x29); //Display on LCD_Write_COM(0x2c); } void Pant(char VL) { int i,j; Address_set(0,0,240,320); for(i=0;i<320;i++) { for (j=0;j<480;j++) { LCD_Write_DATA(VL); } } } void loop() { Pant(0xFF); Pant(0xF0); Pant(0xE0); Pant(0x05); Pant(0x1F); Pant(0x00); } void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_12MHZ; // Set range DCOCTL = CALDCO_12MHZ; BCSCTL2 = 0; //Port1(ILI9341) P1DIR = LCD_DC + LCD_CS + LCD_REST; P1OUT = LCD_CS; P1SEL = LCD_MISO + LCD_CLK + LCD_MOSI; P1SEL2 = LCD_MISO + LCD_CLK + LCD_MOSI; UCA0CTL0 = UCMSB + UCMST + UCMODE_1; // 4-pin, 8-bit SPI master UCA0CTL1 = UCSSEL_2; // SMCLK UCA0BR0 = 3; // UCA0BR1 = 0; // //UCA0MCTL = 0; // No modulation UCA0CTL1 &= ~UCSWRST; LCD_Init(); loop(); while(1); } Nothing happens and I have no idea why ... Quote Link to post Share on other sites
RobG 1,892 Posted October 2, 2013 Share Posted October 2, 2013 It's probably because your USCI is not in synchronous mode, add UCSYNC. In addition, use 3 pin mode since you are not using UCA0STE (UCMODE_1) and SPI mode 1 (UCCKPH) UCA0CTL0 = UCMSB + UCMST + UCSYNC + UCCKPH; // 4-pin, 8-bit SPI master Lacto 1 Quote Link to post Share on other sites
Lacto 2 Posted October 2, 2013 Author Share Posted October 2, 2013 Thanks RobG. It works. Quote Link to post Share on other sites
olajideolaolorun 0 Posted November 20, 2013 Share Posted November 20, 2013 I tried this Rob and its still just a blank screen. The code compiled, no error. Quote Link to post Share on other sites
olajideolaolorun 0 Posted November 20, 2013 Share Posted November 20, 2013 @@RobG I tried this Rob and its still just a blank screen. The code compiled, no error. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.