	.module LCD_1602_Driver.c
	.area data(ram, con, rel)
_new::
	.blkb 1
	.area idata
	.byte 32
	.area data(ram, con, rel)
	.dbfile E:\刻录的\电子技术\项目\驱动程序\LCD1602四线接口应用范例\LCD_1602_Driver.c
	.dbsym e new _new c
_num::
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile E:\刻录的\电子技术\项目\驱动程序\LCD1602四线接口应用范例\LCD_1602_Driver.c
	.dbsym e num _num i
	.area text(rom, con, rel)
	.dbfile E:\刻录的\电子技术\项目\驱动程序\LCD1602四线接口应用范例\LCD_1602_Driver.c
	.dbfunc e LCD_init _LCD_init fV
	.even
_LCD_init::
	.dbline -1
	.dbline 21
; #include <iom8v.h>
; #include <macros.h>
; #include "LCD_1602.h"
; void delay_nms(unsigned int n);
; void delay_nus(unsigned int n);
; unsigned char lcd_data[32];//32字节显存,记录LCD上显示的数据
; unsigned char data[32];//32字节缓存,保存将要写入LCD的数据
; unsigned char add;//显存地址标号
; unsigned char new=32;//显存标号 
; unsigned int num=0;
; /**********************************************************
; TC1602B LCD DISPLAY
; 建立时间：2005年12月12号
; 修改日期：2005年12月12号
; LCD_write函数功能：当command＝0时，向LCD写入数据，否则向LCD写
;                    入命令
; LCD第一行显示寄存器地址：0X80-0X8F
; LCD第二行显示寄存器地址：0XC0-0XCF
; **********************************************************/
; void LCD_init(void)
;   { 
	.dbline 22
;      LCD_EN_DDR|=LCD_EN;//设定该引脚方向为输出
	sbi 0x11,6
	.dbline 23
; 	 LCD_RS_DDR|=LCD_RS;//设定该引脚方向为输出
	sbi 0x11,7
	.dbline 24
; 	 LCD_D4_DDR|=LCD_D4;//设定数据口为输出 
	sbi 0x11,5
	.dbline 25
; 	 LCD_D5_DDR|=LCD_D5;//设定数据口为输出  
	sbi 0x11,4
	.dbline 26
; 	 LCD_D6_DDR|=LCD_D6;//设定数据口为输出  
	sbi 0x11,3
	.dbline 27
; 	 LCD_D7_DDR|=LCD_D7;//设定数据口为输出
	sbi 0x11,2
	.dbline 29
; 	 
; 	  LCD_EN_PORT&=~LCD_EN;//EN设为低电平
	cbi 0x12,6
	.dbline 30
; 	  LCD_RS_PORT&=~LCD_RS;//RS设为低电平
	cbi 0x12,7
	.dbline 31
; 	  LCD_D4_PORT&=~LCD_D4;//数据口置低电平
	cbi 0x12,5
	.dbline 32
; 	  LCD_D5_PORT&=~LCD_D5;//数据口置低电平
	cbi 0x12,4
	.dbline 33
; 	  LCD_D6_PORT&=~LCD_D6;//数据口置低电平
	cbi 0x12,3
	.dbline 34
; 	  LCD_D7_PORT&=~LCD_D7;//数据口置低电平
	cbi 0x12,2
	.dbline 36
; 	  
;     LCD_write_char(0,0x33);      //4bit test
	ldi R18,51
	ldi R19,0
	clr R16
	clr R17
	rcall _LCD_write_char
	.dbline 37
; 	delay_nms(25);
	ldi R16,25
	ldi R17,0
	rcall _delay_nms
	.dbline 38
; 	LCD_write_char(0,0x32);
	ldi R18,50
	ldi R19,0
	clr R16
	clr R17
	rcall _LCD_write_char
	.dbline 39
; 	delay_nms(15);
	ldi R16,15
	ldi R17,0
	rcall _delay_nms
	.dbline 40
; 	LCD_write_char(0,0x28);
	ldi R18,40
	ldi R19,0
	clr R16
	clr R17
	rcall _LCD_write_char
	.dbline 41
; 	delay_nms(15);
	ldi R16,15
	ldi R17,0
	rcall _delay_nms
	.dbline 42
;     LCD_write_char(0,0x0C);      //显示开
	ldi R18,12
	ldi R19,0
	clr R16
	clr R17
	rcall _LCD_write_char
	.dbline 43
; 	delay_nms(15);
	ldi R16,15
	ldi R17,0
	rcall _delay_nms
	.dbline 44
;     LCD_write_char(0,0x01);      //显示清屏
	ldi R18,1
	ldi R19,0
	clr R16
	clr R17
	rcall _LCD_write_char
	.dbline 45
; 	delay_nms(15);
	ldi R16,15
	ldi R17,0
	rcall _delay_nms
	.dbline 46
;     LCD_write_char(0,0x06);      //显示光标移动设置	
	ldi R18,6
	ldi R19,0
	clr R16
	clr R17
	rcall _LCD_write_char
	.dbline 47
; 	LCD_clear();
	rcall _LCD_clear
	.dbline 48
; 	delay_nms(10);
	ldi R16,10
	ldi R17,0
	rcall _delay_nms
	.dbline 49
; 	LCD_init_CGRAM(); 
	rcall _LCD_init_CGRAM
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LCD_write_char _LCD_write_char fV
;           data -> R20,R21
;        command -> R22,R23
	.even
_LCD_write_char::
	rcall push_gset2
	movw R20,R18
	movw R22,R16
	.dbline -1
	.dbline 57
;   }
; /*-----------------------------------------------------------------------
; LCD_write_char    : 写一个字节到LCD的函数
; 编写日期             ：2005-12-12 
; 最后修改日期      ：2005-12-12 		
; -----------------------------------------------------------------------*/
; void LCD_write_char(unsigned command,unsigned data)
;   { 
	.dbline 58
;     if (command == 0)
	cpi R22,0
	cpc R22,R23
	brne L3
X0:
	.dbline 59
;    	LCD_RS_PORT &= ~LCD_RS;   //RS=0  写地址
	cbi 0x12,7
	rjmp L4
L3:
	.dbline 61
; 	else
;     LCD_RS_PORT |= LCD_RS;    //RS=1 写数据
	sbi 0x12,7
L4:
	.dbline 63
; 	
;     LCD_write_DATA_PORT(data);//写高4位
	mov R16,R20
	rcall _LCD_write_DATA_PORT
	.dbline 64
;     LCD_write_DATA_PORT(data<<4);//写低4位
	mov R16,R20
	lsl R16
	rol R17
	lsl R16
	rol R17
	lsl R16
	rol R17
	lsl R16
	rol R17
	rcall _LCD_write_DATA_PORT
	.dbline 65
; 	delay_nus(250);
	ldi R16,250
	ldi R17,0
	rcall _delay_nus
	.dbline 66
; 	num++;//统计向LCD发送的字节数
	lds R24,_num
	lds R25,_num+1
	adiw R24,1
	sts _num+1,R25
	sts _num,R24
	.dbline -2
L2:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r data 20 i
	.dbsym r command 22 i
	.dbend
	.dbfunc e LCD_write_DATA_PORT _LCD_write_DATA_PORT fV
;           data -> R20
	.even
_LCD_write_DATA_PORT::
	rcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 76
;   }
; /*-----------------------------------------------------------------------
; LCD_write_DATA_PORT : 写数据到LCD数据口函数
; 
; 输入参数data   ：要写入的数据(仅高4位)
; 编写日期          ：2005-12-12
; 最后修改日期   ：2005-12-12 		
; -----------------------------------------------------------------------*/
; void LCD_write_DATA_PORT(unsigned char data)
; {   
	.dbline 77
;     if((data>>4)%2)
	ldi R17,2
	mov R16,R20
	swap R16
	andi R16,#0x0F
	rcall mod8u
	tst R16
	breq L6
	.dbline 78
; 	  LCD_D4_PORT |=LCD_D4;
	sbi 0x12,5
	rjmp L7
L6:
	.dbline 80
; 	else
; 	  LCD_D4_PORT &=~LCD_D4;
	cbi 0x12,5
L7:
	.dbline 82
; 	
; 	if((data>>5)%2)
	ldi R17,2
	mov R16,R20
	lsr R16
	lsr R16
	lsr R16
	lsr R16
	lsr R16
	rcall mod8u
	tst R16
	breq L8
	.dbline 83
; 	  LCD_D5_PORT |=LCD_D5;
	sbi 0x12,4
	rjmp L9
L8:
	.dbline 85
; 	else
; 	  LCD_D5_PORT &=~LCD_D5;
	cbi 0x12,4
L9:
	.dbline 87
; 	  
; 	if((data>>6)%2)
	ldi R17,2
	mov R16,R20
	lsr R16
	lsr R16
	lsr R16
	lsr R16
	lsr R16
	lsr R16
	rcall mod8u
	tst R16
	breq L10
	.dbline 88
; 	  LCD_D6_PORT |=LCD_D6;
	sbi 0x12,3
	rjmp L11
L10:
	.dbline 90
; 	else
; 	  LCD_D6_PORT &=~LCD_D6;
	cbi 0x12,3
L11:
	.dbline 92
; 	  
; 	if((data>>7)%2)
	ldi R17,2
	mov R16,R20
	lsr R16
	lsr R16
	lsr R16
	lsr R16
	lsr R16
	lsr R16
	lsr R16
	rcall mod8u
	tst R16
	breq L12
	.dbline 93
; 	  LCD_D7_PORT |=LCD_D7;
	sbi 0x12,2
	rjmp L13
L12:
	.dbline 95
; 	else
; 	  LCD_D7_PORT &=~LCD_D7;
	cbi 0x12,2
L13:
	.dbline 97
; 	  
; 	  LCD_EN_PORT |= LCD_EN; //EN端产生一个由低电平变高电平，写LCD
	sbi 0x12,6
	.dbline 98
; 	  delay_nus(25);
	ldi R16,25
	ldi R17,0
	rcall _delay_nus
	.dbline 99
;       LCD_EN_PORT &= ~LCD_EN; //EN端产生一个由高电平变低电平，写LCD
	cbi 0x12,6
	.dbline 100
; 	  delay_nus(25);
	ldi R16,25
	ldi R17,0
	rcall _delay_nus
	.dbline -2
L5:
	rcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r data 20 c
	.dbend
	.dbfunc e LCD_clear _LCD_clear fV
;              i -> R20
	.even
_LCD_clear::
	rcall push_gset1
	.dbline -1
	.dbline 110
; }
; /*-----------------------------------------------------------------------
; LCD_clear    : 清除屏幕的函数
; 
; 输入参数      ：无
; 编写日期      ：2005/10/18	
;        说明      ：	lcd_data[]也会被清0
; -----------------------------------------------------------------------*/
; void LCD_clear(void)
;   {  
	.dbline 112
;      unsigned char i;
;      LCD_write_char(0,0x01);//显示清屏
	ldi R18,1
	ldi R19,0
	clr R16
	clr R17
	rcall _LCD_write_char
	.dbline 113
; 	 for(i=0;i<32;i++)
	clr R20
	rjmp L18
L15:
	.dbline 114
	.dbline 115
	ldi R24,<_lcd_data
	ldi R25,>_lcd_data
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	clr R2
	std z+0,R2
	.dbline 116
L16:
	.dbline 113
	inc R20
L18:
	.dbline 113
	cpi R20,32
	brlo L15
	.dbline 117
; 	   {
; 	      lcd_data[i]=0;
; 	   }
; 	   delay_nus(500);
	ldi R16,500
	ldi R17,1
	rcall _delay_nus
	.dbline -2
L14:
	rcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.area lit(rom, con, rel)
L20:
	.byte 0
	.byte 0
	.area text(rom, con, rel)
	.dbfile E:\刻录的\电子技术\项目\驱动程序\LCD1602四线接口应用范例\LCD_1602_Driver.c
	.dbfunc e LCD_check _LCD_check fV
;            lcd -> y+0
;              i -> R20
;              y -> R22
;              x -> R20
	.even
_LCD_check::
	rcall push_gset2
	mov R22,R18
	mov R20,R16
	sbiw R28,2
	.dbline -1
	.dbline 128
;   }
; /*-----------------------------------------------------------------------
; LCD_check   : 统计发送数据到LCD次数的函数
; 
; 输入参数      ：x,y 显示结果的座标
; 编写日期      ：2005/10/18	
;        说明      ：如果每秒调用一次，就是统计每秒的次数
; -----------------------------------------------------------------------*/ 
; void LCD_check(unsigned char x,unsigned char y) //检测每秒钟写LCD
;                                                                       //次数的函数
;   {  
	.dbline 130
;     unsigned char  i;
; 	unsigned char  lcd[2]={0};
	ldi R24,<L20
	ldi R25,>L20
	movw R30,R28
	ldi R16,2
	ldi R17,0
	st -y,R31
	st -y,R30
	st -y,R25
	st -y,R24
	rcall asgncblk
	.dbline 131
; 	add=y*16+x;//设置起始座标
	ldi R24,16
	mul R24,R22
	mov R2,R0
	add R2,R20
	sts _add,R2
	.dbline 132
;         lcd[0]=num/10+48;
	ldi R18,10
	ldi R19,0
	lds R16,_num
	lds R17,_num+1
	rcall div16u
	movw R24,R16
	adiw R24,48
	std y+0,R24
	.dbline 133
; 		lcd[1]=num%10+48;
	ldi R18,10
	ldi R19,0
	lds R16,_num
	lds R17,_num+1
	rcall mod16u
	movw R24,R16
	adiw R24,48
	std y+1,R24
	.dbline 134
; 	num=0;  
	clr R2
	clr R3
	sts _num+1,R3
	sts _num,R2
	.dbline 135
;    for (i=0;i<2;i++) 
	clr R20
	rjmp L25
L22:
	.dbline 136
;       {
	.dbline 137
;               if(lcd_data[add]==lcd[i]){}
	movw R24,R28
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldi R24,<_lcd_data
	ldi R25,>_lcd_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	ldd R3,z+0
	cp R3,R2
	brne L26
	.dbline 137
	.dbline 137
	rjmp L27
L26:
	.dbline 139
; 			  else
; 			     {data[add]=lcd[i];}
	.dbline 139
	movw R24,R28
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R2
	.dbline 139
L27:
	.dbline 140
	lds R24,_add
	subi R24,255    ; addi 1
	sts _add,R24
	.dbline 141
L23:
	.dbline 135
	inc R20
L25:
	.dbline 135
	cpi R20,2
	brlo L22
	.dbline 142
; 		          add++;
;       }
; 	LCD_updata;
	clr R2
	sts _new,R2
	.dbline -2
L19:
	adiw R28,2
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l lcd 0 A[2:2]c
	.dbsym r i 20 c
	.dbsym r y 22 c
	.dbsym r x 20 c
	.dbend
	.dbfunc e LCD_write_string _LCD_write_string fV
;              e -> R20
;              s -> R22,R23
;              y -> R18
;              x -> R16
	.even
_LCD_write_string::
	rcall push_gset2
	ldd R22,y+4
	ldd R23,y+5
	ldd R20,y+6
	.dbline -1
	.dbline 153
;   }
; /*-----------------------------------------------------------------------
; LCD_write_string  : 英文字符串显示函数
; 
; 输入参数：*s       ：英文字符串指针；
;                  X、Y    : 显示字符串的位置
; 				 e          : 把从最后一个字符到x=e之间的内容删除
; 编写日期          ：2005/10/18		
; -----------------------------------------------------------------------*/
; void LCD_write_string(unsigned char x,unsigned char y, const unsigned char *s,unsigned char e)
;   { 
	.dbline 154
;     if(y<2)
	cpi R18,2
	brsh L32
	.dbline 155
; 	add=y*16+x;//设置起始座标
	ldi R24,16
	mul R24,R18
	mov R2,R0
	add R2,R16
	sts _add,R2
	rjmp L32
L31:
	.dbline 157
;     while (*s) 
;       { 
	.dbline 158
; 	    if(lcd_data[add]==*s)//如果LCD上显示的数和
	ldi R24,<_lcd_data
	ldi R25,>_lcd_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	movw R30,R22
	lpm R30,Z
	cp R2,R30
	brne L34
	.dbline 159
; 		   {}                             //待写入的数相同的话
	.dbline 159
	rjmp L35
L34:
	.dbline 160
; 		else{data[add]=*s;}//要显示的数据存入显存
	.dbline 160
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	movw R26,R22
	st -y,R31
	st -y,R30
	movw R30,R26
	lpm R26,Z
	ld R30,y+
	ld R31,y+
	std z+0,R26
	.dbline 160
L35:
	.dbline 161
	subi R22,255  ; offset = 1
	sbci R23,255
	.dbline 162
	lds R24,_add
	subi R24,255    ; addi 1
	sts _add,R24
	.dbline 163
L32:
	.dbline 156
	movw R30,R22
	lpm R30,Z
	tst R30
	brne L31
	.dbline 164
; 	       s ++;//指针加1
; 	       add++;//显存地址加1
;       }
; 	  if(y==1)
	cpi R18,1
	brne L41
	.dbline 165
; 	    e+=16;
	subi R20,240    ; addi 16
	.dbline 166
; 	  for(;e>=add;add++)
	rjmp L41
L38:
	.dbline 167
	.dbline 167
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	ldi R24,32
	std z+0,R24
	.dbline 167
L39:
	.dbline 166
	lds R24,_add
	subi R24,255    ; addi 1
	sts _add,R24
L41:
	.dbline 166
	lds R2,_add
	cp R20,R2
	brsh L38
	.dbline 168
; 	   {data[add]=' ';}
; 	LCD_updata;
	clr R2
	sts _new,R2
	.dbline -2
L28:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r e 20 c
	.dbsym r s 22 pkc
	.dbsym r y 18 c
	.dbsym r x 16 c
	.dbend
	.area lit(rom, con, rel)
L43:
	.byte 0
	.byte 0,0,0,0,0,0,0,0,0
	.area text(rom, con, rel)
	.dbfile E:\刻录的\电子技术\项目\驱动程序\LCD1602四线接口应用范例\LCD_1602_Driver.c
	.dbfunc e LCD_write_number _LCD_write_number fV
;              c -> R10
;              b -> R12
;            lcd -> y+0
;              i -> R14
;              e -> R6
;              s -> R8,R9
;            dat -> y+24
;              d -> y+22
;              y -> y+20
;              x -> R14
	.even
_LCD_write_number::
	st -y,r19
	st -y,r18
	rcall push_gset5
	mov R14,R16
	sbiw R28,10
	ldd R8,y+28
	ldd R9,y+29
	ldd R6,y+30
	.dbline -1
	.dbline 182
;   }
; /*-----------------------------------------------------------------------
; LCD_write_number  : 数字显示函数
; 
; 输入参数：
;           X、Y    : 显示字符串的位置
;                d     :在第d位插入小数点
; 		 data      :要显示的数据 长整形
; 		     *s     :数据的单位
; 	         e       : 把从最后一个字符到x=e之间的内容删除
; 编写日期       ：2005/10/18	 		
; -----------------------------------------------------------------------*/ 
; void LCD_write_number(unsigned char x,unsigned char y,unsigned char d,unsigned long dat,const unsigned char *s,unsigned char e)
;   { 
	.dbline 184
;     unsigned char  i;
; 	unsigned char b=0;
	clr R12
	.dbline 185
; 	unsigned char c='.';
	ldi R24,46
	mov R10,R24
	.dbline 186
; 	unsigned char lcd[10]={0};
	ldi R24,<L43
	ldi R25,>L43
	movw R30,R28
	ldi R16,10
	ldi R17,0
	st -y,R31
	st -y,R30
	st -y,R25
	st -y,R24
	rcall asgncblk
	.dbline 187
; 	if(y<2)//如果Y>1则不重新计算地址
	ldd R24,y+20
	cpi R24,2
	brsh L44
	.dbline 188
;     add=y*16+x;//设置起始座标
	ldi R24,16
	ldd R0,y+20
	mul R24,R0
	mov R2,R0
	add R2,R14
	sts _add,R2
L44:
	.dbline 190
;     
;    for (i=10;i>0;i--) 
	ldi R24,10
	mov R14,R24
	rjmp L49
L46:
	.dbline 191
	.dbline 192
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	ldd R2,z+24
	ldd R3,z+25
	ldd R4,z+26
	ldd R5,z+27
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	movw R16,R2
	movw R18,R4
	rcall mod32u
	movw R2,R16
	movw R4,R18
	ldi R20,48
	ldi R21,0
	ldi R22,0
	ldi R23,0
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	movw R24,R28
	mov R30,R14
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R2
	.dbline 193
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	ldd R2,z+24
	ldd R3,z+25
	ldd R4,z+26
	ldd R5,z+27
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	movw R16,R2
	movw R18,R4
	rcall div32u
	movw R30,R28
	std z+24,R16
	std z+25,R17
	std z+26,R18
	std z+27,R19
	.dbline 194
L47:
	.dbline 190
	dec R14
L49:
	.dbline 190
	clr R2
	cp R2,R14
	brsh X1
	rjmp L46
X1:
	.dbline 196
;       {
;         lcd[i]=dat%10+48;
; 		dat=dat/10;
;       }
; 	  
; 	for(i=1;i<11;i++)
	clr R14
	inc R14
	rjmp L53
L50:
	.dbline 197
; 	   { 
	.dbline 198
; 	     if(i==11-d)
	ldi R24,11
	ldd R0,y+22
	sub R24,R0
	cp R14,R24
	brne L54
	.dbline 199
; 		   {  
	.dbline 200
; 		      if(lcd_data[add]==c)
	ldi R24,<_lcd_data
	ldi R25,>_lcd_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	cp R2,R10
	brne L56
	.dbline 201
; 			     {}
	.dbline 201
	rjmp L57
L56:
	.dbline 203
; 			  else
; 			     {data[add]=c;}     
	.dbline 203
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R10
	.dbline 203
L57:
	.dbline 204
; 		          add++;
	lds R24,_add
	subi R24,255    ; addi 1
	sts _add,R24
	.dbline 205
; 			}   
L54:
	.dbline 206
; 	     if((lcd[i]-48+b)==0)
	movw R24,R28
	mov R30,R14
	clr R31
	add R30,R24
	adc R31,R25
	ldd R24,z+0
	subi R24,48
	add R24,R12
	breq X2
	rjmp L58
X2:
	.dbline 207
; 	     {
	.dbline 208
; 		   if(i>=(10-d))
	ldi R24,10
	ldd R0,y+22
	sub R24,R0
	cp R14,R24
	brsh X3
	rjmp L59
X3:
	.dbline 209
; 		   { 
	.dbline 210
; 		      if(lcd_data[add]==lcd[i])
	movw R24,R28
	mov R30,R14
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldi R24,<_lcd_data
	ldi R25,>_lcd_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	ldd R3,z+0
	cp R3,R2
	brne L62
	.dbline 211
; 			     {}
	.dbline 211
	rjmp L63
L62:
	.dbline 213
; 			  else
; 			     {data[add]=lcd[i];}     
	.dbline 213
	movw R24,R28
	mov R30,R14
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R2
	.dbline 213
L63:
	.dbline 214
; 		          add++;
	lds R24,_add
	subi R24,255    ; addi 1
	sts _add,R24
	.dbline 215
; 			} 	 
	.dbline 217
; 		   else
; 		   {}  	   
	.dbline 217
	.dbline 218
; 		 }
	rjmp L59
L58:
	.dbline 220
; 		 else
; 		 {
	.dbline 221
; 		      if(lcd_data[add]==lcd[i])
	movw R24,R28
	mov R30,R14
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldi R24,<_lcd_data
	ldi R25,>_lcd_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	ldd R3,z+0
	cp R3,R2
	brne L64
	.dbline 222
; 			     {}
	.dbline 222
	rjmp L65
L64:
	.dbline 224
; 			  else
; 			     {data[add]=lcd[i];}      
	.dbline 224
	movw R24,R28
	mov R30,R14
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R2
	.dbline 224
L65:
	.dbline 225
; 		          add++;
	lds R24,_add
	subi R24,255    ; addi 1
	sts _add,R24
	.dbline 226
; 		 b=1;
	clr R12
	inc R12
	.dbline 227
; 		 }
L59:
	.dbline 228
L51:
	.dbline 196
	inc R14
L53:
	.dbline 196
	mov R24,R14
	cpi R24,11
	brsh X4
	rjmp L50
X4:
	rjmp L67
L66:
	.dbline 230
; 	   }
; 	   while (*s) 
;       {
	.dbline 231
;         if(lcd_data[add]==*s)//如果LCD上显示的数和
	ldi R24,<_lcd_data
	ldi R25,>_lcd_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	movw R30,R8
	lpm R30,Z
	cp R2,R30
	brne L69
	.dbline 232
; 		   {}                             //待写入的数相同的话
	.dbline 232
	rjmp L70
L69:
	.dbline 233
; 		else{data[add]=*s;}//要显示的数据存入显存
	.dbline 233
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	movw R26,R8
	st -y,R31
	st -y,R30
	movw R30,R26
	lpm R26,Z
	ld R30,y+
	ld R31,y+
	std z+0,R26
	.dbline 233
L70:
	.dbline 234
	movw R24,R8
	adiw R24,1
	movw R8,R24
	.dbline 235
	lds R24,_add
	subi R24,255    ; addi 1
	sts _add,R24
	.dbline 236
L67:
	.dbline 229
	movw R30,R8
	lpm R30,Z
	tst R30
	brne L66
	.dbline 237
; 	       s ++;//指针加1
; 	       add++;//显存地址加1
;       } 
; 	  if(y==1)
	ldd R24,y+20
	cpi R24,1
	brne L76
	.dbline 238
; 	    e+=16;
	mov R24,R6
	subi R24,240    ; addi 16
	mov R6,R24
	.dbline 239
; 	  for(;e>=add;add++)
	rjmp L76
L73:
	.dbline 240
	.dbline 240
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	ldi R24,32
	std z+0,R24
	.dbline 240
L74:
	.dbline 239
	lds R24,_add
	subi R24,255    ; addi 1
	sts _add,R24
L76:
	.dbline 239
	lds R2,_add
	cp R6,R2
	brsh L73
	.dbline 241
; 	   {data[add]=' ';}
; 	    LCD_updata;
	clr R2
	sts _new,R2
	.dbline -2
L42:
	adiw R28,10
	rcall pop_gset5
	adiw R28,2
	.dbline 0 ; func end
	ret
	.dbsym r c 10 c
	.dbsym r b 12 c
	.dbsym l lcd 0 A[10:10]c
	.dbsym r i 14 c
	.dbsym r e 6 c
	.dbsym r s 8 pkc
	.dbsym l dat 24 l
	.dbsym l d 22 c
	.dbsym l y 20 c
	.dbsym r x 14 c
	.dbend
	.area lit(rom, con, rel)
L78:
	.byte 0
	.byte 0,0,0,0,0,0,0
	.area text(rom, con, rel)
	.dbfile E:\刻录的\电子技术\项目\驱动程序\LCD1602四线接口应用范例\LCD_1602_Driver.c
	.dbfunc e LCD_write_time _LCD_write_time fV
;            lcd -> y+0
;              i -> R20
;              s -> y+16
;              m -> y+14
;              h -> y+12
;              y -> R22
;              x -> R20
	.even
_LCD_write_time::
	rcall push_gset2
	mov R22,R18
	mov R20,R16
	sbiw R28,8
	.dbline -1
	.dbline 252
;   }
; /*-----------------------------------------------------------------------
; LCD_write_time  : 数字显示函数
; 
; 输入参数：
;           X、Y    : 显示数据的起始的位置
; 		  h,m,s   :时,分,秒
; 编写日期          ：2005-10-19 		
; -----------------------------------------------------------------------*/ 
; void LCD_write_time(unsigned char x,unsigned char y,unsigned char h,unsigned char m,unsigned char s)
;   { 
	.dbline 254
;     unsigned char  i;
; 	unsigned char  lcd[8]={0};
	ldi R24,<L78
	ldi R25,>L78
	movw R30,R28
	ldi R16,8
	ldi R17,0
	st -y,R31
	st -y,R30
	st -y,R25
	st -y,R24
	rcall asgncblk
	.dbline 255
; 	if(y<2)
	cpi R22,2
	brsh L79
	.dbline 256
; 	add=y*16+x;//设置起始座标LCD_set_xy( X, Y );  
	ldi R24,16
	mul R24,R22
	mov R2,R0
	add R2,R20
	sts _add,R2
L79:
	.dbline 257
; 	lcd[0]=h/10+48;
	ldi R17,10
	ldd R16,y+12
	rcall div8u
	mov R24,R16
	subi R24,208    ; addi 48
	std y+0,R24
	.dbline 258
; 	lcd[1]=h%10+48;
	ldi R17,10
	ldd R16,y+12
	rcall mod8u
	mov R24,R16
	subi R24,208    ; addi 48
	std y+1,R24
	.dbline 259
; 	lcd[2]=':';
	ldi R24,58
	std y+2,R24
	.dbline 260
; 	lcd[3]=m/10+48;
	ldi R17,10
	ldd R16,y+14
	rcall div8u
	mov R24,R16
	subi R24,208    ; addi 48
	std y+3,R24
	.dbline 261
; 	lcd[4]=m%10+48;
	ldi R17,10
	ldd R16,y+14
	rcall mod8u
	mov R24,R16
	subi R24,208    ; addi 48
	std y+4,R24
	.dbline 262
; 	lcd[5]=':';  
	ldi R24,58
	std y+5,R24
	.dbline 263
; 	lcd[6]=s/10+48;
	ldi R17,10
	ldd R16,y+16
	rcall div8u
	mov R24,R16
	subi R24,208    ; addi 48
	std y+6,R24
	.dbline 264
; 	lcd[7]=s%10+48;
	ldi R17,10
	ldd R16,y+16
	rcall mod8u
	mov R24,R16
	subi R24,208    ; addi 48
	std y+7,R24
	.dbline 270
; /*时和分之间的:的闪动效果
; 	if(lcd[7]%2)
; 	   lcd[2]=':';
; 	   else
; 	   lcd[2]=' ';*/
;    for (i=0;i<8;i++) 
	clr R20
	rjmp L91
L88:
	.dbline 271
;       {
	.dbline 272
;               if(lcd_data[add]==lcd[i])
	movw R24,R28
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldi R24,<_lcd_data
	ldi R25,>_lcd_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	ldd R3,z+0
	cp R3,R2
	brne L92
	.dbline 273
; 			     {}
	.dbline 273
	rjmp L93
L92:
	.dbline 275
; 			  else
; 			     {data[add]=lcd[i];}    
	.dbline 275
	movw R24,R28
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R2
	.dbline 275
L93:
	.dbline 276
	lds R24,_add
	subi R24,255    ; addi 1
	sts _add,R24
	.dbline 277
L89:
	.dbline 270
	inc R20
L91:
	.dbline 270
	cpi R20,8
	brlo L88
	.dbline 278
; 		          add++;
;       }
; 	LCD_updata;
	clr R2
	sts _new,R2
	.dbline -2
L77:
	adiw R28,8
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l lcd 0 A[8:8]c
	.dbsym r i 20 c
	.dbsym l s 16 c
	.dbsym l m 14 c
	.dbsym l h 12 c
	.dbsym r y 22 c
	.dbsym r x 20 c
	.dbend
	.dbfunc e LCD_write_new _LCD_write_new fV
;        address -> R20
;        new_add -> R22
	.even
_LCD_write_new::
	rcall push_gset2
	.dbline -1
	.dbline 287
;   }
; /*----------------------------------------------------
;     LCD_write_new:写显存函数
; 	data[]:32字节的显存
; 	new:显存标号
; 	编写日期:2005/10/18
; -----------------------------------------------------*/  
; void  LCD_write_new(void)
;   {   
	.dbline 289
;     unsigned char address;
; 	unsigned char new_add=1;//1表示要更新地址
	ldi R22,1
	rjmp L96
L95:
	.dbline 291
; 	while(new<32)//显存共32个字节,标号从0--31 
;       {    
	.dbline 292
; 		 if(new==16)//换行
	lds R24,_new
	cpi R24,16
	brne L98
	.dbline 293
; 		    new_add=1;	   
	ldi R22,1
L98:
	.dbline 294
; 	     if(data[new])//跳过为0的显存
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_new
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	tst R2
	brne X5
	rjmp L100
X5:
	.dbline 295
;             {  
	.dbline 296
; 			if(new_add)//当new_add=0时表示无需更新地址
	tst R22
	breq L102
	.dbline 297
; 		      {
	.dbline 298
; 		         if(new>15)
	ldi R24,15
	lds R2,_new
	cp R24,R2
	brsh L104
	.dbline 299
; 			       address=0xb0+new;
	mov R20,R2
	subi R20,80    ; addi 176
	rjmp L105
L104:
	.dbline 301
; 				 else
; 			       address=0x80+new;
	lds R20,_new
	subi R20,128    ; addi 128
L105:
	.dbline 302
; 			       LCD_write_char(0,address);//设置起始地址
	mov R18,R20
	clr R19
	clr R16
	clr R17
	rcall _LCD_write_char
	.dbline 303
; 		       }  			  
L102:
	.dbline 304
; 			  LCD_write_char(1,data[new]);//写数据
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_new
	clr R31
	add R30,R24
	adc R31,R25
	ldd R18,z+0
	clr R19
	ldi R16,1
	ldi R17,0
	rcall _LCD_write_char
	.dbline 305
; 			  lcd_data[new]=data[new];
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_new
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldi R24,<_lcd_data
	ldi R25,>_lcd_data
	lds R30,_new
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R2
	.dbline 306
; 			  data[new]=0;//写完数据后,显存清0
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_new
	clr R31
	add R30,R24
	adc R31,R25
	clr R2
	std z+0,R2
	.dbline 307
; 			  new_add=0;
	clr R22
	.dbline 308
; 			}
	rjmp L101
L100:
	.dbline 310
; 		else
; 		   new_add=1;
	ldi R22,1
L101:
	.dbline 311
	lds R24,_new
	subi R24,255    ; addi 1
	sts _new,R24
	.dbline 312
L96:
	.dbline 290
	lds R24,_new
	cpi R24,32
	brsh X6
	rjmp L95
X6:
	.dbline -2
L94:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r address 20 c
	.dbsym r new_add 22 c
	.dbend
	.dbfunc e LCD_write_CGRAM _LCD_write_CGRAM fV
;              n -> R20
;              y -> R18
;              x -> R16
	.even
_LCD_write_CGRAM::
	rcall push_gset1
	ldd R20,y+2
	.dbline -1
	.dbline 322
; 		   new++;//
;       }
;   } 
; /*----------------------------------------------------
;     LCD_write_CGRAM:写CGRAM的函数
; 	输入参数：
;           X、Y    : 显示数据的起始的位置
; 		        n    : 存入LCD的图案的编号
; 	编写日期:2005/10/18
; -----------------------------------------------------*/ 
; void LCD_write_CGRAM(unsigned char x,unsigned char y,unsigned char n) 
; {  
	.dbline 323
;    if(y<2)
	cpi R18,2
	brsh L107
	.dbline 324
;    add=y*16+x;//设置起始座标
	ldi R24,16
	mul R24,R18
	mov R2,R0
	add R2,R16
	sts _add,R2
L107:
	.dbline 325
;     if(n==0)//0表示空数据
	tst R20
	brne L109
	.dbline 326
; 	n+=8;//所以要加上8  (0>8/1>9/2>10...7>15)  
	subi R20,248    ; addi 8
L109:
	.dbline 327
; 	data[add]=n;      
	ldi R24,<_data
	ldi R25,>_data
	lds R30,_add
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R20
	.dbline 328
; 	LCD_updata;
	clr R2
	sts _new,R2
	.dbline -2
L106:
	rcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r n 20 c
	.dbsym r y 18 c
	.dbsym r x 16 c
	.dbend
	.area lit(rom, con, rel)
L112:
	.byte 63,1
	.byte 1,1
	.byte 1,1
	.byte 63,0
	.byte 0,4
	.byte 2,31
	.byte 2,4
	.byte 0,0
	.byte 0,4
	.byte 14,21
	.byte 4,4
	.byte 4,0
	.byte 0,31
	.byte 21,14
	.byte 4,4
	.byte 4,0
	.byte 0,31
	.byte 21,10
	.byte 4,4
	.byte 4,0
	.byte 0,0
	.byte 2,6
	.byte 14,30
	.byte 30,0
	.byte 8,12
	.byte 10,9
	.byte 10,12
	.byte 8,0
	.byte 8,12
	.byte 14,15
	.byte 14,12
	.byte 8,0
	.area text(rom, con, rel)
	.dbfile E:\刻录的\电子技术\项目\驱动程序\LCD1602四线接口应用范例\LCD_1602_Driver.c
	.dbfunc e LCD_init_CGRAM _LCD_init_CGRAM fV
;            ads -> R20
;          CGRAM -> y+0
;              y -> R20
;              x -> R22
	.even
_LCD_init_CGRAM::
	rcall push_gset2
	sbiw R28,63
	sbiw R28,1  ; offset = 64
	.dbline -1
	.dbline 336
; }
; /*----------------------------------------------------
;     LCD_init_CGRAM:初始化CGRAM的函数
; 	
; 	编写日期:2005/10/18
; -----------------------------------------------------*/ 
; void LCD_init_CGRAM(void)
;   {
	.dbline 338
;      unsigned char CGRAM[8][8]=//CGRAM图案的定义
; 	 {  //1     2      3       4       5      6        7      x
	ldi R24,<L112
	ldi R25,>L112
	movw R30,R28
	ldi R16,64
	ldi R17,0
	st -y,R31
	st -y,R30
	st -y,R25
	st -y,R24
	rcall asgncblk
	.dbline 348
; 	   {0x3F,0x01,0x01,0x01,0x01,0x01,0x3F,0x00},//0
; 	   {0x00,0x04,0x02,0x1F,0x02,0x04,0x00,0x00},//1
; 	   {0x00,0x04,0x0E,0x15,0x04,0x04,0x04,0x00},//2
; 	   {0x00,0x1F,0x15,0x0E,0x04,0x04,0x04,0x00},//3
; 	   {0x00,0x1F,0x15,0x0A,0x04,0x04,0x04,0x00},//4
; 	   {0x00,0x00,0x02,0x06,0x0E,0x1E,0x1E,0x00},//5
; 	   {0x08,0x0C,0x0A,0x09,0x0A,0x0C,0x08,0x00},//6		
; 	   {0x08,0x0C,0x0E,0x0F,0x0E,0x0C,0x08,0x00},//7
; 	 };
; 	   unsigned char ads=0x40;
	ldi R20,64
	.dbline 351
; 	   unsigned char x,y;
; 	   
; 	   LCD_write_char(0,ads);//写地址
	mov R18,R20
	clr R19
	clr R16
	clr R17
	rcall _LCD_write_char
	.dbline 352
; 	   for(y=0;y<8;y++)
	clr R20
	rjmp L116
L113:
	.dbline 353
; 	     { 
	.dbline 354
; 		   for(x=0;x<8;x++)
	clr R22
	rjmp L120
L117:
	.dbline 355
	.dbline 356
	ldi R24,8
	mul R24,R20
	movw R2,R0
	movw R24,R28
	add R2,R24
	adc R3,R25
	mov R30,R22
	clr R31
	add R30,R2
	adc R31,R3
	ldd R18,z+0
	clr R19
	ldi R16,1
	ldi R17,0
	rcall _LCD_write_char
	.dbline 357
L118:
	.dbline 354
	inc R22
L120:
	.dbline 354
	cpi R22,8
	brlo L117
	.dbline 358
L114:
	.dbline 352
	inc R20
L116:
	.dbline 352
	cpi R20,8
	brlo L113
	.dbline -2
L111:
	adiw R28,63
	adiw R28,1  ; offset = 64
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r ads 20 c
	.dbsym l CGRAM 0 A[64:8:8]c
	.dbsym r y 20 c
	.dbsym r x 22 c
	.dbend
	.area bss(ram, con, rel)
	.dbfile E:\刻录的\电子技术\项目\驱动程序\LCD1602四线接口应用范例\LCD_1602_Driver.c
_add::
	.blkb 1
	.dbsym e add _add c
_data::
	.blkb 32
	.dbsym e data _data A[32:32]c
_lcd_data::
	.blkb 32
	.dbsym e lcd_data _lcd_data A[32:32]c
