📄 demoa-16sm.lst
字号:
(0068)
(0069) // ************************************************************
(0070) // LCD functions follows
(0071)
(0072) //PORTB to LCD data port
(0073) //PORTA to LCD control port
(0074) //PA0--> R/S
(0075) //PA1--> R/W
(0076) //PA2--> E
(0077)
(0078) void wr_instruction(unsigned char instr)
(0079) {
(0080) DDRA=0xff;
1BB EF8F LDI R24,0xFF
1BC BB8A OUT 0x1A,R24
(0081) lcd_delay(1);
1BD E001 LDI R16,1
1BE E010 LDI R17,0
1BF DFDA RCALL _lcd_delay
(0082) PORTA=0b00000000;
1C0 2422 CLR R2
1C1 BA2B OUT 0x1B,R2
(0083) PORTB=instr; //send out instruction
1C2 BAA8 OUT 0x18,R10
(0084) lcd_delay(2);
1C3 E002 LDI R16,2
1C4 E010 LDI R17,0
1C5 DFD4 RCALL _lcd_delay
(0085) PORTA=0b00000100; //PA2<--1 LCD-E ON (enable)
1C6 E084 LDI R24,4
1C7 BB8B OUT 0x1B,R24
(0086) lcd_delay(2);
1C8 E002 LDI R16,2
1C9 E010 LDI R17,0
1CA DFCF RCALL _lcd_delay
(0087) PORTA=0b00000000; //PA2<--0 LCD-E OFF (disable)
1CB 2422 CLR R2
1CC BA2B OUT 0x1B,R2
(0088) lcd_delay(1);
1CD E001 LDI R16,1
1CE E010 LDI R17,0
1CF DFCA RCALL _lcd_delay
1D0 90A9 LD R10,Y+
1D1 9508 RET
_wr_data:
data --> R10
1D2 92AA ST R10,-Y
1D3 2EA0 MOV R10,R16
(0089) }
(0090)
(0091) void wr_data(unsigned char data)
(0092) {
(0093) DDRA=0xff;
1D4 EF8F LDI R24,0xFF
1D5 BB8A OUT 0x1A,R24
(0094) PORTA=0b00000001; //PA0 <-- 1, Select data register
1D6 E081 LDI R24,1
1D7 BB8B OUT 0x1B,R24
(0095) PORTB=data; //Send out data
1D8 BAA8 OUT 0x18,R10
(0096) lcd_delay(1);
1D9 E001 LDI R16,1
1DA E010 LDI R17,0
1DB DFBE RCALL _lcd_delay
(0097) PORTA=0b00000101; //Enable write to Data register
1DC E085 LDI R24,5
1DD BB8B OUT 0x1B,R24
(0098) lcd_delay(2);
1DE E002 LDI R16,2
1DF E010 LDI R17,0
1E0 DFB9 RCALL _lcd_delay
(0099) PORTA=0b00000000; //disable ????
1E1 2422 CLR R2
1E2 BA2B OUT 0x1B,R2
(0100) lcd_delay(1);
1E3 E001 LDI R16,1
1E4 E010 LDI R17,0
1E5 DFB4 RCALL _lcd_delay
1E6 90A9 LD R10,Y+
1E7 9508 RET
_wr_instruction2:
flags --> Y,+1
instr --> R10
1E8 92AA ST R10,-Y
1E9 2EA0 MOV R10,R16
(0101) }
(0102)
(0103) // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(0104) // Following functions for LCD panel control
(0105)
(0106) void wr_instruction2(unsigned char instr)
(0107) {
(0108) unsigned char flags;
(0109) lcd_delay(10);
1EA E00A LDI R16,0xA
1EB E010 LDI R17,0
1EC DFAD RCALL _lcd_delay
(0110) wr_instruction(instr);
1ED 2D0A MOV R16,R10
1EE DFCA RCALL _wr_instruction
(0111) //PORTD=0x2f;
(0112) lcd_delay(10);
1EF E00A LDI R16,0xA
1F0 E010 LDI R17,0
1F1 DFA8 RCALL _lcd_delay
1F2 90A9 LD R10,Y+
1F3 9508 RET
_wr_data2:
flags --> Y,+1
data --> R10
1F4 92AA ST R10,-Y
1F5 2EA0 MOV R10,R16
(0113) }
(0114)
(0115) void wr_data2(unsigned char data)
(0116) {
(0117) unsigned char flags;
(0118) if(cursor_index==0x10)
1F6 9180 020A LDS R24,cursor_index
1F8 9190 020B LDS R25,cursor_index+1
1FA 3180 CPI R24,0x10
1FB E0E0 LDI R30,0
1FC 079E CPC R25,R30
1FD F411 BNE 0x0200
(0119) cursor_line2();
1FE D037 RCALL _cursor_line2
1FF C009 RJMP 0x0209
(0120) else if(cursor_index==0x50)
200 9180 020A LDS R24,cursor_index
202 9190 020B LDS R25,cursor_index+1
204 3580 CPI R24,0x50
205 E0E0 LDI R30,0
206 079E CPC R25,R30
207 F409 BNE 0x0209
(0121) cursor_line1();
208 D021 RCALL _cursor_line1
(0122) wr_data(data);
209 2D0A MOV R16,R10
20A DFC7 RCALL _wr_data
(0123) cursor_index++;
20B 9180 020A LDS R24,cursor_index
20D 9190 020B LDS R25,cursor_index+1
20F 9601 ADIW R24,1
210 9390 020B STS cursor_index+1,R25
212 9380 020A STS cursor_index,R24
(0124) //PORTD=0x4f;
(0125) lcd_delay(50);
214 E302 LDI R16,0x32
215 E010 LDI R17,0
216 DF83 RCALL _lcd_delay
217 90A9 LD R10,Y+
218 9508 RET
(0126) }
(0127)
(0128) void cursor_home(void) //Move cursor to Home
(0129) {
(0130) wr_instruction2(0x01);
_cursor_home:
219 E001 LDI R16,1
21A DFCD RCALL _wr_instruction2
(0131) lcd_delay(10);
21B E00A LDI R16,0xA
21C E010 LDI R17,0
21D DF7C RCALL _lcd_delay
(0132) wr_instruction2(0x80);
21E E800 LDI R16,0x80
21F DFC8 RCALL _wr_instruction2
(0133) ldelay(5);
220 E005 LDI R16,5
221 E010 LDI R17,0
222 DF86 RCALL _ldelay
(0134) cursor_index=0;
223 2422 CLR R2
224 2433 CLR R3
225 9230 020B STS cursor_index+1,R3
227 9220 020A STS cursor_index,R2
229 9508 RET
(0135) }
(0136)
(0137) void cursor_line1(void) //Move cursor to the first line
(0138) {
(0139) wr_instruction2(0x80);
_cursor_line1:
22A E800 LDI R16,0x80
22B DFBC RCALL _wr_instruction2
(0140) cursor_index=0;
22C 2422 CLR R2
22D 2433 CLR R3
22E 9230 020B STS cursor_index+1,R3
230 9220 020A STS cursor_index,R2
(0141) ldelay(5);
232 E005 LDI R16,5
233 E010 LDI R17,0
234 DF74 RCALL _ldelay
235 9508 RET
(0142) }
(0143)
(0144) void cursor_line2(void) //Move cursor to the second line
(0145) {
(0146) wr_instruction2(0b11000000);
_cursor_line2:
236 EC00 LDI R16,0xC0
237 DFB0 RCALL _wr_instruction2
(0147) cursor_index=0x40;
238 E480 LDI R24,0x40
239 E090 LDI R25,0
23A 9390 020B STS cursor_index+1,R25
23C 9380 020A STS cursor_index,R24
(0148) ldelay(2);
23E E002 LDI R16,2
23F E010 LDI R17,0
240 DF68 RCALL _ldelay
241 9508 RET
(0149) }
(0150)
(0151) void space(void) //Write space, ' ', on the panel
(0152) {
(0153) wr_data2(' ');
_space:
242 E200 LDI R16,0x20
243 DFB0 RCALL _wr_data2
244 9508 RET
_out_string:
onechar --> R12
i --> R20
array --> R10
245 940E 0410 CALL push_xgset303C
247 0158 MOVW R10,R16
(0154) }
(0155)
(0156) void out_string(const char array[]) //Send a string stored in array to LCD panel
(0157) {
(0158) int i=0;
248 2744 CLR R20
249 2755 CLR R21
(0159) unsigned char onechar;
(0160) i=0;
24A C009 RJMP 0x0254
(0161) while(array[i])
(0162) {
(0163) onechar=array[i++];
24B 011A MOVW R2,R20
24C 5F4F SUBI R20,0xFF
24D 4F5F SBCI R21,0xFF
24E 01F1 MOVW R30,R2
24F 0DEA ADD R30,R10
250 1DFB ADC R31,R11
251 90C6 ELPM R12,255(Z)
(0164) wr_data2(onechar);
252 2D0C MOV R16,R12
253 DFA0 RCALL _wr_data2
254 01FA MOVW R30,R20
255 0DEA ADD R30,R10
256 1DFB ADC R31,R11
257 9026 ELPM R2,-96(Z)
258 2022 TST R2
259 F789 BNE 0x024B
25A 940C 0417 JMP pop_xgset303C
(0165) }
(0166) }
(0167)
(0168) void lcd_on(void)
(0169) {
(0170) unsigned char i, ctrl_data;
(0171) ldelay(20);
_lcd_on:
ctrl_data --> Y,+1
i --> Y,+1
25C E104 LDI R16,0x14
25D E010 LDI R17,0
25E DF4A RCALL _ldelay
(0172) PORTD=0x01;
25F E081 LDI R24,1
260 BB82 OUT 0x12,R24
(0173) ldelay(40);
261 E208 LDI R16,0x28
262 E010 LDI R17,0
263 DF45 RCALL _ldelay
(0174) wr_instruction(0b00110000); //Function Set:set 8-bit, 2line, 5x7 fonts
264 E300 LDI R16,0x30
265 DF53 RCALL _wr_instruction
(0175) ldelay(2);
266 E002 LDI R16,2
267 E010 LDI R17,0
268 DF40 RCALL _ldelay
(0176) wr_instruction(0b00110000); //
269 E300 LDI R16,0x30
26A DF4E RCALL _wr_instruction
(0177) ldelay(2);
26B E002 LDI R16,2
26C E010 LDI R17,0
26D DF3B RCALL _ldelay
(0178) wr_instruction(0b00110000); //
26E E300 LDI R16,0x30
26F DF49 RCALL _wr_instruction
(0179) lcd_delay(80);
270 E500 LDI R16,0x50
271 E010 LDI R17,0
272 DF27 RCALL _lcd_delay
(0180) wr_instruction(0b00111100); //8-bit, 2 lines, 5x7 font
273 E30C LDI R16,0x3C
274 DF44 RCALL _wr_instruction
(0181) lcd_delay(20);
275 E104 LDI R16,0x14
276 E010 LDI R17,0
277 DF22 RCALL _lcd_delay
(0182) wr_instruction(0b00001110); //display on, cursor on, blink off
278 E00E LDI R16,0xE
279 DF3F RCALL _wr_instruction
(0183) lcd_delay(20);
27A E104 LDI R16,0x14
27B E010 LDI R17,0
27C DF1D RCALL _lcd_delay
(0184) wr_instruction(0b00001110); //display on,
27D E00E LDI R16,0xE
27E DF3A RCALL _wr_instruction
(0185) lcd_delay(20);
27F E104 LDI R16,0x14
280 E010 LDI R17,0
281 DF18 RCALL _lcd_delay
(0186) wr_instruction(0b00000001); //clear display
282 E001 LDI R16,1
283 DF35 RCALL _wr_instruction
(0187) ldelay(5);
284 E005 LDI R16,5
285 E010 LDI R17,0
286 DF22 RCALL _ldelay
(0188) wr_instruction(0b00000110); //Entry mode
287 E006 LDI R16,6
288 DF30 RCALL _wr_instruction
(0189) lcd_delay(10);
289 E00A LDI R16,0xA
28A E010 LDI R17,0
28B DF0E RCALL _lcd_delay
(0190) wr_instruction(0b00000001); //clear display
28C E001 LDI R16,1
28D DF2B RCALL _wr_instruction
(0191) lcd_delay(20);
28E E104 LDI R16,0x14
28F E010 LDI R17,0
290 DF09 RCALL _lcd_delay
291 9508 RET
_delay:
i --> R20
j --> R22
count --> R16
292 940E 0406 CALL push_xgsetF000
FILE: C:\+samples-16small\DEMOA-16sm\SegDisp-16sn.c
(0001) // Title: SegDisp-16sn.c
(0002) // Function program for DEMOA-16sm utilizing 4x7-segment display
(0003)
(0004) #include <iom16v.h>
(0005) #include <macros.h>
(0006)
(0007) extern void port_init(void);
(0008) const char dig0 = 0x40, dig1 = 0x80, dig2=0x10, dig3=0x08, dot=0x20;
(0009) char segconv[]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
(0010) unsigned char BCD0, BCD1, BCD2, BCD3;
(0011) int count;
(0012) int led_index=0, time_over=0;
(0013) unsigned char swin3;
(0014)
(0015) char pattern1[]= {0x01, 0x03, 0x07, 0x0F, 0x1f, 0x3f, 0x7f, 0xff, 0x7f,
(0016) 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01};
(0017) char pattern2[]= {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x40,
(0018) 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
(0019) char pattern3[]= {0x01, 0x80, 0x02, 0x40, 0x04, 0x20, 0x08, 0x10, 0x10,
(0020) 0x08, 0x20, 0x04, 0x40, 0x02, 0x80};
(0021) char pattern4[]= {0x11, 0x22, 0x44, 0x88, 0x44, 0x22, 0x11, 0x22, 0x44,
(0022) 0x88, 0x44, 0x22, 0x11, 0x00, 0x00};
(0023)
(0024) void delay(int count)
(0025) {
(0026) int i, j;
(0027) for(i=count; i>0; i--)
294 01A8 MOVW R20,R16
295 C00B RJMP 0x02A1
(0028) for(j=3; j>0; j--)
296 E063 LDI R22,3
297 E070 LDI R23,0
298 5061 SUBI R22,1
299 4070 SBCI R23,0
29A 2422 CLR R2
29B 2433 CLR R3
29C 1626 CP R2,R22
29D 0637 CPC R3,R23
29E F3CC BLT 0x0298
29F 5041 SUBI R20,1
2A0 4050 SBCI R21,0
2A1 2422 CLR R2
2A2 2433 CLR R3
2A3 1624 CP R2,R20
2A4 0635 CPC R3,R21
2A5 F384 BLT 0x0296
2A6 940C 040B JMP pop_xgsetF000
(0029) ;
(0030) }
(0031)
(0032) //*****************************************************************
(0033)
(0034) void led_disp(void)
(0035) {
(0036) if(time_over>=10)
_led_disp:
2A8 9180 0218 LDS R24,time_over
2AA 9190 0219 LDS R25,time_over+1
2AC 308A CPI R24,0xA
2AD E0E0 LDI R30,0
2AE 079E CPC R25,R30
2AF F40C BGE 0x02B1
2B0 C05A RJMP 0x030B
(0037) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -