Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Changing the displayed message on an LCD

Status
Not open for further replies.

hawk1943

Member level 3
Joined
Jun 14, 2010
Messages
62
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
United Kingdom
Activity points
1,859
Hi there,

I'm getting myself confused here...

Basically i'm trying to detect multiple pushes from a Push Button, as I wish to use it to change the message displayed on an LCD...

But I am finding that either the push buttons are not that sensitive or I am not reading them correctly...

Basically I am trying to turn on & off an LED on a 16F877 to make sure the code works before I attempt to use it for the LCD...

But I cannot work out how to do it...

Code:
int Debounce_SW1(void) 
{
	if (SW1 == 0)		// test for keypress
		DelayMs(5); 	// wait for switch to stop bouncing

	if (SW1 == 0)		// if button still held down
		RB5 = TRUE;	// Turn on LED
}

But do I now need to test to see if the button has returned to the 5v rail so is therefore "Hi" before I can re-press the push button?

Only I just cannot fathom out how to do it...

At the moment this is how I am doing it...

Code:
int Debounce_SW1(void) 
{
	if (SW1 == 0)		// test for keypress
		DelayMs(5); 	// wait for switch to stop bouncing

	if (SW1 == 0)		// if button still held down
		RB5 = TRUE;		// Turn on LED
}

int Debounce_SW2 (void) 
{
	if (SW2 == 0)		// test for keypress
		DelayMs(5); 	// wait for switch to stop bouncing

	if (SW2 == 0)		// if button still held down
		RB5 = FALSE;	// Turn LED off
}

As you can see one push-button turns the LED on, the other turns it off

All I wish to do is initially toggle the LED on & off from a single Push Button...

At the moment the push button has a 10K pull up resistor on it, pulling it "Hi" so that when I push a button the input is pulled low...

Added after 43 minutes:

Ok... I've resolved the push button problem

Code:
 while(1)
 {
    if (SW1 == 0) // test the switch twice to eliminate *short* glitches
       if(SW1 == 0)   
       {
          shadowB^=1<<5; PORTB=shadowB; // Toggle RB5 cleanly
          DelayMs(50); // 1/20 s  key down debounce time
          while(SW1 == 0); // Wait for  key up 
          DelayMs(50); // 1/20 s  key up debounce time
}

How can I use this to move on the LCD display?
 

Do u want to move the message displayed on LCD by 1 step...each time u press the switch?....

U can do this by passing shift display command each time the switch i pressed...It is a type of command like function set...

Regards.
Sidy.
 

Basically...

At the moment I just wish to display the correct characters as the code is not working at the moment it's displaying the data on different lines...

All that I am aiming to do is be able to scroll through the Keypad a page at a time with a single push of the push button...

At the moment the push button is incrementing the LCD by one each time I push the push button and after 8 pushes is displaying 12345678 onto the LCD evertime but it does not over flow onto the next line but jumps to the next one missing a line out completely...

So I know that I have not got the LCD talking just yet...

But if I can just re-fresh the display and display Page 1 (push of push button) Page 2 etc I would be more than happy...

But at the moment the initial screen is being moved on too quickly and I am unable to slow it down... i've used 2 second delays and the whole display froze on me etc...

I've attached the actual code, so that perhaps someone might be able to see what I am doing wrong...
 

Hi...i had a display routine that was used to set the cursor position to the desired position...it was like this cursorxy(x,y)...where x can be 1 or 2...& y can be 1 to 16...for a 16x2 display...so for setting the cursor postion to line 2 row 1...u have to send cursorxy(2,1)...Now this can be implemented in ur design...as many time u press the push button, for the same times u can cause x to increment...so pressing the button 2 times will cause the Cursor to move down 2 lines...I hope u get what im saying...but ull have to try transfering the code in assembly...as it in C...Tell me if u r intrested...Regards.
 

two things:

1) make sure that your display routines work correctly: for example, is the lcd initialized correctly? is it in the right mode? can your lcd routines display all lines (4?)?, etc.

2) then you want make sure that you are reading the button correctly (with or without debouncing).

without being sure of both, you would be simply wasting your time trying to debug it.
 

Since there is no problem with "Msg not getting displayed".
The problem is where it should get displayed each time switch is pressed...
The LCD library which i have contains one function named cursorxy(x,y)...where x(Rows) can be 1 or 2 & y(columns) can be 1 to 16...
So if i call funcation as cursorxy(2,1) & the display message...The message will be displayed on 2 row 1st column onwards..
This can be implemented in ur design also...U just need to maintain a count of the switch press and pass it as x...Fe.g if switch is pressed 2 times the display will then shift 2 rows down...Hope u understand what im saying...But need to convert the function in Assembly...If intrested do tell me...

Regards...
 

Ok... I've resolved the push button problem

I use something different:

Code:
if (key is pressed) {
  delay some time;
  if (key is still pressed) return (key is pressed);
  else return (key is not pressed);
}

based on the returned value, your code can do different things.

its biggest downside is that it ties down the processor during the delay time.
 

Thanks for that...

I'd love to use assembly language but it's been almost 10 years since I last used it, and i'm struggling to get back into C after a 5 year break...

Never expected to ever do any design or programming work again... but found I needed to as I cannot afford to purchase the actual product...

The inital design ran out of code space so I'm trying to import everything form a 16F636 to a 16F877 and whilst doing it add an LCD and proper uart instead of Bit Banged Serial...

The original post can be found here...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top