⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demob-16sm.lst

📁 大量ATMEGA16实例, 都可以运行,包括驱动LCD1602, 上位机显示等多功能
💻 LST
📖 第 1 页 / 共 2 页
字号:
     1C8 2755      CLR	R21
     1C9 C002      RJMP	0x01CC
     1CA 5F4F      SUBI	R20,0xFF
     1CB 4F5F      SBCI	R21,0xFF
     1CC 154A      CP	R20,R10
     1CD 055B      CPC	R21,R11
     1CE F3DC      BLT	0x01CA
     1CF 940C 02EC JMP	pop_xgset300C
_ldelay:
  i                    --> R20
  ms                   --> R10
     1D1 940E 02E7 CALL	push_xgset300C
     1D3 0158      MOVW	R10,R16
(0050) 			 ;
(0051) }
(0052) 
(0053) void ldelay(int ms)
(0054) {
(0055)  int i;
(0056)  for(i=0; i<=ms; i++)
     1D4 2744      CLR	R20
     1D5 2755      CLR	R21
     1D6 C005      RJMP	0x01DC
(0057)  	 delay(0x2000);	  	  //2000-->4000
     1D7 E000      LDI	R16,0
     1D8 E210      LDI	R17,0x20
     1D9 DFE8      RCALL	_delay
     1DA 5F4F      SUBI	R20,0xFF
     1DB 4F5F      SBCI	R21,0xFF
     1DC 16A4      CP	R10,R20
     1DD 06B5      CPC	R11,R21
     1DE F7C4      BGE	0x01D7
     1DF 940C 02EC JMP	pop_xgset300C
_wr_instruction:
  instr                --> R10
     1E1 92AA      ST	R10,-Y
     1E2 2EA0      MOV	R10,R16
(0058) }		  
(0059) 
(0060) // ************************************************************
(0061) // LCD functions follows
(0062) 
(0063) //PORTB to LCD data port
(0064) //PORTA to LCD control port 
(0065) //PA0--> R/S
(0066) //PA1--> R/W
(0067) //PA2--> E
(0068) 
(0069) void wr_instruction(unsigned char instr)
(0070) {
(0071)  DDRA=0xff;
     1E3 EF8F      LDI	R24,0xFF
     1E4 BB8A      OUT	0x1A,R24
(0072)  delay(1);
     1E5 E001      LDI	R16,1
     1E6 E010      LDI	R17,0
     1E7 DFDA      RCALL	_delay
(0073)  PORTA=0b00000000;
     1E8 2422      CLR	R2
     1E9 BA2B      OUT	0x1B,R2
(0074)  PORTB=instr;	  		 //send out instruction
     1EA BAA8      OUT	0x18,R10
(0075)  delay(2);
     1EB E002      LDI	R16,2
     1EC E010      LDI	R17,0
     1ED DFD4      RCALL	_delay
(0076)  PORTA=0b00000100;		 //PA2<--1 LCD-E ON (enable)
     1EE E084      LDI	R24,4
     1EF BB8B      OUT	0x1B,R24
(0077)  delay(2);
     1F0 E002      LDI	R16,2
     1F1 E010      LDI	R17,0
     1F2 DFCF      RCALL	_delay
(0078)  PORTA=0b00000000; 		 //PA2<--0 LCD-E OFF (disable) 
     1F3 2422      CLR	R2
     1F4 BA2B      OUT	0x1B,R2
(0079)  delay(1);
     1F5 E001      LDI	R16,1
     1F6 E010      LDI	R17,0
     1F7 DFCA      RCALL	_delay
     1F8 90A9      LD	R10,Y+
     1F9 9508      RET
_wr_data:
  data                 --> R10
     1FA 92AA      ST	R10,-Y
     1FB 2EA0      MOV	R10,R16
(0080) }
(0081) 
(0082) void wr_data(unsigned char data)
(0083) {
(0084)  DDRA=0xff;
     1FC EF8F      LDI	R24,0xFF
     1FD BB8A      OUT	0x1A,R24
(0085)  PORTA=0b00000001;	  	  //PA0 <-- 1, Select data register
     1FE E081      LDI	R24,1
     1FF BB8B      OUT	0x1B,R24
(0086)  PORTB=data;			  //Send out data
     200 BAA8      OUT	0x18,R10
(0087)  delay(1);
     201 E001      LDI	R16,1
     202 E010      LDI	R17,0
     203 DFBE      RCALL	_delay
(0088)  PORTA=0b00000101;	  	  //Enable write to Data register
     204 E085      LDI	R24,5
     205 BB8B      OUT	0x1B,R24
(0089)  delay(2);
     206 E002      LDI	R16,2
     207 E010      LDI	R17,0
     208 DFB9      RCALL	_delay
(0090)  PORTA=0b00000000;		  //disable ????
     209 2422      CLR	R2
     20A BA2B      OUT	0x1B,R2
(0091)  delay(1);
     20B E001      LDI	R16,1
     20C E010      LDI	R17,0
     20D DFB4      RCALL	_delay
     20E 90A9      LD	R10,Y+
     20F 9508      RET
_wr_instruction2:
  flags                --> Y,+1
  instr                --> R10
     210 92AA      ST	R10,-Y
     211 2EA0      MOV	R10,R16
(0092) }
(0093) 
(0094) // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(0095) // Following functions for LCD panel control
(0096) 
(0097) void wr_instruction2(unsigned char instr)
(0098) {
(0099)  unsigned char flags;
(0100)   delay(10);
     212 E00A      LDI	R16,0xA
     213 E010      LDI	R17,0
     214 DFAD      RCALL	_delay
(0101)   wr_instruction(instr);
     215 2D0A      MOV	R16,R10
     216 DFCA      RCALL	_wr_instruction
(0102)   delay(10);
     217 E00A      LDI	R16,0xA
     218 E010      LDI	R17,0
     219 DFA8      RCALL	_delay
     21A 90A9      LD	R10,Y+
     21B 9508      RET
_wr_data2:
  flags                --> Y,+1
  data                 --> R10
     21C 92AA      ST	R10,-Y
     21D 2EA0      MOV	R10,R16
(0103) }
(0104) 
(0105) void wr_data2(unsigned char data)
(0106) {
(0107)  unsigned char flags;
(0108)  if(cursor_index==0x10)
     21E 9180 020E LDS	R24,cursor_index
     220 9190 020F LDS	R25,cursor_index+1
     222 3180      CPI	R24,0x10
     223 E0E0      LDI	R30,0
     224 079E      CPC	R25,R30
     225 F411      BNE	0x0228
(0109)     cursor_line2();
     226 D037      RCALL	_cursor_line2
     227 C009      RJMP	0x0231
(0110)  else if(cursor_index==0x50)
     228 9180 020E LDS	R24,cursor_index
     22A 9190 020F LDS	R25,cursor_index+1
     22C 3580      CPI	R24,0x50
     22D E0E0      LDI	R30,0
     22E 079E      CPC	R25,R30
     22F F409      BNE	0x0231
(0111)     cursor_line1();	
     230 D021      RCALL	_cursor_line1
(0112)  wr_data(data);
     231 2D0A      MOV	R16,R10
     232 DFC7      RCALL	_wr_data
(0113)  cursor_index++;
     233 9180 020E LDS	R24,cursor_index
     235 9190 020F LDS	R25,cursor_index+1
     237 9601      ADIW	R24,1
     238 9390 020F STS	cursor_index+1,R25
     23A 9380 020E STS	cursor_index,R24
(0114)  delay(50); 
     23C E302      LDI	R16,0x32
     23D E010      LDI	R17,0
     23E DF83      RCALL	_delay
     23F 90A9      LD	R10,Y+
     240 9508      RET
(0115)  }
(0116)  
(0117) void cursor_home(void)		//Move cursor to Home
(0118) {
(0119)  wr_instruction2(0x01);
_cursor_home:
     241 E001      LDI	R16,1
     242 DFCD      RCALL	_wr_instruction2
(0120)  delay(10);
     243 E00A      LDI	R16,0xA
     244 E010      LDI	R17,0
     245 DF7C      RCALL	_delay
(0121)  wr_instruction2(0x80);
     246 E800      LDI	R16,0x80
     247 DFC8      RCALL	_wr_instruction2
(0122)  ldelay(5);
     248 E005      LDI	R16,5
     249 E010      LDI	R17,0
     24A DF86      RCALL	_ldelay
(0123)  cursor_index=0;
     24B 2422      CLR	R2
     24C 2433      CLR	R3
     24D 9230 020F STS	cursor_index+1,R3
     24F 9220 020E STS	cursor_index,R2
     251 9508      RET
(0124) }
(0125)  
(0126) void cursor_line1(void)		//Move cursor to the first line 
(0127) {
(0128)  wr_instruction2(0x80);
_cursor_line1:
     252 E800      LDI	R16,0x80
     253 DFBC      RCALL	_wr_instruction2
(0129)  cursor_index=0;
     254 2422      CLR	R2
     255 2433      CLR	R3
     256 9230 020F STS	cursor_index+1,R3
     258 9220 020E STS	cursor_index,R2
(0130)  ldelay(5);
     25A E005      LDI	R16,5
     25B E010      LDI	R17,0
     25C DF74      RCALL	_ldelay
     25D 9508      RET
(0131) }
(0132) 
(0133) void cursor_line2(void)		//Move cursor to the second line
(0134) {
(0135)  wr_instruction2(0b11000000);
_cursor_line2:
     25E EC00      LDI	R16,0xC0
     25F DFB0      RCALL	_wr_instruction2
(0136)  cursor_index=0x40;
     260 E480      LDI	R24,0x40
     261 E090      LDI	R25,0
     262 9390 020F STS	cursor_index+1,R25
     264 9380 020E STS	cursor_index,R24
(0137)  ldelay(2);
     266 E002      LDI	R16,2
     267 E010      LDI	R17,0
     268 DF68      RCALL	_ldelay
     269 9508      RET
(0138) } 
(0139) 
(0140) void space(void)   			 //Write space, ' ', on the panel
(0141) {
(0142)  wr_data2(' ');
_space:
     26A E200      LDI	R16,0x20
     26B DFB0      RCALL	_wr_data2
     26C 9508      RET
_clear_line1:
  i                    --> R20
     26D 934A      ST	R20,-Y
     26E 935A      ST	R21,-Y
(0143)  }
(0144)  
(0145) void clear_line1(void)
(0146) {
(0147)  int i;
(0148)  cursor_line1();
     26F DFE2      RCALL	_cursor_line1
(0149)  for(i=0; i<=15; i++)
     270 2744      CLR	R20
     271 2755      CLR	R21
(0150)    space();
     272 DFF7      RCALL	_space
     273 5F4F      SUBI	R20,0xFF
     274 4F5F      SBCI	R21,0xFF
     275 E08F      LDI	R24,0xF
     276 E090      LDI	R25,0
     277 1784      CP	R24,R20
     278 0795      CPC	R25,R21
     279 F7C4      BGE	0x0272
(0151)  cursor_line1();  
     27A DFD7      RCALL	_cursor_line1
     27B 9159      LD	R21,Y+
     27C 9149      LD	R20,Y+
     27D 9508      RET
_clear_line2:
  i                    --> R20
     27E 934A      ST	R20,-Y
     27F 935A      ST	R21,-Y
(0152) }
(0153) 
(0154) void clear_line2(void)
(0155) {
(0156)  int i;
(0157)  cursor_line2();
     280 DFDD      RCALL	_cursor_line2
(0158)  for(i=0; i<=15; i++)
     281 2744      CLR	R20
     282 2755      CLR	R21
(0159)    space();
     283 DFE6      RCALL	_space
     284 5F4F      SUBI	R20,0xFF
     285 4F5F      SBCI	R21,0xFF
     286 E08F      LDI	R24,0xF
     287 E090      LDI	R25,0
     288 1784      CP	R24,R20
     289 0795      CPC	R25,R21
     28A F7C4      BGE	0x0283
(0160)  cursor_line2();  
     28B DFD2      RCALL	_cursor_line2
     28C 9159      LD	R21,Y+
     28D 9149      LD	R20,Y+
     28E 9508      RET
_out_string:
  onechar              --> R12
  i                    --> R20
  array                --> R10
     28F 940E 02F1 CALL	push_xgset303C
     291 0158      MOVW	R10,R16
(0161) } 
(0162) 
(0163)  
(0164) void out_string(const char array[])	 //Send a string stored in array to LCD panel
(0165) {
(0166)  int i=0;
     292 2744      CLR	R20
     293 2755      CLR	R21
(0167)  unsigned char onechar;
(0168)  i=0;
     294 C009      RJMP	0x029E
(0169)  while(array[i])
(0170)   {
(0171)    onechar=array[i++];
     295 011A      MOVW	R2,R20
     296 5F4F      SUBI	R20,0xFF
     297 4F5F      SBCI	R21,0xFF
     298 01F1      MOVW	R30,R2
     299 0DEA      ADD	R30,R10
     29A 1DFB      ADC	R31,R11
     29B 90C6      ELPM	R12,255(Z)
(0172)    wr_data2(onechar);
     29C 2D0C      MOV	R16,R12
     29D DF7E      RCALL	_wr_data2
     29E 01FA      MOVW	R30,R20
     29F 0DEA      ADD	R30,R10
     2A0 1DFB      ADC	R31,R11
     2A1 9026      ELPM	R2,-130(Z)
     2A2 2022      TST	R2
     2A3 F789      BNE	0x0295
     2A4 940C 02F8 JMP	pop_xgset303C
(0173)   }
(0174) }
(0175) 
(0176) void lcd_on(void)
(0177) {
(0178)  unsigned char i, ctrl_data;
(0179)  ldelay(20);
_lcd_on:
  ctrl_data            --> Y,+1
  i                    --> Y,+1
     2A6 E104      LDI	R16,0x14
     2A7 E010      LDI	R17,0
     2A8 DF28      RCALL	_ldelay
(0180)  PORTD=0x01;
     2A9 E081      LDI	R24,1
     2AA BB82      OUT	0x12,R24
(0181)  ldelay(40);
     2AB E208      LDI	R16,0x28
     2AC E010      LDI	R17,0
     2AD DF23      RCALL	_ldelay
(0182)  wr_instruction(0b00110000);   //Function Set:set 8-bit, 2line, 5x7 fonts
     2AE E300      LDI	R16,0x30
     2AF DF31      RCALL	_wr_instruction
(0183)  ldelay(2);
     2B0 E002      LDI	R16,2
     2B1 E010      LDI	R17,0
     2B2 DF1E      RCALL	_ldelay
(0184)  wr_instruction(0b00110000);   //
     2B3 E300      LDI	R16,0x30
     2B4 DF2C      RCALL	_wr_instruction
(0185)  ldelay(2);
     2B5 E002      LDI	R16,2
     2B6 E010      LDI	R17,0
     2B7 DF19      RCALL	_ldelay
(0186)  wr_instruction(0b00110000);   //
     2B8 E300      LDI	R16,0x30
     2B9 DF27      RCALL	_wr_instruction
(0187)  delay(80);
     2BA E500      LDI	R16,0x50
     2BB E010      LDI	R17,0
     2BC DF05      RCALL	_delay
(0188)  wr_instruction(0b00111100);   //8-bit, 2 lines, 5x7 font
     2BD E30C      LDI	R16,0x3C
     2BE DF22      RCALL	_wr_instruction
(0189)  delay(20);
     2BF E104      LDI	R16,0x14
     2C0 E010      LDI	R17,0
     2C1 DF00      RCALL	_delay
(0190)  wr_instruction(0b00001110);   //display on, cursor on, blink off
     2C2 E00E      LDI	R16,0xE
     2C3 DF1D      RCALL	_wr_instruction
(0191)  delay(20);
     2C4 E104      LDI	R16,0x14
     2C5 E010      LDI	R17,0
     2C6 DEFB      RCALL	_delay
(0192)  wr_instruction(0b00001110);   //display on, 
     2C7 E00E      LDI	R16,0xE
     2C8 DF18      RCALL	_wr_instruction
(0193)  delay(20);
     2C9 E104      LDI	R16,0x14
     2CA E010      LDI	R17,0
     2CB DEF6      RCALL	_delay
(0194)  wr_instruction(0b00000001);   //clear display
     2CC E001      LDI	R16,1
     2CD DF13      RCALL	_wr_instruction
(0195)  ldelay(5);
     2CE E005      LDI	R16,5
     2CF E010      LDI	R17,0
     2D0 DF00      RCALL	_ldelay
(0196)  wr_instruction(0b00000110);   //Entry mode
     2D1 E006      LDI	R16,6
     2D2 DF0E      RCALL	_wr_instruction
(0197)  delay(10);
     2D3 E00A      LDI	R16,0xA
     2D4 E010      LDI	R17,0
     2D5 DEEC      RCALL	_delay
(0198)  wr_instruction(0b00000001);   //clear display
     2D6 E001      LDI	R16,1
     2D7 DF09      RCALL	_wr_instruction
(0199)  delay(20);
FILE: <library>
     2D8 E104      LDI	R16,0x14
     2D9 E010      LDI	R17,0
     2DA DEE7      RCALL	_delay
     2DB 9508      RET
_memset:
     2DC 8188      LDD	R24,Y+0
     2DD 8199      LDD	R25,Y+1
     2DE 3080      CPI	R24,0
     2DF 0789      CPC	R24,R25
     2E0 F029      BEQ	0x02E6
     2E1 2FE0      MOV	R30,R16
     2E2 2FF1      MOV	R31,R17
     2E3 9321      ST	R18,Z+
     2E4 9701      SBIW	R24,1
     2E5 F7E9      BNE	0x02E3
     2E6 9508      RET
push_xgset300C:
     2E7 935A      ST	R21,-Y
     2E8 934A      ST	R20,-Y
     2E9 92BA      ST	R11,-Y
     2EA 92AA      ST	R10,-Y
     2EB 9508      RET
pop_xgset300C:
     2EC 90A9      LD	R10,Y+
     2ED 90B9      LD	R11,Y+
     2EE 9149      LD	R20,Y+
     2EF 9159      LD	R21,Y+
     2F0 9508      RET
push_xgset303C:
     2F1 935A      ST	R21,-Y
     2F2 934A      ST	R20,-Y
     2F3 92DA      ST	R13,-Y
     2F4 92CA      ST	R12,-Y
     2F5 92BA      ST	R11,-Y
     2F6 92AA      ST	R10,-Y
     2F7 9508      RET
pop_xgset303C:
     2F8 90A9      LD	R10,Y+
     2F9 90B9      LD	R11,Y+
     2FA 90C9      LD	R12,Y+
     2FB 90D9      LD	R13,Y+
     2FC 9149      LD	R20,Y+
     2FD 9159      LD	R21,Y+
     2FE 9508      RET

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -