lcd-16sm.lst
来自「大量ATMEGA16实例, 都可以运行,包括驱动LCD1602, 上位机显示等多」· LST 代码 · 共 733 行 · 第 1/2 页
LST
733 行
17B 2433 CLR R3
17C 9230 020B STS cursor_index+1,R3
17E 9220 020A STS cursor_index,R2
(0162) ldelay(5);
180 E005 LDI R16,5
181 E010 LDI R17,0
182 DF74 RCALL _ldelay
183 9508 RET
(0163) }
(0164)
(0165) void cursor_line2(void) //Move cursor to the second line
(0166) {
(0167) wr_instruction2(0b11000000);
_cursor_line2:
184 EC00 LDI R16,0xC0
185 DFB0 RCALL _wr_instruction2
(0168) cursor_index=0x40;
186 E480 LDI R24,0x40
187 E090 LDI R25,0
188 9390 020B STS cursor_index+1,R25
18A 9380 020A STS cursor_index,R24
(0169) ldelay(2);
18C E002 LDI R16,2
18D E010 LDI R17,0
18E DF68 RCALL _ldelay
18F 9508 RET
(0170) }
(0171)
(0172) void space(void) //Write space, ' ', on the panel
(0173) {
(0174) wr_data2(' ');
_space:
190 E200 LDI R16,0x20
191 DFB0 RCALL _wr_data2
192 9508 RET
_out_string:
onechar --> R12
i --> R20
array --> R10
193 940E 0256 CALL push_xgset303C
195 0158 MOVW R10,R16
(0175) }
(0176)
(0177) void out_string(const char array[]) //Send a string stored in array to LCD panel
(0178) {
(0179) int i=0;
196 2744 CLR R20
197 2755 CLR R21
(0180) unsigned char onechar;
(0181) i=0;
198 C009 RJMP 0x01A2
(0182) while(array[i])
(0183) {
(0184) onechar=array[i++];
199 011A MOVW R2,R20
19A 5F4F SUBI R20,0xFF
19B 4F5F SBCI R21,0xFF
19C 01F1 MOVW R30,R2
19D 0DEA ADD R30,R10
19E 1DFB ADC R31,R11
19F 90C6 ELPM R12,255(Z)
(0185) wr_data2(onechar);
1A0 2D0C MOV R16,R12
1A1 DFA0 RCALL _wr_data2
1A2 01FA MOVW R30,R20
1A3 0DEA ADD R30,R10
1A4 1DFB ADC R31,R11
1A5 9026 ELPM R2,-96(Z)
1A6 2022 TST R2
1A7 F789 BNE 0x0199
1A8 940C 025D JMP pop_xgset303C
(0186) }
(0187) }
(0188)
(0189) void lcd_on(void)
(0190) {
(0191) unsigned char i, ctrl_data;
(0192) ldelay(20);
_lcd_on:
ctrl_data --> Y,+1
i --> Y,+1
1AA E104 LDI R16,0x14
1AB E010 LDI R17,0
1AC DF4A RCALL _ldelay
(0193) PORTD=0x01;
1AD E081 LDI R24,1
1AE BB82 OUT 0x12,R24
(0194) ldelay(40);
1AF E208 LDI R16,0x28
1B0 E010 LDI R17,0
1B1 DF45 RCALL _ldelay
(0195) wr_instruction(0b00110000); //Function Set:set 8-bit, 2line, 5x7 fonts
1B2 E300 LDI R16,0x30
1B3 DF53 RCALL _wr_instruction
(0196) ldelay(2);
1B4 E002 LDI R16,2
1B5 E010 LDI R17,0
1B6 DF40 RCALL _ldelay
(0197) wr_instruction(0b00110000); //
1B7 E300 LDI R16,0x30
1B8 DF4E RCALL _wr_instruction
(0198) ldelay(2);
1B9 E002 LDI R16,2
1BA E010 LDI R17,0
1BB DF3B RCALL _ldelay
(0199) wr_instruction(0b00110000); //
1BC E300 LDI R16,0x30
1BD DF49 RCALL _wr_instruction
(0200) delay(80);
1BE E500 LDI R16,0x50
1BF E010 LDI R17,0
1C0 DF27 RCALL _delay
(0201) wr_instruction(0b00111100); //8-bit, 2 lines, 5x7 font
1C1 E30C LDI R16,0x3C
1C2 DF44 RCALL _wr_instruction
(0202) delay(20);
1C3 E104 LDI R16,0x14
1C4 E010 LDI R17,0
1C5 DF22 RCALL _delay
(0203) wr_instruction(0b00001110); //display on, cursor on, blink off
1C6 E00E LDI R16,0xE
1C7 DF3F RCALL _wr_instruction
(0204) delay(20);
1C8 E104 LDI R16,0x14
1C9 E010 LDI R17,0
1CA DF1D RCALL _delay
(0205) wr_instruction(0b00001110); //display on,
1CB E00E LDI R16,0xE
1CC DF3A RCALL _wr_instruction
(0206) delay(20);
1CD E104 LDI R16,0x14
1CE E010 LDI R17,0
1CF DF18 RCALL _delay
(0207) wr_instruction(0b00000001); //clear display
1D0 E001 LDI R16,1
1D1 DF35 RCALL _wr_instruction
(0208) ldelay(5);
1D2 E005 LDI R16,5
1D3 E010 LDI R17,0
1D4 DF22 RCALL _ldelay
(0209) wr_instruction(0b00000110); //Entry mode
1D5 E006 LDI R16,6
1D6 DF30 RCALL _wr_instruction
(0210) delay(10);
1D7 E00A LDI R16,0xA
1D8 E010 LDI R17,0
1D9 DF0E RCALL _delay
(0211) wr_instruction(0b00000001); //clear display
1DA E001 LDI R16,1
1DB DF2B RCALL _wr_instruction
(0212) delay(20);
1DC E104 LDI R16,0x14
1DD E010 LDI R17,0
1DE DF09 RCALL _delay
1DF 9508 RET
_main:
a --> Y,+1
array1 --> Y,+0
jsave --> Y,+1
j --> Y,+1
dark --> Y,+1
pfin --> Y,+1
data --> Y,+1
i --> R10
darkfg --> R20
1E0 972A SBIW R28,0xA
(0213) }
(0214) //***********************************************************
(0215)
(0216) // **********************************************************
(0217) // Main program
(0218) void main(void)
(0219) {
(0220) unsigned char data, pfin, dark, darkfg=0xff;
1E1 EF4F LDI R20,0xFF
(0221) int i=0;
1E2 24AA CLR R10
1E3 24BB CLR R11
(0222) unsigned char j, jsave, array1[10];
(0223) int a;
(0224) CLI();
1E4 94F8 BCLR 7
(0225) port_init();
1E5 DEF4 RCALL _port_init
(0226) WDT_off();
1E6 DEFB RCALL _WDT_off
(0227) ldelay(200);
1E7 EC08 LDI R16,0xC8
1E8 E010 LDI R17,0
1E9 DF0D RCALL _ldelay
(0228) lcd_on();
1EA DFBF RCALL _lcd_on
(0229) PORTD=0x50;
1EB E580 LDI R24,0x50
1EC BB82 OUT 0x12,R24
(0230) ldelay(50);
1ED E302 LDI R16,0x32
1EE E010 LDI R17,0
1EF DF07 RCALL _ldelay
(0231) PORTD=0x05;
1F0 E085 LDI R24,5
1F1 BB82 OUT 0x12,R24
(0232) ldelay(50);
1F2 E302 LDI R16,0x32
1F3 E010 LDI R17,0
1F4 DF02 RCALL _ldelay
(0233) out_string(message1);
1F5 EE04 LDI R16,0xE4
1F6 E010 LDI R17,0
1F7 DF9B RCALL _out_string
(0234) cursor_line2();
1F8 DF8B RCALL _cursor_line2
(0235) out_string(message2);
1F9 EF03 LDI R16,0xF3
1FA E010 LDI R17,0
1FB DF97 RCALL _out_string
(0236) PORTD=0x55;
1FC E585 LDI R24,0x55
1FD BB82 OUT 0x12,R24
(0237) PORTA=0xF8;
1FE EF88 LDI R24,0xF8
1FF BB8B OUT 0x1B,R24
(0238) PORTB=0x00;
200 2422 CLR R2
201 BA28 OUT 0x18,R2
(0239) ldelay(100);
202 E604 LDI R16,0x64
203 E010 LDI R17,0
204 DEF2 RCALL _ldelay
205 C043 RJMP 0x0249
(0240)
(0241) while(1)
(0242) {
(0243) WDR();
206 95A8 WDR
(0244) swin=PINC&0x30;
207 B383 IN R24,0x13
208 7380 ANDI R24,0x30
209 9380 020D STS swin,R24
(0245) swin=(swin>>4)&0x03;
20B 9582 SWAP R24
20C 708F ANDI R24,0xF
20D 7083 ANDI R24,3
20E 9380 020D STS swin,R24
(0246)
(0247)
(0248) if(swin2!=swin)
210 2E28 MOV R2,R24
211 9030 020C LDS R3,swin2
213 1638 CP R3,R24
214 F409 BNE 0x0216
215 C030 RJMP 0x0246
(0249) {
(0250) PORTD=swin;
216 BB82 OUT 0x12,R24
(0251) swin2=swin;
217 9220 020C STS swin2,R2
(0252) if(swin==0x00)
219 2388 TST R24
21A F449 BNE 0x0224
(0253) {
(0254) cursor_home();
21B DF4B RCALL _cursor_home
(0255) out_string(message1);
21C EE04 LDI R16,0xE4
21D E010 LDI R17,0
21E DF74 RCALL _out_string
(0256) cursor_line2();
21F DF64 RCALL _cursor_line2
(0257) out_string(message2);
220 EF03 LDI R16,0xF3
221 E010 LDI R17,0
222 DF70 RCALL _out_string
(0258) }
223 C022 RJMP 0x0246
(0259) else if(swin==0x01)
224 9180 020D LDS R24,swin
226 3081 CPI R24,1
227 F449 BNE 0x0231
(0260) {
(0261) cursor_home();
228 DF3E RCALL _cursor_home
(0262) out_string(message3);
229 E003 LDI R16,3
22A E011 LDI R17,1
22B DF67 RCALL _out_string
(0263) cursor_line2();
22C DF57 RCALL _cursor_line2
(0264) out_string(message4);
22D E103 LDI R16,0x13
22E E011 LDI R17,1
22F DF63 RCALL _out_string
(0265) }
230 C015 RJMP 0x0246
(0266) else if(swin==0x02)
231 9180 020D LDS R24,swin
233 3082 CPI R24,2
234 F449 BNE 0x023E
(0267) {
(0268) cursor_home();
235 DF31 RCALL _cursor_home
(0269) out_string(message5);
236 E203 LDI R16,0x23
237 E011 LDI R17,1
238 DF5A RCALL _out_string
(0270) cursor_line2();
239 DF4A RCALL _cursor_line2
(0271) out_string(message6);
23A E302 LDI R16,0x32
23B E011 LDI R17,1
23C DF56 RCALL _out_string
(0272) }
23D C008 RJMP 0x0246
(0273) else
(0274) {
(0275) cursor_home();
23E DF28 RCALL _cursor_home
(0276) out_string(message7);
23F E402 LDI R16,0x42
240 E011 LDI R17,1
241 DF51 RCALL _out_string
(0277) cursor_line2();
242 DF41 RCALL _cursor_line2
(0278) out_string(message8);
243 E500 LDI R16,0x50
244 E011 LDI R17,1
245 DF4D RCALL _out_string
(0279) }
(0280) }
(0281) ldelay(10);
FILE: <library>
246 E00A LDI R16,0xA
247 E010 LDI R17,0
248 DEAE RCALL _ldelay
249 CFBC RJMP 0x0206
24A 962A ADIW R28,0xA
24B 9508 RET
push_xgset300C:
24C 935A ST R21,-Y
24D 934A ST R20,-Y
24E 92BA ST R11,-Y
24F 92AA ST R10,-Y
250 9508 RET
pop_xgset300C:
251 90A9 LD R10,Y+
252 90B9 LD R11,Y+
253 9149 LD R20,Y+
254 9159 LD R21,Y+
255 9508 RET
push_xgset303C:
256 935A ST R21,-Y
257 934A ST R20,-Y
258 92DA ST R13,-Y
259 92CA ST R12,-Y
25A 92BA ST R11,-Y
25B 92AA ST R10,-Y
25C 9508 RET
pop_xgset303C:
25D 90A9 LD R10,Y+
25E 90B9 LD R11,Y+
25F 90C9 LD R12,Y+
260 90D9 LD R13,Y+
261 9149 LD R20,Y+
262 9159 LD R21,Y+
263 9508 RET
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?