CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

TFT Display Driver - PIC 18F4550
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ninoq



Joined: 22 May 2013
Posts: 14

View user's profile Send private message

TFT Display Driver - PIC 18F4550
PostPosted: Thu May 23, 2013 6:30 am     Reply with quote

I'm using a PIC 18F4550 to develop a driver for a TFT display - http://www.emartee.com/product/41969/TFT%202.4%22%20320
The code below is based on Reference Code (an Arduino sketch - see pg. 11 - 8 bit mode) provided on the above product page and on code in post#23 at: http://forums.parallax.com/showthread.php/110134-2.4-quot-320x240-TFT-Prop-based-display-module/page2.

I've been unable to elicit any response from the display. All I get is a blank white screen - the same as when I first powered it up.

I've double checked the connections between the PIC and the display and they appear to be in order. I've also consulted the ILI9325 datasheet but to no avail.

Any guidance/advice would be appreciated.

Code:

#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,PLL5,CPUDIV1,VREGEN,NOMCLR,NOPBADEN

/*OSCILLATOR SETUP***********************************************************************************
20MHz crystal, HSPLL enables PLL, PLL5 gives 4MHz (=20/5) input to PLL - PLL output 96MHz (=24*4)
CPUDIV1 gives FOSC = 48MHz (=96/2) - Single word instruction time = 1/(48/4E6) = 83.3ns (83.3E-9 secs)
*****************************************************************************************************/
#use delay(clock=48M)//48000000Hz
#use rs232(baud=4800, xmit=PIN_C6,rcv=PIN_C7, PARITY=N, BITS=8, STOP=1)

//control pins
#define RS PIN_D5
#define WR PIN_D4
#define CS PIN_D3
#define RESET PIN_D2

//8 bit data bus pins
#define DB0 PIN_B5
#define DB1 PIN_B4
#define DB2 PIN_B3
#define DB3 PIN_B2
#define DB4 PIN_B1
#define DB5 PIN_B0
#define DB6 PIN_D7
#define DB7 PIN_D6

//display image
char const image[3200]={                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XBE,0XF7,0X7D,0XEF,
0XBA,0XD6,0XB6,0XB5,0XF3,0X9C,0XB2,0X94,0XB3,0X9C,0XB2,0X94,0X34,0XA5,0XF7,0XBD,
0XFB,0XDE,0X7D,0XEF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XBE,0XF7,0XFB,0XDE,0XF3,0X9C,0XCB,0X5A,
0XC7,0X39,0X04,0X21,0X82,0X10,0X42,0X10,0X42,0X10,0X41,0X08,0X83,0X18,0X45,0X29,
0XC7,0X39,0X0C,0X63,0X75,0XAD,0X3C,0XE7,0XBE,0XF7,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X3C,0XE7,0XB2,0X94,0X08,0X42,0XC3,0X18,0X82,0X10,
0X04,0X21,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,0X00,0XA8,0X00,0X30,0X4A,0X4A,0XBA,0XD6,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0X7D,0XEF,0X8E,0X73,0XC3,0X18,0X05,0X39,0X82,0XA8,0X00,0XF8,
0XC3,0XF8,0X4D,0XFB,0X4D,0XFB,0XC7,0XF9,0XC3,0XF0,0X82,0XD8,0XC3,0XB0,0X04,0X81,
0X45,0X61,0X46,0X51,0X86,0X49,0X86,0X49,0X46,0X41,0X45,0X41,0X45,0X41,0X45,0X41,
0X05,0X49,0X04,0X61,0X82,0X90,0X41,0XB0,0X00,0XD0,0X00,0XC8,0X00,0XA8,0X00,0XA8,
0X00,0XB8,0X41,0X58,0X82,0X10,0X82,0X10,0XB2,0X94,0XBE,0XF7,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XBE,0XF7,0XCF,0X7B,0X82,0X10,0X04,0X21,0X86,0X29,0X86,0X41,0X04,0X99,
0X40,0XE8,0X41,0XF8,0X86,0XF9,0XCB,0XFA,0X49,0XFA,0X82,0XF8,0X00,0XF8,0X00,0XF0,
0X00,0XE8,0X41,0XD8,0X41,0XD0,0X41,0XC0,0X41,0XC0,0X41,0XC0,0X41,0XC0,0X41,0XC8,
0X00,0XD0,0X00,0XE0,0X00,0XE0,0X00,0XD8,0X00,0XD0,0X00,0XB8,0X00,0XA8,0X41,0X88,
0X82,0X48,0X82,0X10,0X82,0X10,0X00,0X00,0X45,0X29,0X79,0XCE,0XFF,0XFF,0XFF,0XFF,
0XBE,0XF7,0XF3,0X9C,0X82,0X10,0XC3,0X18,0X45,0X29,0X86,0X31,0XC7,0X31,0X30,0X7C,
0XF3,0XDC,0X86,0XE1,0X00,0XF0,0X00,0XF8,0X41,0XF8,0X41,0XF8,0X00,0XF8,0X00,0XF8,
0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,
0X00,0XE8,0X00,0XE0,0X00,0XE0,0X00,0XD8,0X00,0XC8,0X41,0XA0,0X8A,0X9A,0X0C,0X63,
0X04,0X11,0X82,0X10,0X82,0X10,0X41,0X08,0X00,0X00,0X4D,0X6B,0X7D,0XEF,0XFF,0XFF,
0XFB,0XDE,0X08,0X42,0X42,0X10,0X45,0X29,0X86,0X31,0X86,0X31,0X49,0X4A,0X38,0XBE,
0XFF,0XFF,0X38,0XD6,0X86,0XA9,0X00,0XC8,0X00,0XE0,0X00,0XF0,0X00,0XF8,0X00,0XF8,
0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF0,0X00,0XF0,
0X00,0XE8,0X00,0XE0,0X00,0XD0,0XC3,0X98,0X8A,0X8A,0XB2,0XA4,0XBA,0XC6,0XF7,0XB5,
0X08,0X42,0X41,0X08,0X82,0X10,0X41,0X08,0X00,0X00,0X45,0X29,0XF7,0XBD,0XFF,0XFF,
0X71,0X8C,0X41,0X08,0X04,0X21,0X45,0X29,0X86,0X31,0X86,0X31,0X0C,0X63,0X3C,0XE7,
0XFF,0XFF,0X79,0XD6,0X46,0XB9,0X00,0XE0,0X42,0XC8,0X82,0XA8,0X82,0XB0,0X41,0XD8,
0X82,0XE8,0X82,0XF0,0X41,0XE8,0X41,0XE8,0X41,0XE8,0X41,0XF0,0X41,0XE8,0X41,0XD8,
0X04,0XC1,0X08,0X92,0X4D,0X8B,0X34,0XA5,0XFB,0XC6,0XFB,0XD6,0XBA,0XCE,0X3C,0XE7,
0X30,0X84,0XC3,0X18,0X41,0X08,0X41,0X08,0X00,0X00,0X41,0X08,0XCF,0X7B,0X7D,0XEF,
0X49,0X4A,0X00,0X00,0X04,0X21,0X45,0X29,0X46,0X31,0X86,0X31,0X30,0X84,0XFF,0XFF,
0XFF,0XF7,0XF7,0XDD,0X09,0XDA,0X83,0XF8,0X01,0XF0,0X42,0XC0,0X82,0X98,0X49,0X9A,
0XF3,0XB4,0XF3,0XCC,0X71,0XB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0X60,0XF5,
0X20,0XE5,0X80,0X9B,0X86,0X62,0X30,0X84,0X79,0XCE,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X38,0XC6,0X2D,0X9C,0X05,0X93,
0X43,0XA3,0X82,0XB3,0XC2,0XBB,0XC2,0XBB,0X22,0XB4,0X82,0XA3,0X42,0X93,0XC3,0X7A,
0X85,0X62,0X0B,0X63,0X71,0X84,0XB6,0XB5,0X79,0XCE,0X79,0XC6,0XB5,0XAD,0X70,0X94,
0X4A,0X8B,0X06,0X83,0X04,0X93,0X04,0X9B,0X43,0X9B,0X43,0X9B,0X43,0X93,0X04,0X83,
0X08,0X73,0X8D,0X73,0XB3,0X94,0X79,0XCE,0X7D,0XEF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X3C,0XDF,0X38,0XBE,
0X75,0XB5,0X33,0XA5,0X33,0XA5,0XF3,0X9C,0XF3,0X9C,0XF3,0X9C,0XF3,0X94,0XF3,0X9C,
0X35,0XA5,0XF8,0XBD,0XFB,0XDE,0XBE,0XF7,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X7E,0XEF,
0XBB,0XD6,0XF8,0XBD,0XB6,0XAD,0X75,0XAD,0X34,0XA5,0X33,0X9D,0X34,0X9D,0X35,0XA5,
0XB7,0XAD,0X79,0XC6,0X3C,0XE7,0XBE,0XF7,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF
};

//function templates
void LCD_Writ_Bus(char,char);
void LCD_Write_COM(char,char);
void LCD_Write_DATA(char,char);
void Address_set(long, long, long, long);
void LCD_Init(void);
void Pant(char,char);
void SelectDBPin(int, short);

//functions

void SelectDBPin(int index, short HiLo)
{
if (HiLo)
{
switch (index) {
      case 0:   output_high(DB0);
      break;
      case 1:   output_high(DB1);
      break;
      case 2:   output_high(DB2);
      break;
      case 3:   output_high(DB3);
      break;
      case 4:   output_high(DB4);
      break;
      case 5:   output_high(DB5);
      break;
      case 6:   output_high(DB6);
      break;
      case 7:   output_high(DB7);
      break;
      default:printf("bad cmd\r\n");
      break;
      }
}
else
{
switch (index) {
      case 0:   output_low(DB0);
      break;
      case 1:   output_low(DB1);
      break;
      case 2:   output_low(DB2);
      break;
      case 3:   output_low(DB3);
      break;
      case 4:   output_low(DB4);
      break;
      case 5:   output_low(DB5);
      break;
      case 6:   output_low(DB6);
      break;
      case 7:   output_low(DB7);
      break;
      default:printf("bad cmd\r\n");
      break;
      }
}   
}
void LCD_Writ_Bus(char VH, char VL)
{
   unsigned char temp,data;
   int i;

   data=VH;//high byte
   for(i=0;i<8;i++)
   {
      temp=(data&0x01);
      if(temp)SelectDBPin(i,1);
      else SelectDBPin(i,0);
      data=data>>1;
   }
   output_low(WR);
   output_high(WR);

   data=VL;//low byte
   for(i=0;i<8;i++)
   {
      temp=(data&0x01);
      if(temp) SelectDBPin(i,1);
      else SelectDBPin(i,0);
      data=data>>1;
   }
   output_low(WR);
   output_high(WR);
}

void LCD_Write_COM(char VH, char VL) //send command
{
   output_low(RS);
   LCD_Writ_Bus(VH,VL);
}

void LCD_Write_DATA(char VH,char VL) //send data
{
   output_high(RS);
   LCD_Writ_Bus(VH,VL);
}

void Address_set(unsigned long x1, unsigned long y1, unsigned long x2, unsigned long y2)
{
   char x1HiByte, x1LoByte, y1HiByte, y1LoByte, x2HiByte, x2LoByte, y2HiByte, y2LoByte;
   x1HiByte = (char) x1>>8;
   x1LoByte = (char) x1&0x00FF;
   y1HiByte = (char) y1>>8;
   y1LoByte = (char) y1&0x00FF;
   x2HiByte = (char) x2>>8;
   x2LoByte = (char) x2&0x00FF;
   y2HiByte = (char) y2>>8;
   y2LoByte = (char) y2&0x00FF;
   LCD_Write_COM(0x00,0x20);
   LCD_Write_DATA(x1HiByte,x1LoByte);
   LCD_Write_COM(0x00,0x21);
   LCD_Write_DATA(y1HiByte,y1LoByte);
   LCD_Write_COM(0x00,0x50);
   LCD_Write_DATA(x1HiByte,x1LoByte);
   LCD_Write_COM(0x00,0x52);
   LCD_Write_DATA(y1HiByte,y1LoByte);
   LCD_Write_COM(0x00,0x51);
   LCD_Write_DATA(x2HiByte,x2LoByte);
   LCD_Write_COM(0x00,0x53);
   LCD_Write_DATA(y2HiByte,y2LoByte);
   LCD_Write_COM(0x00,0x22);
}

void LCD_Init(void)
{
   output_high(RESET);
   delay_ms(1);
   output_low(RESET);
   delay_ms(10);
   output_high(RESET);
   delay_ms(50);
   output_low(CS);
   
   //************* Start Initial Sequence **********//
   LCD_Write_COM(0x00,0xE5);
   LCD_Write_DATA(0x78,0xF0); // set SRAM internal timing
   LCD_Write_COM(0x00,0x01);
   LCD_Write_DATA(0x01,0x00); // set SS and SM bit
   LCD_Write_COM(0x00,0x02);
   LCD_Write_DATA(0x07,0x00); // set 1 line inversion
   LCD_Write_COM(0x00,0x03);
   LCD_Write_DATA(0x10,0x30); // set GRAM write direction and BGR=1.
   LCD_Write_COM(0x00,0x04);
   LCD_Write_DATA(0x00,0x00); // Resize register
   LCD_Write_COM(0x00,0x08);
   LCD_Write_DATA(0x02,0x07); // set the back porch and front porch
   LCD_Write_COM(0x00,0x09);
   LCD_Write_DATA(0x00,0x00); // set non-display area refresh cycle ISC[3:0]
   LCD_Write_COM(0x00,0x0A);
   LCD_Write_DATA(0x00,0x00); // FMARK function
   LCD_Write_COM(0x00,0x0C);
   LCD_Write_DATA(0x00,0x00); // RGB interface setting
   LCD_Write_COM(0x00,0x0D);
   LCD_Write_DATA(0x00,0x00); // Frame marker Position
   LCD_Write_COM(0x00,0x0F);
   LCD_Write_DATA(0x00,0x00); // RGB interface polarity
   //*************Power On sequence ****************//
   LCD_Write_COM(0x00,0x10);
   LCD_Write_DATA(0x00,0x00); // SAP, BT[3:0], AP, DSTB, SLP, STB
   LCD_Write_COM(0x00,0x11);
   LCD_Write_DATA(0x00,0x07); // DC1[2:0], DC0[2:0], VC[2:0]
   LCD_Write_COM(0x00,0x12);
   LCD_Write_DATA(0x00,0x00); // VREG1OUT voltage
   LCD_Write_COM(0x00,0x13);
   LCD_Write_DATA(0x00,0x00); // VDV[4:0] for VCOM amplitude
   LCD_Write_COM(0x00,0x07);
   LCD_Write_DATA(0x00,0x01);
   delay_ms(50); // Dis-charge capacitor power voltage
   LCD_Write_COM(0x00,0x10);
   LCD_Write_DATA(0x10,0x90); // 1490//SAP, BT[3:0], AP, DSTB, SLP, STB
   LCD_Write_COM(0x00,0x11);
   LCD_Write_DATA(0x02,0x27); // DC1[2:0], DC0[2:0], VC[2:0]
   delay_ms(50); // Delay 50ms
   LCD_Write_COM(0x00,0x12);
   LCD_Write_DATA(0x00,0x1F); //001C// Internal reference voltage= Vci;
   delay_ms(50); // Delay 50ms
   LCD_Write_COM(0x00,0x13);
   LCD_Write_DATA(0x15,0x00); //0x1000//1400 Set VDV[4:0] for VCOM amplitude 1A00
   LCD_Write_COM(0x00,0x29);
   LCD_Write_DATA(0x00,0x27); //0x0012 //001a Set VCM[5:0] for VCOMH //0x0025 0034
   LCD_Write_COM(0x00,0x2B);
   LCD_Write_DATA(0x00,0x0D); // Set Frame Rate 000C
   delay_ms(50); // Delay 50ms
   LCD_Write_COM(0x00,0x20);
   LCD_Write_DATA(0x00,0x00); // GRAM horizontal Address
   LCD_Write_COM(0x00,0x21);
   LCD_Write_DATA(0x00,0x00); // GRAM Vertical Address
   // ----------- Adjust the Gamma Curve ----------//
   LCD_Write_COM(0x00,0x30);
   LCD_Write_DATA(0x00,0x00);
   LCD_Write_COM(0x00,0x31);
   LCD_Write_DATA(0x07,0x07);
   LCD_Write_COM(0x00,0x32);
   LCD_Write_DATA(0x03,0x07);
   LCD_Write_COM(0x00,0x35);
   LCD_Write_DATA(0x02,0x00);
   LCD_Write_COM(0x00,0x36);
   LCD_Write_DATA(0x00,0x08);//0207
   LCD_Write_COM(0x00,0x37);
   LCD_Write_DATA(0x00,0x04);//0306
   LCD_Write_COM(0x00,0x38);
   LCD_Write_DATA(0x00,0x00);//0102
   LCD_Write_COM(0x00,0x39);
   LCD_Write_DATA(0x07,0x07);//0707
   LCD_Write_COM(0x00,0x3C);
   LCD_Write_DATA(0x00,0x02);//0702
   LCD_Write_COM(0x00,0x3D);
   LCD_Write_DATA(0x1D,0x04);//1604
   //------------------ Set GRAM area ---------------//
   LCD_Write_COM(0x00,0x50);
   LCD_Write_DATA(0x00,0x00); // Horizontal GRAM Start Address
   LCD_Write_COM(0x00,0x51);
   LCD_Write_DATA(0x00,0xEF); // Horizontal GRAM End Address
   LCD_Write_COM(0x00,0x52);
   LCD_Write_DATA(0x00,0x00); // Vertical GRAM Start Address
   LCD_Write_COM(0x00,0x53);
   LCD_Write_DATA(0x01,0x3F); // Vertical GRAM Start Address
   LCD_Write_COM(0x00,0x60);
   LCD_Write_DATA(0xA7,0x00); // Gate Scan Line
   LCD_Write_COM(0x00,0x61);
   LCD_Write_DATA(0x00,0x01); // NDL,VLE, REV
   LCD_Write_COM(0x00,0x6A);
   LCD_Write_DATA(0x00,0x00); // set scrolling line
   //-------------- Partial Display Control ---------//
   LCD_Write_COM(0x00,0x80);
   LCD_Write_DATA(0x00,0x00);
   LCD_Write_COM(0x00,0x81);
   LCD_Write_DATA(0x00,0x00);
   LCD_Write_COM(0x00,0x82);
   LCD_Write_DATA(0x00,0x00);
   LCD_Write_COM(0x00,0x83);
   LCD_Write_DATA(0x00,0x00);
   LCD_Write_COM(0x00,0x84);
   LCD_Write_DATA(0x00,0x00);
   LCD_Write_COM(0x00,0x85);
   LCD_Write_DATA(0x00,0x00);
   //-------------- Panel Control -------------------//
   LCD_Write_COM(0x00,0x90);
   LCD_Write_DATA(0x00,0x10);
   LCD_Write_COM(0x00,0x92);
   LCD_Write_DATA(0x06,0x00);
   LCD_Write_COM(0x00,0x07);
   LCD_Write_DATA(0x01,0x33); // 262K color and display ON
   output_high(CS);
}

void Pant(char VH,char VL)
{
   
   int i,j;
   output_low(CS);
   Address_set(0,0,240,320);
   for(i=0;i<320;i++)
   {
      for (j=0;j<240;j++)
      {
      LCD_Write_DATA(VH,VL);
      }
   }
   output_high(CS);
}

void main(void)
{
   char hi,lo;
   unsigned long i, j, k;
   set_Tris_B(0x0);
   set_Tris_D(0x0);
   while(true)
   {
      LCD_Init();
      //Pant(0xff,0xff);
      output_low(CS);
      for(k=0;k<8;k++)//8
      {
         for(j=0;j<6;j++)//6
         {
            Address_set(40*j,40*k,40*j+39,40*k+39);
            for(i=0;i<1600;i++)//1600
            {
               LCD_Write_DATA(image[i*2+1],image[i*2]);
            }
         }
      }
      output_high(CS);
      delay_ms(3000);
   }
}
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu May 23, 2013 7:00 am     Reply with quote

Hi,

You need to take some small steps first! Do you know for a fact that your PIC is actually running? Do you know for a fact that it's running at the correct speed? Every one of my projects has a power LED driven by an I/O pin. I flash this LED at startup to tell me that the PIC is running. During early program development I set the flash rate to be one second On, one second Off, to let me know the PIC is running at the intended speed.

That display is a 3.3V unit, and your PIC is a 5V device. Can you tell us how you are powering each device, and how you are connecting the PIC to the display? The datasheet states that you need to use voltage dividers on the display I/O pins if the PIC is powered at 5V. Do you have a schematic?

An easy way to overcome any interface problems would be to use the 'LF' version of your PIC and to power it at 3.3V.

John
drolleman



Joined: 03 Feb 2011
Posts: 116

View user's profile Send private message

PostPosted: Thu May 23, 2013 10:35 am     Reply with quote

I have developed on a 320 x 240 on a 18f part and found that it was slow! I then moved to a 33f part and it improved. but still slow, now I use a 33ep part @70 and it's acceptable. I now have a 7" screen @640 x 480 and will use 2 ep parts to drive it we will see how it works. just imagine my video card has 3000 cores, so what chance does a single core have to drive video? it would be nice if microchip would produce a multi core mcu.
drolleman



Joined: 03 Feb 2011
Posts: 116

View user's profile Send private message

PostPosted: Thu May 23, 2013 10:45 am     Reply with quote

1. put a lot of delays in starting out slow is ok.
2. scope your pins make sure the signals are getting through correctly.
3. voltage dividers will slow down response time.
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Thu May 23, 2013 4:30 pm     Reply with quote

I have been working with a TFTLCD that uses the same controller ILI9325 in 8bit mode.

http://www.adafruit.com/products/335
Yes the one I am using is pricey but it does 3.3/5V and is easy to connect to proto board.

I like this one too:
http://imall.iteadstudio.com/display/im120419009.html

I have working code for PC and PIC18F4550 for any ILI9325 GLCD that uses 8bit mode that can print to screen and draw a rgb565 bitmap gets the data from PC over USB connection for above GLCD. I have been working on the bugs/code clean up before ready for release. Just some of the gfxlib draw functions have bugs but that doesn't effect the print text and the bitmap drawing.

It takes 400ms to a draw picmap from usb sent data. I think this is as fast as I can make it. The use of a the 8bit port and the speed of the PIC limits this. I am using fast io and all of portD.
It was worse before I switched to bulk transfers and I did some work with the PC code side to queue 64K of USB data then call the PC side bulk_write function and not call it for each 64 byte packet.

Now are you wanting to learn how to do this yourself or do you think you would find my code useful? I converted adafruit's ILI9325 driver code over to CCS C. I need to make sure that I do what they require for release before release the driver code. I think, I just need keep it GPL and give them credit. But if you want to look at it/use it I will do that and release it ASAP on my git hub


notes on your code:

Now is there a reason you can't wire up port D of the pic to the 8bit bus on the 40pin header? The way you are doing it is gonna be really slow. looking at the docs for your GLCD use all of port D from the pic to go to DB8-15 pins on the 40pin header of the GLCD. The D0-D8 pins on the 40pin header should be connected to ground.

Then you could just use output_d( VH ) then do a WR_STROBE for the high byte then again for the lo byte.

Try this you should be able to to read the read ID data even if the LCD init didnt go right. just make sure reset pin is RST_ACTIVE. The following code will require changes to your wiring. I use the #bit stuff as it is faster way of accessing pins. If working readID() should return 0x9325




Code:

#use fast_io(d)
#use fast_io(b)


#bit RD_PIN = getenv( "SFR:PORTB" ).1 //PIN_B1
#bit WR_PIN = getenv( "SFR:PORTB" ).2 //PIN_B2
#bit CD_PIN = getenv( "SFR:PORTB" ).3 //PIN_B3
#bit CS_PIN = getenv( "SFR:PORTB" ).4 //PIN_B4

#define RD_ACTIVE       RD_PIN = 0    // Control signals are ACTIVE LOW (idle is HIGH)
#define RD_IDLE         RD_PIN = 1    // Command/Data: LOW = command, HIGH = data
#define WR_ACTIVE       WR_PIN = 0
#define WR_IDLE         WR_PIN = 1
#define CD_COMMAND      CD_PIN = 0
#define CD_DATA         CD_PIN = 1
#define CS_ACTIVE       CS_PIN = 0
#define CS_IDLE         CS_PIN = 1
#define RST_ACTIVE      output_high(PIN_A0);                                     
#define RST_INACTIVE    output_low(PIN_A0);
                                   
#define RD_STROBE { RD_ACTIVE; RD_IDLE; }
#define WR_STROBE { WR_ACTIVE; WR_IDLE; }

unsigned int16 readID(void)
{

  unsigned int16  id;

  CS_ACTIVE;
  CD_COMMAND;
  write8(0x00);
  WR_STROBE;         // Extra strobe because high, low bytes are the same
  setReadDir();      // Set up LCD data port(s) for READ operations
  CD_DATA;
  id   = read8();       
  id <<= 8;             
  delay_ms( 2 );       
  id  |= read8();       
  CS_IDLE;
  setWriteDir();     // Restore LCD data port(s) to WRITE configuration

  return id;
}


void write8( int8 data )
{
   output_d( data );
   WR_STROBE;
}

unsigned int8 read8(void)
{
   RD_STROBE;
   return input_d();
}

void setWriteDir(void)
{
   SET_TRIS_D( 0x00 );
}

void setReadDir(void)
{
   SET_TRIS_D( 0xFF );
}
ninoq



Joined: 22 May 2013
Posts: 14

View user's profile Send private message

PostPosted: Fri May 24, 2013 9:19 am     Reply with quote

Following up on MikeP's post, I'm getting 0x9393 not 0x9325. It seems to me that I'm reading the first byte (0x93) twice and not getting the second byte which I assume is 0x25. If I omit the second read I get 0x9300. I've tried changing the ReadID function so that it does the write/read cycle twice but it didn't help. I also tried adding an extra "WR_STROBE".

I'd appreciate advice/comments.
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Fri May 24, 2013 3:13 pm     Reply with quote

sorry I forgot something, I set port to all output in my glcd_init function.

Do a SET_TRIS_B( 0x00 );

somewhere in your main before calling readID.

I think the tris defaults to 0xFF which is inputs. This may not be the problem but its the first thing I see after look over my cut and pasted code from last post. Sorry about that.
ninoq



Joined: 22 May 2013
Posts: 14

View user's profile Send private message

PostPosted: Fri May 24, 2013 5:26 pm     Reply with quote

My main had a Set_Tris_B in it:
Code:

void main (void)
{
   unsigned int16 ID;
   SET_TRIS_B( 0x00 );
   RST_ACTIVE;
   ID = readID();
   printf("\r\nID=%Lx\r\n",ID);
}


Does not being able to elicit 0x9325 suggest there could be a hardware problem with the controller?

Do you think there could be timing issues?

With regard to the ReadID function:
Code:

unsigned int16 readID(void)
{
  unsigned int16  id;
  CS_ACTIVE;
  CD_COMMAND;
  write8(0x00);
  WR_STROBE;        // Extra strobe because high, low bytes are the same
  setReadDir();      // Set up LCD data port(s) for READ operations
  CD_DATA;
  id = read8();       
  id <<= 8;       
  delay_ms( 2 );     
  id  |= read8();     
  CS_IDLE;
  setWriteDir();     // Restore LCD data port(s) to WRITE configuration
  return id;
}

I'm not clear on how the second byte is elicited. I would've thought that the 0x00 command would have to be repeated to elicit the second byte or is there some sort of handshaking whereby reading the first byte elicits the second one?

PS. I did make a change to your original code - I used PinB0 instead of A0 for RST.
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Fri May 24, 2013 7:49 pm     Reply with quote

Yes this could be a timing issue. I will think about that more if the following code for you doesn't work. I know this code that I am posting is working I just tested it 2 times once without commenting out the line resetILI932x(); and once with that line commented out like the post is. Try both ways.

Note the reply you get can be 0x9325 or 0x9328 they are the same for the most part.

In 8bit mode you must read the HiByte and LoByte
In 8bit mode you must write the HiByte and LoByte

write8(0x00);
WR_STROBE; // Extra strobe because high, low bytes are the same

The above writes the HiByte and Lobyte of a 16bit word. The glcd looks for 2 WR_STROBES that how it knows when to sample its data bus and the CD_COMMAND; starts and CD_DATA; ends the command write part. Since the write8 function already did output_d( 0x00 ) thats what the glcd sees when you do the WR_STROBE;. So it will read the above as 0x0000
Code:

#include <18F4550.h>
#fuses NOWDT,NOPROTECT,NOLVP,NODEBUG,VREGEN,PUT
#use delay(crystal=20M)
#use rs232(baud=57200, UART1)

#use fast_io(d)
#use fast_io(b)


#bit RD_PIN = getenv( "SFR:PORTB" ).1 //PIN_B1
#bit WR_PIN = getenv( "SFR:PORTB" ).2 //PIN_B2
#bit CD_PIN = getenv( "SFR:PORTB" ).3 //PIN_B3
#bit CS_PIN = getenv( "SFR:PORTB" ).4 //PIN_B4

#define RD_ACTIVE       RD_PIN = 0    // Control signals are ACTIVE LOW (idle is HIGH)
#define RD_IDLE         RD_PIN = 1    // Command/Data: LOW = command, HIGH = data
#define WR_ACTIVE       WR_PIN = 0
#define WR_IDLE         WR_PIN = 1
#define CD_COMMAND      CD_PIN = 0
#define CD_DATA         CD_PIN = 1
#define CS_ACTIVE       CS_PIN = 0
#define CS_IDLE         CS_PIN = 1
#define RST_ACTIVE      output_high(PIN_A0);                                     
#define RST_INACTIVE    output_low(PIN_A0);
                                   
#define RD_STROBE { RD_ACTIVE; RD_IDLE; }
#define WR_STROBE { WR_ACTIVE; WR_IDLE; }




void write8( int8 data )
{
   output_d( data );
   WR_STROBE;
}

unsigned int8 read8(void)
{
   RD_STROBE;
   return input_d();
}

void setWriteDir(void)
{
   SET_TRIS_D( 0x00 );
}

void setReadDir(void)
{
   SET_TRIS_D( 0xFF );
}

unsigned int16 readID(void)
{

  unsigned int16  id;

  CS_ACTIVE;
  CD_COMMAND;
  write8(0x00);
  WR_STROBE;         // Extra strobe because high, low bytes are the same
  setReadDir();      // Set up LCD data port(s) for READ operations
  CD_DATA;
  id   = read8();       
  id <<= 8;             
  delay_ms( 2 );       
  id  |= read8();       
  CS_IDLE;
  setWriteDir();     // Restore LCD data port(s) to WRITE configuration

  return id;
}

void setupIO( void )
{

   CS_IDLE; // Set all control lines to idle state
   WR_IDLE;
   RD_IDLE;
   CD_DATA;

   RST_ACTIVE; // Reset line

   SET_TRIS_B( 0x00 );                                             
   setWriteDir(); // Set up LCD data port for WRITE operations
   
}

void resetILI932x(void)
{

  unsigned int8 i;
 
  CS_IDLE;
  CD_DATA;
  WR_IDLE;
  RD_IDLE;

  RST_INACTIVE;
  delay_ms(2);
  RST_ACTIVE;

  CS_ACTIVE;
  CD_DATA;
  write8(0x00);
  for( i=0; i<7; i++)
      WR_STROBE;
  CS_IDLE;
delay_ms(100);
}

void main( void )
{

   setupIO();
   //resetILI932x();
   
   printf( "ICID: %Lx \r\n", readID() );

}
ninoq



Joined: 22 May 2013
Posts: 14

View user's profile Send private message

PostPosted: Sat May 25, 2013 4:28 pm     Reply with quote

I tried the code both ways and the result was the same - "ICID: 9393".

I'm not sure what to do next - I've rechecked the wiring and it's in order. Perhaps I should approach the vendor and/or the manufacturer.

Advice/comments would be appreciated.
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Sat May 25, 2013 8:52 pm     Reply with quote

I cant get the page for your GLCD to load to look at the info on it


It seems to be in 16bit mode, does it default to that mode? What I remember from the quick look I give it the other day you had to change one of the resistors to another set of pads for 8bit mode. I assumed that you already did that since you were reading it in 8bit mode with your code. Did you change any of that?

Because if you tied d0-d7 to ground like we talked about and writing 0x00 it would get the 0x0000 part but only be able to read the high byte which is 0x93. I would almost be willing to bet that if after the program we have been using ran if you take the wires off d0-d7 and looked at each of those pins for high or low with multimeter the binary pattern would equal 0x25.

Lets add a while loop so we know the pic will stay in a known state. while you measure the pins.

Code:

void main( void )
{

   setupIO();
   //resetILI932x();
   
   printf( "ICID: %Lx \r\n", readID() );
   while(TRUE) { ; }
}


If you you have already set the GLCD up for 8bit mode then this could be a timing issue. We are close because you are getting the right high byte 0x93.

Maybe others can help us here but would the way the web site for the glcd he is using said to lower the voltage coming from the pic slow the control/data lines down that much?

Anyway if you do have the LCD setup right you can try this

Code:

unsigned int8 read8(void)
{
   RD_STROBE;
   delay_ms(2);
   return input_d();
}
ninoq



Joined: 22 May 2013
Posts: 14

View user's profile Send private message

PostPosted: Sat May 25, 2013 9:34 pm     Reply with quote

I disconnected DB0-7 from ground and added "while(TRUE) {;}" at the end of main. The ID changed from 0x9393 to 0x0000. I tested DB0-7 with a logic probe and a multimeter. The logic probe was neutral for all of the pins and the multimeter gave about -0.7V for each pin.

Early on I did query the vendor on the default mode and was assured that the display I got was in 8 bit mode.

For clarification I'm directly supplying 3.3V to the display.
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Sat May 25, 2013 11:04 pm     Reply with quote

Disconnect DB0-7 from ground when the pic gets to the while line not before.
You should still get the 0x9300 out of it. Then measure pins d0-d7.

You need to leave them connect to ground so the write it sees is 0x0000.

I can't get to the page for the info on your GLCD. You need to read it and check that they really did what they said they did for you. If I remember right they come defaulted to 16bit mode.

Just so we all know you are running the PIC at 3.3V also?
Is it a 18F4550?
ninoq



Joined: 22 May 2013
Posts: 14

View user's profile Send private message

PostPosted: Sun May 26, 2013 12:00 am     Reply with quote

To confirm - I'm using a PIC18F4550 (40-Pin PDIP). Pins 11 & 32 are connected to +5V and pins 12 & 31 to ground. The display's LED-A pin is connected directly to +3.3V on the same breadboard power supply used for the PIC18F4550.

I left DB0-7 connected to ground and waited till I got ICID:9393 and then disconnected DB0-7 from ground. I checked pins DB0-7 with both a logic probe and multimeter and got the same as before: neutral(no connection?) and -0.8V on each of the 8 pins.
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Sun May 26, 2013 12:24 am     Reply with quote

Is that GLCD 5V safe? The PIC is outputting 5V to it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group