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

📄 st7920.s

📁 ST7920液晶控制器的AVR程序
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module ST7920.c
	.area text(rom, con, rel)
	.dbfile F:\毕业设计\LCM12864\ST7920.c
	.dbfunc e Delayus _Delayus fV
;              i -> y+0
;              x -> y+8
	.even
_Delayus::
	xcall push_arg4
	sbiw R28,8
	.dbline -1
	.dbline 10
; #include "ST7920.h"
; void Delayus(ulong x);
; void Delayms(uchar x);
; void BUSYLOOP(void);
; void WriteCommand(uchar command);
; void WriteData(uchar data);
; 
; /**********************延时程序START********************************/
; void Delayus(ulong x)  	
; {	ulong i;
	.dbline 11
; 	i = x<<4;
	ldi R24,4
	ldi R25,0
	ldd R16,y+8
	ldd R17,y+9
	ldd R18,y+10
	ldd R19,y+11
	st -y,R24
	xcall lsl32
	std y+0,R16
	std y+1,R17
	std y+2,R18
	std y+3,R19
L2:
	.dbline 12
; 	while(i--);
L3:
	.dbline 12
	ldd R2,y+0
	ldd R3,y+1
	ldd R4,y+2
	ldd R5,y+3
	std y+4,R2
	std y+5,R3
	std y+6,R4
	std y+7,R5
	ldi R24,1
	ldi R25,0
	ldi R26,0
	ldi R27,0
	ldd R2,y+4
	ldd R3,y+5
	ldd R4,y+6
	ldd R5,y+7
	sub R2,R24
	sbc R3,R25
	sbc R4,R26
	sbc R5,R27
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	ldd R2,y+4
	ldd R3,y+5
	ldd R4,y+6
	ldd R5,y+7
	ldi R16,0
	cp R2,R16
	cpc R3,R16
	cpc R4,R16
	cpc R5,R16
	brne L2
X0:
	.dbline -2
L1:
	.dbline 0 ; func end
	adiw R28,12
	ret
	.dbsym l i 0 l
	.dbsym l x 8 l
	.dbend
	.dbfunc e Delayms _Delayms fV
;              i -> R20,R21
;              x -> R10
	.even
_Delayms::
	xcall push_xgset300C
	mov R10,R16
	.dbline -1
	.dbline 15
; }
; void Delayms(uchar x)
; {   uint i;
	.dbline 16
; 	i = x;
	mov R20,R10
	clr R21
	xjmp L7
L6:
	.dbline 17
; 	while(i--)Delayus(1000);
	ldi R16,232
	ldi R17,3
	ldi R18,0
	ldi R19,0
	xcall _Delayus
L7:
	.dbline 17
	movw R2,R20
	subi R20,1
	sbci R21,0
	tst R2
	brne L6
	tst R3
	brne L6
X1:
	.dbline -2
L5:
	.dbline 0 ; func end
	xjmp pop_xgset300C
	.dbsym r i 20 i
	.dbsym r x 10 c
	.dbend
	.dbfunc e BUSYLOOP _BUSYLOOP fV
	.even
_BUSYLOOP::
	.dbline -1
	.dbline 20
; } 	 
; void BUSYLOOP(void)
; {
	.dbline 21
;  	Delayus(10);
	ldi R16,10
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xcall _Delayus
	.dbline -2
L9:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e lcm_out _lcm_out fV
;              d -> R22
;              i -> R20
;              a -> R16
	.even
_lcm_out::
	st -y,R20
	st -y,R22
	.dbline -1
	.dbline 27
; }
; /**********************延时程序END********************************/
;          
; /**********************串行方式相关程序START*********************/								
; void lcm_out(uchar a)
; {
	.dbline 29
; 	char i,d;
; 	for(i=0;i<8;i++)
	clr R20
	xjmp L14
L11:
	.dbline 30
; 	{
	.dbline 31
; 		clrbit(LCD_CTRL,E);  
	cbi 0x18,7
	.dbline 32
; 		d=a&0x80;
	mov R22,R16
	andi R22,128
	.dbline 33
; 		if(d)
	breq L15
X2:
	.dbline 34
; 			setbit(LCD_CTRL,RW);
	sbi 0x18,6
	xjmp L16
L15:
	.dbline 36
; 		else
; 			clrbit(LCD_CTRL,RW);
	cbi 0x18,6
L16:
	.dbline 37
; 		a<<=1;
	lsl R16
	.dbline 38
; 		setbit(LCD_CTRL,E); //上升弦发送
	sbi 0x18,7
	.dbline 39
; 	}
L12:
	.dbline 29
	inc R20
L14:
	.dbline 29
	cpi R20,8
	brlo L11
X3:
	.dbline -2
L10:
	.dbline 0 ; func end
	ld R22,y+
	ld R20,y+
	ret
	.dbsym r d 22 c
	.dbsym r i 20 c
	.dbsym r a 16 c
	.dbend
	.dbfunc e WriteCommand _WriteCommand fV
;              s -> R20
;        command -> R22
	.even
_WriteCommand::
	st -y,R20
	st -y,R22
	mov R22,R16
	.dbline -1
	.dbline 44
; }
; 
; 
; void WriteCommand(uchar command)	//发送命令字
; {    
	.dbline 46
; 	uchar s;  //,i; 
; 	s=command&0xf0;
	mov R20,R22
	andi R20,240
	.dbline 47
; 	lcm_out(0xf8); 			   //送写命令指令  1111 1 RW=0 RS=0  0
	ldi R16,248
	xcall _lcm_out
	.dbline 48
; 	lcm_out(s);            //发送高四位数据
	mov R16,R20
	xcall _lcm_out
	.dbline 49
; 	s=command&0x0f;
	mov R20,R22
	andi R20,15
	.dbline 50
; 	s<<=4;
	mov R24,R20
	andi R24,#0x0F
	swap R24
	mov R20,R24
	.dbline 51
; 	lcm_out(s);            //发送低四位数据
	mov R16,R24
	xcall _lcm_out
	.dbline -2
L17:
	.dbline 0 ; func end
	ld R22,y+
	ld R20,y+
	ret
	.dbsym r s 20 c
	.dbsym r command 22 c
	.dbend
	.dbfunc e WriteData _WriteData fV
;              s -> R20
;           data -> R22
	.even
_WriteData::
	st -y,R20
	st -y,R22
	mov R22,R16
	.dbline -1
	.dbline 57
; 	//for(i=1;i>0;i--)BUSYLOOP();	//延时10us	 延时后写命令就消失?
; }
; 
; 
; void WriteData(uchar data)
; {
	.dbline 60
;     
; 	uchar s;  //,i; 
; 	s=data&0xf0;
	mov R20,R22
	andi R20,240
	.dbline 61
; 	lcm_out(0xfa);         //送写数据指令  1111 1 RW=0 RS=1  0
	ldi R16,250
	xcall _lcm_out
	.dbline 62
; 	lcm_out(s);
	mov R16,R20
	xcall _lcm_out
	.dbline 63
; 	s=data&0x0f;
	mov R20,R22
	andi R20,15
	.dbline 64
; 	s<<=4;
	mov R24,R20
	andi R24,#0x0F
	swap R24
	mov R20,R24
	.dbline 65
; 	lcm_out(s);
	mov R16,R24
	xcall _lcm_out
	.dbline -2
L18:
	.dbline 0 ; func end
	ld R22,y+
	ld R20,y+
	ret
	.dbsym r s 20 c
	.dbsym r data 22 c
	.dbend
	.dbfunc e lcdSetXY _lcdSetXY fV
;       position -> R20
;              y -> R10
;              x -> R22
	.even
_lcdSetXY::
	xcall push_xgsetF00C
	mov R10,R18
	mov R22,R16
	.dbline -1
	.dbline 75
; 	//for(i=1;i>0;i--)BUSYLOOP();	//延时10us	延时后写命令就无效?
; }
; /**********************串行方式相关程序END*********************/
;   
;                 
; /**********************液晶文字显示相关程序START*************/
; 
; 
; void lcdSetXY(uchar x,uchar y)  //定位坐标的位置,这个主要跟字符显示相关
; {  //x:横0-15   y:纵 0-3  ;x,y对应12864的坐标
	.dbline 76
;  	unsigned char position=0;
	clr R20
	.dbline 77
; 	x &= 0x0f;//x%16;
	andi R22,15
	.dbline 78
; 	switch(y%4)
	ldi R18,4
	ldi R19,0
	mov R16,R10
	clr R17
	xcall mod16s
	movw R10,R16
	cpi R16,0
	cpc R16,R17
	breq L23
X4:
	movw R24,R10
	cpi R16,1
	ldi R30,0
	cpc R17,R30
	breq L24
X5:
	cpi R16,2
	ldi R30,0
	cpc R17,R30
	breq L25
X6:
	cpi R16,3
	ldi R30,0
	cpc R17,R30
	breq L26
X7:
	xjmp L21
L23:
	.dbline 80
; 	{    //第零行和第二行寄存器连续   第一行和第三行寄存器连续
; 	  case 0: position = 0x80 + (x>>1); break;		// |0x80	~	0x87|
	mov R20,R22
	lsr R20
	subi R20,128    ; addi 128
	.dbline 80
	xjmp L21
L24:
	.dbline 81
; 		case 1: position = 0x90 + (x>>1); break;		// |0x90	~   0x97|
	mov R20,R22
	lsr R20
	subi R20,112    ; addi 144
	.dbline 81
	xjmp L21
L25:
	.dbline 82
; 		case 2: position = 0x88 + (x>>1); break;		// |0x88 	~   0x8f|
	mov R20,R22
	lsr R20
	subi R20,120    ; addi 136
	.dbline 82
	xjmp L21
L26:
	.dbline 83
; 		case 3: position = 0x98 + (x>>1); break;		// |0x98	~	0x9f|
	mov R20,R22
	lsr R20
	subi R20,104    ; addi 152
	.dbline 83
	.dbline 84
; 		default: break;
L21:
	.dbline 86
; 	}
; 	WriteCommand(position);
	mov R16,R20
	xcall _WriteCommand
	.dbline -2
L19:
	.dbline 0 ; func end
	xjmp pop_xgsetF00C
	.dbsym r position 20 c
	.dbsym r y 10 c
	.dbsym r x 22 c
	.dbend
	.dbfunc e SetGraphicAddr _SetGraphicAddr fV
;          ytemp -> R22
;              y -> R10
;              x -> R20
	.even
_SetGraphicAddr::
	xcall push_xgsetF00C
	mov R10,R18
	mov R20,R16
	.dbline -1
	.dbline 91
; } 
; 
; //x:横0-15   y:纵 0-63  
; void SetGraphicAddr(uchar x,uchar y)
; {
	.dbline 93
;  	uchar ytemp;
; 	EX_FT();  //跟绘图设置有关  8BIT控制界面,扩充指令集,,绘图显示开
	ldi R16,54
	xcall _WriteCommand
	.dbline 94
; 	ytemp = (y & 0x1f) | 0x80;
	mov R22,R10
	andi R22,31
	ori R22,128
	.dbline 95
; 	WriteCommand(ytemp);							//先写st7920 垂直坐标
	mov R16,R22
	xcall _WriteCommand
	.dbline 96
; 	ytemp = (y>>5); 		//12864的y坐标打印32的对应ST水平坐标0x88~0x8f,垂直坐标(y-32)
	mov R22,R10
	lsr R22
	lsr R22
	lsr R22
	lsr R22
	lsr R22
	.dbline 97
; 	x &= 0x0f;//x%16;
	andi R20,15
	.dbline 98
; 	x  = 0x80 +(ytemp<<3) + (x>>1);			 		//0 |0x80	~	0x87|	
	mov R2,R20
	lsr R2
	mov R20,R22
	lsl R20
	lsl R20
	lsl R20
	subi R20,128    ; addi 128
	add R20,R2
	.dbline 99
; 	WriteCommand(x);								//1 |                   																																 
	mov R16,R20
	xcall _WriteCommand
	.dbline 104
; 	                               					//. |数值表示st的位址   
; 							                 		//. |					
; 													//31|                   																												 		
; 													//0	|0x88	~   0x8f|   
; 	FunctionSet();					//功能设置 8位数据,基本指令                                                                                                                     	
	ldi R16,48
	xcall _WriteCommand
	.dbline -2
L27:
	.dbline 0 ; func end
	xjmp pop_xgsetF00C
	.dbsym r ytemp 22 c
	.dbsym r y 10 c
	.dbsym r x 20 c
	.dbend
	.dbfunc e lcdInit _lcdInit fV
	.even
_lcdInit::
	.dbline -1
	.dbline 109
; } 
; 
; 
; void lcdInit()		//液晶初始化						
; { 
	.dbline 111
; 	//初始化控制管脚
; 	DDR_LCD_CTRL |= BIT(RS);
	sbi 0x17,5
	.dbline 112
; 	DDR_LCD_CTRL |= BIT(RW);  
	sbi 0x17,6
	.dbline 113
; 	DDR_LCD_CTRL |= BIT(E);
	sbi 0x17,7
	.dbline 114
; 	LCD_CTRL |= BIT(RS);
	sbi 0x18,5
	.dbline 115
; 	LCD_CTRL |= BIT(RW);  
	sbi 0x18,6
	.dbline 116
; 	LCD_CTRL |= BIT(E);
	sbi 0x18,7
	.dbline 118
; 	
; 	FunctionSet();                      
	ldi R16,48
	xcall _WriteCommand
	.dbline 119
; 	Delayus(150); 
	ldi R16,150
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xcall _Delayus
	.dbline 121
; 	                             	
; 	FunctionSet(); 
	ldi R16,48
	xcall _WriteCommand
	.dbline 122
; 	Delayus(50);
	ldi R16,50
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xcall _Delayus
	.dbline 124
; 	                    	
;   DisplayOff();
	ldi R16,8
	xcall _WriteCommand
	.dbline 125
; 	Delayus(150);
	ldi R16,150
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xcall _Delayus
	.dbline 127
;                                                 
; 	lcdClear(); //清屏程序 需要毫秒级的延时
	.dbline 127
	ldi R16,1
	xcall _WriteCommand
	.dbline 127
	ldi R16,10
	xcall _Delayms
	.dbline 127
	.dbline 127
	.dbline 128
; 	Delayus(150);
	ldi R16,150
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xcall _Delayus
	.dbline 129
;   EntryModeSet();  //设定写入时候指针右移               
	ldi R16,6
	xcall _WriteCommand
	.dbline 130
; 	DisplayOn(); 
	ldi R16,12
	xcall _WriteCommand
	.dbline 131
; 	Delayus(50); 
	ldi R16,50
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xcall _Delayus
	.dbline 132
; 	DisplayOn(); 
	ldi R16,12
	xcall _WriteCommand
	.dbline 133
; 	Delayus(50);                 
	ldi R16,50
	ldi R17,0
	ldi R18,0
	ldi R19,0
	xcall _Delayus
	.dbline -2
L28:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e lcdDisplay _lcdDisplay fV
;    LineDispCnt -> R12
;              i -> R10
;            ptr -> R20,R21
;              y -> R14
;              x -> R22
	.even
_lcdDisplay::
	xcall push_xgsetF0FC
	mov R14,R18
	mov R22,R16
	ldd R20,y+10
	ldd R21,y+11
	.dbline -1
	.dbline 137
; } 
; 
; void lcdDisplay( uchar x, uchar y, uchar *ptr ) //行写满自动换行
; {   
	.dbline 139
; 	uchar i;
; 	uchar LineDispCnt = 0;
	.dbline 140
; 	LineDispCnt = (16-x+x%2);
	ldi R17,2
	mov R16,R22
	xcall mod8u
	ldi R24,16
	mov R12,R24
	sub R12,R22
	add R12,R16
	.dbline 141
; 	lcdSetXY(x,y);
	mov R18,R14
	mov R16,R22
	xcall _lcdSetXY
	.dbline 142
; 	i = 0;
	clr R10
	xjmp L31
L30:
	.dbline 144
; 	while((ptr[i])!='\0')
; 	{
	.dbline 145
; 		WriteData(ptr[i]);

⌨️ 快捷键说明

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