Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 25th July 2007, 02:12 PM   (permalink)
Experienced Member
savnik is on a distinguished road
Default Lcd

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
savnik is offline   Reply With Quote
Old 25th July 2007, 02:39 PM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

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

Mike.
Pommie is offline   Reply With Quote
Old 25th July 2007, 02:47 PM   (permalink)
Experienced Member
savnik is on a distinguished road
Default

Quote:
Originally Posted by Pommie
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
Attached Images
File Type: gif 1.gif (10.7 KB, 19 views)

Last edited by savnik; 25th July 2007 at 02:51 PM.
savnik is offline   Reply With Quote
Old 25th July 2007, 03:22 PM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

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.
Pommie is offline   Reply With Quote
Old 25th July 2007, 03:24 PM   (permalink)
Experienced Member
savnik is on a distinguished road
Default

Quote:
Originally Posted by Pommie
If you want to ground RW then you need to replace the busy test with a delay.

Mike.
yes i want to ground the RW . How delay is need;
savnik is offline   Reply With Quote
Old 25th July 2007, 03:25 PM   (permalink)
Super Moderator
 
Nigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to behold
Default

Quote:
Originally Posted by savnik
yes i want to ground the RW . How delay is need;
Why do you want to ground it?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 25th July 2007, 03:27 PM   (permalink)
Experienced Member
savnik is on a distinguished road
Default

Quote:
Originally Posted by Nigel Goodwin
Why do you want to ground it?.
Because only write to lcd , not read.
savnik is offline   Reply With Quote
Old 25th July 2007, 03:36 PM   (permalink)
Experienced Member
 
ericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to behold
Default

Quote:
Originally Posted by savnik
Because only write to lcd , not read.
You are testing the BUSY bit with a READ!

btfsc LcdStatus, 7 ; test bit 7


Eric
ericgibbs is online now   Reply With Quote
Old 25th July 2007, 03:56 PM   (permalink)
Super Moderator
 
Nigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to behold
Default

Quote:
Originally Posted by savnik
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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 25th July 2007, 03:59 PM   (permalink)
Experienced Member
savnik is on a distinguished road
Default

Quote:
Originally Posted by Nigel Goodwin
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.
Ok i leave it as it , but i want o to swap the E with RW
savnik is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
problem with LCD meera83 Micro Controllers 9 17th July 2007 02:20 PM
Help understanding the Unicorn Kyle-s4h Micro Controllers 2 5th June 2007 06:08 PM
PIC16+Parallel lcd - by twitchy Nigel Goodwin Micro Controllers 16 18th May 2007 10:44 AM
8 bits LCD Problem joe_1 Micro Controllers 3 27th April 2007 01:38 AM
89c4051 4-bit controlled LCD sporadic screwup Pax Writer Micro Controllers 7 26th April 2007 05:58 AM



All times are GMT. The time now is 05:16 PM.


Electronic Circuits  |  Radio Controlled
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.