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

Unable to display function in 16 x 2 LCD in second Line

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



Joined: 31 Mar 2011
Posts: 6

View user's profile Send private message

Unable to display function in 16 x 2 LCD in second Line
PostPosted: Thu Sep 10, 2015 12:20 am     Reply with quote

Hi , Everyone

I am using two push buttons to display two parameters at same time.
But I am unable to do so. I want to change my program each time I press the pushbutton1 in Line 1 and in Line 2 I want to change function F with each press of the other pushbutton2.

Please help me.
Code:

#include <16f876a.h>                     
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP     
#use delay (clock=4000000)         
#use standard_io(b)
#define use_portb_lcd TRUE         
#include<lcd.c>                 

/// Program Function
void program(char);   
void freq(char); 


///PROGRAM
void main(void)
{
   char option=0;       
   char option2=0;         
   
   setup_ccp1(CCP_PWM);   
   
   lcd_init();           
   
   program(option);   
   freq(option2);   
   
   for(;;){     
      if(!input(PIN_A0)){         
         do{                       
         }while(!input(PIN_A0));     
         option++;               
         if(option>9)           
            option=0;           
         program(option);     
         }
       if(!input(PIN_A1)){           
         do{                     
         }while(!input(PIN_A1));     
         option2++;               
         if(option2>4)           
            option2=0;           
         freq(option2);     
         } 
      }         
}


void program(char menu)
{
   lcd_putc("\f");   
   switch(menu){ 
      case 0:   
            lcd_gotoxy(1,1);
            printf(lcd_putc,"\fPROGRAM:   M.STI");
            break;
      case 1:   
            lcd_gotoxy(1,1);
            printf(lcd_putc,"\fPROGRAM:   I.LOS");           
            break;
      case 2:   
            lcd_gotoxy(1,1);
            printf(lcd_putc,"\fPROGRAM:   W.LOS");
            break;
      case 3:   
            lcd_gotoxy(1,1);
            printf(lcd_putc,"\fPROGRAM:   B.TON");         
           break;
      case 4:   
            lcd_gotoxy(1,1);
            printf(lcd_putc,"\fPROGRAM:   B.SCU");
         
            break;
      case 5:   
            lcd_gotoxy(1,1);
            printf(lcd_putc,"\fPROGRAM:   B.SHA");
           
            break;
      case 6:   
            lcd_gotoxy(1,1);
            printf(lcd_putc,"\fPROGRAM:   B.COR");
           
            break;
      case 7:   
            lcd_gotoxy(1,1);
            printf(lcd_putc,"\fPROGRAM:   B.FIR");           
            break;
      case 8:   
            lcd_gotoxy(1,1);
            printf(lcd_putc,"\fPROGRAM:   TUMMY");         
            break;
       case 9:   
            lcd_gotoxy(1,1);
            printf(lcd_putc,"\PROGRAM:   F.LIF");
           
               
      }
}

void freq(char menu)
{
   lcd_putc("\f");   
   switch(menu){   
      case 0:   
            lcd_gotoxy(1,2);
            printf(lcd_putc,"\nF : 1 ");
            break;
      case 1:   
            lcd_gotoxy(1,2);
            printf(lcd_putc,"\nF : 2 ");
            break;
      case 2:   
            lcd_gotoxy(1,2);
            printf(lcd_putc,"\nF : 3 ");
            break;
      case 3:   
            lcd_gotoxy(1,2);
            printf(lcd_putc,"\nF : 4 ");
            break;
      case 4:   
            lcd_gotoxy(1,2);
            printf(lcd_putc,"\nF : 5 ");
            break;     
   }
}
temtronic



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

View user's profile Send private message

PostPosted: Thu Sep 10, 2015 4:59 am     Reply with quote

Looks like the classic 'No debounce on the switches' problem.
Do a search for 'debounce' here and the code library for 20-30 solutions.
Also describe actual hardware( switch type, pullup, filter cap,etc.)

Jay
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Thu Sep 10, 2015 6:51 am     Reply with quote

IMHO, I think its the "\f".
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 10, 2015 10:00 am     Reply with quote

Quote:
void freq(char menu)
{
lcd_putc("\f");
switch(menu){
case 0:
lcd_gotoxy(1,2);
printf(lcd_putc,"\nF : 1 ");
break;

You go to the start of line 2 with the lcd_gotoxy(). Then you send a
newline in the printf. Where will the \n take you to ? You won't be on line 2.
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