How On Interrupt works?


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1

    Default How On Interrupt works?

    Good day Picers

    Where can I get a simple explanation or sample how "On Interrupt" works with Serial communication (HSERIN / HSEROUT)?

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


    Did you find this post helpful? Yes | No

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    http://www.picbasic.co.uk/forum/ could also be helpful.


    ____________
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Bruce, thank you very much for your sample file.
    I have tried to create an easier implementation, just to see if it is working on my circuit.
    I have a TX circuit and an RX circuit, using RS485.

    Below is my code. The LED on the TX is blinking, but not on the RX side.
    Any idea what I am doing wrong?

    <b>TX Code</b>
    <hr>
    <code>
    &nbsp;&nbsp;Include "Modedefs.bas"

    &nbsp;&nbsp;DEFINE&nbsp;&nbsp;&nbsp;&nbsp; OSC 4

    &nbsp;&nbsp;DE_OR_RE&nbsp;&nbsp;&nbsp;&nbsp;VAR PORTC.5&nbsp;&nbsp;&nbsp;&nbsp; ' DE and RE Pin of SN75176
    &nbsp;&nbsp;LEDPIN&nbsp;&nbsp;&nbsp;&nbsp; VAR PORTD.2&nbsp;&nbsp;&nbsp;&nbsp; ' LED to confirm PIC is running
    &nbsp;&nbsp;DATARECEIVED&nbsp;&nbsp;VAR BYTE
    &nbsp;&nbsp;
    &nbsp;&nbsp;'======== HSEROUT, HSERIN SETTINGS ==========
    &nbsp;&nbsp;DEFINE HSER_RCSTA 90h
    &nbsp;&nbsp;DEFINE HSER_TXSTA 24h
    &nbsp;&nbsp;DEFINE HSER_BAUD 9600

    &nbsp;&nbsp;ADCON1 = 7

    &nbsp;&nbsp;RCIF&nbsp;&nbsp;VAR&nbsp;&nbsp;PIR1.5& nbsp;&nbsp;&nbsp;&nbsp;' Alias RCIF (USART Receive Interrupt Flag)
    &nbsp;&nbsp;OERR&nbsp;&nbsp;VAR&nbsp;&nbsp;RCSTA.1 &nbsp;&nbsp;&nbsp;&nbsp;' Alias OERR (USART Overrun Error Flag)
    &nbsp;&nbsp;CREN&nbsp;&nbsp;VAR&nbsp;&nbsp;RCSTA.4 &nbsp;&nbsp;&nbsp;&nbsp;' Alias CREN (USART Continuous Receive Enable)
    &nbsp;&nbsp;
    Main:
    &nbsp;&nbsp;HIGH DE_OR_RE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' Make ready for RX
    &nbsp;&nbsp;HSEROUT ["1"]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp; ' Send R1
    &nbsp;&nbsp;HIGH LEDPIN
    &nbsp;&nbsp;PAUSE 5000
    &nbsp;&nbsp;LOW LEDPIN
    &nbsp;&nbsp;PAUSE 5000
    GOTO MAIN

    END
    </code>


    <b>RX Code</b>
    <hr>
    <code>
    &nbsp;&nbsp;Include "Modedefs.bas"
    &nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;DEFINE&nbsp;&nbsp;&nbsp;&nbsp; OSC 4

    &nbsp;&nbsp;DE_OR_RE&nbsp;&nbsp;&nbsp;&nbsp;VAR PORTC.5&nbsp;&nbsp;&nbsp;&nbsp; ' DE and RE Pin of SN75176 (RS485)
    &nbsp;&nbsp;LEDPIN&nbsp;&nbsp;&nbsp;&nbsp; VAR PORTD.2&nbsp;&nbsp;&nbsp;&nbsp; ' LED Pin
    &nbsp;&nbsp;i&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p; VAR BYTE

    &nbsp;&nbsp;'======== HSEROUT, HSERIN SETTINGS ==========&nbsp;&nbsp;
    &nbsp;&nbsp;DEFINE HSER_RCSTA 90h
    &nbsp;&nbsp;DEFINE HSER_TXSTA 24h
    &nbsp;&nbsp;DEFINE HSER_BAUD 9600

    &nbsp;&nbsp;ADCON1 = 7

    &nbsp;&nbsp;RCIF&nbsp;&nbsp;VAR&nbsp;&nbsp;PIR1.5& nbsp;&nbsp;&nbsp;&nbsp;' Alias RCIF (USART Receive Interrupt Flag)
    &nbsp;&nbsp;OERR&nbsp;&nbsp;VAR&nbsp;&nbsp;RCSTA.1 &nbsp;&nbsp;&nbsp;&nbsp;' Alias OERR (USART Overrun Error Flag)
    &nbsp;&nbsp;CREN&nbsp;&nbsp;VAR&nbsp;&nbsp;RCSTA.4 &nbsp;&nbsp;&nbsp;&nbsp;' Alias CREN (USART Continuous Receive Enable)

    &nbsp;&nbsp;LOW DE_OR_RE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;' Make ready for RX
    &nbsp;&nbsp;INTCON = %11000000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;' Enable interrupts
    &nbsp;&nbsp;ON INTERRUPT GoTo serialin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' Declare interrupt handler routine
    &nbsp;&nbsp;PIE1.5 = 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' Enable interrupt on USART

    DoSomeStuff:
    &nbsp;&nbsp;For i = 0 to 10
    &nbsp;&nbsp;&nbsp;&nbsp;Pause 2
    &nbsp;&nbsp;Next i
    &nbsp;&nbsp;GOTO DoSomeStuff
    &nbsp;&nbsp;
    serialin:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;' Buffer the character received
    &nbsp;&nbsp;GOSUB BLINK
    &nbsp;&nbsp;RESUME
    &nbsp;&nbsp;
    BLINK:
    &nbsp;&nbsp;HIGH LEDPIN
    &nbsp;&nbsp;PAUSE 1000
    &nbsp;&nbsp;LOW LEDPIN
    &nbsp;&nbsp;PAUSE 1000
    &nbsp;&nbsp;RESUME

    END

    </code>

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


    Did you find this post helpful? Yes | No

    Default

    Lookup disable in your manual under ON INTERRUPT. Then lookup RETURN under GOSUB. That will get you started.
    Regards,

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

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Thank you!!

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  2. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  4. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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