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

📄 128x64_ks0108graphic_lcd.asm

📁 sourcecode in assembly 128x64 Graphi LCD KS0108 ASM
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;**********************************************************TST_GLCD***********************************************************
	
	; Author : S.R Raghunathan / 04 August 2003.
	; Assembler : Pinnacle 52
	
	;TST_GLCD is for testing out the functions of a 128 x 64 Graphic LCD module with Driver KS0108B from 
	; Samsung. The complete module has  two such drivers - one for the left half of the display and the other
	;  for the right half - and the total columns add up to 128. The data sheet for  the driver is silent on  the 
	;  memory map of the pixel - hence I have (tried to !) describe it below. 
	
	; A short description on the memory map of the pixels : ( A sketch would have been better - but then it 
	; cannot opened in a notepad !! So lets manage with a description)
	
	; 	The following apply  to the left half of the display and is the same for the right half. (To select the right half
	;   	the CS1 bit is set and to select the left half the CS2 bit is set.)
	
	;  	Each driver KS0108B controls a 64 column by 64 row pixel array. The 64 pixel row arrays are further 
	;  	grouped into 8 pages  - and each page is 8 bits or 1 Byte tall. Thus when you write a Byte, based on the 
	;  	Page address and Column address, this "8 bit tall" area is filled up . The LSB bit of the data byte 
	;  	is at the top and the MSB bit is at the bottom.
	
	; 	The first top most Page address is 0x0b8 and the lowermost page is 0x0c0. Likewise the left most column 
	; 	has an address of 0x040 and the rightmost column  is at 0x080.
	
	; 	Whenever you write or read data into the display RAM, the column address alone is incremented 
	;  	automatically by one. And when the increment happens after the last column (0x080), your code should
	;	should change the Column address to proceed as per need - else it rolls over and overwrites on the first 
	;	column in the current page ! 
	
	; 	For rest of the read / write instructions please refer to the data sheet of KS0108B
	; 	In the coding  X_Address refers to the page and Y_Address refers to the column and depending on whether
	;  	CS1 or CS2 is set the write will happen either  in the left or right column respectively. 
	
	; 	I have not used the  write instructions with  the busy bit checking. I found that this was unreliable in 
	;	many occasions - maybe my code had a bug - so just introduced a 10micro delay before each write. There has 
	; 	been no problems on account of this.  	  
	; 
	; Timings suitable for 80c51RD2 running with 6MHz crystal in 6 Clock mode . ( Each Machine cycle = 1 microsecond )
	
	; The module has the following routines for check out :
	; 	FillChar		;To fill screen with same character
     	;	HorLines		;To fill screen with 1 pixel wide Horizontal lines
      ;     Box			; To draw a 2 pixel wide box margin
      ;     User_Strng		; To display a user defined string
 	;	FillDots		; To demonstrate the way Bytes are written in sequence and finally display a
                  		;  THANKS !

	
	; port 0 is used for data lines ( each line has a 10k pull up )
	; port 1 is used for control lines as listed below
	; P1.0 ---RS
	; P1.1 ---R / W 
	; P1.2 ---E 
	; P1.3 ---CS1 
	; P1.4 ---CS2  
	; The #RESET pin of the display is connected to +5V. In case you need to Reset the module without switching off 
	; power then allocate a port pin for this.        
	

 
             Select           BIT   00H        ; to select cs1 of cs2 (0\1)
             SameChar    	BIT   01H        ; to fill display with same character
             InvertDis       	BIT   02H        ; To invert display string	- not used now		
             
             
             ORG  30H
             
             X_Addr	DS	1	; can be used to pass page address in User_Strng routine ( not used now )
             Y_Addr	DS	1	; can be used to pass column address in User_Strng routine ( not used now )
                  

             ORG 0000h
                  
       	Normal:		mov 	sp,  #60h		; Define stack start point
                  		mov 	p0,  #00h         ; clear port0  
                 			mov 	p1,  #00h         ; clear port1 
                  		mov 	r1,   #5
        	Del:  		call 	Dly150mS
                  		djnz 	r1,   Del		; 150mS delay 
                  		call 	Clr_Disp		; Clear the screen
                  		
             ; After this you have calls to the 5 Demo routines - each demo except FillDots, lasts about 3 secs roughly..
                 		
                 		call	BMP_IMAG
                 		jmp   $
                  		setb	SameChar
                  		mov	r1,  #39		;Load the ASCII number of character to be displayed here
                  		call	FillChar		;To fill screen with above character
                  		call	LDelay
                  		call	Clr_Disp
                  		call 	HorLines		;To fill with Horizontal lines
                  		call	LDelay
                  		call	Clr_Disp
                  		call	Box			; To draw a box
                  		call	LDelay
                  		call	Clr_Disp
                  		call	User_Strng		; Display the user defined String
                  		call	LDelay
                  		call	Clr_Disp
                  		call	FillDots		; Fill screen and then display THANKS
                  		jmp  	$
                  		
			
		LDelay:		mov 	r1,  #20		; General purpose delay routine
       	Del1:    		call  Dly150mS
                  		djnz 	r1,  Del1		; 150 x 20 mS delay = 3 Secs 
                  		ret
                  		
            VarDelay:		mov  	r7,  #20h         ; General purpose delay routine
         	DV:      		mov 	r0,   #0ffh
                  		djnz 	r0,   $
                  		djnz	r0,   $
                  		djnz 	r7,   DV		; Delay = r7 value x 1536 micros
                  		ret

		Clr_Disp:  		clr 	Select            ; for selection of cs1
                  		call  Init_Lcd          ; Initialise cs1 
                  		call 	Page_Sel          ; clears all pages of cs1
                  		setb 	Select            ; for selection of cs2
                  		call 	Init_Lcd          ; Initialise cs2 
                  		call 	Page_Sel          ; clears all pages of cs2
                  		clr 	Select
                  		ret


       	Page_Sel:  		mov 	r5, #0b8h         ; X address counter at First Page
        	pag_sel1:  		mov 	a,   r5
                  		call 	Write_Instr                  
                  		mov 	a,  #40h          ; Y address counter at First Column
                  		call 	Write_Instr                  
                  		mov 	a,  #00h          ; To be cleared
                  		mov 	r1, #64
          	next:   		call 	Write_Data         
                  		dec 	r1
                  		cjne 	r1, #00,next	; Clear all columns in one page
                  		inc 	r5
                  		cjne 	r5,#0c0h, pag_sel1	; Loop for clearing all pages
                  		ret
	;=========================================================================
                  		
	; Routine to fill the display with a particular character

          	FillChar:   	mov 	r5,  #0b8h         ; X address counter at First Page
         	LupFill:		clr 	Select             ; for selection of cs1
                  		call 	Write_XY
                  		call 	CharLup		 ; fill left half / right half  with same character
                  		setb 	Select             ; for selection of cs2
                   		call 	Write_XY
                 			inc 	r5			 ; for all 8 pages
                			cjne 	r5, #0c0h, LupFill
                  		ret
                  		
            Write_XY:   	mov 	a, #40h            ; Y address counter at First Column
                  		call 	Write_Instr
                  		mov 	a,  r5             ; X address counter at 00h
                  		call 	Write_Instr                
                  		call 	CharLup
                  		ret
                  		
            CharLup:    	mov 	r3,  #00h               	
    	      LupAgn:           mov 	a,  #00h
                  		call 	Write_Data
                  		mov 	dptr, #Font_Table
                  		call 	Write_Char
                  		mov 	a, #00h
                  		call 	Write_Data
                  		mov 	a, #00h
                  		call 	Write_Data
                  		jb 	SameChar, SameR1
                  		call 	Dly150mS
                  		inc 	r1			;Load next character for display
     		SameR1:  		inc 	r3
                  		cjne 	r1, #5fh,  NxtChar  
                  		mov 	r1, #00h
          	NxtChar:		cjne 	r3, #8, LupAgn     
                  		ret      		
           ;===========================================================================
                  		
         	FillDots:		clr	Select
         				mov 	r3,  #0b8h		; First page
         	NextPage:		mov	a,  r3		; page counter
         				call	Write_Instr
         				mov	a,  #040h		; First column..
          				call	Write_Instr
         				mov	r4, #0		; CS1 column counter
         				mov	r6, #0		; Total coulmn counter
         			
          	PagLup:		call	VarDelay		; So that you can see the filling...
         				mov	a,  #0ffh
         				call	Write_Data
         				call	Sel_Cs2
         				inc	r6
         				cjne	r6,  #128,  PagLup
         				clr	Select
         				inc	r3
         				cjne	r3,  #0c0h, NextPage
         			
         				call	Clr_Disp		; Now clear the screen
         				call	Box			; Draw the box margin...
         				call	User_Strng		; display THANKS! in the middle before returning
       	Over:			ret
         			
         	Sel_Cs2:		inc	r4			; To automatically switch to CS2
    					cjne	r4,  #40h, NoCs2	
    					setb	Select		; change to right half...
    					mov	a,   r3		; without this it writes to last page of CS2
    					call	Write_Instr
    					mov	a,   #040h
    					call	Write_Instr	
    		NoCs2:		ret	
           
		;===========================================================================
         
           ;Routine to draw horzontal lines in full screen
                  
      	HorLines: 		mov  	r5,  #0b8h		; Page counter
      				mov  	r3,  #0		; Column counter
      				clr   Select		; Left half display selected
      	NxtPat:     	nop
      	Sect2: 		mov  	a,  #40h
      	      		call  Write_Instr		; Y start address
      	      		mov   a,  r5
      	      		call  Write_Instr		; X start address
          	PLoop:       	mov  	a,  #55h		; Horizontal hatching whole screen
      	      		call  Write_Data
      	     	     		inc  	r3
                  		cjne 	r3, #64, PLoop  
                  		mov  	r3,  #0		; Init column counter for next page
     	      			inc  	r5
     	      			cjne  r5,  #0c0h, NxtPat	; One page over. Do next
     	      			jnb	Select, SetCs2
     	      			jb	Select,  Exit		; Second half also over - exit
     		SetCs2:		setb	Select
     	      			mov	r5,  #0b8h
     	      			mov	r3,  #0
     	      			jmp  	Sect2
             Exit:    		ret
             
             
             ;========================================================================
             
             
             ;Routine to draw converted BMP images

⌨️ 快捷键说明

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