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

📄 7920.s

📁 7920两行中文液晶显示屏的源程序及电路图 (ICC)
💻 S
字号:
	.module _7920.c
	.area data(ram, con, rel)
_TextLogo::
	.blkb 19
	.area idata
	.byte 210,186,190,167,207,212,202,190,196,163,191,233,40,'L,'C,'D
	.byte 'M,41,0
	.area data(ram, con, rel)
	.dbfile E:\_opt\___7920_serial\source\7920.c
	.dbsym e TextLogo _TextLogo A[19:19]c
	.area text(rom, con, rel)
	.dbfile E:\_opt\___7920_serial\source\7920.c
	.dbfunc e initLCDM _initLCDM fV
	.even
_initLCDM::
	.dbline -1
	.dbline 55
; //本程序是7920的LM3037的液晶驱动程序
; //汉字2x9
; //ATMEGA16, 内部晶振8M  
; //使用串行传输 
; //本程序测试通过
; 
; //绿叶子整理 -- 2005.08.30
; 
; #include <iom16v.h>
; #include <macros.h>
; 
; #define LCD_DATA_PORT  PORTA
; #define LCD_DATA_DDR   DDRA
; #define LCD_DATA_PIN   PINA
; #define LCD_DATA       0x0ff   //portA   out
; 
; #define LCD_CONTROL_PORT    PORTB
; #define LCD_CONTROL_DDR     DDRB
; 
; #define	RS	 0      //RS(CS) 可直接接VCC -- 替代
; #define	RW	 1      //RW(SID) 
; #define	E	 2      //E(sclk)
; #define	PSB	 3      //可以直接接地  -- 替代
; #define	_RES	 4  //可以去掉
; 
; /*--------------------------------------------------------------------------------------------------
; Public function prototypes
; --------------------------------------------------------------------------------------------------*/
; void delay_1us(void);
; void delay_1ms(void);
; void delay_nus          (unsigned int n);
; void delay_nms          (unsigned int n);
; 
; #define	SETBIT(x,y) (x|=(1<<y))      //set bit y in byte x
; #define	CLRBIT(x,y) (x&=(~(1<<y)))   //clear bit y in byte x
; #define	CHKBIT(x,y) (x&(1<<y))       //check bit y in byte x
; 
; #define uchar unsigned char // 0~255
; #define uint unsigned int   // 0~65535
; 
; void  CheckState();
; void initLCDM(void);
; void Send(unsigned char senddata);
; void SdCmd(unsigned char scmd);
; void SdData(unsigned char DData); 
; void WriteTextScreen(unsigned char *TxtData);
; void WriteTextScreen2(unsigned char *pstr);
; void WriteGraphicScreen(unsigned char *GDData);
; 
; void DispSetCursor(unsigned char LineNum, unsigned char ColumnNum);
; 
; unsigned char  TextLogo[]={"液晶显示模块(LCDM)"};
; 
; void initLCDM(void)
; {
	.dbline 56
; 	delay_nms(100);
	ldi R16,100
	ldi R17,0
	xcall _delay_nms
	.dbline 60
; 
;  	//端口初始化
; 	//LCD_DATA_DDR=0xFF;
; 	LCD_CONTROL_DDR=0xFF; 
	ldi R24,255
	out 0x17,R24
	.dbline 62
; 
; 	CLRBIT(LCD_CONTROL_PORT,E);
	cbi 0x18,2
	.dbline 63
; 	CLRBIT(LCD_CONTROL_PORT,RW);
	cbi 0x18,1
	.dbline 64
; 	CLRBIT(LCD_CONTROL_PORT,RS);
	cbi 0x18,0
	.dbline 65
; 	CLRBIT(LCD_CONTROL_PORT,PSB);
	cbi 0x18,3
	.dbline 70
; 	
; 	//LCD_DATA_PORT|=0x0;	
; 	//delay_nms(1500);
; 		
; 	LCD_DATA_PORT|=0xFF;
	in R24,0x1b
	ori R24,255
	out 0x1b,R24
	.dbline 73
; 		
; 	//SETBIT(LCD_CONTROL_PORT,_RES);
; 	CLRBIT(LCD_CONTROL_PORT,_RES);
	cbi 0x18,4
	.dbline 74
; 	delay_nms(1);
	ldi R16,1
	ldi R17,0
	xcall _delay_nms
	.dbline 75
; 	SETBIT(LCD_CONTROL_PORT,_RES);
	sbi 0x18,4
	.dbline 77
; 
; 	SdCmd(0x20);    // 8bit I/F, basic command, graphic off
	ldi R16,32
	xcall _SdCmd
	.dbline 78
; 	SdCmd(0x20);    // 8bit I/F, basic command, graphic off
	ldi R16,32
	xcall _SdCmd
	.dbline 79
; 	SdCmd(0x0C);    // display on
	ldi R16,12
	xcall _SdCmd
	.dbline 80
; 	SdCmd(0x06);    // cursor right shift
	ldi R16,6
	xcall _SdCmd
	.dbline 81
; 	SdCmd(0x01);    // cursor right shift
	ldi R16,1
	xcall _SdCmd
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e CheckState _CheckState fV
;            dat -> <dead>
	.even
_CheckState::
	.dbline -1
	.dbline 89
; 
; }
; 
; /*-----------------------------------------------------
;   状态检查函数,判断是否处于忙状态
; -------------------------------------------------------*/
; void  CheckState()
; {
	.dbline 91
;  	unsigned char dat;
;  	CLRBIT(LCD_CONTROL_PORT,RS);  //RS=0
	cbi 0x18,0
	.dbline 92
;  	SETBIT(LCD_CONTROL_PORT,RW);  //RW=1
	sbi 0x18,1
	.dbline 93
;  	LCD_DATA_DDR=0x00;			// portA as input
	clr R2
	out 0x1a,R2
L3:
	.dbline 95
;  	do
;  	{
	.dbline 96
;  	   	SETBIT(LCD_CONTROL_PORT,E);
	sbi 0x18,2
	.dbline 97
; 		NOP();
	nop
	.dbline 98
; 		CLRBIT(LCD_CONTROL_PORT,E);
	cbi 0x18,2
	.dbline 99
;     }
L4:
	.dbline 100
;  	while (LCD_DATA_PIN&0x80);
	sbic 0x19,7
	rjmp L3
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbsym l dat 1 c
	.dbend
	.dbfunc e Send _Send fV
;              i -> R20
;       senddata -> R16
	.even
_Send::
	xcall push_gset1
	.dbline -1
	.dbline 104
; }
; 
; void Send(unsigned char senddata)
; {
	.dbline 107
; 	unsigned char i;
; 
; 	for(i=0;i<8;i++)
	clr R20
	xjmp L10
L7:
	.dbline 108
; 	{
	.dbline 109
; 		if((senddata)&0x80)
	sbrs R16,7
	rjmp L11
	.dbline 110
; 		{
	.dbline 112
; 			//D_OUT=1	   ;	
; 			SETBIT(LCD_CONTROL_PORT,RW);	
	sbi 0x18,1
	.dbline 113
; 		}
	xjmp L12
L11:
	.dbline 115
; 		else
; 		{
	.dbline 117
; 			//D_OUT=0;	
; 			CLRBIT(LCD_CONTROL_PORT,RW);		
	cbi 0x18,1
	.dbline 118
; 		}
L12:
	.dbline 121
	sbi 0x18,2
	.dbline 122
	nop
	.dbline 124
	cbi 0x18,2
	.dbline 126
	lsl R16
	.dbline 127
L8:
	.dbline 107
	inc R20
L10:
	.dbline 107
	cpi R20,8
	brlo L7
	.dbline -2
L6:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r senddata 16 c
	.dbend
	.dbfunc e SdCmd _SdCmd fV
;           scmd -> R20
	.even
_SdCmd::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 131
; 		
; 		//SCK=1;
; 		SETBIT(LCD_CONTROL_PORT,E);	
; 		NOP();
; 		//SCK=0;
; 		CLRBIT(LCD_CONTROL_PORT,E);	
; 		
; 		senddata<<=1;
; 	}
; }
; 
; void SdCmd(unsigned char scmd)   //send command
; {
	.dbline 133
; 	//ST7920CS=1;
; 	SETBIT(LCD_CONTROL_PORT,RS);
	sbi 0x18,0
	.dbline 134
; 	Send(0xf8);
	ldi R16,248
	xcall _Send
	.dbline 135
; 	Send(scmd&0xf0);
	mov R16,R20
	andi R16,240
	xcall _Send
	.dbline 136
; 	Send(scmd<<4);	
	mov R16,R20
	andi R16,#0x0F
	swap R16
	xcall _Send
	.dbline 139
; 	
; 	//ST7920CS=0;
; 	SETBIT(LCD_CONTROL_PORT,RS);
	sbi 0x18,0
	.dbline 140
; 	delay_nus(20);
	ldi R16,20
	ldi R17,0
	xcall _delay_nus
	.dbline -2
L13:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r scmd 20 c
	.dbend
	.dbfunc e SdData _SdData fV
;          DData -> R20
	.even
_SdData::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 145
; 	
; }
; 
; void SdData(unsigned char DData) 
; {
	.dbline 147
; 	//ST7920CS=1;
; 	SETBIT(LCD_CONTROL_PORT,RS);
	sbi 0x18,0
	.dbline 148
; 	Send(0xfa);
	ldi R16,250
	xcall _Send
	.dbline 149
; 	Send(DData&0xf0);
	mov R16,R20
	andi R16,240
	xcall _Send
	.dbline 150
; 	Send(DData<<4);	
	mov R16,R20
	andi R16,#0x0F
	swap R16
	xcall _Send
	.dbline 153
; 	
; 	//ST7920CS=0;
; 	SETBIT(LCD_CONTROL_PORT,RS);
	sbi 0x18,0
	.dbline 154
; 	delay_nus(20);
	ldi R16,20
	ldi R17,0
	xcall _delay_nus
	.dbline -2
L14:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r DData 20 c
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	.dbline -1
	.dbline 159
; 	
; }
; 
; void main(void)
; {
	.dbline 161
;  
; 	CLI();                 // disable interrupts
	cli
	.dbline 163
; 
;    	initLCDM();
	xcall _initLCDM
	xjmp L17
L16:
	.dbline 166
	.dbline 167
	ldi R16,32
	xcall _SdCmd
	.dbline 168
	ldi R16,1
	xcall _SdCmd
	.dbline 169
	ldi R16,100
	ldi R17,0
	xcall _delay_nms
	.dbline 171
	ldi R16,<_TextLogo
	ldi R17,>_TextLogo
	xcall _WriteTextScreen2
	.dbline 172
	ldi R16,1500
	ldi R17,5
	xcall _delay_nms
	.dbline 174
	ldi R16,<L19
	ldi R17,>L19
	xcall _WriteTextScreen2
	.dbline 175
	ldi R16,1500
	ldi R17,5
	xcall _delay_nms
	.dbline 178
L17:
	.dbline 165
	xjmp L16
X0:
	.dbline -2
L15:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e DispSetCursor _DispSetCursor fV
;              i -> R20
;      ColumnNum -> R22
;        LineNum -> R10
	.even
_DispSetCursor::
	xcall push_gset3
	mov R22,R18
	mov R10,R16
	.dbline -1
	.dbline 184
; 	
; 	while(1)
; 	{
; 	SdCmd(0x20);          // 8bit I/F, basic command, graphic off
; 	SdCmd(0x01);          // clr text screen
; 	delay_nms(100);
; 	
;     WriteTextScreen2(TextLogo);
;    	delay_nms(1500);
; 
;     WriteTextScreen2("世界你好12345678901234567890");
;    	delay_nms(1500);
; 
; 	
;  	}
; 	
; 
; }
; 
; void DispSetCursor(unsigned char LineNum, unsigned char ColumnNum)
; {
	.dbline 186
; 
;     unsigned char i=0x00;
	clr R20
	.dbline 187
;     switch(LineNum&0x0f)   //确定行号
	mov R24,R10
	clr R25
	andi R24,15
	andi R25,0
	movw R10,R24
	cpi R24,0
	cpc R24,R25
	breq L24
X1:
	movw R24,R10
	cpi R24,1
	ldi R30,0
	cpc R25,R30
	breq L25
	cpi R24,2
	ldi R30,0
	cpc R25,R30
	breq L26
	cpi R24,3
	ldi R30,0
	cpc R25,R30
	breq L27
	xjmp L22
X2:
	.dbline 188
;     {
L24:
	.dbline 190
; 	case 0x00:
; 		i=0x80;
	ldi R20,128
	.dbline 191
; 		break;
	xjmp L22
L25:
	.dbline 193
; 	case 0x01: 
; 		i=0x90; 
	ldi R20,144
	.dbline 194
; 		break;
	xjmp L22
L26:
	.dbline 196
; 	case 0x02: 
; 		i=0x88;
	ldi R20,136
	.dbline 197
; 		break;
	xjmp L22
L27:
	.dbline 199
; 	case 0x03:
; 		i=0x98;
	ldi R20,152
	.dbline 200
; 		break;
	.dbline 202
; 	default : 
; 		break;
L22:
	.dbline 204
;     }
;     i = (ColumnNum&0x0f)|i; //确定列号
	mov R24,R22
	andi R24,15
	or R20,R24
	.dbline 205
;    SdCmd(i);
	mov R16,R20
	xcall _SdCmd
	.dbline -2
L20:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r ColumnNum 22 c
	.dbsym r LineNum 10 c
	.dbend
	.dbfunc e WriteTextScreen2 _WriteTextScreen2 fV
;              i -> R20
;              j -> R10
;           pstr -> R22,R23
	.even
_WriteTextScreen2::
	xcall push_gset3
	movw R22,R16
	.dbline -1
	.dbline 210
; 	
; }
; 
; void WriteTextScreen2(unsigned char *pstr)
; {
	.dbline 214
; unsigned char i;
; unsigned char j;
; 
;    	SdCmd(0x34);        // 8bit I/F, basic command
	ldi R16,52
	xcall _SdCmd
	.dbline 215
;    	SdCmd(0x30);        // 8bit I/F, basic command, graphic off
	ldi R16,48
	xcall _SdCmd
	.dbline 217
; 
; 	 for(i=0;i<36;i++)       //清空屏幕
	clr R20
	xjmp L32
L29:
	.dbline 218
; 	 {
	.dbline 219
; 		 if (i%18==0)         //判断是否换行
	ldi R17,18
	mov R16,R20
	xcall mod8u
	tst R16
	brne L33
	.dbline 220
; 		 {
	.dbline 221
; 			 DispSetCursor(i/18,0);   //如换行, 则光标移动到行首
	clr R18
	ldi R17,18
	mov R16,R20
	xcall div8u
	xcall _DispSetCursor
	.dbline 222
; 		 }
L33:
	.dbline 224
	ldi R16,32
	xcall _SdData
	.dbline 225
L30:
	.dbline 217
	inc R20
L32:
	.dbline 217
	cpi R20,36
	brlo L29
	.dbline 227
; 
; 		 SdData(' '); //
; 	 }
; 		
;      j=0;
	clr R10
	xjmp L36
L35:
	.dbline 230
;      //while (*pstr)
;      while (*pstr && j<36)
;      {
	.dbline 231
; 		 if (j%18==0)         //判断是否换行
	ldi R17,18
	mov R16,R10
	xcall mod8u
	tst R16
	brne L38
	.dbline 232
; 		 {
	.dbline 233
; 			 DispSetCursor(j/18,0);   //如换行, 则光标移动到行首
	clr R18
	ldi R17,18
	mov R16,R10
	xcall div8u
	xcall _DispSetCursor
	.dbline 234
; 		 }
L38:
	.dbline 237
; 		 
; 		 //避免最后一格写半个汉字, 把汉字写到下一行
; 		 if (((j+1)%18==0) && *pstr>127 && *(pstr-1)<128) 
	ldi R17,18
	mov R16,R10
	subi R16,255    ; addi 1
	xcall mod8u
	tst R16
	brne L40
	ldi R24,127
	movw R30,R22
	ldd R2,z+0
	cp R24,R2
	brsh L40
	sbiw R30,1
	ldd R24,z+0
	cpi R24,128
	brsh L40
	.dbline 238
; 		 {
	.dbline 239
; 		 	SdData(' '); //
	ldi R16,32
	xcall _SdData
	.dbline 240
; 			j++;
	inc R10
	.dbline 241
; 		 }
	xjmp L41
L40:
	.dbline 243
; 		else
; 		{	
	.dbline 244
; 		 	SdData(*pstr++);
	movw R30,R22
	ld R16,Z+
	movw R22,R30
	xcall _SdData
	.dbline 245
; 		 	j++;
	inc R10
	.dbline 246
; 		}
L41:
	.dbline 250
L36:
	.dbline 229
	movw R30,R22
	ldd R2,z+0
	tst R2
	breq L42
	mov R24,R10
	cpi R24,36
	brsh X3
	xjmp L35
X3:
L42:
	.dbline -2
L28:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r j 10 c
	.dbsym r pstr 22 pc
	.dbend
	.dbfunc e delay_1us _delay_1us fV
	.even
_delay_1us::
	.dbline -1
	.dbline 259
; 		
;         //SdData(*pstr++);
;         //j++;		
;      }
; 
;  }
; 
; /*-----------------------------------------------------------------------
; 延时函数
; 系统时钟:8M
; -----------------------------------------------------------------------*/
; void delay_1us(void)                 //1us延时函数
;   {
	.dbline 260
;    asm("nop");
	nop
	.dbline -2
L43:
	.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 264
;   }
; 
; void delay_nus(unsigned int n)       //N us延时函数
;   {
	.dbline 265
;    unsigned int i=0;
	clr R20
	clr R21
	.dbline 266
;    for (i=0;i<n;i++)
	xjmp L48
L45:
	.dbline 267
	xcall _delay_1us
L46:
	.dbline 266
	subi R20,255  ; offset = 1
	sbci R21,255
L48:
	.dbline 266
	cp R20,R22
	cpc R21,R23
	brlo L45
	.dbline -2
L44:
	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 271
;    delay_1us();
;   }
;   
; void delay_1ms(void)                 //1ms延时函数
;   {
	.dbline 273
	clr R16
	clr R17
	xjmp L53
L50:
	.dbline 273
L51:
	.dbline 273
	subi R16,255  ; offset = 1
	sbci R17,255
L53:
	.dbline 273
;    unsigned int i;
;    for (i=0;i<1140;i++); 
	cpi R16,116
	ldi R30,4
	cpc R17,R30
	brlo L50
	.dbline -2
L49:
	.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 277
;   }
;   
; void delay_nms(unsigned int n)       //N ms延时函数
;   {
	.dbline 278
;    unsigned int i=0;
	clr R20
	clr R21
	.dbline 279
;    for (i=0;i<n;i++)
	xjmp L58
L55:
	.dbline 280
	xcall _delay_1ms
L56:
	.dbline 279
	subi R20,255  ; offset = 1
	sbci R21,255
L58:
	.dbline 279
	cp R20,R22
	cpc R21,R23
	brlo L55
	.dbline -2
L54:
	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:\_opt\___7920_serial\source\7920.c
L19:
	.blkb 29
	.area idata
	.byte 202,192,189,231,196,227,186,195,49,50,51,52,53,54,55,56
	.byte 57,48,49,50,51,52,53,54,55,56,57,48,0
	.area data(ram, con, rel)
	.dbfile E:\_opt\___7920_serial\source\7920.c

⌨️ 快捷键说明

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