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

18f8722 and T6963c

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



Joined: 09 Dec 2009
Posts: 37

View user's profile Send private message

18f8722 and T6963c
PostPosted: Mon May 24, 2010 11:52 am     Reply with quote

Hi all,
I am using GLCD 240x 128.
I am using the driver from this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=31255

When I connect the control signals of the LCD to PortC 4-7, and using the driver without changing it works great.
But in my real hardware I am using PortJ 4-7 for control signals. I modified the driver to PortJ, but still I could not see anything on the LCD.
I have been trying for 2 days. I wish you can help to solve the problem.

Here the source code for test :
Code:

#include <18F8722.h>
//#device *=16
//#device adc=10
#use delay(clock=4000000)//,RESTART_WDT)
#use rs232(baud=9600, xmit=PIN_A2,rcv=PIN_A3)
#fuses NOWDT,HS, NOPUT, PROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG,MCU

#include <T6963C2.c>

void main() {
   int n;
   int8 bt_logo[11] = { //8x11 picture
      0b00010000,      //     XX
      0b00011000,      //     XXXX
      0b00010100,      //     XX  XX
      0b01010010,      // XX  XX    XX
      0b00110100,      //   XXXX  XX
      0b00011000,      //     XXXX
      0b00110100,      //   XXXX  XX
      0b01010010,      // XX  XX    XX
      0b00010100,      //     XX  XX
      0b00011000,      //     XXXX
      0b00010000       //     XX
   };

   glcd_init(240,128);
   glcd_WriteByte(1, (LCDModeSet|LCDMode_XOR));
   glcd_WriteByte(1, (LCDDispMode|LCDDisp_TXT|LCDDisp_GRH));
   glcd_gotoxy(3,0,1);  // 1 = text area of memory; note that there are only
                        // 8 rows of text possible
   glcd_putc("HELLO  ");
   

  glcd_gotoxy(4,1,1);  // 1 = text area of memory; note that there are only
                        // 8 rows of text possible
   glcd_putc("WELCOME");
   
   glcd_line(1,100,200,100,1);
glcd_image8(&bt_logo[0],212,40,8,11);
     
   glcd_line(1,50,1,100,1);

 glcd_square(2,32,130,113,1);
// glcd_box(25,25,50,40,1);
 //  glcd_box(60,30,100,60,0);

   glcd_line(3,6,20,50,1);
   glcd_line(100,40,210,20,1);
   glcd_box(14,14,100,60,1);
   glcd_box(60,30,100,60,0);
   glcd_square(20,12,180,50,1);
   glcd_image8(&bt_logo[0],212,40,8,11);
   glcd_image8(&bt_logo[0],216,40,8,11);

   glcd_line(30,6,200,100,1);
   
   glcd_square(2,32,130,113,1);
   
   glcd_image8(&bt_logo[0],26,110,8,11);
}


here is the driver
Code:

/////////////////////////////////////////////////////////////////////////
////    T6963C2.c     -      T6963C driver                            ////
////   Not for comercial Use                                         ////
////      Driver by treitmey Graphic functions and Resolution Select ////   
////                                    by endSly (endsly@gmail.com) ////
////                                                                 ////
//// 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 - - j4                                                     ////
////  /RD - - j5                                                     ////
////  C//D- - j6                                                     ////
////  /RST- - j7                                                     ////
////  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

#define set_tris_lcd(x) set_tris_d(x)
#define LCDColorBlack 0b1
#define LCDColorWhite 0b0

//TRIS DataBus=x,  note:control bus (PORTC) always outputs
unsigned int16 TextHome = 0x0F00;//0x0780;
const int8  TextArea = 0x001E; // how many bytes before a new line
const int16 GraphicsHome = 0x0000;
const int8  GraphicsArea = 0x001E; // 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 int8 LCDBitSet   = 0xF8;
const int8 LCDBitReset = 0xF0;
const int8 LCDBit0 = 0b000;
const int8 LCDBit1 = 0b001;
const int8 LCDBit2 = 0b010;
const int8 LCDBit3 = 0b011;
const int8 LCDBit4 = 0b100;
const int8 LCDBit5 = 0b101;
const int8 LCDBit6 = 0b110;
const int8 LCDBit7 = 0b111;

const int8 LCDSetPtr = 0xE0;



struct lcd_pin_def

   BOOLEAN unused1;    // j0
   BOOLEAN unused2;    // j1
   BOOLEAN unused3;  // j2
   BOOLEAN unused4;  // j3


   BOOLEAN w_bar;  // j4 Write bar active low
   BOOLEAN r_bar;  // j5 Read bar active low
   BOOLEAN cd;         // j6 Command/Data BAR   1=command 0=data
  BOOLEAN reset_bar;  // j7 Reset active low
   
   int  data    :  8;  // PortD=Data bus
};
struct lcd_pin_def  LCD;

  #byte LCD = 0xf88   // portj address on 18F8722

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);

#inline
void glcd_init(unsigned int16 res_x, unsigned int16 res_y) {
   
  int16 counter;
 
  TextHome = (res_x/8)*res_y; //0x0F00;//0x0780;
 
  set_tris_J(0x00);  // graphic lcd control lines all output
  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(10);      // 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) * line) + x;
   glcd_WriteCmd2(location, 0x24);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose:       Clears LCD RAM
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_clr(int16 location,int16 size)
{
  ////fprintf(DEBUG,"loc=%lu  size=%lu\n\r",location,size);
  // look very simular to the init,... doesn't it. : )
  glcd_WriteCmd2(location,LCDSetPtr);
  glcd_WriteCmd1(1,AutoModeWrite);
  for (;size;size--)
  {
    glcd_WriteByteAuto(0x00);//clear ram
  }
  glcd_WriteCmd1(1,AutoModeReset);
}

/////////////////////////////////////////
// Graphics Controller by endSly (c)2007
//    endSly@gmail.com
//       Not for comercial use
/////////////////////////////////////////

unsigned int8 i;  //General Purpouse variable

// glcd_pixel(x,y,c) sets pixel x,y with c color
void glcd_pixel(unsigned int8 x, unsigned int8 y, int1 c){
   unsigned int8 x_H;
   unsigned int8 x_L=0;
   x_H = (x / 8);
   x_L = 7 - (x - 8*x_H);
   glcd_gotoxy(x_H,y,0);    //Bug fixed, thanks to etiedon
   if(c){
      glcd_WriteCmd1(1,(LCDBitSet|x_L));
   } else {
      glcd_WriteCmd1(1,(LCDBitReset|x_L));
   }
}

// glcd_pixel8(x,y,px8) sets 8 pixels in line.
void glcd_pixel8(unsigned int8 x, unsigned int8 y, int8 pixel8){
   unsigned int8 x_H;
   x_H = (x / 8);
   glcd_gotoxy(x_H+1,y,0);
   glcd_WriteCmd1(pixel8,0xc0);
}

// glcd_line(x0,y0, x1,y1, c) puts line from (x0, y0) to (x1, y1) with c color
#separate
void glcd_line(signed int16 x0, signed int16 y0,
               signed int16 x1, signed int16 y1 , int1 c){
   int16 x;
   int16 y;
   unsigned int16 n;
   int1 m_case;
   
   x=abs(x1-x0);
   y=abs(y1-y0);
   
   if (y > x){
      n=(y1-y0);
      m_case=1;
   } else {
      n=(x1-x0);
      m_case=0;
   }
   for(i=0 ; i<=n ; i++){
      if (m_case){
         y=i + y0;
         x=(y*(x1-x0))/(y1-y0) + x0;
      } else {
         x=i + x0;
         y=(x*(y1-y0))/(x1-x0) + y0;
      }
      glcd_pixel(x, y,c);
   }
                         
}

// glcd_square(x0,y0,x1,y1, c) sets square
void glcd_square( unsigned int8 x0, unsigned int8 y0,
                  unsigned int8 x1, unsigned int8 y1 , int1 c){
   glcd_line(x0,y0, x1,y0, c);
   glcd_line(x1,y0, x1,y1, c);
   glcd_line(x0,y1, x1,y1, c);
   glcd_line(x0,y0, x0,y1, c);
}

// glcd_box(x0,y0,x1,y1, c)
void glcd_box( unsigned int8 x0, unsigned int8 y0,
               unsigned int8 x1, unsigned int8 y1 , int1 c){
   unsigned int8 x;
   unsigned int8 y;
   for(y=y0; y<=y1;y++){
      for(x=x0; x<=x1;x++){
         if((!(x%8)) && ((x1-x)>8)){
            glcd_pixel8(x,y,0xFF*c);  //Same time to write 8 pixel
            x +=7 ;
         } else {
            glcd_pixel(x,y,c);
         }
      }
   }
}

//glcd_image8 (*Pic, x, y, size_x, size_y)
void glcd_image8(int8 *pic_px, unsigned int8 x, unsigned int8 y,
                 unsigned int8 size_x, unsigned int8 size_y){
   
   unsigned int8 px_y;
   unsigned int8 px_x;
   unsigned int8 px=0;
   
   for(px_y=y; px_y<(y+size_y); px_y++){
      for(px_x=x; px_x<(x+size_x); px_x+=8){
         glcd_pixel8(px_x, px_y, *(pic_px+px));
         px+=1;
      }
   }
}
#use fast_io(D)

The data port is still PortD.

Thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 24, 2010 12:03 pm     Reply with quote

See this thread about how to enable PortJ for normal i/o:
http://www.ccsinfo.com/forum/viewtopic.php?t=23622
assaad



Joined: 09 Dec 2009
Posts: 37

View user's profile Send private message

PostPosted: Tue May 25, 2010 1:53 am     Reply with quote

thank you PCM for fast reply

I did what you said ,
infact the main problem was in the header structure of LCD

the old one was :
Code:

struct lcd_pin_def

   BOOLEAN unused1;    // j0
   BOOLEAN unused2;    // j1
   BOOLEAN unused3;  // j2
   BOOLEAN unused4;  // j3


   BOOLEAN w_bar;  // j4 Write bar active low
   BOOLEAN r_bar;  // j5 Read bar active low
   BOOLEAN cd;         // j6 Command/Data BAR   1=command 0=data
  BOOLEAN reset_bar;  // j7 Reset active low
   
   int  data    :  8;  // PortD=Data bus
};
struct lcd_pin_def  LCD;

  #byte LCD = 0xf88   // portj address on 18F8722


lcd.data was mapped to LATA
so I have to change it to
Code:

struct lcd_pin_def


    int  data    :  8;  // PortD=Data bus

   int  unused_data1    :  8;  // Porte
   int  unused_data2    :  8;  // Portf
   int  unused_data3    :  8;  // Portg
   int  unused_data4    :  8;  // Porth
 
   BOOLEAN unused1;    // j0
   BOOLEAN unused2;    // j1
   BOOLEAN unused3;  // j2
   BOOLEAN unused4;  // j3


   BOOLEAN w_bar;  // j4 Write bar active low
   BOOLEAN r_bar;  // j5 Read bar active low
   BOOLEAN cd;         // j6 Command/Data BAR   1=command 0=data
  BOOLEAN reset_bar;  // j7 Reset active low
   
   
};
struct lcd_pin_def  LCD;

  #byte LCD = 0xf83   // portd address on 18F8722

now it works , but is there any other simpler way to define lcd.data as portd in the old structure ?


Thank you
kurusaray19



Joined: 22 Dec 2011
Posts: 1

View user's profile Send private message

PostPosted: Thu Dec 22, 2011 3:52 am     Reply with quote

Hello. I have a question you would have friends. I need the code according to the chart below. glcd winstar WG24064A. PIC 18F8722 for.

WR=E3
RD=E4
CE=E5
CD=E6
RST=E7

DATA PINS = PORTD
CeMiL_mktrnk



Joined: 21 Mar 2012
Posts: 4

View user's profile Send private message

PostPosted: Wed Mar 21, 2012 8:13 am     Reply with quote

noyz wrote:
Code:

//// 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) ////

How can I change this?
I have a board already connected and need to redefine those.
For example the data pins from glcd are H0-H7 instead d0-d7 on pic.
Pic used is 18f8527.



data pins from glcd are B0-B7 instead d0-d7 on pic.
Pic used is 18f4620.
But control pins arent all any port. For example I use d3, d2, d1 and d7 pins for data write, data read, C/D and reset, I use d0, d4, d5 for SPI. Also I will connect MS2 to e1 and FS1 to e2.

Can you send me upgrated driver or explain where I have to change?
Please help me urgently
CeMiL_mktrnk



Joined: 21 Mar 2012
Posts: 4

View user's profile Send private message

PostPosted: Mon Mar 26, 2012 2:19 am     Reply with quote

Is there anybody who can help me? It is urgent.
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