+ Reply to Thread
Results 1 to 7 of 7

Thread: lcd using pic18f452

  1. #1
    einton Newbie
    Join Date
    Jan 2009
    Location
    pakistan
    Posts
    45

    lcd using pic18f452

    Hi everyone

    i have started pic hardware two weeks ago , before it i gone through much of it programming in assembly , since three days i m working on interfacing 14 pin lcd with ribbon connection , i m using sipmle program which is downloaded well into ic and progrm is burnt well ,with proper setting of configuration bits , when i interface the lcd it just giving some bullets which shows lcd is fine i m sending u my code and hope 4 ur reply since i m finding no way at there. thanx



    LIST p=18F452 , F=INHX32, MM=OFF, N=0, ST=OFF , R=HEX
    #Include P18F452.INC
    CONFIG OSC=HS , OSCS=OFF
    CONFIG WDT=OFF
    CONFIG BORV=45, PWRT=ON, BOR=ON
    CONFIG DEBUG=OFF, LVP=OFF, STVR=OFF
    ORG 00h
    LCD_DATA EQU PORTB
    LCD_CTRL EQU PORTD
    R2 EQU 0*2
    R3 EQU 0*3
    MYREG EQU 0*4
    MTREG EQU 0*5
    RS EQU RD0
    RW EQU RD1
    EN EQU RD2
    CLRF TRISD
    CLRF TRISB
    BCF LCD_CTRL,EN
    CALL LDELAY
    MOVLW 0*38
    CALL COMNWRT
    CALL DELAY
    MOVLW 0*0E
    CALL COMNWRT
    CALL DELAY
    MOVLW 0*01
    CALL COMNWRT
    CALL DELAY
    MOVLW 0*06
    CALL COMNWRT
    CALL DELAY
    MOVLW 0*84
    CALL COMNWRT
    CALL DELAY
    MOVLW A'P'
    CALL DATAWRT
    CALL DELAY
    MOVLW A'A'
    CALL DATAWRT
    AGA BTG LCD_CTRL,0
    BRA AGA
    COMNWRT
    MOVWF LCD_DATA
    BCF LCD_CTRL,RS
    BCF LCD_CTRL,RW
    BCF LCD_CTRL,EN
    CALL DELAY
    BCF LCD_CTRL,EN
    RETURN
    DATAWRT
    MOVWF LCD_DATA
    BSF LCD_CTRL,RS
    BSF LCD_CTRL,RW
    BSF LCD_CTRL,EN
    CALL SDELAY
    BCF LCD_CTRL,EN
    RETURN
    SDELAY
    MOVLW 0FF
    MOVWF MYREG
    ADAIN NOP
    NOP
    DECF MYREG,F
    BNZ ADAIN
    RETURN
    LDELAY
    MOVLW D'200'
    MOVWF R2
    AJAIN MOVLW D'250'
    MOVWF R3
    HERE NOP
    NOP
    DECF R3,F
    BNZ HERE
    DECF R2,F
    BNZ AJAIN
    RETURN
    DELAY
    MOVLW D'200'
    MOVWF MTREG
    AHAIN
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    DECF MTREG,F
    BNZ AHAIN
    RETURN
    END
    Attached Files


  2. #2
    silvarblade Good silvarblade Good
    Join Date
    Feb 2007
    Location
    The Motor city,USA
    Posts
    266

    What is your oscillator frequency? An LCD requires a delay of about 5 to 10 ms for every command and a little more for data.What i do is use a longer delay and use one delay loop for all.
    I just cant come up with a good one!

  3. #3
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,696

    You have a couple of errors in your data and command write routines,

    Code:
    COMNWRT			 
    		movwf	LCD_DATA 
    		bcf	LCD_CTRL,RS
    		bcf	LCD_CTRL,RW
    		bsf	LCD_CTRL,EN	;was bcf
    		call	DELAY
    		bcf	LCD_CTRL,EN
    		return
    DATAWRT
    		movwf	LCD_DATA
    		bsf	LCD_CTRL,RS
    		bcf	LCD_CTRL,RW	;was bsf
    		bsf	LCD_CTRL,EN
    		call	SDELAY
    		bcf	LCD_CTRL,EN
    		return
    
    Mike.

  4. #4
    einton Newbie
    Join Date
    Jan 2009
    Location
    pakistan
    Posts
    45

    lcd using pic18f452

    thanx pommie
    I did what u pointed , but still the things are not working at all , interestingly i m also gettting no any display when i m trying to simulate it on proteas , im using 10 Mhz crystal, i have also used it using single delay of 25 msec but it is also not working . i got blank this time , i think i have used correct config setting .
    Last edited by einton; 7th July 2009 at 03:22 PM.

  5. #5
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,696

    You should try and find some working code that you can test your hardware with. If you post a schematic then people may be able to provide working code.

    Mike.

  6. #6
    Chippie Excellent Chippie Excellent Chippie Excellent Chippie Excellent Chippie Excellent
    Join Date
    Mar 2003
    Location
    Good 'ole England
    Posts
    939

    It may be the contrast pin is not at the correct voltage, hence the blank screen...

    As suggested load some working code to test your hardware..
    Eccentric millionaire financed by 'er indoors

  7. #7
    Wond3rboy Okay
    Join Date
    Jun 2008
    Location
    Hyderabad,Pakistan
    Posts
    435
    Blog Entries
    2

    Hi, here is the code, the problem is that the delay is very small due to you using HS mode of the 18F452. Another problem is that you used PORTx for output when you should be using LATx registers.Here is the code and the attached simulation in Proteus.

    Code:
    LIST p=18F452;This ones for a 10MHz crystal.When you start        ;proteusD.C on the device and change the crystal to 10Mhz.
    #Include P18F452.INC
    CONFIG OSC=HS , OSCS=OFF
    CONFIG WDT=OFF, LVP=OFF
    ORG 00h
    MOVLW 07
    MOVWF T0CON
    LCD_DATA EQU LATB
    LCD_CTRL EQU LATD
    RS EQU RD0
    RW EQU RD1
    EN EQU RD2
    CLRF TRISD
    CLRF TRISB
    BCF LCD_CTRL,EN 
    CALL DELAY 
    MOVLW 0X38
    CALL COMNWRT
    CALL DELAY 
    MOVLW 0X0E
    CALL COMNWRT
    CALL DELAY 
    MOVLW 0X01
    CALL COMNWRT
    CALL DELAY 
    MOVLW 0X06
    CALL COMNWRT
    CALL DELAY 
    MOVLW 0X84
    CALL COMNWRT
    CALL DELAY 
    MOVLW A'P'
    CALL DATAWRT
    CALL DELAY 
    MOVLW A'A'
    CALL DATAWRT
    AGA BTG LCD_CTRL,3
    BRA AGA
    
    
    COMNWRT			 
    		movwf	LCD_DATA 
    		bcf	LCD_CTRL,RS
    		bcf	LCD_CTRL,RW
    		bsf	LCD_CTRL,EN	;was bcf
    		call	DELAY
    		bcf	LCD_CTRL,EN
    		return
    DATAWRT
    		movwf	LCD_DATA
    		bsf	LCD_CTRL,RS
    		bcf	LCD_CTRL,RW	;was bsf
    		bsf	LCD_CTRL,EN
    		call	DELAY
    		bcf	LCD_CTRL,EN
    		return
    
    DELAY:
    MOVLW 4
    MOVWF 0X20
    
    AGAIN:
    
    MOVLW 0FF
    MOVWF TMR0H
    MOVWF TMR0L
    BCF INTCON,TMR0IF
    BSF T0CON,TMR0ON
    
    DELAY1:
    
    BTFSS INTCON,TMR0IF
    BRA DELAY1
    BCF T0CON,TMR0ON
    DECFSZ 0X20
    BRA AGAIN
    RETURN
    END
    
    Attached Files
    Last edited by Wond3rboy; 8th July 2009 at 07:36 AM.
    Syed

+ Reply to Thread

Similar Threads

  1. pic18f452
    By butters in forum Micro Controllers
    Replies: 2
    Latest: 15th May 2009, 07:50 AM
  2. pic18f452 ADC
    By strong-storm2006 in forum Micro Controllers
    Replies: 5
    Latest: 30th November 2008, 08:14 AM
  3. PIC18f452 with accelerometer
    By erictham83 in forum Micro Controllers
    Replies: 2
    Latest: 19th August 2006, 08:44 PM
  4. Pic18f452
    By yantheman in forum Micro Controllers
    Replies: 1
    Latest: 4th May 2006, 05:17 PM
  5. PIC18F452 Timers
    By mora in forum Micro Controllers
    Replies: 1
    Latest: 2nd September 2005, 10:53 AM

Tags for this Thread