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

📄 lcd20x4.s

📁 单片机应用 1.1602LCD 2.2004LCD源码 3.ATmega16 PWM源码 4.ATmega8 LED源码 5.无线影音Nrf2401源码 6.AVR串口源码
💻 S
字号:
	.module LCD20x4.c
	.area text(rom, con, rel)
	.dbfile F:\ouravr\M16LCD~1\LCD20x4.c
	.dbfunc e delay_us _delay_us fV
;           time -> R16,R17
	.even
_delay_us::
	.dbline -1
	.dbline 47
; /*=======================================================
; 20x4字符液晶主程序,编译软件(ICCAVR_6.31)
; CPU内部晶振8M
; 数据线B0~B7接PORTB, E=D7 RW=D6 RS=D5
; =========================================================
; 接线图如下:
; _______________           ______________
;                |      --1|GND           |
;                |      --2|+5V           |
;                |      --3|V0            |
;                |         |              |
;             PD5|--------4|RS            |
;             PD6|--------5|RW            |
;             PD7|--------6|E             |
;  CPU           |         |              |
;  ATmmega16L PB0|--------7|D0  LCD20x4   |
;             PB1|--------8|D1            |
;             PB2|--------9|D2            |
;             PB3|-------10|D3            |
;             PB4|-------11|D4            |
;             PB5|-------12|D5            |
;             PB6|-------13|D6            |
;             PB7|-------14|D7            |
;                |         |              |
;                |     --15|+LED          |
;                |     --16|-LED          |
; _______________|         |______________|
; ========================================================*/
; //#include<ioM16V.h> //CPU_ATmmega16L
; #include <ioM8515V.h>
; #define RS_H  asm("sbi 0x15,5")  
; //RS设为高电平0xDF 0X12,5
; #define RS_L  asm("cbi 0x15,5") 
;  //RS设为低电平0x20
; #define RW_H  asm("sbi 0x15,6") 
;  //RW设为高电平0xBF 
; #define RW_L  asm("cbi 0x15,6") 
;  //RW设为低电平0x40
; #define E_H   asm("sbi 0x15,7") 
;  //E设为高电平0x7F
; #define E_L   asm("cbi 0x15,7") 
;  //E设为低电平0x80
; 
; //=======================================================
; //微秒级延时程序
; void delay_us(int time)
; {
L2:
	.dbline 49
;     do
;     {
	.dbline 50
;         time--;
	subi R16,1
	sbci R17,0
	.dbline 51
;     }	
L3:
	.dbline 52
;     while (time > 1);
	ldi R24,1
	ldi R25,0
	cp R24,R16
	cpc R25,R17
	brlt L2
X0:
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbsym r time 16 I
	.dbend
	.dbfunc e delay_ms _delay_ms fV
;           time -> R20,R21
	.even
_delay_ms::
	st -y,R20
	st -y,R21
	movw R20,R16
	.dbline -1
	.dbline 57
; }
; //=======================================================
; //毫秒级延时程序
; void delay_ms(unsigned int time)
; {
	rjmp L7
L6:
	.dbline 59
;     while(time != 0)
;     {		
	.dbline 60
;         delay_us(1000);
	ldi R16,1000
	ldi R17,3
	rcall _delay_us
	.dbline 61
;         time--;
	subi R20,1
	sbci R21,0
	.dbline 62
;     }
L7:
	.dbline 58
	cpi R20,0
	cpc R20,R21
	brne L6
X1:
	.dbline -2
L5:
	.dbline 0 ; func end
	ld R21,y+
	ld R20,y+
	ret
	.dbsym r time 20 i
	.dbend
	.dbfunc e Lcd_Busy _Lcd_Busy fc
;              r -> R20
	.even
_Lcd_Busy::
	st -y,R20
	.dbline -1
	.dbline 68
; }
; 
; //=======================================================
; //读取lcd是否内部操作(忙碌)状态
; char Lcd_Busy()
; {
	.dbline 70
;     char r;
;     DDRB = 0x00;       //端口B设为输入方式
	clr R2
	out 0x17,R2
	.dbline 71
;     E_L;RS_L;RW_H;     //E=0(致能),RS=0(命令),RW=1(读)
	cbi 0x15,7
	.dbline 71
	cbi 0x15,5
	.dbline 71
	sbi 0x15,6
	.dbline 72
;     delay_us(2);       //液晶延时子程序
	ldi R16,2
	ldi R17,0
	rcall _delay_us
	.dbline 73
;     E_H;
	sbi 0x15,7
	.dbline 74
;     delay_us(2);       //液晶延时子程序
	ldi R16,2
	ldi R17,0
	rcall _delay_us
	.dbline 75
;     r = PINB & 0x80;   //读取lcd_data第八位
	in R20,0x16
	andi R20,128
	.dbline 76
;     E_L;
	cbi 0x15,7
	.dbline 77
;     DDRB=0xff;         //端口B设为输出方式
	ldi R24,255
	out 0x17,R24
	.dbline 78
;     return r;          //读取结果返回
	mov R16,R20
	.dbline -2
L9:
	.dbline 0 ; func end
	ld R20,y+
	ret
	.dbsym r r 20 c
	.dbend
	.dbfunc e Lcd_Command _Lcd_Command fV
;        Command -> R10
	.even
_Lcd_Command::
	st -y,R10
	mov R10,R16
	.dbline -1
	.dbline 84
; }
; 
; //=======================================================
; //向Lcd发送命令程序
; void Lcd_Command(unsigned char Command)
; {
L11:
	.dbline 85
;     while(Lcd_Busy()); //判断lcd是否内部操作状态
L12:
	.dbline 85
	rcall _Lcd_Busy
	tst R16
	brne L11
X2:
	.dbline 86
;     E_L;RS_L;RW_L;     //E=0(致能),RS=0(命令),RW=0(写)
	cbi 0x15,7
	.dbline 86
	cbi 0x15,5
	.dbline 86
	cbi 0x15,6
	.dbline 87
;     delay_us(2);       //液晶延时子程序
	ldi R16,2
	ldi R17,0
	rcall _delay_us
	.dbline 88
;     E_H;
	sbi 0x15,7
	.dbline 89
;     PORTB = Command;   //向Lcd发送命令
	out 0x18,R10
	.dbline 90
;     delay_us(2);       //液晶延时子程序
	ldi R16,2
	ldi R17,0
	rcall _delay_us
	.dbline 91
;     E_L;
	cbi 0x15,7
	.dbline -2
L10:
	.dbline 0 ; func end
	ld R10,y+
	ret
	.dbsym r Command 10 c
	.dbend
	.dbfunc e Lcd_Write _Lcd_Write fV
;           Data -> R10
	.even
_Lcd_Write::
	st -y,R10
	mov R10,R16
	.dbline -1
	.dbline 97
; }
; 
; //=======================================================
; //向lcd写入一个字符程序
; void Lcd_Write(unsigned char Data)
; {
L15:
	.dbline 98
;     while(Lcd_Busy()); //判断lcd是否内部操作状态
L16:
	.dbline 98
	rcall _Lcd_Busy
	tst R16
	brne L15
X3:
	.dbline 99
;     E_L;RS_H;RW_L;     //E=0(致能),RS=1(数据),RW=0(写)
	cbi 0x15,7
	.dbline 99
	sbi 0x15,5
	.dbline 99
	cbi 0x15,6
	.dbline 100
;     delay_us(2);       //液晶延时子程序
	ldi R16,2
	ldi R17,0
	rcall _delay_us
	.dbline 101
;     E_H;
	sbi 0x15,7
	.dbline 102
;     PORTB = Data;      //向lcd写入一个字符
	out 0x18,R10
	.dbline 103
;     delay_us(2);       //液晶延时子程序
	ldi R16,2
	ldi R17,0
	rcall _delay_us
	.dbline 104
;     E_L;
	cbi 0x15,7
	.dbline -2
L14:
	.dbline 0 ; func end
	ld R10,y+
	ret
	.dbsym r Data 10 c
	.dbend
	.dbfunc e Lcd_Init _Lcd_Init fV
	.even
_Lcd_Init::
	.dbline -1
	.dbline 116
; }
; 
; 
; /*=======================================================
; LCD第1行显示地址1~20(0x80~0x93)
; LCD第2行显示地址1~20(0xc0~0xd3)
; LCD第3行显示地址1~20(0x94~0xa7)
; LCD第4行显示地址1~20(0xd4~0xe7)
; =======================================================*/
; //初始化LCD_8位接口,4行x20字符的工作方式
; void Lcd_Init()
; {
	.dbline 117
;     DDRB = 0xff;       //端口B设为输出方式
	ldi R24,255
	out 0x17,R24
	.dbline 118
;     DDRD = 0xff;       //端口D设为输出方式
	out 0x11,R24
	.dbline 119
;     Lcd_Command(0x38); //
	ldi R16,56
	rcall _Lcd_Command
	.dbline 120
;     Lcd_Command(0x38); //
	ldi R16,56
	rcall _Lcd_Command
	.dbline 121
;     Lcd_Command(0x38); //
	ldi R16,56
	rcall _Lcd_Command
	.dbline 122
;     Lcd_Command(0x38); //
	ldi R16,56
	rcall _Lcd_Command
	.dbline 123
;     Lcd_Command(0x08); //令显示器off
	ldi R16,8
	rcall _Lcd_Command
	.dbline 124
;     Lcd_Command(0x01); //清除显示器
	ldi R16,1
	rcall _Lcd_Command
	.dbline 125
;     Lcd_Command(0x06); //令LCD每接收到1Byte数据后,AC自动加1
	ldi R16,6
	rcall _Lcd_Command
	.dbline 126
;     Lcd_Command(0x0C); //令光标,0x0c=不显示,0x0d=显示闪动. 
	ldi R16,12
	rcall _Lcd_Command
	.dbline -2
L18:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e asc_tran _asc_tran fV
;            asc -> R20,R21
	.even
_asc_tran::
	st -y,R20
	st -y,R21
	movw R20,R16
	.dbline -1
	.dbline 132
; }
; 
; //=======================================================
; //写ASCII字符串程序
; void asc_tran(unsigned char *asc)
; {
	rjmp L21
L20:
	.dbline 134
;     while((*asc) != 0)   //判断字是否结束
;     {
	.dbline 135
;         Lcd_Write(*asc); //向lcd写入字符串
	movw R30,R20
	ldd R16,z+0
	rcall _Lcd_Write
	.dbline 136
;         asc++;           //移下一个字符
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 137
;     }
L21:
	.dbline 133
	movw R30,R20
	ldd R2,z+0
	tst R2
	brne L20
X4:
	.dbline -2
L19:
	.dbline 0 ; func end
	ld R21,y+
	ld R20,y+
	ret
	.dbsym r asc 20 pc
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	.dbline -1
	.dbline 143
; }
; 
; //=======================================================
; //测试主LCD主程序
; void main()
; {
	.dbline 144
;     Lcd_Init(); //初始化LCD
	rcall _Lcd_Init
	rjmp L25
L24:
	.dbline 146
;     while(1)
;     {
	.dbline 147
;         Lcd_Command(0x83);               //设置显示位址
	ldi R16,131
	rcall _Lcd_Command
	.dbline 148
;         asc_tran("-----@_@------");      //显示字符串
	ldi R16,<L27
	ldi R17,>L27
	rcall _asc_tran
	.dbline 149
;         Lcd_Command(0x97);               //设置显示位址
	ldi R16,151
	rcall _Lcd_Command
	.dbline 150
;         asc_tran("www.ouravr.com");      //显示字符串
	ldi R16,<L28
	ldi R17,>L28
	rcall _asc_tran
	.dbline 151
;         delay_ms(1000);                  //延迟1秒
	ldi R16,1000
	ldi R17,3
	rcall _delay_ms
	.dbline 152
;         Lcd_Command(0x01);               //清除显示器
	ldi R16,1
	rcall _Lcd_Command
	.dbline 154
; 
;         Lcd_Command(0x83);               //设置显示位址
	ldi R16,131
	rcall _Lcd_Command
	.dbline 155
;         asc_tran("-----^_^------");      //显示字符串
	ldi R16,<L29
	ldi R17,>L29
	rcall _asc_tran
	.dbline 156
;         Lcd_Command(0x94);               //设置显示位址
	ldi R16,148
	rcall _Lcd_Command
	.dbline 157
;         asc_tran("http://59.36.96.196"); //显示字符串
	ldi R16,<L30
	ldi R17,>L30
	rcall _asc_tran
	.dbline 158
;         delay_ms(1000);                  //延迟
	ldi R16,1000
	ldi R17,3
	rcall _delay_ms
	.dbline 159
;         Lcd_Command(0x01);               //清除显示器
	ldi R16,1
	rcall _Lcd_Command
	.dbline 160
;     }
L25:
	.dbline 145
	rjmp L24
X5:
	.dbline -2
L23:
	.dbline 0 ; func end
	ret
	.dbend
	.area data(ram, con, rel)
	.dbfile F:\ouravr\M16LCD~1\LCD20x4.c
L30:
	.blkb 20
	.area idata
	.byte 'h,'t,'t,'p,58,47,47,53,57,46,51,54,46,57,54,46
	.byte 49,57,54,0
	.area data(ram, con, rel)
	.dbfile F:\ouravr\M16LCD~1\LCD20x4.c
L29:
	.blkb 15
	.area idata
	.byte 45,45,45,45,45,94,95,94,45,45,45,45,45,45,0
	.area data(ram, con, rel)
	.dbfile F:\ouravr\M16LCD~1\LCD20x4.c
L28:
	.blkb 15
	.area idata
	.byte 'w,'w,'w,46,'o,'u,'r,'a,'v,'r,46,'c,'o,'m,0
	.area data(ram, con, rel)
	.dbfile F:\ouravr\M16LCD~1\LCD20x4.c
L27:
	.blkb 15
	.area idata
	.byte 45,45,45,45,45,64,95,64,45,45,45,45,45,45,0
	.area data(ram, con, rel)
	.dbfile F:\ouravr\M16LCD~1\LCD20x4.c
; }

⌨️ 快捷键说明

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