i thought i have to share that i solved the problem. Unfortunately the UART pins had to be attached with actual wires, i was using a label for every pin which is working for everything but not the UART . thank you again salem i really appreciate your time. this is what i have added to the code so far.
Door lock
user interface micro-controller code
Code:
#include <avr/io.h>
#include "BASICTYPES.h"
#include <util/delay.h>
#include "keypad.h"
#include "LCD.h"
#include "UART.h"
#define CORRECT_PASSWORD 0X01
#define WRONG_PASWORD 0X02
#define newsetsucces 0x03
#define reset 1
#define open 2
void send_password(void);
void receive_status(void);
void mode_rst_opn(void);
u8 k=0,no_digits=0,ctr=0,cond,passw[4],dec;
u8 flag;
int main(void)
{
keypad_init();
LCD_init();
UART_Init();
_delay_ms(100);
while(1)
{
LCD_command(0x01);
LCD_print(" Enter password");
send_password();
receive_status();
}
}
void send_password(void)
{
LCD_goto(9,2);
no_digits=0;
while (no_digits!=4)
{
k=keypad_read();
_delay_ms(200);
while (k!=0)
{
passw[no_digits]=k;
LCD_data(k);
k=0;
no_digits++;
}
}
for (ctr=4;ctr>0;ctr--)
{
UART_SendByte(passw[4-ctr]);
_delay_ms(100);
}
}
void receive_status(void)
{
cond=UART_ReciveData();
switch (cond)
{
case CORRECT_PASSWORD :
{
LCD_command(0x01);
LCD_goto(0,2);
LCD_print(" Correct password");
_delay_ms(500);
mode_rst_opn();
}
break;
case WRONG_PASWORD :
{
LCD_command(0x01);
LCD_goto(0,2);
LCD_print(" Wrong password");
_delay_ms(1000);
}
break;
}
}
void mode_rst_opn(void)
{
u8 user_deci=0,rst_status;
LCD_command(0x01);
LCD_print(" ON to open");
LCD_goto(0,2);
LCD_print(" '=' to reset");
user_deci=keypad_read();
_delay_ms(100);
while (!user_deci);
if (user_deci=='C')
{
UART_SendByte(open);
LCD_command(0x01);
LCD_print(" door is open ");
_delay_ms(1000);
user_deci=0;
}
else if (user_deci=='=')
{ user_deci=0;
UART_SendByte(reset);
LCD_command(0x01);
LCD_print("please enter ");
LCD_goto(0,2);
LCD_print(" new pass ");
send_password();
LCD_command(0x01);
LCD_print("enter password ");
LCD_goto(0,2);
LCD_print(" again ");
send_password();
rst_status=UART_ReciveData();
if (rst_status==newsetsucces)
{
LCD_command(0x01);
LCD_print("password matched");
_delay_ms(1000);
}
else
{
LCD_command(0x01);
LCD_print("not matched pass");
_delay_ms(1000);
}
}
}
inside room micro-controller
Code:
#include <avr/io.h>
#include "UART.h"
#include "BASICTYPES.h"
#include "EEPROM_Driver.h"
#include <util/delay.h>
#define CORRECT_PASSWORD 0X01
#define WRONG_PASWORD 0X02
#define newsetsucces 0x03
#define setagain 0x04
#define reset 1
#define open 2
void mode_rst_opn(void);
void stor_pass_eeprom(void);
void compare_passes(void);
u8 cmpr_new_pass(void);
u8 password[4]="5555";
u8 flag,gflag;
int main(void)
{
UART_Init();
if (gflag==0)
{
stor_pass_eeprom();
gflag=1;
}
while ( 1 )
{
flag=0;
compare_passes();
if(flag==5)
{
mode_rst_opn();
}
}
}
u8 cmpr_new_pass(void)
{
u8 frst_pass[4], scndpass[4],dec,z;
for (z=0;z<4;z++)
{
frst_pass[z]=UART_ReciveData();
_delay_ms(50);
}
for (z=0;z<4;z++)
{
scndpass[z]=UART_ReciveData();
_delay_ms(50);
}
if ((frst_pass[0]==scndpass[0])&&(frst_pass[1]==scndpass[1])&&(frst_pass[2]==scndpass[2])&&(frst_pass[3]==scndpass[3]))
{
dec=1;
for (z=0;z<4;z++)
{
password[z]=frst_pass[z];
}
stor_pass_eeprom();
}
else
{
dec=2;
}
return dec;
}
void stor_pass_eeprom(void)
{
u8 ctr;
for (ctr=0;ctr<4;ctr++)
{
EEPROM_Write(ctr,password[ctr]);
}
}
void mode_rst_opn(void)
{
u8 mod,cmpr_status;
mod=UART_ReciveData();
if (mod == open)
{
}
else if(mod==reset)
{
cmpr_status=cmpr_new_pass();
if (cmpr_status==1)
{
UART_SendByte(newsetsucces);
}
else if (cmpr_status==2)
{
UART_SendByte(setagain);
}
}
}
void compare_passes(void)
{
u8 rx_pass[4],z,k=0;
for (z=0;z<4;z++)
{
rx_pass[z]=UART_ReciveData();
_delay_ms(50);
}
for (z=0;z<4;z++)
{
password[z]=EEPROM_Read(z);
_delay_ms(50);
}
if((password[0]==rx_pass[0])&&(password[1]==rx_pass[1])&&(password[2]==rx_pass[2])&&(password[3]==rx_pass[3])) k=1;
if (k==1)
{
UART_SendByte(CORRECT_PASSWORD);
flag=5;
}
else if (k==0)
{
UART_SendByte(WRONG_PASWORD);
flag=4;
}
}
i'm still stuck with having a default password 5555 every time you turn on the device. you can change the pass when your using the device but if turned off returns back to 5555.