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

📄 lcd1602.s

📁 环保型IC卡门禁系统的C程序
💻 S
字号:
	.module lcd1602.c
	.area text(rom, con, rel)
	.dbfile D:\PROGRA~1\ICC\Pro(AVR)\环保型IC卡门禁系统\lcd1602.c
	.dbfunc e LCD_init _LCD_init fV
	.even
_LCD_init::
	.dbline -1
	.dbline 7
; //-----------------------------LCD1602 Function---------------------------------
; #include <iom8v.h>
; #include <macros.h>
; #include "lcd1602.h"
; 
; void LCD_init(void)       //液晶初始化
; {
	.dbline 8
;  delay_nms(2);
	ldi R16,2
	ldi R17,0
	rcall _delay_nms
	.dbline 10
;  
;  LCD_write_char(0x28,0);  //4位显示
	clr R18
	clr R19
	ldi R16,40
	ldi R17,0
	rcall _LCD_write_char
	.dbline 11
;  LCD_write_char(0x0c,0);  //显示开
	clr R18
	clr R19
	ldi R16,12
	ldi R17,0
	rcall _LCD_write_char
	.dbline 12
;  LCD_write_char(0x01,0);  //清屏
	clr R18
	clr R19
	ldi R16,1
	ldi R17,0
	rcall _LCD_write_char
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LCD_write_string _LCD_write_string fV
;              s -> R20,R21
;              Y -> R10
;              X -> R22
	.even
_LCD_write_string::
	rcall push_gset3
	mov R10,R18
	mov R22,R16
	ldd R20,y+6
	ldd R21,y+7
	.dbline -1
	.dbline 16
; }
; 
; void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
; {
	.dbline 17
;   LCD_set_xy( X, Y ); //写地址
	mov R18,R10
	mov R16,R22
	rcall _LCD_set_xy
	rjmp L4
L3:
	.dbline 20
	.dbline 21
	movw R30,R20
	ldd R18,z+0
	clr R19
	clr R16
	clr R17
	rcall _LCD_write_char
	.dbline 22
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 23
L4:
	.dbline 19
;     
;   while (*s)  // 写显示字符
	movw R30,R20
	ldd R2,z+0
	tst R2
	brne L3
	.dbline -2
L2:
	rcall 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_set_xy _LCD_set_xy fV
;        address -> R20
;              y -> R20
;              x -> R22
	.even
_LCD_set_xy::
	rcall push_gset2
	mov R20,R18
	mov R22,R16
	.dbline -1
	.dbline 27
;   {
;     LCD_write_char( 0, *s );
;     s ++;
;   }
; }
; 
; void LCD_set_xy( unsigned char x, unsigned char y )  //写地址函数
; {
	.dbline 30
;   unsigned char address;
;   
;   if (y == 0) 
	tst R20
	brne L7
	.dbline 31
;     address = 0x80 + x;
	mov R20,R22
	subi R20,128    ; addi 128
	rjmp L8
L7:
	.dbline 33
;   else 
;     address = 0xc0 + x;
	mov R20,R22
	subi R20,64    ; addi 192
L8:
	.dbline 34
;     LCD_write_char( address, 0 );
	clr R18
	clr R19
	mov R16,R20
	clr R17
	rcall _LCD_write_char
	.dbline -2
L6:
	rcall 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_en_write _LCD_en_write fV
	.even
_LCD_en_write::
	.dbline -1
	.dbline 38
; }
; 
; void LCD_en_write(void)  //液晶使能
; {
	.dbline 39
;   LCD_EN_PORT|=LCD_EN;
	sbi 0x15,4
	.dbline 40
;   delay_nus(1);
	ldi R16,1
	ldi R17,0
	rcall _delay_nus
	.dbline 41
;   LCD_EN_PORT&=~LCD_EN;
	cbi 0x15,4
	.dbline -2
L9:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LCD_write_char _LCD_write_char fV
;      data_temp -> R22,R23
;   command_temp -> R20,R21
;           data -> R12,R13
;        command -> R10,R11
	.even
_LCD_write_char::
	rcall push_gset4
	movw R12,R18
	movw R10,R16
	.dbline -1
	.dbline 45
; }
; 
; void LCD_write_char(unsigned command,unsigned data) // 写数据
; {
	.dbline 48
;  unsigned command_temp,data_temp;
;  
;  command_temp=command;
	movw R20,R10
	.dbline 49
;  data_temp=data;
	movw R22,R12
	.dbline 50
;  delay_nus(16);
	ldi R16,16
	ldi R17,0
	rcall _delay_nus
	.dbline 52
;  
;  if(command==0)
	cpi R20,0
	cpc R20,R21
	brne L11
X0:
	.dbline 53
;  {
	.dbline 54
;   LCD_RS_PORT|=LCD_RS;  //RS=1
	sbi 0x15,5
	.dbline 55
;   LCD_DATA_PORT&=0Xf0;
	in R24,0x15
	andi R24,240
	out 0x15,R24
	.dbline 56
;   LCD_DATA_PORT|=((data_temp&0xf0)>>4);  //写高四位
	movw R24,R22
	andi R24,240
	andi R25,0
	lsr R25
	ror R24
	lsr R25
	ror R24
	lsr R25
	ror R24
	lsr R25
	ror R24
	in R2,0x15
	clr R3
	or R2,R24
	or R3,R25
	out 0x15,R2
	.dbline 57
;   LCD_en_write(); 
	rcall _LCD_en_write
	.dbline 58
;   LCD_DATA_PORT&=0Xf0;
	in R24,0x15
	andi R24,240
	out 0x15,R24
	.dbline 59
;   LCD_DATA_PORT|=data_temp&0x0f;   //写低四位
	movw R24,R22
	andi R24,15
	andi R25,0
	in R2,0x15
	clr R3
	or R2,R24
	or R3,R25
	out 0x15,R2
	.dbline 60
;   LCD_en_write();
	rcall _LCD_en_write
	.dbline 61
;  }
	rjmp L12
L11:
	.dbline 63
	.dbline 64
	cbi 0x15,5
	.dbline 65
	in R24,0x15
	andi R24,240
	out 0x15,R24
	.dbline 66
	movw R24,R20
	andi R24,240
	andi R25,0
	lsr R25
	ror R24
	lsr R25
	ror R24
	lsr R25
	ror R24
	lsr R25
	ror R24
	in R2,0x15
	clr R3
	or R2,R24
	or R3,R25
	out 0x15,R2
	.dbline 67
	rcall _LCD_en_write
	.dbline 68
	in R24,0x15
	andi R24,240
	out 0x15,R24
	.dbline 69
	movw R24,R20
	andi R24,15
	andi R25,0
	in R2,0x15
	clr R3
	or R2,R24
	or R3,R25
	out 0x15,R2
	.dbline 70
	rcall _LCD_en_write
	.dbline 71
L12:
	.dbline -2
L10:
	rcall pop_gset4
	.dbline 0 ; func end
	ret
	.dbsym r data_temp 22 i
	.dbsym r command_temp 20 i
	.dbsym r data 12 i
	.dbsym r command 10 i
	.dbend

⌨️ 快捷键说明

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