How On Interrupt works?


Closed Thread
Results 1 to 13 of 13

Hybrid View

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


    Did you find this post helpful? Yes | No

  2. #2
    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

  3. #3


    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>

  4. #4
    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

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Thank you!!

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


    Did you find this post helpful? Yes | No

    Default

    You're welcome, but you'll want to consider a few other things here too.

    1. RCIF is only cleared after a read of RCREG. To clear RCIF, you will want to read this data
    with HSERIN or X = RCREG until RCIF is cleared.

    2. Values you use in hardware USART defines are not loaded into USART registers if there is
    not at least one instance of HSERIN or HSEROUT used somewhere within your program.

    Just inserting these defines is not configuring the hardware USART for you. Just FYI.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    You're welcome, but you'll want to consider a few other things here too.

    1. RCIF is only cleared after a read of RCREG. To clear RCIF, you will want to read this data
    with HSERIN or X = RCREG until RCIF is cleared.

    2. Values you use in hardware USART defines are not loaded into USART registers if there is
    not at least one instance of HSERIN or HSEROUT used somewhere within your program.

    Just inserting these defines is not configuring the hardware USART for you. Just FYI.
    Hi Bruce,
    That's good info! Thanks, How is that book coming? Sign me up for a copy
    JS
    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. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 10: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, 03:35
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 19:14
  4. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 21:58
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 02: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