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

ks0108 128x64glcd interface problem
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
sresam89



Joined: 15 Mar 2012
Posts: 20
Location: India

View user's profile Send private message

ks0108 128x64glcd interface problem
PostPosted: Thu Mar 15, 2012 1:43 pm     Reply with quote

Dear all,
I am having a tough time interfacing pic16f877a with Glcd 128x64 running in KS0108. I am getting all the data being sent displayed. The problem is only half the display is always displayed. I can' make the full display to show any content. I am attaching the screenshot and the program.
I am using ccs compiler and the example programs and default drivers.
http://www.edaboard.com/attachments/70863d1331801572-photo-0012.jpg
http://www.edaboard.com/attachments/70864d1331801632-photo-0003.jpg
Code:

#include <HDM64GS12.c>
#include <graphics.c>
#include <math.h>

#byte trisa=0x85
#byte trisb=0x86
#byte trisc=0x87
#byte trisd=0x88
#byte trise=0x89
#byte porta=0x05
#byte portb=0x06
#byte portc=0x07
#byte portd=0x08

void displayVoltage(int adc) {
   char voltage[9];
   sprintf(voltage, "%f", (float)adc * .01960784); // Converts adc to text
   voltage[4] = '\0';                              // Limit shown digits to 3
   glcd_rect(45, 18, 69, 25, YES, OFF);            // Clear the old voltage
   glcd_text57(45, 18, voltage, 1, ON);            // Write the new voltage
}

void main() {
   int1  warn = FALSE;
   int8  adc = 0, adc_old = 0;
   char  voltText[] = "VoLtS\0", warning[] = "Warning";
   float theta = 0;

   setup_adc_ports(RA0_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);
   
   TRISA = 0x00;
   TRISB = 0x00;
   TRISC = 0x00;
   TRISD = 0x00;
   TRISE = 0x00;
   porta=0x00;
while(1)
{
   glcd_init(ON);                               // Must initialize the LCD
   //glcd_rect(1, 1, 126, 126, YES, ON);            // Outline the bar
   glcd_text57(50, 100, voltText, 1, ON);        // Display "Volts"
   glcd_circle(30,47, 10, NO, ON);             // Draw the clock circle
  porta=~porta;
  delay_ms(300);
 //  for(;;) {
      adc = read_adc();                         // Read a value from the ADC
      displayVoltage(adc);                      // Display the reading
      adc = (adc > 249) ? 249 : adc;            // Keep the value 249 or less

      if(adc != adc_old) {
         glcd_rect(adc/2+1, 6, adc_old/2+1, 14, YES, OFF);  // Clears the old bar
         glcd_rect(1, 6, adc/2+1, 14, YES, ON);             // Draws a new bar
         adc_old = adc;                                     // Set old value to new

         if(adc > 200 && !warn) {                  // Check if over 4 volts
            glcd_rect(45, 38, 124, 55, YES, ON);   // Draw a filled black rectangle
            glcd_text57(47, 40, warning, 2, OFF);  // Write "Warning" on the LCD
            warn = TRUE; }
         else if(adc <=200 && warn) {
            glcd_rect(45, 37, 125, 55, YES, OFF);  // Draw a filled white rectangle
            warn = FALSE; }
      }

      // The following 3 lines make the clock hand spin around
      glcd_line(30, 47, 30+(int)(8*sin(theta)+.5), 47-(int)(8*cos(theta)+.5), OFF);
      theta = (theta > 5.9) ? 0 : (theta += .3);
      glcd_line(30, 47, 30+(int)(8*sin(theta)+.5), 47-(int)(8*cos(theta)+.5), ON);

      #ifdef FAST_GLCD
      glcd_update();
      #else
      delay_ms(100);    // Reduces flicker by allowing pixels to be on
                        // much longer than off
      #endif
   }
}
ezflyr



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

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 7:55 am     Reply with quote

Hi,

The KS0108 uses two chip select lines, CS1 and CS2. Each one controls half the display, so your problem description suggests an issue in this area. You really should not be manually setting TRIS, so errors here are a possibility. Also be sure that neither chip select is connected to a pin that is "open drain".

John
sresam89



Joined: 15 Mar 2012
Posts: 20
Location: India

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 8:05 am     Reply with quote

ezflyr wrote:
Hi,

The KS0108 uses two chip select lines, CS1and CS2. Each one controls half the display, so your problem description suggests an issue in this area. You really should not be manually setting TRIS, so errors here are a possibility. Also be sure that neither chip select is connected to a pin that is "open drain".

John

i will check on the CS pins, what is your suggestion on the MANUALLY selecting the TRIS i didn't get you on that sorry.
ezflyr



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

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 8:12 am     Reply with quote

Hi,

The default compiler mode is 'standardio' where the compiler sets the TRIS automatically.

John
sresam89



Joined: 15 Mar 2012
Posts: 20
Location: India

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 8:37 am     Reply with quote

ezflyr wrote:
Hi,

The default compiler mode is 'standardio' where the compiler sets the TRIS automatically.

John


I hope you would be knowing that am using picc compiler.

If so can you just explain in detail what you are saying as I am still in a confusion on standardio you were telling.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 1:05 pm     Reply with quote

He means the CCS compiler will automatically set the correct TRIS for
you, if you use their built-in functions. You don't need to directly set the TRIS.

Post a list of all your connections between the PIC and the GLCD.
Also, check the connections to make sure they are correct.
sresam89



Joined: 15 Mar 2012
Posts: 20
Location: India

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 3:23 pm     Reply with quote

PCM programmer wrote:
He means the CCS compiler will automatically set the correct TRIS for
you, if you use their built-in functions. You don't need to directly set the TRIS.

Should I be using any default driver or library files for that ? I don't know this functionality in detail.
Can you please give the function names for doing so.
How will the compiler be knowing of our requirement of setting the pins in ports as IP or OP ?

Quote:

Post a list of all your connections between the PIC and the GLCD.


The pin connections are as in the default glcd driver in picc compiler directory for the file GLCD.c
Code:

* 1: VSS is connected to GND                                   ////
////  * 2: VDD is connected to +5V                                   ////
////  * 3: V0 - LCD operating voltage is connected from a 20k Ohm POT////
////  * 4: D/I - Data or Instruction is connected to B2              ////
////  * 5: R/W - Read or Write is connected to B4                    ////
////  * 6: Enable is connected to B5                                 ////
////  *7-14: Data Bus 0 to 7 is connected to port d                  ////
////  *15: Chip Select 1 is connected to B0                          ////
////  *16: Chip Select 2 is connected to B1                          ////
////  *17: Reset is connected to C0                                  ////
////  *18: Negative voltage is also connected to the 20k Ohm POT     ////
////  *19: Positive voltage for LED backlight is connected to +5V    ////
////  *20: Negavtive voltage for LED backlight is connected to GND   ////


Quote:

Also, check the connections to make sure they are correct.

The connections are double checked.
sresam89



Joined: 15 Mar 2012
Posts: 20
Location: India

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 3:28 pm     Reply with quote

ezflyr wrote:
Hi,

The KS0108 uses two chip select lines, CS1 and CS2. Each one controls half the display, so your problem description suggests an issue in this area. You really should not be manually setting TRIS, so errors here are a possibility. Also be sure that neither chip select is connected to a pin that is "open drain".

John

hope PORTB0 & PORTB1 is not open drain.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 4:11 pm     Reply with quote

Here is a way to let CCS handle the TRIS:
Quote:

#byte trisa=0x85
#byte trisb=0x86
#byte trisc=0x87
#byte trisd=0x88
#byte trise=0x89
#byte porta=0x05
#byte portb=0x06
#byte portc=0x07
#byte portd=0x08

Delete all the above lines.
Also if you have a line for #use fast_io, then delete it.

Quote:

TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
TRISD = 0x00;
TRISE = 0x00;

Delete all the above.


Quote:
porta=0x00;

Delete this, and add the following:
Code:

int8 porta_value;

porta_value = 0;
output_a(porta_value);


Quote:

porta=~porta;

Delete this and change it to:
Code:

porta_value = ~porta_value;
output_a(porta_value);
sresam89



Joined: 15 Mar 2012
Posts: 20
Location: India

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 11:00 pm     Reply with quote

PCM programmer wrote:
Here is a way to let CCS handle the TRIS:


so you say the compiler would automatically comes the know the tris configuration we need to have?

just to clear myself
say all my portc pins are inputs except for portc0 which i have given for glcd enable will my compiler set trisc accordingly?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 11:21 pm     Reply with quote

Yes, it will. The compiler generates code to set the correct TRIS when
it sees these lines:
Code:

output_high(GLCD_E);   

output_low(GLCD_E);

Set the .LST file format for "Symbolic" in the Project / Build Options menu
and then compile the file. Look at those lines in the .LST file and you
will see that the compiler sets the TRIS to output whenever it executes
those lines.
sresam89



Joined: 15 Mar 2012
Posts: 20
Location: India

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 11:32 pm     Reply with quote

PCM programmer wrote:
Yes, it will. .


thank you so much sir

sir can you just post the HDM64GS12.c, GLCD.h GLCD.c files for my use

am now getting not sure of the integrity of the files i have, also may i ask i have been using 4Mhz crystal for my board. but when i look in the example program i used from the picc directory EX_GLCD.C i just noticed this
Code:

#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#define FAST_GLCD    // Try commenting this out to see the differences
#endif


where i replaced all the above lines to suite my project

what am concerned from the example program now in this is this line
Code:

#use delay(clock=20000000)


for this should i be modifying the delay values in the GLCD.c and HDM64GS12.c files to suite them for 4Mhz?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 11:59 pm     Reply with quote

We are not allowed to post CCS files. If you have the compiler, then
you have the files. If you don't trust them, then re-install the compiler
or get a later version of the compiler.

If you are using a 4 MHz crystal, then change the #use delay() statement
to 4 MHz. The #use delay() statement must match the oscillator
frequency of the PIC.

Don't modify the delay values in any of the files. Just edit the #use delay
value to match your PIC oscillator frequency. The compiler will
automatically adjust the delays to be correct.
sresam89



Joined: 15 Mar 2012
Posts: 20
Location: India

View user's profile Send private message

PostPosted: Sat Mar 17, 2012 4:04 am     Reply with quote

ezflyr wrote:
Hi,

The KS0108 uses two chip select lines, CS1 and CS2. Each one controls half the display, so your problem description suggests an issue in this area. You really should not be manually setting TRIS, so errors here are a possibility. Also be sure that neither chip select is connected to a pin that is "open drain".

John



i have checked for the pins integrity its seems fine.as you said i noticed the changes cs1 and cs2 could make in pic simulator. i tried the same in my code still nothing.
i tried even changing the portB to portC still no luck the half display remains the same only thing i could figure out is that(if as ezflyr says) the problem could be with none other than CS2 pin connected to portB.1 later changed to portc.2
i dont find trouble while running in simulator it works just fine but not in the hardware. i have double checked the hardware and the lcd too.

please help sir
sresam89



Joined: 15 Mar 2012
Posts: 20
Location: India

View user's profile Send private message

PostPosted: Sat Mar 17, 2012 6:14 am     Reply with quote

dear pcm programmer and ezflyr
i tried an exchange between cs1 and cs2 pins then am getting the other half of the display on the left side, confirming that my datas are coming out properly. but why is that only my left side of the display is only working not the right?

i have attached the link to a snap taken after the exchange of the CS pins

is there any other method to check the full functionality of my display?

[img]
https://picasaweb.google.com/sresam89/Project?authkey=Gv1sRgCP3WsOikn7-kcw
[/img]

please help
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