Interrupt Or I Am Going To Die


Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    kunguz's Avatar
    kunguz Guest


    Did you find this post helpful? Yes | No

    Question How to read portb

    Thanks for replies, what I wonder is I don't know how to read portb; Can you just write down a sample code _?

    Thanks in advance,

    Saolasın Hocam :P

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


    Did you find this post helpful? Yes | No

    Default

    Like what?

    Example:

    IF PORTB.6 = 0 then .....

    or another one

    WHILE PORTB.3 = 0
    ..
    ....
    WEND

    or

    IF PORTB.2 = 1 AND PORTB.5 = 0 THEN .....

    Etc..


    These are some kind of readinds.
    Make sure you make them input pin.


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

  3. #3
    kunguz's Avatar
    kunguz Guest


    Did you find this post helpful? Yes | No

    Question Really can't understand

    So sorry but can you correct my code , I tried everything as in your sample code for PORTB.6 ; But can't get it out.

    By the way my msn is [email protected]. (Olmadı bana burdan yardımcı olursan çok sevinirim, altı üstü bi interruptan çıkamadık)

    Here is my new code below ;
    device 16f84a
    ON_INTERRUPT goto flash
    intcon = %10001000
    input portb.6 ' Bu pinleri sıfırladıktan sonra alıcı olarak ayarlamalısın

    loop:
    high porta
    delayms 200
    low porta
    delayms 200
    goto loop

    disable

    flash:
    WHILE PORTb.6 = 1: WEND
    intcon.0 = 0
    delayms 20
    low porta
    CONTEXT RESTORE

    end

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


    Did you find this post helpful? Yes | No

    Default

    Couple of things to remember.

    1. It is not a good idea to post an e-mail on the forum. You will get thousands of junks to your e-mail. I suggest that you remove it right away and PM to members instead.

    2. You are not using PBP, but this is a PBP forum

    3. Lets keep this issue on this forum, so that it can be some help to some other members having similar issue.


    -----------------------------
    Let me try to start by changing the code to PBP first.

    In your schematic, I would use Interrupt on RB0 pin, instead of RB6 pin. May be you should change that first.

    Then, assuming you are now using RB0/Int, we set Intcon Bit 4: RB0/INT External Interrupt Enable bit. Thus, we end up with INTCON = %10010000

    Now the code should look like below but remember it is with PBP statements. You can get around it.


    Code:
    TRISA =  %00000000     'All output.
    TRISB =  %00000001     'RB0 is input, rest is output.
    INTCON = %10010000     'Enable global (Bit7) interrupt, enable RB0/Int (Bit4) 
    ON INTERRUPT GOTO FLASH
    
                                                     
    loop:
        PORTA = 255
        PAUSE 200
        PORTA = 0
        PAUSE 200
        GOTO loop
    
    disable
    
        FLASH:
            PORTA = 0
            INTCON.0 = 0
    
    RESUME
    ENABLE
    
    END

    Also, why do you have to use interrupt?


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

  5. #5
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Add this line before your main loop:

    RBIF var INTCON.0

    Add these two lines to your flash subroutine:

    @ MOVE?BA PORTB 'Read PORTB by placing it WREG
    RBIF = 0 'Clear the interrupt flag

    Also, read the pic datasheet on interrupts and under the I/O Ports section. You should find were it mentions both of items added to the ISR.

    Steve

  6. #6
    kunguz's Avatar
    kunguz Guest


    Did you find this post helpful? Yes | No

    Question @ Move?ba Portb

    @ MOVE?BA PORTB

    IDE did not recognize this line

  7. #7
    kunguz's Avatar
    kunguz Guest


    Did you find this post helpful? Yes | No

    Question Retlw Portb.6

    RETLW PORTB.6 when I use this line in top flash block, it doesn't do anything and continue to it's job

  8. #8
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default One Other Thing...

    As Sayzer asked,
    Quote Originally Posted by sayzer
    Also, why do you have to use interrupt?
    Using interrupts may just be overcomplicating the application. Could you just pool the I/O line in question in your main loop?

    Steve

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


    Did you find this post helpful? Yes | No

    Default

    As Steve repeated,

    May be, a code like the one below could do the job for you, may be.

    Code:
    TRISA =  %00000000     'All output.
    TRISB =  %01000000     'RB6 is input, rest is output.
    
    IN_PIN VAR PORTB.6
    
                                                     
    Loop:
    
        WHILE IN_PIN
            PORTA = 255
            PAUSE 200
            PORTA = 0
            PAUSE 200
        WEND
        PORTA = 0
    
        GOTO Loop
    
    END
    Not a real drop-in interrupt compatible code but may work in some cases.

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

  10. #10
    kunguz's Avatar
    kunguz Guest


    Did you find this post helpful? Yes | No

    Question Finally working but still got a problem

    Thanks alot for your helps and replies;

    It finally works with this code below , but to return to main progress takes approximetly 1:20 minute. I think there might be problem with my schematic; If ISIS is that good, may be simulation thinks about small arcs that is created by button .Which gives a unexpected voltage levels for a short time to the PORTB.6.So PIC interrupts it's self for more then one time.The reason that took so long, might be that. Is this the problem or is it still in software _?

    device 16f84a
    ON_INTERRUPT goto flash
    intcon = %10001000
    input portb.6

    loop:
    high porta
    delayms 200
    low porta
    delayms 200
    goto loop

    disable

    flash:
    delayms 1000
    MOVF PORTB, W
    low porta
    intcon.0 = 0
    CONTEXT RESTORE

    end

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. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59
  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