I have a strange "bug" in my PBP program that I canīt understand.
I have taken out the code that contains the bug from my bigger program and run it on two different PICīs on two different devboards and the bug is still there so it must have something with the software to do.
The code lets you to select number of shooters (1-5), if Shooters = 2 the Status_LED will blink 2 times and then delay for a longer time before the next two blink.
You change the Shooters value by pressing SW_Forward or SW_Reverse, SW_Launch will start the rest of the program (not included) with the number of shooters stored in the variable Shooters.
The code works pretty well until yesterday when I tried to press the SW_Forward button for about 10 - 15 times as fast that I could then the program hangs and the Status_LED is constantly on, it looks like the program goes into a never ending loop and I must Reset the PIC to continue. the same thing will happen if I press SW_Reverse as fast I can.
Well the program works, but I want to know why the program hangs when I press the SW_Forward or SW_Reverse buttons several times fast
Code:
<html>
<head></head>
<body><!--StartFragment--><pre><code><font color="#008000"><b>Define </b></font>OSC <font color="#000080"><b>8
</b></font><font color="#008000"><b>Include </b></font><font color="#FF0000">"alldigital.pbp" </font><font color="#000080"><i>;DT´s All Digital
</i></font><font color="#008000"><b>Define </b></font>SHOWDIGITAL <font color="#000080"><b>1
</b></font><font color="#008000"><b>Asm </b></font><font color="#000080"><i>;===========================================================================
</i></font><font color="#008000">__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HS_1H
__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L & 0DFh
<b>Endasm</b></font><font color="#000080"><i>;-------------------------------------------------------------------------
</i></font>Shooters <font color="#008000"><b>Var Byte
</b></font>i <font color="#008000"><b>Var Byte
</b></font>Delayi <font color="#008000"><b>Var Byte
</b></font>SW_Launch <font color="#008000"><b>Var </b></font>PORTA.<font color="#000080"><b>0</b><i>;=======================================================
</i></font>SW_Reverse <font color="#008000"><b>Var </b></font>PORTA.<font color="#000080"><b>1
</b></font>SW_Forward <font color="#008000"><b>Var </b></font>PORTA.<font color="#000080"><b>2
</b></font>Status_LED <font color="#008000"><b>Var </b></font>PORTC.<font color="#000080"><b>0</b><i>;-------------------------------------------------------
</i></font>Shooters = <font color="#000080"><b>2 </b><i>;Default value
</i></font>Main:<font color="#000080"><i>;==========================================================================
</i></font><font color="#008000"><b>Gosub </b></font>Delay2
<font color="#008000"><b>For </b></font>i = <font color="#000080"><b>1 </b></font><font color="#008000"><b>To </b></font>Shooters
<font color="#008000"><b>High </b></font>Status_LED
<font color="#008000"><b>Gosub </b></font>Delay1
<font color="#008000"><b>Low </b></font>Status_LED
<font color="#008000"><b>Gosub </b></font>Delay1
<font color="#008000"><b>Next </b></font>i
<font color="#008000"><b>Goto </b></font>Main<font color="#000080"><i>;----------------------------------------------------------------------
</i></font>Delay1:<font color="#000080"><i>;========================================================================
</i></font><font color="#008000"><b>For </b></font>Delayi = <font color="#000080"><b>0 </b></font><font color="#008000"><b>To </b></font><font color="#000080"><b>100
</b></font><font color="#008000"><b>Pause </b></font><font color="#000080"><b>2
</b></font><font color="#008000"><b>Gosub </b></font>Check_Buttons
<font color="#008000"><b>Next </b></font>Delayi
<font color="#008000"><b>Return
</b></font>Delay2:
<font color="#008000"><b>For </b></font>Delayi = <font color="#000080"><b>0 </b></font><font color="#008000"><b>To </b></font><font color="#000080"><b>255
</b></font><font color="#008000"><b>Pause </b></font><font color="#000080"><b>5
</b></font><font color="#008000"><b>Gosub </b></font>Check_Buttons
<font color="#008000"><b>Next </b></font>Delayi
<font color="#008000"><b>Return</b></font><font color="#000080"><i>;-------------------------------------------------------------------------
</i></font>Check_Buttons:<font color="#000080"><i>;=================================================================
</i></font><font color="#008000"><b>If </b></font>SW_Launch = <font color="#000080"><b>0 </b></font><font color="#008000"><b>Then
High </b></font>Status_LED
<font color="#008000"><b>Pause </b></font><font color="#000080"><b>50
</b></font><font color="#008000"><b>While </b></font>SW_Launch = <font color="#000080"><b>0</b></font>: <font color="#008000"><b>Wend
Pause </b></font><font color="#000080"><b>50
</b><i>' goto start_new
</i></font><font color="#008000"><b>Endif
If </b></font>SW_Forward = <font color="#000080"><b>0 </b></font><font color="#008000"><b>Then
High </b></font>Status_LED
<font color="#008000"><b>Pause </b></font><font color="#000080"><b>50
</b></font>Shooters = Shooters + <font color="#000080"><b>1
</b></font><font color="#008000"><b>If </b></font>Shooters > <font color="#000080"><b>5 </b></font><font color="#008000"><b>Then </b></font>Shooters = <font color="#000080"><b>1
</b></font><font color="#008000"><b>While </b></font>SW_Forward = <font color="#000080"><b>0</b></font>:<font color="#008000"><b>Wend
Pause </b></font><font color="#000080"><b>50
</b></font><font color="#008000"><b>Low </b></font>Status_LED
<font color="#008000"><b>Goto </b></font>Main
<font color="#008000"><b>Endif
If </b></font>SW_Reverse = <font color="#000080"><b>0 </b></font><font color="#008000"><b>Then
High </b></font>Status_LED
<font color="#008000"><b>Pause </b></font><font color="#000080"><b>50
</b></font>Shooters = Shooters - <font color="#000080"><b>1
</b></font><font color="#008000"><b>If </b></font>Shooters < <font color="#000080"><b>1 </b></font><font color="#008000"><b>Then </b></font>Shooters = <font color="#000080"><b>5
</b></font><font color="#008000"><b>While </b></font>SW_Reverse = <font color="#000080"><b>0</b></font>:<font color="#008000"><b>Wend
Pause </b></font><font color="#000080"><b>50
</b></font><font color="#008000"><b>Low </b></font>Status_LED
<font color="#008000"><b>Goto </b></font>Main
<font color="#008000"><b>Endif
Return</b></font><font color="#000080"><i>;-------------------------------------------------------------------------
</i></font></code></pre><!--EndFragment--></body>
</html>
Bookmarks