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

📄 lcd.s

📁 AVR单片机ATmega16(L)应用实例1——风机测试仪
💻 S
字号:
	.module lcd.c
	.area text(rom, con, rel)
	.dbfile D:\ac18-1\lcd.c
	.dbfunc e ePutstr _ePutstr fV
;              l -> R20
;              i -> R22
;            ptr -> R10,R11
;              y -> R12
;              x -> R14
	.even
_ePutstr::
	xcall push_gset5
	mov R12,R18
	mov R14,R16
	sbiw R28,2
	ldd R10,y+12
	ldd R11,y+13
	.dbline -1
	.dbline 15
; #include <iom16v.h>
; #include <macros.h>
; #define uchar unsigned char
; #define uint unsigned int
; #define LCM_RS_1 PORTB|=BIT(PB0)
; #define LCM_RS_0 PORTB&=~BIT(PB0)
; #define LCM_RW_1 PORTB|=BIT(PB2)
; #define LCM_RW_0 PORTB&=~BIT(PB2)
; #define LCM_EN_1 PORTB|=BIT(PB3)
; #define LCM_EN_0 PORTB&=~BIT(PB3)
; #define DataPort PORTC
; #define Busy 0x80
; //***************************************
; void ePutstr(uchar x,uchar y,uchar const *ptr)
; {
	.dbline 16
; uchar i,l=0;
	clr R20
	xjmp L3
L2:
	.dbline 17
	.dbline 17
	inc R20
	.dbline 17
L3:
	.dbline 17
; 	while(ptr[l]>31){l++;}// ptr[l]大于31时,为ASCII码,进入while语句循环,
	mov R30,R20
	clr R31
	add R30,R10
	adc R31,R11
	lpm R30,Z
	ldi R24,31
	cp R24,R30
	brlo L2
	.dbline 19
	clr R22
	xjmp L8
L5:
	.dbline 19
; 							 //l累加,计算出字符串长度。
; 	for(i=0;i<l;i++){
	.dbline 20
; 	DisplayOneChar(x++,y,ptr[i]);// 显示单个字符,同时x轴座标递增。
	mov R30,R22
	clr R31
	add R30,R10
	adc R31,R11
	lpm R2,Z
	clr R3
	std y+1,R3
	std y+0,R2
	mov R18,R12
	clr R19
	mov R2,R14
	clr R3
	mov R24,R2
	subi R24,255    ; addi 1
	mov R14,R24
	mov R16,R2
	clr R17
	xcall _DisplayOneChar
	.dbline 21
; 	if(x==16){//若x等于16,进入if语句。
	mov R24,R14
	cpi R24,16
	brne L9
	.dbline 21
	.dbline 22
; 		x=0;y^=1;// x赋0,y与1按位异或(取反)。
	clr R14
	.dbline 22
	ldi R24,1
	eor R12,R24
	.dbline 23
; 	}
L9:
	.dbline 24
L6:
	.dbline 19
	inc R22
L8:
	.dbline 19
	cp R22,R20
	brlo L5
	.dbline -2
L1:
	adiw R28,2
	xcall pop_gset5
	.dbline 0 ; func end
	ret
	.dbsym r l 20 c
	.dbsym r i 22 c
	.dbsym r ptr 10 pkc
	.dbsym r y 12 c
	.dbsym r x 14 c
	.dbend
	.dbfunc e LocateXY _LocateXY fV
;           temp -> R20
;           posy -> R22
;           posx -> R10
	.even
_LocateXY::
	xcall push_gset3
	mov R22,R18
	mov R10,R16
	.dbline -1
	.dbline 28
;   }
; }
; //*************************************
; void LocateXY(char posx,char posy)
; {
	.dbline 30
; uchar temp;
; 	temp&=0x7f;// temp 的变化范围0~15。
	andi R20,127
	.dbline 31
; 	temp=posx&0x0f;//屏蔽高4位。
	mov R20,R10
	andi R20,15
	.dbline 32
; 	posy&=0x03;// posy的变化范围0~1。
	andi R22,3
	.dbline 33
; 	switch(posy)
	clr R23
	cpi R22,1
	ldi R30,0
	cpc R23,R30
	breq L15
	cpi R22,2
	ldi R30,0
	cpc R23,R30
	breq L16
	cpi R22,3
	ldi R30,0
	cpc R23,R30
	breq L17
	xjmp L13
X0:
	.dbline 34
; 	{
L15:
	.dbline 35
; 	case 1:temp|=0x40;break;//若posy 为1(显示第2行),地址码+0x40。
	ori R20,64
	.dbline 35
	xjmp L13
L16:
	.dbline 36
; 	case 2:temp|=0x10;break;//若posy 为2(显示第3行),地址码+0x10。
	ori R20,16
	.dbline 36
	xjmp L13
L17:
	.dbline 37
; 	case 3:temp|=0x50;break;//若posy 为3(显示第3行),地址码+0x50。
	ori R20,80
	.dbline 37
	.dbline 38
; 	default:break;
L13:
	.dbline 40
; 	}
; 	temp|=0x80;//指令码为地址码+0x80。
	ori R20,128
	.dbline 41
; 	LcdWriteCommand(temp,0);// 将指令temp 写入LCM,忽略忙信号检测。
	clr R18
	clr R19
	mov R16,R20
	clr R17
	xcall _LcdWriteCommand
	.dbline -2
L11:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r temp 20 c
	.dbsym r posy 22 c
	.dbsym r posx 10 c
	.dbend
	.dbfunc e DisplayOneChar _DisplayOneChar fV
;          Wdata -> y+4
;              y -> R22
;              x -> R20
	.even
_DisplayOneChar::
	xcall push_gset2
	mov R22,R18
	mov R20,R16
	.dbline -1
	.dbline 45
; }
; //**************************************
; void DisplayOneChar(uchar x,uchar y,uchar Wdata)
; {
	.dbline 46
; LocateXY(x,y);//调用LocateXY 函数定位显示地址。
	mov R18,R22
	mov R16,R20
	xcall _LocateXY
	.dbline 47
; LcdWriteData(Wdata);//将数据Wdata写入LCM。
	ldd R16,y+4
	clr R17
	xcall _LcdWriteData
	.dbline -2
L18:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l Wdata 4 c
	.dbsym r y 22 c
	.dbsym r x 20 c
	.dbend
	.dbfunc e InitLcd _InitLcd fV
	.even
_InitLcd::
	.dbline -1
	.dbline 51
; }
; //****************************************
; void InitLcd(void)
; {
	.dbline 52
; LcdWriteCommand(0x38,0); //8位数据传送,2行显示,5*7字形,不检测忙信号
	clr R18
	clr R19
	ldi R16,56
	ldi R17,0
	xcall _LcdWriteCommand
	.dbline 53
; Delay_nms(5);
	ldi R16,5
	ldi R17,0
	xcall _Delay_nms
	.dbline 54
; LcdWriteCommand(0x38,0); //8位数据传送,2行显示,5*7字形,不检测忙信号
	clr R18
	clr R19
	ldi R16,56
	ldi R17,0
	xcall _LcdWriteCommand
	.dbline 55
; Delay_nms(5);
	ldi R16,5
	ldi R17,0
	xcall _Delay_nms
	.dbline 56
; LcdWriteCommand(0x38,0); //8位数据传送,2行显示,5*7字形,不检测忙信号
	clr R18
	clr R19
	ldi R16,56
	ldi R17,0
	xcall _LcdWriteCommand
	.dbline 57
; Delay_nms(5);
	ldi R16,5
	ldi R17,0
	xcall _Delay_nms
	.dbline 58
; LcdWriteCommand(0x38,1); //8位数据传送,2行显示,5*7字形,检测忙信号
	ldi R18,1
	ldi R19,0
	ldi R16,56
	ldi R17,0
	xcall _LcdWriteCommand
	.dbline 59
; LcdWriteCommand(0x08,1); //关闭显示,检测忙信号
	ldi R18,1
	ldi R19,0
	ldi R16,8
	ldi R17,0
	xcall _LcdWriteCommand
	.dbline 60
; LcdWriteCommand(0x01,1); //清屏,检测忙信号
	ldi R18,1
	ldi R19,0
	ldi R16,1
	ldi R17,0
	xcall _LcdWriteCommand
	.dbline 61
; LcdWriteCommand(0x06,1); //显示光标右移设置,检测忙信号
	ldi R18,1
	ldi R19,0
	ldi R16,6
	ldi R17,0
	xcall _LcdWriteCommand
	.dbline 62
; LcdWriteCommand(0x0c,1); //显示屏打开,光标不显示、不闪烁,检测忙信号
	ldi R18,1
	ldi R19,0
	ldi R16,12
	ldi R17,0
	xcall _LcdWriteCommand
	.dbline -2
L19:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LcdWriteCommand _LcdWriteCommand fV
;        Attribc -> R22
;            CMD -> R20
	.even
_LcdWriteCommand::
	xcall push_gset2
	mov R22,R18
	mov R20,R16
	.dbline -1
	.dbline 66
; }
; //****************************************
; void LcdWriteCommand(uchar CMD,uchar Attribc)
; {
	.dbline 67
; if(Attribc)WaitForEnable();
	tst R22
	breq L21
	.dbline 67
	xcall _WaitForEnable
L21:
	.dbline 68
; Delay_nms(5);
	ldi R16,5
	ldi R17,0
	xcall _Delay_nms
	.dbline 69
; LCM_RS_0;LCM_RW_0;_NOP();
	cbi 0x18,0
	.dbline 69
	cbi 0x18,2
	.dbline 69
	nop
	.dbline 70
; DataPort=CMD;_NOP();
	out 0x15,R20
	.dbline 70
	nop
	.dbline 71
; LCM_EN_1;_NOP();_NOP();LCM_EN_0;
	sbi 0x18,3
	.dbline 71
	nop
	.dbline 71
	nop
	.dbline 71
	cbi 0x18,3
	.dbline -2
L20:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r Attribc 22 c
	.dbsym r CMD 20 c
	.dbend
	.dbfunc e LcdWriteData _LcdWriteData fV
;          dataW -> R20
	.even
_LcdWriteData::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 75
; }
; //***************************************
; void LcdWriteData(uchar dataW)
; {
	.dbline 76
; WaitForEnable();
	xcall _WaitForEnable
	.dbline 77
; Delay_nms(5);
	ldi R16,5
	ldi R17,0
	xcall _Delay_nms
	.dbline 78
; LCM_RS_1;LCM_RW_0;_NOP();
	sbi 0x18,0
	.dbline 78
	cbi 0x18,2
	.dbline 78
	nop
	.dbline 79
; DataPort=dataW;_NOP();
	out 0x15,R20
	.dbline 79
	nop
	.dbline 80
; LCM_EN_1;_NOP();_NOP();LCM_EN_0;
	sbi 0x18,3
	.dbline 80
	nop
	.dbline 80
	nop
	.dbline 80
	cbi 0x18,3
	.dbline -2
L23:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r dataW 20 c
	.dbend
	.dbfunc e WaitForEnable _WaitForEnable fV
;            val -> R16
	.even
_WaitForEnable::
	.dbline -1
	.dbline 84
; }
; //****************************************
; void WaitForEnable(void)
; {
	.dbline 86
; uchar val;
; DataPort=0xff;
	ldi R24,255
	out 0x15,R24
	.dbline 87
; LCM_RS_0;LCM_RW_1;_NOP();
	cbi 0x18,0
	.dbline 87
	sbi 0x18,2
	.dbline 87
	nop
	.dbline 88
; LCM_EN_1;_NOP();_NOP();
	sbi 0x18,3
	.dbline 88
	nop
	.dbline 88
	nop
	.dbline 89
; DDRC=0x00;
	clr R2
	out 0x14,R2
	.dbline 90
; val=PINA;
	in R16,0x19
	xjmp L26
L25:
	.dbline 91
	.dbline 91
	in R16,0x13
	.dbline 91
	wdr
	.dbline 91
L26:
	.dbline 91
; while(val&Busy){val=PINC;WDR();}
	sbrc R16,7
	rjmp L25
	.dbline 92
; LCM_EN_0;
	cbi 0x18,3
	.dbline 93
; DDRC=0xff;
	ldi R24,255
	out 0x14,R24
	.dbline -2
L24:
	.dbline 0 ; func end
	ret
	.dbsym r val 16 c
	.dbend

⌨️ 快捷键说明

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