📄 avr_gy-29.s
字号:
ldi R17,0
xcall _I2C_Read
mov R20,R16
clr R21
.dbline 44
; x=(x<<8)+I2C_Read(0x32);
ldi R16,50
ldi R17,0
xcall _I2C_Read
mov R21,R20
mov R20,R16
.dbline 46
;
; if(x<0){
cpi R20,0
ldi R30,0
cpc R21,R30
brge L85
X25:
.dbline 46
.dbline 47
; x=-x;
com R20
com R21
subi R20,0xFF
sbci R21,0xFF
.dbline 48
; LCD_write_char(2,0,'-'); //显示负符号位
ldi R24,45
std y+0,R24
clr R18
ldi R16,2
xcall _LCD_write_char
.dbline 49
; }
xjmp L86
L85:
.dbline 51
; else
; LCD_write_char(2,0,' '); //显示空格
ldi R24,32
std y+0,R24
clr R18
ldi R16,2
xcall _LCD_write_char
L86:
.dbline 52
; temp=(float)x*3.9; //计算数据和显示,查考ADXL345快速入门第4页
ldi R16,<L87
ldi R17,>L87
xcall elpm32
movw R2,R16
movw R4,R18
movw R16,R20
xcall int2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
movw R16,R2
movw R18,R4
xcall fpmule2
std y+1,R16
std y+2,R17
std y+3,R18
std y+4,R19
.dbline 53
; conversion(temp); //转换出显示需要的数据
ldd R16,y+1
ldd R17,y+2
ldd R18,y+3
ldd R19,y+4
xcall fpint
xcall _conversion
.dbline 54
; LCD_write_char(0,0,'X'); //第0行,第0列 显示X
ldi R24,88
std y+0,R24
clr R18
clr R16
xcall _LCD_write_char
.dbline 55
; LCD_write_char(1,0,':');
ldi R24,58
std y+0,R24
clr R18
ldi R16,1
xcall _LCD_write_char
.dbline 56
; LCD_write_char(3,0,display[0]);
lds R2,_display
std y+0,R2
clr R18
ldi R16,3
xcall _LCD_write_char
.dbline 57
; LCD_write_char(4,0,'.');
ldi R24,46
std y+0,R24
clr R18
ldi R16,4
xcall _LCD_write_char
.dbline 58
; LCD_write_char(5,0,display[1]);
lds R2,_display+1
std y+0,R2
clr R18
ldi R16,5
xcall _LCD_write_char
.dbline 59
; LCD_write_char(6,0,display[2]);
lds R2,_display+2
std y+0,R2
clr R18
ldi R16,6
xcall _LCD_write_char
.dbline 60
; LCD_write_char(7,0,'g');
ldi R24,103
std y+0,R24
clr R18
ldi R16,7
xcall _LCD_write_char
.dbline -2
L84:
.dbline 0 ; func end
adiw R28,5
ld R21,y+
ld R20,y+
ret
.dbsym l temp 1 D
.dbsym r x 20 I
.dbend
.dbfunc e display_y _display_y fV
; temp -> y+1
; y -> R20,R21
.even
_display_y::
st -y,R20
st -y,R21
sbiw R28,5
.dbline -1
.dbline 66
;
; }
; //*******************************
; //显示y
; void display_y(void)
; { float temp;
.dbline 68
; int y;
; y=I2C_Read(0x35);
ldi R16,53
ldi R17,0
xcall _I2C_Read
mov R20,R16
clr R21
.dbline 69
; y=(y<<8)+I2C_Read(0x34);
ldi R16,52
ldi R17,0
xcall _I2C_Read
mov R21,R20
mov R20,R16
.dbline 71
;
; if(y<0){
cpi R20,0
ldi R30,0
cpc R21,R30
brge L91
X26:
.dbline 71
.dbline 72
; y=-y;
com R20
com R21
subi R20,0xFF
sbci R21,0xFF
.dbline 73
; LCD_write_char(2,1,'-'); //显示负符号位
ldi R24,45
std y+0,R24
ldi R18,1
ldi R16,2
xcall _LCD_write_char
.dbline 74
; }
xjmp L92
L91:
.dbline 76
; else
; LCD_write_char(2,1,' '); //显示空格
ldi R24,32
std y+0,R24
ldi R18,1
ldi R16,2
xcall _LCD_write_char
L92:
.dbline 77
; temp=(float)y*3.9; //计算数据和显示,查考ADXL345快速入门第4页
ldi R16,<L87
ldi R17,>L87
xcall elpm32
movw R2,R16
movw R4,R18
movw R16,R20
xcall int2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
movw R16,R2
movw R18,R4
xcall fpmule2
std y+1,R16
std y+2,R17
std y+3,R18
std y+4,R19
.dbline 78
; conversion(temp); //转换出显示需要的数据
ldd R16,y+1
ldd R17,y+2
ldd R18,y+3
ldd R19,y+4
xcall fpint
xcall _conversion
.dbline 79
; LCD_write_char(0,1,'y'); //第0行,第0列 显示X
ldi R24,121
std y+0,R24
ldi R18,1
clr R16
xcall _LCD_write_char
.dbline 80
; LCD_write_char(1,1,':');
ldi R24,58
std y+0,R24
ldi R18,1
ldi R16,1
xcall _LCD_write_char
.dbline 81
; LCD_write_char(3,1,display[0]);
lds R2,_display
std y+0,R2
ldi R18,1
ldi R16,3
xcall _LCD_write_char
.dbline 82
; LCD_write_char(4,1,'.');
ldi R24,46
std y+0,R24
ldi R18,1
ldi R16,4
xcall _LCD_write_char
.dbline 83
; LCD_write_char(5,1,display[1]);
lds R2,_display+1
std y+0,R2
ldi R18,1
ldi R16,5
xcall _LCD_write_char
.dbline 84
; LCD_write_char(6,1,display[2]);
lds R2,_display+2
std y+0,R2
ldi R18,1
ldi R16,6
xcall _LCD_write_char
.dbline 85
; LCD_write_char(7,1,'g');
ldi R24,103
std y+0,R24
ldi R18,1
ldi R16,7
xcall _LCD_write_char
.dbline -2
L90:
.dbline 0 ; func end
adiw R28,5
ld R21,y+
ld R20,y+
ret
.dbsym l temp 1 D
.dbsym r y 20 I
.dbend
.dbfunc e display_z _display_z fV
; temp -> y+1
; z -> R20,R21
.even
_display_z::
st -y,R20
st -y,R21
sbiw R28,5
.dbline -1
.dbline 91
; }
;
; //*******************************
; //显示z
; void display_z(void)
; { float temp;
.dbline 94
; int z;
;
; z=I2C_Read(0x37);
ldi R16,55
ldi R17,0
xcall _I2C_Read
mov R20,R16
clr R21
.dbline 95
; z=(z<<8)+I2C_Read(0x36);
ldi R16,54
ldi R17,0
xcall _I2C_Read
mov R21,R20
mov R20,R16
.dbline 97
;
; if(z<0){
cpi R20,0
ldi R30,0
cpc R21,R30
brge L96
X27:
.dbline 97
.dbline 98
; z=-z;
com R20
com R21
subi R20,0xFF
sbci R21,0xFF
.dbline 99
; LCD_write_char(10,1,'-'); //显示负符号位
ldi R24,45
std y+0,R24
ldi R18,1
ldi R16,10
xcall _LCD_write_char
.dbline 100
; }
xjmp L97
L96:
.dbline 102
; else
; LCD_write_char(10,1,' '); //显示空格
ldi R24,32
std y+0,R24
ldi R18,1
ldi R16,10
xcall _LCD_write_char
L97:
.dbline 103
; temp=(float)z*3.9; //计算数据和显示,查考ADXL345快速入门第4页
ldi R16,<L87
ldi R17,>L87
xcall elpm32
movw R2,R16
movw R4,R18
movw R16,R20
xcall int2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
movw R16,R2
movw R18,R4
xcall fpmule2
std y+1,R16
std y+2,R17
std y+3,R18
std y+4,R19
.dbline 104
; conversion(temp); //转换出显示需要的数据
ldd R16,y+1
ldd R17,y+2
ldd R18,y+3
ldd R19,y+4
xcall fpint
xcall _conversion
.dbline 105
; LCD_write_char(10,0,'z'); //第0行,第0列 显示X
ldi R24,122
std y+0,R24
clr R18
ldi R16,10
xcall _LCD_write_char
.dbline 106
; LCD_write_char(11,0,':');
ldi R24,58
std y+0,R24
clr R18
ldi R16,11
xcall _LCD_write_char
.dbline 107
; LCD_write_char(11,1,display[0]);
lds R2,_display
std y+0,R2
ldi R18,1
ldi R16,11
xcall _LCD_write_char
.dbline 108
; LCD_write_char(12,1,'.');
ldi R24,46
std y+0,R24
ldi R18,1
ldi R16,12
xcall _LCD_write_char
.dbline 109
; LCD_write_char(13,1,display[1]);
lds R2,_display+1
std y+0,R2
ldi R18,1
ldi R16,13
xcall _LCD_write_char
.dbline 110
; LCD_write_char(14,1,display[2]);
lds R2,_display+2
std y+0,R2
ldi R18,1
ldi R16,14
xcall _LCD_write_char
.dbline 111
; LCD_write_char(15,1,'g');
ldi R24,103
std y+0,R24
ldi R18,1
ldi R16,15
xcall _LCD_write_char
.dbline -2
L95:
.dbline 0 ; func end
adiw R28,5
ld R21,y+
ld R20,y+
ret
.dbsym l temp 1 D
.dbsym r z 20 I
.dbend
.dbfunc e ADXL345_init _ADXL345_init fV
.even
_ADXL345_init::
.dbline -1
.dbline 117
;
; }
;
; //***********************************************
; void ADXL345_init(void) //adxl345初始化
; {
.dbline 118
; I2C_Write(0x31,0x0B); //测量范围,正负16g,13位模式
ldi R18,11
ldi R16,49
xcall _I2C_Write
.dbline 119
; I2C_Write(0x2C,0x08); //速率设定为12.5 参考pdf13页
ldi R18,8
ldi R16,44
xcall _I2C_Write
.dbline 120
; I2C_Write(0x2D,0x08); //选择电源模式 参考pdf24页
ldi R18,8
ldi R16,45
xcall _I2C_Write
.dbline 121
; I2C_Write(0x2E,0x80); //使能 DATA_READY 中断
ldi R18,128
ldi R16,46
xcall _I2C_Write
.dbline 122
; I2C_Write(0x1E,0x00); //X 偏移量 根据测试传感器的状态写入pdf29页
clr R18
ldi R16,30
xcall _I2C_Write
.dbline 123
; I2C_Write(0x1F,0x00); //Y 偏移量 根据测试传感器的状态写入pdf29页
clr R18
ldi R16,31
xcall _I2C_Write
.dbline 124
; I2C_Write(0x20,0x05); //Z 偏移量 根据测试传感器的状态写入pdf29页
ldi R18,5
ldi R16,32
xcall _I2C_Write
.dbline -2
L100:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
; i -> <dead>
.even
_main::
.dbline -1
.dbline 131
; }
;
; /*******************************
; 主程序
; *******************************/
; void main(void)
; {
.dbline 134
; unsigned char i;
;
; delay_nms(20); //lcd上电延时
ldi R16,20
ldi R17,0
xcall _delay_nms
.dbline 135
; LCD_init(); //lcd初始化
xcall _LCD_init
.dbline 136
; ADXL345_init();
xcall _ADXL345_init
xjmp L103
L102:
.dbline 138
;
; while(1){ //循环
.dbline 140
;
; display_x(); //显示x
xcall _display_x
.dbline 141
; display_y(); //显示y
xcall _display_y
.dbline 142
; display_z(); //显示z
xcall _display_z
.dbline 144
;
; delay_nms(100);
ldi R16,100
ldi R17,0
xcall _delay_nms
.dbline 145
; }
L103:
.dbline 138
xjmp L102
X28:
.dbline -2
L101:
.dbline 0 ; func end
ret
.dbsym l i 1 c
.dbend
.area lit(rom, con, rel)
L87:
.word 0x999a,0x4079
; }
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -