lcd-16sn.s
来自「大量ATMEGA16实例, 都可以运行,包括驱动LCD1602, 上位机显示等多」· S 代码 · 共 871 行 · 第 1/2 页
S
871 行
; data -> R10
.even
_wr_data2::
st -y,R10
mov R10,R16
.dbline -1
.dbline 116
; }
;
; void wr_data2(unsigned char data)
; {
.dbline 118
; unsigned char flags;
; if(cursor_index==0x10)
lds R24,_cursor_index
lds R25,_cursor_index+1
cpi R24,16
ldi R30,0
cpc R25,R30
brne L17
X2:
.dbline 119
; cursor_line2();
xcall _cursor_line2
xjmp L18
L17:
.dbline 120
; else if(cursor_index==0x50)
lds R24,_cursor_index
lds R25,_cursor_index+1
cpi R24,80
ldi R30,0
cpc R25,R30
brne L19
X3:
.dbline 121
; cursor_line1();
xcall _cursor_line1
L19:
L18:
.dbline 122
; wr_data(data);
mov R16,R10
xcall _wr_data
.dbline 123
; cursor_index++;
lds R24,_cursor_index
lds R25,_cursor_index+1
adiw R24,1
sts _cursor_index+1,R25
sts _cursor_index,R24
.dbline 125
; //PORTD=0x4f;
; lcd_delay(50);
ldi R16,50
ldi R17,0
xcall _lcd_delay
.dbline -2
L16:
.dbline 0 ; func end
ld R10,y+
ret
.dbsym l flags 1 c
.dbsym r data 10 c
.dbend
.dbfunc e cursor_home _cursor_home fV
.even
_cursor_home::
.dbline -1
.dbline 129
; }
;
; void cursor_home(void) //Move cursor to Home
; {
.dbline 130
; wr_instruction2(0x01);
ldi R16,1
xcall _wr_instruction2
.dbline 131
; lcd_delay(10);
ldi R16,10
ldi R17,0
xcall _lcd_delay
.dbline 132
; wr_instruction2(0x80);
ldi R16,128
xcall _wr_instruction2
.dbline 133
; ldelay(5);
ldi R16,5
ldi R17,0
xcall _ldelay
.dbline 134
; 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 138
; }
;
; void cursor_line1(void) //Move cursor to the first line
; {
.dbline 139
; wr_instruction2(0x80);
ldi R16,128
xcall _wr_instruction2
.dbline 140
; cursor_index=0;
clr R2
clr R3
sts _cursor_index+1,R3
sts _cursor_index,R2
.dbline 141
; 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 145
; }
;
; void cursor_line2(void) //Move cursor to the second line
; {
.dbline 146
; wr_instruction2(0b11000000);
ldi R16,192
xcall _wr_instruction2
.dbline 147
; cursor_index=0x40;
ldi R24,64
ldi R25,0
sts _cursor_index+1,R25
sts _cursor_index,R24
.dbline 148
; 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 152
; }
;
; void space(void) //Write space, ' ', on the panel
; {
.dbline 153
; 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 157
; }
;
; void out_string(const char array[]) //Send a string stored in array to LCD panel
; {
.dbline 158
; int i=0;
clr R20
clr R21
.dbline 160
; unsigned char onechar;
; i=0;
xjmp L27
L26:
.dbline 162
; while(array[i])
; {
.dbline 163
; 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 164
; wr_data2(onechar);
mov R16,R12
xcall _wr_data2
.dbline 165
; }
L27:
.dbline 161
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 169
; }
;
; void lcd_on(void)
; {
.dbline 171
; unsigned char i, ctrl_data;
; ldelay(20);
ldi R16,20
ldi R17,0
xcall _ldelay
.dbline 172
; PORTD=0x01;
ldi R24,1
out 0x12,R24
.dbline 173
; ldelay(40);
ldi R16,40
ldi R17,0
xcall _ldelay
.dbline 174
; wr_instruction(0b00110000); //Function Set:set 8-bit, 2line, 5x7 fonts
ldi R16,48
xcall _wr_instruction
.dbline 175
; ldelay(2);
ldi R16,2
ldi R17,0
xcall _ldelay
.dbline 176
; wr_instruction(0b00110000); //
ldi R16,48
xcall _wr_instruction
.dbline 177
; ldelay(2);
ldi R16,2
ldi R17,0
xcall _ldelay
.dbline 178
; wr_instruction(0b00110000); //
ldi R16,48
xcall _wr_instruction
.dbline 179
; lcd_delay(80);
ldi R16,80
ldi R17,0
xcall _lcd_delay
.dbline 180
; wr_instruction(0b00111100); //8-bit, 2 lines, 5x7 font
ldi R16,60
xcall _wr_instruction
.dbline 181
; lcd_delay(20);
ldi R16,20
ldi R17,0
xcall _lcd_delay
.dbline 182
; wr_instruction(0b00001110); //display on, cursor on, blink off
ldi R16,14
xcall _wr_instruction
.dbline 183
; lcd_delay(20);
ldi R16,20
ldi R17,0
xcall _lcd_delay
.dbline 184
; wr_instruction(0b00001110); //display on,
ldi R16,14
xcall _wr_instruction
.dbline 185
; lcd_delay(20);
ldi R16,20
ldi R17,0
xcall _lcd_delay
.dbline 186
; wr_instruction(0b00000001); //clear display
ldi R16,1
xcall _wr_instruction
.dbline 187
; ldelay(5);
ldi R16,5
ldi R17,0
xcall _ldelay
.dbline 188
; wr_instruction(0b00000110); //Entry mode
ldi R16,6
xcall _wr_instruction
.dbline 189
; lcd_delay(10);
ldi R16,10
ldi R17,0
xcall _lcd_delay
.dbline 190
; wr_instruction(0b00000001); //clear display
ldi R16,1
xcall _wr_instruction
.dbline 191
; lcd_delay(20);
ldi R16,20
ldi R17,0
xcall _lcd_delay
.dbline -2
L29:
.dbline 0 ; func end
ret
.dbsym l ctrl_data 1 c
.dbsym l i 1 c
.dbend
.area bss(ram, con, rel)
.dbfile C:\+samples-16small\DEMOA-16sm\LCD-16sn.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
; }
; //***********************************************************
;
; // **********************************************************
; // Main program
; /*
; void main(void)
; {
; unsigned char data, pfin, dark, darkfg=0xff;
; int i=0;
; unsigned char j, jsave, array1[10];
; int a;
; CLI();
; port_init();
; WDT_off();
; ldelay(200);
; lcd_on();
; PORTD=0x50;
; ldelay(50);
; PORTD=0x05;
; ldelay(50);
; out_string(message1);
; cursor_line2();
; out_string(message2);
; PORTD=0x55;
; PORTA=0xF8;
; PORTB=0x00;
; ldelay(100);
;
; while(1)
; {
; WDR();
; swin=PINC&0x30;
; swin=(swin>>4)&0x03;
;
;
; if(swin2!=swin)
; {
; PORTD=swin;
; swin2=swin;
; if(swin==0x00)
; {
; cursor_home();
; out_string(message1);
; cursor_line2();
; out_string(message2);
; }
; else if(swin==0x01)
; {
; cursor_home();
; out_string(message3);
; cursor_line2();
; out_string(message4);
; }
; else if(swin==0x02)
; {
; cursor_home();
; out_string(message5);
; cursor_line2();
; out_string(message6);
; }
; else
; {
; cursor_home();
; out_string(message7);
; cursor_line2();
; out_string(message8);
; }
; }
; ldelay(10);
; }
; }*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?