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

📄 prj.lst

📁 ATMEGA128控制4×6矩阵键盘,LCD1602 使用protues软件可仿真 附带图片可观看效果
💻 LST
📖 第 1 页 / 共 3 页
字号:
(0091) temp=LCD_OP_PORT;
     10D B342      IN	R20,0x12
(0092) temp=temp&BIT3;
     10E 7048      ANDI	R20,0x8
(0093) LCD_OP_PORT=temp;
     10F BB42      OUT	0x12,R20
(0094) lcd_set_rw(); // Set LCD to READ
     110 9A91      SBI	0x12,1
(0095) lcd_clear_rs();
     111 9890      CBI	0x12,0
(0096) lcd_set_e();
     112 9A92      SBI	0x12,2
(0097) delay_nus(3);
     113 E003      LDI	R16,3
     114 E010      LDI	R17,0
     115 940E 0088 CALL	_delay_nus
(0098) high = LCD_IP_PORT; // read the high nibble.
     117 B2A0      IN	R10,0x10
(0099) lcd_clear_e(); // Disable LCD
     118 9892      CBI	0x12,2
(0100) lcd_set_e();
     119 9A92      SBI	0x12,2
(0101) asm("nop");
     11A 0000      NOP
(0102) asm("nop");
     11B 0000      NOP
(0103) low = LCD_IP_PORT; // read the low nibble.
     11C B2C0      IN	R12,0x10
(0104) lcd_clear_e(); // Disable LCD
     11D 9892      CBI	0x12,2
(0105) } while(high & 0x80);
     11E FCA7      SBRC	R10,7
     11F CFED      RJMP	0x010D
(0106) delay_nus(20);
     120 E104      LDI	R16,0x14
     121 E010      LDI	R17,0
     122 940E 0088 CALL	_delay_nus
     124 940C 0269 JMP	pop_xgset303C
_LCD_WriteControl:
  temp                 --> R20
  CMD                  --> R22
     126 934A      ST	R20,-Y
     127 936A      ST	R22,-Y
     128 2F60      MOV	R22,R16
(0107) }
(0108) // ********************************************** //
(0109) // *** Write a control instruction to the LCD *** //
(0110) // ********************************************** //
(0111) void LCD_WriteControl (unsigned char CMD)
(0112) {
(0113) char temp;
(0114) LCD_Busy(); // Test if LCD busy
     129 DFDF      RCALL	_LCD_Busy
(0115) LCD_DIR_PORT = 0xff; // LCD port output
     12A EF8F      LDI	R24,0xFF
     12B BB81      OUT	0x11,R24
(0116) temp=LCD_OP_PORT;
     12C B342      IN	R20,0x12
(0117) temp=temp&BIT3;
     12D 7048      ANDI	R20,0x8
(0118) LCD_OP_PORT =(CMD & 0xf0)|temp; // Load high-data to port
     12E 2F86      MOV	R24,R22
     12F 7F80      ANDI	R24,0xF0
     130 2B84      OR	R24,R20
     131 BB82      OUT	0x12,R24
(0119) lcd_clear_rw(); // Set LCD to write
     132 9891      CBI	0x12,1
(0120) lcd_clear_rs(); // Set LCD to command
     133 9890      CBI	0x12,0
(0121) lcd_set_e(); // Write data to LCD
     134 9A92      SBI	0x12,2
(0122) asm("nop");
     135 0000      NOP
(0123) asm("nop");
     136 0000      NOP
(0124) lcd_clear_e(); // Disable LCD
     137 9892      CBI	0x12,2
(0125) LCD_OP_PORT =(CMD<<4)|temp; // Load low-data to port
     138 2F86      MOV	R24,R22
     139 708F      ANDI	R24,0xF
     13A 9582      SWAP	R24
     13B 2B84      OR	R24,R20
     13C BB82      OUT	0x12,R24
(0126) lcd_clear_rw(); // Set LCD to write
     13D 9891      CBI	0x12,1
(0127) lcd_clear_rs(); // Set LCD to command
     13E 9890      CBI	0x12,0
(0128) lcd_set_e(); // Write data to LCD
     13F 9A92      SBI	0x12,2
(0129) asm("nop");
     140 0000      NOP
(0130) asm("nop");
     141 0000      NOP
(0131) lcd_clear_e(); // Disable LCD
     142 9892      CBI	0x12,2
     143 9169      LD	R22,Y+
     144 9149      LD	R20,Y+
     145 9508      RET
_LCD_WriteData:
  temp                 --> R20
  Data                 --> R22
     146 934A      ST	R20,-Y
     147 936A      ST	R22,-Y
     148 2F60      MOV	R22,R16
(0132) }
(0133) // ***************************************** //
(0134) // *** Write one byte of data to the LCD *** //
(0135) // ***************************************** //
(0136) void LCD_WriteData (unsigned char Data)
(0137) {
(0138) char temp;
(0139) LCD_Busy(); // Test if LCD Busy
     149 DFBF      RCALL	_LCD_Busy
(0140) LCD_DIR_PORT = 0xFF; // LCD port output
     14A EF8F      LDI	R24,0xFF
     14B BB81      OUT	0x11,R24
(0141) temp=LCD_OP_PORT;
     14C B342      IN	R20,0x12
(0142) temp=temp&BIT3;
     14D 7048      ANDI	R20,0x8
(0143) LCD_OP_PORT =(Data & 0xf0)|temp; // Load high-data to port
     14E 2F86      MOV	R24,R22
     14F 7F80      ANDI	R24,0xF0
     150 2B84      OR	R24,R20
     151 BB82      OUT	0x12,R24
(0144) lcd_clear_rw() ; // Set LCD to write
     152 9891      CBI	0x12,1
(0145) lcd_set_rs(); // Set LCD to data
     153 9A90      SBI	0x12,0
(0146) lcd_set_e(); // Write data to LCD
     154 9A92      SBI	0x12,2
(0147) asm("nop");
     155 0000      NOP
(0148) asm("nop");
     156 0000      NOP
(0149) lcd_clear_e(); // Disable LCD
     157 9892      CBI	0x12,2
(0150) LCD_OP_PORT = (Data << 4)|temp; // Load low-data to port
     158 2F86      MOV	R24,R22
     159 708F      ANDI	R24,0xF
     15A 9582      SWAP	R24
     15B 2B84      OR	R24,R20
     15C BB82      OUT	0x12,R24
(0151) lcd_clear_rw() ; // Set LCD to write
     15D 9891      CBI	0x12,1
(0152) lcd_set_rs(); // Set LCD to data
     15E 9A90      SBI	0x12,0
(0153) lcd_set_e(); // Write data to LCD
     15F 9A92      SBI	0x12,2
(0154) asm("nop");
     160 0000      NOP
(0155) asm("nop");
     161 0000      NOP
(0156) lcd_clear_e(); // Disable LCD
     162 9892      CBI	0x12,2
     163 9169      LD	R22,Y+
     164 9149      LD	R20,Y+
     165 9508      RET
(0157) }
(0158) // ********************************* //
(0159) // *** Initialize the LCD driver *** //
(0160) // ********************************* //
(0161) void Init_LCD(void)
(0162) {
(0163) LCD_INIT();
_Init_LCD:
     166 DF77      RCALL	_LCD_INIT
(0164) LCD_WriteControl (LCD_FUNCTION_SET);
     167 E208      LDI	R16,0x28
     168 DFBD      RCALL	_LCD_WriteControl
(0165) LCD_WriteControl (LCD_OFF);
     169 E008      LDI	R16,0x8
     16A DFBB      RCALL	_LCD_WriteControl
(0166) LCD_WriteControl (LCD_CLEAR);
     16B E001      LDI	R16,1
     16C DFB9      RCALL	_LCD_WriteControl
(0167) LCD_WriteControl (LCD_MODE_SET);
     16D E006      LDI	R16,6
     16E DFB7      RCALL	_LCD_WriteControl
(0168) LCD_WriteControl (LCD_ON);
     16F E00C      LDI	R16,0xC
     170 DFB5      RCALL	_LCD_WriteControl
(0169) LCD_WriteControl (LCD_HOME);
     171 E002      LDI	R16,2
     172 DFB3      RCALL	_LCD_WriteControl
     173 9508      RET
(0170) //LCD_WriteControl (0x90);
(0171) 
(0172) }
(0173) // ************************************************ //
(0174) // *** Clear the LCD screen (also homes cursor) *** //
(0175) // ************************************************ //
(0176) void LCD_Clear(void)
(0177) {
(0178) LCD_WriteControl(0x01);
_LCD_Clear:
     174 E001      LDI	R16,1
     175 DFB0      RCALL	_LCD_WriteControl
     176 9508      RET
(0179) }
(0180) // *********************************************** //
(0181) // *** Position the LCD cursor at row 1, col 1 *** //
(0182) // *********************************************** //
(0183) void LCD_Home(void)
(0184) {
(0185) LCD_WriteControl(0x02);
_LCD_Home:
     177 E002      LDI	R16,2
     178 DFAD      RCALL	_LCD_WriteControl
     179 9508      RET
_LCD_DisplayCharacter:
  Char                 --> R10
     17A 92AA      ST	R10,-Y
     17B 2EA0      MOV	R10,R16
(0186) }
(0187) // ****************************************************************** //
(0188) // *** Display a single character, at the current cursor location *** //
(0189) // ****************************************************************** //
(0190) void LCD_DisplayCharacter (char Char)
(0191) {
(0192) LCD_WriteData (Char);
     17C 2D0A      MOV	R16,R10
     17D DFC8      RCALL	_LCD_WriteData
     17E 90A9      LD	R10,Y+
     17F 9508      RET
_LCD_DisplayString:
  string               --> R10
  column               --> R14
  row                  --> R12
     180 940E 0243 CALL	push_xgset00FC
     182 2EE2      MOV	R14,R18
     183 2EC0      MOV	R12,R16
     184 80AE      LDD	R10,Y+6
     185 80BF      LDD	R11,Y+7
(0193) }
(0194) // ********************************************************************* //
(0195) // *** Display a string at the specified row and column, using FLASH *** //
(0196) // ********************************************************************* //
(0197) /*
(0198) void LCD_DisplayString_F (char row, char column , unsigned char __flash *string)
(0199) {
(0200) LCD_Cursor (row, column);
(0201) while (*string)
(0202) {
(0203) LCD_DisplayCharacter (*string++);
(0204) }
(0205) }
(0206) */
(0207) // ******************************************************************* //
(0208) // *** Display a string at the specified row and column, using RAM *** //
(0209) // ******************************************************************* //
(0210) void LCD_DisplayString (char row, char column ,unsigned char *string)
(0211) {
(0212) LCD_Cursor (row, column);
     186 2D2E      MOV	R18,R14
     187 2D0C      MOV	R16,R12
     188 D00B      RCALL	_LCD_Cursor
     189 C004      RJMP	0x018E
(0213) while (*string)
(0214) LCD_DisplayCharacter (*string++);
     18A 01F5      MOVW	R30,R10
     18B 9101      LD	R16,Z+
     18C 015F      MOVW	R10,R30
     18D DFEC      RCALL	_LCD_DisplayCharacter
     18E 01F5      MOVW	R30,R10
     18F 8020      LDD	R2,Z+0
     190 2022      TST	R2
     191 F7C1      BNE	0x018A
     192 940C 0238 JMP	pop_xgset00FC
_LCD_Cursor:
  column               --> R20
  row                  --> R10
     194 940E 0254 CALL	push_xgsetF00C
     196 2F42      MOV	R20,R18
     197 2EA0      MOV	R10,R16
(0215) }
(0216) // *************************************************** //
(0217) // *** Position the LCD cursor at "row", "column". *** //
(0218) // *************************************************** //
(0219) void LCD_Cursor (char row, char column)
(0220) {
(0221) switch (row) {
     198 2D6A      MOV	R22,R10
     199 2777      CLR	R23
     19A 3061      CPI	R22,1
     19B E0E0      LDI	R30,0
     19C 077E      CPC	R23,R30
     19D F069      BEQ	0x01AB
     19E 3062      CPI	R22,2
     19F E0E0      LDI	R30,0
     1A0 077E      CPC	R23,R30
     1A1 F071      BEQ	0x01B0
     1A2 3063      CPI	R22,3
     1A3 E0E0      LDI	R30,0
     1A4 077E      CPC	R23,R30
     1A5 F079      BEQ	0x01B5
     1A6 3064      CPI	R22,4
     1A7 E0E0      LDI	R30,0
     1A8 077E      CPC	R23,R30
     1A9 F081      BEQ	0x01BA
     1AA C013      RJMP	0x01BE
(0222) case 1: LCD_WriteControl (0x80 + column - 1); break;
     1AB 2F04      MOV	R16,R20
     1AC 5800      SUBI	R16,0x80
     1AD 5001      SUBI	R16,1
     1AE DF77      RCALL	_LCD_WriteControl
     1AF C00E      RJMP	0x01BE
(0223) case 2: LCD_WriteControl (0xc0 + column - 1); break;
     1B0 2F04      MOV	R16,R20
     1B1 5400      SUBI	R16,0x40
     1B2 5001      SUBI	R16,1
     1B3 DF72      RCALL	_LCD_WriteControl
     1B4 C009      RJMP	0x01BE
(0224) case 3: LCD_WriteControl (0x94 + column - 1); break;
     1B5 2F04      MOV	R16,R20
     1B6 560C      SUBI	R16,0x6C
     1B7 5001      SUBI	R16,1
     1B8 DF6D      RCALL	_LCD_WriteControl
     1B9 C004      RJMP	0x01BE
(0225) case 4: LCD_WriteControl (0xd4 + column - 1); break;
     1BA 2F04      MOV	R16,R20
     1BB 520C      SUBI	R16,0x2C
     1BC 5001      SUBI	R16,1
     1BD DF68      RCALL	_LCD_WriteControl
(0226) default: break;

⌨️ 快捷键说明

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