do i need to init the CG or DD in 4 bit lcd?


Closed Thread
Results 1 to 5 of 5
  1. #1
    EDWARD's Avatar
    EDWARD Guest

    Default do i need to init the CG or DD in 4 bit lcd?

    im trying to write an S on the screen,pause for 5 secs, clearscreen, repeat. im
    starting simple so i can build from it. i have no problems doing instuctional commands but everytime i try to write some ascii, the character is blank. the lcd commands does what it is supposed, it clears the screen, goesto line 1, trys to write the S, waits 5 secs then repeats. so all good. i am making the RS pin high
    when i write the ascii. so my question is do i need to initialize the character register before it will work? and how do i do it. i dont understand how to read some of the data sheets that say CG RAM ADDRESS SET and DD RAM ADDRESS SET. i know there are alot of pauses, but thats because im want it to run slow for now. my board has pusbutton pwer so thats why there is the pwr LOCK ON.just ignore that part.

    heres my code so far:


    lcde var PORTC.1
    lcdrs var PORTC.0
    lcd7 var PORTA.0
    lcd6 var PORTA.1
    lcd5 var PORTA.2
    lcd4 var PORTB.3 '<-the reason why this so long

    TRISA=%011000 'PORT A
    TRISB=%11110011 'PORT B
    TRISC=%11100000 'PORT C
    pause 500 'need to hold pwr butn for .5 secs
    PORTA=%100000
    PORTB=%00000000
    PORTC=%00010000 'PWR LOCK-ON
    pause 500 'give lcd time to power up

    Lcde=0 'start with lcd enable low


    Gosub lcdinit 'initialize the lcd
    '--------------------------------------------------------------


    MAIN: 'all i want to do is display an S

    lcdrS = 1 'Data mode
    pause 100
    '--------------------
    lcd7 = 0
    lcd6 = 1
    lcd5 = 0
    lcd4 = 1
    gosub lcdtog 'ascii "S"
    lcd7 = 0
    lcd6 = 0
    lcd5 = 1
    lcd4 = 1
    gosub lcdtog
    '---------------------



    pause 5000
    gosub clearlcd
    Goto MAIN








    '---------------------------------------------------------------------
    ' subroutine to toggle the lcd enable line
    lcdtog:
    pause 50
    High Lcde 'set lcd enable line high
    pause 1
    Low Lcde 'set lcd enable line low
    pause 50
    Return

    '-----------------------------------------------------------------
    clearlcd:
    lcdrS = 0 'instruction mode
    '--------------------
    lcd7 = 0
    lcd6 = 0
    lcd5 = 0
    lcd4 = 0
    gosub lcdtog 'clearscreen
    lcd7 = 0
    lcd6 = 0
    lcd5 = 0
    lcd4 = 1
    gosub lcdtog
    '---------------------

    '--------------------
    lcd7 = 0
    lcd6 = 0
    lcd5 = 0
    lcd4 = 0
    gosub lcdtog 'increment text mode
    lcd7 = 0
    lcd6 = 0
    lcd5 = 1
    lcd4 = 0
    gosub lcdtog
    '---------------------
    return
    '--------------------------------------------------------------


    '--------------------------------------------------------------

    lcdinit:
    '-----------------------
    Pause 15 'wait at least 15ms
    lcdrS = 0 'instruction mode

    pause 50
    lcd7 = 0
    lcd6 = 0
    lcd5 = 1
    lcd4 = 0 'initialize the lcd
    Gosub lcdtog 'Toggle E line
    lcd7 = 0
    lcd6 = 0
    lcd5 = 1
    lcd4 = 0 'initialize the lcd
    Gosub lcdtog 'Toggle E line
    lcd7 = 0
    lcd6 = 0
    lcd5 = 1
    lcd4 = 0 'initialize the lcd
    Gosub lcdtog 'Toggle E line
    lcd7 = 0
    lcd6 = 0
    lcd5 = 1
    lcd4 = 0
    Gosub lcdtog
    lcd7 = 1
    lcd6 = 0
    lcd5 = 0
    lcd4 = 0
    Gosub lcdtog
    '--------------------



    '--------------------
    lcd7 = 0
    lcd6 = 0
    lcd5 = 0
    lcd4 = 0
    Gosub lcdtog 'display on, cursor on, blink on
    lcd7 = 1
    lcd6 = 1
    lcd5 = 1
    lcd4 = 1
    Gosub lcdtog
    '--------------------

    '--------------------
    lcd7 = 0
    lcd6 = 0
    lcd5 = 0
    lcd4 = 0
    gosub lcdtog 'clearscreen
    lcd7 = 0
    lcd6 = 0
    lcd5 = 0
    lcd4 = 1
    gosub lcdtog
    '---------------------

    '--------------------
    lcd7 = 0
    lcd6 = 0
    lcd5 = 0
    lcd4 = 0
    gosub lcdtog 'increment text mode
    lcd7 = 0
    lcd6 = 0
    lcd5 = 1
    lcd4 = 0
    gosub lcdtog
    '---------------------


    Return

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Note that most PIC have now analog Comparator and/or ADC attach to PORTA. Those have to be disable prior to use them in digital mode as you do.

    As you're using an PIC16F73.

    ADCON1=7 ' set all analog pins to digital,see datasheet section 11

    Also i'm i blind/dumb or your Board have an 4.19MHZ crystal on??????

    IF so, you'll have to do some maths 'cause PBP, as i know/read in V2.45, don't have any define for this crystal.... only 4MHZ. So by using default 4MHZ setting all commands will be executed a bit faster than what you expect. few maths to correct your timing will do the job.

    But i feel that LCDs are not so much timing critical. The only question i have... should you set oscillator config fuse to XT or HS? XT is for 4MHZ crystal... so i feeel you'll have to use HS osc but i'm not 100% sure since i never did some test with that crystal speed. Anybody used that crystal speed before?
    Last edited by mister_e; - 14th May 2005 at 15:44.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    EDWARD's Avatar
    EDWARD Guest


    Did you find this post helpful? Yes | No

    Default

    k thnka for the help. portA.3 needs to work as Anologue to digital input so ill need to read the data sheet for that. and there is a voltage referance control on portA.5 i think as well. i havent got to that part yet. i am in HS programming mode, an it seems to work fine. timming is not absolutly critical in my design, as most of the machinary control is relative. but m question is about the LCD screens "memory". does my inititalization code look right? remeber all the instruction commands work. just the display data is always blank, meaning, if i want to display 123 on the screen,the cursor will move to the right 3 places thinking that is just wrote the 123 but the screen is blank except for the cursor.
    do i need to tell it where the CG or DD memory banks start?

  4. #4
    EDWARD's Avatar
    EDWARD Guest


    Did you find this post helpful? Yes | No

    Default Problem Solved

    Thank you Mister_E. The problem I was having was that i forgot to put the line of code:

    ADCON1=7 ' set all analog pins to digital

    At the top of my program.

    This was becuase my PortA has an Anologue to Digital converter onboard and I needed to tell the PIC to have it function as a standard I/O Port, as you have informed me.
    I usually look at the data sheets but the examples are in ASSEMBLY and I get confused.
    Once again thanks for the quick and precise answer.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Thumbs up

    Well done EDWARD. Nice to know that i point you in the right direction.

    Another happy customer!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. 16f688 LCD what have I done wrong
    By spitfiredriver in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th August 2009, 19:54
  2. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  3. having problems with Hantronix 20x4 lcd
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 22nd December 2005, 12:22
  4. encoder wowes
    By wallaby in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 6th December 2005, 21:56
  5. 4 Bit Lcd Hookup
    By GEEZER in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th May 2005, 00:14

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts