A question regarding PIC16F684 to LCD.


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2010
    Posts
    9

    Default A question regarding PIC16F684 to LCD.

    First off, would like to express my thanks to this forum for imparting all this knowledge here. I've been ear-wigging on the sidelines for the past couple months, in which time have managed to glean a whole pile of much-needed information.
    Name here is Peter/Pete, have just recently purchased PBP and in just a few days have so far breadboard'ed several LCD projects.. all working nicely, each one written for the PIC16F628A. From what I have learnt from the PBP manual, and from here, and from the data sheets so far, in order to use a LCD with a 16F684 means having to adjust other parameters, such as ANSEL, etc. I'm obviously not understanding something correctly because it's not working.
    Could I trouble you to grok the code and possibly tell me where I'm going wrong, please?

    Hopefully can one day contribute something back.
    Meantime, top thanks once again.


    ; -----------------------------------------------------------

    ; Date: May 2010
    ; File name: lcd_test.pbp
    ; Compiler: PicBasic Pro V2.6
    ; Editor: MicroStudio V3.0.0.5
    ; Processor: PIC16F684
    ; Oscillator: External 4MHz
    ; LCD: 16 characters X 2 lines

    ; -----------------------------------------------------------

    @ DEVICE PWRT_ON ; Set configuration fuses
    @ Device BOD_ON
    @ Device WDT_ON
    @ Device MCLR_OFF
    @ Device XT_OSC

    ; LCD-to-PIC configuration:
    DEFINE LCD_DREG PortC ; Utilise Port C for all the data lines
    DEFINE LCD_DBIT 0 ; 0 = 4-bit data; 4 = 8-bit data
    ; LCD pins D4 ~ D7 to PIC Port C.3 ~ C.0 (pins 7 ~ 10)
    DEFINE LCD_BITS 4 ; Set bus size (4 = 4-bit data; 8 = 8-bit data)
    DEFINE LCD_RSREG PortC ; Put the R/S Register on Port C
    DEFINE LCD_RSBIT 5 ; LCD R/S pin to PIC Port C.5 (pin 5)
    DEFINE LCD_EREG PortC ; Put the EnABLE Register on Port C
    DEFINE LCD_EBIT 4 ; LCD En pin to PIC Port C.4 (pin 6)
    DEFINE LCD_LINES 2 ; Set number of LCD lines (1 ~ 4)
    DEFINE LCD_COMMANDUS 2000 ; Set 2-millisecond command period
    DEFINE LCD_DATAUS 50 ; Set data delay period

    CMCON0 = %00000111 ; Disable comparators
    ANSEL = %00000111 ; Disable A/D convertors

    TrisA = %000000 : Set Port direction Registers
    TrisC = %000000
    PortA = %000000
    PortC = %000000

    PAUSE 1000

    LCDOUT $FE, 1 ; Initialise and clear the display

    start:
    LCDOUT $FE, $80, "Line 1" ; $80 = First line
    LCDOUT $FE, $C0, "Line 2" ; $C0 = Second line
    GOTO start

    END

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Welcome to the forum!

    On this chip all analog is turned of by
    ANSEL = %00000000
    A little different than some... Data sheet section 4.2.1
    But that may not be the problem.
    ; LCD pins D4 ~ D7 to PIC Port C.3 ~ C.0 (pins 7 ~ 10)
    Do you have the bus pins connected backward?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    May 2010
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Welcome to the forum!
    Do you have the bus pins connected backward?
    Hi, Mackrackit/Dave ~

    Thanks for the welcome.
    The ANSEL value in my previous post was indeed another of my typos, but as soon as I inverted the four data lines was when it all came to life.
    You obviously have a keen eye. Credit to you for having the noodle to spot such an error.

    And thanks a million for helping me out.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    It was you well commented code that allowed the mistake to be found.
    Keep up the good work!

    And be sure to read the section of the data sheet I pointed to to see why the analog settings did not cause the problem... This time
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    May 2010
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    ...be sure to read the section of the data sheet I pointed to to see why the analog settings did not cause the problem...
    Thanks for that.
    Okay by you if I pick your brains one more time, pse?.....
    Just for the sheer sake of learning/curiosity, I'm reading the value of a standard 1mS~2mS R/C pulse, then writing that value to the LCD (Input mode). One of the ADCs is used to create another 1mS~2mS pulse, then displaying that value and at the same time sending the pulse to a separate pin (Output mode)... which works fine on ports A.1 and A.2, but not on ports A.3 ~ A.5.
    I'm not sure that I'm fully understanding the ANSEL/TRISA thing because neither does the mode selection work when A.2 is HIGH - the program jumps straight to output mode and stays there.

    Thanks again for your previous help. Appreciate you coming back.
    Attached Files Attached Files

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Looks like the problem is using an analog configured pin as an input. You can use analog set pins as outputs as the data sheet says but not as digital inputs. The data sheet says something like if a pin is set for analog then all digital reads will be 0(low).
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    May 2010
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    I've cracked it.
    Top thanks once again for the heads-up.

Members who have read this thread : 1

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