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

menu and functions

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



Joined: 20 Apr 2007
Posts: 111

View user's profile Send private message Send e-mail

menu and functions
PostPosted: Tue Mar 31, 2009 6:32 am     Reply with quote

I have tried to do a menu with an lcd on this way:

When program goes to while loop (main program) this call the function menu and after read a key from a keyboard(4x3) go out from menu function and return to while loop (main program)


The problem it is not reading a key from keyboard..

The code I am trying do do is:
Code:

#include <16F877.h>
#use delay(clock=4000000)
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP,NOBROWNOUT
#include <ds1307.c>
#include <flex_lcd420.c>
#include <flex_kbd.c>

char menu(byte sec,int antigo,int status,char k){

kbd_init();
port_b_pullups(TRUE);

sec=read_ds1307(0);
delay_ms(100);
if (antigo != sec){
lcd_gotoxy(1,1);
printf(lcd_putc,"%2X",sec);
delay_ms(100);
lcd_gotoxy(1,2);
printf(lcd_putc,("1 - A"));
lcd_gotoxy(1,3);
printf(lcd_putc,("2 - B"));
delay_ms(100);
lcd_gotoxy(1,4);
printf(lcd_putc,("3 - C"));
antigo = sec;
}

while (true){
k = kbd_getc();
}

return (k);
}


void main() {
char k,sair;
byte hora,min,sec,dia,mes,ano;
int status = 1;
byte antigo = 0;
kbd_init();
port_b_pullups(TRUE);
lcd_init();
delay_ms(200);
init_ds1307();
sec=write_ds1307(0,0x00);


while (1)
{
menu(sec,antigo,status,k);


printf(lcd_putc,"ESCOLHEU OPCAO : %c",k); // to check if it is returning k
}
}

tks

nina
andyfraser



Joined: 04 May 2004
Posts: 47
Location: UK

View user's profile Send private message

menu and functions
PostPosted: Tue Mar 31, 2009 6:46 am     Reply with quote

Hi,

How do you expect menu to return when you have the following :
Code:
while (true)
 {
    k = kbd_getc();
 }

Also, why do you call kbd_init and port_b_pullups each time you call menu ?

Andy
nina



Joined: 20 Apr 2007
Posts: 111

View user's profile Send private message Send e-mail

lcd menu
PostPosted: Tue Mar 31, 2009 8:39 am     Reply with quote

Thank you for your answer...It was a mistake call kbd_init and port_b_pullups ..

But how can I solve the problem to read the key inside the function menu??

tks again

nina
andyfraser



Joined: 04 May 2004
Posts: 47
Location: UK

View user's profile Send private message

lcd menu
PostPosted: Tue Mar 31, 2009 1:10 pm     Reply with quote

Hi,

Well you could do something like :

Code:

k = 0;
while ( ( k < '1' ) || ( k > '3' ) )
{
  k = kbd_getc();
}


Andy
nina



Joined: 20 Apr 2007
Posts: 111

View user's profile Send private message Send e-mail

menu
PostPosted: Wed Apr 01, 2009 4:23 am     Reply with quote

I have tried this but it is not return the value x.
What I want to do is return value x from de menu function to while loop inside the main function..

the code is

#include <16F877.h>
#use delay(clock=4000000)
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP,NOBROWNOUT
#include <ds1307.c>
#include <flex_lcd420.c>
#include <flex_kbd.c>

char menu(){

char x;
lcd_gotoxy(1,2);
printf(lcd_putc,("1 - A"));
lcd_gotoxy(1,3);
printf(lcd_putc,("2 - B"));
delay_ms(100);
lcd_gotoxy(1,4);
printf(lcd_putc,("3 - C"));

while (true){
x = kbd_getc();
if (x=='1'){
break;
}
continue;
}
return (x);
}

void main() {
char x;
kbd_init();
port_b_pullups(TRUE);
lcd_init();
delay_ms(200);

while (1)
{

menu();
printf(lcd_putc,"choice %c", x);
}
}
andyfraser



Joined: 04 May 2004
Posts: 47
Location: UK

View user's profile Send private message

Menu
PostPosted: Wed Apr 01, 2009 6:54 am     Reply with quote

First, please use the Code button when posting this much code.

Second, you need to assign x to the return value of Menu().

i.e.
x = menu();
printf(....

Andy
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