218 lines
5.7 KiB
C
218 lines
5.7 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_i2c.h"
|
|
#include "drv_tim.h"
|
|
#include "drv_adc.h"
|
|
#include "drv_led.h"
|
|
#include "drv_key.h"
|
|
/* Global typedef */
|
|
|
|
/* Global define */
|
|
|
|
/* Global Variable */
|
|
uint8_t Red_Count = 0;
|
|
uint8_t Green_Count = 0;
|
|
uint8_t Blue_Count = 0;
|
|
|
|
uint8_t tx[20] = "123467890asdfghjklq";
|
|
uint8_t rx[20] = {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();
|
|
adc_init();
|
|
exti_init();
|
|
|
|
AT24CXX_Init();
|
|
|
|
/*
|
|
|
|
AT24CXX_Write(0x0010, tx, 20);
|
|
|
|
Delay_Ms(2000);
|
|
*/
|
|
AT24CXX_Read(0x0010, rx, 20);
|
|
|
|
|
|
printf("i2c:%s\t\n", rx);
|
|
|
|
|
|
/*
|
|
GPIO_InitTypeDef GPIO_InitStructure={0};
|
|
|
|
|
|
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE );
|
|
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
|
|
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE );
|
|
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOD, ENABLE );
|
|
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOE, ENABLE );
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
GPIO_Init( GPIOA, &GPIO_InitStructure );
|
|
GPIO_Init( GPIOB, &GPIO_InitStructure );
|
|
GPIO_Init( GPIOC, &GPIO_InitStructure );
|
|
GPIO_Init( GPIOD, &GPIO_InitStructure );
|
|
GPIO_Init( GPIOE, &GPIO_InitStructure );
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
GPIO_Init( GPIOB, &GPIO_InitStructure );
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
|
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("keys:%d,%d,%d,%d\n",keys[0],keys[1],keys[2],keys[3]);
|
|
//printf("adc:\t %4d,%4d,%4d,%4d \n", adc_raw[0],adc_raw[1],adc_raw[2],adc_raw[3]);
|
|
|
|
|
|
Red_Count += 1;
|
|
Green_Count += 1;
|
|
Blue_Count += 1;
|
|
|
|
|
|
if(Red_Count % 2){
|
|
LED_setToggle(0);
|
|
|
|
LED_setToggle(3);
|
|
LED_setToggle(4);
|
|
LED_setToggle(5);
|
|
LED_setToggle(6);
|
|
|
|
/*
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_All, Bit_RESET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_All, Bit_RESET);
|
|
GPIO_WriteBit(GPIOC, GPIO_Pin_All, Bit_RESET);
|
|
GPIO_WriteBit(GPIOD, GPIO_Pin_All, Bit_RESET);
|
|
GPIO_WriteBit(GPIOE, GPIO_Pin_All, Bit_RESET);
|
|
|
|
|
|
GPIO_WriteBit(GPIOD, GPIO_Pin_5, Bit_RESET);
|
|
GPIO_WriteBit(GPIOD, GPIO_Pin_6, Bit_RESET);
|
|
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_RESET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_13, Bit_RESET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_14, Bit_RESET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_15, Bit_RESET);
|
|
|
|
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_1, Bit_RESET);
|
|
|
|
GPIO_WriteBit(GPIOD, GPIO_Pin_2, Bit_RESET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_3, Bit_RESET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_4, Bit_RESET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_5, Bit_RESET);
|
|
*/
|
|
|
|
|
|
}
|
|
else {
|
|
|
|
/*
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_All, Bit_SET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_All, Bit_SET);
|
|
GPIO_WriteBit(GPIOC, GPIO_Pin_All, Bit_SET);
|
|
GPIO_WriteBit(GPIOD, GPIO_Pin_All, Bit_SET);
|
|
GPIO_WriteBit(GPIOE, GPIO_Pin_All, Bit_SET);
|
|
|
|
|
|
GPIO_WriteBit(GPIOD, GPIO_Pin_5, Bit_SET);
|
|
GPIO_WriteBit(GPIOD, GPIO_Pin_6, Bit_SET);
|
|
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_SET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_13, Bit_SET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_14, Bit_SET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_15, Bit_SET);
|
|
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_1, Bit_SET);
|
|
|
|
GPIO_WriteBit(GPIOD, GPIO_Pin_2, Bit_SET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_3, Bit_SET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_4, Bit_SET);
|
|
GPIO_WriteBit(GPIOB, GPIO_Pin_5, 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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|