Загрузка данных


#include "MDR32Fx.h"
#include "core_cm3.h"
#include "MDR32F9Qx_config.h"
#include "system_MDR32F9Qx.h"
#include "MDR32F9Qx_rst_clk.h"
#include "MDR32F9Qx_port.h"

#define TRUE        1
#define FALSE       1

static PORT_InitTypeDef PortInit;
static PORT_InitTypeDef PortInit_B;

uint8_t R = 3;
int8_t X1 = -3;
int8_t Y1 = 3;
int8_t X2 = 3;
int8_t Y2 = -3;


uint8_t button = 3;


void delay(uint32_t s)
{
	uint32_t prev   = 0;
	uint32_t status = 0;
	SysTick->VAL = ((uint32_t)0);
	SysTick->CTRL |= ((uint32_t)0x1);
	
	while(1)
	{
		status = SysTick->CTRL;
		button = ((MDR_PORTB->RXTX & 0x2) > 0 ? 1 : 0);
		if(status & (0x1 << 16))
		{
			prev++;
		}
		if(prev >= s && (button == 0x1))
		{
			prev = 0;
			SysTick->CTRL &= ((uint32_t)0x1 ^ ((uint32_t)0xFFFFFFFF));
			break;
		}
	}
}

uint8_t calculations(int8_t x, int8_t y)
{
	int8_t calculation_part = (x - X1)*(x - X1) + (y - Y1)*(y - Y1);
	int8_t first_part = ((calculation_part <= (R * R)) && (x >= X1 && x =< 0) && (y =< Y1 && x >= 0));  
	calculation_part = (x - X2)*(x - X2) + (y - Y2)*(y - Y2);
	int8_t second_part = ((calculation_part <= (R * R)) && ( x =< X2 && x >= 0) && (y >= Y2 && x <= 0)); 
	int8_t third_part = (x >= -R && x <= 0 ) && (y >= -R && x <= 0);
	int8_t fourth_part = (x >= 0 && x =< R) && (x >= 0 && y =< R);
	if(first_part || second_part || third_part || fourth_part)
	{
		return TRUE;
	}else
	{
		return FALSE;
	}
}



int main(void)
{
	int8_t x = 0;
	int8_t y = 0;
	RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTA, ENABLE);
	RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTB, ENABLE);
	RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTF, ENABLE);
	RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTD, ENABLE);
	SysTick->CTRL |= ((uint32_t)0x4);
	SysTick->LOAD |= ((uint32_t)8000000-1);
	

	
	PortInit_B.PORT_OE = PORT_OE_IN;
	PortInit_B.PORT_FUNC = PORT_FUNC_PORT;
	PortInit_B.PORT_MODE = PORT_MODE_DIGITAL;
	PortInit_B.PORT_SPEED = PORT_SPEED_SLOW;
	
	PortInit_B.PORT_Pin = PORT_Pin_0 |  PORT_Pin_1  | PORT_Pin_2  | PORT_Pin_3 | PORT_Pin_4;
	
	PORT_Init(MDR_PORTB, &PortInit_B);
	
	PortInit_B.PORT_Pin = 0x0;
	
	PortInit_B.PORT_Pin = PORT_Pin_0 |  PORT_Pin_1;

	PORT_Init(MDR_PORTF, &PortInit_B);
	
	PortInit_B.PORT_Pin = 0x0;
	
	PortInit_B.PORT_Pin = PORT_Pin_3;

	PORT_Init(MDR_PORTD, &PortInit_B);
	
	PortInit_B.PORT_OE = PORT_OE_OUT;
	PortInit_B.PORT_FUNC = PORT_FUNC_PORT;
	PortInit_B.PORT_MODE = PORT_MODE_DIGITAL;
	PortInit_B.PORT_SPEED = PORT_SPEED_SLOW;
	
	PORT_Init(MDR_PORTA, &PortInit_B);
	
	while(1)
	{
		x = ((((MDR_PORTF->RXTX & (0x1)) > 0 ? 1 : 0) * 1) + (((MDR_PORTF->RXTX & (0x1 << 1)) > 0 ? 1 : 0) * 2) + (((MDR_PORTB->RXTX & (0x1 << 1)) > 0 ? 1 : 0) * 4) )* (((MDR_PORTB->RXTX & (0x1)) > 0 ? 1 : 0) * (-1)) ;
		y = ((((MDR_PORTD->RXTX & (0x1 << 3)) > 0 ? 1 : 0) * 1) + (((MDR_PORTB->RXTX & (0x1 << 2)) > 0 ? 1 : 0) * 2) + (((MDR_PORTB->RXTX & (0x1 << 3)) > 0 ? 1 : 0) * 4) )* (((MDR_PORTB->RXTX & (0x1 << 4)) > 0 ? 1 : 0) * (-1)) ;
		if(calculations(x,y) == TRUE)
		{
				PORT_SetBits(MDR_PORTA, PORT_Pin_All);
				MDR_PORTA->RXTX = ((uint16_t)0xFFFF) ^ 0x3;
				while(1);
		}
	}
	return 1;
}