16F872 and LCD


Closed Thread
Results 1 to 40 of 49

Thread: 16F872 and LCD

Hybrid View

  1. #1
    Join Date
    Jan 2008
    Location
    Sweden
    Posts
    187

    Default 16F872 and LCD

    How do i know the right pins i should connect my LCD display to? or can i select my own pins in my program?

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


    Did you find this post helpful? Yes | No

    Default

    The manual show the default connections. You can also select your own and add some DEFINEs at the top of your program.
    Code:
        '
        '    LCD setup
        '    =========
    DEFINE LCD_DREG PORTB     ' LCD data port
    DEFINE LCD_DBIT 0         ' LCD data starting bit
    DEFINE LCD_RSREG PORTB    ' LCD register select port
    DEFINE LCD_RSBIT 4        ' LCD register select bit
    DEFINE LCD_EREG PORTB     ' LCD enable port
    DEFINE LCD_EBIT 5         ' LCD enable bit
    DEFINE LCD_BITS 4         ' LCD data bus size
    DEFINE LCD_LINES 2        ' Number lines on LCD
    DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
    DEFINE LCD_DATAUS 50      ' Data delay time in us
    Steve

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

  3. #3
    Join Date
    Jan 2008
    Location
    Sweden
    Posts
    187


    Did you find this post helpful? Yes | No

    Default

    But the manual doese´t shows the default connections for 16F872, what are the defaults for my PIC?

    Can i want use RB1 to RB6 insted och the default or does i have to use pin´s from outher ports?

    btw why does the PIC have diffrent ports like PORTA, PORTB, PORTC..

    And yes i´m new to PIC programing and i have just get my LED to blink when i push a button

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


    Did you find this post helpful? Yes | No

    Default

    But the manual doese´t shows the default connections for 16F872, what are the defaults for my PIC?
    Don't worry, the default one are the same for all PIC model.

    Can i want use RB1 to RB6 insted och the default or does i have to use pin´s from outher ports?
    Not sure what you mean
    Steve

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

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Fredrick View Post
    But the manual doese´t shows the default connections for 16F872, what are the defaults for my PIC?
    Actually the manual does show the default connections.......for all PICs!
    If you don't redefine the pins, they'll default to what the manual says, so long as those pins actually exist.

    Can i want use RB1 to RB6 insted och the default or does i have to use pin´s from outher ports?
    In a roundabout way, you can use any pin you want (using DT's ANYPIN routines) for the LCDIN/LCDOUT commands, but I'm guessing that's probably a bit above your skill at the moment. Give it time and anything is possible.

    btw why does the PIC have diffrent ports like PORTA, PORTB, PORTC..
    I suppose they could name them anything they want, just call them 1 thru 30, or A-Z or whatever.
    But, since the PIC16F872 is primarily an 8bit device, it therefore makes a bit more sense to divide up the pins into 8 bit chunks as much as possible to keep the firmware/instructions/etc a bit simpler.
    Quite frankly, you won't see a lot of 6 bit or 13 bit devices out there, or some other off the wall number. Pretty much everything is either 1,4,8, or 16 bits (yes, there are exceptions to the rule, just not a lot).

    And yes i´m new to PIC programing and i have just get my LED to blink when i push a button
    Get on it! Make 2 LEDs blink with 3 buttons... Then make a servo move with the buttons, then make a .... see how it goes?

    Get out while you can! It's a never ending cycle man!!! You'll end up spending all of your money on the latest greatest thing out there!!! Blowing all of your sleep time programming PICs... Lose your money, house, sanity...it's like drugs! It's terrible!!!

    Ok, not really...but you get the point...(as for me, I'll never learn!)

  6. #6
    Join Date
    Jan 2008
    Location
    Sweden
    Posts
    187


    Did you find this post helpful? Yes | No

    Default

    Hello.

    Now i have connected the LCD as PBP defaults and when i run the PIC with this code the display shown the temerature for 1sec and then it shows "fffffffffffffffffffffff" on both lines for a sec and then shows the temerature again and so on...

    Why?

    Code:
    ' One-wire temperature for LAB-X1 and DS1820
    define OSC 20
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 600
    
    temperature Var	Word			' Temperature storage
    count_remain Var Byte			' Count remaining
    count_per_c Var	Byte			' Count per degree C
    
    pause 1000
    
    
    DQ	Var	PORTB.2			' One-wire data pin
    
    	ADCON1 = 7			' Set PORTA and PORTE to digital
    
    mainloop: OWOut DQ, 1, [$CC, $44]       ' Start temperature conversion
    
    waitloop: OWIn DQ, 4, [count_remain]	' Check for still busy converting
    	
        If count_remain = 0 Then waitloop
    
    	OWOut DQ, 1, [$CC, $BE]		' Read the temperature
        OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
    
    	' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
    	temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    	Lcdout $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " C"
    
    	' Calculate temperature in degrees F to 2 decimal places (not valid for negative temperature)
    	temperature = (temperature */ 461) + 3200
    	Lcdout $fe, $c0, DEC (temperature / 100), ".", DEC2 temperature, " F"
    
        Pause 1000                      ' Display about once a second
    
    	Goto mainloop			' Do it forever

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Try this for Waitloop ...
    Code:
    '*****************************************************************************
    ' Check for still busy converting ( ~ 4500 fois ... )
    '*****************************************************************************
    
    waitloop: 
    
    		INPUT DQ
    		If NOT DQ Then waitloop
    AND ....

    Code:
    DEFINE LCD_DATAUS 600
    Should be ...

    Code:
    DEFINE LCD_DATAUS 60



    Alain
    Last edited by Acetronics2; - 17th January 2008 at 16:40.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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