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 support@ccsinfo.com

keypad !!!

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



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

keypad !!!
PostPosted: Sun Feb 16, 2014 11:50 pm     Reply with quote

Hi, I'm using PIC18F4520, 4Mhz clock, Compiler: CCS 4.114.

Below is the code i used for keypad. Everything is working good. I want to compare the password and display a message. But it's not working.
Code:
#include "18F4520.h"
#fuses XT
#use delay(clock = 4000000)

#include "flex_lcd.c"
#include "flex_kbd.c"
#include "kbd_buffer.c"

#define MAX_PASSWORD_SIZE  8

//==================================
void main()
{
   int8 password_array[MAX_PASSWORD_SIZE +1];
   char msg[];
   
   lcd_init();
   kbd_init();   
   kbd_buffer_init();
   
   while(1)
   {
      lcd_putc("\fEnter Password:\n");
      
      // Get the password from keypad input by the user.  The password
      // can be from 1 to 8 digits.
      // The user must press '#' key to exit the password entry screen.
      // The user can press '*' key to backspace over chars.
      kbd_get_string(password_array, MAX_PASSWORD_SIZE);
      
      // Display the password that we just got.
      lcd_putc("\fPassword is:\n");
      sprintf(msg, "%s", password_array);
      printf(lcd_putc, "%s", password_array);
      
      delay_ms(3000);
      
      if(msg == 12345678)
      {
         lcd_putc ("\fcorrect Password\n");
         delay_ms(3000);
      }
   }
}

Please help. thanks in advance
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Mon Feb 17, 2014 12:41 am     Reply with quote

What isn't working? Does it display anything? How about giving us a clue as to what isn't working ????
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Mon Feb 17, 2014 1:28 am     Reply with quote

See this thread about LCD init delay and using lcd_putc

http://www.ccsinfo.com/forum/viewtopic.php?t=51742

You are using printf only on your 3rd output to the LCD

Regards
benoitstjean



Joined: 30 Oct 2007
Posts: 553
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Mon Feb 17, 2014 1:43 pm     Reply with quote

There are numerous problems here:

1) msg is a char string and you're directly trying to check if it's equal to a super long value 12345678... int8 is 8-bits (one byte). 12345678 is 3 bytes long...

You should do like:
Code:
if( strcmp( msg, "12345678" ) == 0 )
{
 password is ok
}

But that still won't work because you have type issues and such.

2) your password_array is a int8 structure... that you're later trying to compare to a character string (no.1 above)...

I also suggest you use unsigned int and unsigned char as opposed to simple int and char as you may end-up with values from -127 to 127 instead of 0-255.

You should perhaps consider comparing characters one by one in a for loop.

I don't have the time at the moment to write something-up for you but you need to fix these issues first...

Just out of curiosity, do you know C programming at all or is this a little project trying to learn PIC development and C at the same time?

Benoit
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