Interrupts on PIC16F628A

General discussion on mikroBasic.
Post Reply
Author
Message
jrigley
Posts: 8
Joined: 11 Mar 2005 11:01

Interrupts on PIC16F628A

#1 Post by jrigley » 27 Jul 2015 12:26

Hi,

I have started to learn about interrupts reading what I can.

I have a PIC16F628A with an LED on Port A1. I want to be able to apply ground or positive not sure which to Pin 6 (RB0/INT). Below is the code Im using however the LED remains off no matter if I set the Int to high or low.

Can anyone see what i'm doing wrong?

Thank you

Code: Select all

Program Interrupts

Sub procedure interrupt

  If INTCON.INTE  = 1 THEN
    PORTA.1 = 1
    INTCON.INTE  = 0
  End If

End sub

Main:

  TRISB = 0x01
  TRISA = 0x00
  INTCON = 0x90

While (True)
    PORTA.1 = 0
Wend

End.

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Interrupts on PIC16F628A

#2 Post by janni » 27 Jul 2015 23:32

For one thing, even with properly written ISR, the LED would be on for few microseconds only before the main code switched it off :wink: . And, as you disable the INT interrupt in ISR, this happens only once. And there's the matter of disconnecting comparators' inputs, as they're by default assigned to PORTA pins.

BTW, the INTEDG bit in OPTION_REG determines the direction (rising or falling edge) of INT interrupt.

This should produce a short flash on rising edge of INT/RB0 (not tested though).

Code: Select all

Program Interrupts

dim flag as bit

Sub procedure interrupt

  If INTCON.INTF = 1 THEN
    flag = 1
    INTCON.INTF = 0
  End If

End sub

Main:

  TRISB = 0x01
  TRISA = 0x00
  CMCON = 0x07 ' comparators off
  PORTA.1 = 0
  OPTION_REG.INTEDG = 1  ' rising edge 
  INTCON.INTE = 1
  INTCON.GIE = 1

While (True)
  if flag then
    PORTA.1 = 1
    Delay_ms(250)
    PORTA.1 = 0
    flag = 0
  endif
Wend

End.

jrigley
Posts: 8
Joined: 11 Mar 2005 11:01

Re: Interrupts on PIC16F628A

#3 Post by jrigley » 28 Jul 2015 06:44

Thank you that example works perfectly. Thank you for taking the time to explain too.

Jonathan

Post Reply

Return to “mikroBasic General”