lcd-16sm.s

来自「大量ATMEGA16实例, 都可以运行,包括驱动LCD1602, 上位机显示等多」· S 代码 · 共 1,093 行 · 第 1/2 页

S
1,093
字号
	ldi R17,0
	xcall _ldelay
	.dbline 155
;  cursor_index=0;
	clr R2
	clr R3
	sts _cursor_index+1,R3
	sts _cursor_index,R2
	.dbline -2
L21:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e cursor_line1 _cursor_line1 fV
	.even
_cursor_line1::
	.dbline -1
	.dbline 159
; }
;  
; void cursor_line1(void)		//Move cursor to the first line 
; {
	.dbline 160
;  wr_instruction2(0x80);
	ldi R16,128
	xcall _wr_instruction2
	.dbline 161
;  cursor_index=0;
	clr R2
	clr R3
	sts _cursor_index+1,R3
	sts _cursor_index,R2
	.dbline 162
;  ldelay(5);
	ldi R16,5
	ldi R17,0
	xcall _ldelay
	.dbline -2
L22:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e cursor_line2 _cursor_line2 fV
	.even
_cursor_line2::
	.dbline -1
	.dbline 166
; }
; 
; void cursor_line2(void)		//Move cursor to the second line
; {
	.dbline 167
;  wr_instruction2(0b11000000);
	ldi R16,192
	xcall _wr_instruction2
	.dbline 168
;  cursor_index=0x40;
	ldi R24,64
	ldi R25,0
	sts _cursor_index+1,R25
	sts _cursor_index,R24
	.dbline 169
;  ldelay(2);
	ldi R16,2
	ldi R17,0
	xcall _ldelay
	.dbline -2
L23:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e space _space fV
	.even
_space::
	.dbline -1
	.dbline 173
; } 
; 
; void space(void)   			 //Write space, ' ', on the panel
; {
	.dbline 174
;  wr_data2(' ');
	ldi R16,32
	xcall _wr_data2
	.dbline -2
L24:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e out_string _out_string fV
;        onechar -> R12
;              i -> R20,R21
;          array -> R10,R11
	.even
_out_string::
	xcall push_xgset303C
	movw R10,R16
	.dbline -1
	.dbline 178
;  }
;  
; void out_string(const char array[])	 //Send a string stored in array to LCD panel
; {
	.dbline 179
;  int i=0;
	clr R20
	clr R21
	.dbline 181
;  unsigned char onechar;
;  i=0;
	xjmp L27
L26:
	.dbline 183
;  while(array[i])
;   {
	.dbline 184
;    onechar=array[i++];
	movw R2,R20
	subi R20,255  ; offset = 1
	sbci R21,255
	movw R30,R2
	add R30,R10
	adc R31,R11
	elpm R12,Z
	.dbline 185
;    wr_data2(onechar);
	mov R16,R12
	xcall _wr_data2
	.dbline 186
;   }
L27:
	.dbline 182
	movw R30,R20
	add R30,R10
	adc R31,R11
	elpm R2,Z
	tst R2
	brne L26
X4:
	.dbline -2
L25:
	.dbline 0 ; func end
	xjmp pop_xgset303C
	.dbsym r onechar 12 c
	.dbsym r i 20 I
	.dbsym r array 10 pkc
	.dbend
	.dbfunc e lcd_on _lcd_on fV
;      ctrl_data -> <dead>
;              i -> <dead>
	.even
_lcd_on::
	.dbline -1
	.dbline 190
; }
; 
; void lcd_on(void)
; {
	.dbline 192
;  unsigned char i, ctrl_data;
;  ldelay(20);
	ldi R16,20
	ldi R17,0
	xcall _ldelay
	.dbline 193
;  PORTD=0x01;
	ldi R24,1
	out 0x12,R24
	.dbline 194
;  ldelay(40);
	ldi R16,40
	ldi R17,0
	xcall _ldelay
	.dbline 195
;  wr_instruction(0b00110000);   //Function Set:set 8-bit, 2line, 5x7 fonts
	ldi R16,48
	xcall _wr_instruction
	.dbline 196
;  ldelay(2);
	ldi R16,2
	ldi R17,0
	xcall _ldelay
	.dbline 197
;  wr_instruction(0b00110000);   //
	ldi R16,48
	xcall _wr_instruction
	.dbline 198
;  ldelay(2);
	ldi R16,2
	ldi R17,0
	xcall _ldelay
	.dbline 199
;  wr_instruction(0b00110000);   //
	ldi R16,48
	xcall _wr_instruction
	.dbline 200
;  delay(80);
	ldi R16,80
	ldi R17,0
	xcall _delay
	.dbline 201
;  wr_instruction(0b00111100);   //8-bit, 2 lines, 5x7 font
	ldi R16,60
	xcall _wr_instruction
	.dbline 202
;  delay(20);
	ldi R16,20
	ldi R17,0
	xcall _delay
	.dbline 203
;  wr_instruction(0b00001110);   //display on, cursor on, blink off
	ldi R16,14
	xcall _wr_instruction
	.dbline 204
;  delay(20);
	ldi R16,20
	ldi R17,0
	xcall _delay
	.dbline 205
;  wr_instruction(0b00001110);   //display on, 
	ldi R16,14
	xcall _wr_instruction
	.dbline 206
;  delay(20);
	ldi R16,20
	ldi R17,0
	xcall _delay
	.dbline 207
;  wr_instruction(0b00000001);   //clear display
	ldi R16,1
	xcall _wr_instruction
	.dbline 208
;  ldelay(5);
	ldi R16,5
	ldi R17,0
	xcall _ldelay
	.dbline 209
;  wr_instruction(0b00000110);   //Entry mode
	ldi R16,6
	xcall _wr_instruction
	.dbline 210
;  delay(10);
	ldi R16,10
	ldi R17,0
	xcall _delay
	.dbline 211
;  wr_instruction(0b00000001);   //clear display
	ldi R16,1
	xcall _wr_instruction
	.dbline 212
;  delay(20);
	ldi R16,20
	ldi R17,0
	xcall _delay
	.dbline -2
L29:
	.dbline 0 ; func end
	ret
	.dbsym l ctrl_data 1 c
	.dbsym l i 1 c
	.dbend
	.dbfunc e main _main fV
;              a -> <dead>
;         array1 -> y+0
;          jsave -> <dead>
;              j -> <dead>
;           dark -> <dead>
;           pfin -> <dead>
;           data -> <dead>
;              i -> R10,R11
;         darkfg -> R20
	.even
_main::
	sbiw R28,10
	.dbline -1
	.dbline 219
;  }
; //***********************************************************
; 
; // **********************************************************
; // Main program
; void main(void)
; {
	.dbline 220
;  unsigned char data, pfin, dark, darkfg=0xff;
	ldi R20,255
	.dbline 221
;  int i=0;
	clr R10
	clr R11
	.dbline 224
;  unsigned char j, jsave, array1[10];
;  int a;
;  CLI();
	cli
	.dbline 225
;  port_init();
	xcall _port_init
	.dbline 226
;  WDT_off();
	xcall _WDT_off
	.dbline 227
;  ldelay(200);
	ldi R16,200
	ldi R17,0
	xcall _ldelay
	.dbline 228
;  lcd_on();
	xcall _lcd_on
	.dbline 229
;  PORTD=0x50;
	ldi R24,80
	out 0x12,R24
	.dbline 230
;  ldelay(50);
	ldi R16,50
	ldi R17,0
	xcall _ldelay
	.dbline 231
;  PORTD=0x05;
	ldi R24,5
	out 0x12,R24
	.dbline 232
;  ldelay(50);
	ldi R16,50
	ldi R17,0
	xcall _ldelay
	.dbline 233
;  out_string(message1);
	ldi R16,<_message1
	ldi R17,>_message1
	xcall _out_string
	.dbline 234
;  cursor_line2();
	xcall _cursor_line2
	.dbline 235
;  out_string(message2);
	ldi R16,<_message2
	ldi R17,>_message2
	xcall _out_string
	.dbline 236
;  PORTD=0x55;
	ldi R24,85
	out 0x12,R24
	.dbline 237
;  PORTA=0xF8;
	ldi R24,248
	out 0x1b,R24
	.dbline 238
;  PORTB=0x00;
	clr R2
	out 0x18,R2
	.dbline 239
;  ldelay(100);
	ldi R16,100
	ldi R17,0
	xcall _ldelay
	xjmp L32
L31:
	.dbline 242
; 
;  while(1)
;  {
	.dbline 243
;   WDR();
	wdr
	.dbline 244
;   swin=PINC&0x30;
	in R24,0x13
	andi R24,48
	sts _swin,R24
	.dbline 245
;   swin=(swin>>4)&0x03;
	swap R24
	andi R24,#0x0F
	andi R24,3
	sts _swin,R24
	.dbline 248
;   
;   
;   if(swin2!=swin)
	mov R2,R24
	lds R3,_swin2
	cp R3,R24
	brne X10
	xjmp L34
X10:
X5:
	.dbline 249
;     {
	.dbline 250
; 	 PORTD=swin;
	out 0x12,R24
	.dbline 251
; 	 swin2=swin;
	sts _swin2,R2
	.dbline 252
;   	 if(swin==0x00)
	tst R24
	brne L36
X6:
	.dbline 253
;       {
	.dbline 254
; 	  cursor_home();
	xcall _cursor_home
	.dbline 255
; 	  out_string(message1);
	ldi R16,<_message1
	ldi R17,>_message1
	xcall _out_string
	.dbline 256
;  	  cursor_line2();
	xcall _cursor_line2
	.dbline 257
;  	  out_string(message2);
	ldi R16,<_message2
	ldi R17,>_message2
	xcall _out_string
	.dbline 258
; 	  }
	xjmp L37
L36:
	.dbline 259
;   	 else if(swin==0x01)
	lds R24,_swin
	cpi R24,1
	brne L38
X7:
	.dbline 260
;       {
	.dbline 261
; 	  cursor_home();
	xcall _cursor_home
	.dbline 262
; 	  out_string(message3);
	ldi R16,<_message3
	ldi R17,>_message3
	xcall _out_string
	.dbline 263
;  	  cursor_line2();
	xcall _cursor_line2
	.dbline 264
;  	  out_string(message4);
	ldi R16,<_message4
	ldi R17,>_message4
	xcall _out_string
	.dbline 265
; 	  }
	xjmp L39
L38:
	.dbline 266
;      else if(swin==0x02)
	lds R24,_swin
	cpi R24,2
	brne L40
X8:
	.dbline 267
;       {
	.dbline 268
; 	  cursor_home();
	xcall _cursor_home
	.dbline 269
; 	  out_string(message5);
	ldi R16,<_message5
	ldi R17,>_message5
	xcall _out_string
	.dbline 270
;  	  cursor_line2();
	xcall _cursor_line2
	.dbline 271
;  	  out_string(message6);
	ldi R16,<_message6
	ldi R17,>_message6
	xcall _out_string
	.dbline 272
; 	  }
	xjmp L41
L40:
	.dbline 274
;      else
;       {
	.dbline 275
; 	  cursor_home();
	xcall _cursor_home
	.dbline 276
; 	  out_string(message7);
	ldi R16,<_message7
	ldi R17,>_message7
	xcall _out_string
	.dbline 277
;  	  cursor_line2();
	xcall _cursor_line2
	.dbline 278
;  	  out_string(message8);
	ldi R16,<_message8
	ldi R17,>_message8
	xcall _out_string
	.dbline 279
; 	  }		
L41:
L39:
L37:
	.dbline 280
; 	}
L34:
	.dbline 281
;   ldelay(10);
	ldi R16,10
	ldi R17,0
	xcall _ldelay
	.dbline 282
;   }
L32:
	.dbline 241
	xjmp L31
X9:
	.dbline -2
L30:
	.dbline 0 ; func end
	adiw R28,10
	ret
	.dbsym l a 1 I
	.dbsym l array1 0 A[10:10]c
	.dbsym l jsave 1 c
	.dbsym l j 1 c
	.dbsym l dark 1 c
	.dbsym l pfin 1 c
	.dbsym l data 1 c
	.dbsym r i 10 I
	.dbsym r darkfg 20 c
	.dbend
	.area bss(ram, con, rel)
	.dbfile C:\+samples-16small\LCD-16sm\LCD-16sm.c
_swin2::
	.blkb 1
	.dbsym e swin2 _swin2 c
_swin::
	.blkb 1
	.dbsym e swin _swin c
_indexcount::
	.blkb 2
	.dbsym e indexcount _indexcount I
;   
; }

⌨️ 快捷键说明

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