HSERIN advice


Closed Thread
Results 1 to 11 of 11

Thread: HSERIN advice

  1. #1
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120

    Default HSERIN advice

    Hello boys&girls,

    I am using a PIC16F627 with external XT 4Mhz,ST232.My communication to my PC is already working.
    I want to send from the hyperterminal 8 ASCII characters DOT1,DOT2...DOT8 using HSERIN.How can I do that?
    After that the characters will be sent using I2C protocol.

    I just want to know the way I will input the ASCII characters with HSERIN.

    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT0BOTHPLANESADDRESS, ["DOT1"]

    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT1BOTHPLANESADDRESS, ["DOT2"]

    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT2BOTHPLANESADDRESS, ["DOT3"]

    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT3BOTHPLANESADDRESS, ["DOT4"]


    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE2, DIGIT0BOTHPLANESADDRESS, ["DOT5"]

    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE2, DIGIT1BOTHPLANESADDRESS, ["DOT6"]

    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE2, DIGIT2BOTHPLANESADDRESS, ["DOT7"]

    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE2, DIGIT3BOTHPLANESADDRESS, ["DOT8"]

  2. #2
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120


    Did you find this post helpful? Yes | No

    Default

    THAT IS MY CODE IHAVE ALREADY WRITTEN BUT IT IS NOT WORKING PROPERTLY.
    ANY IDEA?


    Main:
    SerData = 0
    HSERIN [SerData]
    IF SerData <> 0 THEN
    hserout ["You typed:", SerData,10,13]
    ELSE
    Goto Main
    ENDIF
    PAUSE 1000
    Goto OUT

    Pause 1000


    OUT:
    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT0BOTHPLANESADDRESS, ["SerData[1]"]

    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT1BOTHPLANESADDRESS, ["SerData[2]"]

    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT2BOTHPLANESADDRESS, ["SerData[3]"]

    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT3BOTHPLANESADDRESS, ["SerData[4]"]

  3. #3
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120


    Did you find this post helpful? Yes | No

    Default

    That is a part of my program.Where is the wrong?The only thing I can see in hyperterminal is nikos.I can not put the 8 ASCII CHARACTERS.Hyperterminal does not allow me!!!
    Any idea?

    INCLUDE "MODEDEFS.BAS"

    DEFINE OSC 4

    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLROERR 1

    CMCON = 7

    ..................
    SerData VAR BYTE [8]

    Hserout [10,13,"nikos",10,13]
    Pause 5000

    Main:
    HSerin 5000,Main,[ STR SerData\8]
    PAUSE 500
    HSEROUT ["You typed:", STR SerData\8,13,10]
    PAUSE 500
    Goto OUT

    OUT:
    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT0BOTHPLANESADDRESS, ["SerData[1]"]

    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT1BOTHPLANESADDRESS, ["SerData[2]"]

    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT2BOTHPLANESADDRESS, ["SerData[3]"]

    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT3BOTHPLANESADDRESS, ["SerData[4]"]


    I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE2, DIGIT0BOTHPLANESADDRESS, ["SerData[5]"]

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


    Did you find this post helpful? Yes | No

    Default

    Hyperterminal is the best piece of ^^%#^ that i've never ever work with. Did you try with another program like MicroCodeStudio , RealTerm or else???

    Also, don't forget that once you type something... your program will go to LaLaLand since you didn't tell to return to [main]. But probably it's an copy paste error too.

    Can you also remove the PAUSE 5000 at the begining???
    Steve

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

  5. #5
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120


    Did you find this post helpful? Yes | No

    Post

    I would like to say the truth,I am working with Tera Term pro,which has no problem.
    My program looks good or not?

    Please advice.

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


    Did you find this post helpful? Yes | No

    Default

    i tried by removing all the delay... no problems here. just smething must be 13,10 intead of 10,13
    Steve

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

  7. #7
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120


    Did you find this post helpful? Yes | No

    Default

    I tried that using the serial communicator.That is what I see WITHOUT sending any character:

    --------------------------------
    You typed: You typed: α

    You typed: α

    You typed: Φ

    You typed: Φ

    You typed: Φ

    You typed: Φ
    ---------------------------------
    It seems like sending by itself bytes.Where is the problem?



    loop: IF RCIF = 1 THEN
    Hserin [Serdata[1]] ' Get a char from serial port
    else
    goto starty
    endif
    HSEROUT ["You typed: ", SerData[1],10,13]
    GOSUB OUT
    Goto loop

    starty: Hserout ["Nothing",10,13]
    Goto loop

    out:
    ......................................
    return

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


    Did you find this post helpful? Yes | No

    Default

    Here's a simple routine I use for testing. It will buffer up to 80 bytes, and
    print it after receiving the end of message ~ character.
    Code:
    DEFINE  LOADER_USED 1
    DEFINE  OSC 20
    DEFINE  HSER_BAUD 9600
    DEFINE  HSER_CLROERR 1  ' Automatically clear over-run errors
    DEFINE  HSER_RCSTA 90h	' Enable USART receive
    DEFINE  HSER_TXSTA 24h	' TXSTA=%00100100. TX enable, BRGH=1 for high-speed
    'DEFINE  HSER_TXSTA 20h	' TXSTA=%00100000. TX enable, BRGH=0 for low-speed
    
    GP      VAR BYTE        ' GP variable
    BytesIn var byte[80]    ' Up to 80 bytes
    ByteCnt var byte        ' Indicates number of bytes in buffer
    EOM     CON "~"         ' EOM = "End Of Message" marker
    OERR    VAR RCSTA.1     ' Alias USART over-run bit
    CREN    VAR RCSTA.4     ' Alias USART continuous receive enable bit
    RCIF    VAR PIR1.5      ' Alias USART received character interrupt flag bit
    INTCON  = 0			    ' Disable interrupts
    ByteCnt = 0             ' Zero counter
    ADCON1 = 7              ' A/D off, all digital
    
    Main:
        IF RCIF THEN            ' If RCIF=1 there's a new character in RCREG
         BytesIn[ByteCnt]=RCREG ' Yes. Then store it in array
         IF BytesIn[ByteCnt]=EOM THEN OutMsg
         ByteCnt=ByteCnt+1      ' Increment array index pointer 
        ENDIF
        GOTO Main
    
    OutMsg:
        HSEROUT [13,10,dec ByteCnt," bytes received",13,10]
        HSEROUT [STR BytesIn\ByteCnt,13,10]
        FOR GP=0 TO ByteCnt   ' Clear array bytes 0 to ByteCnt
         BytesIn[GP]=0        '
        NEXT                  '
        ByteCnt=0             ' Reset index pointer back to first element
        WHILE RCIF            ' Keep reading until RCIF is clear to flush buffer
         GP=RCREG             ' after EOM is received
        WEND
        GOTO Main
    
        END
    Regards,

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

  9. #9
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120


    Did you find this post helpful? Yes | No

    Default

    Thanks my friend Bruce,
    Now it is working with some problems.This is my code.
    PROBLEM:When I send 8 bytes via Serial Communicator like this
    qwertyui
    the answer of the pic16f628-04 is:
    You typed: qqqqqqqq
    You typed: eeeeeeee
    instead of
    You typed: qwertyui
    and it does not respond for the next inport stream(8bytes)

    .................................................. ............................
    loop: IF RCIF = 1 THEN
    for i=0 to 7 STEP 1
    RCREG = 0
    SerData[i] = RCREG
    if i=7 then type
    NEXT i
    endif
    goto loop
    type: HSEROUT ["You typed: ", str SerData\8,13,10]
    GOSUB OUT
    Goto loop


    OUT:
    .............................

  10. #10
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120


    Did you find this post helpful? Yes | No

    Default

    I fix the problem and it is ok.
    Question?How can I reach 38.4k baud
    I try DEFINE HSER_BAUD 38400
    DEFINE HSER_SPBRG 6
    but notning.

    My xt is 4Mhz and my pic16f627-04

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


    Did you find this post helpful? Yes | No

    Default

    Unfortunately not every oscillator speed is going to produce the correct bit
    timing for all data-rates.

    With a 4MHz oscillator the error rate is -6.994% for 38400bps. The datasheet
    shows the calculation for finding the right combination.
    Regards,

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

Similar Threads

  1. timeout of Hserin, goto, gosub or both?
    By flipper_md in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 28th October 2009, 18:43
  2. TMR0 interrupt and HSERIN
    By boban in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd September 2008, 11:48
  3. 16F877a Interupt driven Hserin
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd November 2006, 00:38
  4. Hserin not working...
    By robert0 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 22nd August 2005, 12:25
  5. Hserin
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th November 2004, 15:42

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