1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

avrでeeprom

Last updated at Posted at 2018-02-28

#概要

avrでeepromやってみた。
attiny85でアセンブラで書いた。
attiny85には、512byteのeepromがある。

#環境

avr studio 4
attiny85 1mhz
tera term
usb-serial

#写真

image

#サンプルコード

eepromの先頭から255→1まで、書き込んで読んでみる。

rom_w:
	sbic	EECR, EEPE
	rjmp	rom_w
	ldi 	r16, (0 << EEPM1) | (0 << EEPM0)
	out 	EECR, r16
	out		EEARH, YH
	out		EEARL, YL
	out		EEDR, r22
	sbi		EECR, EEMPE
	sbi		EECR, EEPE
	ret

rom_r:
	sbic	EECR, EEPE
	rjmp	rom_r
	clr 	r0
	out 	EECR, r0
	out		EEARH, YH
	out		EEARL, YL
	sbi		EECR, EERE
	in		r16, EEDR
	ret

setup:
	ldi 	r16, high(RAMEND)
	out 	SPH, r16
	ldi 	r16, low(RAMEND)
	out 	SPL, r16
	cbi 	DDRB, PB0
	sbi 	DDRB, PB1
	sbi 	PORTB, PB1
loop:
	ldi		YL, 0
	ldi		YH, 0
	ldi 	r22, 255
	inc		YL
	rcall	rom_w
	dec		r22
	brne	PC - 3
	ldi		YL, 0
	ldi		YH, 0
	ldi 	r22, 255
	inc		YL
	rcall	rom_r
	rcall	bin2hex2
	ldi		r19, ' '
	rcall	send
	dec		r22
	brne	PC - 6
	rcall	wait
	rjmp	PC - 1

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?