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

glcd 128x64 menu problem

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



Joined: 07 Feb 2012
Posts: 34

View user's profile Send private message

glcd 128x64 menu problem
PostPosted: Wed May 23, 2012 6:00 am     Reply with quote

hello guys !
i'm trying to build a project which is about measurement station , in this project i use a 128x64 glcd (ks0108) . i display menu +sub-mesnu and plot graph.
this project works well on proteus ,and doesn't work well on real hardware .
i use a keypad (4 buttons (up+down+ok+return) to navigate between menus )
the problem is i dont press anything and see changes, random display of menu .

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
this is a second part of code (menu controle )



glcd_init(on); /
glcd_showimage(&image_9);
while(1){

eta1:
if(input(pin_b1)==1) / RB1 : button "up"
{
delay_ms(30);
l=l+1; /inc of variable L { from 0 to 3 } i have 4 images .
if(l>3) l=0;
}
if(input(pin_b2)==1) /RB2: Button "down"
{
delay_ms(30);
l=l-1;
if(l>3) l=3;

}
switch(l)
{
case 0:glcd_showimage(&image_0); / l=0 then show first image .

if(input(pin_b3)==1) / RB3 : Button ok .
{
s=1;
while(s=1) / button ok pressed then send data via rs232
{
glcd_fillscreen(0);

glcd_text57(20,10,rs232,1,on);

printf("%f \n\r",current);
printf("%f \n\r",press);
printf("%f \n\r",volt);
printf("%f \n\r",temp);

if(input(pin_b4)==1) { // RB4: Button "return" if its pressed bck to show first image
s=0;
goto eta1;}
}
}
break;
case 1:glcd_showimage(&image_1); //l=1 then show second image
if(input(pin_b3)==1) //if ok button pressed
{
glcd_fillscreen(0);
framevolts(5,0,125,51); //framevolts use to show a frame for plotting
n=1;

while(n=1)
{
eta2: if(input(pin_b1)==1) // up button pressed
{
delay_ms(10);
m=m+1;
if(m>4) m=0; / i do same to first menu
}
if(input(pin_b2)==1)
{
delay_ms(10);
m=m-1;
if(m>4) m=4; //
}
if(input(pin_b4)==1)
{
goto eta1;
}
switch(m)
{

case 0: glcd_showimage(&image_5);
if(input(pin_b3)==1)
{
glcd_fillscreen(0);
framevolts(5,0,125,51);
glcd_text57(48,57,tmp1,1,on);
s2=1;
while(s2=1)
{
if(input(pin_b4)==1)
{
goto eta2;
}
draw((int)current*5); //plot variable current .
delay_ms(20);


}
}
break;
case 1:
glcd_showimage(&image_6);
if(input(pin_b3)==1)
{
glcd_fillscreen(0);
framevolts(5,0,125,51);
glcd_text57(48,57,tmp,1,on);
s2=1;
while(s2=1)
{
if(input(pin_b4)==1)
{
goto eta2;
}
draw((int)volt*20);
delay_ms(10);


}
}

break;
case 2:
glcd_showimage(&image_7);
if(input(pin_b3)==1)
{
glcd_fillscreen(0);
framevolts(5,0,125,51);
glcd_text57(48,57,tmp3,1,on);
s2=1;
while(s2=1)
{
if(input(pin_b4)==1)
{
goto eta2;
}
draw((int)press);
delay_ms(10);


}
}
break;
case 3:
glcd_showimage(&image_8);
if(input(pin_b3)==1)
{
glcd_fillscreen(0);
framevolts(5,0,125,51);
glcd_text57(48,57,tmp2,1,on);
s2=1;
while(s2=1)
{
if(input(pin_b4)==1)
{
goto eta2;
}
draw((int)temp);
delay_ms(5);


}
}

break;
case 4: glcd_showimage(&image_10);
if(input(pin_b3)==1)
{
glcd_fillscreen(0);
framevolts(5,0,125,51);
glcd_text57(48,57,tmp1,1,on);
s2=1;
while(s2=1)
{
if(input(pin_b4)==1)
{
goto eta2;
}
draw((int)current*5);
delay_ms(20);


}
}
break;
}
}
}
break;
case 2:glcd_showimage(&image_2);
if(input(pin_b3)==1)
{

}
break;
case 3:glcd_showimage(&image_3);
if(input(pin_b3)==1)
{
glcd_fillscreen(0);
glcd_rect(1,1,125,50,off,on);
delay_ms(20);
glcd_rect(10,10,110,40,off,on);
delay_ms(20);
glcd_text57(3,20,contact,1,on);
delay_ms(20);
glcd_text57(15,52,web,1,on);
delay_ms(800);
}
break;
}
}
}

here is a video that shows my problem (sorry i didn't find any way to upload it just on youtube ! sorry )
http://www.youtube.com/watch?v=jlT1woWM68M&feature=youtu.be
advices to improve the code
thanks !!!
_________________
NOway!!
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed May 23, 2012 7:12 am     Reply with quote

You've just learnt your first valuable lesson. Forget proteus, it's so full of bugs.

Lesson 2

Read the CCS forum guidelines.

Use the code box to show your code. As it stands it's almost impossible to decipher.

Have you got pull up resistors on your key inputs or are you relying on the port B internals?

Reduce your code to the minimum which demonstrates your problem.

I sounds like you MAY have button problems.

Try just reading the buttons and sending the button states to LEDs on other pins.

Give your buttons names which correspond with their functions, this will make your code more readable.

When you get stuck, post a complete compilable code which we can test.

Mike
ezflyr



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

View user's profile Send private message

PostPosted: Wed May 23, 2012 7:54 am     Reply with quote

Hi,

I could be wrong, but it looks like a switch bounce problem to me. I've had excellent luck with the 'Button' function written by forum user PCM programmer. This function is used to read and debounce switches. It's easy to implement, and it seems to work great. In fact, I use it in a menu system for a clock that uses a 128x64 GLCD.

Button Function: http://www.ccsinfo.com/forum/viewtopic.php?t=23837

John
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed May 23, 2012 10:33 am     Reply with quote

The display's responding without pressing any buttons.

So either :-

Spurious output from the buttons, possibly caused by bad connection, faulty buttons, electrostatic pick-up if they're floating.......

OR

Some other part of the software is sending data to the LCD.

At this stage it's a divide and conquer excercise.

Mike
ezflyr



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

View user's profile Send private message

PostPosted: Wed May 23, 2012 11:44 am     Reply with quote

Hi Mike,

I guess I missed the part where he said "I don't press anything and see changes", and must have seen a phantom hand in the video pressing buttons Embarassed

He may have his buttons wired incorrectly, or his logic messed up! Here is a line from his code:

Code:

if(input(pin_b1)==1) / RB1 : button "up"


"Normally", the pushbutton is wired so that when it's depressed (please, no funny comments!) it grounds (0V) the input it's connected to. The input also has a pullup resistor (10K works well) to Vcc. If his switch is wired like this, the above code is going to interpret a "non-pushed" button as "pushed"!

If so, change the line to this:

Code:

if(input(pin_b1)==0) / RB1 : button "up"


John
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed May 23, 2012 2:20 pm     Reply with quote

Hi John,

We need the answers to lots of questions.

Could be using pull down resistors, open circuit, we can't tell.

Coding seems to be working on high for button pressed, which could be the problem.

We're wasting time and effort trying to second guess.

Mike
exodia505



Joined: 07 Feb 2012
Posts: 34

View user's profile Send private message

PostPosted: Sun May 27, 2012 1:45 pm     Reply with quote

HI, Mike !
what are the questions that you want their answers?
_________________
NOway!!
temtronic



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

View user's profile Send private message

PostPosted: Sun May 27, 2012 2:48 pm     Reply with quote

First off, a fully documented schematic would be a good start......

Second, you could 'fudge' the keypad entries and see if the rest of the program functions the way it should..that would eliminate most of the potential issues with the keypad. Simply recode (add a function) to accept data from a PC terminal program instead of the keypad. Call this 'data-from-pc' function instead of the 'keypad' function.

Third, follow up with the results....

The more you tell us the better (and faster) the replies will be.
ezflyr



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

View user's profile Send private message

PostPosted: Sun May 27, 2012 7:37 pm     Reply with quote

exodia505 wrote:
HI, Mike !
what are the questions that you want their answers?


We can't help until you describe how you have wired your push buttons. You've got a button problem, so at a minimum, you need to tell us how they are connected. What is the input signal on the PIC pin when the button is not pressed? What is the input signal on the PIC pin when the button is pressed? How are you testing for this in your code?

John
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon May 28, 2012 2:07 pm     Reply with quote

Like I said before it's a divide and conquer exercise.

Without you touching the buttons, your display behaves as though you were.

So, split the problem into two sections; buttons & display.

Test each separately from the other.

Find out which works correctly, and which does not.


TESTING THE BUTTONS

I've already suggested replacing the GLCD with four LEDs.

Each LED corresponding to one button.

As you press each of your four buttons, its LED should light.


TESTING THE GLCD.

Temtronic has suggested replacing the buttons with an RS232 input from a PC.

As you press each key on your PC the GLCD should respond as intended.



You've given us no indication of your schematic.

Ezflyr has asked specifically for details of your button wiring.


Can we assume that each of your four buttons is connected like this?

Code:

 +5V ___WWWWW_____________ To PIC input
                   |
                   |
                 | |
                (|
                 | |
                   |
                   |
                 0V GND


The forum guidelines explain how to go about getting meaningful help.

Mike
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