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

📄 lcd1602显示.s

📁 ICC mega8例子
💻 S
字号:
	.module LCD1602显示.c
	.area text(rom, con, rel)
	.dbfile E:\xiaozhiyong2009\设计资料\项目设计\ICCAVR_mega8_C\ICCAVR_mega8_LCD1602显示\LCD1602显示.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 9
; //ICC-AVR application builder : 2009-3-12 16:02:34
; // Target : M8
; // Crystal: 8.0000Mhz
; 
; #include <iom8v.h>
; #include <macros.h>
; 
; void port_init(void)
; {
	.dbline 10
;  PORTB = 0x00;
	clr R2
	out 0x18,R2
	.dbline 11
;  DDRB  = 0x00;
	out 0x17,R2
	.dbline 12
;  PORTC = 0x00; //m103 output only
	out 0x15,R2
	.dbline 13
;  DDRC  = 0x00;
	out 0x14,R2
	.dbline 14
;  PORTD = 0x00;
	out 0x12,R2
	.dbline 15
;  DDRD  = 0x00;
	out 0x11,R2
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 20
; }
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 22
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 23
;  port_init();
	rcall _port_init
	.dbline 25
; 
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 26
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 27
;  TIMSK = 0x00; //timer interrupt sources
	out 0x39,R2
	.dbline 28
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delay _delay fV
;              i -> R20,R21
;              j -> R22,R23
;             ms -> R16,R17
	.even
_delay::
	rcall push_xgsetF000
	.dbline -1
	.dbline 48
;  //all peripherals are now initialized
; }
; 
; /*************************************************************************
; 用    途:LCD1602显示
; Taget   :mega8
; crystal :8M
; 介    绍:用PB做端口,
;          PB0-D0
; 		 PB7-D7
; 		 ------
; 		 PC0-6
; 		 PC1-5
; 		 PC2-4----456为控制引脚
; 入口参数:
; 出口参数:
; *************************************/
; //延时程序
; void delay(unsigned int ms)
; {
	.dbline 50
;  	 unsigned int i,j;
; 	 for(i=0;i<ms;i++)
	clr R20
	clr R21
	rjmp L7
L4:
	.dbline 51
; 	 	{for(j=0;j<200;j++);}
	.dbline 51
	clr R22
	clr R23
	rjmp L11
L8:
	.dbline 51
L9:
	.dbline 51
	subi R22,255  ; offset = 1
	sbci R23,255
L11:
	.dbline 51
	cpi R22,200
	ldi R30,0
	cpc R23,R30
	brlo L8
X0:
	.dbline 51
L5:
	.dbline 50
	subi R20,255  ; offset = 1
	sbci R21,255
L7:
	.dbline 50
	cp R20,R16
	cpc R21,R17
	brlo L4
X1:
	.dbline -2
L3:
	.dbline 0 ; func end
	rjmp pop_xgsetF000
	.dbsym r i 20 i
	.dbsym r j 22 i
	.dbsym r ms 16 i
	.dbend
	.dbfunc e com_lcd _com_lcd fV
;            com -> R10
	.even
_com_lcd::
	st -y,R10
	mov R10,R16
	.dbline -1
	.dbline 55
; }
; //送指令子程序
; void com_lcd(unsigned char com)
; {
	.dbline 56
;  	 PORTC&=~(1<<PC2);
	cbi 0x15,2
	.dbline 57
; 	 PORTC&=~(1<<PC1);
	cbi 0x15,1
	.dbline 58
; 	 PORTB=com;
	out 0x18,R10
	.dbline 59
; 	 PORTC|=(1<<PC0);
	sbi 0x15,0
	.dbline 60
; 	 delay(5);
	ldi R16,5
	ldi R17,0
	rcall _delay
	.dbline 61
; 	 PORTC&=~(1<<PC0);
	cbi 0x15,0
	.dbline -2
L12:
	.dbline 0 ; func end
	ld R10,y+
	ret
	.dbsym r com 10 c
	.dbend
	.dbfunc e data_lcd _data_lcd fV
;           data -> R10
	.even
_data_lcd::
	st -y,R10
	mov R10,R16
	.dbline -1
	.dbline 65
; }
; //送数据子程序
; void data_lcd(unsigned char data)
; {
	.dbline 66
;  	 PORTC|=(1<<PC2);
	sbi 0x15,2
	.dbline 67
; 	 PORTC&=~(1<<PC1);
	cbi 0x15,1
	.dbline 68
; 	 PORTB=data;
	out 0x18,R10
	.dbline 69
; 	 PORTC|=(1<<PC0);
	sbi 0x15,0
	.dbline 70
; 	 delay(5);
	ldi R16,5
	ldi R17,0
	rcall _delay
	.dbline 71
; 	 PORTC&=~(1<<PC0);
	cbi 0x15,0
	.dbline -2
L13:
	.dbline 0 ; func end
	ld R10,y+
	ret
	.dbsym r data 10 c
	.dbend
	.dbfunc e LCD1602_init _LCD1602_init fV
	.even
_LCD1602_init::
	.dbline -1
	.dbline 75
; }
; //初始化
; void LCD1602_init()
; {
	.dbline 76
;  	 DDRB=0XFF;
	ldi R24,255
	out 0x17,R24
	.dbline 77
; 	 DDRC|=0X07;
	in R24,0x14
	ori R24,7
	out 0x14,R24
	.dbline 78
; 	 PORTC&=~(1<<PC0);
	cbi 0x15,0
	.dbline 80
; 	 
; 	 com_lcd(0x38);//5*7,2行显示
	ldi R16,56
	rcall _com_lcd
	.dbline 81
; 	 delay(5);
	ldi R16,5
	ldi R17,0
	rcall _delay
	.dbline 82
; 	 com_lcd(0x01);	//清屏
	ldi R16,1
	rcall _com_lcd
	.dbline 83
; 	 delay(5);
	ldi R16,5
	ldi R17,0
	rcall _delay
	.dbline 84
; 	 com_lcd(0x0C);//文字不动,光标自动右移
	ldi R16,12
	rcall _com_lcd
	.dbline 85
; 	 delay(5);
	ldi R16,5
	ldi R17,0
	rcall _delay
	.dbline 86
; 	 com_lcd(0x06);//开显示
	ldi R16,6
	rcall _com_lcd
	.dbline 87
; 	 delay(5);
	ldi R16,5
	ldi R17,0
	rcall _delay
	.dbline -2
L14:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LCD1602_clear _LCD1602_clear fV
	.even
_LCD1602_clear::
	.dbline -1
	.dbline 91
; }
; //清屏
; void LCD1602_clear()
; {
	.dbline 92
;  	 com_lcd(0x01);	//清屏
	ldi R16,1
	rcall _com_lcd
	.dbline 93
; 	 delay(5);
	ldi R16,5
	ldi R17,0
	rcall _delay
	.dbline -2
L15:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LCD1602_goxy _LCD1602_goxy fV
;            row -> R10
;           line -> R20
	.even
_LCD1602_goxy::
	rcall push_xgset300C
	mov R10,R18
	mov R20,R16
	.dbline -1
	.dbline 97
; }
; //定位x,y(x-列,y-行)
; void LCD1602_goxy(unsigned char line,unsigned char row)
; {
	.dbline 98
;  if (row==0)
	tst R10
	brne L17
X2:
	.dbline 99
;  	line+=0x81;
	subi R20,127    ; addi 129
	rjmp L18
L17:
	.dbline 101
;  else
;  	line+=0xc0;
	subi R20,64    ; addi 192
L18:
	.dbline 102
;  com_lcd(line);//第二行首地址
	mov R16,R20
	rcall _com_lcd
	.dbline 103
;  delay(5);
	ldi R16,5
	ldi R17,0
	rcall _delay
	.dbline -2
L16:
	.dbline 0 ; func end
	rjmp pop_xgset300C
	.dbsym r row 10 c
	.dbsym r line 20 c
	.dbend
	.dbfunc e LCD1602_print _LCD1602_print fI
;            str -> R20,R21
	.even
_LCD1602_print::
	st -y,R20
	st -y,R21
	movw R20,R16
	.dbline -1
	.dbline 107
; }
; //显示字符串
; LCD1602_print(char *str)
; {
	rjmp L21
L20:
	.dbline 109
;  while(*str)
;  {
	.dbline 110
;   data_lcd(*str);
	movw R30,R20
	ldd R16,z+0
	rcall _data_lcd
	.dbline 111
;   delay(10);
	ldi R16,10
	ldi R17,0
	rcall _delay
	.dbline 112
;   str++;
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 113
;  }
L21:
	.dbline 108
	movw R30,R20
	ldd R2,z+0
	tst R2
	brne L20
X3:
	.dbline -2
L19:
	.dbline 0 ; func end
	ld R21,y+
	ld R20,y+
	ret
	.dbsym r str 20 pc
	.dbend
	.dbfunc e LCD1602_printD _LCD1602_printD fI
;              n -> R10
	.even
_LCD1602_printD::
	st -y,R10
	mov R10,R16
	.dbline -1
	.dbline 117
; }
; //显示一个二位十位数
; LCD1602_printD(unsigned char n)
; {
	.dbline 118
;  data_lcd(n/10+0x30);
	ldi R17,10
	mov R16,R10
	rcall div8u
	subi R16,208    ; addi 48
	rcall _data_lcd
	.dbline 119
;  delay(10);
	ldi R16,10
	ldi R17,0
	rcall _delay
	.dbline 120
;  data_lcd(n%10+0x30);
	ldi R17,10
	mov R16,R10
	rcall mod8u
	subi R16,208    ; addi 48
	rcall _data_lcd
	.dbline 121
;  delay(10);
	ldi R16,10
	ldi R17,0
	rcall _delay
	.dbline -2
L23:
	.dbline 0 ; func end
	ld R10,y+
	ret
	.dbsym r n 10 c
	.dbend
	.dbfunc e main _main fV
;              i -> R20
	.even
_main::
	.dbline -1
	.dbline 126
; }
; //**************************************************************************	
; 
; void main()
; {
	.dbline 127
;  unsigned char i=23;
	ldi R20,23
	.dbline 128
;  port_init();
	rcall _port_init
	.dbline 129
;  init_devices();
	rcall _init_devices
	.dbline 131
;  
;  LCD1602_init();
	rcall _LCD1602_init
	.dbline 132
;  LCD1602_goxy(2,0);
	clr R18
	ldi R16,2
	rcall _LCD1602_goxy
	.dbline 133
;  LCD1602_print("xiaozhiyong");
	ldi R16,<L25
	ldi R17,>L25
	rcall _LCD1602_print
	.dbline 134
;  LCD1602_goxy(2,1);
	ldi R18,1
	ldi R16,2
	rcall _LCD1602_goxy
	.dbline 135
;  LCD1602_printD(i);
	mov R16,R20
	rcall _LCD1602_printD
L26:
	.dbline 138
;  
;  while(1)
;  {
	.dbline 139
;   ;
	.dbline 140
;  }
L27:
	.dbline 137
	rjmp L26
X4:
	.dbline -2
L24:
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.area data(ram, con, rel)
	.dbfile E:\xiaozhiyong2009\设计资料\项目设计\ICCAVR_mega8_C\ICCAVR_mega8_LCD1602显示\LCD1602显示.c
L25:
	.blkb 12
	.area idata
	.byte 'x,'i,'a,'o,'z,'h,'i,'y,'o,'n,'g,0
	.area data(ram, con, rel)
	.dbfile E:\xiaozhiyong2009\设计资料\项目设计\ICCAVR_mega8_C\ICCAVR_mega8_LCD1602显示\LCD1602显示.c
; }

⌨️ 快捷键说明

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