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

T6963C Graphic LCD display trouble

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








T6963C Graphic LCD display trouble
PostPosted: Tue Dec 20, 2005 2:28 pm     Reply with quote

Hello.
I am trying to get an 128x64 lcd display based on the T6963C chip to work with an pic16f877
I actually had it working for a while by using some code i found here, but, when i rewired the circut and tested it on a different PIC (16f917), then it suddently stopped working. I have now gone back to the 16f877, but im doing something wrong.... can anyone help?

This is the "driver" that im using:
Code:


/////////////////////////////////////////////////////////////////////////
////                                                                 ////
//// This file contains drivers for using a Tosiba T6963C controller ////
//// in parallel/8080(intel) mode.  The T6963C is 240 pixels across  ////
////  and 64 pixels down. The driver treats the upper left pixel 0,0 ////
////                                                                 ////
////  Connections are as follows:                                    ////
////  /WR - - C4                                                     ////
////  /RD - - C5                                                     ////
////  C//D- - C6                                                     ////
////  /RST- - C7                                                     ////
////  DATA0-7 PORTD0-7                                               ////
////  LCD's FS is tied low (FS = 0 is 8x8 font)                      ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////

// 240 x 64 in the 8x8 font mode means that 30 characters across by
// 8 rows of characters may be displayed
#ifndef GLCD_COL
#define GLCD_COL 128    // Used for text wrapping by glcd_text57 function and sanity check
#endif
#ifndef GLCD_ROW
#define GLCD_ROW 64    // Used for text wrapping by glcd_text57 function and sanity check
#endif
#define set_tris_lcd(x) set_tris_d(x)
#define ON  1
#define OFF 0
#define YES 1
#define NO  0
#define glcd_WriteCmd0(x) glcd_WriteByte(1,x)
#define LCDSetPtr 0x24
#define LCDTxtAdr(x,y) 0x780+(128)+(30*y)+x

//TRIS DataBus=x,  note:control bus (PORTC) always outputs
const int16 TextHome = 0x0000;
const int8  TextArea = 0x0010; // how many bytes before a new line
const int16 GraphicsHome = 0x0101;
const int8  GraphicsArea = 0x0010; // how many bytes before a new line

const int8 AutoModeWrite = 0xB0;
const int8 AutoModeRead  = 0xB1;
const int8 AutoModeReset = 0xB2;

const int8 LCDModeSet  = 0x80;   // send this OR'd with the following
const int8 LCDMode_OR  = 0b0000;
const int8 LCDMode_XOR = 0b0001;
const int8 LCDMode_AND = 0b0010;
const int8 LCDMode_TA  = 0b0100; // TEXT ATTRIBUTE mode.
const int8 LCDMode_RAM = 0b1000; // 1=CG RAM, 0=internal CG ROM

const int8 LCDSetCursorPtr  = 0x21;  // cursor address
const int8 LCDSetCursorSize = 0xA0;  // 1 line cursor

const int8 LCDDispMode = 0x90;   // send this OR'd with the following
const int8 LCDDisp_BLK = 0b0001;
const int8 LCDDisp_CUR = 0b0010;
const int8 LCDDisp_TXT = 0b0100;
const int8 LCDDisp_GRH = 0b1000;

const int1 LCDFont = 0;//FS pin has internal pull-up. FS=1 unless grounded
const int8 LCDField = 8; //CAMBIO:8 POR 6 //FS=1 then field=6. FS=0 then field=8
const int8 LCDCharWidth = GLCD_COL /LCDField;
const int16 CharPerScn= LCDCharWidth*16; //CAMBIO: 16 por 8 //number of characters on a screen

struct lcd_pin_def
{
   BOOLEAN unused1;    // C0
   BOOLEAN unused2;    // C1
   BOOLEAN unused3;  // C2
   BOOLEAN unused4;  // C3
   BOOLEAN w_bar;  // C4 Write bar active low
   BOOLEAN r_bar;  // C5 Read bar active low
   BOOLEAN cd;         // C6 Command/Data BAR   1=command 0=data
   BOOLEAN reset_bar;  // C7 Reset active low
   int  data    :  8;  // PortD=Data bus
};
struct lcd_pin_def  LCD;

#byte LCD = 0x07    // portC address on 18F877
int   glcd_ReadByte(void);
void  glcd_WriteByte(int1 cd, int data);
void  glcd_WriteByteAuto(int data);
void  glcd_WriteCmd2(int16 data, int cmd);
void  glcd_WriteCmd1(int data, int cmd);
void  glcd_gotoxy(int x, int y, int1 text);
void glcd_clr(int16 location, int16 size);

int16 ERRORS;
//BOOLEAN glcd_pixel(unsigned int x,unsigned int y, int1 color);

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Clears LCD RAM
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_clr(int16 location,int16 size)
{
glcd_WriteCmd2(location,LCDSetPtr);
glcd_WriteCmd0(AutoModeWrite);
for (;size;size--)
{
glcd_WriteByteAuto(0x00);//clear ram
}
glcd_WriteCmd0(AutoModeReset);
}

///////////////////////////////////////////////////////////////////////
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose:       Turn a pixel on a graphic LCD on or off
// Inputs:        x - the x coordinate of the pixel
//                y - the y coordinate of the pixel
//                color - ON or OFF
// Output:        1 if coordinate out of range, 0 if in range
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
glcd_pixel(int16 x,int16 y, int1 color)
{
  int8 r=0,c=0;
  c=color;//converting booean to an int8
  if (x>=GLCD_COL)
  {
    bit_set(ERRORS,5);//ERRORS=bit 5. LCD x range exceeded
    return (FALSE);
  }
  if (y>=GLCD_ROW)
  {
    bit_set(ERRORS,6);//ERRORS=bit 6. LCD y range exceeded
    return (FALSE);
  }

r=fmod(x,8);
  glcd_WriteCmd2(GraphicsHome+(y*16+(x/8)),LCDSetPtr);
  glcd_WriteCmd0(0xf0|(c<<3) |(7-r));
}



// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose:       Draw a line on a graphic LCD using Bresenham's
//                line drawing algorithm
// Inputs:        (x1, y1) - the start coordinate
//                (x2, y2) - the end coordinate
//                color - ON or OFF
// Dependencies:  glcd_pixel()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_line(int x1, int y1, int x2, int y2, int1 color)
{
  signed int  x, y, addx, addy, dx, dy;
  signed long P;
  int i;
  dx = abs((signed int)(x2 - x1));
  dy = abs((signed int)(y2 - y1));
  x = x1;
  y = y1;
  if(x1 > x2)
    addx = -1;
  else
    addx = 1;
  if(y1 > y2)
    addy = -1;
  else
    addy = 1;
  if(dx >= dy)
  {
    P = 2*dy - dx;
    for(i=0; i<=dx; ++i)
    {
      glcd_pixel(x, y, color);
      if(P < 0)
      {
        P += 2*dy;
        x += addx;
      }
      else
      {
        P += 2*dy - 2*dx;
        x += addx;
        y += addy;
      }
    }
  }
  else
  {
    P = 2*dx - dy;
    for(i=0; i<=dy; ++i)
    {
      glcd_pixel(x, y, color);
      if(P < 0)
      {
        P += 2*dx;
        y += addy;
      }
      else
      {
        P += 2*dx - 2*dy;
        x += addx;
        y += addy;
      }
    }
  }
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose:       Draw a rectangle on a graphic LCD
// Inputs:        (x1, y1) - the start coordinate
//                (x2, y2) - the end coordinate
//                fill  - YES or NO
//                color - ON or OFF
// Dependencies:  glcd_pixel(), glcd_line()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_rect(int x1, int y1, int x2, int y2, int fill, int1 color)
{
  if(fill)
  {
    int y, ymax;                          // Find the y min and max
    if(y1 < y2)
    {
      y = y1;
      ymax = y2;
    }
    else
    {
      y = y2;
      ymax = y1;
    }

    for(; y<=ymax; ++y)                    // Draw lines to fill the rectangle
    glcd_line(x1, y, x2, y, color);
  }
  else
  {
    glcd_line(x1, y1, x2, y1, color);      // Draw the 4 sides
    glcd_line(x1, y2, x2, y2, color);
    glcd_line(x1, y1, x1, y2, color);
    glcd_line(x2, y1, x2, y2, color);
  }
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose:       Draw a bar (wide line) on a graphic LCD
// Inputs:        (x1, y1) - the start coordinate
//                (x2, y2) - the end coordinate
//                width  - The number of pixels wide
//                color - ON or OFF
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_bar(int x1, int y1, int x2, int y2, int width, int1 color)
{
  signed int  x, y, addx, addy, j;
  signed long P, dx, dy, c1, c2;
  int i;
  dx = abs((signed int)(x2 - x1));
  dy = abs((signed int)(y2 - y1));
  x = x1;
  y = y1;
  c1 = -dx*x1 - dy*y1;
  c2 = -dx*x2 - dy*y2;

  if(x1 > x2)
  {
    addx = -1;
    c1 = -dx*x2 - dy*y2;
    c2 = -dx*x1 - dy*y1;
  }
  else
  addx = 1;
  if(y1 > y2)
  {
    addy = -1;
    c1 = -dx*x2 - dy*y2;
    c2 = -dx*x1 - dy*y1;
  }
  else
  addy = 1;

  if(dx >= dy)
  {
    P = 2*dy - dx;

    for(i=0; i<=dx; ++i)
    {
      for(j=-(width/2); j<width/2+width%2; ++j)
      {
        if(dx*x+dy*(y+j)+c1 >= 0 && dx*x+dy*(y+j)+c2 <=0)
        glcd_pixel(x, y+j, color);
      }
      if(P < 0)
      {
        P += 2*dy;
        x += addx;
      }
      else
      {
        P += 2*dy - 2*dx;
        x += addx;
        y += addy;
      }
    }
  }
  else
  {
    P = 2*dx - dy;

    for(i=0; i<=dy; ++i)
    {
      if(P < 0)
      {
        P += 2*dx;
        y += addy;
      }
      else
      {
        P += 2*dx - 2*dy;
        x += addx;
        y += addy;
      }
      for(j=-(width/2); j<width/2+width%2; ++j)
      {
        if(dx*x+dy*(y+j)+c1 >= 0 && dx*x+dy*(y+j)+c2 <=0)
          glcd_pixel(x+j, y, color);
      }
    }
  }
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose:       Draw a circle on a graphic LCD
// Inputs:        (x,y) - the center of the circle
//                radius - the radius of the circle
//                fill - YES or NO
//                color - ON or OFF
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_circle(int x, int y, int radius, int1 fill, int1 color)
{
  signed int a, b, P;
  a = 0;
  b = radius;
  P = 1 - radius;

  do
  {
    if(fill)
    {
      glcd_line(x-a, y+b, x+a, y+b, color);
      glcd_line(x-a, y-b, x+a, y-b, color);
      glcd_line(x-b, y+a, x+b, y+a, color);
      glcd_line(x-b, y-a, x+b, y-a, color);
    }
    else
    {
      glcd_pixel(a+x, b+y, color);
      glcd_pixel(b+x, a+y, color);
      glcd_pixel(x-a, b+y, color);
      glcd_pixel(x-b, a+y, color);
      glcd_pixel(b+x, y-a, color);
      glcd_pixel(a+x, y-b, color);
      glcd_pixel(x-a, y-b, color);
      glcd_pixel(x-b, y-a, color);
    }

    if(P < 0)
      P+= 3 + 2*a++;
    else
      P+= 5 + 2*(a++ - b--);
  } while(a <= b);


void glcd_init(void) {
  int16 counter;
  set_tris_lcd(0xff);   //TRIS DATA bus,note:control bus always outputs

  LCD.w_bar = 1;      // INITIAL STATES OF CONTROL PINS
  LCD.r_bar = 1;      //
  LCD.cd = 1;         // command

  LCD.reset_bar = 0;  // perform a reset
  delay_us(20);      // delay for a reset
  LCD.reset_bar = 1;  // run

  // Set up the graphics and text areas
  glcd_WriteCmd2(TextHome, 0x40);
  glcd_WriteCmd2(TextArea, 0x41);
  glcd_WriteCmd2(GraphicsHome, 0x42);
  glcd_WriteCmd2(GraphicsArea, 0x43);

  // set address to 0
  glcd_WriteCmd2(0x0000, 0x24);
  glcd_WriteCmd2(0x0000, 0x24);

  // Clear all RAM of LCD (8k)
  glcd_WriteByte(1, AutoModeWrite);
  for (counter = 0; counter < 0x1fff; counter++)
  {
    glcd_WriteByteAuto(0);    // fill everything with zeros
  }
  glcd_WriteByte(1, AutoModeReset);
}



void glcd_WriteByte(int1 cd, int data)
{
    int status = 0, temp = 0;
    set_tris_lcd(0xff);
    LCD.w_bar = 1;
    LCD.r_bar= 1;
    LCD.cd = 1;//defaults

    while (status != 0x03) {  // is LCD busy?
       LCD.r_bar= 0;
       temp = LCD.data;
       LCD.r_bar = 1;
       status = temp & 0x03;
    }

    set_tris_lcd(0x00);    // All outputs
    LCD.cd = cd;           // Command/Data bar
    LCD.data = data;
    LCD.r_bar = 1;         // not read
    LCD.w_bar = 0;         // write
    LCD.w_bar = 1;         // release
}

void glcd_WriteByteAuto(int data)
{
   int status = 0, temp = 0; // status bits ARE DIFFERENT BITS THAN NORMAL
   set_tris_lcd(0xff);
   LCD.w_bar = 1;
   LCD.r_bar = 1;
   LCD.cd = 1; // defaults

   while (status != 0x08) {  // is LCD busy?
     LCD.r_bar = 0;
     temp = LCD.data;
     LCD.r_bar = 1;
     status = temp & 0x08;
   }

   set_tris_lcd(0x00);     // All outputs
   LCD.cd = 0;             // This is always data, cd=0
   LCD.data = data;        // Put data on data bus
   LCD.w_bar = 0;          // write
   LCD.w_bar = 1;          // release
}

void glcd_WriteCmd1(int data, int cmd)
{
  glcd_WriteByte(0, data);
  glcd_WriteByte(1, cmd);
}

void glcd_WriteCmd2(int16 data, int cmd)
{
  glcd_WriteByte(0, data & 0xff);
  glcd_WriteByte(0, data>>8);
  glcd_WriteByte(1, cmd);
}

int glcd_ReadByte(void)
{
  int data = 0, status = 0, temp = 0;
  set_tris_lcd(0xff);
  LCD.w_bar = 1;
  LCD.r_bar = 1;
  LCD.cd = 1;  // defaults

  #asm nop #endasm

  while (status != 0x03) {  // is LCD busy?
    LCD.r_bar = 0;
    temp = LCD.data;
    LCD.r_bar = 1;
    status = temp & 0x03;
  }

  LCD.cd = 0;          // Command/Data bar
  LCD.r_bar = 0;        // read
  /////////////////////////////////////////////////////////
  #asm nop #endasm    // THIS PAUSE IS VERY NESSESARY !!!//
  /////////////////////////////////////////////////////////
  data = LCD.data;
  LCD.r_bar = 1;
  LCD.cd = 1;
  return data;        // Return the read data
}

void glcd_putc(char c) {
   glcd_WriteCmd1(c - 0x20, 0xc0);
}

void glcd_gotoxy(int x, int y, int1 text) { // sets memory location to screen location x, y
   // location 1,1 is upper left corner;  text = 1 (text area), text = 0 (graphics area)
   int16 location, home;
   int line;

   if (!text) {
      home = GraphicsHome;
      line = GraphicsArea;
   }
   else {
      home = TextHome;
      line = TextArea;
   }

   location = home + (((int16)y - 1) * line) + x - 1;
   glcd_WriteCmd2(location, 0x24);
}

//////////////////////////////////////////////////////////////////
const BYTE TEXT[51][5] ={ 0x00, 0x00, 0x00, 0x00, 0x00, // SPACE
                          0x00, 0x00, 0x5F, 0x00, 0x00, // !
                          0x00, 0x03, 0x00, 0x03, 0x00, // "
                          0x14, 0x3E, 0x14, 0x3E, 0x14, // #
                          0x24, 0x2A, 0x7F, 0x2A, 0x12, // $
                          0x43, 0x33, 0x08, 0x66, 0x61, // %
                          0x36, 0x49, 0x55, 0x22, 0x50, // &
                          0x00, 0x05, 0x03, 0x00, 0x00, // '
                          0x00, 0x1C, 0x22, 0x41, 0x00, // (
                          0x00, 0x41, 0x22, 0x1C, 0x00, // )
                          0x14, 0x08, 0x3E, 0x08, 0x14, // *
                          0x08, 0x08, 0x3E, 0x08, 0x08, // +
                          0x00, 0x50, 0x30, 0x00, 0x00, // ,
                          0x08, 0x08, 0x08, 0x08, 0x08, // -
                          0x00, 0x60, 0x60, 0x00, 0x00, // .
                          0x20, 0x10, 0x08, 0x04, 0x02, // /
                          0x3E, 0x51, 0x49, 0x45, 0x3E, // 0
                          0x04, 0x02, 0x7F, 0x00, 0x00, // 1
                          0x42, 0x61, 0x51, 0x49, 0x46, // 2
                          0x22, 0x41, 0x49, 0x49, 0x36, // 3
                          0x18, 0x14, 0x12, 0x7F, 0x10, // 4
                          0x27, 0x45, 0x45, 0x45, 0x39, // 5
                          0x3E, 0x49, 0x49, 0x49, 0x32, // 6
                          0x01, 0x01, 0x71, 0x09, 0x07, // 7
                          0x36, 0x49, 0x49, 0x49, 0x36, // 8
                          0x26, 0x49, 0x49, 0x49, 0x3E, // 9
                          0x00, 0x36, 0x36, 0x00, 0x00, // :
                          0x00, 0x56, 0x36, 0x00, 0x00, // ;
                          0x08, 0x14, 0x22, 0x41, 0x00, // <
                          0x14, 0x14, 0x14, 0x14, 0x14, // =
                          0x00, 0x41, 0x22, 0x14, 0x08, // >
                          0x02, 0x01, 0x51, 0x09, 0x06, // ?
                          0x3E, 0x41, 0x59, 0x55, 0x5E, // @
                          0x7E, 0x09, 0x09, 0x09, 0x7E, // A
                          0x7F, 0x49, 0x49, 0x49, 0x36, // B
                          0x3E, 0x41, 0x41, 0x41, 0x22, // C
                          0x7F, 0x41, 0x41, 0x41, 0x3E, // D
                          0x7F, 0x49, 0x49, 0x49, 0x41, // E
                          0x7F, 0x09, 0x09, 0x09, 0x01, // F
                          0x3E, 0x41, 0x41, 0x49, 0x3A, // G
                          0x7F, 0x08, 0x08, 0x08, 0x7F, // H
                          0x00, 0x41, 0x7F, 0x41, 0x00, // I
                          0x30, 0x40, 0x40, 0x40, 0x3F, // J
                          0x7F, 0x08, 0x14, 0x22, 0x41, // K
                          0x7F, 0x40, 0x40, 0x40, 0x40, // L
                          0x7F, 0x02, 0x0C, 0x02, 0x7F, // M
                          0x7F, 0x02, 0x04, 0x08, 0x7F, // N
                          0x3E, 0x41, 0x41, 0x41, 0x3E, // O
                          0x7F, 0x09, 0x09, 0x09, 0x06, // P
                          0x1E, 0x21, 0x21, 0x21, 0x5E, // Q
                          0x7F, 0x09, 0x09, 0x09, 0x76};// R

const BYTE TEXT2[44][5]={ 0x26, 0x49, 0x49, 0x49, 0x32, // S
                          0x01, 0x01, 0x7F, 0x01, 0x01, // T
                          0x3F, 0x40, 0x40, 0x40, 0x3F, // U
                          0x1F, 0x20, 0x40, 0x20, 0x1F, // V
                          0x7F, 0x20, 0x10, 0x20, 0x7F, // W
                          0x41, 0x22, 0x1C, 0x22, 0x41, // X
                          0x07, 0x08, 0x70, 0x08, 0x07, // Y
                          0x61, 0x51, 0x49, 0x45, 0x43, // Z
                          0x00, 0x7F, 0x41, 0x00, 0x00, // [
                          0x02, 0x04, 0x08, 0x10, 0x20, // \
                          0x00, 0x00, 0x41, 0x7F, 0x00, // ]
                          0x04, 0x02, 0x01, 0x02, 0x04, // ^
                          0x40, 0x40, 0x40, 0x40, 0x40, // _
                          0x00, 0x01, 0x02, 0x04, 0x00, // `
                          0x20, 0x54, 0x54, 0x54, 0x78, // a
                          0x7F, 0x44, 0x44, 0x44, 0x38, // b
                          0x38, 0x44, 0x44, 0x44, 0x44, // c
                          0x38, 0x44, 0x44, 0x44, 0x7F, // d
                          0x38, 0x54, 0x54, 0x54, 0x18, // e
                          0x04, 0x04, 0x7E, 0x05, 0x05, // f
                          0x08, 0x54, 0x54, 0x54, 0x3C, // g
                          0x7F, 0x08, 0x04, 0x04, 0x78, // h
                          0x00, 0x44, 0x7D, 0x40, 0x00, // i
                          0x20, 0x40, 0x44, 0x3D, 0x00, // j
                          0x7F, 0x10, 0x28, 0x44, 0x00, // k
                          0x00, 0x41, 0x7F, 0x40, 0x00, // l
                          0x7C, 0x04, 0x78, 0x04, 0x78, // m
                          0x7C, 0x08, 0x04, 0x04, 0x78, // n
                          0x38, 0x44, 0x44, 0x44, 0x38, // o
                          0x7C, 0x14, 0x14, 0x14, 0x08, // p
                          0x08, 0x14, 0x14, 0x14, 0x7C, // q
                          0x00, 0x7C, 0x08, 0x04, 0x04, // r
                          0x48, 0x54, 0x54, 0x54, 0x20, // s
                          0x04, 0x04, 0x3F, 0x44, 0x44, // t
                          0x3C, 0x40, 0x40, 0x20, 0x7C, // u
                          0x1C, 0x20, 0x40, 0x20, 0x1C, // v
                          0x3C, 0x40, 0x30, 0x40, 0x3C, // w
                          0x44, 0x28, 0x10, 0x28, 0x44, // x
                          0x0C, 0x50, 0x50, 0x50, 0x3C, // y
                          0x44, 0x64, 0x54, 0x4C, 0x44, // z
                          0x00, 0x08, 0x36, 0x41, 0x41, // {
                          0x00, 0x00, 0x7F, 0x00, 0x00, // |
                          0x41, 0x41, 0x36, 0x08, 0x00, // }
                          0x02, 0x01, 0x02, 0x04, 0x02};// ~

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose:       Write text on a graphic LCD
// Inputs:        (x,y) - The upper left coordinate of the first letter
//                textptr - A pointer to an array of text to display
//                size - The size of the text: 1 = 5x7, 2 = 10x14, ...
//                color - ON or OFF
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_text57(int x, int y, char* textptr, int size, int1 color)
{
  const BYTE bytes_per_char=5;
  int i, j, k, l, m;                     // Loop counters
  BYTE pixelData[bytes_per_char];                     // Stores character data
  for(i=0; textptr[i] != '\0'; ++i, ++x) // Loop through the passed string
  {
    if(textptr[i] < 'S') // Checks if the letter is in the first or second array
    memcpy(pixelData, TEXT[textptr[i]-' '], bytes_per_char);
    else if(textptr[i] <= '~') // Check if the letter is in the second array
    memcpy(pixelData, TEXT2[textptr[i]-'S'], bytes_per_char);
    else
    memcpy(pixelData, TEXT[0], bytes_per_char);   // Default to space

    if(x+5*size >= GLCD_COL)          // Performs character wrapping
    {
      x = 0;                           // Set x at far left position
      y += 7*size + 1;                 // Set y at next position down
    }
    for(j=0; j<bytes_per_char; ++j, x+=size)         // 5 bytes per character
    {
      for(k=0; k<7*size; ++k)          // Loop through the vertical pixels
      {
        if(bit_test(pixelData[j], k)) // Check if the pixel should be set
        {
          for(l=0; l<size; ++l)      // The next two loops change the
          {                          // character's size
            for(m=0; m<size; ++m)
            {
              glcd_pixel(x+m, y+k*size+l, color); // Draws the pixel
            }
          }
        }
      }
    }
  }
}




And this is the main:

Code:
#include  <16F877A.H>
#fuses    XT,NOBROWNOUT,NOWDT,NOPROTECT
#use      delay (clock=4000000)
#include "math.h"
#include "glcd.c"






#use fast_io(D)

void main() {

   while(true)
   {
   output_high(pin_a1);
   delay_ms(1000);
   output_low(pin_a1);
   delay_ms(1000);
      set_tris_c(0x00);  // graphic lcd control lines all output
   glcd_init();
   glcd_WriteByte(1, (LCDModeSet|LCDMode_XOR));
   glcd_WriteByte(1, (LCDDispMode|LCDDisp_TXT|LCDDisp_GRH));

   glcd_gotoxy(3,2,1);

   glcd_putc("Hello");



   
   
   }



}


The "output_high(pin_a1);" part is just to check if the pic is up and running. When i connect a mulitmeter to pin_a1 it goes high and then low. But then it stops. If i remove the lcd initialization routine, then it works..(pin_a1 high and low evey second) So the pic hangs somewhere..

Really need some help here...

Thanks in advance
LTS
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 20, 2005 3:11 pm     Reply with quote

A few obvious comments:

1. Are you using a Low Voltage programmer ? If not, add NOLVP
to the end of the #fuses statement. Programmers such as
PicStart-Plus, ICD2, CCS ICD, Warp-13a and MachX are High Voltage
programmers, and the NOLVP setting should be used with them.

2. You have placed the "#use fast_io(D)" statement after the
#include "glcd.c" statement. This means that the LCD driver
will not use fast i/o. Remember, the fast_io() statement only
applies to code that comes after it in the file.


See the corrections shown below:

Quote:
#include <16F877A.H>
#fuses XT,NOBROWNOUT,NOWDT,NOPROTECT, NOLVP
#use delay (clock=4000000)
#include "math.h"

#use fast_io(D)
#include "glcd.c"


void main() {

while(true)
{
output_high(pin_a1);
delay_ms(1000);
output_low(pin_a1);
delay_ms(1000);
set_tris_c(0x00); // graphic lcd control lines all output
glcd_init();
glcd_WriteByte(1, (LCDModeSet|LCDMode_XOR));
glcd_WriteByte(1, (LCDDispMode|LCDDisp_TXT|LCDDisp_GRH));

glcd_gotoxy(3,2,1);

glcd_putc("Hello");

}
LTS



Joined: 08 Dec 2005
Posts: 8

View user's profile Send private message

PostPosted: Tue Dec 20, 2005 3:23 pm     Reply with quote

Hello
Thanks for suggestions, but it didn't change anything.. The LCD shows nothing... i can change contrast and everything but no text appears....What could cause the pic to hang in the lcd routine??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 20, 2005 4:10 pm     Reply with quote

You need to determine what line of code is causing the program to hang.

If you have a debugger such as ICD2, you can click on the Run button
and then after it's apparent that the program is hanging, you can click
on the halt button. In MPLAB a green arrow will point to the line of
C source code where the program is hanging.

If you don't have a debugger, you can use putc() statements to track
the progress of your code, and to show where it hangs. See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=21949&highlight=putc
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 20, 2005 4:33 pm     Reply with quote

This driver was based on work I did. So I am familiar with it.

Try something simple. init.
Do 1 init filling with 0x00 and wait 1sec and do another filling with 0xFF.
If that doesn't work check the timing of the #asm noop #endasm.

Also double check your ports. Looks like you want to use the port C.
But there is a #define that sets the tris and its using D.
And in main your using fastio on D.

Double check the ports.
LTS



Joined: 08 Dec 2005
Posts: 8

View user's profile Send private message

PostPosted: Tue Dec 20, 2005 5:44 pm     Reply with quote

I've triple checked the wires several times, but now i resoldered everything with new wires... and guess what.. IT WORKS! great. Thanks!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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