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

📄 128x64_ks0108graphic_lcd.asm

📁 sourcecode in assembly 128x64 Graphi LCD KS0108 ASM
💻 ASM
📖 第 1 页 / 共 3 页
字号:
                  
      	BMP_IMAG: 		mov	dptr, #BMPDATA1-1
      				clr	Select
         				mov 	r3,  #0b8h		; First page
         	NexPage:		mov	a,  r3		; page counter
         				call	Write_Instr
         				mov	a,  #040h		; First column..
          				call	Write_Instr
         				mov	r4, #0		; column counter
         				mov	r6, #0		; Total column counter
         			
          	PageLup:		inc	dptr
          				mov	a, #00H
          				movc	a, @a+dptr
         				call	Write_Data
         				;call	VarDelay		; So that you can see the filling...
         				call	Sel_CS2
         				inc	r6
         				cjne	r6,  #128,  PageLup
         				clr	Select
         				inc	r3
         				cjne	r3,  #0c0h, NexPage
         			
           	IMGOVER:		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 a box that is 2 pixel wide on the periphary of the display area.
             
             Box:			clr	Select
             BoxCs2:		mov	r3,  #0
             			mov	a,  #0b8h
      	      		call	Write_Instr
      	      		mov	a,  #40h
      	      		call	Write_Instr		;First page first column CS1 (and then CS2)
      	TLineLup:		mov	a,  #03h		;Horizontal line - 2 pixel  wide..
      	      		call	Write_Data  
      	      		inc 	r3
      	      		cjne	r3,  #64,  TLineLup
      	      		jb	Select,  BLine
      	      		setb	Select
      	      		jmp	BoxCs2
      	      		
      	BLine:		clr	Select
            BlnCs2:		mov	r3,  #0
             			mov	a,  #0bfh		; Last page
      	      		call	Write_Instr
      	      		mov	a,  #40h
      	      		call	Write_Instr		;Last page first column CS1 (and then CS2)
      	BLineLup:		mov	a,  #0C0h		;Horizontal line - 2 pixel  wide..
      	      		call	Write_Data  
      	      		inc 	r3
      	      		cjne	r3,  #64,  BLineLup
      	      		jb	Select,  RVerLine
      	      		setb	Select
      	      		jmp	BlnCs2	
     	
     		RVerLine:   	setb	Select		 ;Already set. Just for comparing with LVerLine
     					mov	r3,  #0b8h
     		VerLup:		mov	a,  r3
     					call	Write_Instr
     					mov	a,  #7eh		;63rd column CS2
     					call	Write_Instr
     					mov	a,  #0ffh
     					call	Write_Data
     					mov	a,  #0ffh
     					call	Write_Data
     					inc	r3
     					cjne	r3,  #0c0h,  VerLup
     			
     		LVerLine:		clr	Select
     					mov	r3,  #0b8h
     		VerLup1:		mov	a,  r3
     					call	Write_Instr
     					mov	a,  #40h		;1st Column CS1. Always write column address AFTER page address
     					call	Write_Instr
     					mov	a,  #0ffh
     					call	Write_Data
     					mov	a,  #0ffh
     					call	Write_Data
     					inc	r3
     					cjne	r3,  #0c0h,  VerLup1
     					ret
    	;==================================================================
    
    	; TIP : For demo, a fixed   X and Y address is used. To make it universal you can pass these references 
    	; via X_Addr and Y_Addr and InvertDis ram locations. And modify this code  to handle them.
    	
    			    			
    		User_Strng:		clr	Select		; Display the user defined string...
    					mov	a,   #0b8h		; Start X  address
    					call	Write_Instr
    					mov	r4, #70h		; Start Y address
    					mov	a,  r4
    					call	Write_Instr
    					mov	r5, #0
    					mov	r3, #0
    			    			
    		NextCh:		mov 	dptr,  #UserMssg
    					mov	a,  r3
    					movc	a, @a+dptr		;Get the ASCII of Character
    			
    					cjne	a, #30h, ChkSpace	;check for "0" and if yes return
    					jmp	EofString				
    		ChkSpace:		cjne	a, #20h, Proceed	;check for Space
    					jmp	Space
    	
    		Proceed:		clr	c
    					subb	a, #33		;adjust the begining of the table
   					mov	dptr,  #Font_Table
                  		mov  	b, #05h		;Offset for 5 columns for each character
                  		mul  	ab
                  		clr 	c
                  		add 	a,dpl			;LSB in acc
                  		mov 	dpl,a
                  		mov 	a,b			;MSB in B
                  		addc 	a, dph
                  		mov  	dph, a		;DPTR now contains pointer to first data byte
    		NxtByte:		mov	a,  #0
    					movc	a, @a+dptr
    					;cpl	a			; for inverted display
    					call	Write_Data
    					call	Swt_Cs2
    					inc	dptr
    					inc	r5
    					cjne	r5, #5,  NxtByte
    					mov	a,  #0
    					;cpl	a			; for inverted display
    					call 	Write_Data		; 1 Pixel gap between characters
    					call	Swt_Cs2
    					mov	r5,  #0
    					jmp	NoSpace
    		Space:		mov	a,  #0
    					;cpl	a			; for inverted display
    					call	Write_Data		; For 2 pixel space
    					call	Swt_Cs2
    					mov    	a, #0
    					;cpl	a			; for inverted display
    					call	Write_Data 
    					call	Swt_Cs2
    			
      	NoSpace:		inc	r3
      				jmp	NextCh
        	EofString:		ret
    			
    		Swt_Cs2:		inc	r4			; To automatically switch to CS2
    					cjne	r4,  #80h, NoSwt	; Last column = 80h
    					setb	Select
    					nop
    					nop
    					mov	a,   #0b8h		; without this it writes to last page of CS2
    					call	Write_Instr
    					mov	a,   #40h
    					call	Write_Instr	
    		NoSwt:		ret
    			
    		UserMssg:		db	'THANKS ! 0 '  	; Message to display .Must terminate with a "0"
    	
   	;===============================================================================
    	
	
		Init_Lcd:         mov 	a, #3eh            ; Display off 
                  		call 	Write_Instr                
                  		mov 	r7, 0ffh
                  		djnz 	r7, $
                  		mov 	a,  #3fh          ; Display on
                  		call 	Write_Instr                
                  		mov 	r7, #0ffh
                  		djnz 	r7,  $
                  		mov 	a, #0c0h               	
                  		call 	Write_Instr               
                  		mov 	a, #40h            ; Y address counter at First column
                  		call 	Write_Instr                
                  		mov 	a,  #0b8h          ; X address counter at Starting point
                  		call 	Write_Instr                
                  		ret

		Write_Char:    	clr  c
                  		push 	dph
                  		push 	dpl
                  		mov  	r2, #00h
                  		mov  	a, r1			;Get the ASCII of Character
                  		mov  	b, #05h		;Offset for 5 columns for each character
                  		mul  	ab
                  		clr 	c
                  		add 	a,dpl			;LSB in acc
                  		mov 	dpl,a
                  		mov 	a,b			;MSB in B
                  		addc 	a, dph
                  		mov  	dph, a		;DPTR now contains pointer to first data byte
       	Send_Next:      	mov 	a, #00h
                  		add 	a, r2
                  		movc 	a, @a+dptr
                  		call 	Write_Data
                  		inc  	r2
                  		cjne 	r2, #05h, Send_Next ;Loop till all 5 data bytes are sent for the character
                  		pop  	dpl
                  		pop  	dph
                  		ret


	
		Write_Instr:      jb 	Select, Cs_2
                  		clr	p1.4
                  		setb 	p1.3               ;Chip select cs1 enabled 
                 			jmp 	WInstr
         	Cs_2:    		clr	p1.3
         	    			setb 	p1.4               ;Chip select cs2 enabled 
           	WInstr:		nop
             			mov	r0,  #10
          				djnz	r0, $
           				clr 	p1.1               ;Write mode selected
                  		clr 	p1.0               ;Instruction mode selected
                 			mov 	p0, acc            ;Place Instruction on bus
                  		setb 	p1.2               ;Enable High
                  		nop
                  		clr 	p1.2               ;Enable Low
                  		nop
                  		clr 	p1.3               ;put cs1 in non select mode
                  		clr 	p1.4               ;put cs2 in non select mode
                  		ret



		Write_Data:   	jb 	Select,Cs_2a
					clr	p1.4
                  		setb 	p1.3               ;Chip select cs1 enabled 
                  		jmp 	WData
        	Cs_2a:    		clr	p1.3
        				setb 	p1.4               ;Chip select cs2 enabled 
        			
          	WData:		nop
          				mov	r0,  #10

⌨️ 快捷键说明

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