/*****************************************************************************************************                                                                        
*   Function: SchM_Start
*
*   Description: Starts the scheduler
*
*   Caveats:
*****************************************************************************************************/
void SchM_Start(void)
{
    u16 index_a; 
    u16 index_b;
    u16 index_ControlBlock;
    /*Start the timer for the OS tick*/
    Gpt_StartTimer(CHANNEL_0, 500u);
    //Gpt_StartTimer(CHANNEL_1, 20000u);
    //Gpt_StartTimer(CHANNEL_2, 40020u);
    /*Enable notification*/
    Gpt_EnableNotification(CHANNEL_0);
    Gpt_EnableNotification(CHANNEL_1);
    Gpt_EnableNotification(CHANNEL_2);
    
    /* Initialize Dispacher Array Vector */
    for(index_a=0U;index_a < MAX_PRIORITY;index_a++)
    {
      for(index_b=0U;index_b < CNF_MAXTASKQUEUE;index_b++)
      {
         DispacherArray[index_a][index_b] = 0xFFFF;            
      }
    }
    
    BackgroundControlBlock.BackgroundContextSave.CCR_TaskContext_u16   = 0U;
    BackgroundControlBlock.BackgroundContextSave.D_TaskContext_u16     = 0U;
    BackgroundControlBlock.BackgroundContextSave.X_TaskContext_u16     = 0U;
    BackgroundControlBlock.BackgroundContextSave.Y_TaskContext_u16     = 0U;
    BackgroundControlBlock.BackgroundContextSave.PC_TaskContext_u16    = 0U;
    BackgroundControlBlock.BackgroundContextSave.PPAGE_TaskContext_u16 = 0U;
    BackgroundControlBlock.BackgroundContextSave.SP_TaskContext_u16    = 0U;
    BackgroundControlBlock.BackgroundInterrupted                       = TASK_NOPREEMPTED;

    TaskControlBlock = ((Task_Control_Block *__far)Mem_Alloc((MAX_NUM_TASK*sizeof(Task_Control_Block))));
    for(index_ControlBlock=0U;index_ControlBlock < MAX_NUM_TASK;index_ControlBlock++)
    {
      TaskControlBlock[index_ControlBlock].Task_ID                                  = TaskConfigInitial->ptr_Task[index_ControlBlock].Task_ID;
      TaskControlBlock[index_ControlBlock].Task_Priority                            = TaskConfigInitial->ptr_Task[index_ControlBlock].Task_Priority;
      TaskControlBlock[index_ControlBlock].Task_State                               = SUSPENDED;
      TaskControlBlock[index_ControlBlock].Stack_Information.StartAddress           = 0U;
      TaskControlBlock[index_ControlBlock].Stack_Information.EndAddress             = 0U;
      TaskControlBlock[index_ControlBlock].Task_Deadline.Relative                   = 0U;
      TaskControlBlock[index_ControlBlock].Task_Deadline.Absolute                   = 0U;
      TaskControlBlock[index_ControlBlock].Task_ContextSave.CCR_TaskContext_u16     = 0U;
      TaskControlBlock[index_ControlBlock].Task_ContextSave.D_TaskContext_u16       = 0U;
      TaskControlBlock[index_ControlBlock].Task_ContextSave.X_TaskContext_u16       = 0U;
      TaskControlBlock[index_ControlBlock].Task_ContextSave.Y_TaskContext_u16       = 0U;
      TaskControlBlock[index_ControlBlock].Task_ContextSave.PC_TaskContext_u16      = 0U;
      TaskControlBlock[index_ControlBlock].Task_ContextSave.PPAGE_TaskContext_u16   = 0U;
      TaskControlBlock[index_ControlBlock].Task_ContextSave.SP_TaskContext_u16      = 0U;
      TaskControlBlock[index_ControlBlock].Task_Interrupted                         = TASK_NOPREEMPTED;
      TaskControlBlock[index_ControlBlock].Task_Mode                                = PERIODIC;
    }
    
    while(1)
    {
      SchM_Background();
      _FEED_COP();
    }

}
/*****************************************************************************************************                                                                        
*   Function: main()
*
*   Description: what I can say about it, it just the tipical main
*
*   Caveats:
*****************************************************************************************************/
void main(void) 
{
  /*Disable interrupts to start the MCU configuration*/  
  DisableInterrupts;
  /* Intilialize the interupt vector base address for default location */
  Init_Interrupt_Vector();
    
  Mcu_Init();
  DDRA =0x0F;
  DDRB =0x0F;
  
  EnableInterrupts;
  
  SchM_Init(SchM_TaskConfigInitial);
  SchM_Start();
  
  for(;;) 
  {
    /* Call the scheduler */
    SchM_Background();
    /* feeds the dog */
    _FEED_COP(); 
  } 
  /* loop forever */
  /* please make sure that you never leave main */
}
Example #3
0
/***********************************************************************
Main
***********************************************************************/
void main(void) {
  DisableInterrupts;
	initializations(); 		  			 		  		
	EnableInterrupts;

//////////////////////////////////////////////////////////////
//;  START OF CODE FOR Spring 2012 MINI-PROJECT
//////////////////////////////////////////////////////////////
  //asm ldx //...

  while(1){
  	
  	
  	
  }
  
  
  

  for(;;) {
   // No need to write any code here
    
    _FEED_COP(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
}
Example #4
0
void main(void)
{
	int temp;
	
	EnableInterrupts;
	
	DDRB = 0xFF;
	
	dostuff_init();
	
	for(;;)
	{
		//temp = testfcn(1, 3, 32);
		temp = testfcn(1);
		//temp = dostuff(3, 4);
		if(temp > 3)
		{
			PORTB = temp;
		}
	}
	
	for(;;) 
	{
    	_FEED_COP(); /* feeds the dog */
    } /* loop forever */
}
Example #5
0
/***********************************************************************
Main
***********************************************************************/
void main(void) {
  DisableInterrupts;
	initializations(); 		  			 		  		
	EnableInterrupts;
	
	//enables external xirq after vSync IRQ
	vSyncFlag = 0;
	while((vSyncFlag != 1) & (hCnt == 0)) {}	      
  asm andcc #$BF 

//////////////////////////////////////////////////////////////
//;  START OF CODE FOR Spring 2012 MINI-PROJECT
//////////////////////////////////////////////////////////////
  
	// Load/Display Spalsh Screen
	displaySplash();

  for(;;) {
   // write code here (Insert Code down here because we need an infinite loop.)

	// Display Menu Screen
	displayMenu(selection);
	// Check for Menu Selection
	checkMenuInputs(joy0vert);
	// Use case statement to branch to appropriate selection.
	// Don't branch unless the user has triggered the 'select' button.
	if (select == 1)
	{
			select = 0;
			switch (selection)
			{
			// Sub Function
			// Menu:
			case 1:
					//	Select Character
					selectCharacter();
					break;
			case 2:
					//	Select Field
					selectField();
					break;
			case 3:
					//	Start Match
					startMatch();
					break;
			// the default case is '-1' if nothing has been selected
			default:
					break;
			}
	}
    
	 // We don't need the watchdog timer, but I don't think it can hurt to feed it anyway.
	 // The watchdog was disabled in the initialization code.
    _FEED_COP(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
}
Example #6
0
void main(void) {
  /* put your own code here */
  /*$XGATECall$*/
	EnableInterrupts;
/*$AsmCall$*/

  for(;;) {
    _FEED_COP(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
}
Example #7
0
File: main.c Project: bencon/1-wire
void DelayUs(uint16_t us){
	volatile uint16_t i;  // Needs volatile so compiler does not optimize
	while (us > 0){
		i = DELAY_1US;
    _FEED_COP();
		while (i > 0) {
			i = i - 1;
		}
		us = us - 1;
	}
}
Example #8
0
File: main.c Project: bencon/1-wire
void DelayMs(uint16_t ms){
	volatile uint16_t i;  // Needs volatile so compiler does not optimize
	while (ms > 0){
		i = DELAY_1MS;
		_FEED_COP();  //important
		while (i > 0) {
			i = i - 1;
		}
		ms = ms - 1;
	}
}
void main(void) {
    /* put your own code here */
    unsigned int res = 8;

    float butter_feedback[] = {-1.7786f, 0.8008f};                        // float butterworth A scalars
    float butter_feedforward[] = {0.0055427, 0.011085, 0.0055427};        // float butterworth B scalars

    long butter_feedbackF[] = {-116562, 52481};                          // scaling factor Q16.16
    long butter_feedforwardF[] = {363, 726, 363};                        // scaling factor Q16.16


    SYNR = 2;                 // 24mHz clock
    REFDV = 0;
    while (!(CRGFLG&0x08)) {};
    CLKSEL |= 0x80;

    RTICTL = 0b01110101;     // every 50ms
    CRGINT = 0b10000000;

    TSCR1 = 0x80;            // set up MT
    TSCR2 = 0x82;

    atd0_powerOn();              // Powers on ATD module 0
    atd0_setFFC(1);              // set fast flag clearing on/off
    atd0_setLength(1);           // sets conversion sequence length of ATD module 0
    atd0_setFifo(0);             // turns FIFO mode on or off (1/0)
    atd0_setResolution(res);     // sets ATD module 0 resolution to 8/10bit
    atd0_setJustification('r');  // 'L' for left, 'R for right
    atd0_setScan(1);             // sets ATD Module 0 SCAN bit on/off (1/0)
    atd0_setMulti(0);            // sets ATD Module 0 MULT bit on/off (1/0)
    atd0_setStart(2);            // sets starting ch

    butterworth_2pole_initF(&butterF, butter_feedbackF, butter_feedforwardF);
    butterworth_2pole_init(&butter, butter_feedback, butter_feedforward);

    EnableInterrupts;

    lcd_setup();     // set up the LCD to write

    for(;;) {

        if(distance1 > FAR)
        {
            motor_stepForward(1,1,600);
        }

        //val = atd0_readChX(0);
        //sliding_window_50_put(&slide, val);
        //butterworth_2pole_put(&butter, val);
        _FEED_COP(); /* feeds the dog */
    } /* loop forever */
    /* please make sure that you never leave main */
}
Example #10
0
/**
* \brief    Scheduler Background task
* \author   Gerardo Valdovinos
* \param    void
* \return   void     
*/
void SchM_Background(void)
{
    /* Loop forever */
    for(;;) 
    {
        //PORTA_PA4 = 1;
        
        /* Call Dispatcher */
        SchM_Dispatcher();
         
        _FEED_COP();    /* feeds the dog */
    }                   /* loop forever */    
}
Example #11
0
void main(void) {
  /* put your own code here */
  

  //function declarations
	void InitSCI(void);
	void InitPorts(void);


  for(;;) {
    _FEED_COP(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
}
void main(void) {
  /* put your own code here */
  unsigned int res = 10;
  unsigned int i, j, val;

    
  SYNR = 2;                    // 24mHz clock
  REFDV = 0;
  while (!(CRGFLG&0x08)){};
  CLKSEL |= 0x80;
  
  RTICTL = 0b01110101;         // rti every 50ms
  CRGINT = 0b10000000;

  atd0_powerOn();              // Powers on ATD module 0
  atd0_setFFC(1);              // set fast flag clearing on/off
  atd0_setLength(1);           // sets conversion sequence length of ATD module 0
  atd0_setFifo(0);             // turns FIFO mode on or off (1/0)
  atd0_setResolution(res);     // sets ATD module 0 resolution to 8/10bit
  atd0_setJustification('r');  // 'L' for left, 'R for right
  atd0_setScan(1);             // sets ATD Module 0 SCAN bit on/off (1/0)
  atd0_setMulti(0);            // sets ATD Module 0 MULT bit on/off (1/0)
  atd0_setStart(2);            // sets starting ch
  
	EnableInterrupts;
	
  lcd_setup();                 // sets up LCD to write
  	
	
  while(1)
  {   
    if(i > 7)
      i = 0; 
    if(j > 49)
      j = 0;
    
    val = atd0_readChX(0);      // reads the IR sensors atd channel
    distances8[i] = val;        // store value in 8 element array
    distances50[j] = val;	      // store value in 50 element array
    i++;
    j++;   
  }
	

  for(;;) {
    _FEED_COP(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
}
Example #13
0
File: main.c Project: bencon/1-wire
//main for i2c  
void main(void){
   i2cInit();
   initI2cStruct(&DAC);
   initI2cStruct(&LED_Driver);
   previous = &DAC;
   DelayMs(1);
   EnableInterrupts;
   for(;;) {
     _FEED_COP(); // feeds the dog 
     i2cProcess();  
     //IIC0_IBCR = 0xF0;
		 //IIC0_IBDR = 0xF0;
     DelayMs(1);
   } 
   
}
Example #14
0
void main(void) {

    byte patterns[]= {0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF,0x7F,0x1F,0x0F,0x07,0x03,0x01,0x00};
    int i;
    byte scan_code;
    DDRA = 0xFF;
    PERT = 0x0F; //pull up resistor?
    PORTA = 0xff;
    DDRP = 0x0f; //pull up resistor?




    //use the folowing to calibrate the delay functions
    //PORTA=0xFF;
    //delay2(10000);
    //PORTA=0x00;

    while(1)
    {
        for(i=0; i<SL; i++)
        {
            PORTA=patterns[i];
            delay(delayTime);

            readButtons();


            scan_code = getkey ();
            if (scan_code != 0xff) //if keyboard press
                block_LEDS(scan_code);

        }//end for
    }//end while



    EnableInterrupts;


    for(;;) {
        _FEED_COP(); /* feeds the dog */
    } /* loop forever */
    /* please make sure that you never leave main */
}
Example #15
0
void main(void) {
  DisableInterrupts;
	initializations(); 		  			 		  		
	EnableInterrupts;
  
  turnOffLEDs();
  // reset game on startup
  resetGame();
  
  TC7 = 15000;            //set up TIM TC7 to generate 0.1 ms interrupt rate
  for(;;) {
    displayBoard();
    
    
    if (interuptFlag) {
       tickCounter++;
       ticksSinceLastEvolution++;  	
  
       if (ticksSinceLastEvolution >= TICKS_BETWEEN_EVOLUTIONS) {
         ticksSinceLastEvolution = 0;
         evolveFlag = 1;
       }  
    }
    
    if (evolveFlag) {
      evolveFlag = 0;
      evolve();
    }
    
    if (boardsAreSame == 1) {
      resetGame();
    }
  
    // check to see if the user would like to reset the game (presses right push button)
    if (rghtpb == 1) {
      rghtpb = 0;
      resetGame();
    }
    
  
    _FEED_COP(); /* feeds the watchdog timer */
  } /* loop forever */
  /* make sure that you never leave main */
}
Example #16
0
/*-- Main Code ----------------------------------------------------------------*/
void main(void)
{
/* Global Sleep Mode enable flag */
UINT8 gu8SleepModeEnabled;

    /* Initialize auxiliary variables */
    gu8Index = 0;                   
    gu8SleepModeEnabled = 0;
    
    /* Prior Initialization, disable interrupts */
    DISABLE_INTERRUPTS();           
    
    /* Initial configuration for ECU hardware resources */
    vfnECU_Init();
    
    /* Initialization of resources for user's, data and engine management */       
    User_Management_Init();    
    Data_Management_Init();
    Engine_Management_Init(); 
    
    /* Start execution of task scheduler */
    vfnScheduler_Start(); 
    
// Only while debugging
//    _DISABLE_COP();
              
    /* Initialization complete, enable interrupts */
    ENABLE_INTERRUPTS();            
      
    /*-- While Power-savings mode is NOT requested --*/
    while (gu8SleepModeEnabled == 0)
    {
// Only while debugging - need to find the right place for this. Maybe in the 1ms task?
        _FEED_COP(); /* feeds the dog */

        /* Execute Multi-thread round robin task scheduler */
        vfnTask_Scheduler();
    }
    
    /* If we ever reach this then we have a problem */
    while(1);
}
Example #17
0
/*****************************************************************************************************                                                                        
*   Function: SchM_OsTick
*
*   Description: Callback handled once an interrupt is generated by Channel 0.
*
*   Caveats: Non Reentrant
*****************************************************************************************************/
void SchM_OsTick(void)
{
  u8 Task_Index = 0;
  Status_Type StatusErrorResult = E_OK;

    _FEED_COP();
    //SchM_OSTickEnabled = SCHM_OSTICK_ENABLED;
    for(Task_Index=0;Task_Index < TaskConfigInitial[0U].TaskNumberConfig;Task_Index++)
    {
       if((SchM_OSTickCounter & TaskConfigInitial->ptr_Task[Task_Index].Mask) == 
           TaskConfigInitial->ptr_Task[Task_Index].Offset)
       {
         StatusErrorResult = ActivateTask(((TaskType)TaskConfigInitial->ptr_Task[Task_Index].Task_ID));
       }
    }
   
  SchM_OSTickCounter ++;
  

}
Example #18
0
File: demo.c Project: cbrem/ourtos
void watchdogKickTask(void) {

    SET_LEDS(LED_WATCHDOG_KICK);

    if ( WATCHDOG_FLG_ALL_SET == _watchdogFlags ) {
        _FEED_COP();

        /* watchdog clear must be atomic so that tasks setting flags
         * are not intermingled with clearing the flags.
         */
        DisableInterrupts;
        CLEAR_WATCHDOG_FLGS();
        EnableInterrupts;

    } else {
        /* not all of the watchdog flags are set
         * so watchdog cannot be kicked yet
         */
    }
}
Example #19
0
void main(void) {
  /* put your own code here */
  	EnableInterrupts;
    
  	DDR1AD0 =	DDRT	= 0xFF;	
	PT1AD0	= 	PTT		= 0x00;
	
	set_baud_rate(9600);
		 
	send();	
	fct_set(8,2,58);
	disp_on(1,1,1);
	entry_mode(1,0);	
	clear_disp();

	char  val,buf[16] ;
	
#define go 5000
	while(1)
	{
		memset(buf,0,16);
		for(int v=0,i =0; i<16 ; i++)
		{   v=0;
			while(	chk_rx() >= 0	? 0:
					i==0 			? 1:
					v++ < go		? 1:
					0);
			if (v >= go){	break;	}
			buf[i]=fetch_char();				
		}
		return_home();
		clear_disp();
		prt_str(buf);	
	}
	 
  for(;;) {
    _FEED_COP(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
}
void main(void) {
  
  UINT8 input_validity;
  UINT8 userInput1,userInput2,userInput3;
  UINT8 flag1, flag2;
  
  struct Stepper stepper1,stepper2;
  
	// set up serial port communication
  InitializeSerialPort();

  
  InitializePWM(); 
	
	//Intialize timer
	InitializeTimer();
	
	// allocate and fill receipe array
	InitializeRecipe();
	
	IntializeLED();
	
	set_stepper(&stepper1,PWM_CHANNEL_STEPPER1,STEPPER1_RECIPE);
	set_stepper(&stepper2,PWM_CHANNEL_STEPPER2,STEPPER2_RECIPE);
  
  if(1 == POST())
  {
    printf("POST failed\r\n");
    for(;;) 
    {
    }
    
  } 
  else 
  {
    printf("POST successful\r\n");  
  
    (void)printf(">");
    for(;;) {
      _FEED_COP();
   
      //check serial port for input
      if(1 == BufferEmpty()) 
      { 
        do
        {  
          userInput1 = GetChar();
          (void)printf("%c", userInput1);
          
          userInput2 = GetChar();
          (void)printf("%c", userInput2);
        
          //get <CR>
          userInput3 = GetChar();
          
          if( 'x' == userInput1 || 'X' == userInput1 || 'x' == userInput2 || 'X' == userInput2 ) 
          {
            input_validity = INVALID_INPUTS;  
          } 
          else
          {
            input_validity = VALID_INPUTS;
          }
          
        }while(INVALID_INPUTS == input_validity);
        
        // print <LF> and then '>'
        (void)printf("\r\n>");
        
        //set state of stepper1
        update_state(&stepper1,userInput1);
        
        //set state of stepper2
        update_state(&stepper2,userInput2);
      }
      
      // for stepper  1 take action according to state
      flag1 = take_action(&stepper1);
      
      // for stepper 2 take action acording to state  
  	  flag2 = take_action(&stepper2);
  	  
  	  glow_led(flag1,flag2);
  	  
  	  (void)wait_cycle();
    } 
  }
  
}
Example #21
0
void main(void) {
	unsigned long delay;
	char exit = 'o';
	
  /* Initialization code */
    clock_init(BUS_CLK);
    sci_init(9600, BUS_CLK, SCI0);
    LIN_PHY_ENABLE;
    sci_init(9600, BUS_CLK, SCI1);
    gpio_init();
    LS_Module_Init();
    HS_Module_Init();
    HS0_On();
    PWM_init();
    ADC_init(BUS_CLK);
    
    /* Test serial communication */
    send_string("\n\rSerial Test, press any key\n\r", SCI1);
    echo(SCI1);
    send_string("\n\rTest successful\n\r",SCI1);

	/* Test Relay */
	send_string("\n\rPress u to activate the relay up and d to activate it down\n\r", SCI1);
	send_string("\n\rPres e to exit relay test\n\r", SCI1);
	
	while(exit != 'e'){
		exit = get_char(SCI1);
		put_char(exit, SCI1);
		if(exit == 'u'){
			send_string("\r\nRelay Low side driver 0 active\r\n", SCI1);
			LS0_On();
			for(delay = 0; delay < 30000; ++delay);
			send_string("\r\nRelay Low side driver 0 inactive\r\n", SCI1);
			LS0_Off();
			exit = 'a';	
		} else if (exit == 'd') {
			send_string("\r\nRelay Low side driver 1 active\r\n", SCI1);
			LS1_On();
			for(delay = 0; delay < 30000; ++delay);
			send_string("\r\nRelay Low side driver 1 inactive\r\n", SCI1);
			LS1_Off();
			exit = 'a';
		}		
	}
	
	put_char('\n', SCI1);
	EnableInterrupts;


  for(;;) {
    _FEED_COP(); /* feeds the dog */
    if(read_sw2){
    	LS0_On();
    	send_string("\r\nSwitch 2 pressed\r\n", SCI1);	
    } else {
    	LS0_Off();
    }
    if(read_sw3){
    	LS1_On();
    	send_string("\r\nSwitch 3 pressed\r\n", SCI1);	
    } else {
    	LS1_Off();
    }
    for(delay = 0; delay < 30000; ++delay);
    send_string("\rADC value:   ", SCI1);
    send_string("\b\b\b", SCI1);
    DisplayInt((unsigned char) ADC_read(POT), SCI1);
    put_char(0x55,SCI0);	/* Send stuff through LIN */
  } /* loop forever */
  /* please make sure that you never leave main */
}
Example #22
0
void main(void) {
  	DisableInterrupts;
	initializations(); 		  			 		  		
	EnableInterrupts;



  for(;;) {

    /* write your code here */

//  If the left pushbutton ("start reaction test") flag is set, then:
//    - clear left pushbutton flag
//    - set the "run/stop" flag
//    - display message "Ready, Set..." on the first line of the LCD
//    - turn off the left LED (PT1)
//    - turn on the right LED (PT0)
//  Endif
  if (leftpb ==1 && !runstp){
      goteam = 0;
      react  = 0;
      runstp = 1;
      leftpb = 0;
      RLed   = 1; //Right LED
      LLed   = 0; //Left LED        
      YELLOW = 0;
      GREEN  = 0;
      RED    = 0;
      send_i(LCDCLR);
      lcdwait();
      pmsglcd("Ready, Set...", 13, LINE2);
    }

//  If the "run/stop" flag is set, then:
//    - If the "goteam" flag is NOT set, then:
//       + If "random" = $0000, then:
//         - set the "goteam" flag
//         - clear TCNT register (of TIM)
//         - clear "react" variable (2 bytes)
//         - enable TIM Ch7 interrupts
//         - turn on YELLOW LED
//         - display message "Go Team!" on the second line of the LCD
//      + Endif
//    - Endif
//  Endif
   if(runstp && !goteam && random==0x00){
     goteam = 1;
     react  = 0;
     YELLOW = 1; //Yellow LED
     send_i(LCDCLR);
     lcdwait();
     pmsglcd("Go team!", 8, LINE2);
     TIE    = 0x80;
   }

//  If the right pushbutton ("stop reaction test") flag is set, then:
//    - clear right pushbutton flag
//    - clear the "run/stop" flag
//    - clear the "goteam" flag
//    - turn off yellow LED
//    - disable TIM Ch 7 interrupts
//    - call "tdisp" to display reaction time message
//    - turn off right LED (PT0)
//    - turn on left LED (PT1)
//  Endif
   if (rghtpb == 1) {
     rghtpb = 0;
     if(runstp && goteam){
       runstp  = 0;
       goteam  = 0;
       YELLOW  = 0;
       TIE     = 0x0;
       send_i(LCDCLR);
       lcdwait();
       tdisp();
      
       if(react <= 250){
         GREEN = 1;
         pmsglcd("F**K YEAH!", 10, LINE2);
       }else{
         GREEN =0;
         pmsglcd("Really?", 7, LINE2);
       }
       RLed    = 0; //Right LED
       LLed    = 1; //Left LED      
     }
   }


//  If "react" = 999 (the maximum 3-digit BCD value), then:
//    - clear the "run/stop" flag
//    - turn off yellow LED, turn on red LED
//    - disable TIM Ch 7 interrupts
//    - display message "Time = 999 ms" on the first line of the LCD
//    - display message "Too slow!" on the second line of the LCD 
//    - turn off right LED (PT0)
//    - turn on left LED (PT1)
//  Endif
    if(react >= 999 && runstp){
      runstp = 0;
      react  =0;
      YELLOW = 0; //Yellow LED
      RED    = 1; //Red LED
      TIE    = 0x0;
      send_i(LCDCLR);
      lcdwait();
      pmsglcd("RT = 999ms", 10, LINE1);
      pmsglcd("Too slow!", 9, LINE2);
      RLed   = 0; //Right LED
      LLed   = 1; //Left LED
    }


      _FEED_COP();
    }/* loop forever */
  
}  /* do not leave main */
Example #23
0
void main(void) 
{
  DisableInterrupts;
  //MCU初始化
  PLL_INIT();
  PIT_INIT();
  PWM_INIT();
  AD_INIT();
  IO_INIT();
  SCI_INIT();
  //LCD_Init();
  DFLASH_INIT();
  
  EnableInterrupts;
  
  for(;;) 
  {
     if(PORTB_PB0==0) 
     {
          AD_biaoding();
     } 
     else if(PORTB_PB2==0) 
     {
        stop_flag=0;
       /* LCD_P6x8Str(0,0,"Angle:"); 

        /*LCD_P6x8Str(0,0,"Angle:"); 
        LCD_P6x8Str(0,0,"Gravity_Offset");
        LCD_P6x8Str(0,1,"Anglespeed:");
        LCD_P6x8Str(67,1,"Gyrscope_Offset"); 
        LCD_P6x8Str(0,2,"Anglespeed:");
        LCD_P6x8Str(66,2,"123"); 
        LCD_P6x8Str(0,3,"Kp:");
        LCD_P6x8Str(18,3,"123");
        LCD_P6x8Str(0,4,"Kd:");
        LCD_P6x8Str(18,4,"123");*/    
     }
     else if(PORTB_PB3==0)
     {
        SCI_senddata();
        Senddata[0]=AngleResult[0];
        Senddata[1]=AngleResult[1];
        Senddata[2]=AngleResult[3];//右轮
        Senddata[3]=Adcalcalation[0];//左轮 
        Senddata[4]=Adcalcalation[2];//AngleResult[3];//Turnstand[0];
        Senddata[5]=Adcalcalation[4];//Turnstand[1];
        Senddata[6]=0;
      } 
      else if(PORTB_PB4==0) 
      {
             AD_Max[0][0]=Dflash_Read(data_Address); 
             AD_Max[0][1]=Dflash_Read(data_Address+2); 
             AD_Max[0][2]=Dflash_Read(data_Address+4); 
             AD_Max[1][0]=Dflash_Read(data_Address+6); 
             AD_Max[1][1]=Dflash_Read(data_Address+8);
             AD_Max[1][2]=Dflash_Read(data_Address+10);
             AD_Max[2][0]=Dflash_Read(data_Address+12);
             AD_Max[2][1]=Dflash_Read(data_Address+14);
             AD_Max[2][2]=Dflash_Read(data_Address+16); 
             AD_Cal[1][0]=AD_Max[1][1];
             AD_Cal[1][1]=(AD_Max[0][1]+AD_Max[2][1])/2;
      }
     
     /*if(AD_flag==1) 
     {
        Adget();
        AD_flag=0;
     } 
     else if(Speed_flag==1) 
     {
        SpeedCalculate();
        Speed_flag=0;
     } 
     else if(Angle_flag==1) 
     {   
        GetAngle(AngleResult);
        AngleControl();
        Angle_flag=0; 
     } 
     /*else if(SCI_flag==10) 
     {
         SCI_senddata();
         SCI_flag=0;
     } */            
     _FEED_COP(); 
  } 
}
Example #24
0
void main(void) {

  UINT8 temp = 0;
  UINT8 temp1 = 0;
  UINT8 temp2 = 0;
  UINT8 temp3 = 0;
  UINT8 temp4 = 0;
  
  // Disable interrupts before init
  DisableInterrupts;
 
  /* PLL initialization, 16 MHz Bus Clock @ 32MHz core */
  vfnClock_Init();
     
  /* Other CPU initalization parameters */
  vfnCpu_init();

  /* SCI initialization */
  vfnSCI_Init();

	EnableInterrupts;
	
  // Send 49 = 1 in ANSI showing that we have reached this point
  temp3 = u8SCI_WriteTx(49);
  
  // Disable PWM
  //PWME = 0x00;
  // Set Port P as output
  //sDDRP = 0xFF;
  
  // secure that input capture is enbled
  //TIOS = 0x00;
  // set port T as output except pt0, pt1 and pt2 
  //sDDRT = 0xF8;
  
  

  // Main loop
  for(;;) {
    _FEED_COP(); /* feeds the dog */


    // Check if there is data in the recive buffer
    if (u8SCI_CheckRx() > 0) {
      // We have new input
      temp2 = 1;
      
      // Check input
      switch (u8SCI_ReadRx()) {
        case 'A': // Select port A
          temp = 4;
          temp1 = 0;
          break;

        case 'B': // Select port B
          temp = 1;
          temp1 = 0;
          break;

        case 'E': // Select port E
          temp = 5;
          temp1 = 0;
          break;

        case 'T': // Select port T
          temp = 2;
          temp1 = 0;
          break;
          
        case 'P': // Select port P
          temp = 3;
          temp1 = 0;
          break;
         
        case 'R': //Reset ports to low
          PORTB = 0x00;
          //PTIT = 0x00;
          temp3 = u8SCI_WriteTx('R');
          break;
        
        case '0':
          temp1 = 0x02;
          break;
 
        case '1':
          temp1 = 0x03;
          break;

        case '2':
          temp1 = 0x05;
          break;
                   
        case '3':
          temp1 = 0x09;
          break;

        case '4':
          temp1 = 0x11;
          break;

        case '5':
          temp1 = 0x21;
          break;
 
        case '6':
          temp1 = 0x41;
          break;

        case '7':
          temp1 = 0x81;
          break;
                            
        default:
          // No valid input recived
          temp = 0;
          temp1 = 0;
          temp2 = 0;
          DDRA = 0x00;
          DDRB = 0x00;
          DDRE = 0x00;
          //DDRP = 0x00;  
          //DDRT = 0x00; 
          temp3 = u8SCI_WriteTx('-');
          break;
      }
      
      //Check if we have valid input data
      if (temp != 0 && temp1 > 0x01 && temp1 < 0x82 && temp2 == 1){
        
        //Extract 1 from temp1
        --temp1;

        if (temp == 4) {
          //DDRA = 0xFF;
          //PORTA = temp1;
          temp4 = PORTA;
          temp3 = u8SCI_WriteTx('A');
          //Send PIN number
          temp3 = u8SCI_WriteTx(temp4);
        }
             
        if (temp == 1) {
          //DDRB = 0xFF;
          //PORTB = temp1;
          temp4 = PORTB;
          temp3 = u8SCI_WriteTx('B'); 
          //Send PIN number
          temp3 = u8SCI_WriteTx(temp4);
        }

        if (temp == 5) {
          //DDRE = 0xFF;
          //PORTE = temp1;
          temp4 = PORTE;
          temp3 = u8SCI_WriteTx('E');
          //Send PIN number
          temp3 = u8SCI_WriteTx(temp4);
        }

        
        if (temp == 2) {
          //DDRT = 0xFF;
          //sPTT = temp1;
          temp4 = sPTT;
          temp3 = u8SCI_WriteTx('T');
          //Send PIN number
          temp3 = u8SCI_WriteTx(temp4);
        }
        
        if (temp == 3) {
          //DDRP = 0xFF;
          //sPTP = temp1;
          temp4 = sPTP;
          temp3 = u8SCI_WriteTx('P');
          //Send PIN number
          temp3 = u8SCI_WriteTx(temp4);
        }
                   
        //reset input
        temp1 = 0;
        temp2 = 0;    
      }
      
     // Read one byte from buffer     
//     temp = u8SCI_ReadRx() + 10;
     
     // Send the byte - test
//     temp3 = u8SCI_WriteTx(temp);    
    }
    
    
       
  } /* loop forever */
  /* please make sure that you never leave main */
}
Example #25
0
void main(void) {

  /* put your own code here */
  static unsigned int last_msec_task1 ; 
  static unsigned int last_msec_task2 ; 
    
  PLL_Init () ; 
  SerialCfgPort() ; 
  init_pit()  ; 
  Mspeed_init() ;
  pwm_init() ; 
  init_sysparam();
  
	EnableInterrupts;

  DDRE = DDRE|0X50; 
  PORTE_PE4 = 1 ; 
  DDRE_DDRE5 = 0 ; 
  for(;;) {                                                            
              PORTE_PE6 = ~PORTE_PE6  ; 
            /*-----------------------------------------------------------------------------
             *  获取激光数据,融合编码器数据控制车体运动
             *-----------------------------------------------------------------------------*/
            if(start_time.msec % 50 == 0 && start_time.msec  != last_msec_task1 
            && start_time.msec != last_msec_task1+1 )    //防止时间的更新正好发生在条件判断的时候
            {    
                
                last_msec_task1 = start_time.msec ;  
                
                /*获取速度*/ 
                buffer_1[0] = PACNT%256 ; //低位
                buffer_1[1] = PACNT/256 ; //高位
                /*计数器清零*/
                PACNT = 0  ; 
                
                /*获取速度*/
               
                buffer_1[2] = PORTB ; 
                /*计数器清零*/
                PORTE_PE4 = 0 ; 
                asm(nop) ; asm(nop) ; 
                asm(nop) ; asm(nop) ; 
                PORTE_PE4 = 1 ; 
               
                /* */ 
                //SCI0Send1(buffer_1[0]) ;
                //SCI0Send1(buffer_1[1]) ;
                SCI0Send1(buffer_1[2]) ;
                 
               // SCI1Send1(buffer_1[1]) ; 
                
               // SCI0Send1(buffer_1[2]) ;
                 
              
            }
            
            /*-----------------------------------------------------------------------------
             *  车体运动控制结束
             *-----------------------------------------------------------------------------*/
            
            /*-----------------------------------------------------------------------------
             *  编码并保存漏磁信号,以最高速度1ms每次的采样率
             *-----------------------------------------------------------------------------*/
            if( start_time.msec  != last_msec_task2 ) 
            {   
                 
                last_msec_task2 = start_time.msec ;    
            }
            /*-----------------------------------------------------------------------------
             *  漏磁信号处理结束
             *-----------------------------------------------------------------------------*/

    _FEED_COP(); /* feeds the dog */
  } /* loop forever */
Example #26
0
void main(void) {
  /* put your own code here */
    int b1on =0;
    int b2on =0;
    int led=0;
    int inc=0;
    int paused =0;
  
  //Setting Ports B0-B3 to imputs
  DDRB_BIT0 = 0x1;
  DDRB_BIT1 = 0x1;
  DDRB_BIT2 = 0x1;
  DDRB_BIT3 = 0x1;

  //Setting Ports A0-A2 to be inputs
  
  DDRA_BIT0 = 0x0;
  DDRA_BIT1 = 0x0;
  DDRA_BIT2 = 0x0;


	
	EnableInterrupts;

 

  for(;;) {
    _FEED_COP(); /* feeds the dog */
    
     // step on LED to light forwards
     if (b1on && !paused){
        PORTB =0x1<<(led%4);
        if (inc > 5000){
          inc = 0;
          led++;
          led = led % 4;
        }
        inc++;
     }
     //step on LED to light backwards 
     if (b2on && !paused){
        PORTB =0x1<<(led%4);
        if (inc > 5000){
          inc = 0;
          led--;
          led = led % 4;
        }
        inc++;
     } 
     if (led < 0) {
        led =3;
     }
     
     //switch roles of buttons when b2 is on
     if ((PORTA_BIT0 == 0x0) && (b2on)){
         b1on = !b1on;
         b2on = !b2on;
         while(PORTA_BIT0 == 0x0){}
     //reset button 1 back to be on
     }else if((PORTA_BIT0 == 0x0) && (!b2on)){
         b1on = 1;

     }else if ((PORTA_BIT1 == 0x0) && (b1on)){
         b2on = !b2on;
         b1on = !b1on;
         while(PORTA_BIT1 == 0x0){}
     }else if ((PORTA_BIT0 == 0x0) && (!b1on)){
         b2on = 1;
     }
     if (PORTA_BIT2 == 0){
         paused = !paused;
         while(PORTA_BIT2 == 0x0){}         
     }

  } /* loop forever */
  /* please make sure that you never leave main */
}