Discussion in "Project Addition or Changes" started by    Neo008    Jun 4, 2010.
Fri Jun 04 2010, 05:12 pm
#1
Dear all,

I am using simple dc motor to shut/open the door with 89c2051 lock project....

Here in my area power failure is a big problem

I want to add two features in it...

A. Password Volatility
B. Some variable storage like boolean/flag ...say 1 or 0 to identify the state of the door i.e. opened/closed.
C. By knowing the open/close state can we force the program to start in locked or unlocked position

i think that 24cxx may be used

i have read the pdf from atmel describes the feature of this interfacing but

D. i want some sample code to read and write to 24c02
E. 2 wire connections with uc


Please help me out.

thanks in advance.
Fri Jun 04 2010, 07:34 pm
#2
Hi,
just type "24c02 and 8051"in google and u wil find a sample code..
Hope this answers ur question.
Sat Jun 05 2010, 03:55 pm
#3
> A. Password Volatility

Storing in EEPROM does that.

> B. Some variable storage like boolean/flag ...say 1 or 0 to identify the state of the door i.e. opened/closed.

store it as a byte during read and write operation.
e.g.
if(Flag == 0)
  storebyte(0, Address);
else
  storebyte(1, Address);

similarly when reading..
readFlag = readbyte(Address);
if(readFlag == 0)
   Flag = 0;
else
   Flag = 1;


> C. By knowing the open/close state can we force the program to start in locked or unlocked position
yes as explained above you can also store the last state of door. and after reading EEPROM you can keep door open/close on power up. But for electronic lock purpose i would not recommend this. coz incase you are going to store door status to close (with prev status open) and power goes during write operation. so when power comes door will remain open which is not desired.
whereas if someone knows the lock he/she can open it anytime. decide over this feature.

> D. i want some sample code to read and write to 24c02
You can make use of library available on tutorial page for I2C.
http://www.8051projects.net/i2c-twi-tutorial/
and write a code for EEPROM yourself. you can ask for help if needed

> E. 2 wire connections with uc
you can implement I2C on any two port pins using the code given in tutorial.
Wed Jun 16 2010, 08:43 pm
#4
Hi and thanks Ajay,

I posted reply 2 times but it failed i don know why it took 'Test' and so i'm editing it.

I think your right about storing the doors states...it's not the right solution. It should be in forced manner as it is already. Though I'll play with it.

As you say..
you can implement I2C on any two port pins using the code given in tutorial.
but in our 2051 lock project we had only one port free which i've used for buzzer...
Do you mean an overlap type of connection..?? Does this work?


[ Edited Wed Jun 16 2010, 09:07 pm ]
Thu Jun 17 2010, 01:03 am
#5
I think this is why it is called bit banging. ac

as i have read.. for communication with E2PROM type of thing it is required to send dummy write cycle to point the read pointer at desired location. This read procedure doesn't seems to do like this

unsigned char I2CRead(){
unsigned char i, Data=0;
for(i=0;i<8;i++){
SCL = 0;
SCL = 1;
if(SDA)
Data |=1;
Data<<=1;
}
SCL = 0;
SDA = 1;
return Data;
}


so how should i send a dummy write? what data should be passed in write function? Or do I have to write another function for dummy write?

-NEO
Fri Jun 18 2010, 12:30 am
#6
yes thats bit banging technique.

yes you need to make a dummy write operation before you read. and the read function shown above reads 8bit from i2c bus.

dummy write operation goes this way:
[start][devaddress+WR][subaddr][restart][Devaddress+RD][data][data]...[Stop]

you can see working example of dummy write here in this example:
http://www.8051projects.net/i2c-twi-tutorial/8051-DS1307-example.php

In example above i am reading 7 registers of DS1307.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

AntoniaRoons
Fri Apr 19 2024, 09:59 pm
carpinteyrowrl
Fri Apr 19 2024, 02:51 pm
DonaldJAX
Fri Apr 19 2024, 01:08 pm
Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am