




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
STM32+按鍵調(diào)控輸出+串口輸出占空比(2010-09-20STM32#include#include"STM32Lib\\stm32f10x.h"#include"hal.h"FunctionName:PB0,5,8,9;PC5,7;PD7PA8LEDvoidGPIO_Configuration(void){STM32的設(shè)計(jì)角度上說,沒被允許的端將不接入時(shí)鐘,也就不會(huì)耗能,STM32節(jié)能的一種技巧,*/RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);/*PC8按鍵輸入GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;//上拉輸入GPIO_Init(GPIOC,&GPIO_InitStructure);/*PC9按鍵輸入*/GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;GPIO_InitStructure.GPIO_ModeGPIO_Mode_IPU;//上拉輸入GPIO_Init(GPIOC,&GPIO_InitStructure);}#ifndef#ifndefHAL_H#defineexternvoid externvoid #defineGET_LEFT()(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_8))#defineGET_RIGHT()(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_9))externvoidUSART1_Putc(u8c);externexternvoidUSART_Configuration(void);externvoidUSART1_Puts(char*str);#include"STM32Lib\\stm32f10x.h"voidTim1_Configuration(void){ GPIO_InitTypeDef/*PA8設(shè)置為功能腳( )*/GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOA,&GPIO_InitStructure);/*TIM1TIM_TimeBaseStructure.TIM_Prescaler=72; TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period=2000; //裝載值1000k/2000=500hzTIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;TIM_TimeBaseStructure.TIM_RepetitionCounter=0x0;/*Channel1Configurationin mode*/TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_ TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OutputNState=TIM_OutputNState_Disable;//反向通道無效TIM_OCInitStructure.TIM_Pulse=300; TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_Low; Polarity= 性性TIM_OCInitStructure.TIM_OCIdleState=TIM_OCIdleState_Set; IdleState=TIM_OCIdleState_Reset;/*TIM1counterenable/*TIM1MainOutputEnable*/ }void 1(u16{TIM1-}****功能:是PA8產(chǎn)生輸出,按鍵調(diào)節(jié)占空#include"STM32Lib\\stm32f10x.h"#include"hal.h"#defineSIZE charbuffer[10]={" voidDelay(u16n);voidd_2_char(u32{ }voidDelay(u16{u16i;{}}externvoid 1(u16int{u16 {{{ }{}}}{{pulse-}{}} }}#includeTIM_OCInitTypeDefTIM_OCInitStructure;uint16_tCCR1_Val=250;uint16_tCCR2_Val=500;uint16_tCCR3_Val=750;uint16_tCCR4_Val=0;uint16_tPrescalerValue=0;voidRCC_Configuration(void); voidGPIO_Configuration(void); voidDelay(IOuint32_tnCount); int{PrescalerValue=(uint16_t)(SystemCoreClock/ )-1;TIM_TimeBaseStructure.TIM_Period=1000; TIM_TimeBaseStructure.TIM_Prescaler=PrescalerValue; TIM_TimeBaseStructure.TIM_ClockDivision=0; TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;, /***************************通道1********************************/TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_2; TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable; //功能使能TIM_OCInitStructure.TIM_Pulse=CCR1_Val; TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_Low; TIM_OC1Init(TIM3,&TIM_OCInitStructure);/******************************2/*1Modeconfiguration:Channel2*/TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;TIM_OCInitStructure.TIM_Pulse=CCR2_Val;TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;TIM_OC2Init(TIM3,&TIM_OCInitStructure);TIM_OC2PreloadConfig(TIM3,TIM_OCPreload_Enable);/*******************************3 1Modeconfiguration:Channel3*/TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;TIM_OCInitStructure.TIM_Pulse=CCR3_Val;TIM_OC3Init(TIM3,&TIM_OCInitStructure);TIM_OC3PreloadConfig(TIM3,TIM_OCPreload_Enable);/******************************4 1Modeconfiguration:Channel4*/TIM_OCInitStructure.TIM_OutputStateTIM_OutputState_Enable;TIM_OCInitStructure.TIM_Pulse=CCR4_Val;TIM_OC4Init(TIM3,&TIM_OCInitStructure);TIM_OC4PreloadConfig(TIM3,TIM_OCPreload_Enable);TIM_ARRPreloadConfig(TIM3,ENABLE); TIM_Cmd(TIM3,ENABLE); while(1) }}/**********************************************************/voidRCC_Configuration(void){, //T3RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO,ENABLE);}/********************************************************/voidGPIO_Configuration(void){GPIO_InitTypeDefGPIO_InitStructure;GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GP
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 地鐵豎井罩棚施工方案
- 景觀樹基礎(chǔ)施工方案
- 海安工裝拆除施工方案
- 水中微型樁施工方案
- 懸浮樓梯施工方案
- 壽光路牙石施工方案
- 工藝燈安裝施工方案
- 二零二五年度勞動(dòng)合同期限與績(jī)效考核結(jié)果關(guān)聯(lián)合同
- 二零二五年度合同解除后債務(wù)重組協(xié)議
- 二零二五年度咖啡連鎖店加盟經(jīng)營(yíng)合同
- 《住院患者身體約束的護(hù)理》團(tuán)體標(biāo)準(zhǔn)解讀課件
- DZ∕T 0213-2020 礦產(chǎn)地質(zhì)勘查規(guī)范 石灰?guī)r、水泥配料類(正式版)
- 2024年黑龍江建筑職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試題庫全面
- MOOC 跨文化交際通識(shí)通論-揚(yáng)州大學(xué) 中國(guó)大學(xué)慕課答案
- GB/T 28799.2-2020冷熱水用耐熱聚乙烯(PE-RT)管道系統(tǒng)第2部分:管材
- 10000中國(guó)普通人名大全
- 公路工程竣工驗(yàn)收鑒定書
- 項(xiàng)目章程模板范文
- 耳尖放血療法治療高血壓病技術(shù)
- 泰山產(chǎn)業(yè)領(lǐng)軍人才工程系統(tǒng)
- 輪扣架支模體系材料量計(jì)算
評(píng)論
0/150
提交評(píng)論