⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 avr_gy-27.s

📁 GY-27资料源码 ADXL345 HMC5883L
💻 S
📖 第 1 页 / 共 2 页
字号:
	ldi R17,0
	xcall _delay_nus
	.dbline 61
;   LCD_EN_PORT&=~LCD_EN;
	cbi 0x15,7
	.dbline -2
L70:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LCD_write_command _LCD_write_command fV
;        command -> R20
	.even
_LCD_write_command::
	st -y,R20
	mov R20,R16
	.dbline -1
	.dbline 65
; }
; 
; void LCD_write_command(unsigned char command) //写指令
; {
	.dbline 67
;   //连线为高4位的写法
;   delay_nus(16);
	ldi R16,16
	ldi R17,0
	xcall _delay_nus
	.dbline 68
;   LCD_RS_PORT&=~LCD_RS;        //RS=0
	cbi 0x15,6
	.dbline 69
;   LCD_DATA_PORT&=0X0f;         //清高四位
	in R24,0x1b
	andi R24,15
	out 0x1b,R24
	.dbline 70
;   LCD_DATA_PORT|=command&0xf0; //写高四位
	mov R24,R20
	andi R24,240
	in R2,0x1b
	or R2,R24
	out 0x1b,R2
	.dbline 71
;   LCD_en_write();
	xcall _LCD_en_write
	.dbline 72
;   command=command<<4;          //低四位移到高四位
	mov R24,R20
	andi R24,#0x0F
	swap R24
	mov R20,R24
	.dbline 73
;   LCD_DATA_PORT&=0x0f;         //清高四位
	in R24,0x1b
	andi R24,15
	out 0x1b,R24
	.dbline 74
;   LCD_DATA_PORT|=command&0xf0; //写低四位
	mov R24,R20
	andi R24,240
	in R2,0x1b
	or R2,R24
	out 0x1b,R2
	.dbline 75
;   LCD_en_write();
	xcall _LCD_en_write
	.dbline -2
L71:
	.dbline 0 ; func end
	ld R20,y+
	ret
	.dbsym r command 20 c
	.dbend
	.dbfunc e LCD_write_data _LCD_write_data fV
;           data -> R20
	.even
_LCD_write_data::
	st -y,R20
	mov R20,R16
	.dbline -1
	.dbline 92
;  
; /*
;   //连线为低四位的写法
;   delay_nus(16);
;   LCD_RS_PORT&=~LCD_RS;        //RS=0
;   LCD_DATA_PORT&=0xf0;         //清高四位
;   LCD_DATA_PORT|=(command>>4)&0x0f; //写高四位
;   LCD_en_write();
;   LCD_DATA_PORT&=0xf0;         //清高四位
;   LCD_DATA_PORT|=command&0x0f; //写低四位
;   LCD_en_write(); 
; */
;   
; }
; 
; void LCD_write_data(unsigned char data) //写数据
; {
	.dbline 94
;   //连线为高4位的写法
;   delay_nus(16);
	ldi R16,16
	ldi R17,0
	xcall _delay_nus
	.dbline 95
;   LCD_RS_PORT|=LCD_RS;       //RS=1
	sbi 0x15,6
	.dbline 96
;   LCD_DATA_PORT&=0X0f;       //清高四位
	in R24,0x1b
	andi R24,15
	out 0x1b,R24
	.dbline 97
;   LCD_DATA_PORT|=data&0xf0;  //写高四位
	mov R24,R20
	andi R24,240
	in R2,0x1b
	or R2,R24
	out 0x1b,R2
	.dbline 98
;   LCD_en_write();
	xcall _LCD_en_write
	.dbline 99
;   data=data<<4;               //低四位移到高四位
	mov R24,R20
	andi R24,#0x0F
	swap R24
	mov R20,R24
	.dbline 100
;   LCD_DATA_PORT&=0X0f;        //清高四位
	in R24,0x1b
	andi R24,15
	out 0x1b,R24
	.dbline 101
;   LCD_DATA_PORT|=data&0xf0;   //写低四位
	mov R24,R20
	andi R24,240
	in R2,0x1b
	or R2,R24
	out 0x1b,R2
	.dbline 102
;   LCD_en_write();
	xcall _LCD_en_write
	.dbline -2
L72:
	.dbline 0 ; func end
	ld R20,y+
	ret
	.dbsym r data 20 c
	.dbend
	.dbfunc e LCD_set_xy _LCD_set_xy fV
;        address -> R20
;              y -> R10
;              x -> R22
	.even
_LCD_set_xy::
	xcall push_xgsetF00C
	mov R10,R18
	mov R22,R16
	.dbline -1
	.dbline 121
;   
; /*
;   //连线为低四位的写法 
;   delay_nus(16);
;   LCD_RS_PORT|=LCD_RS;       //RS=1
;   LCD_DATA_PORT&=0Xf0;       //清高四位
;   LCD_DATA_PORT|=(data>>4)&0x0f;  //写高四位
;   LCD_en_write();
;  
;   LCD_DATA_PORT&=0Xf0;        //清高四位
;   LCD_DATA_PORT|=data&0x0f;   //写低四位
;   LCD_en_write();
; */
;   
; }
; 
; 
; void LCD_set_xy( unsigned char x, unsigned char y )  //写地址函数
; {
	.dbline 123
;     unsigned char address;
;     if (y == 0) address = 0x80 + x;
	tst R10
	brne L74
X23:
	.dbline 123
	mov R20,R22
	subi R20,128    ; addi 128
	xjmp L75
L74:
	.dbline 124
;     else   address = 0xc0 + x;
	mov R20,R22
	subi R20,64    ; addi 192
L75:
	.dbline 125
;     LCD_write_command( address);
	mov R16,R20
	xcall _LCD_write_command
	.dbline -2
L73:
	.dbline 0 ; func end
	xjmp pop_xgsetF00C
	.dbsym r address 20 c
	.dbsym r y 10 c
	.dbsym r x 22 c
	.dbend
	.dbfunc e LCD_write_string _LCD_write_string fV
;              s -> R20,R21
;              Y -> R12
;              X -> R10
	.even
_LCD_write_string::
	xcall push_xgset303C
	mov R12,R18
	mov R10,R16
	ldd R20,y+6
	ldd R21,y+7
	.dbline -1
	.dbline 129
; }
;   
; void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s) //列x=0~15,行y=0,1
; {
	.dbline 130
;     LCD_set_xy( X, Y ); //写地址    
	mov R18,R12
	mov R16,R10
	xcall _LCD_set_xy
	xjmp L78
L77:
	.dbline 132
;     while (*s)  // 写显示字符
;     {
	.dbline 133
;       LCD_write_data( *s );
	movw R30,R20
	ldd R16,z+0
	xcall _LCD_write_data
	.dbline 134
;       s ++;
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 135
;     }
L78:
	.dbline 131
	movw R30,R20
	ldd R2,z+0
	tst R2
	brne L77
X24:
	.dbline -2
L76:
	.dbline 0 ; func end
	xjmp pop_xgset303C
	.dbsym r s 20 pc
	.dbsym r Y 12 c
	.dbsym r X 10 c
	.dbend
	.dbfunc e LCD_write_char _LCD_write_char fV
;           data -> y+2
;              Y -> R12
;              X -> R10
	.even
_LCD_write_char::
	st -y,R10
	st -y,R12
	mov R12,R18
	mov R10,R16
	.dbline -1
	.dbline 140
;       
; }
; 
; void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data) //列x=0~15,行y=0,1
; {
	.dbline 141
;   LCD_set_xy( X, Y ); //写地址
	mov R18,R12
	mov R16,R10
	xcall _LCD_set_xy
	.dbline 142
;   LCD_write_data( data);
	ldd R16,y+2
	xcall _LCD_write_data
	.dbline -2
L80:
	.dbline 0 ; func end
	ld R12,y+
	ld R10,y+
	ret
	.dbsym l data 2 c
	.dbsym r Y 12 c
	.dbsym r X 10 c
	.dbend
	.area data(ram, con, rel)
	.dbfile D:\MCU_Project\MCU_AVR\AVR_GY-27\1602.h
_display::
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.dbfile D:\MCU_Project\MCU_AVR\AVR_GY-27\1602.h
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.dbfile D:\MCU_Project\MCU_AVR\AVR_GY-27\1602.h
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\MCU_Project\MCU_AVR\AVR_GY-27\1602.h
	.dbfile D:\MCU_Project\MCU_AVR\AVR_GY-27\AVR_GY-27.c
	.dbsym e display _display A[5:5]c
	.area text(rom, con, rel)
	.dbfile D:\MCU_Project\MCU_AVR\AVR_GY-27\AVR_GY-27.c
	.dbfunc e conversion _conversion fV
;              i -> R20,R21
	.even
_conversion::
	st -y,R20
	st -y,R21
	movw R20,R16
	.dbline -1
	.dbline 28
; /*****************************************
; * 基于AVR单片机GY-27模块通信程序 		 *
; * HMC5883L+ADXL345 通信程序              *
; * 功    能:IIC通信读取数据并显示        *
; * 时钟频率:内部1M 						 *
; * 设    计:广运电子					 *
; * 修改日期:2011年4月20日				 *
; * 编译环境:ICC-AVR7.14					 *
; * 实验环境:ATmega16+1602    			 *
; * 使用端口:PC0,PC1,PC6,PC7,PA4~PA7 	 *
; * 参    考:莫锦攀实验程序24c02读取实验  *
; *****************************************/
; #include <iom16v.h>
; #include "I2C.h"
; #include "1602.h"
; #include "delay.h"
; #include  "math.h"  
; #include  "stdio.h"  
; void conversion(unsigned int i);
; unsigned char display[5]={0,0,0,0,0};//显示数据
; 
; /*********************************************
; 数据转换,十六进制数据转换成10进制
; 输入十六进制范围:0x0000-0x270f(0-9999)
; 结果分成个十百千位,以ascii存入显示区
; **********************************************/
; void conversion(unsigned int i)  
; {  
	.dbline 29
;  	display[0]=i/10000+0x30 ;
	ldi R18,10000
	ldi R19,39
	movw R16,R20
	xcall div16u
	movw R24,R16
	adiw R24,48
	sts _display,R24
	.dbline 30
;     i=i%10000;    //取余运算
	ldi R18,10000
	ldi R19,39
	movw R16,R20
	xcall mod16u
	movw R20,R16
	.dbline 31
; 	display[1]=i/1000+0x30 ;
	ldi R18,1000
	ldi R19,3
	xcall div16u
	movw R24,R16
	adiw R24,48
	sts _display+1,R24
	.dbline 32
;     i=i%1000;    //取余运算
	ldi R18,1000
	ldi R19,3
	movw R16,R20
	xcall mod16u
	movw R20,R16
	.dbline 33
;     display[2]=i/100+0x30 ;
	ldi R18,100
	ldi R19,0
	xcall div16u
	movw R24,R16
	adiw R24,48
	sts _display+2,R24
	.dbline 34
;     i=i%100;    //取余运算
	ldi R18,100
	ldi R19,0
	movw R16,R20
	xcall mod16u
	movw R20,R16
	.dbline 35
;     display[3]=i/10+0x30 ;
	ldi R18,10
	ldi R19,0
	xcall div16u
	movw R24,R16
	adiw R24,48
	sts _display+3,R24
	.dbline 36
;    i=i%10;     //取余运算
	ldi R18,10
	ldi R19,0
	movw R16,R20
	xcall mod16u
	movw R20,R16
	.dbline 37
;     display[4]=i+0x30;  
	movw R24,R20
	adiw R24,48
	sts _display+4,R24
	.dbline -2
L81:
	.dbline 0 ; func end
	ld R21,y+
	ld R20,y+
	ret
	.dbsym r i 20 i
	.dbend
	.dbfunc e display_angle _display_angle fV
;           temp -> y+8
;          angle -> y+4
;              y -> R10,R11
;              x -> R12,R13
	.even
_display_angle::
	xcall push_xgset00FC
	sbiw R28,12
	.dbline -1
	.dbline 42
; }
; //*******************************
; //显示角度
; void display_angle(void)
; {   float temp;
	.dbline 46
;       int x,y;
; 	 double angle;
; 
;      x=I2C_Read(0x03);
	ldi R16,3
	ldi R17,0
	xcall _I2C_Read
	mov R12,R16
	clr R13
	.dbline 47
;      x=(x<<8)+I2C_Read(0x04);
	ldi R16,4
	ldi R17,0
	xcall _I2C_Read
	mov R13,R12
	mov R12,R16
	.dbline 49
; 	 
; 	 y=I2C_Read(0x07);
	ldi R16,7
	ldi R17,0
	xcall _I2C_Read
	mov R10,R16
	clr R11
	.dbline 50
;      y=(y<<8)+I2C_Read(0x08);
	ldi R16,8
	ldi R17,0
	xcall _I2C_Read
	mov R14,R16
	mov R11,R10
	mov R10,R14
	.dbline 53
; 	
; 	 
;      angle= atan2((double)y,(double)x) * (180 / 3.14159265) + 180; // angle in degrees
	movw R16,R12
	xcall int2fp
	std y+0,R16
	std y+1,R17
	std y+2,R18
	std y+3,R19
	movw R16,R10
	xcall int2fp
	xcall _atan2f
	movw R2,R16
	movw R4,R18
	ldi R16,<L87
	ldi R17,>L87
	xcall elpm32
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall fpmule2
	movw R2,R16
	movw R4,R18
	ldi R16,<L88
	ldi R17,>L88
	xcall elpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R16,R2
	movw R18,R4
	xcall fpadd2
	std y+4,R16
	std y+5,R17
	std y+6,R18
	std y+7,R19
	.dbline 54
;      angle*=10;
	ldi R16,<L89
	ldi R17,>L89
	xcall elpm32
	movw R24,R28
	adiw R24,4
	st -y,R25
	st -y,R24
	xcall fpmule1
	std y+4,R16
	std y+5,R17
	std y+6,R18
	std y+7,R19
	.dbline 56
; 
;     conversion(angle);          //转换出显示需要的数据
	ldd R16,y+4
	ldd R17,y+5
	ldd R18,y+6
	ldd R19,y+7
	xcall fpint
	xcall _conversion
	.dbline 57
; 	LCD_write_char(0,0,'A');   //第0行,第0列 显示A
	ldi R24,65
	std y+0,R24
	clr R18
	clr R16
	xcall _LCD_write_char
	.dbline 58
; 	LCD_write_char(1,0,'n');   //
	ldi R24,110
	std y+0,R24
	clr R18
	ldi R16,1
	xcall _LCD_write_char
	.dbline 59
; 	LCD_write_char(2,0,'g');   //
	ldi R24,103
	std y+0,R24
	clr R18
	ldi R16,2
	xcall _LCD_write_char
	.dbline 60
; 	LCD_write_char(3,0,'l');   //
	ldi R24,108
	std y+0,R24
	clr R18
	ldi R16,3
	xcall _LCD_write_char
	.dbline 61
; 	LCD_write_char(4,0,'e');   //
	ldi R24,101
	std y+0,R24
	clr R18
	ldi R16,4
	xcall _LCD_write_char
	.dbline 62
;     LCD_write_char(5,0,':'); 
	ldi R24,58
	std y+0,R24
	clr R18
	ldi R16,5
	xcall _LCD_write_char
	.dbline 63
;     LCD_write_char(6,0,display[1]);  
	lds R2,_display+1
	std y+0,R2
	clr R18
	ldi R16,6
	xcall _LCD_write_char
	.dbline 64
;     LCD_write_char(7,0,display[2]); 
	lds R2,_display+2
	std y+0,R2
	clr R18
	ldi R16,7
	xcall _LCD_write_char
	.dbline 65
;     LCD_write_char(8,0,display[3]); 
	lds R2,_display+3
	std y+0,R2
	clr R18
	ldi R16,8
	xcall _LCD_write_char
	.dbline 66
;     LCD_write_char(9,0,'.'); 
	ldi R24,46
	std y+0,R24
	clr R18
	ldi R16,9
	xcall _LCD_write_char
	.dbline 67
; 	LCD_write_char(10,0,display[4]); 
	lds R2,_display+4
	std y+0,R2
	clr R18
	ldi R16,10
	xcall _LCD_write_char
	.dbline 68
; 	LCD_write_char(11,0,0xdf); 
	ldi R24,223
	std y+0,R24
	clr R18
	ldi R16,11
	xcall _LCD_write_char
	.dbline -2
L86:
	.dbline 0 ; func end
	adiw R28,12
	xjmp pop_xgset00FC
	.dbsym l temp 8 D
	.dbsym l angle 4 D
	.dbsym r y 10 I
	.dbsym r x 12 I
	.dbend
	.dbfunc e main _main fV
;              i -> <dead>
	.even
_main::
	.dbline -1
	.dbline 76
; 	
; }
; 
; /*******************************
; 主程序
; *******************************/
; void main(void)
; {	
	.dbline 78
; 	unsigned char i;		
; 	 delay_nms(50);          //lcd上电延时
	ldi R16,50
	ldi R17,0
	xcall _delay_nms
	.dbline 79
; 	 LCD_init();             //lcd初始化
	xcall _LCD_init
	xjmp L96
L95:
	.dbline 81
;      
; 	while(1){               //循环  
	.dbline 82
; 	I2C_Write(0x02,0x00);   //模式寄存器写0
	clr R18
	ldi R16,2
	xcall _I2C_Write
	.dbline 83
; 	delay_nms(50); 
	ldi R16,50
	ldi R17,0
	xcall _delay_nms
	.dbline 84
; 	display_angle();       //显示角度
	xcall _display_angle
	.dbline 85
; 	delay_nms(50); 	
	ldi R16,50
	ldi R17,0
	xcall _delay_nms
	.dbline 86
;     }
L96:
	.dbline 81
	xjmp L95
X25:
	.dbline -2
L94:
	.dbline 0 ; func end
	ret
	.dbsym l i 1 c
	.dbend
	.area lit(rom, con, rel)
L89:
	.word 0x0,0x4120
L88:
	.word 0x0,0x4334
L87:
	.word 0x2ee1,0x4265
; }
; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -