lcd-16sn.s
来自「大量ATMEGA16实例, 都可以运行,包括驱动LCD1602, 上位机显示等多」· S 代码 · 共 871 行 · 第 1/2 页
S
871 行
.module LCD-16sn.c
.area text(rom, con, rel)
.dbfile C:\+samples-16small\DEMOA-16sm\LCD-16sn.c
.area data(ram, con, rel)
.dbfile C:\+samples-16small\DEMOA-16sm\LCD-16sn.c
_lcd_enable::
.blkb 1
.area idata
.byte 1
.area data(ram, con, rel)
.dbfile C:\+samples-16small\DEMOA-16sm\LCD-16sn.c
.dbsym e lcd_enable _lcd_enable c
_lcd_disable::
.blkb 1
.area idata
.byte 254
.area data(ram, con, rel)
.dbfile C:\+samples-16small\DEMOA-16sm\LCD-16sn.c
.dbsym e lcd_disable _lcd_disable c
_in_instr_wr::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile C:\+samples-16small\DEMOA-16sm\LCD-16sn.c
.dbsym e in_instr_wr _in_instr_wr c
_in_data_wr::
.blkb 1
.area idata
.byte 4
.area data(ram, con, rel)
.dbfile C:\+samples-16small\DEMOA-16sm\LCD-16sn.c
.dbsym e in_data_wr _in_data_wr c
_in_instr_rd::
.blkb 1
.area idata
.byte 2
.area data(ram, con, rel)
.dbfile C:\+samples-16small\DEMOA-16sm\LCD-16sn.c
.dbsym e in_instr_rd _in_instr_rd c
_in_data_rd::
.blkb 1
.area idata
.byte 6
.area data(ram, con, rel)
.dbfile C:\+samples-16small\DEMOA-16sm\LCD-16sn.c
.dbsym e in_data_rd _in_data_rd c
_indexhead::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile C:\+samples-16small\DEMOA-16sm\LCD-16sn.c
.dbsym e indexhead _indexhead I
_indextail::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile C:\+samples-16small\DEMOA-16sm\LCD-16sn.c
.dbsym e indextail _indextail I
_cursor_index::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile C:\+samples-16small\DEMOA-16sm\LCD-16sn.c
.dbsym e cursor_index _cursor_index I
.area lit(rom, con, rel)
_message1::
.byte 32,32,'H,'e,'l,'l,'o,32,'W,'o,'r,'l,'d,33,0
.dbsym e message1 _message1 A[15:15]kc
_message2::
.byte 'w,'w,'w,46,'i,'n,'o,'v,'a,'c,'s,46,'c,'o,'m,0
.dbsym e message2 _message2 A[16:16]kc
_message3::
.byte 32,'H,'a,'p,'p,'y,32,'N,'e,'w,32,'Y,'e,'a,'r,0
.dbsym e message3 _message3 A[16:16]kc
_message4::
.byte 32,50,48,48,56,32,'i,'s,32,'c,'o,'m,'i,'n,'g,0
.dbsym e message4 _message4 A[16:16]kc
_message5::
.byte 32,'G,'r,'e,'e,'t,'i,'n,'g,32,'F,'r,'o,'m,0
.dbsym e message5 _message5 A[15:15]kc
_message6::
.byte 'w,'w,'w,46,'i,'n,'o,'v,'a,'c,'s,46,'c,'o,'m,0
.dbsym e message6 _message6 A[16:16]kc
_message7::
.byte 'C,'o,'n,'t,'a,'c,'t,32,'I,'n,'o,'v,'a,0
.dbsym e message7 _message7 A[14:14]kc
_message8::
.byte 'T,'e,'l,58,48,53,57,50,32,53,53,54,51,53,55,48
.byte 0
.dbsym e message8 _message8 A[17:17]kc
.area text(rom, con, rel)
.dbfile C:\+samples-16small\DEMOA-16sm\LCD-16sn.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 38
; // Title: LCD-16sn.c
; // Functon program for DEMOA-16sm utilizing LCD
;
; #include <iom16v.h>
; #include <macros.h>
; #include <stdlib.h>
;
; unsigned char lcd_enable = 0b00000001, lcd_disable = 0b11111110;
; unsigned char in_instr_wr = 0b00000000, in_data_wr = 0b00000100;
; unsigned char in_instr_rd = 0b00000010, in_data_rd = 0b00000110;
;
; void wr_instruction(unsigned char instr);
; void wr_data(unsigned char data);
;
; int indexhead=0, indextail=0, indexcount;
; int cursor_index=0;
;
;
; const char message1[]= {" Hello World!"};
; const char message2[]= {"www.inovacs.com"};
; const char message3[]= {" Happy New Year"};
; const char message4[]= {" 2008 is coming"};
; const char message5[]= {" Greeting From"};
; const char message6[]= {"www.inovacs.com"};
; const char message7[]= {"Contact Inova"};
; const char message8[]= {"Tel:0592 5563570"};
;
; void cursor_home(void);
; void cursor_line1(void);
; void cursor_line2(void);
; void lcd_delay(int);
;
; unsigned char swin, swin2;
; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; // Initilization file
;
; void port_init(void)
; {
.dbline 39
; DDRA = 0xff; //PA0-PA2 for LCD control
ldi R24,255
out 0x1a,R24
.dbline 40
; DDRB = 0xff; //PB0-PB7 for LCD data
out 0x17,R24
.dbline 42
;
; DDRD = 0xff; //Control LEDs on left group
out 0x11,R24
.dbline 43
; DDRC = 0x00; //Receive from dip-switch and button
clr R2
out 0x14,R2
.dbline 44
; PORTC=0xff;
out 0x15,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e WDT_off _WDT_off fV
.even
_WDT_off::
.dbline -1
.dbline 48
; }
;
; void WDT_off(void)
; {
.dbline 49
; WDR();
wdr
.dbline 50
; WDTCR=0b00010111;
ldi R24,23
out 0x21,R24
.dbline 51
; WDTCR=0b00000111;
ldi R24,7
out 0x21,R24
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e lcd_delay _lcd_delay fV
; b -> R10,R11
; a -> R20,R21
; count -> R16,R17
.even
_lcd_delay::
xcall push_xgset300C
.dbline -1
.dbline 55
; }
;
; void lcd_delay(int count)
; {
.dbline 57
; int a,b;
; b=2*count;
movw R10,R16
lsl R10
rol R11
.dbline 58
; for(a=0; a<b; a++)
clr R20
clr R21
xjmp L7
L4:
.dbline 59
; ;
L5:
.dbline 58
subi R20,255 ; offset = 1
sbci R21,255
L7:
.dbline 58
cp R20,R10
cpc R21,R11
brlt L4
X0:
.dbline -2
L3:
.dbline 0 ; func end
xjmp pop_xgset300C
.dbsym r b 10 I
.dbsym r a 20 I
.dbsym r count 16 I
.dbend
.dbfunc e ldelay _ldelay fV
; i -> R20,R21
; ms -> R10,R11
.even
_ldelay::
xcall push_xgset300C
movw R10,R16
.dbline -1
.dbline 63
; }
;
; void ldelay(int ms)
; {
.dbline 65
; int i;
; for(i=0; i<=ms; i++)
clr R20
clr R21
xjmp L12
L9:
.dbline 66
; lcd_delay(0x2000); //2000-->4000
ldi R16,8192
ldi R17,32
xcall _lcd_delay
L10:
.dbline 65
subi R20,255 ; offset = 1
sbci R21,255
L12:
.dbline 65
cp R10,R20
cpc R11,R21
brge L9
X1:
.dbline -2
L8:
.dbline 0 ; func end
xjmp pop_xgset300C
.dbsym r i 20 I
.dbsym r ms 10 I
.dbend
.dbfunc e wr_instruction _wr_instruction fV
; instr -> R10
.even
_wr_instruction::
st -y,R10
mov R10,R16
.dbline -1
.dbline 79
; }
;
; // ************************************************************
; // LCD functions follows
;
; //PORTB to LCD data port
; //PORTA to LCD control port
; //PA0--> R/S
; //PA1--> R/W
; //PA2--> E
;
; void wr_instruction(unsigned char instr)
; {
.dbline 80
; DDRA=0xff;
ldi R24,255
out 0x1a,R24
.dbline 81
; lcd_delay(1);
ldi R16,1
ldi R17,0
xcall _lcd_delay
.dbline 82
; PORTA=0b00000000;
clr R2
out 0x1b,R2
.dbline 83
; PORTB=instr; //send out instruction
out 0x18,R10
.dbline 84
; lcd_delay(2);
ldi R16,2
ldi R17,0
xcall _lcd_delay
.dbline 85
; PORTA=0b00000100; //PA2<--1 LCD-E ON (enable)
ldi R24,4
out 0x1b,R24
.dbline 86
; lcd_delay(2);
ldi R16,2
ldi R17,0
xcall _lcd_delay
.dbline 87
; PORTA=0b00000000; //PA2<--0 LCD-E OFF (disable)
clr R2
out 0x1b,R2
.dbline 88
; lcd_delay(1);
ldi R16,1
ldi R17,0
xcall _lcd_delay
.dbline -2
L13:
.dbline 0 ; func end
ld R10,y+
ret
.dbsym r instr 10 c
.dbend
.dbfunc e wr_data _wr_data fV
; data -> R10
.even
_wr_data::
st -y,R10
mov R10,R16
.dbline -1
.dbline 92
; }
;
; void wr_data(unsigned char data)
; {
.dbline 93
; DDRA=0xff;
ldi R24,255
out 0x1a,R24
.dbline 94
; PORTA=0b00000001; //PA0 <-- 1, Select data register
ldi R24,1
out 0x1b,R24
.dbline 95
; PORTB=data; //Send out data
out 0x18,R10
.dbline 96
; lcd_delay(1);
ldi R16,1
ldi R17,0
xcall _lcd_delay
.dbline 97
; PORTA=0b00000101; //Enable write to Data register
ldi R24,5
out 0x1b,R24
.dbline 98
; lcd_delay(2);
ldi R16,2
ldi R17,0
xcall _lcd_delay
.dbline 99
; PORTA=0b00000000; //disable ????
clr R2
out 0x1b,R2
.dbline 100
; lcd_delay(1);
ldi R16,1
ldi R17,0
xcall _lcd_delay
.dbline -2
L14:
.dbline 0 ; func end
ld R10,y+
ret
.dbsym r data 10 c
.dbend
.dbfunc e wr_instruction2 _wr_instruction2 fV
; flags -> <dead>
; instr -> R10
.even
_wr_instruction2::
st -y,R10
mov R10,R16
.dbline -1
.dbline 107
; }
;
; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; // Following functions for LCD panel control
;
; void wr_instruction2(unsigned char instr)
; {
.dbline 109
; unsigned char flags;
; lcd_delay(10);
ldi R16,10
ldi R17,0
xcall _lcd_delay
.dbline 110
; wr_instruction(instr);
mov R16,R10
xcall _wr_instruction
.dbline 112
; //PORTD=0x2f;
; lcd_delay(10);
ldi R16,10
ldi R17,0
xcall _lcd_delay
.dbline -2
L15:
.dbline 0 ; func end
ld R10,y+
ret
.dbsym l flags 1 c
.dbsym r instr 10 c
.dbend
.dbfunc e wr_data2 _wr_data2 fV
; flags -> <dead>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?