lcd-16sm.lst
来自「大量ATMEGA16实例, 都可以运行,包括驱动LCD1602, 上位机显示等多」· LST 代码 · 共 733 行 · 第 1/2 页
LST
733 行
__text_start:
__start:
B7 EFCF LDI R28,0xFF
B8 E2D1 LDI R29,0x21
B9 BFCD OUT 0x3D,R28
BA BFDE OUT 0x3E,R29
BB 51CE SUBI R28,0x1E
BC 40D0 SBCI R29,0
BD EA0A LDI R16,0xAA
BE 8308 STD Y+0,R16
BF 2400 CLR R0
C0 E0EC LDI R30,0xC
C1 E0F2 LDI R31,2
C2 E012 LDI R17,2
C3 31E0 CPI R30,0x10
C4 07F1 CPC R31,R17
C5 F011 BEQ 0x00C8
C6 9201 ST R0,Z+
C7 CFFB RJMP 0x00C3
C8 8300 STD Z+0,R16
C9 E6E1 LDI R30,0x61
CA E0F1 LDI R31,1
CB E0A0 LDI R26,0
CC E0B2 LDI R27,2
CD E011 LDI R17,1
CE E000 LDI R16,0
CF BF0B OUT 0x3B,R16
D0 36ED CPI R30,0x6D
D1 07F1 CPC R31,R17
D2 F021 BEQ 0x00D7
D3 95C8 LPM
D4 9631 ADIW R30,1
D5 920D ST R0,X+
D6 CFF9 RJMP 0x00D0
D7 940E 01E0 CALL _main
_exit:
D9 CFFF RJMP _exit
FILE: C:\+samples-16small\LCD-16sm\LCD-16sm.c
(0001) /*
(0002) Title: LCD-16sm.c
(0003) Connection:
(0004) Factory fixed setting:
(0005) PORTA:
(0006) PA0-PA2 LCD control
(0007) PA3-PA7 4x7-segment display control
(0008) Drive LED group2 (the right group of LED)
(0009) PORTB:
(0010) Shared by LCD and 4x7-segment displays
(0011) output 8-bit data to LCD or 8-bit data to 4x7-segment displays
(0012) PORTC:
(0013) shared by 8-bit dipswitch and 4 x touch switches + 4 buttons
(0014) receive inputs from dipswitch, touch switches and buttons
(0015) PORTD:
(0016) Drive LED group1 (the left group of LED)
(0017) Attention:
(0018) 1. J12 should be capped (connectted)
(0019) 2. J5 is the Jump for LCD back light power
(0020)
(0021) Operation:
(0022) LCD panel display messages
(0023) Four messages can be displayed
(0024) which message displayed is controlled by SW4 and SW5
(0025) LED group1 display status of SW4 and SW5
(0026) */
(0027)
(0028) #include <iom16v.h>
(0029) #include <macros.h>
(0030) #include <stdlib.h>
(0031)
(0032) unsigned char lcd_enable = 0b00000001, lcd_disable = 0b11111110;
(0033) unsigned char in_instr_wr = 0b00000000, in_data_wr = 0b00000100;
(0034) unsigned char in_instr_rd = 0b00000010, in_data_rd = 0b00000110;
(0035)
(0036) void wr_instruction(unsigned char instr);
(0037) void wr_data(unsigned char data);
(0038)
(0039) int indexhead=0, indextail=0, indexcount;
(0040) int cursor_index=0;
(0041)
(0042)
(0043) const char message1[]= {" Hello World!"};
(0044) const char message2[]= {"www.inovacs.com"};
(0045) const char message3[]= {" Happy New Year"};
(0046) const char message4[]= {" 2008 is coming"};
(0047) const char message5[]= {" Greeting From"};
(0048) const char message6[]= {"www.inovacs.com"};
(0049) const char message7[]= {"Contact Inova"};
(0050) const char message8[]= {"Tel:0592 5563570"};
(0051)
(0052) void cursor_home(void);
(0053) void cursor_line1(void);
(0054) void cursor_line2(void);
(0055) int ifr_decode(void);
(0056) unsigned char swin, swin2;
(0057) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(0058) // Initilization file
(0059)
(0060) void port_init(void)
(0061) {
(0062) DDRA = 0xff; //PA0-PA2 for LCD control
_port_init:
DA EF8F LDI R24,0xFF
DB BB8A OUT 0x1A,R24
(0063) DDRB = 0xff; //PB0-PB7 for LCD data
DC BB87 OUT 0x17,R24
(0064)
(0065) DDRD = 0xff; //Control LEDs on left group
DD BB81 OUT 0x11,R24
(0066) DDRC = 0x00; //Receive from dip-switch and button
DE 2422 CLR R2
DF BA24 OUT 0x14,R2
(0067) PORTC=0xff;
E0 BB85 OUT 0x15,R24
E1 9508 RET
(0068) }
(0069)
(0070) void WDT_off(void)
(0071) {
(0072) WDR();
_WDT_off:
E2 95A8 WDR
(0073) WDTCR=0b00010111;
E3 E187 LDI R24,0x17
E4 BD81 OUT 0x21,R24
(0074) WDTCR=0b00000111;
E5 E087 LDI R24,7
E6 BD81 OUT 0x21,R24
E7 9508 RET
_delay:
b --> R10
a --> R20
count --> R16
E8 940E 024C CALL push_xgset300C
(0075) }
(0076)
(0077) void delay(int count)
(0078) {
(0079) int a,b;
(0080) b=2*count;
EA 0158 MOVW R10,R16
EB 0CAA LSL R10
EC 1CBB ROL R11
(0081) for(a=0; a<b; a++)
ED 2744 CLR R20
EE 2755 CLR R21
EF C002 RJMP 0x00F2
F0 5F4F SUBI R20,0xFF
F1 4F5F SBCI R21,0xFF
F2 154A CP R20,R10
F3 055B CPC R21,R11
F4 F3DC BLT 0x00F0
F5 940C 0251 JMP pop_xgset300C
_ldelay:
i --> R20
ms --> R10
F7 940E 024C CALL push_xgset300C
F9 0158 MOVW R10,R16
(0082) ;
(0083) }
(0084)
(0085) void ldelay(int ms)
(0086) {
(0087) int i;
(0088) for(i=0; i<=ms; i++)
FA 2744 CLR R20
FB 2755 CLR R21
FC C005 RJMP 0x0102
(0089) delay(0x2000); //2000-->4000
FD E000 LDI R16,0
FE E210 LDI R17,0x20
FF DFE8 RCALL _delay
100 5F4F SUBI R20,0xFF
101 4F5F SBCI R21,0xFF
102 16A4 CP R10,R20
103 06B5 CPC R11,R21
104 F7C4 BGE 0x00FD
105 940C 0251 JMP pop_xgset300C
_wr_instruction:
instr --> R10
107 92AA ST R10,-Y
108 2EA0 MOV R10,R16
(0090) }
(0091)
(0092) // ************************************************************
(0093) // LCD functions follows
(0094)
(0095) //PORTB to LCD data port
(0096) //PORTA to LCD control port
(0097) //PA0--> R/S
(0098) //PA1--> R/W
(0099) //PA2--> E
(0100)
(0101) void wr_instruction(unsigned char instr)
(0102) {
(0103) DDRA=0xff;
109 EF8F LDI R24,0xFF
10A BB8A OUT 0x1A,R24
(0104) delay(1);
10B E001 LDI R16,1
10C E010 LDI R17,0
10D DFDA RCALL _delay
(0105) PORTA=0b00000000;
10E 2422 CLR R2
10F BA2B OUT 0x1B,R2
(0106) PORTB=instr; //send out instruction
110 BAA8 OUT 0x18,R10
(0107) delay(2);
111 E002 LDI R16,2
112 E010 LDI R17,0
113 DFD4 RCALL _delay
(0108) PORTA=0b00000100; //PA2<--1 LCD-E ON (enable)
114 E084 LDI R24,4
115 BB8B OUT 0x1B,R24
(0109) delay(2);
116 E002 LDI R16,2
117 E010 LDI R17,0
118 DFCF RCALL _delay
(0110) PORTA=0b00000000; //PA2<--0 LCD-E OFF (disable)
119 2422 CLR R2
11A BA2B OUT 0x1B,R2
(0111) delay(1);
11B E001 LDI R16,1
11C E010 LDI R17,0
11D DFCA RCALL _delay
11E 90A9 LD R10,Y+
11F 9508 RET
_wr_data:
data --> R10
120 92AA ST R10,-Y
121 2EA0 MOV R10,R16
(0112) }
(0113)
(0114) void wr_data(unsigned char data)
(0115) {
(0116) DDRA=0xff;
122 EF8F LDI R24,0xFF
123 BB8A OUT 0x1A,R24
(0117) PORTA=0b00000001; //PA0 <-- 1, Select data register
124 E081 LDI R24,1
125 BB8B OUT 0x1B,R24
(0118) PORTB=data; //Send out data
126 BAA8 OUT 0x18,R10
(0119) delay(1);
127 E001 LDI R16,1
128 E010 LDI R17,0
129 DFBE RCALL _delay
(0120) PORTA=0b00000101; //Enable write to Data register
12A E085 LDI R24,5
12B BB8B OUT 0x1B,R24
(0121) delay(2);
12C E002 LDI R16,2
12D E010 LDI R17,0
12E DFB9 RCALL _delay
(0122) PORTA=0b00000000; //disable ????
12F 2422 CLR R2
130 BA2B OUT 0x1B,R2
(0123) delay(1);
131 E001 LDI R16,1
132 E010 LDI R17,0
133 DFB4 RCALL _delay
134 90A9 LD R10,Y+
135 9508 RET
_wr_instruction2:
flags --> Y,+1
instr --> R10
136 92AA ST R10,-Y
137 2EA0 MOV R10,R16
(0124) }
(0125)
(0126) // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(0127) // Following functions for LCD panel control
(0128)
(0129) void wr_instruction2(unsigned char instr)
(0130) {
(0131) unsigned char flags;
(0132) delay(10);
138 E00A LDI R16,0xA
139 E010 LDI R17,0
13A DFAD RCALL _delay
(0133) wr_instruction(instr);
13B 2D0A MOV R16,R10
13C DFCA RCALL _wr_instruction
(0134) delay(10);
13D E00A LDI R16,0xA
13E E010 LDI R17,0
13F DFA8 RCALL _delay
140 90A9 LD R10,Y+
141 9508 RET
_wr_data2:
flags --> Y,+1
data --> R10
142 92AA ST R10,-Y
143 2EA0 MOV R10,R16
(0135) }
(0136)
(0137) void wr_data2(unsigned char data)
(0138) {
(0139) unsigned char flags;
(0140) if(cursor_index==0x10)
144 9180 020A LDS R24,cursor_index
146 9190 020B LDS R25,cursor_index+1
148 3180 CPI R24,0x10
149 E0E0 LDI R30,0
14A 079E CPC R25,R30
14B F411 BNE 0x014E
(0141) cursor_line2();
14C D037 RCALL _cursor_line2
14D C009 RJMP 0x0157
(0142) else if(cursor_index==0x50)
14E 9180 020A LDS R24,cursor_index
150 9190 020B LDS R25,cursor_index+1
152 3580 CPI R24,0x50
153 E0E0 LDI R30,0
154 079E CPC R25,R30
155 F409 BNE 0x0157
(0143) cursor_line1();
156 D021 RCALL _cursor_line1
(0144) wr_data(data);
157 2D0A MOV R16,R10
158 DFC7 RCALL _wr_data
(0145) cursor_index++;
159 9180 020A LDS R24,cursor_index
15B 9190 020B LDS R25,cursor_index+1
15D 9601 ADIW R24,1
15E 9390 020B STS cursor_index+1,R25
160 9380 020A STS cursor_index,R24
(0146) delay(50);
162 E302 LDI R16,0x32
163 E010 LDI R17,0
164 DF83 RCALL _delay
165 90A9 LD R10,Y+
166 9508 RET
(0147) }
(0148)
(0149) void cursor_home(void) //Move cursor to Home
(0150) {
(0151) wr_instruction2(0x01);
_cursor_home:
167 E001 LDI R16,1
168 DFCD RCALL _wr_instruction2
(0152) delay(10);
169 E00A LDI R16,0xA
16A E010 LDI R17,0
16B DF7C RCALL _delay
(0153) wr_instruction2(0x80);
16C E800 LDI R16,0x80
16D DFC8 RCALL _wr_instruction2
(0154) ldelay(5);
16E E005 LDI R16,5
16F E010 LDI R17,0
170 DF86 RCALL _ldelay
(0155) cursor_index=0;
171 2422 CLR R2
172 2433 CLR R3
173 9230 020B STS cursor_index+1,R3
175 9220 020A STS cursor_index,R2
177 9508 RET
(0156) }
(0157)
(0158) void cursor_line1(void) //Move cursor to the first line
(0159) {
(0160) wr_instruction2(0x80);
_cursor_line1:
178 E800 LDI R16,0x80
179 DFBC RCALL _wr_instruction2
(0161) cursor_index=0;
17A 2422 CLR R2
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?