123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #include "sysinit.h"
- extern uint16_t timer;
- extern uint8_t MyType;
- void WatchDog_Init(u8 prer, u16 reld)
- {
- IWDG->KR=0x5555; //允许访问PR和RLR寄存器
- IWDG->PR=prer; //设置分频
- IWDG->RLR=reld; //设定计数器初值
- IWDG->KR=0xaaaa; //初次装初值
- IWDG->KR=0xcccc; //启动看门狗定时器
- }
- //喂狗
- void WatchDog_Feed(void)
- {
- IWDG->KR=0xaaaa;
- }
- void SysTick_Handler() //4ms中断
- {
- timer++;
- }
- void config_io_PuPd_DOWN(GPIO_TypeDef* GPIO_Type,uint16_t GPIO_Pin_)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
- GPIO_Init(GPIO_Type, &GPIO_InitStructure);
- }
- void config_io_PuPd_UP(GPIO_TypeDef* GPIO_Type,uint16_t GPIO_Pin_)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_Init(GPIO_Type, &GPIO_InitStructure);
- }
- void config_io_NOPULL(GPIO_TypeDef* GPIO_Type,uint16_t GPIO_Pin_)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIO_Type, &GPIO_InitStructure);
- }
- void config_io_out(GPIO_TypeDef* GPIO_Type,uint16_t GPIO_Pin_)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_Init(GPIO_Type, &GPIO_InitStructure);
- }
- uint8_t temp1=0x0F,temp2=0;
- uint8_t get_io(void)
- {
-
-
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);
- config_io_NOPULL(GPIOF, GPIO_Pin_0);
- config_io_NOPULL(GPIOF, GPIO_Pin_1);
- config_io_NOPULL(GPIOA, GPIO_Pin_0);
- config_io_NOPULL(GPIOA, GPIO_Pin_1);
- delay_ms_(1);
-
- temp1 = ((GPIOA->IDR&GPIO_Pin_1)==0);
- temp1 = (temp1<<1)|((GPIOA->IDR&GPIO_Pin_0)==0);
- temp1 = (temp1<<1)|((GPIOF->IDR&GPIO_Pin_1)==0);
- temp1 = (temp1<<1)|((GPIOF->IDR&GPIO_Pin_0)==0);
-
- delay_ms_(10);
- temp2 = (GPIOA->IDR&GPIO_Pin_1)==0;
- temp2 = (temp2<<1)|((GPIOA->IDR&GPIO_Pin_0)==0);
- temp2 = (temp2<<1)|((GPIOF->IDR&GPIO_Pin_1)==0);
- temp2 = (temp2<<1)|((GPIOF->IDR&GPIO_Pin_0)==0);
-
- if (temp1==temp2) return temp1;
- else return 0x0F;
- }
- void ALL_Config(void)
- {
- SysTick_Config(SystemCoreClock/1000);
- LED_Init();
-
- MyType = get_io(); //获取编码器当前值
- //MyType = 1; //获取编码器当前值
- USART1_Init_Config(); //配置IO口和中断配置
- USART1_Init(9600); //为初始化蓝牙配置
-
- WatchDog_Init(4, 1350);
- if (MyType==15) AutoBauRate_StartBitMethod(); //获取波特率
-
- WatchDog_Feed();
-
- BLE_init(); //初始化蓝牙配置
- USART1_NVIC_Config();
- }
|