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

📄 key_lcd.lst

📁 键盘扫描及其LCD显示输出,有源程序与仿真文件,都测试通过.
💻 LST
📖 第 1 页 / 共 3 页
字号:
(0101)             case 1:            
(0102)                 LCD_Cursor(2,x_position);
    0142 2F24      MOV	R18,R20
    0143 E002      LDI	R16,2
    0144 D10F      RCALL	_LCD_Cursor
(0103)                 LCD_DisplayCharacter('1');          
    0145 E301      LDI	R16,0x31
    0146 D0D8      RCALL	_LCD_DisplayCharacter
(0104)                 break;
    0147 CFB9      RJMP	0x0101
(0105)             case 2:            
(0106)                 LCD_Cursor(2,x_position);
    0148 2F24      MOV	R18,R20
    0149 E002      LDI	R16,2
    014A D109      RCALL	_LCD_Cursor
(0107)                 LCD_DisplayCharacter('2');          
    014B E302      LDI	R16,0x32
    014C D0D2      RCALL	_LCD_DisplayCharacter
(0108)                 break;
    014D CFB3      RJMP	0x0101
(0109)             case 3:            
(0110)                 LCD_Cursor(2,x_position);
    014E 2F24      MOV	R18,R20
    014F E002      LDI	R16,2
    0150 D103      RCALL	_LCD_Cursor
(0111)                 LCD_DisplayCharacter('3');          
    0151 E303      LDI	R16,0x33
    0152 D0CC      RCALL	_LCD_DisplayCharacter
(0112)                 break; 
    0153 CFAD      RJMP	0x0101
(0113)             case 4:            
(0114)                 LCD_Cursor(2,x_position);
    0154 2F24      MOV	R18,R20
    0155 E002      LDI	R16,2
    0156 D0FD      RCALL	_LCD_Cursor
(0115)                 LCD_DisplayCharacter('4');          
    0157 E304      LDI	R16,0x34
    0158 D0C6      RCALL	_LCD_DisplayCharacter
(0116)                 break;
    0159 CFA7      RJMP	0x0101
(0117)             case 5:            
(0118)                 LCD_Cursor(2,x_position);
    015A 2F24      MOV	R18,R20
    015B E002      LDI	R16,2
    015C D0F7      RCALL	_LCD_Cursor
(0119)                 LCD_DisplayCharacter('5');          
    015D E305      LDI	R16,0x35
    015E D0C0      RCALL	_LCD_DisplayCharacter
(0120)                 break;
    015F CFA1      RJMP	0x0101
(0121)             case 6:            
(0122)                 LCD_Cursor(2,x_position);
    0160 2F24      MOV	R18,R20
    0161 E002      LDI	R16,2
    0162 D0F1      RCALL	_LCD_Cursor
(0123)                 LCD_DisplayCharacter('6');          
    0163 E306      LDI	R16,0x36
    0164 D0BA      RCALL	_LCD_DisplayCharacter
(0124)                 break;
    0165 CF9B      RJMP	0x0101
(0125)             case 7:            
(0126)                 LCD_Cursor(2,x_position);
    0166 2F24      MOV	R18,R20
    0167 E002      LDI	R16,2
    0168 D0EB      RCALL	_LCD_Cursor
(0127)                 LCD_DisplayCharacter('7');          
    0169 E307      LDI	R16,0x37
    016A D0B4      RCALL	_LCD_DisplayCharacter
(0128)                 break;  
    016B CF95      RJMP	0x0101
(0129)             case 8:            
(0130)                 LCD_Cursor(2,x_position);
    016C 2F24      MOV	R18,R20
    016D E002      LDI	R16,2
    016E D0E5      RCALL	_LCD_Cursor
(0131)                 LCD_DisplayCharacter('8');          
    016F E308      LDI	R16,0x38
    0170 D0AE      RCALL	_LCD_DisplayCharacter
(0132)                 break;
    0171 CF8F      RJMP	0x0101
(0133)             case 9:            
(0134)                 LCD_Cursor(2,x_position);
    0172 2F24      MOV	R18,R20
    0173 E002      LDI	R16,2
    0174 D0DF      RCALL	_LCD_Cursor
(0135)                 LCD_DisplayCharacter('9');          
    0175 E309      LDI	R16,0x39
    0176 D0A8      RCALL	_LCD_DisplayCharacter
(0136)                 break;            
    0177 CF89      RJMP	0x0101
(0137)             case 10:            
(0138)                 LCD_Cursor(2,x_position);
    0178 2F24      MOV	R18,R20
    0179 E002      LDI	R16,2
    017A D0D9      RCALL	_LCD_Cursor
(0139)                 LCD_DisplayCharacter('*');          
    017B E20A      LDI	R16,0x2A
    017C D0A2      RCALL	_LCD_DisplayCharacter
(0140)                 break;
    017D CF83      RJMP	0x0101
(0141)             case 11:            
(0142)                 LCD_Cursor(2,x_position);
    017E 2F24      MOV	R18,R20
    017F E002      LDI	R16,2
    0180 D0D3      RCALL	_LCD_Cursor
(0143)                 LCD_DisplayCharacter('0');          
    0181 E300      LDI	R16,0x30
    0182 D09C      RCALL	_LCD_DisplayCharacter
(0144)                 break;
    0183 CF7D      RJMP	0x0101
(0145)              case 12:            
(0146)                 LCD_Cursor(2,x_position);
    0184 2F24      MOV	R18,R20
    0185 E002      LDI	R16,2
    0186 D0CD      RCALL	_LCD_Cursor
(0147)                 LCD_DisplayCharacter('#');          
    0187 E203      LDI	R16,0x23
    0188 D096      RCALL	_LCD_DisplayCharacter
    0189 CF77      RJMP	0x0101
    018A 9622      ADIW	R28,2
    018B 9508      RET
FILE: F:\AVR练习\key_lcd\LCD.c
(0001) // ************************************************
(0002) // *** LCD_4BIT Driver V1.1 ***
(0003) // *** LCD.C ***
(0004) // ************************************************
(0005) #define LCD_C
(0006) #include <io8535v.h>
(0007) #include"lcd.h"
(0008) // ***** Define I/O pins ***** //
(0009) #define BIT7 0x80
(0010) #define BIT6 0x40
(0011) #define BIT5 0x20
(0012) #define BIT4 0x10
(0013) #define BIT3 0x08
(0014) #define BIT2 0x04
(0015) #define BIT1 0x02
(0016) #define BIT0 0x01
(0017) // *** Set port for LCD Data Bus 8 bit mode *** //
(0018) #define LCD_OP_PORT PORTB
(0019) #define LCD_IP_PORT PINB
(0020) #define LCD_DIR_PORT DDRB
(0021) // *** Set LCD Enable Port and Bit values *** //
(0022) //#define LCD_EN LCD_OP_PORT.2
(0023) // *** Set LCD Register Select Port and Bit values *** //
(0024) //#define LCD_RS LCD_OP_PORT.0
(0025) // *** Set LCD Read/Write Port and Bit values *** //
(0026) //#define LCD_RW LCD_OP_PORT.1
(0027) /****************************************************************/
(0028)  
(0029)  #define LCD_EN  (1 << 2)     //引脚定义
(0030)  #define LCD_RS (1 << 0)
(0031)  #define LCD_RW (1 << 1)
(0032)  
(0033)  #define lcd_set_e()  (LCD_OP_PORT |= LCD_EN)   //置位与清零
(0034)  #define lcd_set_rs() (LCD_OP_PORT |= LCD_RS)
(0035)  #define lcd_set_rw() (LCD_OP_PORT |= LCD_RW)
(0036)  #define lcd_clear_e()  (LCD_OP_PORT &= ~LCD_EN)
(0037)  #define lcd_clear_rs() (LCD_OP_PORT &= ~LCD_RS)
(0038)  #define lcd_clear_rw() (LCD_OP_PORT &= ~LCD_RW)
(0039) /****************************************************************/
(0040) 
(0041) #define LCD_ON 0x0C
(0042) #define LCD_CURS_ON 0x0D
(0043) #define LCD_OFF 0x08
(0044) #define LCD_HOME 0x02
(0045) #define LCD_CLEAR 0x01
(0046) #define LCD_NEW_LINE 0xC0
(0047) #define LCD_FUNCTION_SET 0x28
(0048) #define LCD_MODE_SET  0x06
(0049) 
(0050) 
(0051) void LCD_INIT(void)
(0052) {
(0053) LCD_DIR_PORT = 0xff; // LCD port output
_LCD_INIT:
    018C EF8F      LDI	R24,0xFF
    018D BB87      OUT	0x17,R24
(0054) LCD_OP_PORT = 0x30; // Load high-data to port
    018E E380      LDI	R24,0x30
    018F BB88      OUT	0x18,R24
(0055) lcd_clear_rw(); // Set LCD to write
    0190 98C1      CBI	0x18,1
(0056) lcd_clear_rs(); // Set LCD to command
    0191 98C0      CBI	0x18,0
(0057) lcd_set_e(); // Write data to LCD
    0192 9AC2      SBI	0x18,2
(0058) asm("nop");
    0193 0000      NOP
(0059) asm("nop");
    0194 0000      NOP
(0060) lcd_clear_e(); // Disable LCD
    0195 98C2      CBI	0x18,2
(0061) delay_nus(40);
    0196 E208      LDI	R16,0x28
    0197 E010      LDI	R17,0
    0198 D0F3      RCALL	_delay_nus
(0062) lcd_clear_rw() ; // Set LCD to write
    0199 98C1      CBI	0x18,1
(0063) lcd_clear_rs(); // Set LCD to command
    019A 98C0      CBI	0x18,0
(0064) lcd_set_e(); // Write data to LCD
    019B 9AC2      SBI	0x18,2
(0065) asm("nop");
    019C 0000      NOP
(0066) asm("nop");
    019D 0000      NOP
(0067) lcd_clear_e(); // Disable LCD
    019E 98C2      CBI	0x18,2
(0068) delay_nus(40);
    019F E208      LDI	R16,0x28
    01A0 E010      LDI	R17,0
    01A1 D0EA      RCALL	_delay_nus
(0069) lcd_set_e(); // Write data to LCD
    01A2 9AC2      SBI	0x18,2
(0070) asm("nop");
    01A3 0000      NOP
(0071) asm("nop");
    01A4 0000      NOP
(0072) lcd_clear_e(); // Disable LCD
    01A5 98C2      CBI	0x18,2
(0073) delay_nus(40);
    01A6 E208      LDI	R16,0x28
    01A7 E010      LDI	R17,0
    01A8 D0E3      RCALL	_delay_nus
(0074) LCD_OP_PORT = 0x20;
    01A9 E280      LDI	R24,0x20
    01AA BB88      OUT	0x18,R24
(0075) lcd_set_e(); // Write data to LCD
    01AB 9AC2      SBI	0x18,2
(0076) asm("nop");
    01AC 0000      NOP
(0077) asm("nop");
    01AD 0000      NOP
(0078) lcd_clear_e(); // Disable LCD
    01AE 98C2      CBI	0x18,2
(0079) delay_nus(40);
    01AF E208      LDI	R16,0x28
    01B0 E010      LDI	R17,0
    01B1 D0DA      RCALL	_delay_nus
    01B2 9508      RET
_LCD_Busy:
  low                  --> R20
  high                 --> R22
  temp                 --> R10
    01B3 D107      RCALL	push_gset3
(0080) }
(0081) //*****************************************************//
(0082) // This routine will return the busy flag from the LCD //
(0083) //*****************************************************//
(0084) void LCD_Busy ( void )
(0085) {
(0086) unsigned char temp,high;
(0087) unsigned char low;
(0088) LCD_DIR_PORT = 0x0f; // Make I/O Port input
    01B4 E08F      LDI	R24,0xF
    01B5 BB87      OUT	0x17,R24
(0089) do
(0090) {
(0091) temp=LCD_OP_PORT;
    01B6 B2A8      IN	R10,0x18
(0092) temp=temp&BIT3;
    01B7 2D8A      MOV	R24,R10
    01B8 7088      ANDI	R24,0x8
    01B9 2EA8      MOV	R10,R24
(0093) LCD_OP_PORT=temp;
    01BA BB88      OUT	0x18,R24
(0094) lcd_set_rw(); // Set LCD to READ
    01BB 9AC1      SBI	0x18,1
(0095) lcd_clear_rs();
    01BC 98C0      CBI	0x18,0
(0096) lcd_set_e();
    01BD 9AC2      SBI	0x18,2
(0097) delay_nus(3);
    01BE E003      LDI	R16,3
    01BF E010      LDI	R17,0
    01C0 D0CB      RCALL	_delay_nus
(0098) high = LCD_IP_PORT; // read the high nibble.
    01C1 B366      IN	R22,0x16
(0099) lcd_clear_e(); // Disable LCD
    01C2 98C2      CBI	0x18,2
(0100) lcd_set_e();
    01C3 9AC2      SBI	0x18,2
(0101) asm("nop");
    01C4 0000      NOP
(0102) asm("nop");
    01C5 0000      NOP
(0103) low = LCD_IP_PORT; // read the low nibble.
    01C6 B346      IN	R20,0x16
(0104) lcd_clear_e(); // Disable LCD
    01C7 98C2      CBI	0x18,2
(0105) } while(high & 0x80);
    01C8 FD67      SBRC	R22,7
    01C9 CFEC      RJMP	0x01B6
(0106) delay_nus(20);
    01CA E104      LDI	R16,0x14
    01CB E010      LDI	R17,0
    01CC D0BF      RCALL	_delay_nus
    01CD D0E7      RCALL	pop_gset3
    01CE 9508      RET
_LCD_WriteControl:
  temp                 --> R20
  CMD                  --> R22
    01CF D0ED      RCALL	push_gset2
    01D0 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
    01D1 DFE1      RCALL	_LCD_Busy
(0115) LCD_DIR_PORT = 0xff; // LCD port output
    01D2 EF8F      LDI	R24,0xFF
    01D3 BB87      OUT	0x17,R24
(0116) temp=LCD_OP_PORT;
    01D4 B348      IN	R20,0x18
(0117) temp=temp&BIT3;
    01D5 7048      ANDI	R20,0x8
(0118) LCD_OP_PORT =(CMD & 0xf0)|temp; // Load high-data to port
    01D6 2F86      MOV	R24,R22
    01D7 7F80      ANDI	R24,0xF0
    01D8 2B84      OR	R24,R20
    01D9 BB88      OUT	0x18,R24
(0119) lcd_clear_rw(); // Set LCD to write
    01DA 98C1      CBI	0x18,1
(0120) lcd_clear_rs(); // Set LCD to command
    01DB 98C0      CBI	0x18,0
(0121) lcd_set_e(); // Write data to LCD
    01DC 9AC2      SBI	0x18,2
(0122) asm("nop");
    01DD 0000      NOP
(0123) asm("nop");
    01DE 0000      NOP
(0124) lcd_clear_e(); // Disable LCD
    01DF 98C2      CBI	0x18,2
(0125) LCD_OP_PORT =(CMD<<4)|temp; // Load low-data to port
    01E0 2F86      MOV	R24,R22
    01E1 708F      ANDI	R24,0xF
    01E2 9582      SWAP	R24
    01E3 2B84      OR	R24,R20
    01E4 BB88      OUT	0x18,R24
(0126) lcd_clear_rw(); // Set LCD to write
    01E5 98C1      CBI	0x18,1
(0127) lcd_clear_rs(); // Set LCD to command
    01E6 98C0      CBI	0x18,0
(0128) lcd_set_e(); // Write data to LCD
    01E7 9AC2      SBI	0x18,2
(0129) asm("nop");
    01E8 0000      NOP
(0130) asm("nop");
    01E9 0000      NOP
(0131) lcd_clear_e(); // Disable LCD
    01EA 98C2      CBI	0x18,2
    01EB D0C7      RCALL	pop_gset2
    01EC 9508      RET
_LCD_WriteData:
  temp                 --> R20
  Data                 --> R22
    01ED D0CF      RCALL	push_gset2
    01EE 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
    01EF DFC3      RCALL	_LCD_Busy
(0140) LCD_DIR_PORT = 0xFF; // LCD port output
    01F0 EF8F      LDI	R24,0xFF
    01F1 BB87      OUT	0x17,R24
(0141) temp=LCD_OP_PORT;
    01F2 B348      IN	R20,0x18
(0142) temp=temp&BIT3;
    01F3 7048      ANDI	R20,0x8
(0143) LCD_OP_PORT =(Data & 0xf0)|temp; // Load high-data to port
    01F4 2F86      MOV	R24,R22
    01F5 7F80      ANDI	R24,0xF0
    01F6 2B84      OR	R24,R20
    01F7 BB88      OUT	0x18,R24
(0144) lcd_clear_rw() ; // Set LCD to write
    01F8 98C1      CBI	0x18,1
(0145) lcd_set_rs(); // Set LCD to data
    01F9 9AC0      SBI	0x18,0
(0146) lcd_set_e(); // Write data to LCD
    01FA 9AC2      SBI	0x18,2
(0147) asm("nop");
    01FB 0000      NOP

⌨️ 快捷键说明

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