@online67
1. Before I birng you in AVR Assembly Programming for Atiny25/85 using Microchip Studio, I would like to suggest you to practice the following UNO based "EEPROM Register Level codes" to understand the procedures of data read/write operation with EEPROM Memory.
In this program, 5 is being written into EEPROM location 0x0010; the data (n = 5) is read back and the onboard LED (L) is blinked for n times at 1-sec interval as validity check.
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
EEARL = 0x10; //EEPROM location: 0x0010
EEARH = 0x00;
//----------------
EEDR = 0x05; //data to be written
//------------------
EECR &= (0 << EEPM1); //EEPROM programming Mode; Erase and Write
EECR &= (0 << EEPM0);
//--------------------
EECR |= (1 << EEMPE); //Master Programming Bit is active
EECR |= (1 << EEPE); //EEPROM programming is enabled
//--------------------
while (bitRead(EECR, EEPE) != LOW) //wait until data write is done
{
; //wait until writing is done; about 3.4 ms
}
//--------------
EECR |= (1 <<EERE); //data read enabled
byte n = EEDR; //n = 5
Serial.print("Read from EEPROM Location, 0x0010: ");
Serial.println(n);
for (byte i = 0; i < n; i++)
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
}
void loop() {}
2. This is the Assemble Program for the sketch of Step-1 usig ATtiny85 device and Microchip Studio Assembler: (assembly successful)
.cseg
.org $0000 ;External Pin, Power-on Reset, Brown-out Reset, Watchdog system Reset
RESET: nop
rjmp START
.org $0010 ;application space
START: ldi r16, 0x00 ; stack top initialize at 0x2000
out spl, r16
ldi r16, 0x20 ;
out sph, r16 ; Attiny85
sbi DDRB, DDB0 ;PB0-pin is output
ldi r16, 0x10 ;loading low-byte of EEPROM address
out eearl, r16
ldi r16, 0x00 ;loading high byte of EEPROM address
out eearh, r16
ldi r16, 0x05 ;data for EEPROM location
out eedr, r16
cbi eecr, EEPM1 ;EEPROM Programming Mode; erase/write
cbi eecr, EEPM0
sbi eecr, EEMPE ;setting up EEPROM Master programmin Enable bit
sbi eecr, EEPE ;EEPROM programming enable
L1: sbis eecr, EEPE ;skip next line if EEPE-bit of eecr register is HIGH
rjmp L2 ;data write into EEPROM complete
rjmp L1 ;data is not yet written into EEPROM location
L2: sbi eecr, EERE ;data read enable active
in r16, EEDR ; data read
L3: ;blink LED at PB0-pin for n = (r16) times
sbi PORTB, PB0
rcall DELAY
cbi PORTB, PB0
rcall DELAY
dec r16
brne L3
L4: rjmp L4 ;wait here for ever
DELAY: ldi r18, 30 ;time delay subroutine
cagain: ldi r19, 30
magain: ldi r20, 30
fagain: dec r20
brne fagain
dec r19
brne magain
dec r18
brne cagain
ret
.exit
3. Given below is the Intel-Hex formatted file for the program of Step-2, which bears the binary codes of the program. The AVR Programmer of Fig-1 will extract the binary codes from the received hex file and then it will store the binary codes into the flash of ATtiny85.
:020000020000FC
:0400000000000EC02E
:1000200000E00DBF00E20EBFB89A00E10EBB00E099
:100030000FBB05E00DBBE598E498E29AE19AE19BDD
:1000400001C0FDCFE09A0DB3C09A05D0C09803D08F
:100050000A95D1F7FFCF2EE13EE14EE14A95F1F747
:0A0060003A95D9F72A95C1F70895E3
:00000001FF
Figure-1:
4. Place the ATtiny85 in the ZIF socket of Fig-1 and fuse the Hex-file of Step-3.
5. Testing for Data write validiy into EEPROM location.
(1) Take out the Attiny85 from ZIF socket.
(2) Place the ATtin85 on the Breadboard.
(3) Build circuit on Breadboard as per Fig-2.
Figure-2:
(4) Connect GND-pin of UNO (or -side of 5V Battery/Adopter) with Pin-4 of ATtiny85.
(5) Connect 5V-pin of UNO (or +side of 5V Battery/Adopter) with Pin-8 of Attiny85.
(6) Press the RESET Button, K1.
(9) Check that RLED blinks for five times.
The RLED is not blinking!!
6. Storing sketch (comment the Serial commands) Step-1 into the flash memory of ATtiny85 using Arduino UNO as Programmer.
This is working having followed the steps of this link.