thannara123
Advanced Member level 5
- Joined
- Jan 7, 2010
- Messages
- 1,602
- Helped
- 122
- Reputation
- 244
- Reaction score
- 116
- Trophy points
- 1,353
- Activity points
- 10,625
while(1){
[COLOR=#ff0000] LCD_clear;
password= InputNumber("Enter Password");//Get the keycode of pressed key
if(password==ReadPassFromEEPROM())
{
LCD_clear;
string(" Unlocked");
_delay_ms(100);
while(1) {
f=GetKeyPressed();
while(GetKeyPressed()==255)
{
_delay_loop_2(10);
}
if (f==2){ [/COLOR]
password==InputNumber("old"); // not getting values
_delay_ms(300);
if (password==ReadPassFromEEPROM())
{
newpassword=InputNumber("new");
string("just testing");
WritePassToEEPROM(newpassword);
_delay_ms(300);
}
}
}
}
uint16_t InputNumber(char *msg)
{
uint8_t keyCode;
int x=0;
int pos=0;
uint8_t prev_key=0xFF;
uint8_t k=0xc1;
uint8_t system_reset = 0;
int key[4];
dis_cmd(0x81);
while(*msg) dis_data(*msg++);
LINE2;
while(!system_reset)
{
keyCode=GetKeyPressed(); //Get the keycode of pressed key
if(pos==4|keyCode==2)
{
pos==0;
return(((1000*key[0])+(100*key[1])+(10*key[2])+key[3])); //save the password in 16 bit integer
break;
}
if(keyCode==prev_key)
continue;
else if(keyCode==0xFF)
{
prev_key=0xFF;
continue;
}
else
{
prev_key=keyCode;
}
switch (keyCode) //generating key characeter to display on LCD
{
case (11):
string("1");
dis_cmd(k++);
key[x]=1;
x++;
pos++;
break;
case (10):
//dis_cmd(k++);
string("2");
dis_cmd(k++);
key[x]=2;
x++;
pos++;
break;
case (9):
string("3");
dis_cmd(k++);
key[x]=3;
x++;
pos++;
break;
case (8):
string("4");
dis_cmd(k++);
key[x]=4;
x++;
pos++;
break;
case (7):
//dis_cmd(k++);
string("5");
dis_cmd(k++);
key[x]=5;
x++;
pos++;
break;
case (6):
string("6");
dis_cmd(k++);
key[x]=6;
x++;
pos++;
break;
case (5):
string("7");
dis_cmd(k++);
key[x]=7;
x++;
pos++;
break;
case (4):
string("8");
dis_cmd(k++);
key[x]=8;
x++;
pos++;
break;
case (3):
string("9");
dis_cmd(k++);
key[x]=9;
x++;
pos++;
break;
case (2):
//string("*");
//dis_cmd(k++);
key[x]=0;
x++;
pos++;
break;
case (1):
string("0");
dis_cmd(k++);
key[x]=0;
x++;
pos++;
break;
case (12):
system_reset=1;
break;
//default: ;
}
_delay_loop_2(300);
}
}
if(pos==4|keyCode==2)
if(pos==4|| keyCode==2)
case (11):
string("1");
key[x]=1;
dis_cmd(x++);
break;
if(x==4|| keyCode==2)
[COLOR=#FF0000] Main .c[/COLOR]
#include<avr/io.h>
#include<avr/eeprom.h>
#include<util/delay.h>
#include<inttypes.h>
#include "eeprom.h"
#include "lcd.h"
//#include "keypad.h"
#include "user_interface.h"
int main(void)
{
DDRB=0xFF;
lcd_init();
uint16_t password;
uint8_t f;
uint16_t newpassword;
if(ReadPassFromEEPROM()==25755)
{
//Password is blank so store a default password
WritePassToEEPROM(5050);
_delay_ms(400);
}
LCD_clear;
LINE1;
dis_cmd(0x84);
string("Drive");
_delay_ms(200);
while(1){
LCD_clear;
password= InputNumber("Enter Password");//Get the keycode of pressed key
if(password==ReadPassFromEEPROM())
{
LCD_clear;
string(" Unlocked");
_delay_ms(100);
while(1) {
f=GetKeyPressed();
while(GetKeyPressed()==255)
{
_delay_loop_2(10);
}
if (f==2){
password=InputNumber("Old Password");
_delay_ms(1000);
if (password==ReadPassFromEEPROM())
{
newpassword=InputNumber("new");
string("okok");
WritePassToEEPROM(newpassword);
_delay_ms(300);
}
}
}
}
else
{
LCD_clear;
string("Wrong Password");
_delay_ms(1000);
}
}
}
[COLOR=#FF0000] interfacing /decoding section file .c[/COLOR]
#include <avr/io.h>
#include <inttypes.h>
#include<util/delay.h>
#include "keypad.h"
#include "user_interface.h"
#include "lcd.h"
uint16_t InputNumber(char *msg)
{
uint8_t keyCode;
uint8_t x=0;
uint8_t pos=0;
uint8_t prev_key=0xFF;
uint8_t k=0xc1;
int key[4];
uint8_t h=0;
dis_cmd(0x81);
while(*msg) dis_data(*msg++);
LINE2;
while(1)
{
if(h==4)
{ pos=0;
x=0;
return(((1000*key[0])+(100*key[1])+(10*key[2])+key[3])); //save the password in 16 bit integer
}
keyCode=GetKeyPressed();//Get the keycode of pressed key
if(keyCode==prev_key)
continue;
else if(keyCode==0xFF)
{
prev_key=0xFF;
continue;
}
else
{
prev_key=keyCode;
}
h++;
switch (keyCode) //generating key characeter to display on LCD
{
case (11):
string("1");
dis_cmd(k++);
key[x]=1;
x++;
pos++;
break;
case (10):
//dis_cmd(k++);
string("2");
dis_cmd(k++);
key[x]=2;
x++;
pos++;
break;
case (9):
string("3");
dis_cmd(k++);
key[x]=3;
x++;
pos++;
break;
case (8):
string("4");
dis_cmd(k++);
key[x]=4;
x++;
pos++;
break;
case (7):
//dis_cmd(k++);
string("5");
dis_cmd(k++);
key[x]=5;
x++;
pos++;
break;
case (6):
string("6");
dis_cmd(k++);
key[x]=6;
x++;
pos++;
break;
case (5):
string("7");
dis_cmd(k++);
key[x]=7;
x++;
pos++;
break;
case (4):
string("8");
dis_cmd(k++);
key[x]=8;
x++;
pos++;
break;
case (3):
string("9");
dis_cmd(k++);
key[x]=9;
x++;
pos++;
break;
case (2):
//string("*");
//dis_cmd(k++);
key[x]=0;
x++;
pos++;
break;
case (1):
string("0");
dis_cmd(k++);
key[x]=0;
x++;
pos++;
break;
case (12):
break;
//default: ;
}
_delay_loop_2(300);
}
pos=0;
x=0;
}
/*
* keypad.h
*
* Created: 12/19/2012 10:49:06 PM
* Author: Gelectorn
*/
#ifndef KEYPAD_H_
#define KEYPAD_H_
#define KEYPAD_PORT PORTD
#define KEYPAD_DDR DDRD
#define KEYPAD_PIN PIND
uint8_t GetKeyPressed()
{
uint8_t r,c;
KEYPAD_PORT|= 0X0F;
for(c=0;c<3;c++)
{
KEYPAD_DDR&=~(0X7F);
KEYPAD_DDR|=(0X40>>c);
for(r=0;r<4;r++)
{
if(!(KEYPAD_PIN & (0X08>>r)))
{
return (r*3+c);
}
}
}
return 0XFF;//Indicate No key pressed
}
#endif /* KEYPAD_H_ */
if(h==4)
{ pos=0;
x=0;
k=0;
h=0;
return(((1000*key[0])+(100*key[1])+(10*key[2])+key[3])); //save the password in 16 bit integer
}
if(pos==4|| keyCode==2)
main file
#include<avr/io.h>
#include<avr/eeprom.h>
#include<util/delay.h>
#include<inttypes.h>
#include "eeprom.h"
#include "lcd.h"
#include "user_interface.h"
int main(void)
{
DDRB=0xFF;
lcd_init();
uint16_t password;
uint8_t f;
uint16_t newpassword;
if(ReadPassFromEEPROM()==25755)
{
//Password is blank so store a default password
WritePassToEEPROM(5050);
_delay_ms(400);
}
LCD_clear;
LINE1;
dis_cmd(0x84);
string("Drive");
_delay_ms(200);
while(1){
LCD_clear;
password= InputNumber("Enter Password");//Get the keycode of pressed key
if(password==ReadPassFromEEPROM())
{
LCD_clear;
string(" Unlocked");
_delay_ms(100);
while(1) {
f=GetKeyPressed();
while(GetKeyPressed()==255)
{
_delay_loop_2(10);
}
if (f==2){
password=InputNumber("Old Password");
_delay_ms(1000);
if (password==ReadPassFromEEPROM())
{
newpassword=InputNumber("new");
string("okok");
WritePassToEEPROM(newpassword);
_delay_ms(300);
}
}
}
}
else
{
LCD_clear;
string("Wrong Password");
_delay_ms(1000);
}
}
}
interface/keypad convertor
#include <avr/io.h>
#include <inttypes.h>
#include<util/delay.h>
#include "keypad.h"
#include "user_interface.h"
#include "lcd.h"
uint16_t InputNumber(char *msg)
{
uint8_t keyCode;
uint8_t x=0;
uint8_t pos=0;
uint8_t prev_key=0xFF;
uint8_t k=0xc1;
int key[4];
uint8_t h=0,l=0;
dis_cmd(0x81);
while(*msg) dis_data(*msg++);
LINE2;
while(1)
{
if(h==4)
{ pos=0;
x=0;
keyCode=0;
k=0x80;
_delay_ms(100);
return(((1000*key[0])+(100*key[1])+(10*key[2])+key[3])); //save the password in 16 bit integer
h=0;
break;
}
keyCode=GetKeyPressed();//Get the keycode of pressed key
if(keyCode==prev_key)
continue;
else if(keyCode==0xFF)
{
prev_key=0xFF;
continue;
}
else
{
prev_key=keyCode;
}
h++;
switch (keyCode) //generating key characeter to display on LCD
{
case (11):
string("1");
dis_cmd(k++);
key[x]=1;
x++;
pos++;
break;
case (10):
//dis_cmd(k++);
string("2");
dis_cmd(k++);
key[x]=2;
x++;
pos++;
break;
case (9):
string("3");
dis_cmd(k++);
key[x]=3;
x++;
pos++;
break;
case (8):
string("4");
dis_cmd(k++);
key[x]=4;
x++;
pos++;
break;
case (7):
//dis_cmd(k++);
string("5");
dis_cmd(k++);
key[x]=5;
x++;
pos++;
break;
case (6):
string("6");
dis_cmd(k++);
key[x]=6;
x++;
pos++;
break;
case (5):
string("7");
dis_cmd(k++);
key[x]=7;
x++;
pos++;
break;
case (4):
string("8");
dis_cmd(k++);
key[x]=8;
x++;
pos++;
break;
case (3):
string("9");
dis_cmd(k++);
key[x]=9;
x++;
pos++;
break;
case (2):
//string("*");
//dis_cmd(k++);
//key[x]=0;
//x++;
//pos++;
break;
case (1):
string("0");
dis_cmd(k++);
key[x]=0;
x++;
pos++;
break;
case (12):
break;
//default: ;
}
_delay_loop_2(300);
}
}
/*
* keypad.h
*
* Created: 12/19/2012 10:49:06 PM
* Author: Gelectorn
*/
#ifndef KEYPAD_H_
#define KEYPAD_H_
#define KEYPAD_PORT PORTD
#define KEYPAD_DDR DDRD
#define KEYPAD_PIN PIND
uint8_t GetKeyPressed()
{
uint8_t r,c;
KEYPAD_PORT|= 0X0F;
for(c=0;c<3;c++)
{
KEYPAD_DDR&=~(0X7F);
KEYPAD_DDR|=(0X40>>c);
for(r=0;r<4;r++)
{
if(!(KEYPAD_PIN & (0X08>>r)))
{
return (r*3+c);
}
}
}
return 0XFF;//Indicate No key pressed
}
#endif /* KEYPAD_H_ */
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?