How can i use Interrupt in my program??


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2007
    Posts
    4

    Exclamation How can i use Interrupt in my program??

    Im a new user of PBP and im using PIC16F877A microcontroller chip...
    the program i need to have is that a pulses generated with specific frequency and it should generate this frequency pulses untill an interrupt occures from the user, but the problem is that i dont know how to use the interrupt code (i cudnt know the concept of ON INTERRUPT, DISABLE INTERRUPT, ENABLE INTERRUPT and how they are working through the code)

    ==> the interrupt should check if the user presses any other key to change the frequency, if not it should cont looping and generating the previous frequency

    following is my code:
    =====================================
    Define LOADER_USED 1

    ' Define LCD connections
    Define LCD_DREG PORTD
    Define LCD_DBIT 4
    Define LCD_RSREG PORTE
    Define LCD_RSBIT 0
    Define LCD_EREG PORTE
    Define LCD_EBIT 1


    ' Define program variables
    col Var Byte ' Keypad column
    row Var Byte ' Keypad row
    key Var Byte ' Key value
    fre Var byte ' half pulse time
    LED0 var PORTD.0 ' Alias PORTD.0 to LED

    OPTION_REG = $7f ' Enable PORTB pullups

    ADCON1 = 7 ' Make PORTA and PORTE digital
    Low PORTE.2 ' LCD R/W low (write)

    Pause 100 ' Wait for LCD to start

    Lcdout $fe, 1, "Choose Your Frequency" ' Display sign on message

    loop1: Gosub getkey ' Get a key from the keypad

    loop3: if key = 1 then
    Lcdout $fe, 1, "1 Hz"
    fre = 500
    gosub loop2
    endif

    loop4: if key = 2 then
    Lcdout $fe, 1, "10 Hz"
    fre = 50
    gosub loop2
    endif

    loop5: if key = 3 then
    Lcdout $fe, 1, "50 Hz"
    fre = 80
    gosub loop2
    endif

    loop6: if key = 4 then
    Lcdout $fe, 1, "100 Hz"
    fre = 40
    gosub loop2
    endif


    loop2: High LED0 ' Turn on LED connected to PORTD.0
    Pause fre ' Delay for "fre" seconds

    lOW LED0
    Pause fre ' Delay for "fre" seconds

    goto loop2

    Return ' Go back to loop and blink LED forever


    ' Subroutine to get a key from keypad
    getkey:
    Pause 500 ' Debounce

    getkeyu:
    ' Wait for all keys up
    PORTB = 0 ' All output pins low
    TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
    If ((PORTB >> 4) != $f) Then getkeyu ' If any keys down, loop

    Pause 50 ' Debounce

    getkeyp:
    ' Wait for keypress
    For col = 0 To 3 ' 4 columns in keypad
    PORTB = 0 ' All output pins low
    TRISB = (dcd col) ^ $ff ' Set one column pin to output
    row = PORTB >> 4 ' Read row
    If row != $f Then gotkey ' If any keydown, exit
    Next col

    Goto getkeyp ' No keys down, go look again

    gotkey: ' Change row and column to key number 1 - 16

    key = (col * 4) + (ncd (row ^ $f))
    Return ' Subroutine over

    End
    ===========================================

    please.. i need help ASAP... thnx
    Last edited by alabbadi; - 17th November 2007 at 11:30. Reason: missing information

  2. #2
    Join Date
    May 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    Use search at the top of the forum, it's full of discussions and cool examples.
    "Beethoven had his critics too, see if you can name 3 of them"

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. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59
  3. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  4. Simple Interrupt Program
    By eoasap in forum General
    Replies: 5
    Last Post: - 28th October 2005, 16:22
  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