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

📄 usart_icc.lst

📁 M16控制,从键盘输入字符,当输入字符达到10个的时候,终端和LCD都显示所接收到的字符
💻 LST
📖 第 1 页 / 共 3 页
字号:
__start:
__text_start:
      45 E5CF      LDI	R28,0x5F
      46 E0D4      LDI	R29,4
      47 BFCD      OUT	0x3D,R28
      48 BFDE      OUT	0x3E,R29
      49 51CE      SUBI	R28,0x1E
      4A 40D0      SBCI	R29,0
      4B EA0A      LDI	R16,0xAA
      4C 8308      STD	Y+0,R16
      4D 2400      CLR	R0
      4E E9E6      LDI	R30,0x96
      4F E0F0      LDI	R31,0
      50 E010      LDI	R17,0
      51 39E9      CPI	R30,0x99
      52 07F1      CPC	R31,R17
      53 F011      BEQ	0x0056
      54 9201      ST	R0,Z+
      55 CFFB      RJMP	0x0051
      56 8300      STD	Z+0,R16
      57 E5E4      LDI	R30,0x54
      58 E0F0      LDI	R31,0
      59 E6A0      LDI	R26,0x60
      5A E0B0      LDI	R27,0
      5B E010      LDI	R17,0
      5C E000      LDI	R16,0
      5D BF0B      OUT	0x3B,R16
      5E 38EA      CPI	R30,0x8A
      5F 07F1      CPC	R31,R17
      60 F021      BEQ	0x0065
      61 95C8      LPM
      62 9631      ADIW	R30,1
      63 920D      ST	R0,X+
      64 CFF9      RJMP	0x005E
      65 940E 0195 CALL	_main
_exit:
      67 CFFF      RJMP	_exit
FILE: E:\新建文件夹\usart_icc\cfile\delay.c
(0001) #define DELAY_C
(0002) #include "includes.h"
(0003) #define XTAL 4    //晶振频率,单位MHz
(0004) void delay_1us(void)                 //1us延时函数
(0005)   {
(0006)    asm("nop");
_delay_1us:
      68 0000      NOP
      69 9508      RET
_delay_nus:
  i                    --> R20
  n                    --> R10
      6A 940E 0256 CALL	push_xgset300C
      6C 0158      MOVW	R10,R16
(0007)   }
(0008) 
(0009) void delay_nus(unsigned int n)       //N us延时函数
(0010)   {
(0011)    unsigned int i=0;
(0012)    for (i=0;i<n;i++)
      6D 2744      CLR	R20
      6E 2755      CLR	R21
      6F C003      RJMP	0x0073
(0013)    delay_1us();
      70 DFF7      RCALL	_delay_1us
      71 5F4F      SUBI	R20,0xFF
      72 4F5F      SBCI	R21,0xFF
      73 154A      CP	R20,R10
      74 055B      CPC	R21,R11
      75 F3D0      BCS	0x0070
      76 940C 025B JMP	pop_xgset300C
(0014)   }
(0015)   
(0016) void delay_1ms(void)                 //1ms延时函数
(0017)   {
(0018)    unsigned int i;
(0019)    for (i=0;i<(unsigned int)(XTAL*143-2);i++);
_delay_1ms:
  i                    --> R16
      78 2700      CLR	R16
      79 2711      CLR	R17
      7A C002      RJMP	0x007D
      7B 5F0F      SUBI	R16,0xFF
      7C 4F1F      SBCI	R17,0xFF
      7D E38A      LDI	R24,0x3A
      7E E092      LDI	R25,2
      7F 1708      CP	R16,R24
      80 0719      CPC	R17,R25
      81 F3C8      BCS	0x007B
      82 9508      RET
_delay_nms:
  i                    --> R20
  n                    --> R10
      83 940E 0256 CALL	push_xgset300C
      85 0158      MOVW	R10,R16
(0020)   }
(0021)   
(0022) void delay_nms(unsigned int n)       //N ms延时函数
(0023)   {
(0024)    unsigned int i=0;
(0025)    for (i=0;i<n;i++)
      86 2744      CLR	R20
      87 2755      CLR	R21
      88 C003      RJMP	0x008C
(0026)    {
(0027)       delay_1ms();
      89 DFEE      RCALL	_delay_1ms
      8A 5F4F      SUBI	R20,0xFF
      8B 4F5F      SBCI	R21,0xFF
      8C 154A      CP	R20,R10
      8D 055B      CPC	R21,R11
      8E F3D0      BCS	0x0089
      8F 940C 025B JMP	pop_xgset300C
FILE: E:\新建文件夹\usart_icc\cfile\LCD.c
(0001) // ************************************************
(0002) // *** 采用4位数据线的1602液晶驱动程序 ***
(0003) // *** LCD.C ***
(0004) // ************************************************
(0005) #define ENABLE_BIT_DEFINITIONS
(0006) #define LCD_C
(0007) #include "includes.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:
      91 EF8F      LDI	R24,0xFF
      92 BB87      OUT	0x17,R24
(0054) LCD_OP_PORT = 0x30; // Load high-data to port
      93 E380      LDI	R24,0x30
      94 BB88      OUT	0x18,R24
(0055) lcd_clear_rw(); // Set LCD to write
      95 98C1      CBI	0x18,1
(0056) lcd_clear_rs(); // Set LCD to command
      96 98C0      CBI	0x18,0
(0057) lcd_set_e(); // Write data to LCD
      97 9AC2      SBI	0x18,2
(0058) asm("nop");
      98 0000      NOP
(0059) asm("nop");
      99 0000      NOP
(0060) lcd_clear_e(); // Disable LCD
      9A 98C2      CBI	0x18,2
(0061) delay_nus(40);
      9B E208      LDI	R16,0x28
      9C E010      LDI	R17,0
      9D 940E 006A CALL	_delay_nus
(0062) lcd_clear_rw() ; // Set LCD to write
      9F 98C1      CBI	0x18,1
(0063) lcd_clear_rs(); // Set LCD to command
      A0 98C0      CBI	0x18,0
(0064) lcd_set_e(); // Write data to LCD
      A1 9AC2      SBI	0x18,2
(0065) asm("nop");
      A2 0000      NOP
(0066) asm("nop");
      A3 0000      NOP
(0067) lcd_clear_e(); // Disable LCD
      A4 98C2      CBI	0x18,2
(0068) delay_nus(40);
      A5 E208      LDI	R16,0x28
      A6 E010      LDI	R17,0
      A7 940E 006A CALL	_delay_nus
(0069) lcd_set_e(); // Write data to LCD
      A9 9AC2      SBI	0x18,2
(0070) asm("nop");
      AA 0000      NOP
(0071) asm("nop");
      AB 0000      NOP
(0072) lcd_clear_e(); // Disable LCD
      AC 98C2      CBI	0x18,2
(0073) delay_nus(40);
      AD E208      LDI	R16,0x28
      AE E010      LDI	R17,0
      AF 940E 006A CALL	_delay_nus
(0074) LCD_OP_PORT = 0x20;
      B1 E280      LDI	R24,0x20
      B2 BB88      OUT	0x18,R24
(0075) lcd_set_e(); // Write data to LCD
      B3 9AC2      SBI	0x18,2
(0076) asm("nop");
      B4 0000      NOP
(0077) asm("nop");
      B5 0000      NOP
(0078) lcd_clear_e(); // Disable LCD
      B6 98C2      CBI	0x18,2
(0079) delay_nus(40);
      B7 E208      LDI	R16,0x28
      B8 E010      LDI	R17,0
      B9 940E 006A CALL	_delay_nus
      BB 9508      RET
_LCD_Busy:
  low                  --> R12
  high                 --> R10
  temp                 --> R20
      BC 940E 026E CALL	push_xgset303C
(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
      BE E08F      LDI	R24,0xF
      BF BB87      OUT	0x17,R24
(0089) do
(0090) {
(0091) temp=LCD_OP_PORT;
      C0 B348      IN	R20,0x18
(0092) temp=temp&BIT3;
      C1 7048      ANDI	R20,0x8
(0093) LCD_OP_PORT=temp;
      C2 BB48      OUT	0x18,R20
(0094) lcd_set_rw(); // Set LCD to READ
      C3 9AC1      SBI	0x18,1
(0095) lcd_clear_rs();
      C4 98C0      CBI	0x18,0
(0096) lcd_set_e();
      C5 9AC2      SBI	0x18,2
(0097) delay_nus(3);
      C6 E003      LDI	R16,3
      C7 E010      LDI	R17,0
      C8 940E 006A CALL	_delay_nus
(0098) high = LCD_IP_PORT; // read the high nibble.
      CA B2A6      IN	R10,0x16
(0099) lcd_clear_e(); // Disable LCD
      CB 98C2      CBI	0x18,2
(0100) lcd_set_e();
      CC 9AC2      SBI	0x18,2
(0101) asm("nop");
      CD 0000      NOP
(0102) asm("nop");
      CE 0000      NOP
(0103) low = LCD_IP_PORT; // read the low nibble.
      CF B2C6      IN	R12,0x16
(0104) lcd_clear_e(); // Disable LCD
      D0 98C2      CBI	0x18,2
(0105) } while(high & 0x80);
      D1 FCA7      SBRC	R10,7
      D2 CFED      RJMP	0x00C0
(0106) delay_nus(20);
      D3 E104      LDI	R16,0x14
      D4 E010      LDI	R17,0
      D5 940E 006A CALL	_delay_nus
      D7 940C 0275 JMP	pop_xgset303C
_LCD_WriteControl:
  temp                 --> R20
  CMD                  --> R22
      D9 934A      ST	R20,-Y
      DA 936A      ST	R22,-Y
      DB 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
      DC DFDF      RCALL	_LCD_Busy
(0115) LCD_DIR_PORT = 0xff; // LCD port output
      DD EF8F      LDI	R24,0xFF
      DE BB87      OUT	0x17,R24
(0116) temp=LCD_OP_PORT;
      DF B348      IN	R20,0x18
(0117) temp=temp&BIT3;
      E0 7048      ANDI	R20,0x8
(0118) LCD_OP_PORT =(CMD & 0xf0)|temp; // Load high-data to port
      E1 2F86      MOV	R24,R22
      E2 7F80      ANDI	R24,0xF0
      E3 2B84      OR	R24,R20
      E4 BB88      OUT	0x18,R24
(0119) lcd_clear_rw(); // Set LCD to write
      E5 98C1      CBI	0x18,1
(0120) lcd_clear_rs(); // Set LCD to command
      E6 98C0      CBI	0x18,0
(0121) lcd_set_e(); // Write data to LCD
      E7 9AC2      SBI	0x18,2
(0122) asm("nop");
      E8 0000      NOP
(0123) asm("nop");
      E9 0000      NOP
(0124) lcd_clear_e(); // Disable LCD

⌨️ 快捷键说明

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