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

keypad to lcd4x20

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



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

keypad to lcd4x20
PostPosted: Tue Jun 24, 2008 8:50 am     Reply with quote

Hi

I try write on LCD 4x20 key how I press on my keypad

I make this program:

Code:

void main ()
{
   int8 c;
   int i;

lcd_init();
kbd_init();
i=0;

while(TRUE)
   {
   c = kbd_getc();

      if(c=='*' && i==0)
         {
         lcd_gotoxy(0,3);
         lcd_putc(" Insert: ");
         i=1;
         }
      if(c=='#' && i==1)
         {
         lcd_putc('\f');
         lcd_gotoxy(0,3);
         lcd_putc(" OK");
         i=0;
         }
      if(i==1 && c!='*')
         {
         lcd_gotoxy(8,3);
         lcd_putc(c);
         }
   }
}


but now I have 2 problems:

1º- on LCD appear "insert:" and "OK" but dont appear key press.
2º- I need give one space before write like that" Insert:" and " OK" if I dont put space before 1º char appear in other line...

PS: when I put this program write on terminal all work fine.

this is file LCD4x20(I make some modifications on line positions):

Code:

void lcd_gotoxy( BYTE x, BYTE y) {
   BYTE address;
              //lcd_gotoxy(1,1); linha 1
             //lcd_gotoxy(1,4); linha 2
             //lcd_gotoxy(1,2); linha 3
             //lcd_gotoxy(1,3); linha 4
   if(Y==0)
     address=0;
   if(y==1)
     address=0x40;
   if(y==2)
      address=0x14;
   if(y==3)
      address=0x54;
   address+=x-1;
   lcd_send_byte(0,0x80|address);
}



some one can help me?

regards
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Tue Jun 24, 2008 1:55 pm     Reply with quote

Hi

I find on this forum a new libary drivers for LCD and I used them

http://www.ccsinfo.com/forum/viewtopic.php?t=28268&highlight=flexible

but problem continue....

I cant write the numbers Crying or Very sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 24, 2008 2:05 pm     Reply with quote

Quote:
lcd_gotoxy(0,3);


The CCS lcd driver, and the also the Flex driver, do not use "0-based"
coordinates. The lowest coordinate value is 1.

For example, the 4 lines in a 20x4 LCD are numbered as: 1, 2, 3, 4.

You need to fix your code. Get rid of all the "0" coordinates.
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Tue Jun 24, 2008 6:13 pm     Reply with quote

Hi, thanks PCM programmer

now this is solved Laughing but I have a new problem.

I like make some like that:

click on '*' and after press one number and click on '*' and program write on LCD the key how I have pressed.
Code:


void ast()
{
int8 c;

do
{
   c = kbd_getc();
   if(c!=0)
   lcd_gotoxy(1,1);
   lcd_putc(c);
}while(c!='*');

lcd_putc('\f');

}

void card()
{

}


void main ()
{
   int8 c;

lcd_init();
kbd_init();

while(TRUE)
   {

   c = kbd_getc();
   if(c!=0)
      if((c=='*') || (c=='#'))
         {
         if(c=='*')
         {
         lcd_gotoxy(1,4);
         lcd_putc(" key:");
         ast();
         }
         if(c=='#')
         {
         lcd_gotoxy(1,4);
         lcd_putc(" key:");
         card();
         }
         }
       
   }
}

with this program when I press '*' one time on LCD appear all white and when I press for 2nd time it clean LCD.

if some one can help me ...

best regards
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Jun 25, 2008 2:14 am     Reply with quote

You are proberbly missing {}

Code:

do
{
   c = kbd_getc();
   if(c!=0) {        // <------------
     lcd_gotoxy(1,1);
     lcd_putc(c);
  }                    // <------------
}while(c!='*');


Indentation makes the code easier to read!
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Wed Jun 25, 2008 10:12 am     Reply with quote

Hi

thanks, problem solved Cool

now I try join 2 programs, idea is on LCD appear:

1ºline: IN: OUT:
2ºline: Voltage:
3ºline: GPS SPEED:
4ºline: keypad input:

keypad program:

Quote:

void card()
{
int8 c, ctemp;

do
{
c = kbd_getc();
if ((c=='0') || (c=='1') || (c=='2') || (c=='3') || (c=='4') || (c=='5') || (c=='6') || (c=='7') || (c=='8') || (c=='9'))
ctemp=c;

if(c!=0) {
lcd_gotoxy(6,4);
lcd_putc(ctemp);
}
}while(c!='#');

lcd_gotoxy(1,4);
if (ctemp=='1') lcd_putc("PC_ON ");
if (ctemp=='2') lcd_putc("INVERSOR ");
if (ctemp=='3') lcd_putc("DIAGNOSTICO ");
if (ctemp=='4') lcd_putc("LEDs INTERIORES ");
if (ctemp=='5') lcd_putc("LEDs EXTERIORES ");
if (ctemp=='6') lcd_putc("TV TUNER ");
if (ctemp=='7') lcd_putc("SONDA LAMBD ");
if (ctemp=='8') lcd_putc("opcao 8 ");
if (ctemp=='9') lcd_putc("opcao 9 ");
if (ctemp=='0') lcd_putc("PC_OFF ");


}

void ast()
{
int8 c, ctemp;

do
{
c = kbd_getc();
if(c!=0)
{
lcd_gotoxy(1,4);
if (c=='1') lcd_putc("PC_ON ");
if (c=='2') lcd_putc("INVERSOR ");
if (c=='3') lcd_putc("DIAGNOSTICO ");
if (c=='4') lcd_putc("LEDs INTERIORES ");
if (c=='5') lcd_putc("LEDs EXTERIORES ");
if (c=='6') lcd_putc("TV TUNER ");
if (c=='7') lcd_putc("SONDA LAMBD ");
if (c=='8') lcd_putc("opcao 8 ");
if (c=='9') lcd_putc("opcao 9 ");
if (c=='0') lcd_putc("PC_OFF ");
}
}while(c!='*');

lcd_gotoxy(1,4);
lcd_putc(" ");

}


void main ()
{
int8 c;

lcd_init();
kbd_init();

while(TRUE)
{

c = kbd_getc();
if(c!=0)
if((c=='*') || (c=='#'))
{
if(c=='*')
{
lcd_gotoxy(1,4);
lcd_putc("Insert key: ");
ast();
}
if(c=='#')
{
lcd_gotoxy(1,4);
lcd_putc("code: ");
card();
}
}

}
}



Temperature and voltage program:

Quote:

void ALARME()
{
output_high(SIRENE);
delay_ms(20000);
}


void main()
{

int i;
long TEMP_IN,TEMP_OUT;
float VOLT;


setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);


output_low(LUZ_FUNDO);
output_low(SIRENE);
output_low(PC_SINAL);
output_low(TURNOFF);

lcd_init();

While(1)
{
TEMP_IN=0;
TEMP_OUT=0;
VOLT=0;



if (input(PC_SINAL)==1)
{
output_high(LUZ_FUNDO);
}

if (input(PC_SINAL)==0)
{
output_low(LUZ_FUNDO);
output_low(SIRENE);
}

/*****************Calculos das ADC's*********************/

set_adc_channel(0);
delay_us(10);
for(i=0; i<=100; ++i) TEMP_IN=TEMP_IN+Read_ADC();
TEMP_IN=(TEMP_IN/100);

set_adc_channel(1);
delay_us(10);
for(i=0; i<=100; ++i) TEMP_OUT=TEMP_OUT+Read_ADC();
TEMP_OUT=TEMP_OUT/100;

set_adc_channel(2);
delay_us(10);
for(i=0; i<=100; ++i) VOLT=VOLT+Read_ADC();
VOLT=VOLT/1000;


lcd_gotoxy(1,1);
lcd_putc("IN:");
lcd_gotoxy(10,1);
lcd_putc("OUT:");
lcd_gotoxy(3,1);
printf(lcd_putc("%2luC"),TEMP_IN);
lcd_gotoxy(14,1);
printf(lcd_putc("%2luC"),TEMP_OUT);

//printf(lcd_putc, ("\fIN:%2luC OUT:%2luC \r"),TEMP_IN,TEMP_OUT);

lcd_gotoxy(1,2);
printf(lcd_putc, ("Voltagem: %2.1gV \r"),VOLT);

lcd_gotoxy(1,3);
printf(lcd_putc, ("linha 3 "));

lcd_gotoxy(1,4);
printf(lcd_putc, ("linha 4 "));



delay_ms(1000);


/********************ALARME DE BAT FRACA*********************************/

if(VOLT==11.5)
{
delay_ms(5000);
if (VOLT==11.5) ALARME();

if (VOLT==11.0)
{
output_high(TURNOFF);
delay_ms(1500);
output_low(LUZ_FUNDO);
output_low(SIRENE);
}
}


}
}



in this program I have one problem, where I have

Quote:

lcd_gotoxy(1,1);
lcd_putc("IN:");
lcd_gotoxy(10,1);
lcd_putc("OUT:");
lcd_gotoxy(3,1);
printf(lcd_putc("%2luC"),TEMP_IN);
lcd_gotoxy(14,1);
printf(lcd_putc("%2luC"),TEMP_OUT);


it dont appear value of TEMP_IN an TEMP_OUT, I need make this "printf(lcd_putc, ("\fIN:%2luC OUT:%2luC \r"),TEMP_IN,TEMP_OUT);" for see real values. why?

with this code appear on LCD "IN:%2luC OUT:%2luC" Confused


after I try join this two program for when I press "*" or "#" run keypad part..

some one can help me?

regards
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Jun 25, 2008 1:29 pm     Reply with quote

Quote:
Code:
printf(lcd_putc("%2luC"),TEMP_IN);
lcd_gotoxy(14,1);
printf(lcd_putc("%2luC"),TEMP_OUT);


Dont you mean -

Code:
printf(lcd_putc, "%2luC", TEMP_IN);
lcd_gotoxy(14,1);
printf(lcd_putc, "%2luC", TEMP_OUT);
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Wed Jun 25, 2008 3:11 pm     Reply with quote

thanks for help SET this problem is solved...
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