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

📄 lcd_disp.a51

📁 网络单片机 让嵌入式系统上网,基于keil C. 文件名:microweb-keil-0.1
💻 A51
字号:
;*************************************************************************; An 8051 Based Web Server; lcd_disp: code to control the LCD on an EMAC board; By Mason Kidd 10/25/01; Modified 3/7/02 so that it can be called from C;*************************************************************************$NOMOD51		; omit assembler micro definitions$include(reg515.inc)	; define 515 microname		lcd_disppublic		_lcdout, lcdinit, lcd_crlfsc_lcd_disp	SEGMENT	CODE       	RSEG	sc_lcd_disp      		USING	0;************************************************************************;; 20X2 character LCD drivers for the MICROPAC 535;; COPYRIGHT 1993-1995 EMAC INC.;; ESCflag is a bit field that must be declared.; DLAYA is a 5ms delay routine with no registers affected.; LCDINIT should be executed before any other LCD subroutines.;;        ; LCDOUT: Output the char in ACC to LCD        ; Following are some codes that are supported by this driver (20*2 displays);;        0ah      move cursor to other line (i.e. from 1-2 or 2-1);        0dh      move cursor to beginning of line ;        1ah      clear display and move cursor to home;        1bh      the next byte received after this will be written to register;                 0 of the lcd display;                  ; definitionsescflag	equ	psw.5		; LCD equatelcdcmd   	equ	28h      	; value for P2 to select lcd command portinitdata:         db       38h,08,01,06,0eh,80h,0;--------------------------------------------------------------; Dempsey notes; (1) R1,R2 are corrupted by this subroutine; (2) Previously there were several returns- now only one: "LCDEXIT"; (3) From calling program: Use a delay of 5ms (minimum);     between command codes LF (0A) and CR (0D);---------------------------------------------------------------  ; character passed in R7_LCDOUT:  	mov	A, R7	MOV	R2, A             ; SAVE CHAR IN R2	MOV	P2, #LCDCMD       ; POINT TO COMMAND PORT	jnb	ESCflag,lcdnt5    ; skip if no ESC	clr	escflag	sjmp	reg0out           ; write directly to lcd reg 0lcdnt5:	ANL	A,#11100000B      ; SEE IF ANY OF UPPER 3 BITS SET	JNZ	REG1OUT           ; IF YES, PRINT IT	MOV	A,R2              ; RESTORE CHAR	ANL	A,#11111000B      ; SEE IF CHAR IS < 7	JZ	REG1OUT           ; IF LESS, A=0 SO PRINT USER DEF CHAR 0-7         	MOV	A,R2              ; SEE IF CONTROL CHAR	CJNE	A,#0DH,LCNT1      ; IF NOT CR, SKIP	MOVX	A,@R1             ; READ COMMAND PORT TO FIND CURSOR POS	SETB	ACC.7             ; SET BIT 7 FOR DDRAM ADDR	ANL	A,#11100000B      ; MOVE TO LEFT (ONLY VALID ON 2 LINE DISPL)	MOV	R2,A	SJMP	REG0OUT         LCNT1:	CJNE	A,#0AH,LCNT2      ; IF NOT LF, SKIP	MOVX	A,@R1             ; READ COMMAND PORT TO FIND CURSOR POS	CPL	ACC.6             ; SWITCH LINE (ONLY VALID ON 2 LINE DISPL)	SETB	ACC.7             ; SET BIT 7 FOR DDRAM ADDR	MOV	R2,A	SJMP	REG0OUT         LCNT2: 	CJNE	A,#1BH,LCNT3      ; IF NOT ESC, SKIP	setb	ESCflag           ; indicate ESC received	JMP LCDEXIT         LCNT3: 	CJNE	A,#1AH,LCNT4	  ; EXIT IF NOT CLEAR SCREEN	MOV	R2,#1             ; CLEAR COMMAND	SJMP	REG0OUT				  ; OUTPUT THE CHAR IN R2 TO REG 1REG1OUT:	MOVX	A,@R1             ; READ LCD COMMAND PORT	JB 	ACC.7,REG1OUT     ; LOOP IF BUSY FLAG SET	INC	P2                ; POINT TO LCD DATA PORT         	MOV	A,R2              ; RESTORE CHAR	MOVX	@R1,A             ; OUTPUT ITLCNT4:	JMP LCDEXIT                 			  ; OUTPUT THE CHAR IN R2 TO REG 0REG0OUT:	MOVX	A,@R1             ; READ LCD COMMAND PORT	JB  	ACC.7,REG0OUT     ; LOOP IF BUSY FLAG SET	MOV	A,R2              ; RESTORE CHAR	MOVX	@R1,A             ; OUTPUT IT     	JMP LCDEXIT        ; ; LCDINIT: Init the LCD;         LCDINIT:         	clr 	ESCflag           ; indicate no esc found	MOV  	P2,#LCDCMD        ; POINT TO COMMAND PORT	LCALL  	DLAYA             ; 5MS DELAY	LCALL  	DLAYA             ; 5MS DELAY	LCALL  	DLAYA             ; 5MS DELAY	LCALL 	DLAYA             ; 5MS DELAY	MOV    	A,#30H	MOVX  	@R1,A             ; OUT TO LCD COMMAND PORT         	LCALL 	DLAYA             ; 5MS DELAY         	MOVX  	@R1,A             ; OUT TO LCD COMMAND PORT                  	LCALL 	DLAYA             ; 5MS DELAY         	MOVX  	@R1,A             ; OUT TO LCD COMMAND PORT                           	MOV  	DPTR,#INITDATA    ; POINT TO INIT DATA        		          ; the last command should take no more than 40 uS.   	mov	b,#80             ; for timeout of 80*3 * (12/clock)lcdnit2:	movx 	a,@r1             ; read lcd command port     	jnb   	acc.7,lcdnit1     ; exit if not busy     	djnz 	b,lcdnit2         ; loop till timeout     	sjmp 	lcdexit	; exit if timeoutLCDNIT1:	MOVX 	A,@R1             ; READ LCD COMMAND PORT      	JB   	ACC.7,LCDNIT1     ; LOOP IF BUSY FLAG SET				           	CLR  	A     	MOVC  	A,@A+DPTR         ; GET BYTE FROM INIT TABLE     	JZ    	LCDEXIT           ; EXIT IF 0    	INC   	DPTR              ; POINT TO NEXT BYTE             	MOVX  	@R1,A             ; OUTPUT BYTE    	SJMP   	LCDNIT1           ; LOOP         LCDEXIT:	RET   ; subroutine to output a CR and LFlcd_crlf:	push	ACC	mov	R7, #0ah	call	_lcdout	call	dlaya	mov	R7, #0dh	call	_lcdout	pop	ACC	ret;; MISCELLANEOUS DELAYS;DLAYA:		PUSH 	ACC      	MOV    	A,#100      	AJMP  	DLAYA2DLAYB: 		PUSH   	ACC      	MOV   	A,#128       AJMP  	DLAYA2DLAYC: 	PUSH 	ACC      	MOV   	A,#255      	AJMP  	DLAYA2dlayd: 	push 	acc      	mov 	a,#8DLAYA2:     	PUSH 	ACC     	MOV   	A,#0FFHDLAYA1:       	MOV   	A,#0FFH     	DJNZ  	ACC,$             ; LEVEL 3 LOOP                 	POP   	ACC     	DJNZ  	ACC,DLAYA2        ; LEVEL 1 LOOP              	POP   	ACC	RET		END

⌨️ 快捷键说明

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