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

📄 lcd_init.s

📁 avr单片机的定时计数器的使用。包括各种延时子程序的调用。内有电路图。
💻 S
字号:
	.module LCD_init.c
	.area text(rom, con, rel)
	.dbfile D:\+++资料+++\学习\avr\+++精华+++\定时器\LCD_init.c
	.dbfunc e LCD_init _LCD_init fV
	.even
_LCD_init::
	.dbline -1
	.dbline 10
; /*----------------------------------------------------
; 液晶LCD1602C  使用4条数据线(D4~D7)
; 编译器:ICC-AVR v6.31A 
; 目标芯片 : M16
; 时钟: 8.0000Mhz
; ---------------------------------------------------*/
; #include "LCD.h"
; 
; void LCD_init(void)         //液晶初始化
; {
	.dbline 11
;   LCD_DATA_DDR|=LCD_DATA;   //数据口方向为输出
	in R24,0x1a
	ori R24,240
	out 0x1a,R24
	.dbline 12
;   LCD_EN_DDR|=LCD_EN;       //设置EN方向为输出
	sbi 0x14,7
	.dbline 13
;   LCD_RS_DDR|=LCD_RS;       //设置RS方向为输出
	sbi 0x14,6
	.dbline 14
;   LCD_write_command(0x28); 
	ldi R16,40
	xcall _LCD_write_command
	.dbline 15
;   LCD_en_write();
	xcall _LCD_en_write
	.dbline 16
;   delay_nus(40);
	ldi R16,40
	ldi R17,0
	xcall _delay_nus
	.dbline 17
;   LCD_write_command(0x28);  //4位显示
	ldi R16,40
	xcall _LCD_write_command
	.dbline 18
;   LCD_write_command(0x0c);  //显示开
	ldi R16,12
	xcall _LCD_write_command
	.dbline 19
;   LCD_write_command(0x01);  //清屏
	ldi R16,1
	xcall _LCD_write_command
	.dbline 20
;   delay_nms(2);
	ldi R16,2
	ldi R17,0
	xcall _delay_nms
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LCD_en_write _LCD_en_write fV
	.even
_LCD_en_write::
	.dbline -1
	.dbline 24
; }
; 
; void LCD_en_write(void)  //液晶使能
; {
	.dbline 25
;   LCD_EN_PORT|=LCD_EN;
	sbi 0x15,7
	.dbline 26
;   delay_nus(1);
	ldi R16,1
	ldi R17,0
	xcall _delay_nus
	.dbline 27
;   LCD_EN_PORT&=~LCD_EN;
	cbi 0x15,7
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LCD_write_command _LCD_write_command fV
;        command -> R20
	.even
_LCD_write_command::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 31
; }
; 
; void LCD_write_command(unsigned char command) //写指令
; {
	.dbline 32
;   delay_nus(16);
	ldi R16,16
	ldi R17,0
	xcall _delay_nus
	.dbline 33
;   LCD_RS_PORT&=~LCD_RS;        //RS=0
	cbi 0x15,6
	.dbline 34
;   LCD_DATA_PORT&=0X0f;         //清高四位
	in R24,0x1b
	andi R24,15
	out 0x1b,R24
	.dbline 35
;   LCD_DATA_PORT|=command&0xf0; //写高四位
	mov R24,R20
	andi R24,240
	in R2,0x1b
	or R2,R24
	out 0x1b,R2
	.dbline 36
;   LCD_en_write();
	xcall _LCD_en_write
	.dbline 37
;   command=command<<4;          //低四位移到高四位
	mov R24,R20
	andi R24,#0x0F
	swap R24
	mov R20,R24
	.dbline 38
;   LCD_DATA_PORT&=0x0f;         //清高四位
	in R24,0x1b
	andi R24,15
	out 0x1b,R24
	.dbline 39
;   LCD_DATA_PORT|=command&0xf0; //写低四位
	mov R24,R20
	andi R24,240
	in R2,0x1b
	or R2,R24
	out 0x1b,R2
	.dbline 40
;   LCD_en_write();
	xcall _LCD_en_write
	.dbline -2
L3:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r command 20 c
	.dbend
	.dbfunc e LCD_write_data _LCD_write_data fV
;           data -> R20
	.even
_LCD_write_data::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 45
;   
; }
; 
; void LCD_write_data(unsigned char data) //写数据
; {
	.dbline 46
;   delay_nus(16);
	ldi R16,16
	ldi R17,0
	xcall _delay_nus
	.dbline 47
;   LCD_RS_PORT|=LCD_RS;       //RS=1
	sbi 0x15,6
	.dbline 48
;   LCD_DATA_PORT&=0X0f;       //清高四位
	in R24,0x1b
	andi R24,15
	out 0x1b,R24
	.dbline 49
;   LCD_DATA_PORT|=data&0xf0;  //写高四位
	mov R24,R20
	andi R24,240
	in R2,0x1b
	or R2,R24
	out 0x1b,R2
	.dbline 50
;   LCD_en_write();
	xcall _LCD_en_write
	.dbline 51
;   data=data<<4;               //低四位移到高四位
	mov R24,R20
	andi R24,#0x0F
	swap R24
	mov R20,R24
	.dbline 52
;   LCD_DATA_PORT&=0X0f;        //清高四位
	in R24,0x1b
	andi R24,15
	out 0x1b,R24
	.dbline 53
;   LCD_DATA_PORT|=data&0xf0;   //写低四位
	mov R24,R20
	andi R24,240
	in R2,0x1b
	or R2,R24
	out 0x1b,R2
	.dbline 54
;   LCD_en_write();
	xcall _LCD_en_write
	.dbline -2
L4:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r data 20 c
	.dbend
	.dbfunc e LCD_set_xy _LCD_set_xy fV
;        address -> R20
;              y -> R20
;              x -> R22
	.even
_LCD_set_xy::
	xcall push_gset2
	mov R20,R18
	mov R22,R16
	.dbline -1
	.dbline 59
; }
; 
; 
; void LCD_set_xy( unsigned char x, unsigned char y )  //写地址函数
; {
	.dbline 61
;     unsigned char address;
;     if (y == 0) address = 0x80 + x;
	tst R20
	brne L6
	.dbline 61
	mov R20,R22
	subi R20,128    ; addi 128
	xjmp L7
L6:
	.dbline 62
;     else   address = 0xc0 + x;
	mov R20,R22
	subi R20,64    ; addi 192
L7:
	.dbline 63
;     LCD_write_command( address);
	mov R16,R20
	xcall _LCD_write_command
	.dbline -2
L5:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r address 20 c
	.dbsym r y 20 c
	.dbsym r x 22 c
	.dbend
	.dbfunc e LCD_write_string _LCD_write_string fV
;              s -> R20,R21
;              Y -> R10
;              X -> R22
	.even
_LCD_write_string::
	xcall push_gset3
	mov R10,R18
	mov R22,R16
	ldd R20,y+6
	ldd R21,y+7
	.dbline -1
	.dbline 67
; }
;   
; void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s) //列x=0~15,行y=0,1
; {
	.dbline 68
;     LCD_set_xy( X, Y ); //写地址    
	mov R18,R10
	mov R16,R22
	xcall _LCD_set_xy
	xjmp L10
L9:
	.dbline 70
	.dbline 71
	movw R30,R20
	ldd R16,z+0
	xcall _LCD_write_data
	.dbline 72
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 73
L10:
	.dbline 69
;     while (*s)  // 写显示字符
	movw R30,R20
	ldd R2,z+0
	tst R2
	brne L9
	.dbline -2
L8:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r s 20 pc
	.dbsym r Y 10 c
	.dbsym r X 22 c
	.dbend
	.dbfunc e LCD_write_char _LCD_write_char fV
;           data -> y+4
;              Y -> R22
;              X -> R20
	.even
_LCD_write_char::
	xcall push_gset2
	mov R22,R18
	mov R20,R16
	.dbline -1
	.dbline 78
;     {
;       LCD_write_data( *s );
;       s ++;
;     }
;       
; }
; 
; void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data) //列x=0~15,行y=0,1
; {
	.dbline 79
;   LCD_set_xy( X, Y ); //写地址
	mov R18,R22
	mov R16,R20
	xcall _LCD_set_xy
	.dbline 80
;   LCD_write_data( data);
	ldd R16,y+4
	xcall _LCD_write_data
	.dbline -2
L12:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l data 4 c
	.dbsym r Y 22 c
	.dbsym r X 20 c
	.dbend

⌨️ 快捷键说明

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