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


    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

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


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

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


    Did you find this post helpful? Yes | No

    Angry

    Doesn´t work.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


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

  5. #5
    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 18:43.

  6. #6
    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?

  7. #7
    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..

  8. #8
    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

  9. #9
    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...

  10. #10
    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..

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