How do RCIF works?


Closed Thread
Results 1 to 10 of 10
  1. #1

    Default How do RCIF works?

    This is strange, I'm using Microcode studio plus ICD.
    And while the code is running I use the "ICD Serial In" to send a character to the PIC, but my RCIF=0 so it never goes into my label?

    Here is the part of my code?

    <hr>
    DEFINE LOADER_USED 1 ' bootloader
    DEFINE HSER_RCSTA 90h ' enable serial port,
    define HSER_TXSTA 24h ' enable transmit,
    DEFINE HSER_BAUD 9600 ' set baudrate to 9600
    DEFINE HSER_CLOERR 1 ' automatic clear overrun error
    RCIF VAR PIR1.5 ' Receive interrupt flag (1=full , 0=empty)
    TXIF VAR PIR1.4 ' Transmit interrupt flag (1=empty, 0=full)


    if RCIF then ' incomming data?
    gosub MonitorSerialDataReceived
    endif
    <hr>

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


    Did you find this post helpful? Yes | No

    Default

    mmm, could be many things, can you post your whole code?

    One pointer, if you don't use any HSERIN/HSEROUT in your code, the compiler will never consider your SPBRG, TXSTA, RCSTA define. In this case you should write directly to them. Same thing with The TRISx. HSERIN/HSEROUT will do the job for you, but if you don't use them... maybe you'll receive character but... maybe you'll never saw them at the output... maybe.

    Another Thing...
    Quote Originally Posted by Koosa's code
    DEFINE HSER_CLOERR 1 ' automatic clear overrun error
    should be
    Code:
    DEFINE HSER_CLROERR 1 ' automatic clear overrun error
    The define's spelling is verrrrrrrrrrrrrrrryyy important. In uppercase tooo.

    Maybe the following may help you.
    http://www.picbasic.co.uk/forum/show...42&postcount=2
    http://www.picbasic.co.uk/forum/show...1&postcount=11
    Last edited by mister_e; - 8th January 2006 at 17:18.
    Steve

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

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hi Steve

    Thank you verymuch for your feedback, here is my code?

    <pre>
    DEFINE OSC 4
    DEFINE LOADER_USED 1 ' bootloader
    DEFINE HSER_RCSTA 90h ' enable serial port,
    ' enable continuous receive
    define HSER_TXSTA 24h ' enable transmit,
    ' BRGH=1
    define HSER_SPBRG 103 ' set baudrate to 2400
    DEFINE HSER_CLOERR 1 ' automatic clear overrun error

    RCIF VAR PIR1.5 ' Receive interrupt flag (1=full , 0=empty)
    TXIF VAR PIR1.4 ' Transmit interrupt flag (1=empty, 0=full)

    SerialData var byte
    SWITCHPIN VAR PORTD.1
    BUZZER Var PORTC.2

    Main:
    TRISC = %10000000 ' PORTC.7 is the RX input, PORTC.6 is the TX output
    pause 10 'safe start-up delay
    high SWITCHPIN
    high buzzer
    pause 1000
    low buzzer

    if RCIF then ' incomming data?
    hserin [Serialdata] ' take it
    hserout ["x=",serialdata] ' send it
    endif
    goto main
    End
    </pre>

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


    Did you find this post helpful? Yes | No

    Default

    mmm, so is it working or not?

    Assuming it's not working. Can you just forget the ICD idea and use compile-program button (NOT ICD). Then use the SerialCommunicator of MCS (F4)?

    About now?

    If not, what about if you change your main label just before the IF RCIF... line?

    ----------------------------------------------------------------------------------------
    Your CLROERR is still wrong, you wrote
    Code:
    DEFINE HSER_CLOERR  1           ' automatic clear overrun error
    must be
    Code:
    DEFINE HSER_CLROERR  1           ' automatic clear overrun error
    AND OOPS i just saw it's my mistake too on the link i gave.. mmm. BTW it was tested at that time... so i bet on the ICD thing. Keep us inform.

    PS are you using the MAX232 circuit provide in the MCS help?
    Last edited by mister_e; - 8th January 2006 at 18:14.
    Steve

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

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Yes, it looks like it is the ICD.
    If I program it, it is working, so that make it a bit difficult if I want to debug a large project which are using HSERIN?

    THX

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


    Did you find this post helpful? Yes | No

    Default

    yeeehaaa! O.K so you can probably put some DISABLE DEBUG and ENABLE DEBUG in few place in your program OR use another structure in.

    I mean, send some question or ideas with HSEROUT, then sit for an answer.

    Just a thought... i'm not a big fan and user of any ICD. In fact, i can't remind when i used it for the last time... Sorry!

    I'm sure somebody else will come up here with a better solution than mine anyways.

    Good luck!
    Steve

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

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Thx Steve!!

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


    Did you find this post helpful? Yes | No

    Default

    Another thought. You can even use the serial communicator (no ICD) and use an USART interrupt routine that will do something you ask.

    Let's make things more clear by using an example.

    Let's say i want to change a,b,c parameter while the program is running. With serial communicator i'll send a specific start character, then the parameter i want to change. let's say UUCHANGEA#120

    in the interrupt routine i'll write something like
    Code:
    HSERIN [WAIT("CHANGE"),VarToBeChange,ValueToBeChange)
    Select case VarToBeChange
        CASE "A" : a=ValueToBeChange
        CASE "B" : b=ValueToBeChange
        CASE "C" : c=ValueToBeChange
        END SELECT
    By sending UUCHANGEA#120 , the a Variable is suppose to be equal to 120. Read the Serial Communicator help on that (under Transmit windows>> Parse control character) Really handy sometimes.

    But be aware of the latency of your whole program... maybe a bigger amount of UU "Header" will be usefull. OR simply send something then wait fow the PIC question... as you wish.

    HTH
    Steve

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

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default

    Hi Steve.

    The # sign in the sending message isn't it read by the ValueToBeChange variable?

    Ioannis

    Quote Originally Posted by mister_e
    Let's say i want to change a,b,c parameter while the program is running. With serial communicator i'll send a specific start character, then the parameter i want to change. let's say UUCHANGEA#120

    in the interrupt routine i'll write something like
    Code:
    HSERIN [WAIT("CHANGE"),VarToBeChange,ValueToBeChange)
    Select case VarToBeChange
        CASE "A" : a=ValueToBeChange
        CASE "B" : b=ValueToBeChange
        CASE "C" : c=ValueToBeChange
        END SELECT

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


    Did you find this post helpful? Yes | No

    Default

    NOPE, it's a MCS feature. Look in the help file. The parse control character must be enable in the MCS serial communicator.
    Steve

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

Similar Threads

  1. PORTA.0 works, PORTB.7 or .6 do not
    By ozarkshermit in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 3rd September 2009, 04:25
  2. Replies: 42
    Last Post: - 14th January 2008, 11:38
  3. TMR1 How it works?
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 12th January 2007, 14:24
  4. EPIC Programmer - Works for all chips but the 16F876A
    By 4Lewis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 12th April 2006, 23:59
  5. 16F628A using PORTA.4, and it works, but...
    By zx81 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th August 2005, 08:45

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