interrupt the 240ac power line by using the pin rb0/int(zero crossing detector) of pi


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2008
    Posts
    45

    Default interrupt the 240ac power line by using the pin rb0/int(zero crossing detector) of pi

    i try to interrupt the 240ac power line by using the pin rb0/int(zero crossing detector) of pic16f877a.the code as shown below(search from internet):

    void interrupt()
    {
    PORTA = PORTA - 1; //decrement the value on PORTA
    INTCON.INTF = 0; //enable new RB0/INT interrupts
    OPTION_REG=0;
    }

    void main()
    {
    OPTION_REG.INTEDG=1;
    TRISA = 0x00; //set all PORTA pins as outputs
    PORTA = 0xff; //make all PORTA pins high
    INTCON.INTE = 1; //enable RB0/INT interrupts
    INTCON.GIE = 1; //enable all un-masked interrupts
    }

    are those coding will work.can someone help me briefly translate it into basic pro language cause i use microcode studio basic pro to compile.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Cool

    A little bit of legwork on your end wouldn't hurt your case either ya know...
    (Comments in boldface, obviously)
    [code]
    void interrupt() If you don't know how to use interrupts, this would be a good chance to learn how to use them
    {
    PORTA = PORTA - 1; //decrement the value on PORTA PortA = PortA -1, although I don't think I'd use this method. I'd use another variable to do the counting and then copy that variable into portA
    INTCON.INTF = 0; //enable new RB0/INT interrupts The datasheet for your particular PIC will show you which bit of INTCON enables RB0/INT interrupts
    OPTION_REG=0;
    }

    void main()
    {
    OPTION_REG.INTEDG=1; Again, the datasheet will show you which bit select the edge to trigger from
    TRISA = 0x00; //set all PORTA pins as outputs
    PORTA = 0xff; //make all PORTA pins high
    INTCON.INTE = 1; //enable RB0/INT interrupts same as above
    INTCON.GIE = 1; //enable all un-masked interrupts same as above
    }
    [/QUOTE]

  3. #3
    Join Date
    Aug 2008
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    thanx for the comment skimask.but i don't clearly understand about your comment on:

    "PortA = PortA -1, although I don't think I'd use this method. I'd use another variable to do the counting and then copy that variable into portA"

    what method do you prefer to use???what is the meaning of PortA = PortA -1 in this case???sory to ask,i'm a newbie in this thing.thanx once again for your reply...

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by texas5 View Post
    "PortA = PortA -1, although I don't think I'd use this method. I'd use another variable to do the counting and then copy that variable into portA"

    what method do you prefer to use???what is the meaning of PortA = PortA -1 in this case???sory to ask,i'm a newbie in this thing.thanx once again for your reply...
    If you use PortA = PortA - 1, you may run into issues with the PIC.
    PortA=PortA - 1 will read the actual values on the pins, subtract one, and write it back.
    Sounds good in theory, doesn't always work that way in practice. Might work well, might not.
    I think a better way would be to read that PortA value into a temporary variable, subtract 1, then write that value back. At least then you have a copy of that value in that temporary variable to mess with, and without messing with the actual Port itself.

  5. #5
    Join Date
    Aug 2008
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    thanx.actually,u has help me a lot.one more thing...can i compile the coding using microcode studio basic pro???
    Last edited by texas5; - 10th September 2008 at 03:49.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by texas5 View Post
    thanx.actually,u has help me a lot.one more thing...can i compile the coding using microcode studio basic pro???
    What 'coding'?

  7. #7
    Join Date
    Aug 2008
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    nothing.sory.hehe.i've tested my hardware today.it's work man.thanx to you.i modify the above code into:

    DEFINE OSC 8
    TRISA.1=0
    TRISA.2=0

    MAIN:

    INTCON.4 = 1 ;enable RB0/INT interrupts
    INTCON.7 = 1 ;enable all un-masked interrupts

    if INTCON.1 = 1 Then ;RB0/INT interrupts occured
    goto EDGE
    ENDIF

    EDGE:

    IF OPTION_REG.6=1 then ;interrupt on rising edge
    LOW PORTA.1
    else
    OPTION_REG.6=0 ;interrupt on falling edge
    LOW PORTA.2
    endif

    GOTO MAIN

    thanx once again...

Similar Threads

  1. 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
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07
  4. having problems with Hantronix 20x4 lcd
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 22nd December 2005, 12:22
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

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