Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Attiny2313 password based switch

Status
Not open for further replies.

thannara123

Advanced Member level 5
Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,602
Helped
122
Reputation
244
Reaction score
116
Trophy points
1,353
Visit site
Activity points
10,625
Hello expetrs
I am trying to make a code lock (with reffrence https://extremeelectronics.co.in/avr-projects/avr-project-atmega8-based-smart-code-lock/) here they used avr8 . but i changed it as attiny2313 . How to program its EEPROm
Code:
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]
if[/COLOR][/SIZE][/FONT] 
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT] 
[FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2](ReadPassFromEEPROM()==25755) // in case of avr8[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#800000][/COLOR][/SIZE][/FONT]
[FONT=Consolas][SIZE=2][COLOR=#800000][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]{[/SIZE][/FONT][/SIZE][/FONT]
[FONT=Consolas][SIZE=2][COLOR=#800000][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]//Password is blank so store a default password[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#800000][/COLOR][/SIZE][/FONT]
[FONT=Consolas][SIZE=2][COLOR=#800000][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]WritePassToEEPROM(1234);[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#800000][/COLOR][/SIZE][/FONT]
[FONT=Consolas][SIZE=2][COLOR=#800000][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]}[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#800000][FONT=Consolas][SIZE=2][COLOR=#800000][FONT=Consolas][SIZE=2][COLOR=#800000][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Consolas][SIZE=2][COLOR=#800000][FONT=Consolas][SIZE=2][COLOR=#800000][FONT=Consolas][SIZE=2][COLOR=#800000]		
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

what is the blank value attiny 2313 ?

please help me
 

I have already provided you with a link to my blog that showed how you read/write the AVR eeprom so I don't understand the question.
mega and tiny use the same way to access the eeprom.
 

Code:
 if 
 
(ReadPassFromEEPROM()==25755)
means the password is checked with 25777. If the password read using ReadPassFromEEPROM() is 25775 then a default password 1234 is written to the eeprom. The address will be in the 2 functions used.
Code:
 WritePassToEEPROM(1234);
means writing the password 1234 to eeprom.

The code should be something like this
Code:
//Check if the EEPROM has a valid password or is blank
 if((ReadPassFromEEPROM()==25755) || (ReadPassFromEEPROM()==0))
   {
      //Password is blank or 25755 so store a default password

      WritePassToEEPROM(1234);
   }
 
Last edited:

In avr8(ReadPassFromEEPROM()==25755) // .they told that ,it is the default EEPROM value ,(that is nothing write -first time programing )
if so what is the defult value of attiny EEPROM
 

Code:
#include <avr/io.h>
#include <inttypes.h>

#include "eeprom.h"

uint8_t EEPROMRead(uint16_t uiAddress)
{
	/* Wait for completion of previous write */
	while(EECR & (1<<EEPE));
	/* Set up address register */
	EEAR = uiAddress;
	/* Start eeprom read by writing EERE */
	EECR |= (1<<EERE);
	/* Return data from data register */
	return EEDR;
}

void EEPROMWrite(uint16_t uiAddress, uint8_t ucData)
{
	/* Wait for completion of previous write */
	while(EECR & (1<<EEPE));
	/* Set up address and data registers */
	EEAR = uiAddress;
	EEDR = ucData;
	/* Write logical one to EEMWE */
	EECR |= (1<<EEMPE);
	/* Start eeprom write by setting EEWE */
	EECR |= (1<<EEPE);
}
 

Your way of using the functions are wrong.

See the prototypes
Code:
uint8_t EEPROMRead(uint16_t uiAddress)
void EEPROMWrite(uint16_t uiAddress, uint8_t ucData)

You have to pass address to uint8_t EEPROMRead(uint16_t uiAddress) like this EEPROMRead(1234); 1234 is the 16 bit address.
To Write you have to pass the address and data like EEPROMWrite(1234, 25); 1234 is the address and 25 is the data.

You didn't post the code for ReadPassFromEEPROM() and WritePassToEEPROM() functions.

See this is the code for the 2 functions
Code:
 void WritePassToEEPROM(uint16_t pass)
{

	EEPROMWrite(0000,(pass%100));
	EEPROMWrite(0001,(pass/100));
}

uint16_t ReadPassFromEEPROM()
{

	return (EEPROMRead(0001)*100  +	EEPROMRead(0000));
}
The WritePassToEEPROM() function writes to 2 addresses 0000 and 0001. Eg. if password is 1234 then 1234%100 is 34 and 1234/100 is 12. So, at address 0000 it will be 34 and at address 0001 it will be 12.
While reading EEPROMRead(0000) will return 34 and EEPROMRead(0001)*100 will return 1200. 1200 + 34 is 1234. ReadPassFromEEPROM() function returns 16 bit or 2 bytes 1234.
 
Last edited:

Your way of using the functions are wrong.

No they are not, don't jump to conclusions in a hurry
Code:
void WritePassToEEPROM(uint16_t pass)
{

	EEPROMWrite(0000,(pass%100));
	EEPROMWrite(0001,(pass/100));
}

uint16_t ReadPassFromEEPROM()
{

	return (EEPROMRead(0001)*100  +	EEPROMRead(0000));
}

- - - Updated - - -

what is the blank value attiny 2313 ?


If I'm not mistaken the eeprom space is filled with 1s so this would give a default of (255 * 100)+255 = 25755

Why don't you use WritePassToEEPROM(); to write the new password you want to use?
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top