16F872 and LCD


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 49

Thread: 16F872 and LCD

  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,648


    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Angry

    Doesn´t work.

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Lightbulb

    Aha ...

    Code:
    ' One-wire temperature for Picboard and DS1820
    
    'Ok le 29/08/2004 - 534 lignes
    
    
    ' Define LCD registers and bits
    
    Define	LCD_EBIT	1
    
    DQ				Var	PORTB.4		' One-wire data pin
    Ok				Var PORTB.5		' Led Verte
    Waito			Var PORTB.6		' Led Orange
    Error			Var PORTB.7		' Led Rouge
    
    
    temperature 	Var	Word			' Temperature storage
    count_remain 	Var Byte			' Count remaining
    count_per_c 	Var	Byte			' Count per degree C
    offset			Var Word			' 100 * offset réel !!!
    
    offset = 293
    
    PAUSE 500
    LCDOUT $FE,1
    
    
    '*****************************************************************************
    ' Start temperature conversion
    '*****************************************************************************
    
    mainloop: OWOut DQ, 1, [$CC, $44 ]
    
    '*****************************************************************************
    ' Check for still busy converting ( ~ 4500 fois ... )
    '*****************************************************************************
    
    waitloop: 
    
    		INPUT DQ
    		If NOT DQ Then waitloop
    	
    '*****************************************************************************
    ' Read the temperature
    '*****************************************************************************
    	
    	OWOut DQ, 1, [$CC, $BE ]		
    	
        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)+ offset
    	
    	Lcdout $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " ",$DF,"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, " ",$DF,"F"
    	
    '*****************************************************************************
    ' Display about once a second
    '*****************************************************************************
    
            Pause 1000                      
    
    	Goto mainloop			' Do it forever
    looks we have the same source !!! ... This one works perfectly aboard a 16F84 ...

    soo ... let's check the 872 config ... AND,AND,AND :


    Wich PbP version do you use ... and has your PBPpic14.lib being modified ???

    There was an interesting thread those days about 1Wire and > 8 Mhz Osc ...

    see here : http://www.picbasic.co.uk/forum/show...79&postcount=4

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    I use PBP v2.45 and have not modified anything.

    The PIC runs on OSC 20


    Edit: Just tryed to put in a 4 Mhz crystal but i does´t work
    Last edited by Fredrick; - 17th January 2008 at 17:43.

  11. #11
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Fredrick View Post
    I use PBP v2.45 and have not modified anything.
    The PIC runs on OSC 20
    Edit: Just tryed to put in a 4 Mhz crystal but i does´t work
    Apparently, the bug mentioned at the end of post #9 is only applicable to PBP2.50(a).

    But still, something wierd going on...

    Change your LCD_DATAUS from 600 to 255.
    LCD_DATAUS is a byte value (up until PBP2.50 as far as I know), so 600 is actually 88 (600 - 256 - 256 ) as far as PBP knows.

    Past that...
    Check the pullup on MCLR?
    Watchdog timer off?

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


    Did you find this post helpful? Yes | No

    Default

    I dont know what i have done but now the display shows "333333333333333" on both lines and some times the temerature shows on diffrent positions in the display whit "3" all over the display.

    The display is an HD44780 OLED, can the display be broken?

    The PBP Hello World sampel works..

  13. #13
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Fredrick View Post
    I dont know what i have done but now the display shows "333333333333333" on both lines and some times the temerature shows on diffrent positions in the display whit "3" all over the display.
    The display is an HD44780 OLED, can the display be broken?
    The PBP Hello World sampel works..
    I'm sure the 'Hello World' sample works just fine, but when you start messing around with some of the special LCD commands and stuff, the LCD timing starts to matter.
    Did you change the LCD_DATAUS yet?

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


    Did you find this post helpful? Yes | No

    Default

    Yes i have.

  15. #15
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Place this in the first section of your code;

    @ device pic16F872, hs_osc, wdt_off, pwrt_on, lvp_off, protect_off

    Change DEFINE LCD_DATAUS 600 to DEFINE LCD_DATAUS 50.

    Does it work now?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  16. #16
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Give this a shot:

    Code:
    @ DEVICE PIC16F872, HS_OSC, WDT_OFF, PWRT_ON, LVP_OFF, PROTECT_OFF
    DEFINE OSC 20
    DEFINE LCD_COMMANDUS 3000
    DEFINE LCD_DATAUS 250
    temperature var word : count_remain var byte : count_per_c var byte
    dq var portb.2 : ADCON1 = 7 : pause 1000 : lcdout $fe , 1
    mainloop: OWOut DQ , 1 , [ $CC , $44 ]
    waitloop: OWIn DQ, 4, [count_remain]	 : If count_remain = 0 Then waitloop
    owout dq, 1, [$cc,$be]
    owin dq , 0 , [ temperature.lowbyte , temperature.highbyte , skip 4 , count_remain , count_per_c ]
    temperature = ( ( ( temperature >> 1 ) * 100 ) - 25 ) + ( ( ( count_per_c - count_remain ) * 100 ) / count_per_c )
    Lcdout $fe , $80 , DEC3 ( temperature / 100 ) , "." , DEC2 temperature, " C"
    temperature = ( temperature * / 461 ) + 3200
    Lcdout $fe , $c0 , DEC3 ( temperature / 100 ) , "." , DEC2 temperature , " F"
    Pause 1000 : goto mainloop

    Also, in your original code, you show:
    define OSC 20

    Put all DEFINE's in upper case. It's a bit weird like that.
    Your original code was probably still compiled as if it were for a 4 Mhz oscillator, even though you had 'define OSC 20'.
    Last edited by skimask; - 17th January 2008 at 18:47.

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


    Did you find this post helpful? Yes | No

    Default

    No i does not work...

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


    Did you find this post helpful? Yes | No

    Default

    temperature = ( temperature * / 461 ) + 3200

    ERROR Line 23: Bad expression. (TEST.pbp)


    I use Microcode Studio and microcode put define in uppercase by auto, or do i still have to write it in uppercase?

  19. #19
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Fredrick View Post
    temperature = ( temperature * / 461 ) + 3200

    ERROR Line 23: Bad expression. (TEST.pbp)


    I use Microcode Studio and microcode put define in uppercase by auto, or do i still have to write it in uppercase?
    I just write it in uppercase myself.
    No questions about it then.
    As far as the bad expression, the fix is in the manual.

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


    Did you find this post helpful? Yes | No

    Default

    Bad expression is fixed now, but the problem whit the LCD still remains...

    This is driving me crasy..... gaaahhh i have to take a pause and a cup of coffee now...

  21. #21
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Fredrick View Post
    I use PBP v2.45 and have not modified anything.
    Sounds like it's time to get the 2.50a update...

  22. #22
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Remove the space between the * and / in temperature = ( temperature * / 461 ) + 3200.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Default

    Why? 2.45 should work...

    And update the PBP is not an garanti for that i will work..

  24. #24
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Remove the space between the * and / in temperature = ( temperature * / 461 ) + 3200.
    Fixed in post #20, apparently anyways.

  25. #25
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Fredrick View Post
    Why? 2.45 should work...

    And update the PBP is not an garanti for that i will work..
    The update is only $25, get a new book, all the fixes, support for 32 bit variables, etc.

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


    Did you find this post helpful? Yes | No

    Default

    Maybe i will do that, but still i want to get the LCD to work now..... with the current version...

  27. #27
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Fredrick View Post
    Maybe i will do that, but still i want to get the LCD to work now..... with the current version...
    Are you using the PBP DEMO version?

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


    Did you find this post helpful? Yes | No

    Default

    No i use PICBASIC PRO

    Will it do any diffrent if i use an PIC16F876 insted?
    Last edited by Fredrick; - 17th January 2008 at 19:28.

  29. #29
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Fredrick View Post
    No i use PICBASIC PRO
    '876 vs. '872 - shouldn't make much difference at all.

    PicBasicPro or PicBasicPro Demo version?
    Last edited by skimask; - 17th January 2008 at 19:40.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    '876 vs. '872 - shouldn't make much difference at all.

    PicBasicPro or PicBasicPro Demo version?
    PICBASICPRO

  31. #31
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Fredrick View Post
    PICBASICPRO
    When did you get PicBasicPro?
    How long have you been using it to write programs for PIC's?

    As far as the LCD, maybe the config registers aren't being set up correctly.
    You said you were using an OLED LCD?
    Are they EXACTLY the same as the non-OLED LCD's as far as programming goes?

  32. #32
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Question

    I do not know if any issue ...

    But found this on Melab's site:

    LAB X1
    Compatible with the following microcontrollers:

    PIC16C64(A), 16C65(B), 16C662, 16C67, 16C74(AB), 16C765, 16C77, 16C774, 16F74, 16F747, 16F77, 16F777, 16F871, 16F874, 16F874A, 16F877, 16F877A, 16F884, 16F887, 16F914, 16F917, 18C442, 18C452, 18F4220, 18F4221, 18F4320, 18F4321, 18F4331, 18F4410, 18F442, 18F4420, 18F4423, 18F4431, 18F4439, 18F4450, 18F4455, 18F4458, 18F448, 18F4480, 18F4510, 18F4515, 18F452, 18F4520, 18F4523, 18F4525, 18F4539, 18F4550, 18F4553, 18F458, 18F4580, 18F4585, 18F4610, 18F4620, 18F4680, 18F4682, 18F4685

    16F872 and 876 are not on the list ... simply forgotten or ???

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  33. #33
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    I do not know if any issue ...
    But found this on Melab's site:
    LAB X1
    Compatible with the following microcontrollers:
    16F872 and 876 are not on the list ... simply forgotten or ???
    Alain
    I don't think he's using the LAB X1, just the code has that in the comments.

  34. #34
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    So, Might we think to a bad connection on the breadboard ???
    ************************************************** ***********************
    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 " !!!
    *****************************************

  35. #35
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    So, Might we think to a bad connection on the breadboard ???
    Very possible...but, it works correctly (I think, haven't really determined that) and the LCD only messes up after running for a second or so.

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


    Did you find this post helpful? Yes | No

    Default

    There is nothing wrong whit the code....

    When i put my finger on the LCDs Enable pin everythings become normal, and it´s not a bad soldering, becouse the LCD have tre diffrent connection pionts and everythings become normal when i put my finger of any och the tre connections Enable pin.

    What is wrong?

    A picture of the LCD (OLED)
    http://www.fractronics.com/oled1_b.jpg

  37. #37
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Fredrick,
    I had an issue with some "Import" LCD units and I solved it with a bypass capacitor on the power and ground leads, Pin 1, 2 . My issue was similar to yours.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

    I will try that..

    Btw how do i do if i want to messure both positive and negative temperature?

  39. #39
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Fredrick View Post
    I will try that..

    Btw how do i do if i want to messure both positive and negative temperature?
    Do a search, bunch of code examples here on how to do that.

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


    Did you find this post helpful? Yes | No

    Default

    A 10Kohms resistor i serie with the enable wire and the code works as normal... strange???

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