lcd-16sm.s
来自「大量ATMEGA16实例, 都可以运行,包括驱动LCD1602, 上位机显示等多」· S 代码 · 共 1,093 行 · 第 1/2 页
S
1,093 行
.module LCD-16sm.c
.area text(rom, con, rel)
.dbfile C:\+samples-16small\LCD-16sm\LCD-16sm.c
.area data(ram, con, rel)
.dbfile C:\+samples-16small\LCD-16sm\LCD-16sm.c
_lcd_enable::
.blkb 1
.area idata
.byte 1
.area data(ram, con, rel)
.dbfile C:\+samples-16small\LCD-16sm\LCD-16sm.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\LCD-16sm\LCD-16sm.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\LCD-16sm\LCD-16sm.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\LCD-16sm\LCD-16sm.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\LCD-16sm\LCD-16sm.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\LCD-16sm\LCD-16sm.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\LCD-16sm\LCD-16sm.c
.dbsym e indexhead _indexhead I
_indextail::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile C:\+samples-16small\LCD-16sm\LCD-16sm.c
.dbsym e indextail _indextail I
_cursor_index::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile C:\+samples-16small\LCD-16sm\LCD-16sm.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\LCD-16sm\LCD-16sm.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 61
; /*
; Title: LCD-16sm.c
; Connection:
; Factory fixed setting:
; PORTA:
; PA0-PA2 LCD control
; PA3-PA7 4x7-segment display control
; Drive LED group2 (the right group of LED)
; PORTB:
; Shared by LCD and 4x7-segment displays
; output 8-bit data to LCD or 8-bit data to 4x7-segment displays
; PORTC:
; shared by 8-bit dipswitch and 4 x touch switches + 4 buttons
; receive inputs from dipswitch, touch switches and buttons
; PORTD:
; Drive LED group1 (the left group of LED)
; Attention:
; 1. J12 should be capped (connectted)
; 2. J5 is the Jump for LCD back light power
;
; Operation:
; LCD panel display messages
; Four messages can be displayed
; which message displayed is controlled by SW4 and SW5
; LED group1 display status of SW4 and SW5
; */
;
; #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);
; int ifr_decode(void);
; unsigned char swin, swin2;
; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; // Initilization file
;
; void port_init(void)
; {
.dbline 62
; DDRA = 0xff; //PA0-PA2 for LCD control
ldi R24,255
out 0x1a,R24
.dbline 63
; DDRB = 0xff; //PB0-PB7 for LCD data
out 0x17,R24
.dbline 65
;
; DDRD = 0xff; //Control LEDs on left group
out 0x11,R24
.dbline 66
; DDRC = 0x00; //Receive from dip-switch and button
clr R2
out 0x14,R2
.dbline 67
; 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 71
; }
;
; void WDT_off(void)
; {
.dbline 72
; WDR();
wdr
.dbline 73
; WDTCR=0b00010111;
ldi R24,23
out 0x21,R24
.dbline 74
; WDTCR=0b00000111;
ldi R24,7
out 0x21,R24
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay _delay fV
; b -> R10,R11
; a -> R20,R21
; count -> R16,R17
.even
_delay::
xcall push_xgset300C
.dbline -1
.dbline 78
; }
;
; void delay(int count)
; {
.dbline 80
; int a,b;
; b=2*count;
movw R10,R16
lsl R10
rol R11
.dbline 81
; for(a=0; a<b; a++)
clr R20
clr R21
xjmp L7
L4:
.dbline 82
; ;
L5:
.dbline 81
subi R20,255 ; offset = 1
sbci R21,255
L7:
.dbline 81
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 86
; }
;
; void ldelay(int ms)
; {
.dbline 88
; int i;
; for(i=0; i<=ms; i++)
clr R20
clr R21
xjmp L12
L9:
.dbline 89
; delay(0x2000); //2000-->4000
ldi R16,8192
ldi R17,32
xcall _delay
L10:
.dbline 88
subi R20,255 ; offset = 1
sbci R21,255
L12:
.dbline 88
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 102
; }
;
; // ************************************************************
; // 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 103
; DDRA=0xff;
ldi R24,255
out 0x1a,R24
.dbline 104
; delay(1);
ldi R16,1
ldi R17,0
xcall _delay
.dbline 105
; PORTA=0b00000000;
clr R2
out 0x1b,R2
.dbline 106
; PORTB=instr; //send out instruction
out 0x18,R10
.dbline 107
; delay(2);
ldi R16,2
ldi R17,0
xcall _delay
.dbline 108
; PORTA=0b00000100; //PA2<--1 LCD-E ON (enable)
ldi R24,4
out 0x1b,R24
.dbline 109
; delay(2);
ldi R16,2
ldi R17,0
xcall _delay
.dbline 110
; PORTA=0b00000000; //PA2<--0 LCD-E OFF (disable)
clr R2
out 0x1b,R2
.dbline 111
; delay(1);
ldi R16,1
ldi R17,0
xcall _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 115
; }
;
; void wr_data(unsigned char data)
; {
.dbline 116
; DDRA=0xff;
ldi R24,255
out 0x1a,R24
.dbline 117
; PORTA=0b00000001; //PA0 <-- 1, Select data register
ldi R24,1
out 0x1b,R24
.dbline 118
; PORTB=data; //Send out data
out 0x18,R10
.dbline 119
; delay(1);
ldi R16,1
ldi R17,0
xcall _delay
.dbline 120
; PORTA=0b00000101; //Enable write to Data register
ldi R24,5
out 0x1b,R24
.dbline 121
; delay(2);
ldi R16,2
ldi R17,0
xcall _delay
.dbline 122
; PORTA=0b00000000; //disable ????
clr R2
out 0x1b,R2
.dbline 123
; delay(1);
ldi R16,1
ldi R17,0
xcall _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 130
; }
;
; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; // Following functions for LCD panel control
;
; void wr_instruction2(unsigned char instr)
; {
.dbline 132
; unsigned char flags;
; delay(10);
ldi R16,10
ldi R17,0
xcall _delay
.dbline 133
; wr_instruction(instr);
mov R16,R10
xcall _wr_instruction
.dbline 134
; delay(10);
ldi R16,10
ldi R17,0
xcall _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>
; data -> R10
.even
_wr_data2::
st -y,R10
mov R10,R16
.dbline -1
.dbline 138
; }
;
; void wr_data2(unsigned char data)
; {
.dbline 140
; 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 141
; cursor_line2();
xcall _cursor_line2
xjmp L18
L17:
.dbline 142
; 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 143
; cursor_line1();
xcall _cursor_line1
L19:
L18:
.dbline 144
; wr_data(data);
mov R16,R10
xcall _wr_data
.dbline 145
; cursor_index++;
lds R24,_cursor_index
lds R25,_cursor_index+1
adiw R24,1
sts _cursor_index+1,R25
sts _cursor_index,R24
.dbline 146
; delay(50);
ldi R16,50
ldi R17,0
xcall _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 150
; }
;
; void cursor_home(void) //Move cursor to Home
; {
.dbline 151
; wr_instruction2(0x01);
ldi R16,1
xcall _wr_instruction2
.dbline 152
; delay(10);
ldi R16,10
ldi R17,0
xcall _delay
.dbline 153
; wr_instruction2(0x80);
ldi R16,128
xcall _wr_instruction2
.dbline 154
; ldelay(5);
ldi R16,5
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?