📄 eeprom.s
字号:
.module EEprom.c
.area text(rom, con, rel)
.dbfile F:\job\M16学习板\EEPROM实验(实验八)\EEprom.c
.dbfile F:\job\M16学习板\EEPROM实验(实验八)\..\ICC_H\SOFTWARE.h
.dbfunc e ChangeIntToHex _ChangeIntToHex fV
; dec -> R20,R21
.even
_ChangeIntToHex::
xcall push_gset1
movw R20,R16
.dbline -1
.dbline 136
; /*******************************************************************
; 实验八
; 实验名称: AVR单片机内部EEPROM实验
; 实验目的: 学习AVR单片机的内部的EEPROM的读写
; 实验现象: 通过串口发送字符串给EEPROM,M16 512个字节,发送@R,读EEPROM
; 中的内容,并通过串口发送给PC机
; 环 境: ICCAVR6.31A
; 设 计 者: shinea8868
; 说 明: 部分程序原型源自网络,经本人修改调试可用,请尊重知识产权,如
; 作商业用途请保留本段文字
; 完成日期: 2007年4月10日
; *******************************************************************/
; #include <iom16v.h>
; #include <macros.h>
; #include "..\ICC_H\SOFTWARE.h"
;
; uchar RecvFlag = 0; //串口接收到的数据
; uchar Flag = 0; //为1时表示接收到了@,如果紧接着收到
; //R则发送EEPROM中的数据
; uint EEpromAdd = 0; //存储在EEPROM中的地址
; uchar temp[255],tempcnt = 0; //暂存数据
; uchar temp1; //暂存串口接收到的数据
; /*-----------------------------------------------------------------
; 函数名称: void EepromWrite (uint addr, uchar val)
; 函数功能: EEPROM的写程序
; 参 数: num 写的字符个数,
; addr 存放的首地址
; *val 存储数据的首地址
; 返 回 值: 无
; -----------------------------------------------------------------*/
; void EepromWrite ( uint addr, uchar val)
; {
; while ( EECR&0x02 ); //判断EEWE是否为0
; EEAR = addr;
; EEDR = val;
; CLI();
; EECR = EECR|0x04; //置EEMWE为1
; EECR = EECR|0x02; //置EEWE为1
; SEI();
; }
; /*-----------------------------------------------------------------
; 函数名称: void EepromRead (uchar num, uint addr, uchar *val)
; 函数功能: EEPROM的写程序
; 参 数: num 读的字符个数,
; addr 读字符的首地址
; *val 读数据的暂存的首地址
; 返 回 值: 无
; -----------------------------------------------------------------*/
; void EepromRead (uchar num, uint addr, uchar *val)
; {
; while (num)
; {
; while ( EECR&0x01 ); //判断EEWE是否为0
; EEAR = addr;
; EECR = EECR|0x01; //置EERE为1
; *val = EEDR;
; addr++;
; val++;
; num--;
; }
; }
; /*-----------------------------------------------------------------
; 函数名称: void Uart0Init(void)
; 函数功能: 串口初始化
; 波特率 600 0.2% 字符长度 8bit 无奇偶校验
; 参 数:
; 返 回 值: 无
; -----------------------------------------------------------------*/
; void Uart0Init(void)
; {
; UCSRB = 0x00; //关串口
; UCSRA = 0x02; //倍速模式 M16中文P151
; UCSRC = BIT(URSEL) | 0x06; //写UCSRC寄存器,设定8个bit
; UBRR = 206; //设定串口波特率为600
; UCSRB = 0x98; //开串口
; }
; /*-----------------------------------------------------------------
; 函数名称: void UartRecvData(void)
; 函数功能:
; 参 数:
; 返 回 值: 无
; -----------------------------------------------------------------*/
; #pragma interrupt_handler UartRecvData:12
; void UartRecvData(void)
; {
; temp1 = UDR;
; RecvFlag = 1;
; }
; /*-----------------------------------------------------------------
; 函数名称: void UartTransmitData(uchar *SendData, uchar len)
; 函数功能: 发送字符串
; 参 数: SendData 发送字符串的首地址
; len 发送字符串的长度
; 返 回 值: 无
; -----------------------------------------------------------------*/
; void UartTransmitData(uchar *SendData, uint len)
; {
; uint i;
; for( i = 0; i < len; i++)
; {
; while(!(UCSRA&0x20)); //判断数据寄存器是否为空
; UDR = SendData[i];
; }
; }
; /*-----------------------------------------------------------------
; 函数名称: void InitDevices(void)
; 函数功能: 初始化各种信息
; 参 数:
; 返 回 值: 无
; -----------------------------------------------------------------*/
; void InitDevices(void)
; {
; CLI(); //关全部中断
; Uart0Init();
; SEI(); //开全中断
; }
;
; void main(void)
; {
; uchar EepromData[255] ;
; uint j;
; InitDevices();
; while(j++);
; EepromRead (255, 0, EepromData); //读取上次断电前程序存储的数据
; UartTransmitData(EepromData, 255); //通过串口显示
; while(1)
; {
; if( Flag == 2)
; {
; Flag = 0;
; EepromRead (EEpromAdd, 0, EepromData);//读取本次存储的数据,串口输出
; UartTransmitData(EepromData, EEpromAdd);
; }
; if( RecvFlag)
; {
; RecvFlag = 0;
.dbline 137
; if( temp1 == '@')
movw R30,R20
ldd R2,z+0
clr R3
ldi R17,10
mov R16,R2
xcall mod8u
mov R4,R16
ldi R17,10
mov R16,R2
xcall div8u
mov R24,R16
andi R24,#0x0F
swap R24
or R24,R4
movw R30,R20
std z+0,R24
.dbline -2
L1:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r dec 20 pc
.dbend
.dbfunc e ChangeHexToInt _ChangeHexToInt fV
; hex -> R16,R17
.even
_ChangeHexToInt::
.dbline -1
.dbline 166
; Flag = 1;
; else if(((temp1 == 'R')||(temp1 == 'r'))&&( Flag == 1))//连续接收到@R
; {
; Flag = 2;
; }
; else
; {
; Flag = 0;
; EepromWrite ( EEpromAdd++, temp1);
; if( EEpromAdd >= 255)
; EEpromAdd = 0;
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
.dbline 167
; }
movw R30,R16
ldd R2,z+0
clr R3
mov R24,R2
swap R24
andi R24,#0x0F
ldi R25,10
mul R25,R24
mov R24,R2
andi R24,15
mov R2,R0
add R2,R24
std z+0,R2
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbsym r hex 16 pc
.dbend
.dbfunc e Delay _Delay fV
; i -> R16
.even
_Delay::
.dbline -1
.dbline 180
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
.dbline 182
; }
; }
ldi R16,200
L4:
.dbline 183
L5:
.dbline 183
; }
mov R2,R16
clr R3
subi R16,1
tst R2
brne L4
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbsym r i 16 c
.dbend
.area data(ram, con, rel)
.dbfile F:\job\M16学习板\EEPROM实验(实验八)\..\ICC_H\SOFTWARE.h
_RecvFlag::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\job\M16学习板\EEPROM实验(实验八)\..\ICC_H\SOFTWARE.h
.dbfile F:\job\M16学习板\EEPROM实验(实验八)\EEprom.c
.dbsym e RecvFlag _RecvFlag c
_Flag::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\job\M16学习板\EEPROM实验(实验八)\EEprom.c
.dbsym e Flag _Flag c
_EEpromAdd::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile F:\job\M16学习板\EEPROM实验(实验八)\EEprom.c
.dbsym e EEpromAdd _EEpromAdd i
_tempcnt::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\job\M16学习板\EEPROM实验(实验八)\EEprom.c
.dbsym e tempcnt _tempcnt c
.area text(rom, con, rel)
.dbfile F:\job\M16学习板\EEPROM实验(实验八)\EEprom.c
.dbfunc e EepromWrite _EepromWrite fV
; val -> R18
; addr -> R16,R17
.even
_EepromWrite::
.dbline -1
.dbline 32
L8:
.dbline 33
L9:
.dbline 33
sbic 0x1c,1
rjmp L8
.dbline 34
out 0x1f,R17
out 0x1e,R16
.dbline 35
out 0x1d,R18
.dbline 36
cli
.dbline 37
sbi 0x1c,2
.dbline 38
sbi 0x1c,1
.dbline 39
sei
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbsym r val 18 c
.dbsym r addr 16 i
.dbend
.dbfunc e EepromRead _EepromRead fV
; val -> R20,R21
; addr -> R18,R19
; num -> R16
.even
_EepromRead::
xcall push_gset1
ldd R20,y+2
ldd R21,y+3
.dbline -1
.dbline 50
xjmp L13
X0:
.dbline 52
L15:
.dbline 53
L16:
.dbline 53
sbic 0x1c,0
rjmp L15
.dbline 54
out 0x1f,R19
out 0x1e,R18
.dbline 55
sbi 0x1c,0
.dbline 56
in R2,0x1d
movw R30,R20
std z+0,R2
.dbline 57
subi R18,255 ; offset = 1
sbci R19,255
.dbline 58
subi R20,255 ; offset = 1
sbci R21,255
.dbline 59
dec R16
.dbline 60
L13:
.dbline 51
tst R16
brne L16
.dbline -2
L11:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r val 20 pc
.dbsym r addr 18 i
.dbsym r num 16 c
.dbend
.dbfunc e Uart0Init _Uart0Init fV
.even
_Uart0Init::
.dbline -1
.dbline 70
.dbline 71
clr R2
out 0xa,R2
.dbline 72
ldi R24,2
out 0xb,R24
.dbline 73
ldi R24,134
out 0x20,R24
.dbline 74
ldi R24,206
out 0x9,R24
.dbline 75
ldi R24,152
out 0xa,R24
.dbline -2
L18:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 44
jmp _UartRecvData
.area text(rom, con, rel)
.dbfile F:\job\M16学习板\EEPROM实验(实验八)\EEprom.c
.dbfunc e UartRecvData _UartRecvData fV
.even
_UartRecvData::
st -y,R2
st -y,R24
in R2,0x3f
st -y,R2
.dbline -1
.dbline 85
.dbline 86
in R2,0xc
sts _temp1,R2
.dbline 87
ldi R24,1
sts _RecvFlag,R24
.dbline -2
L19:
ld R2,y+
out 0x3f,R2
ld R24,y+
ld R2,y+
.dbline 0 ; func end
reti
.dbend
.dbfunc e UartTransmitData _UartTransmitData fV
; i -> R20,R21
; len -> R18,R19
; SendData -> R16,R17
.even
_UartTransmitData::
xcall push_gset1
.dbline -1
.dbline 97
.dbline 99
clr R20
clr R21
xjmp L24
X1:
.dbline 100
L25:
.dbline 101
L26:
.dbline 101
sbis 0xb,5
rjmp L25
.dbline 102
movw R30,R20
add R30,R16
adc R31,R17
ldd R2,z+0
out 0xc,R2
.dbline 103
L22:
.dbline 99
subi R20,255 ; offset = 1
sbci R21,255
L24:
.dbline 99
cp R20,R18
cpc R21,R19
brlo L26
.dbline -2
L20:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r len 18 i
.dbsym r SendData 16 pc
.dbend
.dbfunc e InitDevices _InitDevices fV
.even
_InitDevices::
.dbline -1
.dbline 112
.dbline 113
cli
.dbline 114
xcall _Uart0Init
.dbline 115
sei
.dbline -2
L28:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
; j -> R20,R21
; EepromData -> y+2
.even
_main::
sbiw R28,63
sbiw R28,63
sbiw R28,63
sbiw R28,63
sbiw R28,5 ; offset = 257
.dbline -1
.dbline 119
.dbline 122
xcall _InitDevices
L30:
.dbline 123
L31:
.dbline 123
movw R2,R20
subi R20,255 ; offset = 1
sbci R21,255
tst R2
brne L30
tst R3
brne L30
X2:
.dbline 124
movw R24,R28
adiw R24,2
std y+1,R25
std y+0,R24
clr R18
clr R19
ldi R16,255
xcall _EepromRead
.dbline 125
ldi R18,255
ldi R19,0
movw R16,R28
subi R16,254 ; offset = 2
sbci R17,255
xcall _UartTransmitData
xjmp L34
L33:
.dbline 127
.dbline 128
lds R24,_Flag
cpi R24,2
brne L36
.dbline 129
.dbline 130
clr R2
sts _Flag,R2
.dbline 131
movw R24,R28
adiw R24,2
std y+1,R25
std y+0,R24
clr R18
clr R19
lds R16,_EEpromAdd
xcall _EepromRead
.dbline 132
lds R18,_EEpromAdd
lds R19,_EEpromAdd+1
movw R16,R28
subi R16,254 ; offset = 2
sbci R17,255
xcall _UartTransmitData
.dbline 133
L36:
.dbline 134
lds R2,_RecvFlag
tst R2
breq L38
.dbline 135
.dbline 136
clr R2
sts _RecvFlag,R2
.dbline 137
lds R24,_temp1
cpi R24,64
brne L40
.dbline 138
ldi R24,1
sts _Flag,R24
xjmp L41
L40:
.dbline 139
lds R24,_temp1
cpi R24,82
breq L44
cpi R24,114
brne L42
L44:
lds R24,_Flag
cpi R24,1
brne L42
.dbline 140
.dbline 141
ldi R24,2
sts _Flag,R24
.dbline 142
xjmp L43
L42:
.dbline 144
.dbline 145
clr R2
sts _Flag,R2
.dbline 146
lds R18,_temp1
lds R2,_EEpromAdd
lds R3,_EEpromAdd+1
movw R24,R2
adiw R24,1
sts _EEpromAdd+1,R25
sts _EEpromAdd,R24
movw R16,R2
xcall _EepromWrite
.dbline 147
lds R24,_EEpromAdd
lds R25,_EEpromAdd+1
cpi R24,255
ldi R30,0
cpc R25,R30
brlo L45
.dbline 148
clr R2
clr R3
sts _EEpromAdd+1,R3
sts _EEpromAdd,R2
L45:
.dbline 149
L43:
L41:
.dbline 150
L38:
.dbline 151
L34:
.dbline 126
xjmp L33
X3:
.dbline -2
L29:
adiw R28,63
adiw R28,63
adiw R28,63
adiw R28,63
adiw R28,5 ; offset = 257
.dbline 0 ; func end
ret
.dbsym r j 20 i
.dbsym l EepromData 2 A[255:255]c
.dbend
.area bss(ram, con, rel)
.dbfile F:\job\M16学习板\EEPROM实验(实验八)\EEprom.c
_temp1::
.blkb 1
.dbsym e temp1 _temp1 c
_temp::
.blkb 255
.dbsym e temp _temp A[255:255]c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -