Look in the Help file within the GCBasic folder, and you will find Interrupts under the Command Reference heading. Hopefully your device has a hardware Usart, so you could use the Usart interrupts that are available.
On UsartRX1Ready Call xyzsub 'data has been received
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
By customizing or making your own interrupt service routine. Put a flag in the ISR, and instead of saving PCL just have it return to ORG X0000, check for the flag there, if true then clear the flag, jump or goto where you want to be in your main program. This is hypothetical speaking, as I have not found a reason to do this, or tried to implement it.
If starting at beginning of main is O.K., then try a hard reset of MCLR from the ISR?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
so I put in this:
#config MCLRE=off, WDT=off, bod=off',INTRC_OSC_NOCLKOUT
#define USART_BLOCKING
#define SerInPort PORTc.5
#define USART_BAUD_RATE 2400 'the speed you want
InitUsart
On Interrupt UsartRX1Ready call getdata 'info
if leave = 1 then temp = 0
leave = 0
if temp = 67 then colors
if porta.0 off then proc
if porta.1 off then prod
if porta.2 off then proe
if portc.4 off then proa
if portc.3 off then prob
if porta.3 off then prof
pwmout 1, pv0, 1
pwmout 2, pv1, 1
pwmout 3, pv2, 1
goto main
sub getdata
leave=1
hserreceive temp
if temp = 67 then colors
if sloc=1 then buttonmem
if sloc=0 then
blah blah blah
end sub
sub colors
leave = 0
LoopCounter = 0
For LoopCounter = 1 to 255
if leave = 1 then exit sub
pvalue = loopcounter/2
pv1 = 128 - pvalue
pv2 = 128 - pv1
repeat 4
pwmout 1, pvalue, 1
pwmout 2, pvalue, 1
pwmout 3, pv1, 1
end repeat
Next
But it is like it ignores the varible "leave" check and waits until it finishes the loop routine then exits the sub if the leave varible is set?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Didn't realize the Sub colors was in the interrupt routine. You have to be very careful when calling a sub inside an interrupt. It would really be best to handle it outside the interrupt at the top of main. Don't clear leave at top of sub, put it in the conditional checking if the flag is true like:
if leave = 1 then
leave = 0
exit sub
end if
It appears you expect an interrupt to happen inside an interrupt, not gonna happen because once inside they are disabled.
As for your state machine stuff (i.e. checking buttons and so forth) keep that at the top of main too, and out of the interrupt. If you have an 18f device, you could play with priority interrupts, haven't done that personally either. This is mostly just house keeping stuff.
Not actually seeing label Main: in your code, must be somewhere, otherwise you would get compiler errors.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
How can I get out of this sub immediatly by sending a serial character?
sub color
LoopCounter = 0
For LoopCounter = 1 to 255
pvalue = loopcounter/2
pv1 = 128 - pvalue
pv2 = 128 - pv1
repeat 4
pwmout 1, pvalue, 1
pwmout 2, pvalue, 1
pwmout 3, pv1, 1
end repeat
Next
end sub
Look in the Help file within the GCBasic folder, and you will find Interrupts under the Command Reference heading. Hopefully your device has a hardware Usart, so you could use the Usart interrupts that are available.
i have that, but how do i "exit" the color sub and return to the main?
By customizing or making your own interrupt service routine. Put a flag in the ISR, and instead of saving PCL just have it return to ORG X0000, check for the flag there, if true then clear the flag, jump or goto where you want to be in your main program. This is hypothetical speaking, as I have not found a reason to do this, or tried to implement it.
If starting at beginning of main is O.K., then try a hard reset of MCLR from the ISR?
so I put in this:
#config MCLRE=off, WDT=off, bod=off',INTRC_OSC_NOCLKOUT
#define USART_BLOCKING
#define SerInPort PORTc.5
#define USART_BAUD_RATE 2400 'the speed you want
InitUsart
On Interrupt UsartRX1Ready call getdata 'info
if leave = 1 then temp = 0
leave = 0
if temp = 67 then colors
if porta.0 off then proc
if porta.1 off then prod
if porta.2 off then proe
if portc.4 off then proa
if portc.3 off then prob
if porta.3 off then prof
pwmout 1, pv0, 1
pwmout 2, pv1, 1
pwmout 3, pv2, 1
goto main
sub getdata
leave=1
hserreceive temp
if temp = 67 then colors
if sloc=1 then buttonmem
if sloc=0 then
blah blah blah
end sub
sub colors
leave = 0
LoopCounter = 0
For LoopCounter = 1 to 255
if leave = 1 then exit sub
pvalue = loopcounter/2
pv1 = 128 - pvalue
pv2 = 128 - pv1
repeat 4
pwmout 1, pvalue, 1
pwmout 2, pvalue, 1
pwmout 3, pv1, 1
end repeat
Next
But it is like it ignores the varible "leave" check and waits until it finishes the loop routine then exits the sub if the leave varible is set?
Didn't realize the Sub colors was in the interrupt routine. You have to be very careful when calling a sub inside an interrupt. It would really be best to handle it outside the interrupt at the top of main. Don't clear leave at top of sub, put it in the conditional checking if the flag is true like:
It appears you expect an interrupt to happen inside an interrupt, not gonna happen because once inside they are disabled.
As for your state machine stuff (i.e. checking buttons and so forth) keep that at the top of main too, and out of the interrupt. If you have an 18f device, you could play with priority interrupts, haven't done that personally either. This is mostly just house keeping stuff.
Not actually seeing label Main: in your code, must be somewhere, otherwise you would get compiler errors.
Thanks, that was the problem i forgot/ didn't notice colors was part of the interrupt and disabled them