156 lines
4.1 KiB
C
156 lines
4.1 KiB
C
|
|
/********************************** (C) COPYRIGHT *******************************
|
||
|
|
* File Name : main.c
|
||
|
|
* Author : WCH
|
||
|
|
* Version : V1.0.0
|
||
|
|
* Date : 2021/06/06
|
||
|
|
* Description : Main program body.
|
||
|
|
*********************************************************************************
|
||
|
|
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||
|
|
* Attention: This software (modified or not) and binary are used for
|
||
|
|
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||
|
|
*******************************************************************************/
|
||
|
|
|
||
|
|
/*
|
||
|
|
*@Note
|
||
|
|
USART Print debugging routine:
|
||
|
|
USART1_Tx(PA9).
|
||
|
|
This example demonstrates using USART1(PA9) as a print debug port output.
|
||
|
|
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include "debug.h"
|
||
|
|
|
||
|
|
|
||
|
|
#include "main_task.h"
|
||
|
|
|
||
|
|
#include "drv_tim.h"
|
||
|
|
#include "drv_adc.h"
|
||
|
|
#include "drv_led.h"
|
||
|
|
|
||
|
|
/* Global typedef */
|
||
|
|
|
||
|
|
/* Global define */
|
||
|
|
|
||
|
|
/* Global Variable */
|
||
|
|
uint8_t Red_Count = 0;
|
||
|
|
uint8_t Green_Count = 0;
|
||
|
|
uint8_t Blue_Count = 0;
|
||
|
|
/*********************************************************************
|
||
|
|
* @fn main
|
||
|
|
*
|
||
|
|
* @brief Main program.
|
||
|
|
*
|
||
|
|
* @return none
|
||
|
|
*/
|
||
|
|
int main(void)
|
||
|
|
{
|
||
|
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
||
|
|
Delay_Init();
|
||
|
|
USART_Printf_Init(115200);
|
||
|
|
printf("SystemClk:%d\t\n", SystemCoreClock);
|
||
|
|
|
||
|
|
LED_Init();
|
||
|
|
TIM_PWM_Init();
|
||
|
|
|
||
|
|
GPIO_InitTypeDef GPIO_InitStructure={0};
|
||
|
|
|
||
|
|
/*
|
||
|
|
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE );
|
||
|
|
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
|
||
|
|
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE );
|
||
|
|
|
||
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
|
||
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
|
|
GPIO_Init( GPIOA, &GPIO_InitStructure );
|
||
|
|
|
||
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
|
||
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
|
|
GPIO_Init( GPIOC, &GPIO_InitStructure );
|
||
|
|
|
||
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
|
||
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
|
|
GPIO_Init( GPIOB, &GPIO_InitStructure );
|
||
|
|
*/
|
||
|
|
|
||
|
|
|
||
|
|
while(1)
|
||
|
|
{
|
||
|
|
Delay_Ms(10);
|
||
|
|
printf("This is printf example\r\n");
|
||
|
|
|
||
|
|
|
||
|
|
Red_Count += 1;
|
||
|
|
Green_Count += 1;
|
||
|
|
Blue_Count += 1;
|
||
|
|
|
||
|
|
|
||
|
|
if(Red_Count % 2){
|
||
|
|
LED_setToggle(0);
|
||
|
|
|
||
|
|
/*
|
||
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_0, Bit_RESET);
|
||
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_1, Bit_RESET);
|
||
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_2, Bit_RESET);
|
||
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_3, Bit_RESET);
|
||
|
|
|
||
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_8, Bit_RESET);
|
||
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_9, Bit_RESET);
|
||
|
|
|
||
|
|
GPIO_WriteBit(GPIOC, GPIO_Pin_6, Bit_RESET);
|
||
|
|
GPIO_WriteBit(GPIOC, GPIO_Pin_7, Bit_RESET);
|
||
|
|
GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_RESET);
|
||
|
|
GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_RESET);
|
||
|
|
*/
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
/*
|
||
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_0, Bit_SET);
|
||
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_1, Bit_SET);
|
||
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_2, Bit_SET);
|
||
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_3, Bit_SET);
|
||
|
|
|
||
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_8, Bit_SET);
|
||
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_9, Bit_SET);
|
||
|
|
|
||
|
|
GPIO_WriteBit(GPIOC, GPIO_Pin_6, Bit_SET);
|
||
|
|
GPIO_WriteBit(GPIOC, GPIO_Pin_7, Bit_SET);
|
||
|
|
GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_SET);
|
||
|
|
GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_SET);
|
||
|
|
*/
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
if(Green_Count % 3){
|
||
|
|
LED_setToggle(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
if(Blue_Count % 5){
|
||
|
|
LED_setToggle(2);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
TIM_SetCompare3(TIM4, 1000);
|
||
|
|
TIM_SetCompare4(TIM4, 1100);
|
||
|
|
|
||
|
|
TIM_SetCompare1(TIM2, 1200);
|
||
|
|
TIM_SetCompare2(TIM2, 1300);
|
||
|
|
TIM_SetCompare3(TIM2, 1400);
|
||
|
|
TIM_SetCompare4(TIM2, 1500);
|
||
|
|
|
||
|
|
TIM_SetCompare1(TIM3, 200);
|
||
|
|
TIM_SetCompare2(TIM3, 300);
|
||
|
|
TIM_SetCompare3(TIM3, 400);
|
||
|
|
TIM_SetCompare4(TIM3, 500);
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|