PIC Interrupt help

Thread Starter

electronic_noob

Joined Jan 15, 2010
42
I need help on my pic program, the program goes like this the combination of LED to be turned ON depends on the input from serin but I want to put an interrupt so that when the interrupt is enabled all LED would be turned on..., I couldn't make it work is it possible that there is some conflict on the serin with interrupt?

Im planning to let the pic read first the last input that when there would be black out it would still retain it's last input , thats why the program is written that way. my problem is interrupt, I want it that if there is voltage in Rb0 all the LED would be high please help me.


this is the code:

@ DEVICE pic16F628A,INTOSC_OSC_NOCLKOUT
@ DEVICE pic16F628A,WDT_OFF
@ DEVICE pic16F628A,CPD_OFF
@ DEVICE PIC16F628A,PROTECT_OFF
@ DEVICE PIC16F628A,BOD_OFF
@ DEVICE PIC16F628A,LVP_OFF
@ DEVICE PIC16F628A,MCLR_OFF

TRISB = %00000011
TRISA = %00000000
CMCON=7
Include "modedefs.bas"
MARCUS VAR BYTE
B0 VAR BYTE
LED VAR PORTB.3
TRUE CON 1
FALSE CON 0
LOW PORTB.3
LOW PORTB.4
LOW PORTB.5
LOW PORTB.6
OPTION_REG = %00111111
On Interrupt Goto myint ' Define interrupt handler
INTCON = %10010000



START

SERIN PORTB.1,2,["U"],MARCUS
SEROUT PORTB.2,2,["ERROR",10,13]

IF MARCUS.0=TRUE THEN
HIGH PORTB.3
ELSE
LOW PORTB.3
ENDIF
IF MARCUS.1=TRUE THEN
HIGH PORTB.4
ELSE
LOW PORTB.4
ENDIF
IF MARCUS.2=TRUE THEN
HIGH PORTB.5
ELSE
LOW PORTB.5
ENDIF
IF MARCUS.3=TRUE THEN
HIGH PORTB.6
ELSE
LOW PORTB.6
ENDIF





GOTO START


Disable 'No interrupts past this point
myint:

PORTB.3 = FALSE
PORTB.4 = TRUE
PORTB.5 = TRUE
PORTB.6 = TRUE
pause 500

INTCON.1 = 0 ' Clear interrupt flag
Resume ' Return to main program
Enable
 
Last edited:

bertus

Joined Apr 5, 2008
22,948
Hello,

The picture is not visible as it is a local file on your own computer.
You can upload the picture using the manage attachments button.

Greetings,
Bertus
 

Thread Starter

electronic_noob

Joined Jan 15, 2010
42
Hello,

The picture is not visible as it is a local file on your own computer.
You can upload the picture using the manage attachments button.

Greetings,
Bertus
I do not intend to include any image, it's just a mistake...I'm sure with my connections in the circuit all want is the interrupt thing, I cant seem to use interrupt when I use serin. MY pic is 16f628A...Rb0 is interrupt all connection is fine but the program I want to modify to suit what I have posted previously

thanks a lot in advance
 

Markd77

Joined Sep 7, 2009
2,806
I don't understand BASIC so I might be very wrong, but here goes:
You use goto myint - should this be call?
At the end there is resume, then enable. Should it be the other way round?
 

Thread Starter

electronic_noob

Joined Jan 15, 2010
42
I don't understand BASIC so I might be very wrong, but here goes:
You use goto myint - should this be call?
At the end there is resume, then enable. Should it be the other way round?

ah yes I think, I just want to ask if its possible that the interrupt function is disabled because Im using SERIN command, because I tried the interrupt on a simple function and it does work but as I added some code specifically the serin the interruot seems to fail to function, the interrupt is on RB0 and to enable it I connect it to the ground. Am I missing something?
 

Thread Starter

electronic_noob

Joined Jan 15, 2010
42
Your interrupt call doesn't work simply because your program is always listening at your serin command and stay there till some data is received.

To avoid that and give a window to the interrupt to be executed, just change your code in this way:
Rich (BB code):
your code
SERIN PORTB.1,2,["U"],B0
SEROUT PORTB.2,2,["ERROR",10,13]
 
'modified code
Label01:
SERIN PORTB.1,2,100,Label01,["U"],B0
SEROUT PORTB.2,2,["ERROR",10,13]
serin will be serviced for 100 millisecs and then jumps to label to repeat, giving a chance to the interrupt to be executed.

You can have your pin RB0 serviced even better polling it in this way:
Rich (BB code):
Label01:
if PorB.0 = False then gosub your label
SERIN PORTB.1,2,100,Label01,["U"],B0
SEROUT PORTB.2,2,["ERROR",10,13]
Alberto


its working but..., I cant seem to have that fast response in multiple inputs...but it does work
 
Last edited:
Top