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

📄 display.s

📁 Proteus实例集锦(包括电路图.仿真程序,各种各样的电路
💻 S
📖 第 1 页 / 共 5 页
字号:
	.module DISPLAY.C
	.area text(rom, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM/delay.h
	.dbfunc e delay_1us _delay_1us fV
	.even
_delay_1us::
	.dbline -1
	.dbline 14
; /*
; KS0108 128*64 LCD C语言驱动
; LCD引脚定义
; 1---GND 
; 2---VCC
; 3---VLCD
; 4---D/I
; 5---R/W
; 6---E
; 7到14 D0-D7
; 15--CS1
; 16--CS2
; 17--RESET
; 18--VEE
	.dbline 15
; 19--SW
	nop
	.dbline -2
	.dbline 16
; 20--NC 
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delay_nus _delay_nus fV
;              i -> R20,R21
;              n -> R22,R23
	.even
_delay_nus::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 19
; */
; #include <iom32v.h>
; #include <macros.h>
	.dbline 20
; #include "delay.h"
	clr R20
	clr R21
	.dbline 21
; unsigned char CurOffset,CurRow,CurPage,CurCol;	
	xjmp L6
L3:
	.dbline 22
	xcall _delay_1us
L4:
	.dbline 21
	subi R20,255  ; offset = 1
	sbci R21,255
L6:
	.dbline 21
	cp R20,R22
	cpc R21,R23
	brlo L3
	.dbline -2
	.dbline 23
; #define uchar unsigned char
; /*  常量定义  */
L2:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r n 22 i
	.dbend
	.dbfunc e delay_1ms _delay_1ms fV
;              i -> R16,R17
	.even
_delay_1ms::
	.dbline -1
	.dbline 26
; #define  LCD_STATUS_BUSY 0x80
; #define  START_LINE0   0xc0
; #define  DISPLAY_ON    0x3f
	.dbline 28
	clr R16
	clr R17
	xjmp L11
L8:
	.dbline 28
L9:
	.dbline 28
	subi R16,255  ; offset = 1
	sbci R17,255
L11:
	.dbline 28
; #define  DISPLAY_OFF   0x3e
; #define  PARA1         0x40
	cpi R16,116
	ldi R30,4
	cpc R17,R30
	brlo L8
	.dbline -2
	.dbline 29
; //#define  BIT(x)  (1<<x)
L7:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 i
	.dbend
	.dbfunc e delay_nms _delay_nms fV
;              i -> R20,R21
;              n -> R22,R23
	.even
_delay_nms::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 32
; //PORTA---数据口  PORTB----控制口
; volatile unsigned char *LCD_DIR_PORT = &DDRA;
; volatile unsigned char *LCD_IP_PORT  = &PINA;
	.dbline 33
; volatile unsigned char *LCD_OP_PORT  = &PORTA;
	clr R20
	clr R21
	.dbline 34
; 
	xjmp L16
L13:
	.dbline 35
	.dbline 36
	xcall _delay_1ms
	.dbline 37
L14:
	.dbline 34
	subi R20,255  ; offset = 1
	sbci R21,255
L16:
	.dbline 34
	cp R20,R22
	cpc R21,R23
	brlo L13
	.dbline -2
	.dbline 38
; volatile unsigned char *LCD_EN_PORT  = &PORTB;
; volatile unsigned char *LCD_CS2_PORT = &PORTC;
; volatile unsigned char *LCD_CS1_PORT = &PORTC;
; volatile unsigned char *LCD_RW_PORT  = &PORTC;
L12:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r n 22 i
	.dbend
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM/delay.h
_LCD_DIR_PORT::
	.blkb 2
	.area idata
	.word 58
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM/delay.h
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbsym e LCD_DIR_PORT _LCD_DIR_PORT pc
_LCD_IP_PORT::
	.blkb 2
	.area idata
	.word 57
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbsym e LCD_IP_PORT _LCD_IP_PORT pc
_LCD_OP_PORT::
	.blkb 2
	.area idata
	.word 59
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbsym e LCD_OP_PORT _LCD_OP_PORT pc
_LCD_EN_PORT::
	.blkb 2
	.area idata
	.word 56
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbsym e LCD_EN_PORT _LCD_EN_PORT pc
_LCD_CS2_PORT::
	.blkb 2
	.area idata
	.word 53
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbsym e LCD_CS2_PORT _LCD_CS2_PORT pc
_LCD_CS1_PORT::
	.blkb 2
	.area idata
	.word 53
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbsym e LCD_CS1_PORT _LCD_CS1_PORT pc
_LCD_RW_PORT::
	.blkb 2
	.area idata
	.word 53
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbsym e LCD_RW_PORT _LCD_RW_PORT pc
_LCD_DI_PORT::
	.blkb 2
	.area idata
	.word 53
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbsym e LCD_DI_PORT _LCD_DI_PORT pc
_LCD_EN_BIT::
	.blkb 1
	.area idata
	.byte 16
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbsym e LCD_EN_BIT _LCD_EN_BIT c
_LCD_CS2_BIT::
	.blkb 1
	.area idata
	.byte 8
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbsym e LCD_CS2_BIT _LCD_CS2_BIT c
_LCD_CS1_BIT::
	.blkb 1
	.area idata
	.byte 4
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbsym e LCD_CS1_BIT _LCD_CS1_BIT c
_LCD_RW_BIT::
	.blkb 1
	.area idata
	.byte 32
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbsym e LCD_RW_BIT _LCD_RW_BIT c
_LCD_DI_BIT::
	.blkb 1
	.area idata
	.byte 16
	.area data(ram, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbsym e LCD_DI_BIT _LCD_DI_BIT c
	.area text(rom, con, rel)
	.dbfile E:\PROTEU~1.7\User\MEGA32-LCM\MEGA32-LCM\DISPLAY.C
	.dbfunc e LCD_BUSY _LCD_BUSY fV
;         status -> <dead>
;             lr -> R16
	.even
_LCD_BUSY::
	.dbline -1
	.dbline 68
; volatile unsigned char *LCD_DI_PORT  = &PORTC;
; 
; char LCD_EN_BIT  = BIT(4);
; char LCD_CS2_BIT = BIT(3);
; char LCD_CS1_BIT = BIT(2);
; char LCD_RW_BIT  = BIT(5);
; char LCD_DI_BIT  = BIT(4);
; 
; #define SET_LCD_E      	        *LCD_EN_PORT |= LCD_EN_BIT    //LCD使能
; #define CLEAR_LCD_E       	    *LCD_EN_PORT &= ~LCD_EN_BIT   //LCD禁止
; 
; #define SET_LCD_DATA      	    *LCD_DI_PORT |= LCD_DI_BIT    //选择指令端口
; #define SET_LCD_CMD       	    *LCD_DI_PORT &= ~LCD_DI_BIT   //选择数据端口
; 
; #define SET_LCD_READ      	    *LCD_RW_PORT |= LCD_RW_BIT    //读模式
; #define SET_LCD_WRITE      	    *LCD_RW_PORT &= ~LCD_RW_BIT   //写模式
; 
; #define SET_LCD_CS2      	    *LCD_CS2_PORT |= LCD_CS2_BIT  //左屏选择禁止
; #define CLEAR_LCD_CS2      	    *LCD_CS2_PORT &= ~LCD_CS2_BIT //左屏选择使能
; 
; #define SET_LCD_CS1      	    *LCD_CS1_PORT |= LCD_CS1_BIT  //左屏选择禁止
; #define CLEAR_LCD_CS1      	    *LCD_CS1_PORT &= ~LCD_CS1_BIT //左屏选择使能
; 
; #define LEFT 0
; #define RIGHT 1
; #define CMD 0
; #define DATA 1
; 
; void LCD_BUSY(unsigned char lr) //判断忙标志
; {
	.dbline 70
;     unsigned char status;
;     _CLI();
	cli
	.dbline 71
;     if(lr==LEFT)
	tst R16
	brne L18
	.dbline 72
;     {
	.dbline 73
;         CLEAR_LCD_CS2; //cs2=0
	lds R2,_LCD_CS2_BIT
	com R2
	lds R30,_LCD_CS2_PORT
	lds R31,_LCD_CS2_PORT+1
	ldd R3,z+0
	and R3,R2
	std z+0,R3
	.dbline 74
;         SET_LCD_CS1;   //cs1=1
	lds R2,_LCD_CS1_BIT
	lds R30,_LCD_CS1_PORT
	lds R31,_LCD_CS1_PORT+1
	ldd R3,z+0
	or R3,R2
	std z+0,R3
	.dbline 75
;     }
	xjmp L19
L18:
	.dbline 77
;     else
;     {
	.dbline 78
;         SET_LCD_CS2;   //cs2=1
	lds R2,_LCD_CS2_BIT
	lds R30,_LCD_CS2_PORT
	lds R31,_LCD_CS2_PORT+1
	ldd R3,z+0
	or R3,R2
	std z+0,R3
	.dbline 79
;         CLEAR_LCD_CS1; //cs1=0
	lds R2,_LCD_CS1_BIT
	com R2
	lds R30,_LCD_CS1_PORT
	lds R31,_LCD_CS1_PORT+1
	ldd R3,z+0
	and R3,R2
	std z+0,R3
	.dbline 80
;     }	
L19:
	.dbline 81
;     SET_LCD_CMD;
	lds R2,_LCD_DI_BIT
	com R2
	lds R30,_LCD_DI_PORT
	lds R31,_LCD_DI_PORT+1
	ldd R3,z+0
	and R3,R2
	std z+0,R3
	.dbline 82
;     *LCD_DIR_PORT = 0x00;
	clr R2
	lds R30,_LCD_DIR_PORT
	lds R31,_LCD_DIR_PORT+1
	std z+0,R2
	.dbline 83
;     *LCD_OP_PORT = 0xff;		
	ldi R24,255
	lds R30,_LCD_OP_PORT
	lds R31,_LCD_OP_PORT+1
	std z+0,R24
	.dbline 84
;     SET_LCD_READ;
	lds R2,_LCD_RW_BIT
	lds R30,_LCD_RW_PORT
	lds R31,_LCD_RW_PORT+1
	ldd R3,z+0
	or R3,R2
	std z+0,R3
	.dbline 85
;     SET_LCD_E;					
	lds R2,_LCD_EN_BIT
	lds R30,_LCD_EN_PORT
	lds R31,_LCD_EN_PORT+1
	ldd R3,z+0
	or R3,R2
	std z+0,R3
	.dbline 86
;     _NOP();	
	nop
	.dbline 87
;     _NOP();
	nop
	.dbline 88
;     _NOP();
	nop
	.dbline 89
;     _NOP();
	nop
	xjmp L21
L20:
	.dbline 91
	.dbline 92
	lds R2,_LCD_EN_BIT
	com R2
	lds R30,_LCD_EN_PORT
	lds R31,_LCD_EN_PORT+1
	ldd R3,z+0
	and R3,R2
	std z+0,R3
	.dbline 93
	nop
	.dbline 94
	nop
	.dbline 95
	nop
	.dbline 96
	nop
	.dbline 97
	lds R2,_LCD_EN_BIT
	or R3,R2
	std z+0,R3
	.dbline 98
	nop
	.dbline 99
	nop
	.dbline 100
	nop
	.dbline 101
	nop
	.dbline 102
L21:
	.dbline 90
;     while((*LCD_IP_PORT) & LCD_STATUS_BUSY)
	lds R30,_LCD_IP_PORT
	lds R31,_LCD_IP_PORT+1
	ldd R2,z+0
	sbrc R2,7
	rjmp L20
	.dbline 103
;     {
;         CLEAR_LCD_E;	   		
;         _NOP();
;         _NOP();
;         _NOP();
;         _NOP();
;         SET_LCD_E;
;         _NOP();
;         _NOP();
;         _NOP();
;         _NOP();
;     }
;     CLEAR_LCD_E;
	lds R2,_LCD_EN_BIT
	com R2
	lds R30,_LCD_EN_PORT
	lds R31,_LCD_EN_PORT+1
	ldd R3,z+0
	and R3,R2
	std z+0,R3
	.dbline 104
;     SET_LCD_WRITE;
	lds R2,_LCD_RW_BIT
	com R2
	lds R30,_LCD_RW_PORT
	lds R31,_LCD_RW_PORT+1
	ldd R3,z+0
	and R3,R2
	std z+0,R3
	.dbline 105
;     *LCD_OP_PORT = 0xff;
	ldi R24,255
	lds R30,_LCD_OP_PORT
	lds R31,_LCD_OP_PORT+1
	std z+0,R24
	.dbline 106
;     asm("sei");//)asm("sei");
	sei
	.dbline -2
	.dbline 107
; }
L17:
	.dbline 0 ; func end
	ret
	.dbsym l status 1 c
	.dbsym r lr 16 c
	.dbend
	.dbfunc e write_LCD _write_LCD fV
;           data -> y+4
;             cd -> R20
;             lr -> R22
	.even
_write_LCD::
	xcall push_gset2
	mov R20,R18
	mov R22,R16
	.dbline -1
	.dbline 110
; 
; void write_LCD(unsigned char lr,unsigned char cd,unsigned char data) /*写入指令或数据*/
; {	
	.dbline 111
;     _CLI();//_CLI();
	cli
	.dbline 112
;     LCD_BUSY(lr);
	mov R16,R22
	xcall _LCD_BUSY
	.dbline 113
;     if(cd==CMD)
	tst R20
	brne L24
	.dbline 114
;     {
	.dbline 115
;         SET_LCD_CMD;
	lds R2,_LCD_DI_BIT
	com R2
	lds R30,_LCD_DI_PORT
	lds R31,_LCD_DI_PORT+1
	ldd R3,z+0
	and R3,R2
	std z+0,R3
	.dbline 116
;     }
	xjmp L25
L24:
	.dbline 118
;     else
;     {
	.dbline 119
;         SET_LCD_DATA;
	lds R2,_LCD_DI_BIT
	lds R30,_LCD_DI_PORT
	lds R31,_LCD_DI_PORT+1
	ldd R3,z+0
	or R3,R2
	std z+0,R3
	.dbline 120
;     }
L25:
	.dbline 121
;     SET_LCD_WRITE; 
	lds R2,_LCD_RW_BIT
	com R2
	lds R30,_LCD_RW_PORT
	lds R31,_LCD_RW_PORT+1
	ldd R3,z+0
	and R3,R2
	std z+0,R3
	.dbline 122
;     SET_LCD_E;
	lds R2,_LCD_EN_BIT
	lds R30,_LCD_EN_PORT
	lds R31,_LCD_EN_PORT+1
	ldd R3,z+0
	or R3,R2
	std z+0,R3
	.dbline 123
;     *LCD_DIR_PORT = 0xff;
	ldi R24,255
	lds R30,_LCD_DIR_PORT
	lds R31,_LCD_DIR_PORT+1
	std z+0,R24
	.dbline 124
;     *LCD_OP_PORT = data;
	lds R30,_LCD_OP_PORT
	lds R31,_LCD_OP_PORT+1
	ldd R0,y+4
	std z+0,R0
	.dbline 125
;     _NOP();
	nop
	.dbline 126
;     _NOP();
	nop
	.dbline 127
;     _NOP();
	nop
	.dbline 128
;     _NOP();
	nop
	.dbline 129
;     CLEAR_LCD_E;
	com R2
	lds R30,_LCD_EN_PORT
	lds R31,_LCD_EN_PORT+1
	ldd R3,z+0
	and R3,R2
	std z+0,R3
	.dbline 130
;     *LCD_OP_PORT = 0xff;
	lds R30,_LCD_OP_PORT
	lds R31,_LCD_OP_PORT+1
	std z+0,R24
	.dbline 131
;     _SEI();
	sei
	.dbline -2
	.dbline 132
; }
L23:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l data 4 c
	.dbsym r cd 20 c
	.dbsym r lr 22 c
	.dbend
	.dbfunc e read_LCD _read_LCD fc
;           data -> R20
;             lr -> R22
	.even
_read_LCD::
	xcall push_gset2
	mov R22,R16
	.dbline -1
	.dbline 134
; unsigned char read_LCD(unsigned char lr)	  /*  读显示数据 */
; {
	.dbline 136
;     unsigned char data;
;     _CLI();
	cli
	.dbline 137
;     LCD_BUSY(lr);
	mov R16,R22
	xcall _LCD_BUSY
	.dbline 138
;     SET_LCD_DATA;
	lds R2,_LCD_DI_BIT
	lds R30,_LCD_DI_PORT
	lds R31,_LCD_DI_PORT+1
	ldd R3,z+0
	or R3,R2
	std z+0,R3
	.dbline 139
;     *LCD_DIR_PORT = 0x00;
	clr R2
	lds R30,_LCD_DIR_PORT
	lds R31,_LCD_DIR_PORT+1
	std z+0,R2
	.dbline 140
;     *LCD_OP_PORT = 0xff;
	ldi R24,255
	lds R30,_LCD_OP_PORT
	lds R31,_LCD_OP_PORT+1
	std z+0,R24
	.dbline 141
;     SET_LCD_READ;
	lds R2,_LCD_RW_BIT
	lds R30,_LCD_RW_PORT
	lds R31,_LCD_RW_PORT+1
	ldd R3,z+0
	or R3,R2
	std z+0,R3
	.dbline 142
;     SET_LCD_E;
	lds R2,_LCD_EN_BIT
	lds R30,_LCD_EN_PORT
	lds R31,_LCD_EN_PORT+1
	ldd R3,z+0
	or R3,R2
	std z+0,R3
	.dbline 143
;     _NOP();
	nop
	.dbline 144
;     _NOP();
	nop
	.dbline 145
;     _NOP();
	nop
	.dbline 146
;     _NOP();
	nop
	.dbline 147
;     data=*LCD_IP_PORT;
	lds R30,_LCD_IP_PORT
	lds R31,_LCD_IP_PORT+1
	ldd R20,z+0
	.dbline 148
;     CLEAR_LCD_E;
	com R2
	lds R30,_LCD_EN_PORT
	lds R31,_LCD_EN_PORT+1
	ldd R3,z+0
	and R3,R2
	std z+0,R3
	.dbline 149
;     SET_LCD_WRITE;
	lds R2,_LCD_RW_BIT
	com R2
	lds R30,_LCD_RW_PORT
	lds R31,_LCD_RW_PORT+1
	ldd R3,z+0
	and R3,R2
	std z+0,R3
	.dbline 150
;     LCD_BUSY(lr);
	mov R16,R22
	xcall _LCD_BUSY
	.dbline 151
;     SET_LCD_DATA; 
	lds R2,_LCD_DI_BIT
	lds R30,_LCD_DI_PORT
	lds R31,_LCD_DI_PORT+1
	ldd R3,z+0
	or R3,R2
	std z+0,R3
	.dbline 152
;     *LCD_DIR_PORT = 0x00;
	clr R2
	lds R30,_LCD_DIR_PORT
	lds R31,_LCD_DIR_PORT+1
	std z+0,R2
	.dbline 153
;     *LCD_OP_PORT = 0xff;
	ldi R24,255
	lds R30,_LCD_OP_PORT
	lds R31,_LCD_OP_PORT+1
	std z+0,R24
	.dbline 154
;     SET_LCD_READ; 
	lds R2,_LCD_RW_BIT
	lds R30,_LCD_RW_PORT
	lds R31,_LCD_RW_PORT+1
	ldd R3,z+0
	or R3,R2
	std z+0,R3
	.dbline 155
;     SET_LCD_E;
	lds R2,_LCD_EN_BIT
	lds R30,_LCD_EN_PORT
	lds R31,_LCD_EN_PORT+1
	ldd R3,z+0
	or R3,R2
	std z+0,R3
	.dbline 156
;     _NOP();	
	nop
	.dbline 157
;     _NOP();
	nop
	.dbline 158
;     _NOP();
	nop
	.dbline 159
;     _NOP();
	nop
	.dbline 160
;     data=*LCD_IP_PORT;
	lds R30,_LCD_IP_PORT
	lds R31,_LCD_IP_PORT+1
	ldd R20,z+0
	.dbline 161
;     CLEAR_LCD_E;
	com R2
	lds R30,_LCD_EN_PORT
	lds R31,_LCD_EN_PORT+1

⌨️ 快捷键说明

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