📄 eeprom读写.s
字号:
.module EEPROM读写.c
.area text(rom, con, rel)
.dbfile E:\xiaozhiyong2009\设计资料\项目设计\ICCAVR_mega8_C\ICCAVR_mega8_EEPROM读写\EEPROM读写.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 9
; //ICC-AVR application builder : 2009-3-12 17:39:42
; // Target : M8
; // Crystal: 8.0000Mhz
;
; #include <iom8v.h>
; #include <macros.h>
;
; void port_init(void)
; {
.dbline 10
; PORTB = 0x00;
clr R2
out 0x18,R2
.dbline 11
; DDRB = 0x00;
out 0x17,R2
.dbline 12
; PORTC = 0x00; //m103 output only
out 0x15,R2
.dbline 13
; DDRC = 0x00;
out 0x14,R2
.dbline 14
; PORTD = 0x00;
out 0x12,R2
.dbline 15
; DDRD = 0x00;
out 0x11,R2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 20
; }
;
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
.dbline 22
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 23
; port_init();
rcall _port_init
.dbline 25
;
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 26
; GICR = 0x00;
out 0x3b,R2
.dbline 27
; TIMSK = 0x00; //timer interrupt sources
out 0x39,R2
.dbline 28
; SEI(); //re-enable interrupts
sei
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e eeprom_write _eeprom_write fV
; data -> R18
; address -> R16,R17
.even
_eeprom_write::
.dbline -1
.dbline 40
; //all peripherals are now initialized
; }
;
; /*****************************************************************************
; 用 途:EEPROM读写程序
; Taget :mega8
; crystal :8M
; 介 绍:
; *****************************************************************************/
; //eeprom写操作
; void eeprom_write(unsigned int address,unsigned char data)
; {
L4:
.dbline 42
; while(EECR&(1<<EEWE))
; {;}
.dbline 42
.dbline 42
L5:
.dbline 41
sbic 0x1c,1
rjmp L4
X0:
.dbline 43
; EEAR=address;
out 0x1f,R17
out 0x1e,R16
.dbline 44
; EEDR=data;
out 0x1d,R18
.dbline 45
; EECR|=(1<<EEMWE);
sbi 0x1c,2
.dbline 46
; EECR|=(1<<EEWE);
sbi 0x1c,1
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbsym r data 18 c
.dbsym r address 16 i
.dbend
.dbfunc e eeprom_read _eeprom_read fc
; address -> R16,R17
.even
_eeprom_read::
.dbline -1
.dbline 50
; }
; //eeprom读操作
; unsigned char eeprom_read(unsigned int address)
; {
L8:
.dbline 52
; while(EECR&(1<<EEWE))
; {;}
.dbline 52
.dbline 52
L9:
.dbline 51
sbic 0x1c,1
rjmp L8
X1:
.dbline 53
; EEAR=address;
out 0x1f,R17
out 0x1e,R16
.dbline 54
; EECR|=(1<<EERE);
sbi 0x1c,0
.dbline 55
; return EEDR;
in R16,0x1d
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbsym r address 16 i
.dbend
.dbfunc e main _main fV
; i -> R10
.even
_main::
.dbline -1
.dbline 59
; }
; //****************************************************************************
; void main()
; {
.dbline 61
; unsigned char i;
; port_init();
rcall _port_init
.dbline 62
; init_devices();
rcall _init_devices
.dbline 64
;
; eeprom_write(1,0x55);
ldi R18,85
ldi R16,1
ldi R17,0
rcall _eeprom_write
.dbline 65
; eeprom_write(2,0xAA);
ldi R18,170
ldi R16,2
ldi R17,0
rcall _eeprom_write
.dbline 66
; i=eeprom_read(1);
ldi R16,1
ldi R17,0
rcall _eeprom_read
.dbline 67
; PORTB=i;
out 0x18,R16
.dbline 68
; i=eeprom_read(2);
ldi R16,2
ldi R17,0
rcall _eeprom_read
mov R10,R16
.dbline 69
; PORTD=i;
out 0x12,R16
L12:
.dbline 71
; while(1)
; {
.dbline 72
; ;
.dbline 73
; }
L13:
.dbline 70
rjmp L12
X2:
.dbline -2
L11:
.dbline 0 ; func end
ret
.dbsym r i 10 c
.dbend
; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -