TA的每日心情 | 开心 2018-3-29 09:22 |
---|
签到天数: 15 天 连续签到: 1 天 [LV.4]偶尔看看III
|
楼主 |
发表于 2016-3-15 23:27:47
|
显示全部楼层
TIMER2 PWM输出配置程序(用库):配置PA1 PA2
void TIM_Configuration(void)
{
/* -----------------------------------------------------------------------
TIMER2 Configuration: generate 2 PWM signals with 2 different duty cycles:
TIMER2CLK = SystemCoreClock / 8 = 9MHz
TIMER2 frequency = 180/9M = 0.02ms
----------------------------------------------------------------------- */
TIMER_BaseInitPara TIMER_TimeBaseStructure;
TIMER_OCInitPara TIMER_OCInitStructure;
/* TIMER2 clock enable */
RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2,ENABLE);
/* TIMER2 configuration */
TIMER_DeInit(TIMER2);
TIMER_TimeBaseStructure.TIMER_Prescaler = 8-1;
TIMER_TimeBaseStructure.TIMER_CounterMode = TIMER_COUNTER_UP;
TIMER_TimeBaseStructure.TIMER_Period = 180-1;
TIMER_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
TIMER_BaseInit(TIMER2,&TIMER_TimeBaseStructure);
/* CH2,CH3 and CH4 Configuration in PWM mode */
TIMER_OCInitStructure.TIMER_OCMode = TIMER_OC_MODE_PWM1;
TIMER_OCInitStructure.TIMER_OCPolarity = TIMER_OC_POLARITY_HIGH;
TIMER_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;
TIMER_OCInitStructure.TIMER_OCIdleState = TIMER_OC_IDLE_STATE_RESET;
TIMER_OCInitStructure.TIMER_Pulse = 0;
TIMER_OC2_Init(TIMER2, &TIMER_OCInitStructure);
TIMER_OC2_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);
TIMER_OCInitStructure.TIMER_Pulse = 0;
TIMER_OC3_Init(TIMER2, &TIMER_OCInitStructure);
TIMER_OC3_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);
/* Auto-reload preload enable */
TIMER_CARLPreloadConfig(TIMER2,ENABLE);
/* TIMER enable counter*/
TIMER_Enable( TIMER2, ENABLE );
}
复制代码
FMC 存储数据函数:
void FMC_savedate(void)
{
uint8_t p=0,n=0,flashflag[3]={0};
if(flashdate==1)
{
if(ReadData[0]>=PVMIN&&ReadData[0]<=PVMAX){backupData[0]=ReadData[0];flashflag[0]=1;}else{/*printf("PV SETTING ERROR\n\r");*/}
if(ReadData[1]>=BATMIN&&ReadData[1]<=BATMAX){backupData[1]=ReadData[1];flashflag[1]=1;}else{/*printf("BAT SETTING ERROR\n\r");*/}
if(ReadData[2]>=FANMIN&&ReadData[2]<=FANMAX){backupData[2]=ReadData[2];flashflag[2]=1;}else{/*printf("FAN TEMP SETTING ERROR\n\r");*/}
for(p=0;p<Savenumber;p++){ReadData[p]=0;}
if(flashflag[0]==1&&flashflag[1]==1&&flashflag[2]==1)
{
FMC_Unlock();
/* Define the number of page to be erased */
NbrOfPage = (BANK1_WRITE_END_ADDR - BANK1_WRITE_START_ADDR) / FMC_PAGE_SIZE;
/* Clear All pending flags */
FMC_ClearBitState(FMC_FLAG_EOP | FMC_FLAG_WERR | FMC_FLAG_PERR );
/* Erase the FLASH pages */
for(EraseCounter = 0; EraseCounter < NbrOfPage; EraseCounter++)
{
FMCStatus = FMC_ErasePage(BANK1_WRITE_START_ADDR + (FMC_PAGE_SIZE * EraseCounter));
FMC_ClearBitState(FMC_FLAG_EOP | FMC_FLAG_WERR | FMC_FLAG_PERR );
}
FMC_Lock();
/* Unlock the Flash Bank1 Program Erase controller */
FMC_Unlock();
/* Define the number of page to be erased */
NbrOfPage = (BANK1_WRITE_END_ADDR - BANK1_WRITE_START_ADDR) / FMC_PAGE_SIZE;
/* Clear All pending flags */
FMC_ClearBitState(FMC_FLAG_EOP | FMC_FLAG_WERR | FMC_FLAG_PERR );
/* Program Flash Bank1 */
Address = BANK1_WRITE_START_ADDR;
for(save=0;save<Savenumber;save++)
{
FMCStatus = FMC_ProgramWord(Address, backupData[save]);
FMC_ClearBitState(FMC_FLAG_EOP | FMC_FLAG_WERR | FMC_FLAG_PERR );
Address+=4;
}
FMC_Lock();
for(n=0;n<3;n++){flashflag[n]=0;}
reset=1;
}
flashdate=0;
}
}
复制代码
串口DMA+IDLE中断接收数据
void USART1_IRQHandler(void)
{
uint32_t tmp_flag = 0;
uint32_t temp;
tmp_flag=USART_GetIntBitState(USART1, USART_INT_IDLEF);
if(tmp_flag!= RESET)
{
DMA_Enable(DMA1_CHANNEL5, DISABLE);
temp = USART1->STR;
temp = USART1->DR;
temp= DMA_GetCurrDataCounter(DMA1_CHANNEL5);;
Length=BufferSize-temp;
flag=1;
DMA1_CHANNEL5->RCNT=BufferSize;
DMA_Enable(DMA1_CHANNEL5,ENABLE);
}
__nop();
} |
|