Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
cloner
PostPosted: Jul 11, 2012 - 03:44 PM
Newbie


Joined: Jul 11, 2012
Posts: 9
Location: INDIA

want to know the pbobs in the code

Code:
// Using DTMF(Dual Tone Multiple Frequency) to check the password and
  //  then using the LEDs to indicate the no's entered.

#include<avr/io.h>
#include<util/delay.h>
#include"lcd.h"
#include"lcd.c"
void main()
{
   int i;
   DDRD=0xFF;
   DDRC=0x00;
   lcd_init(LCD_DISP_ON);
   while(1)
   {   
      label_one;
      lcd_puts("Enter Password");
      
   // for checking the entered password.

      while((PINC&15)!=5)
      {
         lcd_clrscr():
         lcd_puts("Wrong password");
      }
      lcd_puts("5");
      
      while((PINC&15)!=4)
      {
         lcd_clrscr();
         lcd_puts("wrong");
         goto label_one;
      }
      lcd_puts("4");
      
      while((PINC&15)!=3)
      {
         lcd_clrscr();
         lcd_puts("wrong");
         goto label_one;
      }
      lcd_puts("3");
      
      lcd_clrscr();
      lcd_puts("Correct Password");
      
   // for glowing the LEDs after pressing the no in mobile
      
      
      for(i=0;i<13;i++)
      {
         while((PINC&15)==i)
         {   
            PORTD=i;
            _delay_ms(250);
         }
      }
   }
}
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jul 11, 2012 - 04:01 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62230
Location: (using avr-gcc in) Finchingfield, Essex, England

What is connected to the bottom 4 bits of PORTC? It looks like it must be a keypad that actually returns a BCD code or something?

Anyway I suggest you research the topic "finite state machine" which would be a better way to implement this.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: Jul 11, 2012 - 04:09 PM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16271
Location: Wormshill, England

Shirley, you read the inputted string / DTMF tones and compare it with the password. Then pass or fail

You don't tell the user what the password should be.

You probably only maintain the last 3 digits received. e.g. char digits[3];
As a new digit arrives, you shift the existing ones to make room. Then compare with memcmp(digits, password, 3).

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
cloner
PostPosted: Jul 11, 2012 - 04:40 PM
Newbie


Joined: Jul 11, 2012
Posts: 9
Location: INDIA

clawson wrote:
What is connected to the bottom 4 bits of PORTC? It looks like it must be a keypad that actually returns a BCD code or something?

Anyway I suggest you research the topic "finite state machine" which would be a better way to implement this.


yes, the bottom 4 bits of PORTC are conneced to the output of DTMF circuit
 
 View user's profile Send private message  
Reply with quote Back to top
cloner
PostPosted: Jul 11, 2012 - 04:44 PM
Newbie


Joined: Jul 11, 2012
Posts: 9
Location: INDIA

david.prentice wrote:
Shirley, you read the inputted string / DTMF tones and compare it with the password. Then pass or fail

You don't tell the user what the password should be.

You probably only maintain the last 3 digits received. e.g. char digits[3];
As a new digit arrives, you shift the existing ones to make room. Then compare with memcmp(digits, password, 3).

David.



I only want to check the the password here which is 432.If the password is correct then only the no's entered by the caller are obtained on the LEDs.This is the aim and I am not getting what u want to tell.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jul 11, 2012 - 04:46 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62230
Location: (using avr-gcc in) Finchingfield, Essex, England

As it stands if I start pressing 0/1/2/3.. then when I press 5 the display switches from "Wrong password" to "wrong" so I am left in no doubt that the first digit is 5. Not a great idea.

BTW are you sure the device really outputs BCD on 4 pins?

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: Jul 11, 2012 - 05:27 PM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16271
Location: Wormshill, England

Yes, DTMF chips will output the BCD on 4 pins.

No, I can't see that the code is going to be difficult to crack.

You could possibly set off alarms, fire guns, drop nets, ... when the burglar enters a wrong number.

The normal procedure in films is scary music with loud heartbeats.

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
cloner
PostPosted: Jul 12, 2012 - 04:03 AM
Newbie


Joined: Jul 11, 2012
Posts: 9
Location: INDIA

clawson wrote:
As it stands if I start pressing 0/1/2/3.. then when I press 5 the display switches from "Wrong password" to "wrong" so I am left in no doubt that the first digit is 5. Not a great idea.

BTW are you sure the device really outputs BCD on 4 pins?


So can you tell what should i do instead of that??
 
 View user's profile Send private message  
Reply with quote Back to top
Visovian
PostPosted: Jul 12, 2012 - 05:58 AM
Posting Freak


Joined: Aug 07, 2007
Posts: 1470
Location: Czech

First: In dtmf receiver there is a pin which indicates that the next number is on the output.
You have to watch it.
It is named NUM_CHANGED and supposed active high in the code. After a delay this bit goes back to LOW.

The code is not tested.
Code:
#define NUM_CHANGED 5  // pinc.5
char password[10];
uint8_t i;

int main(void)
{
   while(1)
   {
      lcd_puts("Enter Password");
     
   // for checking the entered password.

      for (i=0; i<4; i++)
      {
         loop_until_bit_is_set(PINC,NUM_CHANGED);
         password[i] = (PINC & 15) + '0'; // save as ascii
         loop_until_bit_is_clear(PINC,NUM_CHANGED);
      }   
      password[i+1] = 0; // terminate string

      if (strcmp(password, "5432") == 0)
         lcd_puts("Correct Password");
      else
         lcd_puts("Wrong Password");
   }
}
 
 View user's profile Send private message  
Reply with quote Back to top
sternst
PostPosted: Jul 12, 2012 - 06:41 AM
Raving lunatic


Joined: Jul 23, 2001
Posts: 2437
Location: Osnabrueck, Germany

Code:
password[i+1] = 0; // terminate string
->
Code:
password[i] = 0; // terminate string

_________________
Stefan Ernst
 
 View user's profile Send private message  
Reply with quote Back to top
Visovian
PostPosted: Jul 12, 2012 - 06:54 AM
Posting Freak


Joined: Aug 07, 2007
Posts: 1470
Location: Czech

sternst:
For an unknown reason I had an illusion that i=3 after the for loop.
Thanks.
 
 View user's profile Send private message  
Reply with quote Back to top
cloner
PostPosted: Jul 12, 2012 - 11:41 AM
Newbie


Joined: Jul 11, 2012
Posts: 9
Location: INDIA

Thank you all for your efforts.
But i have simply a dtmf ckt containing the dtmf decoder IC, so i just want to check that the entered password is 432 otherwise it would show "wrong password" and if the password is correct then i want to knowthe digits entered by the caller using led.
As i m new to avr so want your help in determining the faults or the cons in the code that i have written above.
Thnks
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jul 12, 2012 - 12:06 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62230
Location: (using avr-gcc in) Finchingfield, Essex, England

You appear to have rushed into implementation without stopping to consider the design first. You really need a clear picture of how you want this to operate before attempting to write the code.

Visovian has told you that the DTMF chip also has an output to say "new digit typed" (his NUM_CHANGED) so that is going to be key to your design (rather than just sitting in while loops repeatedly rereading the last digit typed). It's also been pointed out that you probably want to buffer the digits as they are typed. The user may well know the password is 432 but suppose they start typing 433 then realise they have made an error - then what? There is no concept of a "go back" key so if the password really is going to be 3 digits long then you need to keep a copy of the last 3 digits typed. The user who typed 433 can now just go on and type 432 and as they do that the 3 digits held will be 433 then 434 then 343 then 432 and they are in. But something else you may also want to consider is exactly how many attempts are you going to give them? If you don't limit it they could just type 000001002003004..998999 and at some point they would break in. So you might want to give them the chance to type maybe 6 or 8 digits and then, if they haven't got the PIN number in that (which is enough digits to correct an error), then you maybe wait for N seconds before allowing them to type again (for this you would need some kind of user feedback like a red LED or something to say "you are locked out and I'm not listening" - maybe an LCD message?)

Only once you have followed this kind of process (and there's probably other design considerations I haven't thought of above yet) can you then say: "This is how it's got to work". Then you are in a position to start writing some C code to actually implement the design you have come up with. Of course the implementation may have bugs and there may be one or two things you still haven't thought of that only come to light when you start to use what you implement but you then think about (that's very important!) then fix/change those things.

So a few things you need are a loop that doesn't even do anything else but wait until the chip has told you that another digit has been typed. A "rolling" buffer that holds the last 3 or 4 digits typed. Possibly a "lock out" to prevent multiple attempts in a short space of time. A conversion of the binary digits into ASCII for display on the user interface.

Visovian has shown you the basis of something that already has some of these elements but think out the big picture of how everything will work first, then put all the pieces together.

Your code that just sits in while() loops waiting for digits to change is not great. Suppose you actually want to set the PIN to be 339 - how would that work in your current scheme if you don't use the NUM_CHANGED mechanism?

EDIT: terrible typos!

_________________


Last edited by clawson on Jul 12, 2012 - 01:03 PM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
awneil
PostPosted: Jul 12, 2012 - 12:58 PM
Resident


Joined: Jul 02, 2005
Posts: 534
Location: Basingstoke, Hampshire, UK

clawson wrote:
You really need a clear picture of how you want this to operate before attempting to write the code.

Absolutely Exclamation

This is fundamental to any form of software development - no just the AVR.
(actaully, applies to any form of development work - not just software)

A State Machine (aka Finite State Machine, FSM) has already been suggested as an appropriate approach.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
cloner
PostPosted: Jul 13, 2012 - 01:19 PM
Newbie


Joined: Jul 11, 2012
Posts: 9
Location: INDIA

Thnx
i would try to implement all the suggestions.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits