LCD / PC question


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    May 2007
    Location
    Area 71
    Posts
    52

    Exclamation LCD / PC question

    I tried to connect my PIC to PC

    LCD shows value exactly as the reading ( 0 to 255 ), but the terminal program shows a 2 bytes combination ( 0 / 0 to 255 / 255 )

    For example : at reading 0, LCD shows 0 and terminal shows 0 0,
    at reading 255, LCD shows 255 and terminal shows 255 255,

    How to make both display the same reading - I want PC terminal displays the same reading as LCD (0 to 255 )? Thank you

    Code:
    main:
    adcin 0,reading
    lcdout $Fe,1,"   value:    "
    LCDOUT $FE, $C0, dec reading
    pause 50
    hserout [reading]
    pause 50
    goto main
    Last edited by luminas; - 23rd August 2008 at 10:02.

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


    Did you find this post helpful? Yes | No

    Default

    Hi luminas,
    is the variable "reading" a word, or byte variable ?
    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.

  3. #3
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    that "main" loop will continue looping, but each time the LCD will be cleared and the value re-written, however, the pc will just keep receiving a value each time, so you will get a whole heap of values spit out in your terminal.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

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


    Did you find this post helpful? Yes | No

    Default

    So try:
    Code:
    main:
    adcin 0,reading
    lcdout $Fe,1,"   value:    "
    LCDOUT $FE, $C0, dec reading
    pause 50
    hserout [DEC reading,10] ' DECIMAL VALUE OF READING WITH LINEFEED
    pause 50
    goto main
    PP 80:81 ver 2.47
    PP 82:83 ver 2.5
    Note: I only looked at Hserout code. . .
    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.

  5. #5
    Join Date
    May 2007
    Location
    Area 71
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Thank you for yor comments,
    Joe: adding DEC statement caused the value in Terminal program incorrect , it spits more character

    This is my code, please check if there is something wrong with fuses or defines
    I use 18F2550, 10mhz xtal with hs pll ( 40mhz)

    Code:
    ASM
            __CONFIG    _CONFIG1L, _PLLDIV_10_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_1_1L
            __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
            __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _VREGEN_OFF_2L
            __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
            __CONFIG    _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_ON_3H  & _CCP2MX_ON_3H
            __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L  & _DEBUG_OFF_4L
               
    ENDASM
    
    define OSC 40
    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 1500 ' Command delay time in us
    DEFINE LCD_DATAUS 44      ' Data delay time in us
    
    DEFINE ADC_BITS 8               ' ADC resolution 8 bit
    DEFINE ADC_CLOCK 3              ' 
    DEFINE ADC_SAMPLEUS 50
    
    define HSER_RCSTA 90H
    DEFINE HSER_TXSTA 20H
    DEFINE HSER_BAUD 9600
    DEFINE HSER_SPBRG 25
    DEFINE HSER_CLROERR 1
    
    reading var byte
    
    
    clear
    porta = 0
    portb = 0
    portc = 0
    TRISA = %00000001               ' Set PORTA to all input
    TRISB = %00000000               ' Set PORTB to all output
    TRISC = %00000000               ' Set PORTC.7 as input, other RC as output
    ADCON1 = %00001110
    
    
    LCDOUT $FE, 1  
    pause 100
    
    
    main:
    adcin 0,reading
    lcdout $Fe,1,"   Value    "
    LCDOUT $FE, $C0, dec reading
    pause 50
    hserout [reading ]
    pause 50
    goto main

  6. #6
    Join Date
    May 2007
    Location
    Area 71
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    I just modified the program as follow:
    Code:
    main:
    
    LCDOUT $FE, 1
    for reading = 1 to 10
    LCDOUT $FE, $C0, dec reading
    hserout [reading ]
    pause 500
    next reading
    LCD shows 1 to 10 sequence correctly, but the terminal program shows:
    3
    254
    4
    254
    7
    254
    8
    254
    11
    254
    12
    254
    15
    254
    48
    254
    51
    254
    52
    254

    What is wrong ?

  7. #7
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    hserout[reading] will not display the value of "reading", it will send "reading" as if it was an ascii character. so for example, if reading=37 you will see the character % on your terminal.

    You need to use hserout[DEC reading] for it to display the decimal representation of the value of reading.

    *edit* also, check to make sure the serial out is working. try hserout["Test"] and see if u get Test on your terminal.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  8. #8
    Join Date
    May 2007
    Location
    Area 71
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    I changed my code to :
    Code:
    main:
    LCDOUT $FE, 1
    LCDOUT $FE, $C0, "test"
    hserout ["test" ]
    pause 1000
    goto main
    LCD displays "test" , nO problem
    Terminal program displays:"
    ÈKÛ¼ìÿ ( String )
    C8 4B DB BC EC FF (Hex)

  9. #9
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Its a problem with your serial baud settings for your pic.

    Change the SPBRG value to 64 like this:

    DEFINE HSER_SPBRG 64

    You could probably even remove that line altogether.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  10. #10
    Join Date
    May 2007
    Location
    Area 71
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    thanks Kamikaze

    After few hours trying any possible setup, I solved the problem

    The problem is with HSPLL config.

    If I change the config to:
    _FOSC_HS_1H
    define osc 10, it works

    but if I change the config to :
    _FOSC_HSPLL_HS_1H
    define osc 40, it did not work as expected

    HSPLL suppose to multiply the frequency, and if I define osc to 40 ( 4x ) it should be working right out of the box , right ? Or did I forget something ?

    Could anyone share information about this ?

  11. #11
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    The PLL expects an input frequency that is a multiple of 4, which your 10 Mhz clock is not.

    For this PIC I usually use a 4Mhz crystal with _PLLDIV_1_1L, _CPUDIV_OSC1_PLL2_1L, and _USBDIV_2_1L which results in a 48Mhz clock for the processor.

    Have a look at the table in the data sheet on pages 29 and 30.

    edit: also have a look at the figure on page 24 - it shows that the PLL must have a 4Mhz input.
    Last edited by Kamikaze47; - 25th August 2008 at 09:56.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

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. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 16:56
  3. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. Dedicated LCD Controller question
    By chuckles in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th February 2006, 14:44

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