When i was running my programme in a for loop, it can loop 3 time and in fourth times, it shows Unhandled int code, what should i do ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

When i was running my programme in a for loop, it can loop 3 time and in fourth times, it shows Unhandled int code, what should i do ?

1,009 Views
lammanhuen926
Contributor I

Here is my code, the colours are just making LED flash in different colour and FAIL is pink light

/* ###################################################################
**     Filename    : main.c
**     Project     : Assginment 1
**     Processor   : MKL25Z128VLK4
**     Version     : Driver 01.01
**     Compiler    : GNU C Compiler
**     Date/Time   : 2018-11-08, 10:09, # CodeGen: 0
**     Abstract    :
**         Main module.
**         This module contains user's application code.
**     Settings    :
**     Contents    :
**         No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.01
** @brief
**         Main module.
**         This module contains user's application code.
*/        
/*!
**  @addtogroup main_module main module documentation
**  @{
*/        
/* MODULE main */

/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "RED_LED.h"
#include "TU1.h"
#include "GREEN_LED.h"
#include "BLUE_LED.h"
#include "TU2.h"
#include "TSS1.h"
#include "AD1.h"
#include "AdcLdd1.h"
#include "stdlib.h"
/* Including shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
/* User includes (#include below this line is not maintained by Processor Expert) */
int ispressed=0;
static uint16_t Random;
/*lint -save  -e970 Disable MISRA rule (6.3) checking. */

int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */
unsigned char i=0,k,y,p,l,j;
unsigned char Arraycolour[30],Gamecolour[30],Inputcolour[30];
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/
  /* Write your code here */
for (;;){                  /*For loop just for looping the game */
 ALLOFF();
 k=0,y=0,p=5,l=0,j=0;
 ispressed=0;
   AD1_Measure(TRUE);               /* do measurment and wait for the result */
   AD1_GetValue16(&Random);              /* get the result into Random variable */
 srand(Random);
 TSS_Task();
 while(ispressed <2){
  TSS_Task();}

 if(TSS1_cKey0.Position >= 0 && TSS1_cKey0.Position<=64){      /*game start when user touch slider*/
    yellow();                 /*signal for game start*/
   }
 for (y=0;y<p+i;y++){              /*For loop to create random light and store
                                        light signal in to Array*/
        k=rand()%9;
        if(k<=2)
        {BLUELED();
        Arraycolour[j]=1;
        Gamecolour[j]=1;
       Inputcolour[j]=1;}
        else if(k>=3 && k<6)
        {REDLED();
        Arraycolour[j]=2;
        Gamecolour[j]=2;
       Inputcolour[j]=2;}
        else if(k>=6)
        {GREENLED();
        Arraycolour[j]=3;
        Gamecolour[j]=3;
       Inputcolour[j]=3;
        }
       j++;}
   /* y=0;
        for (y=0;y=p;y++){
         if(Arraycolour[y]=1)
                  {BLUELED();}
              else if(Arraycolour[y]=2 )
                  {REDLED();}
              else if(Arraycolour[y]=3)
                 {GREENLED();}}*/
  ALLOFF();
                    /* light signal shows repeat colour with a missing one */
    l=rand()%(p+i);                /* y will random value according to number of round
                         (Round 1 is 0-4, round 2 is 0-5), it will decide
                         where to start to get the light out from array*/
    if (l>=p-i){                /* if loop just prevent the random going too large, think
                         of in loop 3, there are 7 colours, if l==5  while we have
                          to pick up random numbers start from Arraycolour[5], it can
                          only pick up two and 7 is nothing in Arraycolour[7], so by
                          comparing l value is not grater than y-i, it will minus i
                          to get the random l in range of array to pick colours out  */
     l=l-i;
    }
    for (y=0;y<1+i;y++){              /* Make colour missing in an array */
     Gamecolour[l]=0;
     l++;}
    l-=y;                  /* Make l back to origion place for use in array later */
    for (y=0;y<5+i;y++){              /* Displaying missing colour */
     if (Gamecolour[y]==0)
  {white();}
     else if(Gamecolour[y]==1)
     {BLUELED();}
     else if(Gamecolour[y]==2 )
     {REDLED();}
     else if(Gamecolour[y]==3)
     {GREENLED();}}
    for (y=0;y<1+i;y++){
     TSS_Task();
 ispressed=0;
 while(ispressed <2){
  TSS_Task();}            /* Get user input */
wait(250);
     if( TSS1_cKey0.Position >= 0 && TSS1_cKey0.Position<18){
      Gamecolour[l]=2;}
  else if( TSS1_cKey0.Position >= 19 && TSS1_cKey0.Position<48){
   Gamecolour[l]=3;}
  else if( TSS1_cKey0.Position >= 48 && TSS1_cKey0.Position<=64){
   Gamecolour[l]=1;}
      l++;}
    for (y=0;y<5+i;y++){              /* If user input is match Gamecolour, An Array will
                                             store it as 1, if not store it as 0*/
     if(Inputcolour[y]==Gamecolour[y]){
  Arraycolour[y]=1;}
     else {Arraycolour[y]=0;}}
     j=0;
  for (y=0;y<5+i;y++){              /* Adding up values in an array, to determinate final
                                          value of j*/
   j+=Arraycolour[y];}
   if (j==5+i){               /* Check value of j if it match the correct answer */
   i++;
   SKYBLUE();}                /*Light showing all correct and go to next level  */
   else {i=0;
   FAIL();}                /* Light showing wrong input and restart game */
 }
  /* For example: for(;;) { } */
  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
**     This file was created by Processor Expert 10.5 [05.21]
**     for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/
Tags (1)
0 Kudos
1 Reply

652 Views
HerbertCunningham
Contributor I
I am also facing the same problem, what is the solution to this problem download mod apkrabi
0 Kudos