|
|
View previous topic :: View next topic |
Author |
Message |
yasotha
Joined: 05 Mar 2012 Posts: 6
|
Need help on keypad and RFID door lock |
Posted: Mon Mar 05, 2012 1:27 am |
|
|
Hi, I'm currently doing my project on Keypad & RFID door lock. I tried to do coding testing for keypad and run in Proteus, but I couldn't get the desired output on lcd... here's my coding. Can anyone help me, did I miss anything?
Code: |
#include <18F4550.h> // PIC18F4550 HEADER FILE
#fuses XT,NOWDT,NOLVP,NOPROTECT // EXTERNAL CLOCK, NO WATCH DOG TIMER
#use delay (clock =4M) // 4 MHZ CRYSTAL
#include <flex_lcd.c> // LCD DISPLAY HEADER FILE
#include <Flex_KBD.c> // KEYPAD HEADER FILE
//FUNCTION PROTOTYPE
void keyboard(char);
//GLOBAL VARIABLE
unsigned char lcd_count=0;
unsigned char init;
char k;
void main()
{
lcd_init(); // INITIALIZE LCD
kbd_init(); // INITIALIZE KEYPAD
while(TRUE) // always repeat the program below
{
k=kbd_getc();
keyboard(k);
if(!input(PIN_C0)) // CLEAR SCREEN
{
lcd_putc("\f");
}
}
}
//-------------------------------------------------------------------------------
void Keyboard(char l)
{
if(l=='1') //value 1
{
if(init==0)lcd_putc("\f"); //if init is clear,clear the lcd
lcd_putc("1");
lcd_count+=1; //increase lcd_count by 1
init=1;
}
else if(l=='2') //value 2
{
if(init==0)lcd_putc("\f"); //if init is clear,clear the lcd
lcd_putc("2");
lcd_count+=1; //increase lcd_count by 1
init=1;
}
else if(l=='3') //value 3
{
if(init==0)lcd_putc("\f"); //if init is clear,clear the lcd
lcd_putc("3");
lcd_count+=1; //increase lcd_count by 1
init=1;
}
else if(l=='4') //value 4
{
if(init==0)lcd_putc("\f"); //if init is clear,clear the lcd
lcd_putc("4");
lcd_count+=1; //increase lcd_count by 1
init=1;
}
else if(l=='5') //value 5
{
if(init==0)lcd_putc("\f"); //if init is clear,clear the lcd
lcd_putc("5");
lcd_count+=1; //increase lcd_count by 1
init=1;
}
else if(l=='6') //value 6
{
if(init==0)lcd_putc("\f"); //if init is clear,clear the lcd
lcd_putc("6");
lcd_count+=1; //increase lcd_count by 1
init=1;
}
else if(l=='7') //value 7
{
if(init==0)lcd_putc("\f"); //if init is clear,clear the lcd
lcd_putc("7");
lcd_count+=1; //increase lcd_count by 1
init=1;
}
else if(l=='8') //value 8
{
if(init==0)lcd_putc("\f"); //if init is clear,clear the lcd
lcd_putc("8");
lcd_count+=1; //increase lcd_count by 1
init=1;
}
else if(l=='9') //value 9
{
if(init==0)lcd_putc("\f"); //if init is clear,clear the lcd
lcd_putc("9");
lcd_count+=1; //increase lcd_count by 1
init=1;
}
else if(l=='0') //value 0
{
if(init==0)lcd_putc("\f"); //if init is clear,clear the lcd
lcd_putc("0");
lcd_count+=1; //increase lcd_count by 1
init=1;
}
else if(l=='*') //value *
{
if(init==0)lcd_putc("\f"); //if init is clear,clear the lcd
lcd_putc("*");
lcd_count+=1; //increase lcd_count by 1
init=1;
}
else if(l=='#') //value #
{
if(init==0)lcd_putc("\f"); //if init is clear,clear the lcd
lcd_putc("#");
lcd_count+=1; //increase lcd_count by 1
init=1;
}
} |
|
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Mar 05, 2012 2:31 am |
|
|
Based on others experiences, I would not even bother to load Proteus on my machine - seems like they spend more time debugging it than the actual program.
As for your code, I think I would first suggest considering the "switch" statement instead of a whole pile of if .. else statements. See the section on "Statements" near the front of the compiler manual (well, at least in mine, it is on page 31).
mikey _________________ 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 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Mon Mar 05, 2012 6:11 am |
|
|
Biggest 'miss' is in believing that Proteus actually works !
You couldn't pay me to waste my time trying to use Proteus. It is FULL of bugs,errors, faulty DRCs, the list is endless.
Unless you want( and have the skills) to disassemble Proteus, locate and correct 100s of errors ,just delete it from your PC.It came off my PCs in less than an hour.
If this is a 'student' project and the teacher say you must Proteus, have him correct all the errors and bad DRCs, confirming his version works.
Honestly, if you want a WORKING simulator, cut your own simulator.
Better yet, get a real PIC,white breadboard and experiment in the real world.Get real hands on knowledge of how the PIC works. Yeesh, they only basically have 35 instructions, the compiler makes it easy to create high level code,NOTHING is 'hidden'. You have full access to both source and listings,just take the time to read,program,read more,try again. |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon Mar 05, 2012 10:14 am |
|
|
Hi,
This post is a great example of a type that is becoming increasingly prevalent here on the forum - essentially a "code dump" followed by a statement along the lines of "this code doesn't work, why not?"
Well, how are we supposed to know???
If you don't tell us what you expect, very few people are going to take the time to try to figure out the desired operation of your program.
If you don't tell us what you observe, very few people are going to take the time to try to figure out the actual operation of your program.
Please do everyone a favor, yourself included, and at least provide us with this very basic, minimum information!
John |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Mon Mar 05, 2012 12:29 pm |
|
|
Ok, I'll give him one 'freebie'...
NEVER EVER use a single lower case letter l as a variable.
Old guys like me can't see whether you typed in an l or an I or a 1 or a | !!!
You're allowed 255 characters for a variable name, please, use at least 2,preferably more to 'self-describe' what it is, or what it's used for .
Make it easier for everyone. |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Mar 05, 2012 3:15 pm |
|
|
temtronic wrote: | Ok, I'll give him one 'freebie'...
NEVER EVER use a single lower case letter l as a variable.
Old guys like me can't see whether you typed in an l or an I or a 1 or a | !!!
You're allowed 255 characters for a variable name, please, use at least 2,preferably more to 'self-describe' what it is, or what it's used for .
Make it easier for everyone. |
While generally true, that is why I prefer to use the Verdana font - I used to maintain a large database at work and was forever running into that problem with text etc being entered in text fields by folks. When I forced all text boxes to use Verdana, life got much better (still not perfect, but at least you can tell lower case el from 1 from capital I :-)
While not everybody agrees, there are a number of "coding standards" out there that discuss variable naming conventions etc. Life is much easier if you grab one and use it. One book that has some good information is "Code Complete". The easier it is to read and understand the code (both by you and someone else), the more likely they/you are to be able to solve problems
mikey
mikey _________________ 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 |
|
|
|
|
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
|