![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Experienced 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
__________________
http://users.otenet.gr/~nsavvas/index.html |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Some of the code is writing to portb, some to portc and some portd. How have you got your LCD connected?
Mike. |
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
but i want to swap the E with RW or to ground the RW
__________________
http://users.otenet.gr/~nsavvas/index.html Last edited by savnik; 25th July 2007 at 02:51 PM. |
|
|
|
|
|
|
(permalink) |
|
Experienced Member
|
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. |
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
__________________
http://users.otenet.gr/~nsavvas/index.html |
|
|
|
|
|
|
(permalink) | |
|
Super Moderator
|
Quote:
|
|
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
__________________
http://users.otenet.gr/~nsavvas/index.html |
|
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
btfsc LcdStatus, 7 ; test bit 7 Eric |
|
|
|
|
|
|
(permalink) | |
|
Super Moderator
|
Quote:
|
|
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
__________________
http://users.otenet.gr/~nsavvas/index.html |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| 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 |