SERIN frustration


+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2012
    Location
    Australia
    Posts
    3

    Default SERIN frustration

    Trying to understand serial communications..
    The aim is to load a large number of 5 digit numbers into a serial eeprom from a PC.
    Step 1 is to master serial comms from PC.

    Using serial communicator (Microcode Studio tool) I send "1234", BUT LCD displays "Received = 3846"

    Any advice would be most welcome.

    My code..

    '**********************************
    @ device PIC16F877a , hs_osc, wdt_on, lvp_off, protect_off
    CLEAR
    DEFINE OSC 8

    DEFINE LCD_DREG PORTB ' Set LCD Data port
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 2
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 3 ' Set LCD Enable bit

    PortA = %00000000 'all outputs low
    PortB = %00000000 'all outputs low
    TrisA = %00000000 'All as outputs
    TrisB = %00000000 ' B.0 as input all others as outs
    TrisC = %11111111

    include"modedefs.bas" ' includes aliases for modes
    W0 var word
    B0 Var byte
    B1 var byte

    LCDOUT 254, 1 'Clear Screen
    pause 100
    LCDOUT 254, 1 'Clear Screen
    LCDOUT "W0 = " , dec W0
    pause 1000
    LCDOUT 254, 1 'Clear Screen
    mainloop:

    serin PortC.7,T2400,[] ,w0.lowbyte ,w0.highbyte

    LCDOUT 254, 1 'Clear Screen
    LCDOUT "Received =" , #W0
    pause 1500

    goto mainloop

    end
    '*******************************************

  2. #2
    Join Date
    Jun 2012
    Location
    Australia
    Posts
    3

    Default SERIN frustration

    Trying to understand serial communications..
    The aim is to load a large number of 5 digit numbers into a serial eeprom from a PC.
    Step 1 is to master serial comms from PC.

    Using serial communicator (Microcode Studio tool) I send "1234", BUT LCD displays "Received = 3846"

    Any advice would be most welcome.

    My code..

    '**********************************
    @ device PIC16F877a , hs_osc, wdt_on, lvp_off, protect_off
    CLEAR
    DEFINE OSC 8

    DEFINE LCD_DREG PORTB ' Set LCD Data port
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 2
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 3 ' Set LCD Enable bit

    PortA = %00000000 'all outputs low
    PortB = %00000000 'all outputs low
    TrisA = %00000000 'All as outputs
    TrisB = %00000000 ' B.0 as input all others as outs
    TrisC = %11111111

    include"modedefs.bas" ' includes aliases for modes
    W0 var word
    B0 Var byte
    B1 var byte

    LCDOUT 254, 1 'Clear Screen
    pause 100
    LCDOUT 254, 1 'Clear Screen
    LCDOUT "W0 = " , dec W0
    pause 1000
    LCDOUT 254, 1 'Clear Screen
    mainloop:

    serin PortC.7,T2400,[] ,w0.lowbyte ,w0.highbyte

    LCDOUT 254, 1 'Clear Screen
    LCDOUT "Received =" , #W0
    pause 1500

    goto mainloop

    end
    '*******************************************

  3. #3
    Join Date
    Jun 2012
    Location
    Australia
    Posts
    3

    Default Re: SERIN frustration

    CORRECTION .. had terminal set to 1200..

    set terminal to 2400 - No Parity - Byte Size = 8 - No Stop Bit
    NOW displays "12849"

  4. #4
    Join Date
    Sep 2009
    Posts
    716

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    1,930

    Default Re: SERIN frustration

    Using serial communicator (Microcode Studio tool) I send "1234", BUT LCD displays "Received = 3846"
    will actually send [0x31,0x32,0x33,0x34,0x0d,0x0a] ascii 1,2,3,4,cr,lf



    how is your pc serial port connected to your pic ?

  6. #6
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    195

    Default Re: SERIN frustration

    I think Richard is correct. This from the manual:

    SERIN begins storing data in the variables associated with each Item. If the variable name is used alone, the value of the received ASCII character is stored in the variable.

    Meaning, in my mind, that you are actually receiving "3" "8" "4" "6" rather than 3846. If the LCD character codes are different than the ASCII character codes...

    The manual goes on to say:

    If variable is preceded by a pound sign ( # ), SERIN converts a decimal value in ASCII and stores the result in that variable.

    This seems to indicate you will receive 3, 8, 4, 6 if you modify your statement. You can receive your data as byte array, and then use multiplication to expand the value into a word variable.

    Editing to include this, a snippet from a recent project of mine that accepts a serial command in the format: CC*HR:MN to reset the time via serial input.

    IF (CO[0] ="T") AND (CO[1]="I") THEN
    REG_VAL[2] = (CO[3]-48) * 10 + (CO[4]-48)
    REG_VAL[1] = (CO[6]-48) * 10 + (CO[7]-48)
    GOSUB CLK_WRITE

    CO[3] and CO[4] are the hour value of the time - I had to subtract 48 from the serial input to convert from the string value to the numeric value and multiply. I suspect you will need to do something similar.
    Last edited by Amoque; - 20th November 2014 at 01:46.

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

    Default Re: SERIN frustration

    Is this what you want?
    Code:
    mainloop:
    serin2 porta.1,84, [STR buffer\5]
    
    pause 200   
    
    serout2 PortA.0,84,[ "Received = ",STR buffer\5]
    pause 500
    
    goto mainloop
    it works using debug a little faster too
    Last edited by Archangel; - 20th November 2014 at 05:50.
    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.

  8. #8
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    195

    Default Re: SERIN frustration

    I think, Archangel, that it exactly the opposite of what he wants - though your code demonstrates the issue perfectly. The OP, it seems from my read, is transmitting the value 3846, but receiving the ASCII character codes of the digits, rather than the single numeric value he desires. Rereading my own post, I was not as clear as I'd wish to be in explaining this - and how to recover the actual value. Your use of STR demonstrates more clearly that it is actually 5 STRing characters received, rather than 1 numeric value.

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

    Default Re: SERIN frustration

    Hi Amoque,
    If he wants the Decimal number he will run into a problem at 65535 as that completely fills a WORD variable, requiring the use of a LONG variable.
    His OP didn't indicate this need, at least that's how I read it. Still ASCII can be the medium for transport, doing the MATH (dirty 4 letter word) after receiving the number. LCD isn't going to display actual numbers as the first 47 are commands and symbols dating back to RTTY for which ASCII was invented, and that is what LCDs display (ASCII)
    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.

Similar Threads

  1. New user frustration (16F688 + LCD)
    By wcpesp in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 3rd February 2013, 16:52
  2. forum posting frustration
    By Heckler in forum Forum Requests
    Replies: 8
    Last Post: - 16th March 2012, 11:31
  3. how to use SERIN???
    By texas5 in forum Serial
    Replies: 4
    Last Post: - 23rd September 2008, 00:03
  4. Serin
    By Eyal in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th February 2007, 13:10
  5. serin
    By Sphere in forum Serial
    Replies: 2
    Last Post: - 28th August 2005, 18:43

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts