Ejemplo n.º 1
0
void CAN1RxMsgProcess(void)
{
    CANRxMessageBuffer *message;

    if(isCAN1MsgReceived == FALSE)
    {
        return;
    }

    isCAN1MsgReceived = FALSE;

    message = CANGetRxMessage(CAN1, CAN_CHANNEL1);
    lcdInstruction("0;0H");
    unsigned int sid = message->msgSID.SID;

    unsigned int data = message->data[0] << 8;
    unsigned int data2 = message->data[1];
    float temp = (data + data2) * 0.1;

    sprintf(buffer, "%u", sid);
    lcdString(buffer);

    sprintf(buffer, "%2.2fF", temp);

    lcdInstruction("1;0H");
    lcdString("ET: ");
    lcdString(buffer);

    CANUpdateChannel(CAN1, CAN_CHANNEL1);
    CANEnableChannelEvent(CAN1, CAN_CHANNEL1, CAN_RX_CHANNEL_NOT_EMPTY, TRUE);

}
Ejemplo n.º 2
0
//to mozna przezucic do lcdDraw.c/h
void lcdMenu()
{
  lcdString(300, 100, "MENU");
  lcdString(250, 150, "1. INT0 - New Game");
  lcdString(200, 150, "2. Cos tam");
  lcdString(150, 150, "3. Cos ");

}
Ejemplo n.º 3
0
 int main() {
	int column;
	char str[24];
	
	/* Test #1: Initialize LCD screen */
	initLcd();
	_delay_ms(DELAY_COUNT);
	
	
	/* Test #2: Write letter in each cell on screen */
	
	for(column = 0; column < 16; column ++) {
		lcdCursor(1, column+1);
		snprintf(str, sizeof(str), "%X", column);
		lcdString(str);
		_delay_ms(DELAY_COUNT/6);
	}
	
	for(column = 0; column < 16; column ++) {
		lcdCursor(2, column+1);
		snprintf(str, sizeof(str), "%x", column);
		lcdString(str);
		_delay_ms(DELAY_COUNT/6);
	}
	
	/* Test #3: Clear screen */
	
	lcdClear();
	_delay_ms(DELAY_COUNT);
		
	/* Test #4: Write first line */
	
	lcdCursor(1, 1);
	snprintf(str, sizeof(str), "----++++----++++0000");
	lcdString(str);
	_delay_ms(DELAY_COUNT);
	
	/* Test #5: Write second line */
	
	lcdCursor(2, 1);
	snprintf(str, sizeof(str), "AAAABBBBAAAABBBB====");
	lcdString(str);
	_delay_ms(DELAY_COUNT);
	
	return 0;
 }
Ejemplo n.º 4
0
void lcdInt(int16_t i)
{
	if (i < 0) 
	{
		lcdString("-");
		i = -i;
	}
	lcdUint(i);
}
Ejemplo n.º 5
0
//Prints Welcome screen
void welcomeScreen()
{	
	if(button1)
	{
		lcdInstruction("j");
		while(!secondTick());
		while(!secondTick());
		lcdString("Secure Vault");
		button1 = FALSE;
		
	}
}
 int main() {
	MotorDirection dirs[] = {FORWARD, BACKWARD, RIGHT, LEFT,
			SOFT_RIGHT, SOFT_LEFT, SOFT_RIGHT2, SOFT_LEFT2, STOP};
	char strDirs[9][16] = {"FORWARD", "BACKWARD", "RIGHT", "LEFT",
			"SOFT_RIGHT", "SOFT_LEFT", "SOFT_RIGHT2", "SOFT_LEFT2", "STOP"};

	int idx;
	
	initMotor();
	initLcd();

#if 0
	/* Test #1: Check direction */
	
	motorVelocitySet(255, 255);

	for(idx = 0; idx < (sizeof(dirs)/sizeof(dirs[0])); idx ++) {
		lcdClear();
		lcdCursor(1,1);
		lcdString(strDirs[idx]);
		_delay_ms(DELAY_COUNT*2);
		motorDirectionSet(dirs[idx]);
		
		/* Delay for some time */
		
		_delay_ms(DELAY_COUNT);
				
		motorDirectionSet(STOP);

	}
	
	/* Test #2: Check speed */

	lcdClear();
	lcdCursor(1,1);
	lcdString("Speed : ");
	lcdCursor(2,1);
	lcdString("L 100, R 100");
	_delay_ms(DELAY_COUNT*2);

	motorVelocitySet(100, 100);
	motorDirectionSet(FORWARD);
		
	/* Delay for some time */

	_delay_ms(DELAY_COUNT);
		
	motorDirectionSet(STOP);

	/* Test #3: Check individual wheel speed (L < R) */
	
	lcdClear();
	lcdCursor(1,1);
	lcdString("Speed : ");
	lcdCursor(2,1);
	lcdString("L 100, R 255");
	_delay_ms(DELAY_COUNT*2);

	motorVelocitySet(100, 255);	/* Left turn expected */
	motorDirectionSet(FORWARD);
	
	/* Delay for some time */
	
	_delay_ms(DELAY_COUNT);	
	
	motorDirectionSet(STOP);

	/* Test #4: Check individual wheel speed (L > R) */

	lcdClear();
	lcdCursor(1,1);
	lcdString("Speed : ");
	lcdCursor(2,1);
	lcdString("L 255, R 100");
	_delay_ms(DELAY_COUNT*2);

	motorVelocitySet(255, 100);	/* Right turn expected */
	motorDirectionSet(FORWARD);
	
	/* Delay for some time */
	
	_delay_ms(DELAY_COUNT);
		
	motorDirectionSet(STOP);


	/* Test #5: Check left position encoder */

	motorLeftPositionEncoderInit(leftPosEncoderIsr);
	lPosCount = 100;
	motorVelocitySet(255, 255);
	motorDirectionSet(FORWARD);
#endif

	
	/* Test #6: Check orientation */
	motorLeftPositionEncoderInit(leftPosEncoderIsr);
	lPosCount = 23;
	motorVelocitySet(150, 150);
	motorDirectionSet(LEFT);


	while(1);
	return 0;
 }
 int main() {
	AdcChannel channel[] = {
		ADC_BATTERY_VOLTAGE,
		ADC_WHITE_LINE1,
		ADC_WHITE_LINE2,
		ADC_WHITE_LINE3,
		ADC_IR_PROXIMITY1,
		ADC_IR_PROXIMITY2,
		ADC_IR_PROXIMITY3,
		ADC_IR_PROXIMITY4,
		ADC_IR_PROXIMITY5,
		ADC_IR_RANGE1,
		ADC_IR_RANGE2,
		ADC_IR_RANGE3,
		ADC_IR_RANGE4,
		ADC_IR_RANGE5,
		ADC_SERVO_POD1,
		ADC_SERVO_POD1,
		ADC_LAST
	};

	char strChannel[17][20] = {
		"ADC_BATTERY_VOLTAGE",
		"ADC_WHITE_LINE1",
		"ADC_WHITE_LINE2",
		"ADC_WHITE_LINE3",
		"ADC_IR_PROXIMITY1",
		"ADC_IR_PROXIMITY2",
		"ADC_IR_PROXIMITY3",
		"ADC_IR_PROXIMITY4",
		"ADC_IR_PROXIMITY5",
		"ADC_IR_RANGE1",
		"ADC_IR_RANGE2",
		"ADC_IR_RANGE3",
		"ADC_IR_RANGE4",
		"ADC_IR_RANGE5",
		"ADC_SERVO_POD1",
		"ADC_SERVO_POD2",
		"ADC_LAST"
	};

	char buf[17];
	UINT value, idx;

	initAdc();
	initLcd();
	
	for(idx = 0; idx < (sizeof(channel)/sizeof(channel[0])); idx ++) {
		lcdClear();
		lcdCursor(1,1);
		lcdString(strChannel[idx]);
		lcdCursor(2,1);

		if(getAdcValue(channel[idx], &value) == STATUS_OK) {
			snprintf(buf, sizeof(buf), "%d", value);
			lcdString(buf);
		}
		else {
			lcdString("Error");
		}
		_delay_ms(DELAY_COUNT);
	}
	

	return 0;
 }
Ejemplo n.º 8
0
int main()
{
    SysTick_Config(SystemCoreClock/100);
	magazyn = malloc(sizeof(Element)*1200);
    Timer3Conf();
	Joystick_Initialize();
	Buttons_Initialize();
	initDisplay();
	lcdClean();
	Timer3Disable();
    Timer1Conf();

	lcdMenu();
    while(1)
    {
		while(tickCounter<10);
		tickCounter=0;
		switch(Buttons_GetState())
		{
			case BUTTON_INT0:
            //lcdClean();
            initSnake();
            game = 1;
            while(game == 1)
            {
                //while(tickCounter<10);
                //tickCounter=0;
                inputControl = 0;
                switch(Joystick_GetState())
                {
                    case JOYSTICK_UP:
                        inputControl = 1;
                        break;
                    case JOYSTICK_LEFT:
                        inputControl = 2;
                        break;
                    case JOYSTICK_DOWN:
                        inputControl = 4;
                        break;
                    case JOYSTICK_RIGHT:
                        inputControl = 8;
                                break;
                            default:
                                inputControl = oldControl;
                        }
                        if(inputControl == forbidden)
                            inputControl = oldControl;

                        if(reactCount > 0) {
                            game = react(inputControl);
                            --reactCount;
                        }
                    }
                    lcdString(250, 150, "Koniec gry");
                    while(1);
			break;
			case BUTTON_KEY1:
				lcdString(250, 150, "Opcja 2");
                while(1);
			break;
			case BUTTON_KEY2:
			    lcdString(250, 150, "Opcja 3");
			    while(1);
			break;
		}

	}
	return 0;
}
//------------------------------------------------------------------------------
void TIM2_IRQHandler(void)
{
  if (TIM_GetITStatus (TIM2, TIM_IT_Update) != RESET)
  {
    uiTime_AlarmLevel = uiTime_AlarmLevel + 1;
    uiRespond_time = uiRespond_time + 1;
    STM_EVAL_LEDOff(LED5);

    if (uiCurrent_Status == STATUS_SpO2_BELOW_L1 | uiCurrent_Status == STATUS_SpO2_BEHIGH_L1)
    {
      if (uiTime_AlarmLevel > SProfile.uiAlarm_Level1)
      {
        uiTime_AlarmLevel = 0;                                                  // Reset Time_AlarmLevel
        uiRespond_time = 0;
        
        /* If Time alarm more than alarm level 1 set */
        if (uiCurrent_Status == STATUS_SpO2_BELOW_L1)
        {
          uiCurrent_Status = STATUS_SpO2_BELOW_ALARM_L1;
          uiPurpose_FiO2 = uiPurpose_FiO2 + 6;
          
          if (uiPurpose_FiO2 > SProfile.uiFiO2_Maximum)
          {
            /* if uiPurpose_FiO2 more than uiFiO2_Maximum */
            uiPurpose_FiO2 = SProfile.uiFiO2_Maximum;
          }

          FiO2_Range(uiPurpose_FiO2);
          
          /* Update LCD */
          lcdString(1,5,"Status: Below ");
          lcdString(1,6,"Alarm Level 2");
        }
        else if (uiCurrent_Status == STATUS_SpO2_BEHIGH_L1)
        {
          uiCurrent_Status = STATUS_SpO2_BEHIGH_ALARM_L1;
          uiPurpose_FiO2 = uiPurpose_FiO2 - 6;

          if (uiPurpose_FiO2 < SProfile.uiFiO2_Minimum)
          {
            /* if uiPurpose_FiO2 more than uiFiO2_Minimum */
            uiPurpose_FiO2 = SProfile.uiFiO2_Minimum;
          }

          FiO2_Range(uiPurpose_FiO2);
          
          /* Update LCD */
          lcdString(1,5,"Status: Behigh ");
          lcdString(1,6,"Alarm Level 2");          
        }
      }
      else if( uiRespond_time > SProfile.uiRespondsTime)
      {
        if( uiCurrent_Status == STATUS_SpO2_BELOW_L1)
        {
          /* Check Current SpO2. if SpO2 is lower than last time, the system will increase FiO2 */
          if (uiCurrent_SpO2 <= uiInitial_SpO2)
          {
            uiPurpose_FiO2 = uiPurpose_FiO2 + 4;                                // Increase FiO2 4 percent
          }
          uiRespond_time = 0;                                                   // clear Respond time
          
          /* Check Limit of FiO2 */
          if (uiPurpose_FiO2 > SProfile.uiFiO2_Maximum)
          {
            uiPurpose_FiO2 = SProfile.uiFiO2_Maximum;
          }
          uiInitial_SpO2 = uiCurrent_SpO2;                                      // save current SpO2 at initial
        }
        else if(uiCurrent_Status == STATUS_SpO2_BEHIGH_L1)
        {
          /* if SpO2 is higher than last time, the system will decrease FiO2*/
          if(uiCurrent_SpO2 >= uiInitial_SpO2)
          {
            uiPurpose_FiO2 = uiPurpose_FiO2 - 4;                                // Decrease FiO2 4 percent
          }
          uiRespond_time = 0;                                                   // Clear Respond time
          
          /* Check Limit of FiO2 */
          if (uiPurpose_FiO2 < SProfile.uiFiO2_Minimum)
          {
            uiPurpose_FiO2 = SProfile.uiFiO2_Minimum;
          }
        }
      
        uiInitial_SpO2 = uiCurrent_SpO2;                                        // save new Current SpO2
        FiO2_Range(uiPurpose_FiO2);
      }
    }
    else if (uiCurrent_Status == STATUS_SpO2_BEHIGH_L2 | uiCurrent_Status == STATUS_SpO2_BELOW_L2)
    {
      /* Alarm Level 2 */
      if (uiTime_AlarmLevel >= SProfile.uiAlarm_Level2)
      {
        GPIO_SetBits(Alarm_Set_GPIO_Port, Alarm_Set_Pin);
        uiCurrent_Status = STATUS_ALARM;
        USART_Cmd(OPM_USART, ENABLE);                                          // ENABLE Oxygen Pulse Meter USART
        TIM_ITConfig(TIM3, TIM_IT_Update, DISABLE);
        TIM_Cmd(TIM3, DISABLE);
      
//        NVIC_InitTypeDef   NVIC_InitStructure;
        
        /* Enable and set Alarm_Button_EXTI Line Interrupt to the lowest priority */
//        NVIC_InitStructure.NVIC_IRQChannel = Alarm_Button_IRQn;
//        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
//        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
//        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//        NVIC_Init(&NVIC_InitStructure);


        //Time_AlarmLevel = 0;

        /* Notification Alarm Board (Toggle Pin to Alarm Circuit) */
        lcdClear();
        lcdUpdate();
        lcdString(3,1,"ALARM !!!");
        lcdString(2,2,"PLEASE PUSH");
        lcdString(2,3,"ALARM BUTTON");
        alarm_timer(TIMER_DISABLE);
      }
      else if (uiRespond_time >= SProfile.uiRespondsTime)
      {
        if(uiCurrent_Status == STATUS_SpO2_BEHIGH_L2)
        {
          /* Is SpO2 higher than last SpO2 ?*/
          if(uiCurrent_SpO2 >= uiInitial_SpO2)
          {
            uiPurpose_FiO2 = uiPurpose_FiO2 - 6;                                // Decrease FiO2 6 percent
          }
          uiRespond_time = 0;                                                   // Clear Respond time
          
          /* Check Limit of FiO2 range */
          if (uiPurpose_FiO2 < SProfile.uiFiO2_Minimum)
          {
            uiPurpose_FiO2 = SProfile.uiFiO2_Minimum;
          }
          
          uiInitial_SpO2 = uiCurrent_SpO2;                                      // save current SpO2
        }
        else if(uiCurrent_Status == STATUS_SpO2_BELOW_L2)
        {
          /* Is SpO2 lower than last SpO2 ? */
          if(uiCurrent_SpO2 <= uiInitial_SpO2)
          {
            uiPurpose_FiO2 = uiPurpose_FiO2 + 6;
          }
          uiRespond_time = 0;                                                   // clear respond time
          
          /* Check Limit of FiO2 range */
          if(uiPurpose_FiO2 > SProfile.uiSpO2_Maximum)
          {
            uiPurpose_FiO2 = SProfile.uiSpO2_Maximum;
          }
          
          uiInitial_SpO2 = uiCurrent_SpO2;                                      // save Current SpO2
        }
        
        FiO2_Range(uiPurpose_FiO2);
      }
    }
    else if ((uiCurrent_Status == STATUS_MIDDLE_SpO2_BELOW) | (uiCurrent_Status == STATUS_MIDDLE_SpO2_BEHIGH))
    {
      if (uiRespond_time >= SProfile.uiRespondsTime)
      {
        /* if time over than Responds time, FiO2 will increse or decrease 2 percent */
        uiTime_AlarmLevel = 0;                                                  // clear Time_AlarmLevel
        uiRespond_time = 0;                                                     // clear respond time
        
        if (uiCurrent_SpO2 < SProfile.uiSpO2_middleRange)
        {
          uiPurpose_FiO2 = uiPurpose_FiO2 + 2;                                  // increase FiO2 more than present 2 percent
          
          if (uiPurpose_FiO2 > SProfile.uiFiO2_Maximum)
          {
            uiPurpose_FiO2 = SProfile.uiFiO2_Maximum;
          }
          uiInitial_SpO2 = uiCurrent_SpO2;
        }
        else if (uiCurrent_SpO2 > SProfile.uiSpO2_middleRange)
        {
          uiPurpose_FiO2 = uiPurpose_FiO2 - 2;                                  // decrease FiO2 more than present 2 percent
          
          if (uiPurpose_FiO2 < SProfile.uiFiO2_Minimum)
          {
            uiPurpose_FiO2 = SProfile.uiFiO2_Minimum;
          }
          
          uiInitial_SpO2 = uiCurrent_SpO2;
        }
      }
      
      uiInitial_SpO2 = uiCurrent_SpO2;
      FiO2_Range(uiPurpose_FiO2);
    }

    TIM_ClearITPendingBit (TIM2, TIM_IT_Update);
  }
}
Ejemplo n.º 10
0
//Function to enter password or reset password
void enterVault()
{
	char display[8];
	pass[0] = 0x00;
	pass[1] = 0x00;
	pass[2] = 0x00;
	if(buttonPressed(BTN_ROTARY))	//Section for entering password
	{	
		UINT8 mem[3];
		eepromRead(0x0000, 3, mem);	//Read stored password from eeprom
		int y;
		y = 0;
		lcdInstruction("j");
		lcdString("   Enter Key   "); 
		lcdInstruction("1;0H");
		lcdString("    ");
		sprintf(display, "%2.2X-%2.2X-%2.2X", pass[0], pass[1], pass[2]);
		lcdString(display);		
		while(TRUE)
		{
			int x;
			x = 0;
			if(buttonPressed(BTN_ROTARY))
				y++;
			x = readRotaryKnob();
			if(x != 0 || y == 3)
			{	
				if(switchState(SWITCH_ROTARY))
					x = x*8;
				pass[y] += x;
				lcdInstruction("j");
				lcdString("   Enter Key   "); 
				lcdInstruction("1;0H");
				lcdString("    ");
				sprintf(display, "%2.2X-%2.2X-%2.2X", pass[0], pass[1], pass[2]);
				lcdString(display); 
				if(y == 3)				
				{
					lcdInstruction("j");
					if(mem[0] == pass[0] && mem[1] == pass[1] && mem[2] == pass[2])		//Compare passwords
					{
						lcdString("  Key Correct! ");
						while(!secondTick());
						while(!secondTick());
						vault();				//If correct go to data editing function
						break;
					}
					else
					{
						lcdString(" Key Incorrect! ");		//If incorrect print message and break
						while(!secondTick());
						while(!secondTick());
						break;
					}
				}
			}
		}			
	}
	
	else if(buttonPressed(BTN3))		//Section for resetting password
	{
		char data[17] = "abcdefghijklmnop";		//Used to reset data on eeprom
		int y;
		y = 0;
		lcdInstruction("j");
		lcdString("   Reset Key   "); 
		lcdInstruction("1;0H");
		lcdString("    ");
		sprintf(display, "%2.2X-%2.2X-%2.2X", pass[0], pass[1], pass[2]);
		lcdString(display);
		while(TRUE)
		{
			int x;
			x = 0;
			if(buttonPressed(BTN_ROTARY))
				y++;
			x = readRotaryKnob();
			if(x != 0 || y == 3)
			{	
					if(switchState(SWITCH_ROTARY))	
						x = x*8;
					pass[y] += x;
					lcdInstruction("j");
					lcdString("   Reset Key   "); 
					lcdInstruction("1;0H");
					lcdString("    ");
					sprintf(display, "%2.2X-%2.2X-%2.2X", pass[0], pass[1], pass[2]);
					lcdString(display); 
					if(y == 3)
					{
						lcdInstruction("j");
						lcdString("   Key Reset!   ");
						eepromWrite(0x0000, 3, pass);		//store new password
						while(!secondTick());
						while(!secondTick());
						while(!secondTick());
						eepromWrite(0x0003, 16, data);		//reset data
						vault();
						break;
					}
				}
			}
	}
}
Ejemplo n.º 11
0
//Function to store and edit user data
void vault()
{
	char cursor[5];		//used to format cursor
	UINT8 data[17];		//used to store the user data
	while(!secondTick());
	while(!secondTick());
	eepromRead(0x0003, 16, data);
	lcdInstruction("j");
	lcdString("   Edit Data: "); 
	lcdInstruction("1;0H");
	lcdString(data);
	lcdInstruction("1;0H");
	lcdInstruction("1c");
	
	int y;
	y = 0;
	while(TRUE)
	{
		int x;
		x = 0;
		if(buttonPressed(BTN_ROTARY))
		{
			y++;
			if(y == 16)
				y = 0;
			sprintf(cursor, "1;%dH", y);
 			lcdInstruction(cursor);
		}
		x = readRotaryKnob();
		if(x != 0)					//To edit data
		{
			if(switchState(SWITCH_ROTARY))
				x = x*8;
			data[y] += x;
			if((int)data[y] >= 123)
			{	
				int k;
				k = (int)data[y] -123;// = k;  97;
				data[y] = 97 + k;
			}
			if((int)data[y] <= 96)
			{
				int k;
				k = 96 - (int)data[y];
				data[y] = 122 - k;
			}
			lcdInstruction("j");
			lcdString("   Edit Data: "); 
			lcdInstruction("1c");
			lcdInstruction("1;0H");			
			lcdString(data);
			sprintf(cursor, "1;%dH", y);
 			lcdInstruction(cursor);
		}
		if(buttonPressed(BTN1))		//To exit data entry 
		{
			lcdInstruction("j");
			lcdInstruction("0c");
			lcdString("   Data Saved   ");
			eepromWrite(0x0003, 16, data);
			button1 = TRUE;
			while(!secondTick());
			while(!secondTick());
			break;
		}
	}

}