📄 avr_gy-29.s
字号:
cpi R24,88
breq L67
X22:
.dbline 104
; return 1; //ACK
ldi R16,1
xjmp L38
L67:
.dbline 106
;
; temp=TWDR;//读取I2C接收数据
in R10,0x3
.dbline 107
; Stop();//I2C停止
ldi R24,148
out 0x36,R24
.dbline 108
; return temp;
mov R16,R10
.dbline -2
L38:
.dbline 0 ; func end
ld R10,y+
ret
.dbsym r temp 10 c
.dbsym r RegAddress 16 i
.dbend
.dbfile D:\MCU_Project\MCU_AVR\AVR_GY-29\1602.h
.dbfunc e LCD_init _LCD_init fV
.even
_LCD_init::
.dbline -1
.dbline 44
; /* 用法:
; LCD_init();
; LCD_write_string(列,行,"字符串");
; LCD_write_char(列,行,'字符');
; ---------------------------------------------------------------
; 下面是AVR与LCD连接信息
; PC6 ->RS
; PC7 ->EN
; 地 ->RW
; PA4 ->D4
; PA5 ->D5
; PA6 ->D6
; PA7 ->D7
; 使用端口:1602:PC6,PC7,PA4~PA7
; 要使用本驱动,改变下面配置信息即可
; -----------------------------------------------------------------*/
; #define LCD_EN_PORT PORTC //以下2个要设为同一个口
; #define LCD_EN_DDR DDRC
; #define LCD_RS_PORT PORTC //以下2个要设为同一个口
; #define LCD_RS_DDR DDRC
; #define LCD_DATA_PORT PORTA //以下3个要设为同一个口
; #define LCD_DATA_DDR DDRA //默认情况下连线必须使用高四位端口,如果不是请注意修改
; #define LCD_DATA_PIN PINA
; #define LCD_RS (1<<PC6) //0x20 portC6 out
; #define LCD_EN (1<<PC7) //0x40 portC7 out
; #define LCD_DATA ((1<<PA4)|(1<<PA5)|(1<<PA6)|(1<<PA7)) //0xf0 portA 4/5/6/7 out
; /*--------------------------------------------------------------------------------------------------
; 函数说明
; --------------------------------------------------------------------------------------------------*/
; void LCD_init(void);
; void LCD_en_write(void);
; void LCD_write_command(unsigned char command) ;
; void LCD_write_data(unsigned char data);
; void LCD_set_xy (unsigned char x, unsigned char y);
; void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);
; void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data);
;
; //-----------------------------------------------------------------------------------------
;
; #include <macros.h>
; #include "delay.h"
;
; void LCD_init(void) //液晶初始化
; {
.dbline 45
; LCD_DATA_DDR|=LCD_DATA; //数据口方向为输出
in R24,0x1a
ori R24,240
out 0x1a,R24
.dbline 46
; LCD_EN_DDR|=LCD_EN; //设置EN方向为输出
sbi 0x14,7
.dbline 47
; LCD_RS_DDR|=LCD_RS; //设置RS方向为输出
sbi 0x14,6
.dbline 48
; LCD_write_command(0x28);
ldi R16,40
xcall _LCD_write_command
.dbline 49
; LCD_en_write();
xcall _LCD_en_write
.dbline 50
; delay_nus(40);
ldi R16,40
ldi R17,0
xcall _delay_nus
.dbline 51
; LCD_write_command(0x28); //4位显示
ldi R16,40
xcall _LCD_write_command
.dbline 52
; LCD_write_command(0x0c); //显示开
ldi R16,12
xcall _LCD_write_command
.dbline 53
; LCD_write_command(0x01); //清屏
ldi R16,1
xcall _LCD_write_command
.dbline 54
; delay_nms(10);
ldi R16,10
ldi R17,0
xcall _delay_nms
.dbline -2
L69:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_en_write _LCD_en_write fV
.even
_LCD_en_write::
.dbline -1
.dbline 58
; }
;
; void LCD_en_write(void) //液晶使能
; {
.dbline 59
; LCD_EN_PORT|=LCD_EN;
sbi 0x15,7
.dbline 60
; delay_nus(1);
ldi R16,1
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-29\1602.h
_display::
.blkb 2
.area idata
.byte 0,0
.area data(ram, con, rel)
.dbfile D:\MCU_Project\MCU_AVR\AVR_GY-29\1602.h
.blkb 2
.area idata
.byte 0,'g
.area data(ram, con, rel)
.dbfile D:\MCU_Project\MCU_AVR\AVR_GY-29\1602.h
.dbfile D:\MCU_Project\MCU_AVR\AVR_GY-29\AVR_GY-29.c
.dbsym e display _display A[4:4]c
.area text(rom, con, rel)
.dbfile D:\MCU_Project\MCU_AVR\AVR_GY-29\AVR_GY-29.c
.dbfunc e conversion _conversion fV
; i -> R10,R11
.even
_conversion::
st -y,R10
st -y,R11
movw R10,R16
.dbline -1
.dbline 26
; /*****************************************
; * 基于AVR单片机GY-29模块通信程序 *
; * 功 能: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"
; void conversion(unsigned int i);
; void ADXL345_init(void);
; unsigned char display[4]={0,0,0,'g'};//显示数据
;
; /*********************************************
; 数据转换,十六进制数据转换成10进制
; 输入十六进制范围:0x0000-0x270f(0-9999)
; 结果分成个十百千位,以ascii存入显示区
; **********************************************/
; void conversion(unsigned int i)
; {
.dbline 29
; // display[0]=i/10000+0x30 ;
; // i=i%10000; //取余运算
; display[0]=i/1000+0x30 ;
ldi R18,1000
ldi R19,3
movw R16,R10
xcall div16u
movw R24,R16
adiw R24,48
sts _display,R24
.dbline 30
; i=i%1000; //取余运算
ldi R18,1000
ldi R19,3
movw R16,R10
xcall mod16u
movw R10,R16
.dbline 31
; display[1]=i/100+0x30 ;
ldi R18,100
ldi R19,0
xcall div16u
movw R24,R16
adiw R24,48
sts _display+1,R24
.dbline 32
; i=i%100; //取余运算
ldi R18,100
ldi R19,0
movw R16,R10
xcall mod16u
movw R10,R16
.dbline 33
; display[2]=i/10+0x30 ;
ldi R18,10
ldi R19,0
xcall div16u
movw R24,R16
adiw R24,48
sts _display+2,R24
.dbline -2
L81:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
.dbsym r i 10 i
.dbend
.dbfunc e display_x _display_x fV
; temp -> y+1
; x -> R20,R21
.even
_display_x::
st -y,R20
st -y,R21
sbiw R28,5
.dbline -1
.dbline 40
; // i=i%10; //取余运算
; // display[3]=i+0x30;
; }
; //*******************************
; //显示x
; void display_x(void)
; { float temp;
.dbline 43
; int x;
;
; x=I2C_Read(0x33);
ldi R16,51
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -