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


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

static PORT_InitTypeDef PortInit;
volatile uint32_t ms_tick = 0;

void SysTick_Handler() {
    ms_tick++;
}

void delay_mss(uint32_t ms) {
    uint32_t start = ms_tick;
    while ((ms_tick - start) < ms);
}

int main () {
    RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTA, ENABLE);
    RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTC, ENABLE);
    
    PortInit.PORT_OE = PORT_OE_IN;
    PortInit.PORT_FUNC = PORT_FUNC_PORT;
    PortInit.PORT_MODE = PORT_MODE_DIGITAL;
    PortInit.PORT_SPEED = PORT_SPEED_SLOW;
    PortInit.PORT_Pin = (PORT_Pin_0);
    PORT_Init(MDR_PORTC, &PortInit);
    
    PortInit.PORT_OE = PORT_OE_OUT;
    PortInit.PORT_Pin = PORT_Pin_All;
    PORT_Init(MDR_PORTA, &PortInit); 

    SysTick->LOAD = (8000000/1000) - 1;
    SysTick->VAL = 0;
    SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;

    int step = 0;               
    uint8_t is_paused = 0;      
    uint8_t last_btn_state = 1;
    uint32_t last_move_time = 0;

    PORT_Write(MDR_PORTA, PORT_Pin_All);

    while(1) {
        uint8_t current_btn = PORT_ReadInputDataBit(MDR_PORTC, PORT_Pin_0);
        if (current_btn == 0 && last_btn_state == 1) {
            is_paused = !is_paused;
            delay_mss(200);
        }
        last_btn_state = current_btn;
        if (is_paused == 0) {
            if ((ms_tick - last_move_time) >= 1000) {
                
                if (step >= 0 && step <= 3) {
                    uint32_t mask = (1 << step) | (1 << (7 - step));
                    PORT_Write(MDR_PORTA, ~mask);
                } 
                else if (step == 4) {
                    PORT_Write(MDR_PORTA, 0x00); 
                } 
                else if (step == 5) {
                    PORT_Write(MDR_PORTA, 0xFF);
                }
                step++;
                if (step > 5) step = 0;
                last_move_time = ms_tick;
            }
        }
    }
}