Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Lcd

Status
Not open for further replies.

savnik

Member
I swap the :

LcdE equ 0 ; enable Lcd
LcdRw equ 3 ; read Lcd

with this

LcdE equ 3 ; read Lcd
LcdRw equ 0 ; enable Lcd

but the below code isn't work
Before swap the code work

Code:
;**************************************************************	
;*	PORTB:	0 LCD Display E
;*		1 		
;*		2 LCD Display RS
;*		3 LCD Display R/W	
;*		4-7 LCD Display D4 .. D7 	

PORTC	equ	PORTB		; LCD-Control-Port
PORTD	equ	PORTB		; LCD-Daten-Port
LcdE	equ	0		; enable Lcd
LcdRw	equ	3		; read Lcd
LcdRs	equ	2		; Data Lcd (not control)	

;********************************************************
; The program begins with the initialization

Init	bsf     STATUS, RP0	; Bank 1 
	movlw	B'00000000'	; PortB all outputs 
	movwf	TRISB
	bcf     STATUS, RP0	; Bank 0

	call	InitLCD		; Display initialization

;*****************************************************************	
;around loops * 1 ms
;10MHz -> 2,5MHz -> 2500T

WAIT
top      movlw   .249           ; timing adjustment variable (1ms)  10MHz 249*10=2490T
         movwf   loops2
top2     nop                    ; sit and wait (Schleifenlδnge 10T)
         nop
         nop
         nop
         nop
         nop
	 nop			
         decfsz  loops2, F      ; internal loops complete?
         goto    top2           ; no, go again
                                ;
         decfsz  loops, F       ; more outer loops complete?
         goto    top            ; no, go again
         retlw   0              ; yes, return from subWAIT

;**************************************************************
; LCD-Routinen
;	
; initialization the LCD-Displays
InitLCD
	movlw	D'255'		; 250 ms Break after switching on
	movwf	loops	
	call	WAIT		

	movlw	B'00110000'	; 1
	movwf	PORTB
	bsf	PORTB, LcdE
	nop	
	bcf	PORTB, LcdE
	
	movlw	D'50'		; 50 ms Pause
	movwf	loops
	call	WAIT
	
	movlw	B'00110000'	; 2
	call	Control8Bit
	movlw	B'00110000'	; 3
	call 	Control8Bit
	movlw	B'00100000'	; 4
	call 	Control8Bit

	movlw	B'00000001'	; lφschen and cusor home
	call	OutLcdControl	
	movlw	B'00101000'	; 5 function set, 4-bit  2-lined,  5x7
	call	OutLcdControl	
	movlw	B'00001000'	; 6 display off
	call	OutLcdControl
	movlw	B'00000110'	; 7 entry mode, increment, disable display-shift
	call	OutLcdControl
	movlw	B'00000011'	; 8 cursor home, cursor home
	call	OutLcdControl
	movlw	B'00001100'	; 9 display on, cursor off, cursor flash off
	call	OutLcdControl
	return

; a control byte 8-bit upper-carry
Control8Bit
	movwf	PORTB
	bsf	PORTB, LcdE
	nop
	bcf	PORTB, LcdE
	movlw	D'10'
	movwf	loops
	call 	WAIT
	return

; for it wait, there? the display for the data acceptance is ready
LcdBusy
        bsf     STATUS, RP0	; make Port B4..7 input
	movlw	B'11110000'
	iorwf   TRISB, f 
        bcf     STATUS, RP0
BusyLoop		
	bcf	PORTC, LcdRs
	bsf	PORTC, LcdRw	; Lesen
	bsf	PORTC, LcdE
	nop
	movf	PORTD, w
	movwf	LcdStatus
	bcf	PORTC, LcdE
	nop
	bsf	PORTC, LcdE	; Enable
	nop
	bcf	PORTC, LcdE
	btfsc	LcdStatus, 7	; test bit 7
	goto	BusyLoop
	bcf	PORTC, LcdRw
        bsf     STATUS, RP0	; make Port B4..7 output
	movlw	B'00001111'
	andwf   TRISB, f    
        bcf     STATUS, RP0
	return	

; a byte with tax data from LCD data to the display upper-carry
OutLcdControl
	movwf	LcdDaten
	call	LcdBusy
	movf	LcdDaten, w
	andlw	H'F0'
	movwf	PORTD		; Hi-teil data write
	bsf	PORTC, LcdE
	nop
	bcf	PORTC, LcdE	; Disable LcdBus
	swapf	LcdDaten, w
	andlw	H'F0'
	movwf	PORTD		; Lo-teil data write
	bsf	PORTC, LcdE
	nop
	bcf	PORTC, LcdE	; Disable LcdBus
	return

; a data byte of LCD upper-carry data to the display
OutLcdDaten
	movwf	LcdDaten
	call	LcdBusy
	movf	LcdDaten, w
	andlw	H'F0'
	movwf	PORTD		; Hi-teil data write
	bsf	PORTC, LcdRs	; Daten
	bsf	PORTC, LcdE	; Enable LcdBus
	nop
	bcf	PORTC, LcdE	; Disable LcdBus	
	swapf	LcdDaten, w
	andlw	H'F0'
	movwf	PORTD		; Lo-teil data write
	bsf	PORTC, LcdRs	; Daten
	bsf	PORTC, LcdE
	nop
	bcf	PORTC, LcdE	; Disable LcdBus	
	bcf	PORTC, LcdRs	;
	return
 
Some of the code is writing to portb, some to portc and some portd. How have you got your LCD connected?

Mike.
 
Pommie said:
Some of the code is writing to portb, some to portc and some portd. How have you got your LCD connected?

Mike.
like this and works
but i want to swap the E with RW or to ground the RW
 

Attachments

  • 1.gif
    1.gif
    10.7 KB · Views: 159
Last edited:
I see, you have equated portc and portd as portb - how confusing.

I can't see why it shouldn't work. Maybe you should go through the code and replace all port accesses with portb - you might then be able to spot the error.

If you want to ground RW then you need to replace the busy test with a delay.

Mike.
 
savnik said:
Because only write to lcd , not read.

You are testing the BUSY bit with a READ!

btfsc LcdStatus, 7 ; test bit 7


Eric
 
savnik said:
Because only write to lcd , not read.

Leave it as it is, it makes for the fastest possible updating speed of the LCD, otherwise you have to introduce fixed delays, which waste time. The read is to check the busy flag, so it never waits longer than it needs to.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top