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

[SOLVED]How to use glcd data pin from pin8 to pin15 ?
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
borseyogesh1436



Joined: 30 Nov 2017
Posts: 29

View user's profile Send private message

[SOLVED]How to use glcd data pin from pin8 to pin15 ?
PostPosted: Tue Jan 02, 2018 12:55 am     Reply with quote

Hi friends
I want to use Glcd data pin from pin 8 to pin 15 of portD of pic24FJ96GA010 and also use portd 4,5,7 for CS 1&2 RST of GLCD.
Changes are made in void glcd_writeByte(int1 side, int8 data) and BYTE glcd_readByte(int1 side).

Code is working when i use PORTF for CS1,2 & RST of glcd, but not working when used PORTD PIN 4,5 and 7 for CS1,2 & RST.

How to send 8 bit data without affecting rst and cs1&2 ?

pic24FJ96GA010 with compiler PCD Ver.5.015

FULL PROGRAM AND CIRCUIT
https://drive.google.com/file/d/1D-OMci3YKztx68kuMQpVusV99kK3je-N/view?usp=sharing

Code:

#define GLCD_CS1    PIN_D4   // Chip Selection 1
#define GLCD_CS2    PIN_D5   // Chip Selection 2
#define GLCD_DI      PIN_F3   // Data or Instruction input
#define GLCD_RW     PIN_A14   // Read/Write
#define GLCD_E       PIN_A15   // Enable
#define GLCD_RST    PIN_D7   // Reset

void glcd_writeByte(int1 side, int8 data)
{
   if(side)                   // Choose which side to write to
      output_high(GLCD_CS2);
   else
      output_high(GLCD_CS1);

   output_low(GLCD_RW);       // Set for writing
   output_d(data<<8);            // Put the data on the port
   delay_cycles(1);
   output_high(GLCD_E);       // Pulse the enable pin
   delay_cycles(5);
   output_low(GLCD_E);
   output_low(GLCD_CS1);      // Reset the chip select lines
   output_low(GLCD_CS2);
}

BYTE glcd_readByte(int1 side)
{
   int8 data;              // Stores the data read from the LCD

   set_tris_d(0xFF00);          // Set port d to input
   output_high(GLCD_RW);      // Set for reading

   if(side)                   // Choose which side to write to
   output_high(GLCD_CS2);
   else
   output_high(GLCD_CS1);

   delay_cycles(1);
   output_high(GLCD_E);       // Pulse the enable pin
   delay_cycles(4);
   data = input_d();          // Get the data from the display's output register
   data=data>>8;
   output_low(GLCD_E);
   output_low(GLCD_CS1);      // Reset the chip select lines
   output_low(GLCD_CS2);
   return data;               // Return the read data
}


THANKS


Last edited by borseyogesh1436 on Sat Jan 06, 2018 5:38 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 02, 2018 5:55 am     Reply with quote

I don't use that PIC but the obvious answers are
1) those pins are input only
2) those pins have another peripheral on them
3) those pins are grounded or not connected to GLCD

ohmeter proves #3, the datasheet #1 and #2

Jay
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Tue Jan 02, 2018 7:56 am     Reply with quote

In both routines you shift data left by eight bits:

Code:

output_d(data<<8);

As data is int8, what you are doing is shifting all the bits out of the byte. You need to cast to 16 bits before shifting:

Code:

output_d((int16)data<<8);


Remember, in C, where you put the result of the expression does not determine what type the expression variables need to be.

When you read, the ports on 24s are sixteen bits wide, so you need to assign to an int16 and then shift. At the moment you assign it to an int8, loosing the top eight bits, i.e. the data, completely.

Better yet, use Uint8 and Uint16 rather than int8 and int16. The results of shifts on signed variables are not defined in C. Int is signed on 24s (PCD compiler) but unsigned on 18/16/12/10s (PCM and PCH compilers).

Neither of these has anything to do with port d.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 02, 2018 9:51 am     Reply with quote

OK....can anyone explain WHY you'd alter the data from the GLCD display?
The OP does the right shift >>8, I'd expect to NOT alter the data but them I don't use GLCDs...

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 02, 2018 12:14 pm     Reply with quote

Quote:
How to send 8 bit data without affecting rst and cs1&2 ?

You are not using #fast_io, so CCS i/o functions will set the TRIS before
they do the read or write operation. These i/o functions include input_d()
and output_d(), etc.

This means the following line in your glcd_readByte() function will set
all pins on PortD to be inputs.
Quote:
data = input_d();

But this will ruin pins CS1,2 & RST, which must always be outputs.


--------------------------------
temtronic, he says the reason in his post:
Quote:
I want to use Glcd data pin from pin 8 to pin 15 of portD

He is using the upper 8 bits of a 16-bit i/o port on a PIC24.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 02, 2018 12:30 pm     Reply with quote

hmm 16 bit port...doh ! I must be getting old ( or too cold). My mind's kinda stuck in 'BYTE' mode as I'm always using 16 or 18 series I forget about the 'big brother' version of PICs.

2nd hmm... anyone cut code for a 'flex_GLCD'?

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Tue Jan 02, 2018 1:33 pm     Reply with quote

It's worth realising you can cheat.

If you use:
Code:

#BYTE PORTDH=getenv("SFR:PORTD+1

//You can then write to the high byte of PORTD, without changing
//the TRIS, by just writing to PORTDH

PORTDH=data;
borseyogesh1436



Joined: 30 Nov 2017
Posts: 29

View user's profile Send private message

PostPosted: Tue Jan 02, 2018 10:46 pm     Reply with quote

Thanks for reply friends
Quote:
output_d((int16)data<<8);

Code:
void glcd_writeByte(int1 side, int8 data)
{
   set_tris_d(0x0000);
   if(side)                   // Choose which side to write to
      output_high(GLCD_CS2);
   else
      output_high(GLCD_CS1);

   output_low(GLCD_RW);       // Set for writing
   output_d((int16)data<<8);         // Put the data on the port
   delay_cycles(1);
   output_high(GLCD_E);       // Pulse the enable pin
   delay_cycles(5);
   output_low(GLCD_E);
   output_low(GLCD_CS1);      // Reset the chip select lines
   output_low(GLCD_CS2);
}

BYTE glcd_readByte(int1 side)
{
   int8 data; int16 dat;             // Stores the data read from the LCD

   set_tris_d(0xFF00);          // Set port d to input
   output_high(GLCD_RW);      // Set for reading

   if(side)                   // Choose which side to write to
   output_high(GLCD_CS2);
   else
   output_high(GLCD_CS1);

   delay_cycles(1);
   output_high(GLCD_E);       // Pulse the enable pin
   delay_cycles(4);
   dat = input_d();          // Get the data from the display's output register
   data=(int8)dat>>8;
   output_low(GLCD_E);
   output_low(GLCD_CS1);      // Reset the chip select lines
   output_low(GLCD_CS2);
   return data;               // Return the read data
}


This doesn't work it will effect on cs1,2and RST but LCD data PIN 8 to PIN15 work


And another change
Quote:
#BYTE PORTDH=getenv("SFR:PORTD+1
PORTDH=data;


It is showing error string too long

I think proper syntax is
Quote:
#BYTE PORTDH=getenv("SFR:PORTD")

I try this
Quote:
#BYTE PORTDH=getenv("SFR:PORTD+1")

But it will showing error
Expecting an identifier bad SFR name


I have ready made hardware setup so that I change LCD pins on software only

I try other compiler xc16

Quote:
PORTD & =0X00FF;
PORTD |= (data<<8);


It will work and not affecting cs1,2and RST.

But I have to use CCS without changing hardware. Pls help me friends.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 02, 2018 11:56 pm     Reply with quote

I suspect that he wants you to do this:
Code:
#BYTE PORTDH=getenv("SFR:PORTD")+1
borseyogesh1436



Joined: 30 Nov 2017
Posts: 29

View user's profile Send private message

PostPosted: Wed Jan 03, 2018 12:24 am     Reply with quote

thanks for reply

its working but after connect rst to 5v

its affecting RST PIN only that is connected to PIND.7 its showing 0v

why affecting only RST PIN ?

output_high(GLCD_RST); IS HIGH IN glcd_init

i change code of TRISDH without that not working proper

Code:
#BYTE PORTDH=getenv("SFR:PORTD")+1
#BYTE TRISDH=getenv("SFR:TRISD")+1


void glcd_init(int1 mode)
{
   // Initialze some pins
   output_high(GLCD_RST);
   output_low(GLCD_E);
   output_low(GLCD_CS1);
   output_low(GLCD_CS2);

   output_low(GLCD_DI);                 // Set for instruction
   glcd_writeByte(GLCD_LEFT,  0xC0);    // Specify first RAM line at the top
   glcd_writeByte(GLCD_RIGHT, 0xC0);    //   of the screen
   glcd_writeByte(GLCD_LEFT,  0x40);    // Set the column address to 0
   glcd_writeByte(GLCD_RIGHT, 0x40);
   glcd_writeByte(GLCD_LEFT,  0xB8);    // Set the page address to 0
   glcd_writeByte(GLCD_RIGHT, 0xB8);

   if(mode == ON)
   {
      glcd_writeByte(GLCD_LEFT,  0x3F); // Turn the display on
      glcd_writeByte(GLCD_RIGHT, 0x3F);
   }
   else
   {
      glcd_writeByte(GLCD_LEFT,  0x3E); // Turn the display off
      glcd_writeByte(GLCD_RIGHT, 0x3E);
   }

   glcd_fillScreen(OFF);                // Clear the display

   #ifdef FAST_GLCD
   glcd_update();
   #endif
}


void glcd_writeByte(int1 side, int8 data)
{ set_tris_d(0x0000);
  output_high(GLCD_RST);
   if(side)                   // Choose which side to write to
      output_high(GLCD_CS2);
   else
      output_high(GLCD_CS1);

   output_low(GLCD_RW);       // Set for writing
   PORTDH=data;
   //output_d((int16)data<<8);         // Put the data on the port
   delay_cycles(1);
   output_high(GLCD_E);       // Pulse the enable pin
   delay_cycles(5);
   output_low(GLCD_E);
   output_low(GLCD_CS1);      // Reset the chip select lines
   output_low(GLCD_CS2);
}


// Purpose:    Reads a byte of data from the specified chip
// Ouputs:     A byte of data read from the chip
BYTE glcd_readByte(int1 side)
{
   int8 data; //int16 dat;             // Stores the data read from the LCD

   TRISDH=0xFF;               // Set port d to input
   output_high(GLCD_RW);      // Set for reading

   if(side)                   // Choose which side to write to
   output_high(GLCD_CS2);
   else
   output_high(GLCD_CS1);

   delay_cycles(1);
   output_high(GLCD_E);       // Pulse the enable pin
   delay_cycles(4);
   data = PORTDH  ;        // Get the data from the display's output register
   output_low(GLCD_E);
   output_low(GLCD_CS1);      // Reset the chip select lines
   output_low(GLCD_CS2);
   return data;               // Return the read data
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Jan 03, 2018 1:41 am     Reply with quote

Apologies. The bracket got missed.

Typing on the train.

PCM_programmer has given the correct syntax.

The point is you don't want to be taling to PORTD (this would be the low byte), but the address of PORTD, +1, is the address of just the high byte, using byte I/O.

I'm quite worried by your compiler version number. 5.015, was a relatively early 'workable' V5 compiler, and I'd not be surprised if this had problems with some features. However D7 is a pin I'd not expect any problems with (hasn't got any other peripheral on it that would affect I/O). Are you _sure_ the physical connection to the pin is working?. Leave everything disconnected, and just toggle this pin. Does it toggle as it should?.
borseyogesh1436



Joined: 30 Nov 2017
Posts: 29

View user's profile Send private message

PostPosted: Wed Jan 03, 2018 2:25 am     Reply with quote

Thanks for reply.

Physical connection to the all pin is correct and working properly. I test other compiler "XC16" program for testing is working correctly and PIND7 is also toggle as
Code:
   
output_high(PIN_D7);
delay_ms(1000);
output_low(PIN_D7);
delay_ms(1000);


But when i try full code the RST pin always LOW. If it's LOW GLCD doesn't show anything and after i disconnect RST pin and connect that to 5V, LCD working properly in normal mode GLCD. FAST_GLCD MODE its not working any thing.

code and connection

https://drive.google.com/file/d/1PdXr-zwNcDfkmTQuxhC6rc_aoYGfjkeE/view?usp=sharing
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Jan 03, 2018 3:01 am     Reply with quote

If you look through the listing file, RST is being set high:
Code:

....................    output_high(GLCD_RST);
*
043C:  BCLR.B  2D2.7
043E:  BSET.B  2D6.7

0x2D2 is the TRIS and 2D6 is the port.

If we then search for 2D6, there are no other instructions on the code turning this bit off. What is the drive current requirement of the RST pin on your LCD?.
It may just require more current than the PIC is able to deliver. What happens if you pull it up with a 100R resistor, rather than a direct connection?.
borseyogesh1436



Joined: 30 Nov 2017
Posts: 29

View user's profile Send private message

PostPosted: Wed Jan 03, 2018 3:29 am     Reply with quote

thanks for replay Ttelmah

pullup with 100R is not working, direct 5v is working

i try that code with other device i have PIC30f6014Ai try that code with other device i have PIC30f6014A see if it's working or not

thanks once again friends Laughing Laughing Laughing
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Jan 03, 2018 4:32 am     Reply with quote

The 6014A, is an 80pin chip, while the GA010, is a 100pin chip. I'd be quadruple checking the connections....

Do you have a data sheet for the GLCD?.
What current does it say the RST pin requires?.
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