HELP 16*2 LCD interface with HC11

Discussion in 'General Electronics Chat' started by tsl83, Nov 11, 2005.

  1. tsl83

    Thread Starter New Member

    Nov 11, 2005
    2
    0
    I'm currently doing the Undergraduate Final Year Project and I'm adding an LCD to my developement board.

    The development board that i designed is M68HC11A1 based.

    The LCD model that I'm using is the POWERTIP PC1602H with KS0066 as the LCD driver.

    I'm facing some problem on interfacing the LCD to the HC11 and also on programming the LCD.

    The wiring connections that i made is as below:

    lcd pin1 ---- gnd
    lcd pin2 ---- vcc
    lcd pin3 ---- variable resistor
    lcd pin4(RS) ---- mcu PA6
    lcd pin5(RW')---- mcu PA3
    lcd pin6(EN) ---- mcu PA5
    lcd pin7 ---- mcu PC0
    lcd pin8 ---- mcu PC1
    lcd pin9 ---- mcu PC2
    lcd pin10 ---- mcu PC3
    lcd pin11 ---- mcu PC4
    lcd pin12 ---- mcu PC5
    lcd pin13 ---- mcu PC6
    lcd pin14 ---- mcu PC7
    lcd pin15 ---- +5V
    lcd pin16 ---- gnd

    I would like to know if the connections i've made are correct especially for the LED Backlights. Should I make the connections like this instead?

    lcd pin15 ---- +4.2V
    lcd pin16 ---- -4.2V

    However, if I am to make this connection, I would like to know how can I supply a negative power since the power supply that I used for all devices are +5V and Gnd only.


    I have written an asm program for my LCD but it doesn't work! Can anyone help me to figure out what's wrong with this program?

    *EQUATES
    PORTA EQU $1000
    PORTC EQU $1003
    DDRC EQU $1007
    STACK EQU $DFFF

    *MAIN PROGRAM
    ORG $C000
    START LDX #STACK
    JSR INIT
    JSR CLEAR
    LDAB #$47 ;WRITE CHAR 'G'
    JSR WRITE
    LDAB #$6F ;WRITE CHAR 'O'
    JSR WRITE
    LDAB #$6F ;WRITE CHAR 'O'
    JSR WRITE
    LDAB #$64 ;WRITE CHAR 'D'
    JSR WRITE
    LDAB #$20 ;WRITE 'SPACE'
    JSR WRITE
    LDAB #$4D ;WRITE CHAR 'M'
    JSR WRITE
    LDAB #$6F ;WRITE CHAR 'O'
    JSR WRITE
    LDAB #$72 ;WRITE CHAR 'R'
    JSR WRITE
    LDAB #$6E ;WRITE CHAR 'N'
    JSR WRITE
    LDAB #$69 ;WRITE CHAR 'I'
    JSR WRITE
    LDAB #$6E ;WRITE CHAR 'N'
    JSR WRITE
    LDAB #$67 ;WRITE CHAR 'G'
    JSR WRITE
    NOP
    SWI
    END

    *INITIALIZE LCD

    INIT LDAA #$00
    STAA PORTC
    STAA PORTA ;CLEAR PORTC & PORTA

    *INITIALIZE FUNCTION SET
    LDAA $#FF
    STAA DDRC ;PORTC AS OUTPUT
    LDAA #$20
    STAA PORTA ;EN=1, RS=0
    LDAA #$38
    STAA PORTC
    LDAA #00
    STAA PORTA ;CLEAR EN
    JSR WAIT

    *INITIALIZE DISPLAY ON/OFF CONTROL
    LDAA $#FF
    STAA DDRC ;PORTC AS OUTPUT
    LDAA #$20
    STAA PORTA ;EN=1, RS=0
    LDAA #$0E
    STAA PORTC
    LDAA #00
    STAA PORTA ;CLEAR EN
    JSR WAIT

    *INITIALIZE ENTRY MODE SET
    LDAA $#FF
    STAA DDRC ;PORTC AS OUTPUT
    LDAA #$20
    STAA PORTA ;EN=1, RS=0
    LDAA #$06
    STAA PORTC
    LDAA #00
    STAA PORTA ;CLEAR EN
    JSR WAIT
    RTS

    *CLEAR DISPLAY
    CLEAR LDAA $#FF
    STAA DDRC ;PORTC AS OUTPUT
    LDAA #$20
    STAA PORTA ;SET EN=1, RS=0
    LDAA #$01
    STAA PORTC
    LDAA #00
    STAA PORTA ;CLEAR EN
    JSR WAIT
    RTS

    *DISPLAY ON LCD
    WRITE PSHB
    LDAA $#FF
    STAA DDRC ;PORTC AS OUTPUT
    LDAA #$60
    STAA PORTA ;EN=1, RS=1, RW'=0
    PULB
    STAB PORTC
    LDAA #$00
    STAA PORTA ;CLEAR CONTROL PINS
    JSR WAIT
    RTS

    *CHECK BUSY FLAG
    WAIT LDAA #$28 ;EN=1, RS=0, RW'=1
    STAA PORTA
    LDAA #$00
    STAA DDRC ;PORTC AS INPUT
    LDAA PORTC ;READ PSDB
    ANDA #$80 ;CHECK THE BUSY FLAG
    CMPA #$80
    BEQ WAIT ;LOOP IF FLAG IS SET, ELSE
    LDAA #$00
    STAA PORTA ;EN=0, RS=0, RW'=0
    RTS

    ORG $FFFE
    FDB START
     
  2. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    With a LED backlight, typically the LCD just has LEDS & no limiting resistors.
    You need to check the forward voltage & continuous current rating for the backlight and add a series resistor to set the current appropriately.

    e.g. if the backlight forward voltage was 4V and it's rated at 50mA, you could use a 22 Ohm resistor in series with the 5V supply to set a reasonable current.
    (5 - 4) / .05 = 20 so use 22 as a convenient value.

    One thing I notice with the progam is that you are often clearing Port A by writing #$00 to it. This may cause problems as you are simultaneously changing EN & possibly RS and R/W. It's probably better to clear the EN pin only and keep RS & R/W stable.

    Likewise at the start of a write, set all other control & data pins to the required state with EN off, then toggle EN on & back off again to latch the data.

    A tip for checking the busy flag; once you have loaded the data, you can use the ANDA #$80 (or just TSTA ?? Long time since I've done any HC11 assembler..)
    then BMI xxx as the negative bit will be set if the high bit of the value is 1.
     
  3. Gorgon

    Senior Member

    Aug 14, 2005
    113
    0
    Hi,
    The LED backlight of your display has a forward voltage drop of 4.2V. I normally feed this with 5V with a 5 ohm(2x 10 in parallel) resistor in series.

    Most of your code is ok, but you need to change this:

    Code ( (Unknown Language)):
    1. *DISPLAY ON LCD
    2. WRITE   PSHB    ;You don't need to push B since you don't use B in the routine
    3.     LDAA    $#FF
    4.     STAA    DDRC;PORTC AS OUTPUT
    5.     LDAA    #$60
    6.     STAA    PORTA;EN=1, RS=1, RW'=0
    7.     PULB
    8.     STAB    PORTC
    9.     LDAA    #$40;00  #### keep RS =1 you clock data when EN goes low #####
    10.     STAA    PORTA;CLEAR CONTROL PINS
    11.     JSR WAIT
    12.     RTS
    13.  
    I also changed your wait routine, because you enabled the outputs from portC and the LCD at the same time:
    Code ( (Unknown Language)):
    1. Alternative WAIT routine:
    2.  
    3. WAIT    LDAA    #$00
    4.     STAA    DDRC;PORTC AS INPUT   ## change port to input before you enble the LCD output.
    5.     LDAA    #$28    EN=1, RS=0, RW'=1
    6.     STAA    PORTA
    7.     LDAA    PORTC;READ PSDB
    8.     BMI WAIT;LOOP IF FLAG IS SET, ELSE
    9.     LDAA    #$00
    10.     STAA    PORTA;EN=0, RS=0, RW'=0
    11.     RTS
    12.  
    I hope this make your display work.

    TOK ;)
     
Loading...