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

📄 lcd.s

📁 用的avr icc 开发的atmega16的超声波测距仪模型。
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module LCD.c
	.area text(rom, con, rel)
	.dbfile D:\NEW\ECHO\LCD.c
	.dbfunc e LCD_INIT _LCD_INIT fV
	.even
_LCD_INIT::
	.dbline -1
	.dbline 42
; // ************************************************
; // *** 采用4位数据线的1602液晶驱动程序 ***
; // *** LCD.C ***
; // ************************************************
; #define ENABLE_BIT_DEFINITIONS
; #define LCD_C
; #include "includes.h"
; // ***** Define I/O pins ***** //
; #define BIT7 0x80
; #define BIT6 0x40
; #define BIT5 0x20
; #define BIT4 0x10
; #define BIT3 0x08
; #define BIT2 0x04
; #define BIT1 0x02
; #define BIT0 0x01
; 
; 
;  #define LCD_EN  (1 << 2)     //引脚定义
;  #define LCD_RS (1 << 0)
;  #define LCD_RW (1 << 1)
;  
;  #define lcd_set_e()  (LCD_OP_PORT |= LCD_EN)   //置位与清零
;  #define lcd_set_rs() (LCD_OP_PORT |= LCD_RS)
;  #define lcd_set_rw() (LCD_OP_PORT |= LCD_RW)
;  #define lcd_clear_e()  (LCD_OP_PORT &= ~LCD_EN)
;  #define lcd_clear_rs() (LCD_OP_PORT &= ~LCD_RS)
;  #define lcd_clear_rw() (LCD_OP_PORT &= ~LCD_RW)
; /****************************************************************/
; 
; #define LCD_ON 0x0C
; #define LCD_CURS_ON 0x0D
; #define LCD_OFF 0x08
; #define LCD_HOME 0x02
; #define LCD_CLEAR 0x01
; #define LCD_NEW_LINE 0xC0
; #define LCD_FUNCTION_SET 0x28
; #define LCD_MODE_SET 0x06
; 
; 
; void LCD_INIT(void)
; {
	.dbline 43
; LCD_DIR_PORT = 0xff; // LCD port output
	ldi R24,255
	out 0x1a,R24
	.dbline 44
; LCD_OP_PORT = 0x30; // Load high-data to port
	ldi R24,48
	out 0x1b,R24
	.dbline 45
; lcd_clear_rw(); // Set LCD to write
	cbi 0x1b,1
	.dbline 46
; lcd_clear_rs(); // Set LCD to command
	cbi 0x1b,0
	.dbline 47
; lcd_set_e(); // Write data to LCD
	sbi 0x1b,2
	.dbline 48
; asm("nop");
	nop
	.dbline 49
; asm("nop");
	nop
	.dbline 50
; lcd_clear_e(); // Disable LCD
	cbi 0x1b,2
	.dbline 51
; delay_nus(40);
	ldi R16,40
	ldi R17,0
	xcall _delay_nus
	.dbline 52
; lcd_clear_rw() ; // Set LCD to write
	cbi 0x1b,1
	.dbline 53
; lcd_clear_rs(); // Set LCD to command
	cbi 0x1b,0
	.dbline 54
; lcd_set_e(); // Write data to LCD
	sbi 0x1b,2
	.dbline 55
; asm("nop");
	nop
	.dbline 56
; asm("nop");
	nop
	.dbline 57
; lcd_clear_e(); // Disable LCD
	cbi 0x1b,2
	.dbline 58
; delay_nus(40);
	ldi R16,40
	ldi R17,0
	xcall _delay_nus
	.dbline 59
; lcd_set_e(); // Write data to LCD
	sbi 0x1b,2
	.dbline 60
; asm("nop");
	nop
	.dbline 61
; asm("nop");
	nop
	.dbline 62
; lcd_clear_e(); // Disable LCD
	cbi 0x1b,2
	.dbline 63
; delay_nus(40);
	ldi R16,40
	ldi R17,0
	xcall _delay_nus
	.dbline 64
; LCD_OP_PORT = 0x20;
	ldi R24,32
	out 0x1b,R24
	.dbline 65
; lcd_set_e(); // Write data to LCD
	sbi 0x1b,2
	.dbline 66
; asm("nop");
	nop
	.dbline 67
; asm("nop");
	nop
	.dbline 68
; lcd_clear_e(); // Disable LCD
	cbi 0x1b,2
	.dbline 69
; delay_nus(40);
	ldi R16,40
	ldi R17,0
	.dbline -2
	.dbline 70
; }
L1:
	.dbline 0 ; func end
	xjmp _delay_nus
	.dbend
	.dbfunc e LCD_Busy _LCD_Busy fV
;            low -> R20
;           high -> R22
;           temp -> R10
	.even
_LCD_Busy::
	xcall push_gset3
	.dbline -1
	.dbline 75
; //*****************************************************//
; // This routine will return the busy flag from the LCD //
; //*****************************************************//
; void LCD_Busy ( void )
; {
	.dbline 78
; unsigned char temp,high;
; unsigned char low;
; LCD_DIR_PORT = 0x0f; // Make I/O Port input
	ldi R24,15
	out 0x1a,R24
L3:
	.dbline 80
; do
; {
	.dbline 81
; temp=LCD_OP_PORT;
	in R10,0x1b
	.dbline 82
; temp=temp&BIT3;
	mov R24,R10
	andi R24,8
	mov R10,R24
	.dbline 83
; LCD_OP_PORT=temp;
	out 0x1b,R24
	.dbline 84
; lcd_set_rw(); // Set LCD to READ
	sbi 0x1b,1
	.dbline 85
; lcd_clear_rs();
	cbi 0x1b,0
	.dbline 86
; lcd_set_e();
	sbi 0x1b,2
	.dbline 87
; delay_nus(3);
	ldi R16,3
	ldi R17,0
	xcall _delay_nus
	.dbline 88
; high = LCD_IP_PORT; // read the high nibble.
	in R22,0x19
	.dbline 89
; lcd_clear_e(); // Disable LCD
	cbi 0x1b,2
	.dbline 90
; lcd_set_e();
	sbi 0x1b,2
	.dbline 91
; asm("nop");
	nop
	.dbline 92
; asm("nop");
	nop
	.dbline 93
; low = LCD_IP_PORT; // read the low nibble.
	in R20,0x19
	.dbline 94
; lcd_clear_e(); // Disable LCD
	cbi 0x1b,2
	.dbline 95
L4:
	.dbline 95
; } while(high & 0x80);
	sbrc R22,7
	rjmp L3
	.dbline 96
; delay_nus(20);
	ldi R16,20
	ldi R17,0
	xcall _delay_nus
	.dbline -2
	.dbline 97
; }
L2:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r low 20 c
	.dbsym r high 22 c
	.dbsym r temp 10 c
	.dbend
	.dbfunc e LCD_WriteControl _LCD_WriteControl fV
;           temp -> R20
;            CMD -> R22
	.even
_LCD_WriteControl::
	xcall push_gset2
	mov R22,R16
	.dbline -1
	.dbline 102
; // ********************************************** //
; // *** Write a control instruction to the LCD *** //
; // ********************************************** //
; void LCD_WriteControl (unsigned char CMD)
; {
	.dbline 104
; char temp;
; LCD_Busy(); // Test if LCD busy
	xcall _LCD_Busy
	.dbline 105
; LCD_DIR_PORT = 0xff; // LCD port output
	ldi R24,255
	out 0x1a,R24
	.dbline 106
; temp=LCD_OP_PORT;
	in R20,0x1b
	.dbline 107
; temp=temp&BIT3;
	andi R20,8
	.dbline 108
; LCD_OP_PORT =(CMD & 0xf0)|temp; // Load high-data to port
	mov R24,R22
	andi R24,240
	or R24,R20
	out 0x1b,R24
	.dbline 109
; lcd_clear_rw(); // Set LCD to write
	cbi 0x1b,1
	.dbline 110
; lcd_clear_rs(); // Set LCD to command
	cbi 0x1b,0
	.dbline 111
; lcd_set_e(); // Write data to LCD
	sbi 0x1b,2
	.dbline 112
; asm("nop");
	nop
	.dbline 113
; asm("nop");
	nop
	.dbline 114
; lcd_clear_e(); // Disable LCD
	cbi 0x1b,2
	.dbline 115
; LCD_OP_PORT =(CMD<<4)|temp; // Load low-data to port
	mov R24,R22
	andi R24,#0x0F
	swap R24
	or R24,R20
	out 0x1b,R24
	.dbline 116
; lcd_clear_rw(); // Set LCD to write
	cbi 0x1b,1
	.dbline 117
; lcd_clear_rs(); // Set LCD to command
	cbi 0x1b,0
	.dbline 118
; lcd_set_e(); // Write data to LCD
	sbi 0x1b,2
	.dbline 119
; asm("nop");
	nop
	.dbline 120
; asm("nop");
	nop
	.dbline 121
; lcd_clear_e(); // Disable LCD
	cbi 0x1b,2
	.dbline -2
	.dbline 122
; }
L6:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r temp 20 c
	.dbsym r CMD 22 c
	.dbend
	.dbfunc e LCD_WriteData _LCD_WriteData fV
;           temp -> R20
;           Data -> R22
	.even
_LCD_WriteData::
	xcall push_gset2
	mov R22,R16
	.dbline -1
	.dbline 127
; // ***************************************** //
; // *** Write one byte of data to the LCD *** //
; // ***************************************** //
; void LCD_WriteData (unsigned char Data)
; {
	.dbline 129
; char temp;
; LCD_Busy(); // Test if LCD Busy
	xcall _LCD_Busy
	.dbline 130
; LCD_DIR_PORT = 0xFF; // LCD port output
	ldi R24,255
	out 0x1a,R24
	.dbline 131
; temp=LCD_OP_PORT;
	in R20,0x1b
	.dbline 132
; temp=temp&BIT3;
	andi R20,8
	.dbline 133
; LCD_OP_PORT =(Data & 0xf0)|temp; // Load high-data to port
	mov R24,R22
	andi R24,240
	or R24,R20
	out 0x1b,R24
	.dbline 134
; lcd_clear_rw() ; // Set LCD to write
	cbi 0x1b,1
	.dbline 135
; lcd_set_rs(); // Set LCD to data
	sbi 0x1b,0
	.dbline 136
; lcd_set_e(); // Write data to LCD
	sbi 0x1b,2
	.dbline 137
; asm("nop");
	nop
	.dbline 138
; asm("nop");
	nop
	.dbline 139
; lcd_clear_e(); // Disable LCD
	cbi 0x1b,2
	.dbline 140
; LCD_OP_PORT = (Data << 4)|temp; // Load low-data to port
	mov R24,R22
	andi R24,#0x0F
	swap R24
	or R24,R20
	out 0x1b,R24
	.dbline 141
; lcd_clear_rw() ; // Set LCD to write
	cbi 0x1b,1
	.dbline 142
; lcd_set_rs(); // Set LCD to data
	sbi 0x1b,0
	.dbline 143
; lcd_set_e(); // Write data to LCD
	sbi 0x1b,2
	.dbline 144
; asm("nop");
	nop
	.dbline 145
; asm("nop");
	nop
	.dbline 146
; lcd_clear_e(); // Disable LCD
	cbi 0x1b,2
	.dbline -2
	.dbline 147
; }
L7:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r temp 20 c
	.dbsym r Data 22 c
	.dbend
	.dbfunc e Init_LCD _Init_LCD fV
	.even
_Init_LCD::
	.dbline -1
	.dbline 152
; // ********************************* //

⌨️ 快捷键说明

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